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