Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 5 | * (C) 2008-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <errno.h> |
| 29 | #include <time.h> |
| 30 | #include <netinet/in.h> |
| 31 | |
Harald Welte | eaf4a52 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 32 | #include "bscconfig.h" |
| 33 | |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 34 | #include <openbsc/auth.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 35 | #include <openbsc/db.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 36 | #include <openbsc/debug.h> |
| 37 | #include <openbsc/gsm_data.h> |
| 38 | #include <openbsc/gsm_subscriber.h> |
| 39 | #include <openbsc/gsm_04_11.h> |
| 40 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | 9aa29b5 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 41 | #include <openbsc/gsm_04_80.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 42 | #include <openbsc/abis_rsl.h> |
| 43 | #include <openbsc/chan_alloc.h> |
| 44 | #include <openbsc/paging.h> |
| 45 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 46 | #include <osmocom/abis/trau_frame.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 47 | #include <openbsc/trau_mux.h> |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 48 | #include <openbsc/rtp_proxy.h> |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 49 | #include <openbsc/transaction.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 50 | #include <openbsc/ussd.h> |
Harald Welte | f6a38ec | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 51 | #include <openbsc/silent_call.h> |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 52 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | 3a0ec17 | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 53 | #include <openbsc/osmo_msc.h> |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 54 | #include <openbsc/handover.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 55 | #include <osmocom/abis/e1_input.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 56 | #include <osmocom/core/bitvec.h> |
Holger Hans Peter Freyther | 8925313 | 2010-09-30 18:52:23 +0800 | [diff] [blame] | 57 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 58 | #include <osmocom/gsm/gsm48.h> |
| 59 | #include <osmocom/gsm/gsm0480.h> |
| 60 | #include <osmocom/gsm/gsm_utils.h> |
| 61 | #include <osmocom/core/msgb.h> |
| 62 | #include <osmocom/core/talloc.h> |
| 63 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 64 | |
Holger Hans Peter Freyther | ac009e5 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 65 | #include <assert.h> |
| 66 | |
Harald Welte (local) | 8751ee9 | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 67 | void *tall_locop_ctx; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 68 | void *tall_authciphop_ctx; |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 69 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 70 | int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, uint32_t tmsi); |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 71 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 72 | uint8_t pdisc, uint8_t msg_type); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 73 | static void schedule_reject(struct gsm_subscriber_connection *conn); |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 74 | static void release_anchor(struct gsm_subscriber_connection *conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 75 | |
| 76 | struct gsm_lai { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 77 | uint16_t mcc; |
| 78 | uint16_t mnc; |
| 79 | uint16_t lac; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 80 | }; |
| 81 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 82 | static uint32_t new_callref = 0x80000001; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 83 | |
Harald Welte | 4f272cc | 2011-03-03 23:29:05 +0100 | [diff] [blame] | 84 | void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg) |
| 85 | { |
| 86 | net->mncc_recv(net, msg); |
| 87 | } |
| 88 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 89 | static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn, |
| 90 | struct gsm_trans *trans) |
| 91 | { |
| 92 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data; |
| 93 | |
| 94 | /* if we get passed a transaction reference, do some common |
| 95 | * work that the caller no longer has to do */ |
| 96 | if (trans) { |
| 97 | gh->proto_discr = trans->protocol | (trans->transaction_id << 4); |
| 98 | msg->lchan = trans->conn->lchan; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | if (msg->lchan) { |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 103 | struct e1inp_sign_link *sign_link = |
| 104 | msg->lchan->ts->trx->rsl_link; |
| 105 | |
| 106 | msg->dst = sign_link; |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 107 | if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) |
| 108 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) " |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 109 | "Sending '%s' to MS.\n", |
| 110 | sign_link->trx->bts->nr, |
| 111 | sign_link->trx->nr, msg->lchan->ts->nr, |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 112 | gh->proto_discr & 0xf0, |
| 113 | gsm48_cc_msg_name(gh->msg_type)); |
| 114 | else |
| 115 | DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) " |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 116 | "Sending 0x%02x to MS.\n", |
| 117 | sign_link->trx->bts->nr, |
| 118 | sign_link->trx->nr, msg->lchan->ts->nr, |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 119 | gh->proto_discr, gh->msg_type); |
| 120 | } |
| 121 | |
Holger Hans Peter Freyther | 6bfcad8 | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 122 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 123 | } |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 124 | |
Holger Hans Peter Freyther | 9aa29b5 | 2010-08-12 01:41:57 +0800 | [diff] [blame] | 125 | int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message) |
| 126 | { |
| 127 | struct gsm48_hdr *gh; |
| 128 | struct msgb *ss_notify; |
| 129 | |
| 130 | ss_notify = gsm0480_create_notifySS(message); |
| 131 | if (!ss_notify) |
| 132 | return -1; |
| 133 | |
| 134 | gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0); |
| 135 | uint8_t *data = msgb_push(ss_notify, 1); |
| 136 | data[0] = ss_notify->len - 1; |
| 137 | gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh)); |
| 138 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 139 | return gsm48_conn_sendmsg(ss_notify, trans->conn, trans); |
| 140 | } |
| 141 | |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 142 | void release_security_operation(struct gsm_subscriber_connection *conn) |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 143 | { |
| 144 | if (!conn->sec_operation) |
| 145 | return; |
| 146 | |
| 147 | talloc_free(conn->sec_operation); |
| 148 | conn->sec_operation = NULL; |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 149 | msc_release_connection(conn); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 152 | void allocate_security_operation(struct gsm_subscriber_connection *conn) |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 153 | { |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 154 | conn->sec_operation = talloc_zero(tall_authciphop_ctx, |
| 155 | struct gsm_security_operation); |
| 156 | } |
| 157 | |
Sylvain Munaut | c0bdbb4 | 2010-12-01 22:37:05 +0100 | [diff] [blame] | 158 | int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq, |
| 159 | gsm_cbfn *cb, void *cb_data) |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 160 | { |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 161 | struct gsm_network *net = conn->bts->network; |
| 162 | struct gsm_subscriber *subscr = conn->subscr; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 163 | struct gsm_security_operation *op; |
| 164 | struct gsm_auth_tuple atuple; |
| 165 | int status = -1, rc; |
| 166 | |
| 167 | /* Check if we _can_ enable encryption. Cases where we can't: |
| 168 | * - Encryption disabled in config |
| 169 | * - Channel already secured (nothing to do) |
| 170 | * - Subscriber equipment doesn't support configured encryption |
| 171 | */ |
| 172 | if (!net->a5_encryption) { |
| 173 | status = GSM_SECURITY_NOAVAIL; |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 174 | } else if (conn->lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) { |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 175 | DEBUGP(DMM, "Requesting to secure an already secure channel"); |
Andreas Eversberg | ee99535 | 2013-07-10 08:58:03 +0200 | [diff] [blame] | 176 | status = GSM_SECURITY_ALREADY; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 177 | } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2, |
| 178 | net->a5_encryption)) { |
| 179 | DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption"); |
| 180 | status = GSM_SECURITY_NOAVAIL; |
| 181 | } |
| 182 | |
| 183 | /* If not done yet, try to get info for this user */ |
| 184 | if (status < 0) { |
| 185 | rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq); |
| 186 | if (rc <= 0) |
| 187 | status = GSM_SECURITY_NOAVAIL; |
| 188 | } |
| 189 | |
| 190 | /* Are we done yet ? */ |
| 191 | if (status >= 0) |
| 192 | return cb ? |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 193 | cb(GSM_HOOK_RR_SECURITY, status, NULL, conn, cb_data) : |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 194 | 0; |
| 195 | |
| 196 | /* Start an operation (can't have more than one pending !!!) */ |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 197 | if (conn->sec_operation) |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 198 | return -EBUSY; |
| 199 | |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 200 | allocate_security_operation(conn); |
| 201 | op = conn->sec_operation; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 202 | op->cb = cb; |
| 203 | op->cb_data = cb_data; |
| 204 | memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple)); |
| 205 | |
| 206 | /* FIXME: Should start a timer for completion ... */ |
| 207 | |
| 208 | /* Then do whatever is needed ... */ |
Harald Welte | 857e15d | 2010-12-23 18:07:49 +0100 | [diff] [blame] | 209 | if (rc == AUTH_DO_AUTH_THAN_CIPH) { |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 210 | /* Start authentication */ |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 211 | return gsm48_tx_mm_auth_req(conn, op->atuple.rand, op->atuple.key_seq); |
Harald Welte | 857e15d | 2010-12-23 18:07:49 +0100 | [diff] [blame] | 212 | } else if (rc == AUTH_DO_CIPH) { |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 213 | /* Start ciphering directly */ |
Sylvain Munaut | 469c28f | 2010-11-29 08:19:04 +0100 | [diff] [blame] | 214 | return gsm0808_cipher_mode(conn, net->a5_encryption, |
| 215 | op->atuple.kc, 8, 0); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | return -EINVAL; /* not reached */ |
| 219 | } |
| 220 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 221 | static int authorize_subscriber(struct gsm_loc_updating_operation *loc, |
| 222 | struct gsm_subscriber *subscriber) |
| 223 | { |
| 224 | if (!subscriber) |
| 225 | return 0; |
| 226 | |
| 227 | /* |
| 228 | * Do not send accept yet as more information should arrive. Some |
| 229 | * phones will not send us the information and we will have to check |
| 230 | * what we want to do with that. |
| 231 | */ |
| 232 | if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei)) |
| 233 | return 0; |
| 234 | |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 235 | switch (subscriber->net->auth_policy) { |
| 236 | case GSM_AUTH_POLICY_CLOSED: |
| 237 | return subscriber->authorized; |
Harald Welte (local) | 16480eb | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 238 | case GSM_AUTH_POLICY_TOKEN: |
Harald Welte (local) | 272f5c7 | 2009-08-13 20:44:23 +0200 | [diff] [blame] | 239 | if (subscriber->authorized) |
| 240 | return subscriber->authorized; |
Harald Welte (local) | 16480eb | 2009-08-13 13:49:51 +0200 | [diff] [blame] | 241 | return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT); |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 242 | case GSM_AUTH_POLICY_ACCEPT_ALL: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 243 | return 1; |
Jan Luebbe | 3d6294e | 2009-08-12 12:48:00 +0200 | [diff] [blame] | 244 | default: |
| 245 | return 0; |
| 246 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 249 | static void release_loc_updating_req(struct gsm_subscriber_connection *conn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 250 | { |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 251 | if (!conn->loc_operation) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 252 | return; |
| 253 | |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 254 | /* No need to keep the connection up */ |
| 255 | release_anchor(conn); |
| 256 | |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 257 | osmo_timer_del(&conn->loc_operation->updating_timer); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 258 | talloc_free(conn->loc_operation); |
Holger Hans Peter Freyther | bed0709 | 2010-12-22 08:53:28 +0100 | [diff] [blame] | 259 | conn->loc_operation = NULL; |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 260 | msc_release_connection(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 261 | } |
| 262 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 263 | static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 264 | { |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 265 | if (conn->loc_operation) |
| 266 | LOGP(DMM, LOGL_ERROR, "Connection already had operation.\n"); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 267 | release_loc_updating_req(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 268 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 269 | conn->loc_operation = talloc_zero(tall_locop_ctx, |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 270 | struct gsm_loc_updating_operation); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 271 | } |
| 272 | |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 273 | static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event, |
| 274 | struct msgb *msg, void *data, void *param) |
| 275 | { |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 276 | struct gsm_subscriber_connection *conn = data; |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 277 | int rc = 0; |
| 278 | |
| 279 | switch (event) { |
| 280 | case GSM_SECURITY_AUTH_FAILED: |
| 281 | release_loc_updating_req(conn); |
| 282 | break; |
| 283 | |
| 284 | case GSM_SECURITY_NOAVAIL: |
| 285 | case GSM_SECURITY_SUCCEEDED: |
| 286 | /* We're all good */ |
| 287 | db_subscriber_alloc_tmsi(conn->subscr); |
Holger Hans Peter Freyther | fa2bafd | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 288 | rc = gsm0408_loc_upd_acc(conn, conn->subscr->tmsi); |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 289 | if (conn->bts->network->send_mm_info) { |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 290 | /* send MM INFO with network name */ |
Holger Hans Peter Freyther | 3d31527 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 291 | rc = gsm48_tx_mm_info(conn); |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* call subscr_update after putting the loc_upd_acc |
| 295 | * in the transmit queue, since S_SUBSCR_ATTACHED might |
| 296 | * trigger further action like SMS delivery */ |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 297 | subscr_update(conn->subscr, conn->bts, |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 298 | GSM_SUBSCRIBER_UPDATE_ATTACHED); |
| 299 | |
Holger Hans Peter Freyther | f08a1d7 | 2010-12-22 12:11:01 +0100 | [diff] [blame] | 300 | /* |
| 301 | * The gsm0408_loc_upd_acc sends a MI with the TMSI. The |
| 302 | * MS needs to respond with a TMSI REALLOCATION COMPLETE |
| 303 | * (even if the TMSI is the same). |
| 304 | */ |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 305 | break; |
| 306 | |
| 307 | default: |
| 308 | rc = -EINVAL; |
| 309 | }; |
| 310 | |
| 311 | return rc; |
| 312 | } |
| 313 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 314 | static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 315 | { |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 316 | if (authorize_subscriber(conn->loc_operation, conn->subscr)) |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 317 | return gsm48_secure_channel(conn, |
Sylvain Munaut | cb321fb | 2009-12-24 00:28:01 +0100 | [diff] [blame] | 318 | conn->loc_operation->key_seq, |
| 319 | _gsm0408_authorize_sec_cb, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
Holger Hans Peter Freyther | dfd61a3 | 2010-09-18 06:44:24 +0800 | [diff] [blame] | 323 | void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 324 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 325 | struct gsm_trans *trans, *temp; |
Holger Hans Peter Freyther | 6e5c50f | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 326 | |
| 327 | /* avoid someone issuing a clear */ |
| 328 | conn->in_release = 1; |
| 329 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 330 | /* |
| 331 | * Cancel any outstanding location updating request |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 332 | * operation taking place on the subscriber connection. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 333 | */ |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 334 | release_loc_updating_req(conn); |
Holger Hans Peter Freyther | d91346a | 2010-12-28 14:57:20 +0100 | [diff] [blame] | 335 | |
| 336 | /* We might need to cancel the paging response or such. */ |
| 337 | if (conn->sec_operation && conn->sec_operation->cb) { |
| 338 | conn->sec_operation->cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED, |
| 339 | NULL, conn, conn->sec_operation->cb_data); |
| 340 | } |
| 341 | |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 342 | release_security_operation(conn); |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 343 | release_anchor(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 344 | |
Holger Hans Peter Freyther | 0b28dbc | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 345 | /* |
| 346 | * Free all transactions that are associated with the released |
| 347 | * connection. The transaction code will inform the CC or SMS |
| 348 | * facilities that will send the release indications. As part of |
| 349 | * the CC REL_IND the remote leg might be released and this will |
| 350 | * trigger the call to trans_free. This is something the llist |
| 351 | * macro can not handle and we will need to re-iterate the list. |
| 352 | * |
| 353 | * TODO: Move the trans_list into the subscriber connection and |
| 354 | * create a pending list for MT transactions. These exist before |
| 355 | * we have a subscriber connection. |
| 356 | */ |
| 357 | restart: |
Holger Hans Peter Freyther | ed4e3bd | 2010-06-15 13:16:52 +0800 | [diff] [blame] | 358 | llist_for_each_entry_safe(trans, temp, &conn->bts->network->trans_list, entry) { |
Holger Hans Peter Freyther | 0b28dbc | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 359 | if (trans->conn == conn) { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 360 | trans_free(trans); |
Holger Hans Peter Freyther | 0b28dbc | 2012-12-22 18:45:27 +0100 | [diff] [blame] | 361 | goto restart; |
| 362 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 363 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 364 | } |
| 365 | |
Harald Welte | e8d1617 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 366 | void gsm0408_clear_all_trans(struct gsm_network *net, int protocol) |
| 367 | { |
| 368 | struct gsm_trans *trans, *temp; |
| 369 | |
| 370 | LOGP(DCC, LOGL_NOTICE, "Clearing all currently active transactions!!!\n"); |
| 371 | |
| 372 | llist_for_each_entry_safe(trans, temp, &net->trans_list, entry) { |
Harald Welte | bd0f33c | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 373 | if (trans->protocol == protocol) { |
| 374 | trans->callref = 0; |
Harald Welte | e8d1617 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 375 | trans_free(trans); |
Harald Welte | bd0f33c | 2010-12-23 02:47:53 +0100 | [diff] [blame] | 376 | } |
Harald Welte | e8d1617 | 2010-12-22 23:17:50 +0100 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 380 | /* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 381 | int gsm0408_loc_upd_rej(struct gsm_subscriber_connection *conn, uint8_t cause) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 382 | { |
Holger Hans Peter Freyther | b57d556 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 383 | struct gsm_bts *bts = conn->bts; |
Holger Hans Peter Freyther | 8073cbd | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 384 | struct msgb *msg; |
| 385 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 386 | osmo_counter_inc(bts->network->stats.loc_upd_resp.reject); |
Holger Hans Peter Freyther | 8073cbd | 2010-06-15 19:40:05 +0800 | [diff] [blame] | 387 | |
| 388 | msg = gsm48_create_loc_upd_rej(cause); |
| 389 | if (!msg) { |
| 390 | LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n"); |
| 391 | return -1; |
| 392 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 393 | |
Holger Hans Peter Freyther | b57d556 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 394 | msg->lchan = conn->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 395 | |
Harald Welte (local) | 38a9e5d | 2009-12-26 22:15:28 +0100 | [diff] [blame] | 396 | LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT " |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 397 | "LAC=%u BTS=%u\n", conn->subscr ? |
| 398 | subscr_name(conn->subscr) : "unknown", |
Holger Hans Peter Freyther | b57d556 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 399 | bts->location_area_code, bts->nr); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 400 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 401 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 405 | int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, uint32_t tmsi) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 406 | { |
Holger Hans Peter Freyther | fa2bafd | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 407 | struct gsm_bts *bts = conn->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 408 | struct msgb *msg = gsm48_msgb_alloc(); |
| 409 | struct gsm48_hdr *gh; |
| 410 | struct gsm48_loc_area_id *lai; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 411 | uint8_t *mid; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 412 | |
Holger Hans Peter Freyther | fa2bafd | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 413 | msg->lchan = conn->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 414 | |
| 415 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 416 | gh->proto_discr = GSM48_PDISC_MM; |
| 417 | gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT; |
| 418 | |
| 419 | lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai)); |
Harald Welte | d8493ac | 2010-03-04 10:55:40 +0100 | [diff] [blame] | 420 | gsm48_generate_lai(lai, bts->network->country_code, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 421 | bts->network->network_code, bts->location_area_code); |
| 422 | |
Holger Hans Peter Freyther | 3689710 | 2009-08-01 07:26:59 +0200 | [diff] [blame] | 423 | mid = msgb_put(msg, GSM48_MID_TMSI_LEN); |
Holger Hans Peter Freyther | 20a0f32 | 2009-08-20 08:41:24 +0200 | [diff] [blame] | 424 | gsm48_generate_mid_from_tmsi(mid, tmsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 425 | |
| 426 | DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n"); |
| 427 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 428 | osmo_counter_inc(bts->network->stats.loc_upd_resp.accept); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 429 | |
Holger Hans Peter Freyther | fa2bafd | 2010-06-15 14:07:27 +0800 | [diff] [blame] | 430 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 431 | } |
| 432 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 433 | /* Transmit Chapter 9.2.10 Identity Request */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 434 | static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, uint8_t id_type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 435 | { |
| 436 | struct msgb *msg = gsm48_msgb_alloc(); |
| 437 | struct gsm48_hdr *gh; |
| 438 | |
Holger Hans Peter Freyther | cbecea5 | 2010-06-15 14:11:01 +0800 | [diff] [blame] | 439 | msg->lchan = conn->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 440 | |
| 441 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1); |
| 442 | gh->proto_discr = GSM48_PDISC_MM; |
| 443 | gh->msg_type = GSM48_MT_MM_ID_REQ; |
| 444 | gh->data[0] = id_type; |
| 445 | |
Holger Hans Peter Freyther | cbecea5 | 2010-06-15 14:11:01 +0800 | [diff] [blame] | 446 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 447 | } |
| 448 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 449 | |
| 450 | /* Parse Chapter 9.2.11 Identity Response */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 451 | static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 452 | { |
| 453 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 454 | struct gsm_lchan *lchan = msg->lchan; |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 455 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 456 | struct gsm_network *net = bts->network; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 457 | uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 458 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 459 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 460 | gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 461 | DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 462 | mi_type, mi_string); |
| 463 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 464 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data); |
Harald Welte | edf48af | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 465 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 466 | switch (mi_type) { |
| 467 | case GSM_MI_TYPE_IMSI: |
Jan Luebbe | 9bdbd62 | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 468 | /* look up subscriber based on IMSI, create if not found */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 469 | if (!conn->subscr) { |
| 470 | conn->subscr = subscr_get_by_imsi(net, mi_string); |
| 471 | if (!conn->subscr) |
| 472 | conn->subscr = db_create_subscriber(net, mi_string); |
Jan Luebbe | e297403 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 473 | } |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 474 | if (conn->loc_operation) |
| 475 | conn->loc_operation->waiting_for_imsi = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 476 | break; |
| 477 | case GSM_MI_TYPE_IMEI: |
| 478 | case GSM_MI_TYPE_IMEISV: |
| 479 | /* update subscribe <-> IMEI mapping */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 480 | if (conn->subscr) { |
| 481 | db_subscriber_assoc_imei(conn->subscr, mi_string); |
| 482 | db_sync_equipment(&conn->subscr->equipment); |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 483 | } |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 484 | if (conn->loc_operation) |
| 485 | conn->loc_operation->waiting_for_imei = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | |
| 489 | /* Check if we can let the mobile station enter */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 490 | return gsm0408_authorize(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
| 494 | static void loc_upd_rej_cb(void *data) |
| 495 | { |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 496 | struct gsm_subscriber_connection *conn = data; |
| 497 | struct gsm_lchan *lchan = conn->lchan; |
Harald Welte | 59936d7 | 2009-11-18 20:33:19 +0100 | [diff] [blame] | 498 | struct gsm_bts *bts = lchan->ts->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 499 | |
Holger Hans Peter Freyther | 0d91c46 | 2011-11-07 12:26:29 +0100 | [diff] [blame] | 500 | LOGP(DMM, LOGL_DEBUG, "Location Updating Request procedure timedout.\n"); |
Holger Hans Peter Freyther | b57d556 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 501 | gsm0408_loc_upd_rej(conn, bts->network->reject_cause); |
Holger Hans Peter Freyther | 1817b0b | 2010-06-16 12:52:28 +0800 | [diff] [blame] | 502 | release_loc_updating_req(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 503 | } |
| 504 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 505 | static void schedule_reject(struct gsm_subscriber_connection *conn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 506 | { |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 507 | conn->loc_operation->updating_timer.cb = loc_upd_rej_cb; |
| 508 | conn->loc_operation->updating_timer.data = conn; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 509 | osmo_timer_schedule(&conn->loc_operation->updating_timer, 5, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 510 | } |
| 511 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 512 | static const char *lupd_name(uint8_t type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 513 | { |
| 514 | switch (type) { |
| 515 | case GSM48_LUPD_NORMAL: |
| 516 | return "NORMAL"; |
| 517 | case GSM48_LUPD_PERIODIC: |
| 518 | return "PEROIDOC"; |
| 519 | case GSM48_LUPD_IMSI_ATT: |
| 520 | return "IMSI ATTACH"; |
| 521 | default: |
| 522 | return "UNKNOWN"; |
| 523 | } |
| 524 | } |
| 525 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 526 | /* Chapter 9.2.15: Receive Location Updating Request */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 527 | static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 528 | { |
| 529 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 530 | struct gsm48_loc_upd_req *lu; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 531 | struct gsm_subscriber *subscr = NULL; |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 532 | struct gsm_bts *bts = conn->bts; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 533 | uint8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 534 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 535 | |
| 536 | lu = (struct gsm48_loc_upd_req *) gh->data; |
| 537 | |
| 538 | mi_type = lu->mi[0] & GSM_MI_TYPE_MASK; |
| 539 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 540 | gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 541 | |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 542 | DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 543 | lupd_name(lu->type)); |
| 544 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 545 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len); |
Harald Welte | edf48af | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 546 | |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 547 | switch (lu->type) { |
| 548 | case GSM48_LUPD_NORMAL: |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 549 | osmo_counter_inc(bts->network->stats.loc_upd_type.normal); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 550 | break; |
| 551 | case GSM48_LUPD_IMSI_ATT: |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 552 | osmo_counter_inc(bts->network->stats.loc_upd_type.attach); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 553 | break; |
| 554 | case GSM48_LUPD_PERIODIC: |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 555 | osmo_counter_inc(bts->network->stats.loc_upd_type.periodic); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 559 | /* |
| 560 | * Pseudo Spoof detection: Just drop a second/concurrent |
| 561 | * location updating request. |
| 562 | */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 563 | if (conn->loc_operation) { |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 564 | DEBUGPC(DMM, "ignoring request due an existing one: %p.\n", |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 565 | conn->loc_operation); |
Holger Hans Peter Freyther | b57d556 | 2010-06-15 14:09:34 +0800 | [diff] [blame] | 566 | gsm0408_loc_upd_rej(conn, GSM48_REJECT_PROTOCOL_ERROR); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 570 | allocate_loc_updating_req(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 571 | |
Sylvain Munaut | 360fc58 | 2010-06-10 13:36:59 +0200 | [diff] [blame] | 572 | conn->loc_operation->key_seq = lu->key_seq; |
| 573 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 574 | switch (mi_type) { |
| 575 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 576 | DEBUGPC(DMM, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 577 | /* we always want the IMEI, too */ |
Holger Hans Peter Freyther | 1a9f3ee | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 578 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 579 | conn->loc_operation->waiting_for_imei = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 580 | |
Jan Luebbe | 9bdbd62 | 2009-08-12 10:19:34 +0200 | [diff] [blame] | 581 | /* look up subscriber based on IMSI, create if not found */ |
| 582 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
| 583 | if (!subscr) { |
| 584 | subscr = db_create_subscriber(bts->network, mi_string); |
| 585 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 586 | break; |
| 587 | case GSM_MI_TYPE_TMSI: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 588 | DEBUGPC(DMM, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 589 | /* look up the subscriber based on TMSI, request IMSI if it fails */ |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 590 | subscr = subscr_get_by_tmsi(bts->network, |
| 591 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 592 | if (!subscr) { |
| 593 | /* send IDENTITY REQUEST message to get IMSI */ |
Holger Hans Peter Freyther | 1a9f3ee | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 594 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMSI); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 595 | conn->loc_operation->waiting_for_imsi = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 596 | } |
Harald Welte | ca6dfc0 | 2010-06-07 17:56:32 +0200 | [diff] [blame] | 597 | /* we always want the IMEI, too */ |
Holger Hans Peter Freyther | 1a9f3ee | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 598 | mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI); |
Harald Welte | ca6dfc0 | 2010-06-07 17:56:32 +0200 | [diff] [blame] | 599 | conn->loc_operation->waiting_for_imei = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 600 | break; |
| 601 | case GSM_MI_TYPE_IMEI: |
| 602 | case GSM_MI_TYPE_IMEISV: |
| 603 | /* no sim card... FIXME: what to do ? */ |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 604 | DEBUGPC(DMM, "unimplemented mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 605 | break; |
| 606 | default: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 607 | DEBUGPC(DMM, "unknown mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 608 | break; |
| 609 | } |
| 610 | |
Harald Welte | ccd6936 | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 611 | /* schedule the reject timer */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 612 | schedule_reject(conn); |
Harald Welte | ccd6936 | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 613 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 614 | if (!subscr) { |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 615 | DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n"); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 616 | /* FIXME: request id? close channel? */ |
| 617 | return -EINVAL; |
| 618 | } |
| 619 | |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 620 | conn->subscr = subscr; |
| 621 | conn->subscr->equipment.classmark1 = lu->classmark1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 622 | |
Harald Welte | ccd6936 | 2009-07-04 10:18:00 +0200 | [diff] [blame] | 623 | /* check if we can let the subscriber into our network immediately |
| 624 | * or if we need to wait for identity responses. */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 625 | return gsm0408_authorize(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 626 | } |
| 627 | |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 628 | /* Turn int into semi-octet representation: 98 => 0x89 */ |
| 629 | static uint8_t bcdify(uint8_t value) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 630 | { |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 631 | uint8_t ret; |
| 632 | |
| 633 | ret = value / 10; |
| 634 | ret |= (value % 10) << 4; |
| 635 | |
| 636 | return ret; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 637 | } |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 638 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 639 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 640 | /* Section 9.2.15a */ |
Holger Hans Peter Freyther | 3d31527 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 641 | int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 642 | { |
| 643 | struct msgb *msg = gsm48_msgb_alloc(); |
| 644 | struct gsm48_hdr *gh; |
Holger Hans Peter Freyther | 3d31527 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 645 | struct gsm_network *net = conn->bts->network; |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 646 | struct gsm_bts *bts = conn->bts; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 647 | uint8_t *ptr8; |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 648 | int name_len, name_pad; |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 649 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 650 | time_t cur_t; |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 651 | struct tm* gmt_time; |
| 652 | struct tm* local_time; |
| 653 | int tzunits; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 654 | |
Holger Hans Peter Freyther | 3d31527 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 655 | msg->lchan = conn->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 656 | |
| 657 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 658 | gh->proto_discr = GSM48_PDISC_MM; |
| 659 | gh->msg_type = GSM48_MT_MM_INFO; |
| 660 | |
| 661 | if (net->name_long) { |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 662 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 663 | name_len = strlen(net->name_long); |
| 664 | /* 10.5.3.5a */ |
| 665 | ptr8 = msgb_put(msg, 3); |
| 666 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 667 | ptr8[1] = name_len*2 +1; |
| 668 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 669 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 670 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 671 | for (i = 0; i < name_len; i++) |
| 672 | ptr16[i] = htons(net->name_long[i]); |
| 673 | |
| 674 | /* FIXME: Use Cell Broadcast, not UCS-2, since |
| 675 | * UCS-2 is only supported by later revisions of the spec */ |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 676 | #endif |
| 677 | name_len = (strlen(net->name_long)*7)/8; |
| 678 | name_pad = (8 - strlen(net->name_long)*7)%8; |
| 679 | if (name_pad > 0) |
| 680 | name_len++; |
| 681 | /* 10.5.3.5a */ |
| 682 | ptr8 = msgb_put(msg, 3); |
| 683 | ptr8[0] = GSM48_IE_NAME_LONG; |
| 684 | ptr8[1] = name_len +1; |
| 685 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 686 | |
| 687 | ptr8 = msgb_put(msg, name_len); |
| 688 | gsm_7bit_encode(ptr8, net->name_long); |
| 689 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | if (net->name_short) { |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 693 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 694 | name_len = strlen(net->name_short); |
| 695 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 696 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Harald Welte | f628471 | 2009-07-19 17:51:36 +0200 | [diff] [blame] | 697 | ptr8[0] = GSM48_IE_NAME_SHORT; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 698 | ptr8[1] = name_len*2 + 1; |
| 699 | ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */ |
| 700 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 701 | ptr16 = (uint16_t *) msgb_put(msg, name_len*2); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 702 | for (i = 0; i < name_len; i++) |
| 703 | ptr16[i] = htons(net->name_short[i]); |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 704 | #endif |
| 705 | name_len = (strlen(net->name_short)*7)/8; |
| 706 | name_pad = (8 - strlen(net->name_short)*7)%8; |
| 707 | if (name_pad > 0) |
| 708 | name_len++; |
| 709 | /* 10.5.3.5a */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 710 | ptr8 = (uint8_t *) msgb_put(msg, 3); |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 711 | ptr8[0] = GSM48_IE_NAME_SHORT; |
| 712 | ptr8[1] = name_len +1; |
| 713 | ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */ |
| 714 | |
| 715 | ptr8 = msgb_put(msg, name_len); |
| 716 | gsm_7bit_encode(ptr8, net->name_short); |
| 717 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 718 | } |
| 719 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 720 | /* Section 10.5.3.9 */ |
| 721 | cur_t = time(NULL); |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 722 | gmt_time = gmtime(&cur_t); |
| 723 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 724 | ptr8 = msgb_put(msg, 8); |
| 725 | ptr8[0] = GSM48_IE_NET_TIME_TZ; |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 726 | ptr8[1] = bcdify(gmt_time->tm_year % 100); |
| 727 | ptr8[2] = bcdify(gmt_time->tm_mon + 1); |
| 728 | ptr8[3] = bcdify(gmt_time->tm_mday); |
| 729 | ptr8[4] = bcdify(gmt_time->tm_hour); |
| 730 | ptr8[5] = bcdify(gmt_time->tm_min); |
| 731 | ptr8[6] = bcdify(gmt_time->tm_sec); |
| 732 | |
Harald Welte | 5c3abf9 | 2012-07-08 16:48:11 +0200 | [diff] [blame] | 733 | if (bts->tz.override) { |
| 734 | /* Convert tz.hr and tz.mn to units */ |
| 735 | if (bts->tz.hr < 0) { |
| 736 | tzunits = ((bts->tz.hr/-1)*4); |
| 737 | tzunits = tzunits + (bts->tz.mn/15); |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 738 | ptr8[7] = bcdify(tzunits); |
| 739 | /* Set negative time */ |
| 740 | ptr8[7] |= 0x08; |
| 741 | } |
| 742 | else { |
Harald Welte | 5c3abf9 | 2012-07-08 16:48:11 +0200 | [diff] [blame] | 743 | tzunits = bts->tz.hr*4; |
| 744 | tzunits = tzunits + (bts->tz.mn/15); |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 745 | ptr8[7] = bcdify(tzunits); |
| 746 | } |
| 747 | } |
| 748 | else { |
| 749 | /* Need to get GSM offset and convert into 15 min units */ |
| 750 | /* This probably breaks if gmtoff returns a value not evenly divisible by 15? */ |
| 751 | local_time = localtime(&cur_t); |
Harald Welte | eaf4a52 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 752 | #ifdef HAVE_TM_GMTOFF_IN_TM |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 753 | tzunits = (local_time->tm_gmtoff/60)/15; |
Harald Welte | eaf4a52 | 2012-04-08 16:59:24 +0200 | [diff] [blame] | 754 | #else |
| 755 | #warning find a portable way to obtain the timezone offset |
| 756 | tzunits = 0; |
| 757 | #endif |
Gus Bourg | f9dc16b | 2011-12-02 10:18:17 +0100 | [diff] [blame] | 758 | if (tzunits < 0) { |
| 759 | tzunits = tzunits/-1; |
| 760 | ptr8[7] = bcdify(tzunits); |
| 761 | /* Flip it to negative */ |
| 762 | ptr8[7] |= 0x08; |
| 763 | } |
| 764 | else |
| 765 | ptr8[7] = bcdify(tzunits); |
| 766 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 767 | |
Daniel Willmann | c818820 | 2009-08-13 03:42:07 +0200 | [diff] [blame] | 768 | DEBUGP(DMM, "-> MM INFO\n"); |
| 769 | |
Holger Hans Peter Freyther | 3d31527 | 2010-06-15 14:16:02 +0800 | [diff] [blame] | 770 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 773 | /* Section 9.2.2 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 774 | int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, uint8_t *rand, int key_seq) |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 775 | { |
| 776 | struct msgb *msg = gsm48_msgb_alloc(); |
| 777 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 778 | struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar)); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 779 | |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 780 | DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", osmo_hexdump(rand, 16)); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 781 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 782 | msg->lchan = conn->lchan; |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 783 | gh->proto_discr = GSM48_PDISC_MM; |
| 784 | gh->msg_type = GSM48_MT_MM_AUTH_REQ; |
| 785 | |
Sylvain Munaut | 0789c59 | 2009-12-24 00:23:46 +0100 | [diff] [blame] | 786 | ar->key_seq = key_seq; |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 787 | |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 788 | /* 16 bytes RAND parameters */ |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 789 | if (rand) |
Sylvain Munaut | 6de6dc1 | 2009-09-27 11:10:17 +0200 | [diff] [blame] | 790 | memcpy(ar->rand, rand, 16); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 791 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 792 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* Section 9.2.1 */ |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 796 | int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn) |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 797 | { |
| 798 | DEBUGP(DMM, "-> AUTH REJECT\n"); |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 799 | return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ); |
Harald Welte | 36970f6 | 2009-08-12 22:56:50 +0200 | [diff] [blame] | 800 | } |
| 801 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 802 | static int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 803 | { |
| 804 | DEBUGP(DMM, "-> CM SERVICE ACK\n"); |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 805 | return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* 9.2.6 CM service reject */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 809 | static int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 810 | enum gsm48_reject_value value) |
| 811 | { |
Holger Hans Peter Freyther | a44eea5 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 812 | struct msgb *msg; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 813 | |
Holger Hans Peter Freyther | a44eea5 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 814 | msg = gsm48_create_mm_serv_rej(value); |
| 815 | if (!msg) { |
| 816 | LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n"); |
| 817 | return -1; |
| 818 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 819 | |
Holger Hans Peter Freyther | a44eea5 | 2010-06-15 19:39:27 +0800 | [diff] [blame] | 820 | DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 821 | msg->lchan = conn->lchan; |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 822 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 823 | } |
| 824 | |
Sylvain Munaut | badc711 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 825 | static int _gsm48_rx_mm_serv_req_sec_cb( |
| 826 | unsigned int hooknum, unsigned int event, |
| 827 | struct msgb *msg, void *data, void *param) |
| 828 | { |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 829 | struct gsm_subscriber_connection *conn = data; |
Sylvain Munaut | badc711 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 830 | int rc = 0; |
| 831 | |
| 832 | switch (event) { |
| 833 | case GSM_SECURITY_AUTH_FAILED: |
| 834 | /* Nothing to do */ |
| 835 | break; |
| 836 | |
| 837 | case GSM_SECURITY_NOAVAIL: |
Andreas Eversberg | ee99535 | 2013-07-10 08:58:03 +0200 | [diff] [blame] | 838 | case GSM_SECURITY_ALREADY: |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 839 | rc = gsm48_tx_mm_serv_ack(conn); |
Sylvain Munaut | badc711 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case GSM_SECURITY_SUCCEEDED: |
| 843 | /* nothing to do. CIPHER MODE COMMAND is |
| 844 | * implicit CM SERV ACK */ |
| 845 | break; |
| 846 | |
| 847 | default: |
| 848 | rc = -EINVAL; |
| 849 | }; |
| 850 | |
| 851 | return rc; |
| 852 | } |
| 853 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 854 | /* |
| 855 | * Handle CM Service Requests |
| 856 | * a) Verify that the packet is long enough to contain the information |
| 857 | * we require otherwsie reject with INCORRECT_MESSAGE |
| 858 | * b) Try to parse the TMSI. If we do not have one reject |
| 859 | * c) Check that we know the subscriber with the TMSI otherwise reject |
| 860 | * with a HLR cause |
| 861 | * d) Set the subscriber on the gsm_lchan and accept |
| 862 | */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 863 | static int gsm48_rx_mm_serv_req(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 864 | { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 865 | uint8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 866 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 867 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 868 | struct gsm_bts *bts = conn->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 869 | struct gsm_subscriber *subscr; |
| 870 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 871 | struct gsm48_service_request *req = |
| 872 | (struct gsm48_service_request *)gh->data; |
Holger Hans Peter Freyther | 0570832 | 2010-05-14 08:02:08 +0800 | [diff] [blame] | 873 | /* unfortunately in Phase1 the classmark2 length is variable */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 874 | uint8_t classmark2_len = gh->data[1]; |
| 875 | uint8_t *classmark2 = gh->data+2; |
| 876 | uint8_t mi_len = *(classmark2 + classmark2_len); |
| 877 | uint8_t *mi = (classmark2 + classmark2_len + 1); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 878 | |
| 879 | DEBUGP(DMM, "<- CM SERVICE REQUEST "); |
| 880 | if (msg->data_len < sizeof(struct gsm48_service_request*)) { |
| 881 | DEBUGPC(DMM, "wrong sized message\n"); |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 882 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 883 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 884 | } |
| 885 | |
| 886 | if (msg->data_len < req->mi_len + 6) { |
| 887 | DEBUGPC(DMM, "does not fit in packet\n"); |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 888 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 889 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 890 | } |
| 891 | |
| 892 | mi_type = mi[0] & GSM_MI_TYPE_MASK; |
| 893 | if (mi_type != GSM_MI_TYPE_TMSI) { |
| 894 | DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type); |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 895 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 896 | GSM48_REJECT_INCORRECT_MESSAGE); |
| 897 | } |
| 898 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 899 | gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 900 | DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n", |
| 901 | req->cm_service_type, mi_type, mi_string); |
| 902 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 903 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len)); |
Harald Welte | edf48af | 2009-12-13 12:39:18 +0100 | [diff] [blame] | 904 | |
Harald Welte | 583ceaf | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 905 | if (is_siemens_bts(bts)) |
| 906 | send_siemens_mrpci(msg->lchan, classmark2-1); |
| 907 | |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 908 | subscr = subscr_get_by_tmsi(bts->network, |
| 909 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 910 | |
| 911 | /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */ |
| 912 | if (!subscr) |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 913 | return gsm48_tx_mm_serv_rej(conn, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 914 | GSM48_REJECT_IMSI_UNKNOWN_IN_HLR); |
Holger Hans Peter Freyther | fe03695 | 2013-01-01 17:18:27 +0100 | [diff] [blame] | 915 | if (subscr->lac == GSM_LAC_RESERVED_DETACHED) |
Sylvain Munaut | f108741 | 2012-12-28 00:33:04 +0100 | [diff] [blame] | 916 | /* If the subscriber is not attached, reject service */ |
| 917 | return gsm48_tx_mm_serv_rej(conn, |
| 918 | GSM48_REJECT_IMSI_UNKNOWN_IN_VLR); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 919 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 920 | if (!conn->subscr) |
| 921 | conn->subscr = subscr; |
| 922 | else if (conn->subscr == subscr) |
Sylvain Munaut | 7b9852c | 2009-12-18 18:28:10 +0100 | [diff] [blame] | 923 | subscr_put(subscr); /* lchan already has a ref, don't need another one */ |
| 924 | else { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 925 | DEBUGP(DMM, "<- CM Channel already owned by someone else?\n"); |
| 926 | subscr_put(subscr); |
| 927 | } |
| 928 | |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 929 | subscr->equipment.classmark2_len = classmark2_len; |
| 930 | memcpy(subscr->equipment.classmark2, classmark2, classmark2_len); |
| 931 | db_sync_equipment(&subscr->equipment); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 932 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 933 | return gsm48_secure_channel(conn, req->cipher_key_seq, |
Sylvain Munaut | badc711 | 2009-12-24 00:28:46 +0100 | [diff] [blame] | 934 | _gsm48_rx_mm_serv_req_sec_cb, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 935 | } |
| 936 | |
Holger Hans Peter Freyther | e9db44d | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 937 | static int gsm48_rx_mm_imsi_detach_ind(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 938 | { |
Holger Hans Peter Freyther | e9db44d | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 939 | struct gsm_bts *bts = conn->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 940 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 941 | struct gsm48_imsi_detach_ind *idi = |
| 942 | (struct gsm48_imsi_detach_ind *) gh->data; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 943 | uint8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 944 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 945 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 946 | |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 947 | gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len); |
Daniel Willmann | 2be30fe | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 948 | DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s)", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 949 | mi_type, mi_string); |
| 950 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 951 | osmo_counter_inc(bts->network->stats.loc_upd_type.detach); |
Harald Welte | 3edc5a9 | 2009-12-22 00:41:05 +0100 | [diff] [blame] | 952 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 953 | switch (mi_type) { |
| 954 | case GSM_MI_TYPE_TMSI: |
Daniel Willmann | 2be30fe | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 955 | DEBUGPC(DMM, "\n"); |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 956 | subscr = subscr_get_by_tmsi(bts->network, |
| 957 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 958 | break; |
| 959 | case GSM_MI_TYPE_IMSI: |
Daniel Willmann | 2be30fe | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 960 | DEBUGPC(DMM, "\n"); |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 961 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 962 | break; |
| 963 | case GSM_MI_TYPE_IMEI: |
| 964 | case GSM_MI_TYPE_IMEISV: |
| 965 | /* no sim card... FIXME: what to do ? */ |
Daniel Willmann | 2be30fe | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 966 | DEBUGPC(DMM, ": unimplemented mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 967 | break; |
| 968 | default: |
Daniel Willmann | 2be30fe | 2012-12-28 19:29:44 +0100 | [diff] [blame] | 969 | DEBUGPC(DMM, ": unknown mobile identity type\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 970 | break; |
| 971 | } |
| 972 | |
| 973 | if (subscr) { |
Holger Hans Peter Freyther | e9db44d | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 974 | subscr_update(subscr, bts, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 975 | GSM_SUBSCRIBER_UPDATE_DETACHED); |
Harald Welte | 0747c6a | 2009-12-24 14:50:24 +0100 | [diff] [blame] | 976 | DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr)); |
Harald Welte (local) | ced09ed | 2009-08-17 09:39:55 +0200 | [diff] [blame] | 977 | |
| 978 | subscr->equipment.classmark1 = idi->classmark1; |
| 979 | db_sync_equipment(&subscr->equipment); |
| 980 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 981 | subscr_put(subscr); |
| 982 | } else |
| 983 | DEBUGP(DMM, "Unknown Subscriber ?!?\n"); |
| 984 | |
Harald Welte | 43250dd | 2009-12-20 09:58:40 +0100 | [diff] [blame] | 985 | /* FIXME: iterate over all transactions and release them, |
| 986 | * imagine an IMSI DETACH happening during an active call! */ |
| 987 | |
Holger Hans Peter Freyther | e9db44d | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 988 | release_anchor(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
| 992 | static int gsm48_rx_mm_status(struct msgb *msg) |
| 993 | { |
| 994 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 995 | |
| 996 | DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]); |
| 997 | |
| 998 | return 0; |
| 999 | } |
| 1000 | |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1001 | /* Chapter 9.2.3: Authentication Response */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1002 | static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1003 | { |
| 1004 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1005 | struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data; |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 1006 | struct gsm_network *net = conn->bts->network; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1007 | |
Sylvain Munaut | 20d99c6 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1008 | DEBUGP(DMM, "MM AUTHENTICATION RESPONSE (sres = %s): ", |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 1009 | osmo_hexdump(ar->sres, 4)); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1010 | |
| 1011 | /* Safety check */ |
| 1012 | if (!conn->sec_operation) { |
| 1013 | DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n"); |
| 1014 | return -EIO; |
| 1015 | } |
| 1016 | |
| 1017 | /* Validate SRES */ |
| 1018 | if (memcmp(conn->sec_operation->atuple.sres, ar->sres,4)) { |
Holger Hans Peter Freyther | 8f35157 | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1019 | int rc; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1020 | gsm_cbfn *cb = conn->sec_operation->cb; |
Sylvain Munaut | 20d99c6 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1021 | |
| 1022 | DEBUGPC(DMM, "Invalid (expected %s)\n", |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 1023 | osmo_hexdump(conn->sec_operation->atuple.sres, 4)); |
Sylvain Munaut | 20d99c6 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1024 | |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1025 | if (cb) |
| 1026 | cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED, |
Holger Hans Peter Freyther | 9acd1b1 | 2010-06-16 12:47:59 +0800 | [diff] [blame] | 1027 | NULL, conn, conn->sec_operation->cb_data); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1028 | |
Holger Hans Peter Freyther | 8f35157 | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1029 | rc = gsm48_tx_mm_auth_rej(conn); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1030 | release_security_operation(conn); |
Holger Hans Peter Freyther | 8f35157 | 2010-12-27 10:57:56 +0100 | [diff] [blame] | 1031 | return rc; |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
Sylvain Munaut | 20d99c6 | 2010-06-10 23:51:41 +0200 | [diff] [blame] | 1034 | DEBUGPC(DMM, "OK\n"); |
| 1035 | |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1036 | /* Start ciphering */ |
Sylvain Munaut | 469c28f | 2010-11-29 08:19:04 +0100 | [diff] [blame] | 1037 | return gsm0808_cipher_mode(conn, net->a5_encryption, |
| 1038 | conn->sec_operation->atuple.kc, 8, 0); |
Sylvain Munaut | 28c4716 | 2009-12-24 00:27:26 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1041 | /* Receive a GSM 04.08 Mobility Management (MM) message */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1042 | static int gsm0408_rcv_mm(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1043 | { |
| 1044 | struct gsm48_hdr *gh = msgb_l3(msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1045 | int rc = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1046 | |
| 1047 | switch (gh->msg_type & 0xbf) { |
| 1048 | case GSM48_MT_MM_LOC_UPD_REQUEST: |
Harald Welte | 7963966 | 2009-06-27 02:58:43 +0200 | [diff] [blame] | 1049 | DEBUGP(DMM, "LOCATION UPDATING REQUEST: "); |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1050 | rc = mm_rx_loc_upd_req(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1051 | break; |
| 1052 | case GSM48_MT_MM_ID_RESP: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1053 | rc = mm_rx_id_resp(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1054 | break; |
| 1055 | case GSM48_MT_MM_CM_SERV_REQ: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1056 | rc = gsm48_rx_mm_serv_req(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1057 | break; |
| 1058 | case GSM48_MT_MM_STATUS: |
| 1059 | rc = gsm48_rx_mm_status(msg); |
| 1060 | break; |
| 1061 | case GSM48_MT_MM_TMSI_REALL_COMPL: |
| 1062 | DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n", |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1063 | conn->subscr ? |
| 1064 | subscr_name(conn->subscr) : |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1065 | "unknown subscriber"); |
Holger Hans Peter Freyther | f08a1d7 | 2010-12-22 12:11:01 +0100 | [diff] [blame] | 1066 | release_loc_updating_req(conn); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1067 | break; |
| 1068 | case GSM48_MT_MM_IMSI_DETACH_IND: |
Holger Hans Peter Freyther | e9db44d | 2012-07-10 08:53:27 +0200 | [diff] [blame] | 1069 | rc = gsm48_rx_mm_imsi_detach_ind(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1070 | break; |
| 1071 | case GSM48_MT_MM_CM_REEST_REQ: |
| 1072 | DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n"); |
| 1073 | break; |
| 1074 | case GSM48_MT_MM_AUTH_RESP: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1075 | rc = gsm48_rx_mm_auth_resp(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1076 | break; |
| 1077 | default: |
Harald Welte | 60e5f4f | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 1078 | LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1079 | gh->msg_type); |
| 1080 | break; |
| 1081 | } |
| 1082 | |
| 1083 | return rc; |
| 1084 | } |
| 1085 | |
| 1086 | /* Receive a PAGING RESPONSE message from the MS */ |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1087 | static int gsm48_rx_rr_pag_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1088 | { |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1089 | struct gsm_bts *bts = conn->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1090 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | a943b2a | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1091 | struct gsm48_pag_resp *resp; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1092 | uint8_t *classmark2_lv = gh->data + 1; |
| 1093 | uint8_t mi_type; |
Holger Hans Peter Freyther | 1e6ef9f | 2009-08-19 07:54:59 +0200 | [diff] [blame] | 1094 | char mi_string[GSM48_MI_SIZE]; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1095 | struct gsm_subscriber *subscr = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1096 | int rc = 0; |
| 1097 | |
Holger Hans Peter Freyther | a943b2a | 2010-05-16 01:51:14 +0800 | [diff] [blame] | 1098 | resp = (struct gsm48_pag_resp *) &gh->data[0]; |
| 1099 | gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh), |
| 1100 | mi_string, &mi_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1101 | DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n", |
| 1102 | mi_type, mi_string); |
Harald Welte | 583ceaf | 2009-08-10 10:12:45 +0200 | [diff] [blame] | 1103 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1104 | switch (mi_type) { |
| 1105 | case GSM_MI_TYPE_TMSI: |
Holger Hans Peter Freyther | cd8bacf | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 1106 | subscr = subscr_get_by_tmsi(bts->network, |
| 1107 | tmsi_from_string(mi_string)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1108 | break; |
| 1109 | case GSM_MI_TYPE_IMSI: |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 1110 | subscr = subscr_get_by_imsi(bts->network, mi_string); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | if (!subscr) { |
| 1115 | DEBUGP(DRR, "<- Can't find any subscriber for this ID\n"); |
| 1116 | /* FIXME: request id? close channel? */ |
| 1117 | return -EINVAL; |
| 1118 | } |
| 1119 | DEBUGP(DRR, "<- Channel was requested by %s\n", |
Harald Welte | 68b7df2 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1120 | subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1121 | |
Harald Welte | f6845a7 | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 1122 | subscr->equipment.classmark2_len = *classmark2_lv; |
| 1123 | memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv); |
| 1124 | db_sync_equipment(&subscr->equipment); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1125 | |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1126 | rc = gsm48_handle_paging_resp(conn, msg, subscr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1127 | return rc; |
| 1128 | } |
| 1129 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1130 | static int gsm48_rx_rr_app_info(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1131 | { |
| 1132 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1133 | uint8_t apdu_id_flags; |
| 1134 | uint8_t apdu_len; |
| 1135 | uint8_t *apdu_data; |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1136 | |
| 1137 | apdu_id_flags = gh->data[0]; |
| 1138 | apdu_len = gh->data[1]; |
| 1139 | apdu_data = gh->data+2; |
| 1140 | |
Harald Welte | d4f2166 | 2012-07-16 13:22:19 +0200 | [diff] [blame] | 1141 | DEBUGP(DRR, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s", |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 1142 | apdu_id_flags, apdu_len, osmo_hexdump(apdu_data, apdu_len)); |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1143 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1144 | return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data); |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1147 | /* Receive a GSM 04.08 Radio Resource (RR) message */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1148 | static int gsm0408_rcv_rr(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1149 | { |
| 1150 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1151 | int rc = 0; |
| 1152 | |
| 1153 | switch (gh->msg_type) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1154 | case GSM48_MT_RR_PAG_RESP: |
Holger Hans Peter Freyther | 0b83e54 | 2010-06-21 10:46:44 +0800 | [diff] [blame] | 1155 | rc = gsm48_rx_rr_pag_resp(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1156 | break; |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1157 | case GSM48_MT_RR_APP_INFO: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 1158 | rc = gsm48_rx_rr_app_info(conn, msg); |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1159 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1160 | default: |
Harald Welte | fe01ed7 | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 1161 | LOGP(DRR, LOGL_NOTICE, "MSC: Unimplemented " |
Harald Welte | 60e5f4f | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 1162 | "GSM 04.08 RR msg type 0x%02x\n", gh->msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | |
| 1166 | return rc; |
| 1167 | } |
| 1168 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1169 | int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, uint8_t apdu_id, |
| 1170 | uint8_t apdu_len, const uint8_t *apdu) |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1171 | { |
| 1172 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1173 | struct gsm48_hdr *gh; |
| 1174 | |
Holger Hans Peter Freyther | 92f1b2d | 2010-06-16 13:52:55 +0800 | [diff] [blame] | 1175 | msg->lchan = conn->lchan; |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1176 | |
| 1177 | DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n", |
| 1178 | apdu_id, apdu_len); |
| 1179 | |
| 1180 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len); |
| 1181 | gh->proto_discr = GSM48_PDISC_RR; |
| 1182 | gh->msg_type = GSM48_MT_RR_APP_INFO; |
| 1183 | gh->data[0] = apdu_id; |
| 1184 | gh->data[1] = apdu_len; |
| 1185 | memcpy(gh->data+2, apdu, apdu_len); |
| 1186 | |
Holger Hans Peter Freyther | 92f1b2d | 2010-06-16 13:52:55 +0800 | [diff] [blame] | 1187 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte (local) | b510392 | 2009-08-15 23:32:44 +0200 | [diff] [blame] | 1188 | } |
| 1189 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1190 | /* Call Control */ |
| 1191 | |
| 1192 | /* The entire call control code is written in accordance with Figure 7.10c |
| 1193 | * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE |
| 1194 | * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY |
| 1195 | * it for voice */ |
| 1196 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1197 | static void new_cc_state(struct gsm_trans *trans, int state) |
| 1198 | { |
| 1199 | if (state > 31 || state < 0) |
| 1200 | return; |
| 1201 | |
| 1202 | DEBUGP(DCC, "new state %s -> %s\n", |
Harald Welte | b30935e | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 1203 | gsm48_cc_state_name(trans->cc.state), |
| 1204 | gsm48_cc_state_name(state)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1205 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1206 | trans->cc.state = state; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1210 | { |
| 1211 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1212 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1213 | uint8_t *cause, *call_state; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1214 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1215 | gh->msg_type = GSM48_MT_CC_STATUS; |
| 1216 | |
| 1217 | cause = msgb_put(msg, 3); |
| 1218 | cause[0] = 2; |
| 1219 | cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER; |
| 1220 | cause[2] = 0x80 | 30; /* response to status inquiry */ |
| 1221 | |
| 1222 | call_state = msgb_put(msg, 1); |
| 1223 | call_state[0] = 0xc0 | 0x00; |
| 1224 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1225 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1226 | } |
| 1227 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1228 | static int gsm48_tx_simple(struct gsm_subscriber_connection *conn, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1229 | uint8_t pdisc, uint8_t msg_type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1230 | { |
| 1231 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1232 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1233 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1234 | msg->lchan = conn->lchan; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1235 | |
| 1236 | gh->proto_discr = pdisc; |
| 1237 | gh->msg_type = msg_type; |
| 1238 | |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 1239 | return gsm48_conn_sendmsg(msg, conn, NULL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1242 | static void gsm48_stop_cc_timer(struct gsm_trans *trans) |
| 1243 | { |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1244 | if (osmo_timer_pending(&trans->cc.timer)) { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1245 | DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent); |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1246 | osmo_timer_del(&trans->cc.timer); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1247 | trans->cc.Tcurrent = 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1248 | } |
| 1249 | } |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1250 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1251 | static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans, |
| 1252 | int msg_type, struct gsm_mncc *mncc) |
| 1253 | { |
| 1254 | struct msgb *msg; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1255 | unsigned char *data; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1256 | |
| 1257 | if (trans) |
Harald Welte | c51b192 | 2010-12-26 19:06:37 +0100 | [diff] [blame] | 1258 | if (trans->conn && trans->conn->lchan) |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 1259 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1260 | "Sending '%s' to MNCC.\n", |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1261 | trans->conn->lchan->ts->trx->bts->nr, |
| 1262 | trans->conn->lchan->ts->trx->nr, |
| 1263 | trans->conn->lchan->ts->nr, trans->transaction_id, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1264 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1265 | get_mncc_name(msg_type)); |
| 1266 | else |
| 1267 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 1268 | "Sending '%s' to MNCC.\n", |
| 1269 | (trans->subscr)?(trans->subscr->extension):"-", |
| 1270 | get_mncc_name(msg_type)); |
| 1271 | else |
| 1272 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) " |
| 1273 | "Sending '%s' to MNCC.\n", get_mncc_name(msg_type)); |
| 1274 | |
| 1275 | mncc->msg_type = msg_type; |
| 1276 | |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 1277 | msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC"); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1278 | if (!msg) |
| 1279 | return -ENOMEM; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 1280 | |
| 1281 | data = msgb_put(msg, sizeof(struct gsm_mncc)); |
| 1282 | memcpy(data, mncc, sizeof(struct gsm_mncc)); |
| 1283 | |
Harald Welte | be0cb68 | 2010-12-22 23:43:29 +0100 | [diff] [blame] | 1284 | cc_tx_to_mncc(net, msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1290 | uint32_t callref, int location, int value) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1291 | { |
| 1292 | struct gsm_mncc rel; |
| 1293 | |
Harald Welte | cb0595f | 2009-06-12 01:54:08 +0800 | [diff] [blame] | 1294 | memset(&rel, 0, sizeof(rel)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1295 | rel.callref = callref; |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1296 | mncc_set_cause(&rel, location, value); |
Andreas Eversberg | 59e79ee | 2013-01-25 08:38:29 +0100 | [diff] [blame] | 1297 | if (trans && trans->cc.state == GSM_CSTATE_RELEASE_REQ) |
| 1298 | return mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1299 | return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 1300 | } |
| 1301 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1302 | /* Call Control Specific transaction release. |
| 1303 | * gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 1304 | void _gsm48_cc_trans_free(struct gsm_trans *trans) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1305 | { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1306 | gsm48_stop_cc_timer(trans); |
| 1307 | |
| 1308 | /* send release to L4, if callref still exists */ |
| 1309 | if (trans->callref) { |
| 1310 | /* Ressource unavailable */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1311 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1312 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1313 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1314 | } |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1315 | if (trans->cc.state != GSM_CSTATE_NULL) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1316 | new_cc_state(trans, GSM_CSTATE_NULL); |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1317 | if (trans->conn) |
| 1318 | trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg); |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1322 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1323 | /* call-back from paging the B-end of the connection */ |
| 1324 | static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event, |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1325 | struct msgb *msg, void *_conn, void *param) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1326 | { |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1327 | int found = 0; |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1328 | struct gsm_subscriber_connection *conn = _conn; |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1329 | struct gsm_network **paging_request = param, *net; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1330 | struct gsm_trans *transt, *tmp; |
Harald Welte | 1ff81b5 | 2009-06-26 20:17:06 +0200 | [diff] [blame] | 1331 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1332 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 1333 | return -EINVAL; |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1334 | |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1335 | net = *paging_request; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1336 | if (!net) { |
| 1337 | DEBUGP(DCC, "Error Network not set!\n"); |
| 1338 | return -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1341 | /* check all tranactions (without lchan) for subscriber */ |
| 1342 | llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) { |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1343 | if (transt->paging_request != paging_request || transt->conn) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1344 | continue; |
| 1345 | switch (event) { |
| 1346 | case GSM_PAGING_SUCCEEDED: |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1347 | if (!conn) // paranoid |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1348 | break; |
| 1349 | DEBUGP(DCC, "Paging subscr %s succeeded!\n", |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1350 | transt->subscr->extension); |
| 1351 | found = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1352 | /* Assign lchan */ |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1353 | if (!transt->conn) { |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1354 | transt->paging_request = NULL; |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 1355 | transt->conn = conn; |
Holger Hans Peter Freyther | fb68bf3 | 2010-12-29 16:28:33 +0100 | [diff] [blame] | 1356 | conn->put_channel = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1357 | } |
| 1358 | /* send SETUP request to called party */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1359 | gsm48_cc_tx_setup(transt, &transt->cc.msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1360 | break; |
| 1361 | case GSM_PAGING_EXPIRED: |
Holger Hans Peter Freyther | ab2a933 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 1362 | case GSM_PAGING_BUSY: |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1363 | DEBUGP(DCC, "Paging subscr %s expired!\n", |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1364 | transt->subscr->extension); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1365 | /* Temporarily out of order */ |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1366 | found = 1; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1367 | mncc_release_ind(transt->subscr->net, transt, |
| 1368 | transt->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1369 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1370 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1371 | transt->callref = 0; |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1372 | transt->paging_request = NULL; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1373 | trans_free(transt); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | } |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 1377 | |
| 1378 | talloc_free(paging_request); |
| 1379 | |
| 1380 | /* |
| 1381 | * FIXME: The queue needs to be kicked. This is likely to go through a RF |
| 1382 | * failure and then the subscr will be poke again. This needs a lot of fixing |
| 1383 | * in the subscriber queue code. |
| 1384 | */ |
| 1385 | if (!found && conn) |
| 1386 | conn->put_channel = 1; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1387 | return 0; |
| 1388 | } |
| 1389 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1390 | static int tch_recv_mncc(struct gsm_network *net, uint32_t callref, int enable); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1391 | |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1392 | /* handle audio path for handover */ |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1393 | static int switch_for_handover(struct gsm_lchan *old_lchan, |
| 1394 | struct gsm_lchan *new_lchan) |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1395 | { |
| 1396 | struct rtp_socket *old_rs, *new_rs, *other_rs; |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1397 | |
| 1398 | if (ipacc_rtp_direct) { |
| 1399 | LOGP(DHO, LOGL_ERROR, "unable to handover in direct RTP mode\n"); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | /* RTP Proxy mode */ |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1404 | new_rs = new_lchan->abis_ip.rtp_socket; |
| 1405 | old_rs = old_lchan->abis_ip.rtp_socket; |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1406 | |
| 1407 | if (!new_rs) { |
| 1408 | LOGP(DHO, LOGL_ERROR, "no RTP socket for new_lchan\n"); |
| 1409 | return -EIO; |
| 1410 | } |
| 1411 | |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1412 | rsl_ipacc_mdcx_to_rtpsock(new_lchan); |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1413 | |
| 1414 | if (!old_rs) { |
| 1415 | LOGP(DHO, LOGL_ERROR, "no RTP socket for old_lchan\n"); |
| 1416 | return -EIO; |
| 1417 | } |
| 1418 | |
| 1419 | /* copy rx_action and reference to other sock */ |
| 1420 | new_rs->rx_action = old_rs->rx_action; |
| 1421 | new_rs->tx_action = old_rs->tx_action; |
| 1422 | new_rs->transmit = old_rs->transmit; |
| 1423 | |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1424 | switch (old_lchan->abis_ip.rtp_socket->rx_action) { |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1425 | case RTP_PROXY: |
| 1426 | other_rs = old_rs->proxy.other_sock; |
| 1427 | rtp_socket_proxy(new_rs, other_rs); |
| 1428 | /* delete reference to other end socket to prevent |
| 1429 | * rtp_socket_free() from removing the inverse reference */ |
| 1430 | old_rs->proxy.other_sock = NULL; |
| 1431 | break; |
| 1432 | case RTP_RECV_UPSTREAM: |
| 1433 | new_rs->receive = old_rs->receive; |
| 1434 | break; |
| 1435 | case RTP_NONE: |
| 1436 | break; |
| 1437 | } |
| 1438 | |
| 1439 | return 0; |
| 1440 | } |
| 1441 | |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1442 | /* some other part of the code sends us a signal */ |
| 1443 | static int handle_abisip_signal(unsigned int subsys, unsigned int signal, |
| 1444 | void *handler_data, void *signal_data) |
| 1445 | { |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1446 | struct gsm_lchan *lchan = signal_data, *old_lchan; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1447 | int rc; |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1448 | struct gsm_network *net; |
| 1449 | struct gsm_trans *trans; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1450 | |
| 1451 | if (subsys != SS_ABISIP) |
| 1452 | return 0; |
| 1453 | |
| 1454 | /* in case we use direct BTS-to-BTS RTP */ |
| 1455 | if (ipacc_rtp_direct) |
| 1456 | return 0; |
| 1457 | |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1458 | switch (signal) { |
Holger Hans Peter Freyther | 5ea7ea6 | 2009-11-18 21:06:12 +0100 | [diff] [blame] | 1459 | case S_ABISIP_CRCX_ACK: |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1460 | /* in case we don't use direct BTS-to-BTS RTP */ |
| 1461 | /* the BTS has successfully bound a TCH to a local ip/port, |
| 1462 | * which means we can connect our UDP socket to it */ |
| 1463 | if (lchan->abis_ip.rtp_socket) { |
| 1464 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1465 | lchan->abis_ip.rtp_socket = NULL; |
| 1466 | } |
| 1467 | |
| 1468 | lchan->abis_ip.rtp_socket = rtp_socket_create(); |
| 1469 | if (!lchan->abis_ip.rtp_socket) |
| 1470 | return -EIO; |
| 1471 | |
| 1472 | rc = rtp_socket_connect(lchan->abis_ip.rtp_socket, |
| 1473 | lchan->abis_ip.bound_ip, |
| 1474 | lchan->abis_ip.bound_port); |
| 1475 | if (rc < 0) |
| 1476 | return -EIO; |
| 1477 | |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1478 | /* check if any transactions on this lchan still have |
| 1479 | * a tch_recv_mncc request pending */ |
| 1480 | net = lchan->ts->trx->bts->network; |
| 1481 | llist_for_each_entry(trans, &net->trans_list, entry) { |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1482 | if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) { |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1483 | DEBUGP(DCC, "pending tch_recv_mncc request\n"); |
| 1484 | tch_recv_mncc(net, trans->callref, 1); |
| 1485 | } |
| 1486 | } |
Holger Hans Peter Freyther | c3649d2 | 2012-12-26 10:17:42 +0100 | [diff] [blame] | 1487 | |
| 1488 | /* |
| 1489 | * TODO: this appears to be too early? Why not until after |
| 1490 | * the handover detect or the handover complete? |
| 1491 | * |
| 1492 | * Do we have a handover pending for this new lchan? In that |
| 1493 | * case re-route the audio from the old channel to the new one. |
| 1494 | */ |
| 1495 | old_lchan = bsc_handover_pending(lchan); |
| 1496 | if (old_lchan) |
| 1497 | switch_for_handover(old_lchan, lchan); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1498 | break; |
Holger Hans Peter Freyther | 02fca86 | 2011-01-06 13:31:41 +0100 | [diff] [blame] | 1499 | case S_ABISIP_DLCX_IND: |
| 1500 | /* the BTS tells us a RTP stream has been disconnected */ |
| 1501 | if (lchan->abis_ip.rtp_socket) { |
| 1502 | rtp_socket_free(lchan->abis_ip.rtp_socket); |
| 1503 | lchan->abis_ip.rtp_socket = NULL; |
| 1504 | } |
| 1505 | |
| 1506 | break; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | return 0; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1510 | } |
| 1511 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1512 | /* map two ipaccess RTP streams onto each other */ |
| 1513 | static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan) |
| 1514 | { |
| 1515 | struct gsm_bts *bts = lchan->ts->trx->bts; |
| 1516 | struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1517 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1518 | |
| 1519 | DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n", |
| 1520 | bts->nr, lchan->ts->trx->nr, lchan->ts->nr, |
| 1521 | remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr); |
| 1522 | |
| 1523 | if (bts->type != remote_bts->type) { |
Harald Welte | 8099a71 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1524 | LOGP(DCC, LOGL_ERROR, "Cannot switch calls between different BTS types yet\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1525 | return -EINVAL; |
| 1526 | } |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1527 | |
| 1528 | // todo: map between different bts types |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1529 | switch (bts->type) { |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 1530 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 1531 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1532 | if (!ipacc_rtp_direct) { |
| 1533 | /* connect the TCH's to our RTP proxy */ |
Harald Welte | 9947d9f | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1534 | rc = rsl_ipacc_mdcx_to_rtpsock(lchan); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1535 | if (rc < 0) |
| 1536 | return rc; |
Harald Welte | 9947d9f | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1537 | rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan); |
Harald Welte | 30f93fb | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 1538 | if (rc < 0) |
| 1539 | return rc; |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1540 | /* connect them with each other */ |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1541 | rtp_socket_proxy(lchan->abis_ip.rtp_socket, |
| 1542 | remote_lchan->abis_ip.rtp_socket); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1543 | } else { |
| 1544 | /* directly connect TCH RTP streams to each other */ |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1545 | rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip, |
| 1546 | remote_lchan->abis_ip.bound_port, |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1547 | remote_lchan->abis_ip.rtp_payload2); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1548 | if (rc < 0) |
| 1549 | return rc; |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1550 | rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip, |
| 1551 | lchan->abis_ip.bound_port, |
Harald Welte | 8750421 | 2009-12-02 01:56:49 +0530 | [diff] [blame] | 1552 | lchan->abis_ip.rtp_payload2); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 1553 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1554 | break; |
| 1555 | case GSM_BTS_TYPE_BS11: |
Harald Welte | f39e3b5 | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 1556 | case GSM_BTS_TYPE_RBS2000: |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 1557 | case GSM_BTS_TYPE_NOKIA_SITE: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1558 | trau_mux_map_lchan(lchan, remote_lchan); |
| 1559 | break; |
| 1560 | default: |
Harald Welte | 8099a71 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1561 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1562 | return -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1568 | /* bridge channels of two transactions */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1569 | static int tch_bridge(struct gsm_network *net, uint32_t *refs) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1570 | { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1571 | struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]); |
| 1572 | struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1573 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1574 | if (!trans1 || !trans2) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1575 | return -EIO; |
| 1576 | |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1577 | if (!trans1->conn || !trans2->conn) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1578 | return -EIO; |
| 1579 | |
| 1580 | /* through-connect channel */ |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1581 | return tch_map(trans1->conn->lchan, trans2->conn->lchan); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1584 | /* enable receive of channels to MNCC upqueue */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1585 | static int tch_recv_mncc(struct gsm_network *net, uint32_t callref, int enable) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1586 | { |
| 1587 | struct gsm_trans *trans; |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1588 | struct gsm_lchan *lchan; |
| 1589 | struct gsm_bts *bts; |
| 1590 | int rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1591 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1592 | /* Find callref */ |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1593 | trans = trans_find_by_callref(net, callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1594 | if (!trans) |
| 1595 | return -EIO; |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1596 | if (!trans->conn) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1597 | return 0; |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 1598 | lchan = trans->conn->lchan; |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1599 | bts = lchan->ts->trx->bts; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1600 | |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1601 | switch (bts->type) { |
| 1602 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 1603 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1604 | if (ipacc_rtp_direct) { |
Harald Welte | 8099a71 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1605 | LOGP(DCC, LOGL_ERROR, "Error: RTP proxy is disabled\n"); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1606 | return -EINVAL; |
| 1607 | } |
| 1608 | /* in case, we don't have a RTP socket yet, we note this |
| 1609 | * in the transaction and try later */ |
| 1610 | if (!lchan->abis_ip.rtp_socket) { |
| 1611 | trans->tch_recv = enable; |
| 1612 | DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable); |
| 1613 | return 0; |
| 1614 | } |
| 1615 | if (enable) { |
| 1616 | /* connect the TCH's to our RTP proxy */ |
Harald Welte | 9947d9f | 2009-12-20 16:51:09 +0100 | [diff] [blame] | 1617 | rc = rsl_ipacc_mdcx_to_rtpsock(lchan); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1618 | if (rc < 0) |
| 1619 | return rc; |
| 1620 | /* assign socket to application interface */ |
| 1621 | rtp_socket_upstream(lchan->abis_ip.rtp_socket, |
| 1622 | net, callref); |
| 1623 | } else |
| 1624 | rtp_socket_upstream(lchan->abis_ip.rtp_socket, |
| 1625 | net, 0); |
| 1626 | break; |
| 1627 | case GSM_BTS_TYPE_BS11: |
Harald Welte | f39e3b5 | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 1628 | case GSM_BTS_TYPE_RBS2000: |
Harald Welte | c0cf002 | 2011-08-05 20:11:18 +0200 | [diff] [blame] | 1629 | case GSM_BTS_TYPE_NOKIA_SITE: |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1630 | if (enable) |
| 1631 | return trau_recv_lchan(lchan, callref); |
| 1632 | return trau_mux_unmap(NULL, callref); |
| 1633 | break; |
| 1634 | default: |
Harald Welte | 8099a71 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 1635 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 1636 | return -EINVAL; |
| 1637 | } |
| 1638 | |
| 1639 | return 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1642 | static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg) |
| 1643 | { |
| 1644 | DEBUGP(DCC, "-> STATUS ENQ\n"); |
| 1645 | return gsm48_cc_tx_status(trans, msg); |
| 1646 | } |
| 1647 | |
| 1648 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg); |
| 1649 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg); |
| 1650 | |
| 1651 | static void gsm48_cc_timeout(void *arg) |
| 1652 | { |
| 1653 | struct gsm_trans *trans = arg; |
| 1654 | int disconnect = 0, release = 0; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1655 | int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER; |
| 1656 | int mo_location = GSM48_CAUSE_LOC_USER; |
| 1657 | int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC; |
| 1658 | int l4_location = GSM48_CAUSE_LOC_PRN_S_LU; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1659 | struct gsm_mncc mo_rel, l4_rel; |
| 1660 | |
| 1661 | memset(&mo_rel, 0, sizeof(struct gsm_mncc)); |
| 1662 | mo_rel.callref = trans->callref; |
| 1663 | memset(&l4_rel, 0, sizeof(struct gsm_mncc)); |
| 1664 | l4_rel.callref = trans->callref; |
| 1665 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1666 | switch(trans->cc.Tcurrent) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1667 | case 0x303: |
| 1668 | release = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1669 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1670 | break; |
| 1671 | case 0x310: |
| 1672 | disconnect = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1673 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1674 | break; |
| 1675 | case 0x313: |
| 1676 | disconnect = 1; |
| 1677 | /* unknown, did not find it in the specs */ |
| 1678 | break; |
| 1679 | case 0x301: |
| 1680 | disconnect = 1; |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 1681 | l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1682 | break; |
| 1683 | case 0x308: |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1684 | if (!trans->cc.T308_second) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1685 | /* restart T308 a second time */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1686 | gsm48_cc_tx_release(trans, &trans->cc.msg); |
| 1687 | trans->cc.T308_second = 1; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1688 | break; /* stay in release state */ |
| 1689 | } |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1690 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1691 | return; |
| 1692 | // release = 1; |
| 1693 | // l4_cause = 14; |
| 1694 | // break; |
| 1695 | case 0x306: |
| 1696 | release = 1; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1697 | mo_cause = trans->cc.msg.cause.value; |
| 1698 | mo_location = trans->cc.msg.cause.location; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1699 | break; |
| 1700 | case 0x323: |
| 1701 | disconnect = 1; |
| 1702 | break; |
| 1703 | default: |
| 1704 | release = 1; |
| 1705 | } |
| 1706 | |
| 1707 | if (release && trans->callref) { |
| 1708 | /* process release towards layer 4 */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1709 | mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1710 | l4_location, l4_cause); |
| 1711 | trans->callref = 0; |
| 1712 | } |
| 1713 | |
| 1714 | if (disconnect && trans->callref) { |
| 1715 | /* process disconnect towards layer 4 */ |
| 1716 | mncc_set_cause(&l4_rel, l4_location, l4_cause); |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1717 | mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | /* process disconnect towards mobile station */ |
| 1721 | if (disconnect || release) { |
| 1722 | mncc_set_cause(&mo_rel, mo_location, mo_cause); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1723 | mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0'; |
| 1724 | mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0'; |
| 1725 | mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0'; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1726 | mo_rel.cause.diag_len = 3; |
| 1727 | |
| 1728 | if (disconnect) |
| 1729 | gsm48_cc_tx_disconnect(trans, &mo_rel); |
| 1730 | if (release) |
| 1731 | gsm48_cc_tx_release(trans, &mo_rel); |
| 1732 | } |
| 1733 | |
| 1734 | } |
| 1735 | |
| 1736 | static void gsm48_start_cc_timer(struct gsm_trans *trans, int current, |
| 1737 | int sec, int micro) |
| 1738 | { |
| 1739 | DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1740 | trans->cc.timer.cb = gsm48_cc_timeout; |
| 1741 | trans->cc.timer.data = trans; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 1742 | osmo_timer_schedule(&trans->cc.timer, sec, micro); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1743 | trans->cc.Tcurrent = current; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg) |
| 1747 | { |
| 1748 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1749 | uint8_t msg_type = gh->msg_type & 0xbf; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1750 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1751 | struct tlv_parsed tp; |
| 1752 | struct gsm_mncc setup; |
| 1753 | |
| 1754 | memset(&setup, 0, sizeof(struct gsm_mncc)); |
| 1755 | setup.callref = trans->callref; |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 1756 | if (trans->conn && trans->conn->lchan) |
| 1757 | setup.lchan_type = trans->conn->lchan->type; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1758 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1759 | /* emergency setup is identified by msg_type */ |
| 1760 | if (msg_type == GSM48_MT_CC_EMERG_SETUP) |
| 1761 | setup.emergency = 1; |
| 1762 | |
| 1763 | /* use subscriber as calling party number */ |
Holger Hans Peter Freyther | ac009e5 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 1764 | setup.fields |= MNCC_F_CALLING; |
| 1765 | strncpy(setup.calling.number, trans->subscr->extension, |
| 1766 | sizeof(setup.calling.number)-1); |
| 1767 | strncpy(setup.imsi, trans->subscr->imsi, |
| 1768 | sizeof(setup.imsi)-1); |
| 1769 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1770 | /* bearer capability */ |
| 1771 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1772 | setup.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1773 | gsm48_decode_bearer_cap(&setup.bearer_cap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1774 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1775 | } |
| 1776 | /* facility */ |
| 1777 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1778 | setup.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1779 | gsm48_decode_facility(&setup.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1780 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1781 | } |
| 1782 | /* called party bcd number */ |
| 1783 | if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) { |
| 1784 | setup.fields |= MNCC_F_CALLED; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1785 | gsm48_decode_called(&setup.called, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1786 | TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1); |
| 1787 | } |
| 1788 | /* user-user */ |
| 1789 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 1790 | setup.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1791 | gsm48_decode_useruser(&setup.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1792 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 1793 | } |
| 1794 | /* ss-version */ |
| 1795 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1796 | setup.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1797 | gsm48_decode_ssversion(&setup.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1798 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 1799 | } |
| 1800 | /* CLIR suppression */ |
| 1801 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP)) |
| 1802 | setup.clir.sup = 1; |
| 1803 | /* CLIR invocation */ |
| 1804 | if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC)) |
| 1805 | setup.clir.inv = 1; |
| 1806 | /* cc cap */ |
| 1807 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 1808 | setup.fields |= MNCC_F_CCCAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1809 | gsm48_decode_cccap(&setup.cccap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1810 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 1811 | } |
| 1812 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1813 | new_cc_state(trans, GSM_CSTATE_INITIATED); |
| 1814 | |
Harald Welte (local) | 5b722d4 | 2009-12-26 19:45:03 +0100 | [diff] [blame] | 1815 | LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n", |
| 1816 | subscr_name(trans->subscr), trans->subscr->extension, |
| 1817 | setup.called.number); |
| 1818 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 1819 | osmo_counter_inc(trans->subscr->net->stats.call.mo_setup); |
Harald Welte | c56006b | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 1820 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1821 | /* indicate setup to MNCC */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1822 | mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1823 | |
Harald Welte | ca745e2 | 2009-07-29 12:10:35 +0200 | [diff] [blame] | 1824 | /* MNCC code will modify the channel asynchronously, we should |
| 1825 | * ipaccess-bind only after the modification has been made to the |
| 1826 | * lchan->tch_mode */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1831 | { |
| 1832 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1833 | struct gsm48_hdr *gh; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1834 | struct gsm_mncc *setup = arg; |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1835 | int rc, trans_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1836 | |
| 1837 | gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1838 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1839 | /* transaction id must not be assigned */ |
| 1840 | if (trans->transaction_id != 0xff) { /* unasssigned */ |
| 1841 | DEBUGP(DCC, "TX Setup with assigned transaction. " |
| 1842 | "This is not allowed!\n"); |
| 1843 | /* Temporarily out of order */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1844 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1845 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1846 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1847 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1848 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1849 | return rc; |
| 1850 | } |
| 1851 | |
| 1852 | /* Get free transaction_id */ |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1853 | trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0); |
| 1854 | if (trans_id < 0) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1855 | /* no free transaction ID */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1856 | rc = mncc_release_ind(trans->subscr->net, trans, trans->callref, |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 1857 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 1858 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1859 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 1860 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1861 | return rc; |
| 1862 | } |
Harald Welte | 165fc33 | 2009-07-23 21:36:44 +0200 | [diff] [blame] | 1863 | trans->transaction_id = trans_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1864 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1865 | gh->msg_type = GSM48_MT_CC_SETUP; |
| 1866 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1867 | gsm48_start_cc_timer(trans, 0x303, GSM48_T303); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1868 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1869 | /* bearer capability */ |
| 1870 | if (setup->fields & MNCC_F_BEARER_CAP) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1871 | gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1872 | /* facility */ |
| 1873 | if (setup->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1874 | gsm48_encode_facility(msg, 0, &setup->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1875 | /* progress */ |
| 1876 | if (setup->fields & MNCC_F_PROGRESS) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1877 | gsm48_encode_progress(msg, 0, &setup->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1878 | /* calling party BCD number */ |
| 1879 | if (setup->fields & MNCC_F_CALLING) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1880 | gsm48_encode_calling(msg, &setup->calling); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1881 | /* called party BCD number */ |
| 1882 | if (setup->fields & MNCC_F_CALLED) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1883 | gsm48_encode_called(msg, &setup->called); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1884 | /* user-user */ |
| 1885 | if (setup->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1886 | gsm48_encode_useruser(msg, 0, &setup->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1887 | /* redirecting party BCD number */ |
| 1888 | if (setup->fields & MNCC_F_REDIRECTING) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1889 | gsm48_encode_redirecting(msg, &setup->redirecting); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1890 | /* signal */ |
| 1891 | if (setup->fields & MNCC_F_SIGNAL) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1892 | gsm48_encode_signal(msg, setup->signal); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1893 | |
| 1894 | new_cc_state(trans, GSM_CSTATE_CALL_PRESENT); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1895 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 1896 | osmo_counter_inc(trans->subscr->net->stats.call.mt_setup); |
Harald Welte | c56006b | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 1897 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1898 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1899 | } |
| 1900 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1901 | static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg) |
| 1902 | { |
| 1903 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1904 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1905 | struct tlv_parsed tp; |
| 1906 | struct gsm_mncc call_conf; |
| 1907 | |
| 1908 | gsm48_stop_cc_timer(trans); |
| 1909 | gsm48_start_cc_timer(trans, 0x310, GSM48_T310); |
| 1910 | |
| 1911 | memset(&call_conf, 0, sizeof(struct gsm_mncc)); |
| 1912 | call_conf.callref = trans->callref; |
Harald Welte | 1ed89d4 | 2011-09-01 18:18:43 +0200 | [diff] [blame] | 1913 | if (trans->conn && trans->conn->lchan) |
| 1914 | call_conf.lchan_type = trans->conn->lchan->type; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1915 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1916 | #if 0 |
| 1917 | /* repeat */ |
| 1918 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR)) |
| 1919 | call_conf.repeat = 1; |
| 1920 | if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ)) |
| 1921 | call_conf.repeat = 2; |
| 1922 | #endif |
| 1923 | /* bearer capability */ |
| 1924 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 1925 | call_conf.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1926 | gsm48_decode_bearer_cap(&call_conf.bearer_cap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1927 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 1928 | } |
| 1929 | /* cause */ |
| 1930 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 1931 | call_conf.fields |= MNCC_F_CAUSE; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1932 | gsm48_decode_cause(&call_conf.cause, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1933 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 1934 | } |
| 1935 | /* cc cap */ |
| 1936 | if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) { |
| 1937 | call_conf.fields |= MNCC_F_CCCAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1938 | gsm48_decode_cccap(&call_conf.cccap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1939 | TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1); |
| 1940 | } |
| 1941 | |
| 1942 | new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF); |
| 1943 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 1944 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND, |
| 1945 | &call_conf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg) |
| 1949 | { |
| 1950 | struct gsm_mncc *proceeding = arg; |
| 1951 | struct msgb *msg = gsm48_msgb_alloc(); |
| 1952 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 1953 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1954 | gh->msg_type = GSM48_MT_CC_CALL_PROC; |
| 1955 | |
| 1956 | new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC); |
| 1957 | |
| 1958 | /* bearer capability */ |
| 1959 | if (proceeding->fields & MNCC_F_BEARER_CAP) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1960 | gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1961 | /* facility */ |
| 1962 | if (proceeding->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1963 | gsm48_encode_facility(msg, 0, &proceeding->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1964 | /* progress */ |
| 1965 | if (proceeding->fields & MNCC_F_PROGRESS) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1966 | gsm48_encode_progress(msg, 0, &proceeding->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1967 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 1968 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg) |
| 1972 | { |
| 1973 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 1974 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 1975 | struct tlv_parsed tp; |
| 1976 | struct gsm_mncc alerting; |
| 1977 | |
| 1978 | gsm48_stop_cc_timer(trans); |
| 1979 | gsm48_start_cc_timer(trans, 0x301, GSM48_T301); |
| 1980 | |
| 1981 | memset(&alerting, 0, sizeof(struct gsm_mncc)); |
| 1982 | alerting.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 1983 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1984 | /* facility */ |
| 1985 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 1986 | alerting.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1987 | gsm48_decode_facility(&alerting.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1988 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 1989 | } |
| 1990 | |
| 1991 | /* progress */ |
| 1992 | if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) { |
| 1993 | alerting.fields |= MNCC_F_PROGRESS; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 1994 | gsm48_decode_progress(&alerting.progress, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 1995 | TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1); |
| 1996 | } |
| 1997 | /* ss-version */ |
| 1998 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 1999 | alerting.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2000 | gsm48_decode_ssversion(&alerting.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2001 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2002 | } |
| 2003 | |
| 2004 | new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED); |
| 2005 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2006 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND, |
| 2007 | &alerting); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg) |
| 2011 | { |
| 2012 | struct gsm_mncc *alerting = arg; |
| 2013 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2014 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2015 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2016 | gh->msg_type = GSM48_MT_CC_ALERTING; |
| 2017 | |
| 2018 | /* facility */ |
| 2019 | if (alerting->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2020 | gsm48_encode_facility(msg, 0, &alerting->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2021 | /* progress */ |
| 2022 | if (alerting->fields & MNCC_F_PROGRESS) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2023 | gsm48_encode_progress(msg, 0, &alerting->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2024 | /* user-user */ |
| 2025 | if (alerting->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2026 | gsm48_encode_useruser(msg, 0, &alerting->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2027 | |
| 2028 | new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED); |
| 2029 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2030 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg) |
| 2034 | { |
| 2035 | struct gsm_mncc *progress = arg; |
| 2036 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2037 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2038 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2039 | gh->msg_type = GSM48_MT_CC_PROGRESS; |
| 2040 | |
| 2041 | /* progress */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2042 | gsm48_encode_progress(msg, 1, &progress->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2043 | /* user-user */ |
| 2044 | if (progress->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2045 | gsm48_encode_useruser(msg, 0, &progress->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2046 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2047 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg) |
| 2051 | { |
| 2052 | struct gsm_mncc *connect = arg; |
| 2053 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2054 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2055 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2056 | gh->msg_type = GSM48_MT_CC_CONNECT; |
| 2057 | |
| 2058 | gsm48_stop_cc_timer(trans); |
| 2059 | gsm48_start_cc_timer(trans, 0x313, GSM48_T313); |
| 2060 | |
| 2061 | /* facility */ |
| 2062 | if (connect->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2063 | gsm48_encode_facility(msg, 0, &connect->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2064 | /* progress */ |
| 2065 | if (connect->fields & MNCC_F_PROGRESS) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2066 | gsm48_encode_progress(msg, 0, &connect->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2067 | /* connected number */ |
| 2068 | if (connect->fields & MNCC_F_CONNECTED) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2069 | gsm48_encode_connected(msg, &connect->connected); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2070 | /* user-user */ |
| 2071 | if (connect->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2072 | gsm48_encode_useruser(msg, 0, &connect->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2073 | |
| 2074 | new_cc_state(trans, GSM_CSTATE_CONNECT_IND); |
| 2075 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2076 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg) |
| 2080 | { |
| 2081 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2082 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2083 | struct tlv_parsed tp; |
| 2084 | struct gsm_mncc connect; |
| 2085 | |
| 2086 | gsm48_stop_cc_timer(trans); |
| 2087 | |
| 2088 | memset(&connect, 0, sizeof(struct gsm_mncc)); |
| 2089 | connect.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2090 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2091 | /* use subscriber as connected party number */ |
Holger Hans Peter Freyther | ac009e5 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 2092 | connect.fields |= MNCC_F_CONNECTED; |
| 2093 | strncpy(connect.connected.number, trans->subscr->extension, |
| 2094 | sizeof(connect.connected.number)-1); |
| 2095 | strncpy(connect.imsi, trans->subscr->imsi, |
| 2096 | sizeof(connect.imsi)-1); |
| 2097 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2098 | /* facility */ |
| 2099 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2100 | connect.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2101 | gsm48_decode_facility(&connect.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2102 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2103 | } |
| 2104 | /* user-user */ |
| 2105 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2106 | connect.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2107 | gsm48_decode_useruser(&connect.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2108 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2109 | } |
| 2110 | /* ss-version */ |
| 2111 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2112 | connect.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2113 | gsm48_decode_ssversion(&connect.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2114 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2115 | } |
| 2116 | |
| 2117 | new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST); |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 2118 | osmo_counter_inc(trans->subscr->net->stats.call.mt_connect); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2119 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2120 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | |
| 2124 | static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg) |
| 2125 | { |
| 2126 | struct gsm_mncc connect_ack; |
| 2127 | |
| 2128 | gsm48_stop_cc_timer(trans); |
| 2129 | |
| 2130 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 2131 | osmo_counter_inc(trans->subscr->net->stats.call.mo_connect_ack); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2132 | |
| 2133 | memset(&connect_ack, 0, sizeof(struct gsm_mncc)); |
| 2134 | connect_ack.callref = trans->callref; |
Harald Welte | c56006b | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 2135 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2136 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2137 | &connect_ack); |
| 2138 | } |
| 2139 | |
| 2140 | static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg) |
| 2141 | { |
| 2142 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2143 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2144 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2145 | gh->msg_type = GSM48_MT_CC_CONNECT_ACK; |
| 2146 | |
| 2147 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2148 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2149 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg) |
| 2153 | { |
| 2154 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2155 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2156 | struct tlv_parsed tp; |
| 2157 | struct gsm_mncc disc; |
| 2158 | |
| 2159 | gsm48_stop_cc_timer(trans); |
| 2160 | |
| 2161 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ); |
| 2162 | |
| 2163 | memset(&disc, 0, sizeof(struct gsm_mncc)); |
| 2164 | disc.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2165 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2166 | /* cause */ |
| 2167 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2168 | disc.fields |= MNCC_F_CAUSE; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2169 | gsm48_decode_cause(&disc.cause, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2170 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2171 | } |
| 2172 | /* facility */ |
| 2173 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2174 | disc.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2175 | gsm48_decode_facility(&disc.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2176 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2177 | } |
| 2178 | /* user-user */ |
| 2179 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2180 | disc.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2181 | gsm48_decode_useruser(&disc.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2182 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2183 | } |
| 2184 | /* ss-version */ |
| 2185 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2186 | disc.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2187 | gsm48_decode_ssversion(&disc.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2188 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2189 | } |
| 2190 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2191 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2192 | |
| 2193 | } |
| 2194 | |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 2195 | static struct gsm_mncc_cause default_cause = { |
| 2196 | .location = GSM48_CAUSE_LOC_PRN_S_LU, |
| 2197 | .coding = 0, |
| 2198 | .rec = 0, |
| 2199 | .rec_val = 0, |
| 2200 | .value = GSM48_CC_CAUSE_NORMAL_UNSPEC, |
| 2201 | .diag_len = 0, |
| 2202 | .diag = { 0 }, |
| 2203 | }; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2204 | |
| 2205 | static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg) |
| 2206 | { |
| 2207 | struct gsm_mncc *disc = arg; |
| 2208 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2209 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2210 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2211 | gh->msg_type = GSM48_MT_CC_DISCONNECT; |
| 2212 | |
| 2213 | gsm48_stop_cc_timer(trans); |
| 2214 | gsm48_start_cc_timer(trans, 0x306, GSM48_T306); |
| 2215 | |
| 2216 | /* cause */ |
| 2217 | if (disc->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2218 | gsm48_encode_cause(msg, 1, &disc->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2219 | else |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2220 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2221 | |
| 2222 | /* facility */ |
| 2223 | if (disc->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2224 | gsm48_encode_facility(msg, 0, &disc->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2225 | /* progress */ |
| 2226 | if (disc->fields & MNCC_F_PROGRESS) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2227 | gsm48_encode_progress(msg, 0, &disc->progress); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2228 | /* user-user */ |
| 2229 | if (disc->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2230 | gsm48_encode_useruser(msg, 0, &disc->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2231 | |
| 2232 | /* store disconnect cause for T306 expiry */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2233 | memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2234 | |
| 2235 | new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND); |
| 2236 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2237 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg) |
| 2241 | { |
| 2242 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2243 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2244 | struct tlv_parsed tp; |
| 2245 | struct gsm_mncc rel; |
| 2246 | int rc; |
| 2247 | |
| 2248 | gsm48_stop_cc_timer(trans); |
| 2249 | |
| 2250 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2251 | rel.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2252 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2253 | /* cause */ |
| 2254 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2255 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2256 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2257 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2258 | } |
| 2259 | /* facility */ |
| 2260 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2261 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2262 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2263 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2264 | } |
| 2265 | /* user-user */ |
| 2266 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2267 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2268 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2269 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2270 | } |
| 2271 | /* ss-version */ |
| 2272 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2273 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2274 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2275 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2276 | } |
| 2277 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2278 | if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2279 | /* release collision 5.4.5 */ |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2280 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2281 | } else { |
Holger Hans Peter Freyther | 5a38f92 | 2010-06-16 12:30:50 +0800 | [diff] [blame] | 2282 | rc = gsm48_tx_simple(trans->conn, |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 2283 | GSM48_PDISC_CC | (trans->transaction_id << 4), |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2284 | GSM48_MT_CC_RELEASE_COMPL); |
| 2285 | rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | new_cc_state(trans, GSM_CSTATE_NULL); |
| 2289 | |
| 2290 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2291 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2292 | |
| 2293 | return rc; |
| 2294 | } |
| 2295 | |
| 2296 | static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg) |
| 2297 | { |
| 2298 | struct gsm_mncc *rel = arg; |
| 2299 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2300 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2301 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2302 | gh->msg_type = GSM48_MT_CC_RELEASE; |
| 2303 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2304 | gsm48_stop_cc_timer(trans); |
| 2305 | gsm48_start_cc_timer(trans, 0x308, GSM48_T308); |
| 2306 | |
| 2307 | /* cause */ |
| 2308 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2309 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2310 | /* facility */ |
| 2311 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2312 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2313 | /* user-user */ |
| 2314 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2315 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2316 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2317 | trans->cc.T308_second = 0; |
| 2318 | memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2319 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2320 | if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2321 | new_cc_state(trans, GSM_CSTATE_RELEASE_REQ); |
| 2322 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2323 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg) |
| 2327 | { |
| 2328 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2329 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2330 | struct tlv_parsed tp; |
| 2331 | struct gsm_mncc rel; |
| 2332 | int rc = 0; |
| 2333 | |
| 2334 | gsm48_stop_cc_timer(trans); |
| 2335 | |
| 2336 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2337 | rel.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2338 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2339 | /* cause */ |
| 2340 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2341 | rel.fields |= MNCC_F_CAUSE; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2342 | gsm48_decode_cause(&rel.cause, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2343 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2344 | } |
| 2345 | /* facility */ |
| 2346 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2347 | rel.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2348 | gsm48_decode_facility(&rel.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2349 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2350 | } |
| 2351 | /* user-user */ |
| 2352 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2353 | rel.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2354 | gsm48_decode_useruser(&rel.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2355 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2356 | } |
| 2357 | /* ss-version */ |
| 2358 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2359 | rel.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2360 | gsm48_decode_ssversion(&rel.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2361 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2362 | } |
| 2363 | |
| 2364 | if (trans->callref) { |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2365 | switch (trans->cc.state) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2366 | case GSM_CSTATE_CALL_PRESENT: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2367 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2368 | MNCC_REJ_IND, &rel); |
| 2369 | break; |
| 2370 | case GSM_CSTATE_RELEASE_REQ: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2371 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2372 | MNCC_REL_CNF, &rel); |
| 2373 | break; |
| 2374 | default: |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2375 | rc = mncc_recvmsg(trans->subscr->net, trans, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2376 | MNCC_REL_IND, &rel); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2381 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2382 | |
| 2383 | return rc; |
| 2384 | } |
| 2385 | |
| 2386 | static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg) |
| 2387 | { |
| 2388 | struct gsm_mncc *rel = arg; |
| 2389 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2390 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
Harald Welte | 4a6d4ab | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2391 | int ret; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2392 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2393 | gh->msg_type = GSM48_MT_CC_RELEASE_COMPL; |
| 2394 | |
| 2395 | trans->callref = 0; |
| 2396 | |
| 2397 | gsm48_stop_cc_timer(trans); |
| 2398 | |
| 2399 | /* cause */ |
| 2400 | if (rel->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2401 | gsm48_encode_cause(msg, 0, &rel->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2402 | /* facility */ |
| 2403 | if (rel->fields & MNCC_F_FACILITY) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2404 | gsm48_encode_facility(msg, 0, &rel->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2405 | /* user-user */ |
| 2406 | if (rel->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2407 | gsm48_encode_useruser(msg, 0, &rel->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2408 | |
Harald Welte | 4a6d4ab | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2409 | ret = gsm48_conn_sendmsg(msg, trans->conn, trans); |
| 2410 | |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2411 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2412 | |
Harald Welte | 4a6d4ab | 2010-12-21 19:31:41 +0100 | [diff] [blame] | 2413 | return ret; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg) |
| 2417 | { |
| 2418 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2419 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2420 | struct tlv_parsed tp; |
| 2421 | struct gsm_mncc fac; |
| 2422 | |
| 2423 | memset(&fac, 0, sizeof(struct gsm_mncc)); |
| 2424 | fac.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2425 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2426 | /* facility */ |
| 2427 | if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) { |
| 2428 | fac.fields |= MNCC_F_FACILITY; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2429 | gsm48_decode_facility(&fac.facility, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2430 | TLVP_VAL(&tp, GSM48_IE_FACILITY)-1); |
| 2431 | } |
| 2432 | /* ss-version */ |
| 2433 | if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) { |
| 2434 | fac.fields |= MNCC_F_SSVERSION; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2435 | gsm48_decode_ssversion(&fac.ssversion, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2436 | TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1); |
| 2437 | } |
| 2438 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2439 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg) |
| 2443 | { |
| 2444 | struct gsm_mncc *fac = arg; |
| 2445 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2446 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2447 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2448 | gh->msg_type = GSM48_MT_CC_FACILITY; |
| 2449 | |
| 2450 | /* facility */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2451 | gsm48_encode_facility(msg, 1, &fac->facility); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2452 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2453 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg) |
| 2457 | { |
| 2458 | struct gsm_mncc hold; |
| 2459 | |
| 2460 | memset(&hold, 0, sizeof(struct gsm_mncc)); |
| 2461 | hold.callref = trans->callref; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2462 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg) |
| 2466 | { |
| 2467 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2468 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2469 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2470 | gh->msg_type = GSM48_MT_CC_HOLD_ACK; |
| 2471 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2472 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg) |
| 2476 | { |
| 2477 | struct gsm_mncc *hold_rej = arg; |
| 2478 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2479 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2480 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2481 | gh->msg_type = GSM48_MT_CC_HOLD_REJ; |
| 2482 | |
| 2483 | /* cause */ |
| 2484 | if (hold_rej->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2485 | gsm48_encode_cause(msg, 1, &hold_rej->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2486 | else |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2487 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2488 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2489 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg) |
| 2493 | { |
| 2494 | struct gsm_mncc retrieve; |
| 2495 | |
| 2496 | memset(&retrieve, 0, sizeof(struct gsm_mncc)); |
| 2497 | retrieve.callref = trans->callref; |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2498 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND, |
| 2499 | &retrieve); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg) |
| 2503 | { |
| 2504 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2505 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2506 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2507 | gh->msg_type = GSM48_MT_CC_RETR_ACK; |
| 2508 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2509 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg) |
| 2513 | { |
| 2514 | struct gsm_mncc *retrieve_rej = arg; |
| 2515 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2516 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2517 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2518 | gh->msg_type = GSM48_MT_CC_RETR_REJ; |
| 2519 | |
| 2520 | /* cause */ |
| 2521 | if (retrieve_rej->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2522 | gsm48_encode_cause(msg, 1, &retrieve_rej->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2523 | else |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2524 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2525 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2526 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2530 | { |
| 2531 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2532 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2533 | struct tlv_parsed tp; |
| 2534 | struct gsm_mncc dtmf; |
| 2535 | |
| 2536 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2537 | dtmf.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2538 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2539 | /* keypad facility */ |
| 2540 | if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) { |
| 2541 | dtmf.fields |= MNCC_F_KEYPAD; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2542 | gsm48_decode_keypad(&dtmf.keypad, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2543 | TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1); |
| 2544 | } |
| 2545 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2546 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2550 | { |
| 2551 | struct gsm_mncc *dtmf = arg; |
| 2552 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2553 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2554 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2555 | gh->msg_type = GSM48_MT_CC_START_DTMF_ACK; |
| 2556 | |
| 2557 | /* keypad */ |
| 2558 | if (dtmf->fields & MNCC_F_KEYPAD) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2559 | gsm48_encode_keypad(msg, dtmf->keypad); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2560 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2561 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg) |
| 2565 | { |
| 2566 | struct gsm_mncc *dtmf = arg; |
| 2567 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2568 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2569 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2570 | gh->msg_type = GSM48_MT_CC_START_DTMF_REJ; |
| 2571 | |
| 2572 | /* cause */ |
| 2573 | if (dtmf->fields & MNCC_F_CAUSE) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2574 | gsm48_encode_cause(msg, 1, &dtmf->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2575 | else |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2576 | gsm48_encode_cause(msg, 1, &default_cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2577 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2578 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg) |
| 2582 | { |
| 2583 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2584 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2585 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2586 | gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK; |
| 2587 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2588 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg) |
| 2592 | { |
| 2593 | struct gsm_mncc dtmf; |
| 2594 | |
| 2595 | memset(&dtmf, 0, sizeof(struct gsm_mncc)); |
| 2596 | dtmf.callref = trans->callref; |
| 2597 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2598 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg) |
| 2602 | { |
| 2603 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2604 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2605 | struct tlv_parsed tp; |
| 2606 | struct gsm_mncc modify; |
| 2607 | |
| 2608 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2609 | modify.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2610 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2611 | /* bearer capability */ |
| 2612 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2613 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2614 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2615 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2616 | } |
| 2617 | |
| 2618 | new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY); |
| 2619 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2620 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg) |
| 2624 | { |
| 2625 | struct gsm_mncc *modify = arg; |
| 2626 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2627 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2628 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2629 | gh->msg_type = GSM48_MT_CC_MODIFY; |
| 2630 | |
| 2631 | gsm48_start_cc_timer(trans, 0x323, GSM48_T323); |
| 2632 | |
| 2633 | /* bearer capability */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2634 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2635 | |
| 2636 | new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY); |
| 2637 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2638 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg) |
| 2642 | { |
| 2643 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2644 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2645 | struct tlv_parsed tp; |
| 2646 | struct gsm_mncc modify; |
| 2647 | |
| 2648 | gsm48_stop_cc_timer(trans); |
| 2649 | |
| 2650 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2651 | modify.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2652 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2653 | /* bearer capability */ |
| 2654 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2655 | modify.fields |= MNCC_F_BEARER_CAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2656 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2657 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2658 | } |
| 2659 | |
| 2660 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2661 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2662 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg) |
| 2666 | { |
| 2667 | struct gsm_mncc *modify = arg; |
| 2668 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2669 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2670 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2671 | gh->msg_type = GSM48_MT_CC_MODIFY_COMPL; |
| 2672 | |
| 2673 | /* bearer capability */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2674 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2675 | |
| 2676 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2677 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2678 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg) |
| 2682 | { |
| 2683 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2684 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2685 | struct tlv_parsed tp; |
| 2686 | struct gsm_mncc modify; |
| 2687 | |
| 2688 | gsm48_stop_cc_timer(trans); |
| 2689 | |
| 2690 | memset(&modify, 0, sizeof(struct gsm_mncc)); |
| 2691 | modify.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2692 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2693 | /* bearer capability */ |
| 2694 | if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) { |
| 2695 | modify.fields |= GSM48_IE_BEARER_CAP; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2696 | gsm48_decode_bearer_cap(&modify.bearer_cap, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2697 | TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1); |
| 2698 | } |
| 2699 | /* cause */ |
| 2700 | if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) { |
| 2701 | modify.fields |= MNCC_F_CAUSE; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2702 | gsm48_decode_cause(&modify.cause, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2703 | TLVP_VAL(&tp, GSM48_IE_CAUSE)-1); |
| 2704 | } |
| 2705 | |
| 2706 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2707 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2708 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg) |
| 2712 | { |
| 2713 | struct gsm_mncc *modify = arg; |
| 2714 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2715 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2716 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2717 | gh->msg_type = GSM48_MT_CC_MODIFY_REJECT; |
| 2718 | |
| 2719 | /* bearer capability */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2720 | gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2721 | /* cause */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2722 | gsm48_encode_cause(msg, 1, &modify->cause); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2723 | |
| 2724 | new_cc_state(trans, GSM_CSTATE_ACTIVE); |
| 2725 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2726 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg) |
| 2730 | { |
| 2731 | struct gsm_mncc *notify = arg; |
| 2732 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2733 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2734 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2735 | gh->msg_type = GSM48_MT_CC_NOTIFY; |
| 2736 | |
| 2737 | /* notify */ |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2738 | gsm48_encode_notify(msg, notify->notify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2739 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2740 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg) |
| 2744 | { |
| 2745 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2746 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2747 | // struct tlv_parsed tp; |
| 2748 | struct gsm_mncc notify; |
| 2749 | |
| 2750 | memset(¬ify, 0, sizeof(struct gsm_mncc)); |
| 2751 | notify.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2752 | // tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2753 | if (payload_len >= 1) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2754 | gsm48_decode_notify(¬ify.notify, gh->data); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2755 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2756 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, ¬ify); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg) |
| 2760 | { |
| 2761 | struct gsm_mncc *user = arg; |
| 2762 | struct msgb *msg = gsm48_msgb_alloc(); |
| 2763 | struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); |
| 2764 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2765 | gh->msg_type = GSM48_MT_CC_USER_INFO; |
| 2766 | |
| 2767 | /* user-user */ |
| 2768 | if (user->fields & MNCC_F_USERUSER) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2769 | gsm48_encode_useruser(msg, 1, &user->useruser); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2770 | /* more data */ |
| 2771 | if (user->more) |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2772 | gsm48_encode_more(msg); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2773 | |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 2774 | return gsm48_conn_sendmsg(msg, trans->conn, trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg) |
| 2778 | { |
| 2779 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 2780 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 2781 | struct tlv_parsed tp; |
| 2782 | struct gsm_mncc user; |
| 2783 | |
| 2784 | memset(&user, 0, sizeof(struct gsm_mncc)); |
| 2785 | user.callref = trans->callref; |
Harald Welte | 705f294 | 2010-03-02 23:18:30 +0100 | [diff] [blame] | 2786 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2787 | /* user-user */ |
| 2788 | if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) { |
| 2789 | user.fields |= MNCC_F_USERUSER; |
Harald Welte | fdc93d9 | 2010-03-07 23:40:35 +0100 | [diff] [blame] | 2790 | gsm48_decode_useruser(&user.useruser, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2791 | TLVP_VAL(&tp, GSM48_IE_USER_USER)-1); |
| 2792 | } |
| 2793 | /* more data */ |
| 2794 | if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA)) |
| 2795 | user.more = 1; |
| 2796 | |
Harald Welte | 0abe5a6 | 2009-07-23 19:06:52 +0200 | [diff] [blame] | 2797 | return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2798 | } |
| 2799 | |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 2800 | static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2801 | { |
| 2802 | struct gsm_mncc *mode = arg; |
| 2803 | |
Holger Hans Peter Freyther | 3f6430d | 2011-01-16 18:17:04 +0100 | [diff] [blame] | 2804 | return gsm0808_assign_req(trans->conn, mode->lchan_mode, 1); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | static struct downstate { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2808 | uint32_t states; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2809 | int type; |
| 2810 | int (*rout) (struct gsm_trans *trans, void *arg); |
| 2811 | } downstatelist[] = { |
| 2812 | /* mobile originating call establishment */ |
| 2813 | {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */ |
| 2814 | MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc}, |
| 2815 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */ |
| 2816 | MNCC_ALERT_REQ, gsm48_cc_tx_alerting}, |
| 2817 | {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC) | SBIT(GSM_CSTATE_CALL_DELIVERED), /* 5.2.1.2 | 5.2.1.6 | 5.2.1.6 */ |
| 2818 | MNCC_SETUP_RSP, gsm48_cc_tx_connect}, |
| 2819 | {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */ |
| 2820 | MNCC_PROGRESS_REQ, gsm48_cc_tx_progress}, |
| 2821 | /* mobile terminating call establishment */ |
| 2822 | {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */ |
| 2823 | MNCC_SETUP_REQ, gsm48_cc_tx_setup}, |
| 2824 | {SBIT(GSM_CSTATE_CONNECT_REQUEST), |
| 2825 | MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack}, |
| 2826 | /* signalling during call */ |
| 2827 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2828 | MNCC_NOTIFY_REQ, gsm48_cc_tx_notify}, |
| 2829 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), |
| 2830 | MNCC_FACILITY_REQ, gsm48_cc_tx_facility}, |
| 2831 | {ALL_STATES, |
| 2832 | MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack}, |
| 2833 | {ALL_STATES, |
| 2834 | MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej}, |
| 2835 | {ALL_STATES, |
| 2836 | MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack}, |
| 2837 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2838 | MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack}, |
| 2839 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2840 | MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej}, |
| 2841 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2842 | MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack}, |
| 2843 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2844 | MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej}, |
| 2845 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2846 | MNCC_MODIFY_REQ, gsm48_cc_tx_modify}, |
| 2847 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2848 | MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete}, |
| 2849 | {SBIT(GSM_CSTATE_MO_ORIG_MODIFY), |
| 2850 | MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject}, |
| 2851 | {SBIT(GSM_CSTATE_ACTIVE), |
| 2852 | MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo}, |
| 2853 | /* clearing */ |
| 2854 | {SBIT(GSM_CSTATE_INITIATED), |
| 2855 | MNCC_REJ_REQ, gsm48_cc_tx_release_compl}, |
| 2856 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */ |
| 2857 | MNCC_DISC_REQ, gsm48_cc_tx_disconnect}, |
| 2858 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 2859 | MNCC_REL_REQ, gsm48_cc_tx_release}, |
| 2860 | /* special */ |
| 2861 | {ALL_STATES, |
Holger Hans Peter Freyther | cf0f336 | 2009-10-22 15:13:00 +0200 | [diff] [blame] | 2862 | MNCC_LCHAN_MODIFY, _gsm48_lchan_modify}, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2863 | }; |
| 2864 | |
| 2865 | #define DOWNSLLEN \ |
| 2866 | (sizeof(downstatelist) / sizeof(struct downstate)) |
| 2867 | |
| 2868 | |
Harald Welte | f4e4b8a | 2010-12-22 23:57:45 +0100 | [diff] [blame] | 2869 | int mncc_tx_to_cc(struct gsm_network *net, int msg_type, void *arg) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2870 | { |
Harald Welte | aa60edb | 2009-08-09 18:52:33 +0200 | [diff] [blame] | 2871 | int i, rc = 0; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2872 | struct gsm_trans *trans = NULL, *transt; |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2873 | struct gsm_subscriber_connection *conn = NULL; |
Holger Hans Peter Freyther | 50366f2 | 2010-12-27 16:02:25 +0100 | [diff] [blame] | 2874 | struct gsm_bts *bts = NULL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2875 | struct gsm_mncc *data = arg, rel; |
| 2876 | |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2877 | DEBUGP(DMNCC, "receive message %s\n", get_mncc_name(msg_type)); |
| 2878 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2879 | /* handle special messages */ |
| 2880 | switch(msg_type) { |
| 2881 | case MNCC_BRIDGE: |
| 2882 | return tch_bridge(net, arg); |
| 2883 | case MNCC_FRAME_DROP: |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2884 | return tch_recv_mncc(net, data->callref, 0); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2885 | case MNCC_FRAME_RECV: |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2886 | return tch_recv_mncc(net, data->callref, 1); |
| 2887 | case GSM_TCHF_FRAME: |
| 2888 | /* Find callref */ |
| 2889 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2890 | if (!trans) { |
| 2891 | LOGP(DMNCC, LOGL_ERROR, "TCH frame for non-existing trans\n"); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2892 | return -EIO; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2893 | } |
| 2894 | if (!trans->conn) { |
| 2895 | LOGP(DMNCC, LOGL_NOTICE, "TCH frame for trans without conn\n"); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2896 | return 0; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2897 | } |
| 2898 | if (trans->conn->lchan->type != GSM_LCHAN_TCH_F) { |
| 2899 | /* This should be LOGL_ERROR or NOTICE, but |
| 2900 | * unfortuantely it happens for a couple of frames at |
| 2901 | * the beginning of every RTP connection */ |
| 2902 | LOGP(DMNCC, LOGL_DEBUG, "TCH frame for lchan != TCH_F\n"); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2903 | return 0; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2904 | } |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2905 | bts = trans->conn->lchan->ts->trx->bts; |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2906 | switch (bts->type) { |
| 2907 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 2908 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2909 | if (!trans->conn->lchan->abis_ip.rtp_socket) { |
Harald Welte | 45d6e4d | 2010-12-24 12:40:21 +0100 | [diff] [blame] | 2910 | DEBUGP(DMNCC, "TCH frame to lchan without RTP connection\n"); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2911 | return 0; |
Harald Welte | 17b5652 | 2010-12-22 21:45:05 +0100 | [diff] [blame] | 2912 | } |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2913 | return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2914 | case GSM_BTS_TYPE_BS11: |
Harald Welte | f39e3b5 | 2011-03-20 06:27:31 -0300 | [diff] [blame] | 2915 | case GSM_BTS_TYPE_RBS2000: |
Harald Welte | c0cf002 | 2011-08-05 20:11:18 +0200 | [diff] [blame] | 2916 | case GSM_BTS_TYPE_NOKIA_SITE: |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 2917 | return trau_send_frame(trans->conn->lchan, arg); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2918 | default: |
Harald Welte | 8099a71 | 2011-08-09 21:53:20 +0200 | [diff] [blame] | 2919 | LOGP(DCC, LOGL_ERROR, "Unknown BTS type %u\n", bts->type); |
Harald Welte | 3971ad5 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 2920 | } |
| 2921 | return -EINVAL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | memset(&rel, 0, sizeof(struct gsm_mncc)); |
| 2925 | rel.callref = data->callref; |
| 2926 | |
| 2927 | /* Find callref */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2928 | trans = trans_find_by_callref(net, data->callref); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2929 | |
| 2930 | /* Callref unknown */ |
| 2931 | if (!trans) { |
Holger Hans Peter Freyther | e2a3c9f | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 2932 | struct gsm_subscriber *subscr; |
| 2933 | |
Harald Welte | 6e1536e | 2009-07-04 10:11:24 +0200 | [diff] [blame] | 2934 | if (msg_type != MNCC_SETUP_REQ) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2935 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2936 | "Received '%s' from MNCC with " |
| 2937 | "unknown callref %d\n", data->called.number, |
| 2938 | get_mncc_name(msg_type), data->callref); |
| 2939 | /* Invalid call reference */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2940 | return mncc_release_ind(net, NULL, data->callref, |
| 2941 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2942 | GSM48_CC_CAUSE_INVAL_TRANS_ID); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2943 | } |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2944 | if (!data->called.number[0] && !data->imsi[0]) { |
| 2945 | DEBUGP(DCC, "(bts - trx - ts - ti) " |
| 2946 | "Received '%s' from MNCC with " |
| 2947 | "no number or IMSI\n", get_mncc_name(msg_type)); |
| 2948 | /* Invalid number */ |
| 2949 | return mncc_release_ind(net, NULL, data->callref, |
| 2950 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2951 | GSM48_CC_CAUSE_INV_NR_FORMAT); |
| 2952 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2953 | /* New transaction due to setup, find subscriber */ |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2954 | if (data->called.number[0]) |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 2955 | subscr = subscr_get_by_extension(net, |
| 2956 | data->called.number); |
Andreas Eversberg | 9eaa5da | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 2957 | else |
Harald Welte | 7535041 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 2958 | subscr = subscr_get_by_imsi(net, data->imsi); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2959 | /* If subscriber is not found */ |
| 2960 | if (!subscr) { |
| 2961 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2962 | "Received '%s' from MNCC with " |
| 2963 | "unknown subscriber %s\n", data->called.number, |
| 2964 | get_mncc_name(msg_type), data->called.number); |
| 2965 | /* Unknown subscriber */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2966 | return mncc_release_ind(net, NULL, data->callref, |
| 2967 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2968 | GSM48_CC_CAUSE_UNASSIGNED_NR); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2969 | } |
| 2970 | /* If subscriber is not "attached" */ |
| 2971 | if (!subscr->lac) { |
| 2972 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
| 2973 | "Received '%s' from MNCC with " |
| 2974 | "detached subscriber %s\n", data->called.number, |
| 2975 | get_mncc_name(msg_type), data->called.number); |
| 2976 | subscr_put(subscr); |
| 2977 | /* Temporarily out of order */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2978 | return mncc_release_ind(net, NULL, data->callref, |
| 2979 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2980 | GSM48_CC_CAUSE_DEST_OOO); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2981 | } |
| 2982 | /* Create transaction */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 2983 | trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref); |
| 2984 | if (!trans) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2985 | DEBUGP(DCC, "No memory for trans.\n"); |
| 2986 | subscr_put(subscr); |
| 2987 | /* Ressource unavailable */ |
Andreas Eversberg | b992a8a | 2009-06-14 22:14:12 +0800 | [diff] [blame] | 2988 | mncc_release_ind(net, NULL, data->callref, |
| 2989 | GSM48_CAUSE_LOC_PRN_S_LU, |
| 2990 | GSM48_CC_CAUSE_RESOURCE_UNAVAIL); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2991 | return -ENOMEM; |
| 2992 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2993 | /* Find lchan */ |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2994 | conn = connection_for_subscr(subscr); |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 2995 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2996 | /* If subscriber has no lchan */ |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 2997 | if (!conn) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2998 | /* find transaction with this subscriber already paging */ |
| 2999 | llist_for_each_entry(transt, &net->trans_list, entry) { |
| 3000 | /* Transaction of our lchan? */ |
| 3001 | if (transt == trans || |
| 3002 | transt->subscr != subscr) |
| 3003 | continue; |
Holger Hans Peter Freyther | 346074d | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3004 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3005 | "Received '%s' from MNCC with " |
| 3006 | "unallocated channel, paging already " |
Holger Hans Peter Freyther | 346074d | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3007 | "started for lac %d.\n", |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3008 | data->called.number, |
Holger Hans Peter Freyther | 346074d | 2010-12-27 16:08:34 +0100 | [diff] [blame] | 3009 | get_mncc_name(msg_type), subscr->lac); |
Holger Hans Peter Freyther | e2a3c9f | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3010 | subscr_put(subscr); |
| 3011 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3012 | return 0; |
| 3013 | } |
| 3014 | /* store setup informations until paging was successfull */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3015 | memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc)); |
Sylvain Munaut | 892f695 | 2010-12-01 22:17:36 +0100 | [diff] [blame] | 3016 | |
| 3017 | /* Get a channel */ |
Holger Hans Peter Freyther | 02539b1 | 2010-12-29 17:09:07 +0100 | [diff] [blame] | 3018 | trans->paging_request = talloc_zero(subscr->net, struct gsm_network*); |
| 3019 | if (!trans->paging_request) { |
| 3020 | LOGP(DCC, LOGL_ERROR, "Failed to allocate paging token.\n"); |
| 3021 | subscr_put(subscr); |
| 3022 | trans_free(trans); |
| 3023 | return 0; |
| 3024 | } |
| 3025 | |
| 3026 | *trans->paging_request = subscr->net; |
| 3027 | subscr_get_channel(subscr, RSL_CHANNEED_TCH_F, setup_trig_pag_evt, trans->paging_request); |
Sylvain Munaut | 892f695 | 2010-12-01 22:17:36 +0100 | [diff] [blame] | 3028 | |
Holger Hans Peter Freyther | e2a3c9f | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3029 | subscr_put(subscr); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3030 | return 0; |
| 3031 | } |
| 3032 | /* Assign lchan */ |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3033 | trans->conn = conn; |
Holger Hans Peter Freyther | e2a3c9f | 2009-10-27 14:21:14 +0100 | [diff] [blame] | 3034 | subscr_put(subscr); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3035 | } |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3036 | |
| 3037 | if (trans->conn) |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3038 | conn = trans->conn; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3039 | |
| 3040 | /* if paging did not respond yet */ |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3041 | if (!conn) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3042 | DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) " |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 3043 | "Received '%s' from MNCC in paging state\n", |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3044 | (trans->subscr)?(trans->subscr->extension):"-", |
| 3045 | get_mncc_name(msg_type)); |
Harald Welte | bbc636a | 2009-06-11 14:23:20 +0800 | [diff] [blame] | 3046 | mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, |
| 3047 | GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3048 | if (msg_type == MNCC_REL_REQ) |
| 3049 | rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel); |
| 3050 | else |
| 3051 | rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel); |
| 3052 | trans->callref = 0; |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3053 | trans_free(trans); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3054 | return rc; |
| 3055 | } |
| 3056 | |
| 3057 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) " |
| 3058 | "Received '%s' from MNCC in state %d (%s)\n", |
Holger Hans Peter Freyther | 2f4af77 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 3059 | conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr, |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3060 | trans->transaction_id, |
Holger Hans Peter Freyther | 4009da4 | 2010-03-23 07:00:22 +0100 | [diff] [blame] | 3061 | (trans->conn->subscr)?(trans->conn->subscr->extension):"-", |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3062 | get_mncc_name(msg_type), trans->cc.state, |
Harald Welte | b30935e | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3063 | gsm48_cc_state_name(trans->cc.state)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3064 | |
| 3065 | /* Find function for current state and message */ |
| 3066 | for (i = 0; i < DOWNSLLEN; i++) |
| 3067 | if ((msg_type == downstatelist[i].type) |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3068 | && ((1 << trans->cc.state) & downstatelist[i].states)) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3069 | break; |
| 3070 | if (i == DOWNSLLEN) { |
| 3071 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3072 | return 0; |
| 3073 | } |
| 3074 | |
| 3075 | rc = downstatelist[i].rout(trans, arg); |
| 3076 | |
| 3077 | return rc; |
| 3078 | } |
| 3079 | |
| 3080 | |
| 3081 | static struct datastate { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3082 | uint32_t states; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3083 | int type; |
| 3084 | int (*rout) (struct gsm_trans *trans, struct msgb *msg); |
| 3085 | } datastatelist[] = { |
| 3086 | /* mobile originating call establishment */ |
| 3087 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3088 | GSM48_MT_CC_SETUP, gsm48_cc_rx_setup}, |
| 3089 | {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */ |
| 3090 | GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup}, |
| 3091 | {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */ |
| 3092 | GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack}, |
| 3093 | /* mobile terminating call establishment */ |
| 3094 | {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */ |
| 3095 | GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf}, |
| 3096 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */ |
| 3097 | GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting}, |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 3098 | {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */ |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3099 | GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect}, |
| 3100 | /* signalling during call */ |
| 3101 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), |
| 3102 | GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility}, |
| 3103 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3104 | GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify}, |
| 3105 | {ALL_STATES, |
| 3106 | GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf}, |
| 3107 | {ALL_STATES, |
| 3108 | GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf}, |
| 3109 | {ALL_STATES, |
| 3110 | GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq}, |
| 3111 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3112 | GSM48_MT_CC_HOLD, gsm48_cc_rx_hold}, |
| 3113 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3114 | GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve}, |
| 3115 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3116 | GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify}, |
| 3117 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3118 | GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete}, |
| 3119 | {SBIT(GSM_CSTATE_MO_TERM_MODIFY), |
| 3120 | GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject}, |
| 3121 | {SBIT(GSM_CSTATE_ACTIVE), |
| 3122 | GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo}, |
| 3123 | /* clearing */ |
| 3124 | {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */ |
| 3125 | GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect}, |
| 3126 | {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */ |
| 3127 | GSM48_MT_CC_RELEASE, gsm48_cc_rx_release}, |
| 3128 | {ALL_STATES, /* 5.4.3.4 */ |
| 3129 | GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl}, |
| 3130 | }; |
| 3131 | |
| 3132 | #define DATASLLEN \ |
| 3133 | (sizeof(datastatelist) / sizeof(struct datastate)) |
| 3134 | |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3135 | static int gsm0408_rcv_cc(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3136 | { |
| 3137 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3138 | uint8_t msg_type = gh->msg_type & 0xbf; |
| 3139 | uint8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */ |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3140 | struct gsm_trans *trans = NULL; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3141 | int i, rc = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3142 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3143 | if (msg_type & 0x80) { |
| 3144 | DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type); |
| 3145 | return -EINVAL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3146 | } |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3147 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3148 | /* Find transaction */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3149 | trans = trans_find_by_id(conn->subscr, GSM48_PDISC_CC, transaction_id); |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3150 | |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3151 | DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3152 | "Received '%s' from MS in state %d (%s)\n", |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3153 | conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr, |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3154 | transaction_id, (conn->subscr)?(conn->subscr->extension):"-", |
Harald Welte | b30935e | 2010-03-25 12:13:02 +0800 | [diff] [blame] | 3155 | gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0, |
| 3156 | gsm48_cc_state_name(trans?(trans->cc.state):0)); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3157 | |
| 3158 | /* Create transaction */ |
| 3159 | if (!trans) { |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3160 | DEBUGP(DCC, "Unknown transaction ID %x, " |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3161 | "creating new trans.\n", transaction_id); |
| 3162 | /* Create transaction */ |
Holger Hans Peter Freyther | 065b811 | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 3163 | trans = trans_alloc(conn->subscr, GSM48_PDISC_CC, |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3164 | transaction_id, new_callref++); |
| 3165 | if (!trans) { |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3166 | DEBUGP(DCC, "No memory for trans.\n"); |
Holger Hans Peter Freyther | 3f6430d | 2011-01-16 18:17:04 +0100 | [diff] [blame] | 3167 | rc = gsm48_tx_simple(conn, |
Harald Welte | 4861c82 | 2009-07-23 21:21:14 +0200 | [diff] [blame] | 3168 | GSM48_PDISC_CC | (transaction_id << 4), |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3169 | GSM48_MT_CC_RELEASE_COMPL); |
| 3170 | return -ENOMEM; |
| 3171 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3172 | /* Assign transaction */ |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3173 | trans->conn = conn; |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | /* find function for current state and message */ |
| 3177 | for (i = 0; i < DATASLLEN; i++) |
| 3178 | if ((msg_type == datastatelist[i].type) |
Harald Welte | c2189a6 | 2009-07-23 18:56:43 +0200 | [diff] [blame] | 3179 | && ((1 << trans->cc.state) & datastatelist[i].states)) |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3180 | break; |
| 3181 | if (i == DATASLLEN) { |
| 3182 | DEBUGP(DCC, "Message unhandled at this state.\n"); |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
Holger Hans Peter Freyther | ac009e5 | 2013-07-06 11:45:38 +0200 | [diff] [blame] | 3186 | assert(trans->subscr); |
| 3187 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 3188 | rc = datastatelist[i].rout(trans, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3189 | |
| 3190 | return rc; |
| 3191 | } |
| 3192 | |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3193 | /* Create a dummy to wait five seconds */ |
| 3194 | static void release_anchor(struct gsm_subscriber_connection *conn) |
| 3195 | { |
| 3196 | if (!conn->anch_operation) |
| 3197 | return; |
| 3198 | |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 3199 | osmo_timer_del(&conn->anch_operation->timeout); |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3200 | talloc_free(conn->anch_operation); |
| 3201 | conn->anch_operation = NULL; |
| 3202 | } |
| 3203 | |
| 3204 | static void anchor_timeout(void *_data) |
| 3205 | { |
| 3206 | struct gsm_subscriber_connection *con = _data; |
| 3207 | |
| 3208 | release_anchor(con); |
| 3209 | msc_release_connection(con); |
| 3210 | } |
| 3211 | |
| 3212 | int gsm0408_new_conn(struct gsm_subscriber_connection *conn) |
| 3213 | { |
| 3214 | conn->anch_operation = talloc_zero(conn, struct gsm_anchor_operation); |
| 3215 | if (!conn->anch_operation) |
| 3216 | return -1; |
| 3217 | |
| 3218 | conn->anch_operation->timeout.data = conn; |
| 3219 | conn->anch_operation->timeout.cb = anchor_timeout; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 3220 | osmo_timer_schedule(&conn->anch_operation->timeout, 5, 0); |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3221 | return 0; |
| 3222 | } |
| 3223 | |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 3224 | /* here we get data from the BSC level... */ |
| 3225 | int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3226 | { |
| 3227 | struct gsm48_hdr *gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 3228 | uint8_t pdisc = gh->proto_discr & 0x0f; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3229 | int rc = 0; |
Harald Welte | f6a38ec | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 3230 | |
Holger Hans Peter Freyther | 4854939 | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 3231 | if (silent_call_reroute(conn, msg)) |
| 3232 | return silent_call_rx(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3233 | |
| 3234 | switch (pdisc) { |
| 3235 | case GSM48_PDISC_CC: |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3236 | release_anchor(conn); |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3237 | rc = gsm0408_rcv_cc(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3238 | break; |
| 3239 | case GSM48_PDISC_MM: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3240 | rc = gsm0408_rcv_mm(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3241 | break; |
| 3242 | case GSM48_PDISC_RR: |
Holger Hans Peter Freyther | 96aeb2b | 2010-06-17 17:14:35 +0800 | [diff] [blame] | 3243 | rc = gsm0408_rcv_rr(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3244 | break; |
| 3245 | case GSM48_PDISC_SMS: |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3246 | release_anchor(conn); |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 3247 | rc = gsm0411_rcv_sms(conn, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3248 | break; |
| 3249 | case GSM48_PDISC_MM_GPRS: |
| 3250 | case GSM48_PDISC_SM_GPRS: |
Harald Welte | 60e5f4f | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3251 | LOGP(DRLL, LOGL_NOTICE, "Unimplemented " |
| 3252 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3253 | break; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3254 | case GSM48_PDISC_NC_SS: |
Holger Hans Peter Freyther | 425cfc4 | 2010-07-05 15:34:16 +0800 | [diff] [blame] | 3255 | release_anchor(conn); |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 3256 | rc = handle_rcv_ussd(conn, msg); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 3257 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3258 | default: |
Harald Welte | 60e5f4f | 2009-12-24 12:13:17 +0100 | [diff] [blame] | 3259 | LOGP(DRLL, LOGL_NOTICE, "Unknown " |
| 3260 | "GSM 04.08 discriminator 0x%02x\n", pdisc); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 3261 | break; |
| 3262 | } |
| 3263 | |
| 3264 | return rc; |
| 3265 | } |
| 3266 | |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3267 | /* |
| 3268 | * This will be ran by the linker when loading the DSO. We use it to |
| 3269 | * do system initialization, e.g. registration of signal handlers. |
| 3270 | */ |
| 3271 | static __attribute__((constructor)) void on_dso_load_0408(void) |
| 3272 | { |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 3273 | osmo_signal_register_handler(SS_ABISIP, handle_abisip_signal, NULL); |
Harald Welte | 3c06207 | 2009-07-28 18:25:29 +0200 | [diff] [blame] | 3274 | } |