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