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