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