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