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