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