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