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