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