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