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