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