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