blob: f022c04a93d885b2a90266d28631acf3d5473fc2 [file] [log] [blame]
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
Harald Welte52b1f982008-12-23 20:25:15 +00002 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
Harald Weltebf5e8df2009-02-03 12:59:45 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +08005 * (C) 2008-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte8470bf22008-12-25 23:28:35 +00006 *
Harald Welte52b1f982008-12-23 20:25:15 +00007 * 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 Weltedb253af2008-12-30 17:56:55 +000030#include <time.h>
Harald Welte4b634542008-12-27 01:55:51 +000031#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000032
Sylvain Munaut30a15382009-12-24 00:27:26 +010033#include <openbsc/auth.h>
Harald Welte75a983f2008-12-27 21:34:06 +000034#include <openbsc/db.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010035#include <osmocore/msgb.h>
36#include <osmocore/bitvec.h>
37#include <osmocore/tlv.h>
Harald Welte8470bf22008-12-25 23:28:35 +000038#include <openbsc/debug.h>
39#include <openbsc/gsm_data.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010040#include <osmocore/gsm_utils.h>
Harald Welte8470bf22008-12-25 23:28:35 +000041#include <openbsc/gsm_subscriber.h>
Daniel Willmann8b3390e2008-12-28 00:31:09 +000042#include <openbsc/gsm_04_11.h>
Harald Welte8470bf22008-12-25 23:28:35 +000043#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +080044#include <openbsc/gsm_04_80.h>
Harald Welte8470bf22008-12-25 23:28:35 +000045#include <openbsc/abis_rsl.h>
Holger Freytherca362a62009-01-04 21:05:01 +000046#include <openbsc/chan_alloc.h>
Harald Welte0b4c34e2009-02-09 17:54:43 +000047#include <openbsc/paging.h>
Holger Freyther053e09d2009-02-14 22:51:06 +000048#include <openbsc/signal.h>
Harald Welte45b407a2009-05-23 15:51:12 +000049#include <openbsc/trau_frame.h>
Harald Welte11fa29c2009-02-19 17:24:39 +000050#include <openbsc/trau_mux.h>
Harald Welte805f6442009-07-28 18:25:29 +020051#include <openbsc/rtp_proxy.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +010052#include <osmocore/talloc.h>
Harald Welte55c8f352010-03-07 23:40:35 +010053#include <osmocore/gsm48.h>
Harald Weltedcaf5652009-07-23 18:56:43 +020054#include <openbsc/transaction.h>
Harald Welte6eafe912009-10-16 08:32:58 +020055#include <openbsc/ussd.h>
Harald Welte51008772009-12-29 11:49:12 +010056#include <openbsc/silent_call.h>
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +080057#include <openbsc/bsc_api.h>
Holger Hans Peter Freyther88519ea2010-06-30 12:44:07 +080058#include <openbsc/osmo_msc.h>
Harald Welte52b1f982008-12-23 20:25:15 +000059
Harald Welte (local)d19e58b2009-08-15 02:30:58 +020060void *tall_locop_ctx;
Sylvain Munaut30a15382009-12-24 00:27:26 +010061void *tall_authciphop_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +020062
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +080063int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +080064static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte65e74cc2008-12-29 01:55:35 +000065 u_int8_t pdisc, u_int8_t msg_type);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010066static void schedule_reject(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080067static void release_anchor(struct gsm_subscriber_connection *conn);
Harald Welte65e74cc2008-12-29 01:55:35 +000068
Harald Welte52b1f982008-12-23 20:25:15 +000069struct gsm_lai {
70 u_int16_t mcc;
71 u_int16_t mnc;
72 u_int16_t lac;
73};
74
Harald Welte4bfdfe72009-06-10 23:11:52 +080075static u_int32_t new_callref = 0x80000001;
76
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +080077static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn,
78 struct gsm_trans *trans)
79{
80 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
81
82 /* if we get passed a transaction reference, do some common
83 * work that the caller no longer has to do */
84 if (trans) {
85 gh->proto_discr = trans->protocol | (trans->transaction_id << 4);
86 msg->lchan = trans->conn->lchan;
87 }
88
89
90 if (msg->lchan) {
91 msg->trx = msg->lchan->ts->trx;
92 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC)
93 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) "
94 "Sending '%s' to MS.\n", msg->trx->bts->nr,
95 msg->trx->nr, msg->lchan->ts->nr,
96 gh->proto_discr & 0xf0,
97 gsm48_cc_msg_name(gh->msg_type));
98 else
99 DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) "
100 "Sending 0x%02x to MS.\n", msg->trx->bts->nr,
101 msg->trx->nr, msg->lchan->ts->nr,
102 gh->proto_discr, gh->msg_type);
103 }
104
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800105 return gsm0808_submit_dtap(conn, msg, 0);
106}
Sylvain Munaut30a15382009-12-24 00:27:26 +0100107
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +0800108int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message)
109{
110 struct gsm48_hdr *gh;
111 struct msgb *ss_notify;
112
113 ss_notify = gsm0480_create_notifySS(message);
114 if (!ss_notify)
115 return -1;
116
117 gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0);
118 uint8_t *data = msgb_push(ss_notify, 1);
119 data[0] = ss_notify->len - 1;
120 gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh));
121 gh->msg_type = GSM48_MT_CC_FACILITY;
122 return gsm48_conn_sendmsg(ss_notify, trans->conn, trans);
123}
124
Sylvain Munaut30a15382009-12-24 00:27:26 +0100125static void release_security_operation(struct gsm_subscriber_connection *conn)
126{
127 if (!conn->sec_operation)
128 return;
129
130 talloc_free(conn->sec_operation);
131 conn->sec_operation = NULL;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800132 msc_release_connection(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100133}
134
135static void allocate_security_operation(struct gsm_subscriber_connection *conn)
136{
Sylvain Munaut30a15382009-12-24 00:27:26 +0100137 conn->sec_operation = talloc_zero(tall_authciphop_ctx,
138 struct gsm_security_operation);
139}
140
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800141static int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq,
142 gsm_cbfn *cb, void *cb_data)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100143{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800144 struct gsm_network *net = conn->bts->network;
145 struct gsm_subscriber *subscr = conn->subscr;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100146 struct gsm_security_operation *op;
147 struct gsm_auth_tuple atuple;
148 int status = -1, rc;
149
150 /* Check if we _can_ enable encryption. Cases where we can't:
151 * - Encryption disabled in config
152 * - Channel already secured (nothing to do)
153 * - Subscriber equipment doesn't support configured encryption
154 */
155 if (!net->a5_encryption) {
156 status = GSM_SECURITY_NOAVAIL;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800157 } else if (conn->lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
Sylvain Munaut30a15382009-12-24 00:27:26 +0100158 DEBUGP(DMM, "Requesting to secure an already secure channel");
159 status = GSM_SECURITY_SUCCEEDED;
160 } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2,
161 net->a5_encryption)) {
162 DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption");
163 status = GSM_SECURITY_NOAVAIL;
164 }
165
166 /* If not done yet, try to get info for this user */
167 if (status < 0) {
168 rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq);
169 if (rc <= 0)
170 status = GSM_SECURITY_NOAVAIL;
171 }
172
173 /* Are we done yet ? */
174 if (status >= 0)
175 return cb ?
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800176 cb(GSM_HOOK_RR_SECURITY, status, NULL, conn, cb_data) :
Sylvain Munaut30a15382009-12-24 00:27:26 +0100177 0;
178
179 /* Start an operation (can't have more than one pending !!!) */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800180 if (conn->sec_operation)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100181 return -EBUSY;
182
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800183 allocate_security_operation(conn);
184 op = conn->sec_operation;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100185 op->cb = cb;
186 op->cb_data = cb_data;
187 memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple));
188
189 /* FIXME: Should start a timer for completion ... */
190
191 /* Then do whatever is needed ... */
192 if (rc == 1) {
193 /* Start authentication */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800194 return gsm48_tx_mm_auth_req(conn, op->atuple.rand, op->atuple.key_seq);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100195 } else if (rc == 2) {
196 /* Start ciphering directly */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800197 conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
198 conn->lchan->encr.key_len = 8;
199 memcpy(conn->lchan->encr.key, op->atuple.kc, 8);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100200
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800201 return gsm48_send_rr_ciph_mode(conn->lchan, 0);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100202 }
203
204 return -EINVAL; /* not reached */
205}
206
Holger Freyther73487a22008-12-31 18:53:57 +0000207static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
208 struct gsm_subscriber *subscriber)
Holger Freyther89824fc2008-12-30 16:18:18 +0000209{
210 if (!subscriber)
211 return 0;
212
Holger Freyther73487a22008-12-31 18:53:57 +0000213 /*
214 * Do not send accept yet as more information should arrive. Some
215 * phones will not send us the information and we will have to check
216 * what we want to do with that.
217 */
218 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
219 return 0;
220
Jan Luebbe06513f22009-08-12 12:48:00 +0200221 switch (subscriber->net->auth_policy) {
222 case GSM_AUTH_POLICY_CLOSED:
223 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200224 case GSM_AUTH_POLICY_TOKEN:
Harald Welte (local)ee9afe32009-08-13 20:44:23 +0200225 if (subscriber->authorized)
226 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200227 return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
Jan Luebbe06513f22009-08-12 12:48:00 +0200228 case GSM_AUTH_POLICY_ACCEPT_ALL:
Holger Freyther89824fc2008-12-30 16:18:18 +0000229 return 1;
Jan Luebbe06513f22009-08-12 12:48:00 +0200230 default:
231 return 0;
232 }
Holger Freyther89824fc2008-12-30 16:18:18 +0000233}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000234
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100235static void release_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000236{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100237 if (!conn->loc_operation)
Holger Freyther73487a22008-12-31 18:53:57 +0000238 return;
239
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800240 /* No need to keep the connection up */
241 release_anchor(conn);
242
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100243 bsc_del_timer(&conn->loc_operation->updating_timer);
244 talloc_free(conn->loc_operation);
245 conn->loc_operation = 0;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800246 msc_release_connection(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000247}
248
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100249static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000250{
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800251 if (conn->loc_operation)
252 LOGP(DMM, LOGL_ERROR, "Connection already had operation.\n");
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100253 release_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000254
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100255 conn->loc_operation = talloc_zero(tall_locop_ctx,
Harald Welte470ec292009-06-26 20:25:23 +0200256 struct gsm_loc_updating_operation);
Holger Freyther73487a22008-12-31 18:53:57 +0000257}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000258
Sylvain Munaut267fba02009-12-24 00:28:01 +0100259static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event,
260 struct msgb *msg, void *data, void *param)
261{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800262 struct gsm_subscriber_connection *conn = data;
Sylvain Munaut267fba02009-12-24 00:28:01 +0100263 int rc = 0;
264
265 switch (event) {
266 case GSM_SECURITY_AUTH_FAILED:
267 release_loc_updating_req(conn);
268 break;
269
270 case GSM_SECURITY_NOAVAIL:
271 case GSM_SECURITY_SUCCEEDED:
272 /* We're all good */
273 db_subscriber_alloc_tmsi(conn->subscr);
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800274 rc = gsm0408_loc_upd_acc(conn, conn->subscr->tmsi);
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800275 if (conn->bts->network->send_mm_info) {
Sylvain Munaut267fba02009-12-24 00:28:01 +0100276 /* send MM INFO with network name */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800277 rc = gsm48_tx_mm_info(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100278 }
279
280 /* call subscr_update after putting the loc_upd_acc
281 * in the transmit queue, since S_SUBSCR_ATTACHED might
282 * trigger further action like SMS delivery */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800283 subscr_update(conn->subscr, conn->bts,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100284 GSM_SUBSCRIBER_UPDATE_ATTACHED);
285
286 /* try to close channel ASAP */
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800287 release_loc_updating_req(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100288 break;
289
290 default:
291 rc = -EINVAL;
292 };
293
294 return rc;
295}
296
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100297static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg)
Holger Freytherd51524f2009-06-09 08:27:07 +0000298{
Sylvain Munaut267fba02009-12-24 00:28:01 +0100299 if (authorize_subscriber(conn->loc_operation, conn->subscr))
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800300 return gsm48_secure_channel(conn,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100301 conn->loc_operation->key_seq,
302 _gsm0408_authorize_sec_cb, NULL);
Holger Freytherd51524f2009-06-09 08:27:07 +0000303 return 0;
304}
305
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800306void gsm0408_clear_request(struct gsm_subscriber_connection* conn, uint32_t cause)
Holger Freyther7c19f742009-06-06 13:54:35 +0000307{
Harald Welte4bfdfe72009-06-10 23:11:52 +0800308 struct gsm_trans *trans, *temp;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800309
310 /* avoid someone issuing a clear */
311 conn->in_release = 1;
312
Holger Freyther7c19f742009-06-06 13:54:35 +0000313 /*
314 * Cancel any outstanding location updating request
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800315 * operation taking place on the subscriber connection.
Holger Freyther7c19f742009-06-06 13:54:35 +0000316 */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800317 release_loc_updating_req(conn);
318 release_security_operation(conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800319 release_anchor(conn);
Holger Freyther7c19f742009-06-06 13:54:35 +0000320
Harald Welte4bfdfe72009-06-10 23:11:52 +0800321 /* Free all transactions that are associated with the released lchan */
Harald Weltedcaf5652009-07-23 18:56:43 +0200322 /* FIXME: this is not neccessarily the right thing to do, we should
323 * only set trans->lchan to NULL and wait for another lchan to be
324 * established to the same MM entity (phone/subscriber) */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800325 llist_for_each_entry_safe(trans, temp, &conn->bts->network->trans_list, entry) {
326 if (trans->conn == conn)
Harald Weltedcaf5652009-07-23 18:56:43 +0200327 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800328 }
Holger Freyther7c19f742009-06-06 13:54:35 +0000329}
330
Holger Freyther429e7762008-12-30 13:28:30 +0000331/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800332int gsm0408_loc_upd_rej(struct gsm_subscriber_connection *conn, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000333{
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800334 struct gsm_bts *bts = conn->bts;
Holger Hans Peter Freyther230a4d82010-06-15 19:40:05 +0800335 struct msgb *msg;
336
337 counter_inc(bts->network->stats.loc_upd_resp.reject);
338
339 msg = gsm48_create_loc_upd_rej(cause);
340 if (!msg) {
341 LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n");
342 return -1;
343 }
Harald Welte52b1f982008-12-23 20:25:15 +0000344
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800345 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000346
Harald Welte (local)198d5ad2009-12-26 22:15:28 +0100347 LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT "
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100348 "LAC=%u BTS=%u\n", conn->subscr ?
349 subscr_name(conn->subscr) : "unknown",
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800350 bts->location_area_code, bts->nr);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100351
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800352 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000353}
354
355/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800356int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000357{
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800358 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000359 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000360 struct gsm48_hdr *gh;
361 struct gsm48_loc_area_id *lai;
362 u_int8_t *mid;
363
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800364 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000365
366 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
367 gh->proto_discr = GSM48_PDISC_MM;
368 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
369
370 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Harald Welteafedeab2010-03-04 10:55:40 +0100371 gsm48_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000372 bts->network->network_code, bts->location_area_code);
373
Holger Hans Peter Freyther1494a762009-08-01 07:26:59 +0200374 mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200375 gsm48_generate_mid_from_tmsi(mid, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000376
377 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
378
Harald Welteffa55a42009-12-22 19:07:32 +0100379 counter_inc(bts->network->stats.loc_upd_resp.accept);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100380
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800381 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000382}
383
Harald Weltebf5e8df2009-02-03 12:59:45 +0000384/* Transmit Chapter 9.2.10 Identity Request */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800385static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, u_int8_t id_type)
Harald Welte231ad4f2008-12-27 11:15:38 +0000386{
387 struct msgb *msg = gsm48_msgb_alloc();
388 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000389
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800390 msg->lchan = conn->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000391
392 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
393 gh->proto_discr = GSM48_PDISC_MM;
394 gh->msg_type = GSM48_MT_MM_ID_REQ;
395 gh->data[0] = id_type;
396
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800397 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte231ad4f2008-12-27 11:15:38 +0000398}
399
Harald Welte231ad4f2008-12-27 11:15:38 +0000400
Harald Weltebf5e8df2009-02-03 12:59:45 +0000401/* Parse Chapter 9.2.11 Identity Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800402static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte231ad4f2008-12-27 11:15:38 +0000403{
404 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000405 struct gsm_lchan *lchan = msg->lchan;
Harald Welte9176bd42009-07-23 18:46:00 +0200406 struct gsm_bts *bts = lchan->ts->trx->bts;
407 struct gsm_network *net = bts->network;
Harald Welte231ad4f2008-12-27 11:15:38 +0000408 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200409 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000410
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200411 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000412 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000413 mi_type, mi_string);
414
Harald Welte7659de12009-12-13 12:39:18 +0100415 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data);
416
Harald Welte75a983f2008-12-27 21:34:06 +0000417 switch (mi_type) {
418 case GSM_MI_TYPE_IMSI:
Jan Luebbe370b41d2009-08-12 10:19:34 +0200419 /* look up subscriber based on IMSI, create if not found */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100420 if (!conn->subscr) {
421 conn->subscr = subscr_get_by_imsi(net, mi_string);
422 if (!conn->subscr)
423 conn->subscr = db_create_subscriber(net, mi_string);
Jan Luebbeb0dfc312009-08-12 10:12:52 +0200424 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100425 if (conn->loc_operation)
426 conn->loc_operation->waiting_for_imsi = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000427 break;
428 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000429 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000430 /* update subscribe <-> IMEI mapping */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100431 if (conn->subscr) {
432 db_subscriber_assoc_imei(conn->subscr, mi_string);
433 db_sync_equipment(&conn->subscr->equipment);
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200434 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100435 if (conn->loc_operation)
436 conn->loc_operation->waiting_for_imei = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000437 break;
438 }
Holger Freyther73487a22008-12-31 18:53:57 +0000439
440 /* Check if we can let the mobile station enter */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100441 return gsm0408_authorize(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000442}
443
Harald Welte255539c2008-12-28 02:26:27 +0000444
445static void loc_upd_rej_cb(void *data)
446{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100447 struct gsm_subscriber_connection *conn = data;
448 struct gsm_lchan *lchan = conn->lchan;
Harald Welte1085c092009-11-18 20:33:19 +0100449 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte255539c2008-12-28 02:26:27 +0000450
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800451 gsm0408_loc_upd_rej(conn, bts->network->reject_cause);
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800452 release_loc_updating_req(conn);
Harald Welte255539c2008-12-28 02:26:27 +0000453}
454
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100455static void schedule_reject(struct gsm_subscriber_connection *conn)
Holger Freytherb7193e42008-12-29 17:44:08 +0000456{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100457 conn->loc_operation->updating_timer.cb = loc_upd_rej_cb;
458 conn->loc_operation->updating_timer.data = conn;
459 bsc_schedule_timer(&conn->loc_operation->updating_timer, 5, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000460}
461
Harald Welte2a139372009-02-22 21:14:55 +0000462static const char *lupd_name(u_int8_t type)
463{
464 switch (type) {
465 case GSM48_LUPD_NORMAL:
466 return "NORMAL";
467 case GSM48_LUPD_PERIODIC:
468 return "PEROIDOC";
469 case GSM48_LUPD_IMSI_ATT:
470 return "IMSI ATTACH";
471 default:
472 return "UNKNOWN";
473 }
474}
475
Harald Weltebf5e8df2009-02-03 12:59:45 +0000476/* Chapter 9.2.15: Receive Location Updating Request */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800477static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000478{
Harald Welte8470bf22008-12-25 23:28:35 +0000479 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000480 struct gsm48_loc_upd_req *lu;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800481 struct gsm_subscriber *subscr = NULL;
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800482 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000483 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200484 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000485 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000486
Harald Welte8470bf22008-12-25 23:28:35 +0000487 lu = (struct gsm48_loc_upd_req *) gh->data;
488
489 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000490
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200491 gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
Harald Weltefc977a82008-12-27 10:19:37 +0000492
Harald Weltea0368542009-06-27 02:58:43 +0200493 DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
Harald Welte2a139372009-02-22 21:14:55 +0000494 lupd_name(lu->type));
Holger Freyther73487a22008-12-31 18:53:57 +0000495
Harald Welte7659de12009-12-13 12:39:18 +0100496 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len);
497
Harald Welte24ff6ee2009-12-22 00:41:05 +0100498 switch (lu->type) {
499 case GSM48_LUPD_NORMAL:
Harald Welteffa55a42009-12-22 19:07:32 +0100500 counter_inc(bts->network->stats.loc_upd_type.normal);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100501 break;
502 case GSM48_LUPD_IMSI_ATT:
Harald Welteffa55a42009-12-22 19:07:32 +0100503 counter_inc(bts->network->stats.loc_upd_type.attach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100504 break;
505 case GSM48_LUPD_PERIODIC:
Harald Welteffa55a42009-12-22 19:07:32 +0100506 counter_inc(bts->network->stats.loc_upd_type.periodic);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100507 break;
508 }
509
Holger Freythereaf04692009-06-06 13:54:44 +0000510 /*
511 * Pseudo Spoof detection: Just drop a second/concurrent
512 * location updating request.
513 */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100514 if (conn->loc_operation) {
Harald Weltea0368542009-06-27 02:58:43 +0200515 DEBUGPC(DMM, "ignoring request due an existing one: %p.\n",
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100516 conn->loc_operation);
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800517 gsm0408_loc_upd_rej(conn, GSM48_REJECT_PROTOCOL_ERROR);
Holger Freythereaf04692009-06-06 13:54:44 +0000518 return 0;
519 }
520
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800521 allocate_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000522
Sylvain Munaut2030a2a2010-06-10 13:36:59 +0200523 conn->loc_operation->key_seq = lu->key_seq;
524
Harald Welte52b1f982008-12-23 20:25:15 +0000525 switch (mi_type) {
526 case GSM_MI_TYPE_IMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200527 DEBUGPC(DMM, "\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000528 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800529 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100530 conn->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000531
Jan Luebbe370b41d2009-08-12 10:19:34 +0200532 /* look up subscriber based on IMSI, create if not found */
533 subscr = subscr_get_by_imsi(bts->network, mi_string);
534 if (!subscr) {
535 subscr = db_create_subscriber(bts->network, mi_string);
536 }
Harald Welte4b634542008-12-27 01:55:51 +0000537 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000538 case GSM_MI_TYPE_TMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200539 DEBUGPC(DMM, "\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000540 /* look up the subscriber based on TMSI, request IMSI if it fails */
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200541 subscr = subscr_get_by_tmsi(bts->network,
542 tmsi_from_string(mi_string));
Harald Welte52b1f982008-12-23 20:25:15 +0000543 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000544 /* send IDENTITY REQUEST message to get IMSI */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800545 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMSI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100546 conn->loc_operation->waiting_for_imsi = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000547 }
Harald Weltef5f512c2010-06-07 17:56:32 +0200548 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800549 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Harald Weltef5f512c2010-06-07 17:56:32 +0200550 conn->loc_operation->waiting_for_imei = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000551 break;
552 case GSM_MI_TYPE_IMEI:
553 case GSM_MI_TYPE_IMEISV:
554 /* no sim card... FIXME: what to do ? */
Harald Weltea0368542009-06-27 02:58:43 +0200555 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000556 break;
557 default:
Harald Weltea0368542009-06-27 02:58:43 +0200558 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000559 break;
560 }
561
Harald Welte24516ea2009-07-04 10:18:00 +0200562 /* schedule the reject timer */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100563 schedule_reject(conn);
Harald Welte24516ea2009-07-04 10:18:00 +0200564
Harald Welte4bfdfe72009-06-10 23:11:52 +0800565 if (!subscr) {
Harald Weltea0368542009-06-27 02:58:43 +0200566 DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte4bfdfe72009-06-10 23:11:52 +0800567 /* FIXME: request id? close channel? */
568 return -EINVAL;
569 }
570
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100571 conn->subscr = subscr;
572 conn->subscr->equipment.classmark1 = lu->classmark1;
Harald Welte255539c2008-12-28 02:26:27 +0000573
Harald Welte24516ea2009-07-04 10:18:00 +0200574 /* check if we can let the subscriber into our network immediately
575 * or if we need to wait for identity responses. */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100576 return gsm0408_authorize(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000577}
578
Harald Welte4bfdfe72009-06-10 23:11:52 +0800579#if 0
580static u_int8_t to_bcd8(u_int8_t val)
581{
582 return ((val / 10) << 4) | (val % 10);
583}
584#endif
585
Harald Weltedb253af2008-12-30 17:56:55 +0000586/* Section 9.2.15a */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800587int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
Harald Weltedb253af2008-12-30 17:56:55 +0000588{
589 struct msgb *msg = gsm48_msgb_alloc();
590 struct gsm48_hdr *gh;
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800591 struct gsm_network *net = conn->bts->network;
Harald Weltedb253af2008-12-30 17:56:55 +0000592 u_int8_t *ptr8;
Daniel Willmanneea93372009-08-13 03:42:07 +0200593 int name_len, name_pad;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800594#if 0
595 time_t cur_t;
596 struct tm* cur_time;
597 int tz15min;
598#endif
Harald Weltedb253af2008-12-30 17:56:55 +0000599
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800600 msg->lchan = conn->lchan;
Harald Weltedb253af2008-12-30 17:56:55 +0000601
602 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
603 gh->proto_discr = GSM48_PDISC_MM;
604 gh->msg_type = GSM48_MT_MM_INFO;
605
606 if (net->name_long) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200607#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000608 name_len = strlen(net->name_long);
609 /* 10.5.3.5a */
610 ptr8 = msgb_put(msg, 3);
611 ptr8[0] = GSM48_IE_NAME_LONG;
612 ptr8[1] = name_len*2 +1;
613 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
614
615 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
616 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000617 ptr16[i] = htons(net->name_long[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000618
619 /* FIXME: Use Cell Broadcast, not UCS-2, since
620 * UCS-2 is only supported by later revisions of the spec */
Daniel Willmanneea93372009-08-13 03:42:07 +0200621#endif
622 name_len = (strlen(net->name_long)*7)/8;
623 name_pad = (8 - strlen(net->name_long)*7)%8;
624 if (name_pad > 0)
625 name_len++;
626 /* 10.5.3.5a */
627 ptr8 = msgb_put(msg, 3);
628 ptr8[0] = GSM48_IE_NAME_LONG;
629 ptr8[1] = name_len +1;
630 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
631
632 ptr8 = msgb_put(msg, name_len);
633 gsm_7bit_encode(ptr8, net->name_long);
634
Harald Weltedb253af2008-12-30 17:56:55 +0000635 }
636
637 if (net->name_short) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200638#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000639 name_len = strlen(net->name_short);
640 /* 10.5.3.5a */
641 ptr8 = (u_int8_t *) msgb_put(msg, 3);
Harald Welte7543eb72009-07-19 17:51:36 +0200642 ptr8[0] = GSM48_IE_NAME_SHORT;
Harald Weltedb253af2008-12-30 17:56:55 +0000643 ptr8[1] = name_len*2 + 1;
644 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
645
Harald Weltee872cb12009-01-01 00:33:37 +0000646 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
Harald Weltedb253af2008-12-30 17:56:55 +0000647 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000648 ptr16[i] = htons(net->name_short[i]);
Daniel Willmanneea93372009-08-13 03:42:07 +0200649#endif
650 name_len = (strlen(net->name_short)*7)/8;
651 name_pad = (8 - strlen(net->name_short)*7)%8;
652 if (name_pad > 0)
653 name_len++;
654 /* 10.5.3.5a */
655 ptr8 = (u_int8_t *) msgb_put(msg, 3);
656 ptr8[0] = GSM48_IE_NAME_SHORT;
657 ptr8[1] = name_len +1;
658 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
659
660 ptr8 = msgb_put(msg, name_len);
661 gsm_7bit_encode(ptr8, net->name_short);
662
Harald Weltedb253af2008-12-30 17:56:55 +0000663 }
664
665#if 0
666 /* Section 10.5.3.9 */
667 cur_t = time(NULL);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800668 cur_time = gmtime(&cur_t);
Harald Weltedb253af2008-12-30 17:56:55 +0000669 ptr8 = msgb_put(msg, 8);
670 ptr8[0] = GSM48_IE_NET_TIME_TZ;
671 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
672 ptr8[2] = to_bcd8(cur_time->tm_mon);
673 ptr8[3] = to_bcd8(cur_time->tm_mday);
674 ptr8[4] = to_bcd8(cur_time->tm_hour);
675 ptr8[5] = to_bcd8(cur_time->tm_min);
676 ptr8[6] = to_bcd8(cur_time->tm_sec);
677 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
678 tz15min = (cur_time->tm_gmtoff)/(60*15);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800679 ptr8[7] = to_bcd8(tz15min);
Harald Weltedb253af2008-12-30 17:56:55 +0000680 if (tz15min < 0)
Harald Welte4bfdfe72009-06-10 23:11:52 +0800681 ptr8[7] |= 0x80;
Harald Weltedb253af2008-12-30 17:56:55 +0000682#endif
683
Daniel Willmanneea93372009-08-13 03:42:07 +0200684 DEBUGP(DMM, "-> MM INFO\n");
685
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800686 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Weltedb253af2008-12-30 17:56:55 +0000687}
688
Harald Welte7984d5c2009-08-12 22:56:50 +0200689/* Section 9.2.2 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800690int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, u_int8_t *rand, int key_seq)
Harald Welte7984d5c2009-08-12 22:56:50 +0200691{
692 struct msgb *msg = gsm48_msgb_alloc();
693 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Sylvain Munaut849f5542009-09-27 11:10:17 +0200694 struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar));
Harald Welte7984d5c2009-08-12 22:56:50 +0200695
Sylvain Munaut8608e7c2009-12-24 00:24:29 +0100696 DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", hexdump(rand, 16));
Harald Welte7984d5c2009-08-12 22:56:50 +0200697
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800698 msg->lchan = conn->lchan;
Harald Welte7984d5c2009-08-12 22:56:50 +0200699 gh->proto_discr = GSM48_PDISC_MM;
700 gh->msg_type = GSM48_MT_MM_AUTH_REQ;
701
Sylvain Munautbd55a6d2009-12-24 00:23:46 +0100702 ar->key_seq = key_seq;
Sylvain Munaut849f5542009-09-27 11:10:17 +0200703
Harald Welte7984d5c2009-08-12 22:56:50 +0200704 /* 16 bytes RAND parameters */
Harald Welte7984d5c2009-08-12 22:56:50 +0200705 if (rand)
Sylvain Munaut849f5542009-09-27 11:10:17 +0200706 memcpy(ar->rand, rand, 16);
Harald Welte7984d5c2009-08-12 22:56:50 +0200707
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800708 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte7984d5c2009-08-12 22:56:50 +0200709}
710
711/* Section 9.2.1 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800712int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn)
Harald Welte7984d5c2009-08-12 22:56:50 +0200713{
714 DEBUGP(DMM, "-> AUTH REJECT\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800715 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ);
Harald Welte7984d5c2009-08-12 22:56:50 +0200716}
717
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800718static int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
Harald Welte4b634542008-12-27 01:55:51 +0000719{
Harald Welte4b634542008-12-27 01:55:51 +0000720 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800721 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000722}
Harald Welteba4cf162009-01-10 01:49:35 +0000723
724/* 9.2.6 CM service reject */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100725static int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000726 enum gsm48_reject_value value)
727{
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800728 struct msgb *msg;
Harald Welteba4cf162009-01-10 01:49:35 +0000729
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800730 msg = gsm48_create_mm_serv_rej(value);
731 if (!msg) {
732 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
733 return -1;
734 }
Harald Welteba4cf162009-01-10 01:49:35 +0000735
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800736 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100737 msg->lchan = conn->lchan;
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800738 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welteba4cf162009-01-10 01:49:35 +0000739}
740
Sylvain Munautba87f452009-12-24 00:28:46 +0100741static int _gsm48_rx_mm_serv_req_sec_cb(
742 unsigned int hooknum, unsigned int event,
743 struct msgb *msg, void *data, void *param)
744{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800745 struct gsm_subscriber_connection *conn = data;
Sylvain Munautba87f452009-12-24 00:28:46 +0100746 int rc = 0;
747
748 switch (event) {
749 case GSM_SECURITY_AUTH_FAILED:
750 /* Nothing to do */
751 break;
752
753 case GSM_SECURITY_NOAVAIL:
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800754 rc = gsm48_tx_mm_serv_ack(conn);
Sylvain Munautba87f452009-12-24 00:28:46 +0100755 break;
756
757 case GSM_SECURITY_SUCCEEDED:
758 /* nothing to do. CIPHER MODE COMMAND is
759 * implicit CM SERV ACK */
760 break;
761
762 default:
763 rc = -EINVAL;
764 };
765
766 return rc;
767}
768
Harald Welte4ed0e922009-01-10 03:17:30 +0000769/*
770 * Handle CM Service Requests
771 * a) Verify that the packet is long enough to contain the information
772 * we require otherwsie reject with INCORRECT_MESSAGE
773 * b) Try to parse the TMSI. If we do not have one reject
774 * c) Check that we know the subscriber with the TMSI otherwise reject
775 * with a HLR cause
776 * d) Set the subscriber on the gsm_lchan and accept
777 */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800778static int gsm48_rx_mm_serv_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4b634542008-12-27 01:55:51 +0000779{
Harald Welteba4cf162009-01-10 01:49:35 +0000780 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200781 char mi_string[GSM48_MI_SIZE];
Harald Welte4b634542008-12-27 01:55:51 +0000782
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800783 struct gsm_bts *bts = conn->bts;
Harald Welteba4cf162009-01-10 01:49:35 +0000784 struct gsm_subscriber *subscr;
785 struct gsm48_hdr *gh = msgb_l3(msg);
786 struct gsm48_service_request *req =
787 (struct gsm48_service_request *)gh->data;
Holger Hans Peter Freyther5d658062010-05-14 08:02:08 +0800788 /* unfortunately in Phase1 the classmark2 length is variable */
Harald Weltec9e02182009-05-01 19:07:53 +0000789 u_int8_t classmark2_len = gh->data[1];
790 u_int8_t *classmark2 = gh->data+2;
791 u_int8_t mi_len = *(classmark2 + classmark2_len);
792 u_int8_t *mi = (classmark2 + classmark2_len + 1);
Harald Welteba4cf162009-01-10 01:49:35 +0000793
Harald Weltec9e02182009-05-01 19:07:53 +0000794 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
Harald Welteba4cf162009-01-10 01:49:35 +0000795 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
Harald Weltec9e02182009-05-01 19:07:53 +0000796 DEBUGPC(DMM, "wrong sized message\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800797 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000798 GSM48_REJECT_INCORRECT_MESSAGE);
799 }
800
801 if (msg->data_len < req->mi_len + 6) {
Harald Weltec9e02182009-05-01 19:07:53 +0000802 DEBUGPC(DMM, "does not fit in packet\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800803 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000804 GSM48_REJECT_INCORRECT_MESSAGE);
805 }
806
Harald Weltec9e02182009-05-01 19:07:53 +0000807 mi_type = mi[0] & GSM_MI_TYPE_MASK;
Harald Welteba4cf162009-01-10 01:49:35 +0000808 if (mi_type != GSM_MI_TYPE_TMSI) {
Harald Weltec9e02182009-05-01 19:07:53 +0000809 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800810 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000811 GSM48_REJECT_INCORRECT_MESSAGE);
812 }
813
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200814 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Weltec9e02182009-05-01 19:07:53 +0000815 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
Harald Welte4ed0e922009-01-10 03:17:30 +0000816 req->cm_service_type, mi_type, mi_string);
Harald Weltebcae43f2008-12-27 21:45:37 +0000817
Harald Welte7659de12009-12-13 12:39:18 +0100818 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len));
819
Harald Welte3ac7f102009-08-10 10:12:45 +0200820 if (is_siemens_bts(bts))
821 send_siemens_mrpci(msg->lchan, classmark2-1);
822
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200823 subscr = subscr_get_by_tmsi(bts->network,
824 tmsi_from_string(mi_string));
Holger Freythereb443982009-06-04 13:58:42 +0000825
Harald Welte2a139372009-02-22 21:14:55 +0000826 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
Harald Welte4ed0e922009-01-10 03:17:30 +0000827 if (!subscr)
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800828 return gsm48_tx_mm_serv_rej(conn,
Harald Welte4ed0e922009-01-10 03:17:30 +0000829 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
830
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800831 if (!conn->subscr)
832 conn->subscr = subscr;
833 else if (conn->subscr == subscr)
Sylvain Munautea3f6742009-12-18 18:28:10 +0100834 subscr_put(subscr); /* lchan already has a ref, don't need another one */
835 else {
Harald Welte9bb7c702009-01-10 03:21:41 +0000836 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
837 subscr_put(subscr);
838 }
839
Harald Weltec2e302d2009-07-05 14:08:13 +0200840 subscr->equipment.classmark2_len = classmark2_len;
841 memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
842 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +0000843
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800844 return gsm48_secure_channel(conn, req->cipher_key_seq,
Sylvain Munautba87f452009-12-24 00:28:46 +0100845 _gsm48_rx_mm_serv_req_sec_cb, NULL);
Harald Welte4b634542008-12-27 01:55:51 +0000846}
847
Harald Welte2a139372009-02-22 21:14:55 +0000848static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
849{
Harald Welte9176bd42009-07-23 18:46:00 +0200850 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte2a139372009-02-22 21:14:55 +0000851 struct gsm48_hdr *gh = msgb_l3(msg);
852 struct gsm48_imsi_detach_ind *idi =
853 (struct gsm48_imsi_detach_ind *) gh->data;
854 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200855 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +0800856 struct gsm_subscriber *subscr = NULL;
Harald Welte2a139372009-02-22 21:14:55 +0000857
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200858 gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
Harald Welte2a139372009-02-22 21:14:55 +0000859 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
860 mi_type, mi_string);
861
Harald Welteffa55a42009-12-22 19:07:32 +0100862 counter_inc(bts->network->stats.loc_upd_type.detach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100863
Harald Welte2a139372009-02-22 21:14:55 +0000864 switch (mi_type) {
865 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200866 subscr = subscr_get_by_tmsi(bts->network,
867 tmsi_from_string(mi_string));
Harald Welte2a139372009-02-22 21:14:55 +0000868 break;
869 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +0200870 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte2a139372009-02-22 21:14:55 +0000871 break;
872 case GSM_MI_TYPE_IMEI:
873 case GSM_MI_TYPE_IMEISV:
874 /* no sim card... FIXME: what to do ? */
Holger Freyther79f4ae62009-06-02 03:25:04 +0000875 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000876 break;
877 default:
Holger Freyther79f4ae62009-06-02 03:25:04 +0000878 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000879 break;
880 }
881
Holger Freyther4a49e772009-04-12 05:37:29 +0000882 if (subscr) {
883 subscr_update(subscr, msg->trx->bts,
884 GSM_SUBSCRIBER_UPDATE_DETACHED);
Harald Welte2e6d4682009-12-24 14:50:24 +0100885 DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr));
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200886
887 subscr->equipment.classmark1 = idi->classmark1;
888 db_sync_equipment(&subscr->equipment);
889
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000890 subscr_put(subscr);
Holger Freyther4a49e772009-04-12 05:37:29 +0000891 } else
Harald Welte2a139372009-02-22 21:14:55 +0000892 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
893
Harald Welte31981a02009-12-20 09:58:40 +0100894 /* FIXME: iterate over all transactions and release them,
895 * imagine an IMSI DETACH happening during an active call! */
896
Harald Welteb83d9382009-12-12 21:00:48 +0100897 /* subscriber is detached: should we release lchan? */
Harald Welte2a139372009-02-22 21:14:55 +0000898 return 0;
899}
900
Harald Welted2a7f5a2009-06-05 20:08:20 +0000901static int gsm48_rx_mm_status(struct msgb *msg)
902{
903 struct gsm48_hdr *gh = msgb_l3(msg);
904
905 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
906
907 return 0;
908}
909
Sylvain Munaut30a15382009-12-24 00:27:26 +0100910/* Chapter 9.2.3: Authentication Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800911static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100912{
913 struct gsm48_hdr *gh = msgb_l3(msg);
914 struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800915 struct gsm_network *net = conn->bts->network;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100916
Sylvain Munautc593cf12010-06-10 23:51:41 +0200917 DEBUGP(DMM, "MM AUTHENTICATION RESPONSE (sres = %s): ",
Sylvain Munaut30a15382009-12-24 00:27:26 +0100918 hexdump(ar->sres, 4));
919
920 /* Safety check */
921 if (!conn->sec_operation) {
922 DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n");
923 return -EIO;
924 }
925
926 /* Validate SRES */
927 if (memcmp(conn->sec_operation->atuple.sres, ar->sres,4)) {
928 gsm_cbfn *cb = conn->sec_operation->cb;
Sylvain Munautc593cf12010-06-10 23:51:41 +0200929
930 DEBUGPC(DMM, "Invalid (expected %s)\n",
931 hexdump(conn->sec_operation->atuple.sres, 4));
932
Sylvain Munaut30a15382009-12-24 00:27:26 +0100933 if (cb)
934 cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800935 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100936
937 release_security_operation(conn);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800938 return gsm48_tx_mm_auth_rej(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100939 }
940
Sylvain Munautc593cf12010-06-10 23:51:41 +0200941 DEBUGPC(DMM, "OK\n");
942
Sylvain Munaut30a15382009-12-24 00:27:26 +0100943 /* Start ciphering */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800944 conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
945 conn->lchan->encr.key_len = 8;
946 memcpy(conn->lchan->encr.key, conn->sec_operation->atuple.kc, 8);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100947
948 return gsm48_send_rr_ciph_mode(msg->lchan, 0);
949}
950
Harald Weltebf5e8df2009-02-03 12:59:45 +0000951/* Receive a GSM 04.08 Mobility Management (MM) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800952static int gsm0408_rcv_mm(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000953{
954 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800955 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000956
957 switch (gh->msg_type & 0xbf) {
958 case GSM48_MT_MM_LOC_UPD_REQUEST:
Harald Weltea0368542009-06-27 02:58:43 +0200959 DEBUGP(DMM, "LOCATION UPDATING REQUEST: ");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800960 rc = mm_rx_loc_upd_req(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000961 break;
962 case GSM48_MT_MM_ID_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800963 rc = mm_rx_id_resp(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000964 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000965 case GSM48_MT_MM_CM_SERV_REQ:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800966 rc = gsm48_rx_mm_serv_req(conn, msg);
Harald Welte4b634542008-12-27 01:55:51 +0000967 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000968 case GSM48_MT_MM_STATUS:
Harald Welted2a7f5a2009-06-05 20:08:20 +0000969 rc = gsm48_rx_mm_status(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000970 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000971 case GSM48_MT_MM_TMSI_REALL_COMPL:
Harald Welte69b2af22009-01-06 19:47:00 +0000972 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800973 conn->subscr ?
974 subscr_name(conn->subscr) :
Harald Welte69b2af22009-01-06 19:47:00 +0000975 "unknown subscriber");
976 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000977 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte2a139372009-02-22 21:14:55 +0000978 rc = gsm48_rx_mm_imsi_detach_ind(msg);
979 break;
980 case GSM48_MT_MM_CM_REEST_REQ:
981 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
982 break;
983 case GSM48_MT_MM_AUTH_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800984 rc = gsm48_rx_mm_auth_resp(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000985 break;
986 default:
Harald Welte5d24ba12009-12-24 12:13:17 +0100987 LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n",
Harald Welte52b1f982008-12-23 20:25:15 +0000988 gh->msg_type);
989 break;
990 }
991
992 return rc;
993}
Harald Weltebf5e8df2009-02-03 12:59:45 +0000994
Harald Welte2d35ae62009-02-06 12:02:13 +0000995/* Receive a PAGING RESPONSE message from the MS */
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +0800996static int gsm48_rx_rr_pag_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte2d35ae62009-02-06 12:02:13 +0000997{
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +0800998 struct gsm_bts *bts = conn->bts;
Harald Welte2d35ae62009-02-06 12:02:13 +0000999 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +08001000 struct gsm48_pag_resp *resp;
Harald Welte61548982009-02-22 21:26:29 +00001001 u_int8_t *classmark2_lv = gh->data + 1;
Holger Hans Peter Freyther3ee5d3e2009-08-21 05:18:21 +02001002 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +02001003 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +08001004 struct gsm_subscriber *subscr = NULL;
Harald Welte2d35ae62009-02-06 12:02:13 +00001005 int rc = 0;
1006
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +08001007 resp = (struct gsm48_pag_resp *) &gh->data[0];
1008 gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
1009 mi_string, &mi_type);
Harald Welte2d35ae62009-02-06 12:02:13 +00001010 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
1011 mi_type, mi_string);
Harald Welte3ac7f102009-08-10 10:12:45 +02001012
Harald Weltefe18d8f2009-02-22 21:14:24 +00001013 switch (mi_type) {
1014 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +02001015 subscr = subscr_get_by_tmsi(bts->network,
1016 tmsi_from_string(mi_string));
Harald Weltefe18d8f2009-02-22 21:14:24 +00001017 break;
1018 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +02001019 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Weltefe18d8f2009-02-22 21:14:24 +00001020 break;
1021 }
Harald Welte2d35ae62009-02-06 12:02:13 +00001022
1023 if (!subscr) {
1024 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001025 /* FIXME: request id? close channel? */
Harald Welte2d35ae62009-02-06 12:02:13 +00001026 return -EINVAL;
1027 }
1028 DEBUGP(DRR, "<- Channel was requested by %s\n",
Harald Welte76042182009-08-08 16:03:15 +02001029 subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi);
Holger Freyther053e09d2009-02-14 22:51:06 +00001030
Harald Weltec2e302d2009-07-05 14:08:13 +02001031 subscr->equipment.classmark2_len = *classmark2_lv;
1032 memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
1033 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001034
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001035 rc = gsm48_handle_paging_resp(conn, msg, subscr);
Harald Welte2d35ae62009-02-06 12:02:13 +00001036 return rc;
1037}
1038
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001039static int gsm48_rx_rr_classmark(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Weltef7c43522009-06-09 20:24:21 +00001040{
1041 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001042 struct gsm_subscriber *subscr = conn->subscr;
Harald Weltef7c43522009-06-09 20:24:21 +00001043 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1044 u_int8_t cm2_len, cm3_len = 0;
1045 u_int8_t *cm2, *cm3 = NULL;
1046
1047 DEBUGP(DRR, "CLASSMARK CHANGE ");
1048
1049 /* classmark 2 */
1050 cm2_len = gh->data[0];
1051 cm2 = &gh->data[1];
1052 DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
1053
1054 if (payload_len > cm2_len + 1) {
1055 /* we must have a classmark3 */
1056 if (gh->data[cm2_len+1] != 0x20) {
1057 DEBUGPC(DRR, "ERR CM3 TAG\n");
1058 return -EINVAL;
1059 }
1060 if (cm2_len > 3) {
1061 DEBUGPC(DRR, "CM2 too long!\n");
1062 return -EINVAL;
1063 }
1064
1065 cm3_len = gh->data[cm2_len+2];
1066 cm3 = &gh->data[cm2_len+3];
1067 if (cm3_len > 14) {
1068 DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
1069 return -EINVAL;
1070 }
1071 DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
1072 }
1073 if (subscr) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001074 subscr->equipment.classmark2_len = cm2_len;
1075 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001076 if (cm3) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001077 subscr->equipment.classmark3_len = cm3_len;
1078 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001079 }
Harald Weltec2e302d2009-07-05 14:08:13 +02001080 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001081 }
1082
Harald Weltef7c43522009-06-09 20:24:21 +00001083 return 0;
1084}
1085
Harald Weltecf5b3592009-05-01 18:28:42 +00001086static int gsm48_rx_rr_status(struct msgb *msg)
1087{
1088 struct gsm48_hdr *gh = msgb_l3(msg);
1089
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001090 DEBUGP(DRR, "STATUS rr_cause = %s\n",
Harald Weltecf5b3592009-05-01 18:28:42 +00001091 rr_cause_name(gh->data[0]));
1092
1093 return 0;
1094}
1095
Harald Weltef7c43522009-06-09 20:24:21 +00001096static int gsm48_rx_rr_meas_rep(struct msgb *msg)
1097{
Harald Welted12b0fd2009-12-15 21:36:05 +01001098 struct gsm_meas_rep *meas_rep = lchan_next_meas_rep(msg->lchan);
Harald Weltef7c43522009-06-09 20:24:21 +00001099
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001100 /* This shouldn't actually end up here, as RSL treats
1101 * L3 Info of 08.58 MEASUREMENT REPORT different by calling
1102 * directly into gsm48_parse_meas_rep */
1103 DEBUGP(DMEAS, "DIRECT GSM48 MEASUREMENT REPORT ?!? ");
Harald Welted12b0fd2009-12-15 21:36:05 +01001104 gsm48_parse_meas_rep(meas_rep, msg);
Harald Weltef7c43522009-06-09 20:24:21 +00001105
1106 return 0;
1107}
1108
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001109static int gsm48_rx_rr_app_info(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001110{
1111 struct gsm48_hdr *gh = msgb_l3(msg);
1112 u_int8_t apdu_id_flags;
1113 u_int8_t apdu_len;
1114 u_int8_t *apdu_data;
1115
1116 apdu_id_flags = gh->data[0];
1117 apdu_len = gh->data[1];
1118 apdu_data = gh->data+2;
1119
1120 DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s",
1121 apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len));
1122
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001123 return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001124}
1125
Sylvain Munaut30a15382009-12-24 00:27:26 +01001126/* Chapter 9.1.10 Ciphering Mode Complete */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001127static int gsm48_rx_rr_ciph_m_compl(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +01001128{
Sylvain Munaut30a15382009-12-24 00:27:26 +01001129 gsm_cbfn *cb;
1130 int rc = 0;
1131
1132 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
1133
1134 /* Safety check */
1135 if (!conn->sec_operation) {
1136 DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n");
1137 return -EIO;
1138 }
1139
1140 /* FIXME: check for MI (if any) */
1141
1142 /* Call back whatever was in progress (if anything) ... */
1143 cb = conn->sec_operation->cb;
1144 if (cb) {
1145 rc = cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +08001146 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +01001147 }
1148
1149 /* Complete the operation */
1150 release_security_operation(conn);
1151
1152 return rc;
1153}
1154
Harald Welted011e8b2009-11-29 22:45:52 +01001155/* Chapter 9.1.16 Handover complete */
Harald Welte1e191c52009-12-14 17:51:15 +01001156static int gsm48_rx_rr_ho_compl(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001157{
1158 struct gsm48_hdr *gh = msgb_l3(msg);
1159
1160 DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n",
1161 rr_cause_name(gh->data[0]));
1162
1163 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, msg->lchan);
1164 /* FIXME: release old channel */
1165
1166 return 0;
1167}
1168
1169/* Chapter 9.1.17 Handover Failure */
Harald Welte1e191c52009-12-14 17:51:15 +01001170static int gsm48_rx_rr_ho_fail(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001171{
1172 struct gsm48_hdr *gh = msgb_l3(msg);
1173
1174 DEBUGP(DRR, "HANDOVER FAILED cause = %s\n",
1175 rr_cause_name(gh->data[0]));
1176
1177 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, msg->lchan);
1178 /* FIXME: release allocated new channel */
1179
1180 return 0;
1181}
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001182
Harald Weltebf5e8df2009-02-03 12:59:45 +00001183/* Receive a GSM 04.08 Radio Resource (RR) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001184static int gsm0408_rcv_rr(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001185{
1186 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001187 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001188
1189 switch (gh->msg_type) {
1190 case GSM48_MT_RR_CLSM_CHG:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001191 rc = gsm48_rx_rr_classmark(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001192 break;
Harald Weltefc977a82008-12-27 10:19:37 +00001193 case GSM48_MT_RR_GPRS_SUSP_REQ:
1194 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1195 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001196 case GSM48_MT_RR_PAG_RESP:
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001197 rc = gsm48_rx_rr_pag_resp(conn, msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001198 break;
Harald Welte7ccf7782009-02-17 01:43:01 +00001199 case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
Holger Hans Peter Freytherf520e642009-10-22 15:23:11 +02001200 rc = gsm48_rx_rr_modif_ack(msg);
Harald Welte7ccf7782009-02-17 01:43:01 +00001201 break;
Harald Weltecf5b3592009-05-01 18:28:42 +00001202 case GSM48_MT_RR_STATUS:
1203 rc = gsm48_rx_rr_status(msg);
1204 break;
Harald Weltef7c43522009-06-09 20:24:21 +00001205 case GSM48_MT_RR_MEAS_REP:
1206 rc = gsm48_rx_rr_meas_rep(msg);
1207 break;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001208 case GSM48_MT_RR_APP_INFO:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001209 rc = gsm48_rx_rr_app_info(conn, msg);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001210 break;
Harald Welte08d91a52009-08-30 15:37:11 +09001211 case GSM48_MT_RR_CIPH_M_COMPL:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001212 rc = gsm48_rx_rr_ciph_m_compl(conn, msg);
Harald Welte08d91a52009-08-30 15:37:11 +09001213 break;
Harald Welteccd5a882009-11-29 20:02:20 +01001214 case GSM48_MT_RR_HANDO_COMPL:
Harald Welted011e8b2009-11-29 22:45:52 +01001215 rc = gsm48_rx_rr_ho_compl(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001216 break;
1217 case GSM48_MT_RR_HANDO_FAIL:
Harald Welted011e8b2009-11-29 22:45:52 +01001218 rc = gsm48_rx_rr_ho_fail(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001219 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001220 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01001221 LOGP(DRR, LOGL_NOTICE, "Unimplemented "
1222 "GSM 04.08 RR msg type 0x%02x\n", gh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001223 break;
1224 }
1225
Harald Welte2d35ae62009-02-06 12:02:13 +00001226 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001227}
1228
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001229int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, u_int8_t apdu_id,
Holger Hans Peter Freyther8b77a342009-10-22 15:42:19 +02001230 u_int8_t apdu_len, const u_int8_t *apdu)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001231{
1232 struct msgb *msg = gsm48_msgb_alloc();
1233 struct gsm48_hdr *gh;
1234
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001235 msg->lchan = conn->lchan;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001236
1237 DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n",
1238 apdu_id, apdu_len);
1239
1240 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len);
1241 gh->proto_discr = GSM48_PDISC_RR;
1242 gh->msg_type = GSM48_MT_RR_APP_INFO;
1243 gh->data[0] = apdu_id;
1244 gh->data[1] = apdu_len;
1245 memcpy(gh->data+2, apdu, apdu_len);
1246
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001247 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001248}
1249
Harald Welte4bc90a12008-12-27 16:32:52 +00001250/* Call Control */
1251
Harald Welte7584aea2009-02-11 11:44:12 +00001252/* The entire call control code is written in accordance with Figure 7.10c
1253 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1254 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1255 * it for voice */
1256
Harald Welte4bfdfe72009-06-10 23:11:52 +08001257static void new_cc_state(struct gsm_trans *trans, int state)
1258{
1259 if (state > 31 || state < 0)
1260 return;
1261
1262 DEBUGP(DCC, "new state %s -> %s\n",
Harald Weltee95daf192010-03-25 12:13:02 +08001263 gsm48_cc_state_name(trans->cc.state),
1264 gsm48_cc_state_name(state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001265
Harald Weltedcaf5652009-07-23 18:56:43 +02001266 trans->cc.state = state;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001267}
1268
1269static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
Harald Welte4bc90a12008-12-27 16:32:52 +00001270{
1271 struct msgb *msg = gsm48_msgb_alloc();
1272 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1273 u_int8_t *cause, *call_state;
1274
Harald Welte4bc90a12008-12-27 16:32:52 +00001275 gh->msg_type = GSM48_MT_CC_STATUS;
1276
1277 cause = msgb_put(msg, 3);
1278 cause[0] = 2;
1279 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1280 cause[2] = 0x80 | 30; /* response to status inquiry */
1281
1282 call_state = msgb_put(msg, 1);
1283 call_state[0] = 0xc0 | 0x00;
1284
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001285 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bc90a12008-12-27 16:32:52 +00001286}
1287
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001288static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte6f4b7532008-12-29 00:39:37 +00001289 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +00001290{
1291 struct msgb *msg = gsm48_msgb_alloc();
1292 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1293
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001294 msg->lchan = conn->lchan;
Harald Welte4bc90a12008-12-27 16:32:52 +00001295
Harald Welte6f4b7532008-12-29 00:39:37 +00001296 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +00001297 gh->msg_type = msg_type;
1298
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001299 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte4bc90a12008-12-27 16:32:52 +00001300}
1301
Harald Welte4bfdfe72009-06-10 23:11:52 +08001302static void gsm48_stop_cc_timer(struct gsm_trans *trans)
1303{
Harald Weltedcaf5652009-07-23 18:56:43 +02001304 if (bsc_timer_pending(&trans->cc.timer)) {
1305 DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent);
1306 bsc_del_timer(&trans->cc.timer);
1307 trans->cc.Tcurrent = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001308 }
1309}
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001310
Harald Welte4bfdfe72009-06-10 23:11:52 +08001311static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
1312 int msg_type, struct gsm_mncc *mncc)
1313{
1314 struct msgb *msg;
1315
1316 if (trans)
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001317 if (trans->conn)
Harald Welte6f5aee02009-07-23 21:21:14 +02001318 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08001319 "Sending '%s' to MNCC.\n",
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001320 trans->conn->lchan->ts->trx->bts->nr,
1321 trans->conn->lchan->ts->trx->nr,
1322 trans->conn->lchan->ts->nr, trans->transaction_id,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001323 (trans->subscr)?(trans->subscr->extension):"-",
1324 get_mncc_name(msg_type));
1325 else
1326 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
1327 "Sending '%s' to MNCC.\n",
1328 (trans->subscr)?(trans->subscr->extension):"-",
1329 get_mncc_name(msg_type));
1330 else
1331 DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) "
1332 "Sending '%s' to MNCC.\n", get_mncc_name(msg_type));
1333
1334 mncc->msg_type = msg_type;
1335
Harald Welte966636f2009-06-26 19:39:35 +02001336 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
Harald Welte4bfdfe72009-06-10 23:11:52 +08001337 if (!msg)
1338 return -ENOMEM;
1339 memcpy(msg->data, mncc, sizeof(struct gsm_mncc));
1340 msgb_enqueue(&net->upqueue, msg);
1341
1342 return 0;
1343}
1344
1345int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
1346 u_int32_t callref, int location, int value)
1347{
1348 struct gsm_mncc rel;
1349
Harald Welte92f70c52009-06-12 01:54:08 +08001350 memset(&rel, 0, sizeof(rel));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001351 rel.callref = callref;
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001352 mncc_set_cause(&rel, location, value);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001353 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1354}
1355
Harald Weltedcaf5652009-07-23 18:56:43 +02001356/* Call Control Specific transaction release.
1357 * gets called by trans_free, DO NOT CALL YOURSELF! */
1358void _gsm48_cc_trans_free(struct gsm_trans *trans)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001359{
Harald Welte4bfdfe72009-06-10 23:11:52 +08001360 gsm48_stop_cc_timer(trans);
1361
1362 /* send release to L4, if callref still exists */
1363 if (trans->callref) {
1364 /* Ressource unavailable */
Harald Welte596fed42009-07-23 19:06:52 +02001365 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001366 GSM48_CAUSE_LOC_PRN_S_LU,
1367 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001368 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001369 if (trans->cc.state != GSM_CSTATE_NULL)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001370 new_cc_state(trans, GSM_CSTATE_NULL);
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001371 if (trans->conn)
1372 trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001373}
1374
1375static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001376
Harald Welte09e38af2009-02-16 22:52:23 +00001377/* call-back from paging the B-end of the connection */
1378static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001379 struct msgb *msg, void *_conn, void *param)
Harald Welte09e38af2009-02-16 22:52:23 +00001380{
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001381 struct gsm_subscriber_connection *conn = _conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001382 struct gsm_subscriber *subscr = param;
1383 struct gsm_trans *transt, *tmp;
1384 struct gsm_network *net;
Harald Weltec05677b2009-06-26 20:17:06 +02001385
Harald Welte09e38af2009-02-16 22:52:23 +00001386 if (hooknum != GSM_HOOK_RR_PAGING)
1387 return -EINVAL;
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001388
Harald Welte4bfdfe72009-06-10 23:11:52 +08001389 if (!subscr)
1390 return -EINVAL;
1391 net = subscr->net;
1392 if (!net) {
1393 DEBUGP(DCC, "Error Network not set!\n");
1394 return -EINVAL;
Harald Welte5a065df2009-02-22 21:13:18 +00001395 }
Harald Welte7584aea2009-02-11 11:44:12 +00001396
Harald Welte4bfdfe72009-06-10 23:11:52 +08001397 /* check all tranactions (without lchan) for subscriber */
1398 llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001399 if (transt->subscr != subscr || transt->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001400 continue;
1401 switch (event) {
1402 case GSM_PAGING_SUCCEEDED:
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001403 if (!conn) // paranoid
Harald Welte4bfdfe72009-06-10 23:11:52 +08001404 break;
1405 DEBUGP(DCC, "Paging subscr %s succeeded!\n",
1406 subscr->extension);
1407 /* Assign lchan */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001408 if (!transt->conn) {
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001409 transt->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001410 }
1411 /* send SETUP request to called party */
Harald Weltedcaf5652009-07-23 18:56:43 +02001412 gsm48_cc_tx_setup(transt, &transt->cc.msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001413 break;
1414 case GSM_PAGING_EXPIRED:
1415 DEBUGP(DCC, "Paging subscr %s expired!\n",
1416 subscr->extension);
1417 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001418 mncc_release_ind(transt->subscr->net, transt,
1419 transt->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001420 GSM48_CAUSE_LOC_PRN_S_LU,
1421 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001422 transt->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001423 trans_free(transt);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001424 break;
1425 }
1426 }
Harald Welte09e38af2009-02-16 22:52:23 +00001427 return 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00001428}
Harald Welte7584aea2009-02-11 11:44:12 +00001429
Harald Welteda7ab742009-12-19 22:23:05 +01001430static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable);
1431
Harald Welte805f6442009-07-28 18:25:29 +02001432/* some other part of the code sends us a signal */
1433static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
1434 void *handler_data, void *signal_data)
1435{
1436 struct gsm_lchan *lchan = signal_data;
Harald Welte805f6442009-07-28 18:25:29 +02001437 int rc;
Harald Welteda7ab742009-12-19 22:23:05 +01001438 struct gsm_network *net;
1439 struct gsm_trans *trans;
Harald Welte805f6442009-07-28 18:25:29 +02001440
1441 if (subsys != SS_ABISIP)
1442 return 0;
1443
1444 /* in case we use direct BTS-to-BTS RTP */
1445 if (ipacc_rtp_direct)
1446 return 0;
1447
Harald Welte805f6442009-07-28 18:25:29 +02001448 switch (signal) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001449 case S_ABISIP_CRCX_ACK:
Harald Welteda7ab742009-12-19 22:23:05 +01001450 /* check if any transactions on this lchan still have
1451 * a tch_recv_mncc request pending */
1452 net = lchan->ts->trx->bts->network;
1453 llist_for_each_entry(trans, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001454 if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) {
Harald Welteda7ab742009-12-19 22:23:05 +01001455 DEBUGP(DCC, "pending tch_recv_mncc request\n");
1456 tch_recv_mncc(net, trans->callref, 1);
1457 }
1458 }
Harald Welte805f6442009-07-28 18:25:29 +02001459 break;
Harald Welte805f6442009-07-28 18:25:29 +02001460 }
1461
1462 return 0;
Harald Welte805f6442009-07-28 18:25:29 +02001463}
1464
Harald Welte49f48b82009-02-17 15:29:33 +00001465/* map two ipaccess RTP streams onto each other */
Harald Welte11fa29c2009-02-19 17:24:39 +00001466static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
Harald Welte49f48b82009-02-17 15:29:33 +00001467{
Harald Welte11fa29c2009-02-19 17:24:39 +00001468 struct gsm_bts *bts = lchan->ts->trx->bts;
1469 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
Harald Welte805f6442009-07-28 18:25:29 +02001470 int rc;
Harald Welte49f48b82009-02-17 15:29:33 +00001471
Harald Welte11fa29c2009-02-19 17:24:39 +00001472 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1473 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1474 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1475
1476 if (bts->type != remote_bts->type) {
1477 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1478 return -EINVAL;
1479 }
Harald Welteda7ab742009-12-19 22:23:05 +01001480
1481 // todo: map between different bts types
Harald Welte11fa29c2009-02-19 17:24:39 +00001482 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001483 case GSM_BTS_TYPE_NANOBTS:
Harald Welte805f6442009-07-28 18:25:29 +02001484 if (!ipacc_rtp_direct) {
1485 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001486 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welte805f6442009-07-28 18:25:29 +02001487 if (rc < 0)
1488 return rc;
Harald Weltea72273e2009-12-20 16:51:09 +01001489 rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001490#warning do we need a check of rc here?
Harald Welte805f6442009-07-28 18:25:29 +02001491
1492 /* connect them with each other */
Harald Welte2c828992009-12-02 01:56:49 +05301493 rtp_socket_proxy(lchan->abis_ip.rtp_socket,
1494 remote_lchan->abis_ip.rtp_socket);
Harald Welte805f6442009-07-28 18:25:29 +02001495 } else {
1496 /* directly connect TCH RTP streams to each other */
Harald Welte2c828992009-12-02 01:56:49 +05301497 rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip,
1498 remote_lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301499 remote_lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001500 if (rc < 0)
1501 return rc;
Harald Welte2c828992009-12-02 01:56:49 +05301502 rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip,
1503 lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301504 lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001505 }
Harald Welte11fa29c2009-02-19 17:24:39 +00001506 break;
1507 case GSM_BTS_TYPE_BS11:
1508 trau_mux_map_lchan(lchan, remote_lchan);
1509 break;
1510 default:
1511 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
Harald Welteda7ab742009-12-19 22:23:05 +01001512 return -EINVAL;
Harald Welte11fa29c2009-02-19 17:24:39 +00001513 }
Harald Welte49f48b82009-02-17 15:29:33 +00001514
1515 return 0;
1516}
1517
Harald Welte4bfdfe72009-06-10 23:11:52 +08001518/* bridge channels of two transactions */
1519static int tch_bridge(struct gsm_network *net, u_int32_t *refs)
Harald Welte7ccf7782009-02-17 01:43:01 +00001520{
Harald Weltedcaf5652009-07-23 18:56:43 +02001521 struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]);
1522 struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]);
Harald Welte7ccf7782009-02-17 01:43:01 +00001523
Harald Welte4bfdfe72009-06-10 23:11:52 +08001524 if (!trans1 || !trans2)
Harald Welte7ccf7782009-02-17 01:43:01 +00001525 return -EIO;
1526
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001527 if (!trans1->conn || !trans2->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001528 return -EIO;
1529
1530 /* through-connect channel */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001531 return tch_map(trans1->conn->lchan, trans2->conn->lchan);
Harald Welte7ccf7782009-02-17 01:43:01 +00001532}
1533
Harald Welteda7ab742009-12-19 22:23:05 +01001534/* enable receive of channels to MNCC upqueue */
1535static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001536{
1537 struct gsm_trans *trans;
Harald Welteda7ab742009-12-19 22:23:05 +01001538 struct gsm_lchan *lchan;
1539 struct gsm_bts *bts;
1540 int rc;
Harald Welte7ccf7782009-02-17 01:43:01 +00001541
Harald Welte4bfdfe72009-06-10 23:11:52 +08001542 /* Find callref */
Harald Welteda7ab742009-12-19 22:23:05 +01001543 trans = trans_find_by_callref(net, callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001544 if (!trans)
1545 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001546 if (!trans->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001547 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001548 lchan = trans->conn->lchan;
Harald Welteda7ab742009-12-19 22:23:05 +01001549 bts = lchan->ts->trx->bts;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001550
Harald Welteda7ab742009-12-19 22:23:05 +01001551 switch (bts->type) {
1552 case GSM_BTS_TYPE_NANOBTS:
1553 if (ipacc_rtp_direct) {
1554 DEBUGP(DCC, "Error: RTP proxy is disabled\n");
1555 return -EINVAL;
1556 }
1557 /* in case, we don't have a RTP socket yet, we note this
1558 * in the transaction and try later */
1559 if (!lchan->abis_ip.rtp_socket) {
1560 trans->tch_recv = enable;
1561 DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable);
1562 return 0;
1563 }
1564 if (enable) {
1565 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001566 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001567 if (rc < 0)
1568 return rc;
1569 /* assign socket to application interface */
1570 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1571 net, callref);
1572 } else
1573 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1574 net, 0);
1575 break;
1576 case GSM_BTS_TYPE_BS11:
1577 if (enable)
1578 return trau_recv_lchan(lchan, callref);
1579 return trau_mux_unmap(NULL, callref);
1580 break;
1581 default:
1582 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
1583 return -EINVAL;
1584 }
1585
1586 return 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001587}
1588
Harald Welte4bfdfe72009-06-10 23:11:52 +08001589static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
1590{
1591 DEBUGP(DCC, "-> STATUS ENQ\n");
1592 return gsm48_cc_tx_status(trans, msg);
1593}
1594
1595static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
1596static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
1597
1598static void gsm48_cc_timeout(void *arg)
1599{
1600 struct gsm_trans *trans = arg;
1601 int disconnect = 0, release = 0;
Harald Weltec66b71c2009-06-11 14:23:20 +08001602 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
1603 int mo_location = GSM48_CAUSE_LOC_USER;
1604 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
1605 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001606 struct gsm_mncc mo_rel, l4_rel;
1607
1608 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
1609 mo_rel.callref = trans->callref;
1610 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
1611 l4_rel.callref = trans->callref;
1612
Harald Weltedcaf5652009-07-23 18:56:43 +02001613 switch(trans->cc.Tcurrent) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001614 case 0x303:
1615 release = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001616 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001617 break;
1618 case 0x310:
1619 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001620 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001621 break;
1622 case 0x313:
1623 disconnect = 1;
1624 /* unknown, did not find it in the specs */
1625 break;
1626 case 0x301:
1627 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001628 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001629 break;
1630 case 0x308:
Harald Weltedcaf5652009-07-23 18:56:43 +02001631 if (!trans->cc.T308_second) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001632 /* restart T308 a second time */
Harald Weltedcaf5652009-07-23 18:56:43 +02001633 gsm48_cc_tx_release(trans, &trans->cc.msg);
1634 trans->cc.T308_second = 1;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001635 break; /* stay in release state */
1636 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001637 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001638 return;
1639// release = 1;
1640// l4_cause = 14;
1641// break;
1642 case 0x306:
1643 release = 1;
Harald Weltedcaf5652009-07-23 18:56:43 +02001644 mo_cause = trans->cc.msg.cause.value;
1645 mo_location = trans->cc.msg.cause.location;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001646 break;
1647 case 0x323:
1648 disconnect = 1;
1649 break;
1650 default:
1651 release = 1;
1652 }
1653
1654 if (release && trans->callref) {
1655 /* process release towards layer 4 */
Harald Welte596fed42009-07-23 19:06:52 +02001656 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001657 l4_location, l4_cause);
1658 trans->callref = 0;
1659 }
1660
1661 if (disconnect && trans->callref) {
1662 /* process disconnect towards layer 4 */
1663 mncc_set_cause(&l4_rel, l4_location, l4_cause);
Harald Welte596fed42009-07-23 19:06:52 +02001664 mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001665 }
1666
1667 /* process disconnect towards mobile station */
1668 if (disconnect || release) {
1669 mncc_set_cause(&mo_rel, mo_location, mo_cause);
Harald Weltedcaf5652009-07-23 18:56:43 +02001670 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
1671 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
1672 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
Harald Welte4bfdfe72009-06-10 23:11:52 +08001673 mo_rel.cause.diag_len = 3;
1674
1675 if (disconnect)
1676 gsm48_cc_tx_disconnect(trans, &mo_rel);
1677 if (release)
1678 gsm48_cc_tx_release(trans, &mo_rel);
1679 }
1680
1681}
1682
1683static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
1684 int sec, int micro)
1685{
1686 DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec);
Harald Weltedcaf5652009-07-23 18:56:43 +02001687 trans->cc.timer.cb = gsm48_cc_timeout;
1688 trans->cc.timer.data = trans;
1689 bsc_schedule_timer(&trans->cc.timer, sec, micro);
1690 trans->cc.Tcurrent = current;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001691}
1692
1693static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
1694{
1695 struct gsm48_hdr *gh = msgb_l3(msg);
1696 u_int8_t msg_type = gh->msg_type & 0xbf;
1697 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1698 struct tlv_parsed tp;
1699 struct gsm_mncc setup;
1700
1701 memset(&setup, 0, sizeof(struct gsm_mncc));
1702 setup.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001703 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001704 /* emergency setup is identified by msg_type */
1705 if (msg_type == GSM48_MT_CC_EMERG_SETUP)
1706 setup.emergency = 1;
1707
1708 /* use subscriber as calling party number */
1709 if (trans->subscr) {
1710 setup.fields |= MNCC_F_CALLING;
1711 strncpy(setup.calling.number, trans->subscr->extension,
1712 sizeof(setup.calling.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02001713 strncpy(setup.imsi, trans->subscr->imsi,
1714 sizeof(setup.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001715 }
1716 /* bearer capability */
1717 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1718 setup.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001719 gsm48_decode_bearer_cap(&setup.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001720 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1721 }
1722 /* facility */
1723 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1724 setup.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001725 gsm48_decode_facility(&setup.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001726 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1727 }
1728 /* called party bcd number */
1729 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
1730 setup.fields |= MNCC_F_CALLED;
Harald Welte55c8f352010-03-07 23:40:35 +01001731 gsm48_decode_called(&setup.called,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001732 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
1733 }
1734 /* user-user */
1735 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1736 setup.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01001737 gsm48_decode_useruser(&setup.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001738 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1739 }
1740 /* ss-version */
1741 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1742 setup.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001743 gsm48_decode_ssversion(&setup.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001744 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1745 }
1746 /* CLIR suppression */
1747 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
1748 setup.clir.sup = 1;
1749 /* CLIR invocation */
1750 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
1751 setup.clir.inv = 1;
1752 /* cc cap */
1753 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1754 setup.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001755 gsm48_decode_cccap(&setup.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001756 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1757 }
1758
Harald Welte4bfdfe72009-06-10 23:11:52 +08001759 new_cc_state(trans, GSM_CSTATE_INITIATED);
1760
Harald Welte (local)47df3992009-12-26 19:45:03 +01001761 LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n",
1762 subscr_name(trans->subscr), trans->subscr->extension,
1763 setup.called.number);
1764
Harald Welte4bfdfe72009-06-10 23:11:52 +08001765 /* indicate setup to MNCC */
Harald Welte596fed42009-07-23 19:06:52 +02001766 mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001767
Harald Welte13cac662009-07-29 12:10:35 +02001768 /* MNCC code will modify the channel asynchronously, we should
1769 * ipaccess-bind only after the modification has been made to the
1770 * lchan->tch_mode */
Harald Welte4bfdfe72009-06-10 23:11:52 +08001771 return 0;
1772}
1773
1774static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
Harald Welte65e74cc2008-12-29 01:55:35 +00001775{
1776 struct msgb *msg = gsm48_msgb_alloc();
1777 struct gsm48_hdr *gh;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001778 struct gsm_mncc *setup = arg;
Harald Welte78283ef2009-07-23 21:36:44 +02001779 int rc, trans_id;
Harald Welte65e74cc2008-12-29 01:55:35 +00001780
Harald Welte7ccf7782009-02-17 01:43:01 +00001781 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Harald Welte65e74cc2008-12-29 01:55:35 +00001782
Harald Welte4bfdfe72009-06-10 23:11:52 +08001783 /* transaction id must not be assigned */
1784 if (trans->transaction_id != 0xff) { /* unasssigned */
1785 DEBUGP(DCC, "TX Setup with assigned transaction. "
1786 "This is not allowed!\n");
1787 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001788 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001789 GSM48_CAUSE_LOC_PRN_S_LU,
1790 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001791 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001792 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001793 return rc;
1794 }
1795
1796 /* Get free transaction_id */
Harald Welte78283ef2009-07-23 21:36:44 +02001797 trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0);
1798 if (trans_id < 0) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001799 /* no free transaction ID */
Harald Welte596fed42009-07-23 19:06:52 +02001800 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001801 GSM48_CAUSE_LOC_PRN_S_LU,
1802 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001803 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001804 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001805 return rc;
1806 }
Harald Welte78283ef2009-07-23 21:36:44 +02001807 trans->transaction_id = trans_id;
Harald Welte49f48b82009-02-17 15:29:33 +00001808
Harald Welte65e74cc2008-12-29 01:55:35 +00001809 gh->msg_type = GSM48_MT_CC_SETUP;
Harald Welte09e38af2009-02-16 22:52:23 +00001810
Harald Welte4bfdfe72009-06-10 23:11:52 +08001811 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
Harald Welte65e74cc2008-12-29 01:55:35 +00001812
Harald Welte4bfdfe72009-06-10 23:11:52 +08001813 /* bearer capability */
1814 if (setup->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001815 gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001816 /* facility */
1817 if (setup->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001818 gsm48_encode_facility(msg, 0, &setup->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001819 /* progress */
1820 if (setup->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001821 gsm48_encode_progress(msg, 0, &setup->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001822 /* calling party BCD number */
1823 if (setup->fields & MNCC_F_CALLING)
Harald Welte55c8f352010-03-07 23:40:35 +01001824 gsm48_encode_calling(msg, &setup->calling);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001825 /* called party BCD number */
1826 if (setup->fields & MNCC_F_CALLED)
Harald Welte55c8f352010-03-07 23:40:35 +01001827 gsm48_encode_called(msg, &setup->called);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001828 /* user-user */
1829 if (setup->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001830 gsm48_encode_useruser(msg, 0, &setup->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001831 /* redirecting party BCD number */
1832 if (setup->fields & MNCC_F_REDIRECTING)
Harald Welte55c8f352010-03-07 23:40:35 +01001833 gsm48_encode_redirecting(msg, &setup->redirecting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001834 /* signal */
1835 if (setup->fields & MNCC_F_SIGNAL)
Harald Welte55c8f352010-03-07 23:40:35 +01001836 gsm48_encode_signal(msg, setup->signal);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001837
1838 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
Harald Welte65e74cc2008-12-29 01:55:35 +00001839
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001840 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte65e74cc2008-12-29 01:55:35 +00001841}
1842
Harald Welte4bfdfe72009-06-10 23:11:52 +08001843static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
1844{
1845 struct gsm48_hdr *gh = msgb_l3(msg);
1846 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1847 struct tlv_parsed tp;
1848 struct gsm_mncc call_conf;
1849
1850 gsm48_stop_cc_timer(trans);
1851 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
1852
1853 memset(&call_conf, 0, sizeof(struct gsm_mncc));
1854 call_conf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001855 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001856#if 0
1857 /* repeat */
1858 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
1859 call_conf.repeat = 1;
1860 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
1861 call_conf.repeat = 2;
1862#endif
1863 /* bearer capability */
1864 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1865 call_conf.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001866 gsm48_decode_bearer_cap(&call_conf.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001867 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1868 }
1869 /* cause */
1870 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1871 call_conf.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01001872 gsm48_decode_cause(&call_conf.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001873 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1874 }
1875 /* cc cap */
1876 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1877 call_conf.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001878 gsm48_decode_cccap(&call_conf.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001879 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1880 }
1881
1882 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
1883
Harald Welte596fed42009-07-23 19:06:52 +02001884 return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND,
1885 &call_conf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001886}
1887
1888static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg)
1889{
1890 struct gsm_mncc *proceeding = arg;
1891 struct msgb *msg = gsm48_msgb_alloc();
1892 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1893
Harald Welte4bfdfe72009-06-10 23:11:52 +08001894 gh->msg_type = GSM48_MT_CC_CALL_PROC;
1895
1896 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
1897
1898 /* bearer capability */
1899 if (proceeding->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001900 gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001901 /* facility */
1902 if (proceeding->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001903 gsm48_encode_facility(msg, 0, &proceeding->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001904 /* progress */
1905 if (proceeding->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001906 gsm48_encode_progress(msg, 0, &proceeding->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001907
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001908 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001909}
1910
1911static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
1912{
1913 struct gsm48_hdr *gh = msgb_l3(msg);
1914 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1915 struct tlv_parsed tp;
1916 struct gsm_mncc alerting;
1917
1918 gsm48_stop_cc_timer(trans);
1919 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
1920
1921 memset(&alerting, 0, sizeof(struct gsm_mncc));
1922 alerting.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001923 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001924 /* facility */
1925 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1926 alerting.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001927 gsm48_decode_facility(&alerting.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001928 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1929 }
1930
1931 /* progress */
1932 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
1933 alerting.fields |= MNCC_F_PROGRESS;
Harald Welte55c8f352010-03-07 23:40:35 +01001934 gsm48_decode_progress(&alerting.progress,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001935 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
1936 }
1937 /* ss-version */
1938 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1939 alerting.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001940 gsm48_decode_ssversion(&alerting.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001941 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1942 }
1943
1944 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
1945
Harald Welte596fed42009-07-23 19:06:52 +02001946 return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND,
1947 &alerting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001948}
1949
1950static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
1951{
1952 struct gsm_mncc *alerting = arg;
1953 struct msgb *msg = gsm48_msgb_alloc();
1954 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1955
Harald Welte4bfdfe72009-06-10 23:11:52 +08001956 gh->msg_type = GSM48_MT_CC_ALERTING;
1957
1958 /* facility */
1959 if (alerting->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001960 gsm48_encode_facility(msg, 0, &alerting->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001961 /* progress */
1962 if (alerting->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001963 gsm48_encode_progress(msg, 0, &alerting->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001964 /* user-user */
1965 if (alerting->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001966 gsm48_encode_useruser(msg, 0, &alerting->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001967
1968 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
1969
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001970 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001971}
1972
1973static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
1974{
1975 struct gsm_mncc *progress = arg;
1976 struct msgb *msg = gsm48_msgb_alloc();
1977 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1978
Harald Welte4bfdfe72009-06-10 23:11:52 +08001979 gh->msg_type = GSM48_MT_CC_PROGRESS;
1980
1981 /* progress */
Harald Welte55c8f352010-03-07 23:40:35 +01001982 gsm48_encode_progress(msg, 1, &progress->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001983 /* user-user */
1984 if (progress->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001985 gsm48_encode_useruser(msg, 0, &progress->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001986
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001987 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001988}
1989
1990static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
1991{
1992 struct gsm_mncc *connect = arg;
1993 struct msgb *msg = gsm48_msgb_alloc();
1994 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1995
Harald Welte4bfdfe72009-06-10 23:11:52 +08001996 gh->msg_type = GSM48_MT_CC_CONNECT;
1997
1998 gsm48_stop_cc_timer(trans);
1999 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
2000
2001 /* facility */
2002 if (connect->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002003 gsm48_encode_facility(msg, 0, &connect->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002004 /* progress */
2005 if (connect->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01002006 gsm48_encode_progress(msg, 0, &connect->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002007 /* connected number */
2008 if (connect->fields & MNCC_F_CONNECTED)
Harald Welte55c8f352010-03-07 23:40:35 +01002009 gsm48_encode_connected(msg, &connect->connected);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002010 /* user-user */
2011 if (connect->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002012 gsm48_encode_useruser(msg, 0, &connect->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002013
2014 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
2015
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002016 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002017}
2018
2019static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
2020{
2021 struct gsm48_hdr *gh = msgb_l3(msg);
2022 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2023 struct tlv_parsed tp;
2024 struct gsm_mncc connect;
2025
2026 gsm48_stop_cc_timer(trans);
2027
2028 memset(&connect, 0, sizeof(struct gsm_mncc));
2029 connect.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002030 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002031 /* use subscriber as connected party number */
2032 if (trans->subscr) {
2033 connect.fields |= MNCC_F_CONNECTED;
2034 strncpy(connect.connected.number, trans->subscr->extension,
2035 sizeof(connect.connected.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002036 strncpy(connect.imsi, trans->subscr->imsi,
2037 sizeof(connect.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002038 }
2039 /* facility */
2040 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2041 connect.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002042 gsm48_decode_facility(&connect.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002043 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2044 }
2045 /* user-user */
2046 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2047 connect.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002048 gsm48_decode_useruser(&connect.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002049 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2050 }
2051 /* ss-version */
2052 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2053 connect.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002054 gsm48_decode_ssversion(&connect.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002055 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2056 }
2057
2058 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
2059
Harald Welte596fed42009-07-23 19:06:52 +02002060 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002061}
2062
2063
2064static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
2065{
2066 struct gsm_mncc connect_ack;
2067
2068 gsm48_stop_cc_timer(trans);
2069
2070 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2071
2072 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
2073 connect_ack.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002074 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002075 &connect_ack);
2076}
2077
2078static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
2079{
2080 struct msgb *msg = gsm48_msgb_alloc();
2081 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2082
Harald Welte4bfdfe72009-06-10 23:11:52 +08002083 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
2084
2085 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2086
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002087 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002088}
2089
2090static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
2091{
2092 struct gsm48_hdr *gh = msgb_l3(msg);
2093 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2094 struct tlv_parsed tp;
2095 struct gsm_mncc disc;
2096
2097 gsm48_stop_cc_timer(trans);
2098
2099 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
2100
2101 memset(&disc, 0, sizeof(struct gsm_mncc));
2102 disc.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002103 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002104 /* cause */
2105 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2106 disc.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002107 gsm48_decode_cause(&disc.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002108 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2109 }
2110 /* facility */
2111 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2112 disc.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002113 gsm48_decode_facility(&disc.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002114 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2115 }
2116 /* user-user */
2117 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2118 disc.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002119 gsm48_decode_useruser(&disc.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002120 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2121 }
2122 /* ss-version */
2123 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2124 disc.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002125 gsm48_decode_ssversion(&disc.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002126 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2127 }
2128
Harald Welte596fed42009-07-23 19:06:52 +02002129 return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002130
2131}
2132
Harald Weltec66b71c2009-06-11 14:23:20 +08002133static struct gsm_mncc_cause default_cause = {
2134 .location = GSM48_CAUSE_LOC_PRN_S_LU,
2135 .coding = 0,
2136 .rec = 0,
2137 .rec_val = 0,
2138 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
2139 .diag_len = 0,
2140 .diag = { 0 },
2141};
Harald Welte4bfdfe72009-06-10 23:11:52 +08002142
2143static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
2144{
2145 struct gsm_mncc *disc = arg;
2146 struct msgb *msg = gsm48_msgb_alloc();
2147 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2148
Harald Welte4bfdfe72009-06-10 23:11:52 +08002149 gh->msg_type = GSM48_MT_CC_DISCONNECT;
2150
2151 gsm48_stop_cc_timer(trans);
2152 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
2153
2154 /* cause */
2155 if (disc->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002156 gsm48_encode_cause(msg, 1, &disc->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002157 else
Harald Welte55c8f352010-03-07 23:40:35 +01002158 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002159
2160 /* facility */
2161 if (disc->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002162 gsm48_encode_facility(msg, 0, &disc->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002163 /* progress */
2164 if (disc->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01002165 gsm48_encode_progress(msg, 0, &disc->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002166 /* user-user */
2167 if (disc->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002168 gsm48_encode_useruser(msg, 0, &disc->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002169
2170 /* store disconnect cause for T306 expiry */
Harald Weltedcaf5652009-07-23 18:56:43 +02002171 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002172
2173 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
2174
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002175 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002176}
2177
2178static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
2179{
2180 struct gsm48_hdr *gh = msgb_l3(msg);
2181 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2182 struct tlv_parsed tp;
2183 struct gsm_mncc rel;
2184 int rc;
2185
2186 gsm48_stop_cc_timer(trans);
2187
2188 memset(&rel, 0, sizeof(struct gsm_mncc));
2189 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002190 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002191 /* cause */
2192 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2193 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002194 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002195 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2196 }
2197 /* facility */
2198 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2199 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002200 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002201 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2202 }
2203 /* user-user */
2204 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2205 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002206 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002207 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2208 }
2209 /* ss-version */
2210 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2211 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002212 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002213 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2214 }
2215
Harald Weltedcaf5652009-07-23 18:56:43 +02002216 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002217 /* release collision 5.4.5 */
Harald Welte596fed42009-07-23 19:06:52 +02002218 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002219 } else {
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08002220 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02002221 GSM48_PDISC_CC | (trans->transaction_id << 4),
Harald Welte596fed42009-07-23 19:06:52 +02002222 GSM48_MT_CC_RELEASE_COMPL);
2223 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002224 }
2225
2226 new_cc_state(trans, GSM_CSTATE_NULL);
2227
2228 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002229 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002230
2231 return rc;
2232}
2233
2234static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
2235{
2236 struct gsm_mncc *rel = arg;
2237 struct msgb *msg = gsm48_msgb_alloc();
2238 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2239
Harald Welte4bfdfe72009-06-10 23:11:52 +08002240 gh->msg_type = GSM48_MT_CC_RELEASE;
2241
2242 trans->callref = 0;
2243
2244 gsm48_stop_cc_timer(trans);
2245 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
2246
2247 /* cause */
2248 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002249 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002250 /* facility */
2251 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002252 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002253 /* user-user */
2254 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002255 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002256
Harald Weltedcaf5652009-07-23 18:56:43 +02002257 trans->cc.T308_second = 0;
2258 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002259
Harald Weltedcaf5652009-07-23 18:56:43 +02002260 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002261 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
2262
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002263 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002264}
2265
2266static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
2267{
2268 struct gsm48_hdr *gh = msgb_l3(msg);
2269 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2270 struct tlv_parsed tp;
2271 struct gsm_mncc rel;
2272 int rc = 0;
2273
2274 gsm48_stop_cc_timer(trans);
2275
2276 memset(&rel, 0, sizeof(struct gsm_mncc));
2277 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002278 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002279 /* cause */
2280 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2281 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002282 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002283 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2284 }
2285 /* facility */
2286 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2287 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002288 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002289 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2290 }
2291 /* user-user */
2292 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2293 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002294 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002295 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2296 }
2297 /* ss-version */
2298 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2299 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002300 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002301 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2302 }
2303
2304 if (trans->callref) {
Harald Weltedcaf5652009-07-23 18:56:43 +02002305 switch (trans->cc.state) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002306 case GSM_CSTATE_CALL_PRESENT:
Harald Welte596fed42009-07-23 19:06:52 +02002307 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002308 MNCC_REJ_IND, &rel);
2309 break;
2310 case GSM_CSTATE_RELEASE_REQ:
Harald Welte596fed42009-07-23 19:06:52 +02002311 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002312 MNCC_REL_CNF, &rel);
2313 break;
2314 default:
Harald Welte596fed42009-07-23 19:06:52 +02002315 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002316 MNCC_REL_IND, &rel);
2317 }
2318 }
2319
2320 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002321 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002322
2323 return rc;
2324}
2325
2326static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
2327{
2328 struct gsm_mncc *rel = arg;
2329 struct msgb *msg = gsm48_msgb_alloc();
2330 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2331
Harald Welte4bfdfe72009-06-10 23:11:52 +08002332 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
2333
2334 trans->callref = 0;
2335
2336 gsm48_stop_cc_timer(trans);
2337
2338 /* cause */
2339 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002340 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002341 /* facility */
2342 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002343 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002344 /* user-user */
2345 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002346 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002347
Harald Weltedcaf5652009-07-23 18:56:43 +02002348 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002349
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002350 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002351}
2352
2353static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
2354{
2355 struct gsm48_hdr *gh = msgb_l3(msg);
2356 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2357 struct tlv_parsed tp;
2358 struct gsm_mncc fac;
2359
2360 memset(&fac, 0, sizeof(struct gsm_mncc));
2361 fac.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002362 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002363 /* facility */
2364 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2365 fac.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002366 gsm48_decode_facility(&fac.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002367 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2368 }
2369 /* ss-version */
2370 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2371 fac.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002372 gsm48_decode_ssversion(&fac.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002373 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2374 }
2375
Harald Welte596fed42009-07-23 19:06:52 +02002376 return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002377}
2378
2379static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
2380{
2381 struct gsm_mncc *fac = arg;
2382 struct msgb *msg = gsm48_msgb_alloc();
2383 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2384
Harald Welte4bfdfe72009-06-10 23:11:52 +08002385 gh->msg_type = GSM48_MT_CC_FACILITY;
2386
2387 /* facility */
Harald Welte55c8f352010-03-07 23:40:35 +01002388 gsm48_encode_facility(msg, 1, &fac->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002389
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002390 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002391}
2392
2393static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
2394{
2395 struct gsm_mncc hold;
2396
2397 memset(&hold, 0, sizeof(struct gsm_mncc));
2398 hold.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002399 return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002400}
2401
2402static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
2403{
2404 struct msgb *msg = gsm48_msgb_alloc();
2405 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2406
Harald Welte4bfdfe72009-06-10 23:11:52 +08002407 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
2408
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002409 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002410}
2411
2412static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
2413{
2414 struct gsm_mncc *hold_rej = arg;
2415 struct msgb *msg = gsm48_msgb_alloc();
2416 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2417
Harald Welte4bfdfe72009-06-10 23:11:52 +08002418 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
2419
2420 /* cause */
2421 if (hold_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002422 gsm48_encode_cause(msg, 1, &hold_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002423 else
Harald Welte55c8f352010-03-07 23:40:35 +01002424 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002425
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002426 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002427}
2428
2429static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
2430{
2431 struct gsm_mncc retrieve;
2432
2433 memset(&retrieve, 0, sizeof(struct gsm_mncc));
2434 retrieve.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002435 return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND,
2436 &retrieve);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002437}
2438
2439static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
2440{
2441 struct msgb *msg = gsm48_msgb_alloc();
2442 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2443
Harald Welte4bfdfe72009-06-10 23:11:52 +08002444 gh->msg_type = GSM48_MT_CC_RETR_ACK;
2445
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002446 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002447}
2448
2449static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
2450{
2451 struct gsm_mncc *retrieve_rej = arg;
2452 struct msgb *msg = gsm48_msgb_alloc();
2453 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2454
Harald Welte4bfdfe72009-06-10 23:11:52 +08002455 gh->msg_type = GSM48_MT_CC_RETR_REJ;
2456
2457 /* cause */
2458 if (retrieve_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002459 gsm48_encode_cause(msg, 1, &retrieve_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002460 else
Harald Welte55c8f352010-03-07 23:40:35 +01002461 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002462
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002463 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002464}
2465
2466static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
2467{
2468 struct gsm48_hdr *gh = msgb_l3(msg);
2469 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2470 struct tlv_parsed tp;
2471 struct gsm_mncc dtmf;
2472
2473 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2474 dtmf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002475 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002476 /* keypad facility */
2477 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
2478 dtmf.fields |= MNCC_F_KEYPAD;
Harald Welte55c8f352010-03-07 23:40:35 +01002479 gsm48_decode_keypad(&dtmf.keypad,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002480 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
2481 }
2482
Harald Welte596fed42009-07-23 19:06:52 +02002483 return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002484}
2485
2486static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
2487{
2488 struct gsm_mncc *dtmf = arg;
2489 struct msgb *msg = gsm48_msgb_alloc();
2490 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2491
Harald Welte4bfdfe72009-06-10 23:11:52 +08002492 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
2493
2494 /* keypad */
2495 if (dtmf->fields & MNCC_F_KEYPAD)
Harald Welte55c8f352010-03-07 23:40:35 +01002496 gsm48_encode_keypad(msg, dtmf->keypad);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002497
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002498 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002499}
2500
2501static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
2502{
2503 struct gsm_mncc *dtmf = arg;
2504 struct msgb *msg = gsm48_msgb_alloc();
2505 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2506
Harald Welte4bfdfe72009-06-10 23:11:52 +08002507 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
2508
2509 /* cause */
2510 if (dtmf->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002511 gsm48_encode_cause(msg, 1, &dtmf->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002512 else
Harald Welte55c8f352010-03-07 23:40:35 +01002513 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002514
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002515 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002516}
2517
2518static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
2519{
2520 struct msgb *msg = gsm48_msgb_alloc();
2521 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2522
Harald Welte4bfdfe72009-06-10 23:11:52 +08002523 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
2524
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002525 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002526}
2527
2528static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
2529{
2530 struct gsm_mncc dtmf;
2531
2532 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2533 dtmf.callref = trans->callref;
2534
Harald Welte596fed42009-07-23 19:06:52 +02002535 return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002536}
2537
2538static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
2539{
2540 struct gsm48_hdr *gh = msgb_l3(msg);
2541 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2542 struct tlv_parsed tp;
2543 struct gsm_mncc modify;
2544
2545 memset(&modify, 0, sizeof(struct gsm_mncc));
2546 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002547 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002548 /* bearer capability */
2549 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2550 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002551 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002552 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2553 }
2554
2555 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
2556
Harald Welte596fed42009-07-23 19:06:52 +02002557 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002558}
2559
2560static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
2561{
2562 struct gsm_mncc *modify = arg;
2563 struct msgb *msg = gsm48_msgb_alloc();
2564 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2565
Harald Welte4bfdfe72009-06-10 23:11:52 +08002566 gh->msg_type = GSM48_MT_CC_MODIFY;
2567
2568 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
2569
2570 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002571 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002572
2573 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
2574
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002575 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002576}
2577
2578static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
2579{
2580 struct gsm48_hdr *gh = msgb_l3(msg);
2581 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2582 struct tlv_parsed tp;
2583 struct gsm_mncc modify;
2584
2585 gsm48_stop_cc_timer(trans);
2586
2587 memset(&modify, 0, sizeof(struct gsm_mncc));
2588 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002589 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002590 /* bearer capability */
2591 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2592 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002593 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002594 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2595 }
2596
2597 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2598
Harald Welte596fed42009-07-23 19:06:52 +02002599 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002600}
2601
2602static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
2603{
2604 struct gsm_mncc *modify = arg;
2605 struct msgb *msg = gsm48_msgb_alloc();
2606 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2607
Harald Welte4bfdfe72009-06-10 23:11:52 +08002608 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
2609
2610 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002611 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002612
2613 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2614
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002615 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002616}
2617
2618static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
2619{
2620 struct gsm48_hdr *gh = msgb_l3(msg);
2621 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2622 struct tlv_parsed tp;
2623 struct gsm_mncc modify;
2624
2625 gsm48_stop_cc_timer(trans);
2626
2627 memset(&modify, 0, sizeof(struct gsm_mncc));
2628 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002629 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002630 /* bearer capability */
2631 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2632 modify.fields |= GSM48_IE_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002633 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002634 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2635 }
2636 /* cause */
2637 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2638 modify.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002639 gsm48_decode_cause(&modify.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002640 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2641 }
2642
2643 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2644
Harald Welte596fed42009-07-23 19:06:52 +02002645 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002646}
2647
2648static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
2649{
2650 struct gsm_mncc *modify = arg;
2651 struct msgb *msg = gsm48_msgb_alloc();
2652 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2653
Harald Welte4bfdfe72009-06-10 23:11:52 +08002654 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
2655
2656 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002657 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002658 /* cause */
Harald Welte55c8f352010-03-07 23:40:35 +01002659 gsm48_encode_cause(msg, 1, &modify->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002660
2661 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2662
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002663 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002664}
2665
2666static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
2667{
2668 struct gsm_mncc *notify = arg;
2669 struct msgb *msg = gsm48_msgb_alloc();
2670 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2671
Harald Welte4bfdfe72009-06-10 23:11:52 +08002672 gh->msg_type = GSM48_MT_CC_NOTIFY;
2673
2674 /* notify */
Harald Welte55c8f352010-03-07 23:40:35 +01002675 gsm48_encode_notify(msg, notify->notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002676
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002677 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002678}
2679
2680static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
2681{
2682 struct gsm48_hdr *gh = msgb_l3(msg);
2683 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2684// struct tlv_parsed tp;
2685 struct gsm_mncc notify;
2686
2687 memset(&notify, 0, sizeof(struct gsm_mncc));
2688 notify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002689// tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002690 if (payload_len >= 1)
Harald Welte55c8f352010-03-07 23:40:35 +01002691 gsm48_decode_notify(&notify.notify, gh->data);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002692
Harald Welte596fed42009-07-23 19:06:52 +02002693 return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, &notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002694}
2695
2696static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
2697{
2698 struct gsm_mncc *user = arg;
2699 struct msgb *msg = gsm48_msgb_alloc();
2700 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2701
Harald Welte4bfdfe72009-06-10 23:11:52 +08002702 gh->msg_type = GSM48_MT_CC_USER_INFO;
2703
2704 /* user-user */
2705 if (user->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002706 gsm48_encode_useruser(msg, 1, &user->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002707 /* more data */
2708 if (user->more)
Harald Welte55c8f352010-03-07 23:40:35 +01002709 gsm48_encode_more(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002710
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002711 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002712}
2713
2714static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
2715{
2716 struct gsm48_hdr *gh = msgb_l3(msg);
2717 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2718 struct tlv_parsed tp;
2719 struct gsm_mncc user;
2720
2721 memset(&user, 0, sizeof(struct gsm_mncc));
2722 user.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002723 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002724 /* user-user */
2725 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2726 user.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002727 gsm48_decode_useruser(&user.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002728 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2729 }
2730 /* more data */
2731 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
2732 user.more = 1;
2733
Harald Welte596fed42009-07-23 19:06:52 +02002734 return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002735}
2736
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002737static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002738{
2739 struct gsm_mncc *mode = arg;
2740
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002741 return gsm48_lchan_modify(trans->conn->lchan, mode->lchan_mode);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002742}
2743
2744static struct downstate {
2745 u_int32_t states;
2746 int type;
2747 int (*rout) (struct gsm_trans *trans, void *arg);
2748} downstatelist[] = {
2749 /* mobile originating call establishment */
2750 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
2751 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc},
2752 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
2753 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
2754 {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 */
2755 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
2756 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
2757 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
2758 /* mobile terminating call establishment */
2759 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
2760 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
2761 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
2762 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
2763 /* signalling during call */
2764 {SBIT(GSM_CSTATE_ACTIVE),
2765 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
2766 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
2767 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
2768 {ALL_STATES,
2769 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
2770 {ALL_STATES,
2771 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
2772 {ALL_STATES,
2773 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
2774 {SBIT(GSM_CSTATE_ACTIVE),
2775 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
2776 {SBIT(GSM_CSTATE_ACTIVE),
2777 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
2778 {SBIT(GSM_CSTATE_ACTIVE),
2779 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
2780 {SBIT(GSM_CSTATE_ACTIVE),
2781 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
2782 {SBIT(GSM_CSTATE_ACTIVE),
2783 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
2784 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2785 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
2786 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2787 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
2788 {SBIT(GSM_CSTATE_ACTIVE),
2789 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
2790 /* clearing */
2791 {SBIT(GSM_CSTATE_INITIATED),
2792 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
2793 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
2794 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
2795 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
2796 MNCC_REL_REQ, gsm48_cc_tx_release},
2797 /* special */
2798 {ALL_STATES,
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002799 MNCC_LCHAN_MODIFY, _gsm48_lchan_modify},
Harald Welte4bfdfe72009-06-10 23:11:52 +08002800};
2801
2802#define DOWNSLLEN \
2803 (sizeof(downstatelist) / sizeof(struct downstate))
2804
2805
2806int mncc_send(struct gsm_network *net, int msg_type, void *arg)
2807{
Harald Welte1a6f7982009-08-09 18:52:33 +02002808 int i, rc = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002809 struct gsm_trans *trans = NULL, *transt;
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002810 struct gsm_subscriber_connection *conn = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002811 struct gsm_bts *bts = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002812 struct gsm_mncc *data = arg, rel;
2813
2814 /* handle special messages */
2815 switch(msg_type) {
2816 case MNCC_BRIDGE:
2817 return tch_bridge(net, arg);
2818 case MNCC_FRAME_DROP:
Harald Welteda7ab742009-12-19 22:23:05 +01002819 return tch_recv_mncc(net, data->callref, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002820 case MNCC_FRAME_RECV:
Harald Welteda7ab742009-12-19 22:23:05 +01002821 return tch_recv_mncc(net, data->callref, 1);
2822 case GSM_TCHF_FRAME:
2823 /* Find callref */
2824 trans = trans_find_by_callref(net, data->callref);
2825 if (!trans)
2826 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002827 if (!trans->conn)
Harald Welteda7ab742009-12-19 22:23:05 +01002828 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002829 if (trans->conn->lchan->type != GSM_LCHAN_TCH_F)
Harald Welteda7ab742009-12-19 22:23:05 +01002830 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002831 bts = trans->conn->lchan->ts->trx->bts;
Harald Welteda7ab742009-12-19 22:23:05 +01002832 switch (bts->type) {
2833 case GSM_BTS_TYPE_NANOBTS:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002834 if (!trans->conn->lchan->abis_ip.rtp_socket)
Harald Welteda7ab742009-12-19 22:23:05 +01002835 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002836 return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002837 case GSM_BTS_TYPE_BS11:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002838 return trau_send_frame(trans->conn->lchan, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002839 default:
2840 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
2841 }
2842 return -EINVAL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002843 }
2844
2845 memset(&rel, 0, sizeof(struct gsm_mncc));
2846 rel.callref = data->callref;
2847
2848 /* Find callref */
Harald Weltedcaf5652009-07-23 18:56:43 +02002849 trans = trans_find_by_callref(net, data->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002850
2851 /* Callref unknown */
2852 if (!trans) {
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002853 struct gsm_subscriber *subscr;
2854
Harald Welte4a3464c2009-07-04 10:11:24 +02002855 if (msg_type != MNCC_SETUP_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002856 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2857 "Received '%s' from MNCC with "
2858 "unknown callref %d\n", data->called.number,
2859 get_mncc_name(msg_type), data->callref);
2860 /* Invalid call reference */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002861 return mncc_release_ind(net, NULL, data->callref,
2862 GSM48_CAUSE_LOC_PRN_S_LU,
2863 GSM48_CC_CAUSE_INVAL_TRANS_ID);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002864 }
Andreas Eversbergc079be42009-06-15 23:22:09 +02002865 if (!data->called.number[0] && !data->imsi[0]) {
2866 DEBUGP(DCC, "(bts - trx - ts - ti) "
2867 "Received '%s' from MNCC with "
2868 "no number or IMSI\n", get_mncc_name(msg_type));
2869 /* Invalid number */
2870 return mncc_release_ind(net, NULL, data->callref,
2871 GSM48_CAUSE_LOC_PRN_S_LU,
2872 GSM48_CC_CAUSE_INV_NR_FORMAT);
2873 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002874 /* New transaction due to setup, find subscriber */
Andreas Eversbergc079be42009-06-15 23:22:09 +02002875 if (data->called.number[0])
Harald Welte9176bd42009-07-23 18:46:00 +02002876 subscr = subscr_get_by_extension(net,
2877 data->called.number);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002878 else
Harald Welte9176bd42009-07-23 18:46:00 +02002879 subscr = subscr_get_by_imsi(net, data->imsi);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002880 /* If subscriber is not found */
2881 if (!subscr) {
2882 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2883 "Received '%s' from MNCC with "
2884 "unknown subscriber %s\n", data->called.number,
2885 get_mncc_name(msg_type), data->called.number);
2886 /* Unknown subscriber */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002887 return mncc_release_ind(net, NULL, data->callref,
2888 GSM48_CAUSE_LOC_PRN_S_LU,
2889 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002890 }
2891 /* If subscriber is not "attached" */
2892 if (!subscr->lac) {
2893 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2894 "Received '%s' from MNCC with "
2895 "detached subscriber %s\n", data->called.number,
2896 get_mncc_name(msg_type), data->called.number);
2897 subscr_put(subscr);
2898 /* Temporarily out of order */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002899 return mncc_release_ind(net, NULL, data->callref,
2900 GSM48_CAUSE_LOC_PRN_S_LU,
2901 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002902 }
2903 /* Create transaction */
Harald Weltedcaf5652009-07-23 18:56:43 +02002904 trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref);
2905 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002906 DEBUGP(DCC, "No memory for trans.\n");
2907 subscr_put(subscr);
2908 /* Ressource unavailable */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002909 mncc_release_ind(net, NULL, data->callref,
2910 GSM48_CAUSE_LOC_PRN_S_LU,
2911 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002912 return -ENOMEM;
2913 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002914 /* Find lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002915 conn = connection_for_subscr(subscr);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01002916
Harald Welte4bfdfe72009-06-10 23:11:52 +08002917 /* If subscriber has no lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002918 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002919 /* find transaction with this subscriber already paging */
2920 llist_for_each_entry(transt, &net->trans_list, entry) {
2921 /* Transaction of our lchan? */
2922 if (transt == trans ||
2923 transt->subscr != subscr)
2924 continue;
2925 DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) "
2926 "Received '%s' from MNCC with "
2927 "unallocated channel, paging already "
2928 "started.\n", bts->nr,
2929 data->called.number,
2930 get_mncc_name(msg_type));
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002931 subscr_put(subscr);
2932 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002933 return 0;
2934 }
2935 /* store setup informations until paging was successfull */
Harald Weltedcaf5652009-07-23 18:56:43 +02002936 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
Harald Weltea1b28582009-08-01 19:31:47 +02002937 /* Trigger paging */
2938 paging_request(net, subscr, RSL_CHANNEED_TCH_F,
2939 setup_trig_pag_evt, subscr);
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002940 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002941 return 0;
2942 }
2943 /* Assign lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002944 trans->conn = conn;
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002945 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002946 }
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002947
2948 if (trans->conn)
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002949 conn = trans->conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002950
2951 /* if paging did not respond yet */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002952 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002953 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02002954 "Received '%s' from MNCC in paging state\n",
Harald Welte4bfdfe72009-06-10 23:11:52 +08002955 (trans->subscr)?(trans->subscr->extension):"-",
2956 get_mncc_name(msg_type));
Harald Weltec66b71c2009-06-11 14:23:20 +08002957 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
2958 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002959 if (msg_type == MNCC_REL_REQ)
2960 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
2961 else
2962 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
2963 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002964 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002965 return rc;
2966 }
2967
2968 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) "
2969 "Received '%s' from MNCC in state %d (%s)\n",
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002970 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002971 trans->transaction_id,
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002972 (trans->conn->subscr)?(trans->conn->subscr->extension):"-",
Harald Weltedcaf5652009-07-23 18:56:43 +02002973 get_mncc_name(msg_type), trans->cc.state,
Harald Weltee95daf192010-03-25 12:13:02 +08002974 gsm48_cc_state_name(trans->cc.state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002975
2976 /* Find function for current state and message */
2977 for (i = 0; i < DOWNSLLEN; i++)
2978 if ((msg_type == downstatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02002979 && ((1 << trans->cc.state) & downstatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08002980 break;
2981 if (i == DOWNSLLEN) {
2982 DEBUGP(DCC, "Message unhandled at this state.\n");
2983 return 0;
2984 }
2985
2986 rc = downstatelist[i].rout(trans, arg);
2987
2988 return rc;
2989}
2990
2991
2992static struct datastate {
2993 u_int32_t states;
2994 int type;
2995 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
2996} datastatelist[] = {
2997 /* mobile originating call establishment */
2998 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2999 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
3000 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
3001 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
3002 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
3003 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
3004 /* mobile terminating call establishment */
3005 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
3006 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
3007 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
3008 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02003009 {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 Welte4bfdfe72009-06-10 23:11:52 +08003010 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
3011 /* signalling during call */
3012 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
3013 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
3014 {SBIT(GSM_CSTATE_ACTIVE),
3015 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
3016 {ALL_STATES,
3017 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
3018 {ALL_STATES,
3019 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
3020 {ALL_STATES,
3021 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
3022 {SBIT(GSM_CSTATE_ACTIVE),
3023 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
3024 {SBIT(GSM_CSTATE_ACTIVE),
3025 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
3026 {SBIT(GSM_CSTATE_ACTIVE),
3027 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
3028 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3029 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
3030 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3031 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
3032 {SBIT(GSM_CSTATE_ACTIVE),
3033 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
3034 /* clearing */
3035 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3036 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
3037 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
3038 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
3039 {ALL_STATES, /* 5.4.3.4 */
3040 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
3041};
3042
3043#define DATASLLEN \
3044 (sizeof(datastatelist) / sizeof(struct datastate))
3045
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003046static int gsm0408_rcv_cc(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4bc90a12008-12-27 16:32:52 +00003047{
3048 struct gsm48_hdr *gh = msgb_l3(msg);
3049 u_int8_t msg_type = gh->msg_type & 0xbf;
Harald Welte6f5aee02009-07-23 21:21:14 +02003050 u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */
Harald Weltedcaf5652009-07-23 18:56:43 +02003051 struct gsm_trans *trans = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003052 int i, rc = 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00003053
Harald Welte4bfdfe72009-06-10 23:11:52 +08003054 if (msg_type & 0x80) {
3055 DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type);
3056 return -EINVAL;
Harald Welte4bc90a12008-12-27 16:32:52 +00003057 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003058
Harald Welte4bfdfe72009-06-10 23:11:52 +08003059 /* Find transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003060 trans = trans_find_by_id(conn->subscr, GSM48_PDISC_CC, transaction_id);
Harald Weltedcaf5652009-07-23 18:56:43 +02003061
Harald Welte6f5aee02009-07-23 21:21:14 +02003062 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003063 "Received '%s' from MS in state %d (%s)\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003064 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003065 transaction_id, (conn->subscr)?(conn->subscr->extension):"-",
Harald Weltee95daf192010-03-25 12:13:02 +08003066 gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0,
3067 gsm48_cc_state_name(trans?(trans->cc.state):0));
Harald Welte4bfdfe72009-06-10 23:11:52 +08003068
3069 /* Create transaction */
3070 if (!trans) {
Harald Welte6f5aee02009-07-23 21:21:14 +02003071 DEBUGP(DCC, "Unknown transaction ID %x, "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003072 "creating new trans.\n", transaction_id);
3073 /* Create transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003074 trans = trans_alloc(conn->subscr, GSM48_PDISC_CC,
Harald Weltedcaf5652009-07-23 18:56:43 +02003075 transaction_id, new_callref++);
3076 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08003077 DEBUGP(DCC, "No memory for trans.\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08003078 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02003079 GSM48_PDISC_CC | (transaction_id << 4),
Harald Welte4bfdfe72009-06-10 23:11:52 +08003080 GSM48_MT_CC_RELEASE_COMPL);
3081 return -ENOMEM;
3082 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08003083 /* Assign transaction */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003084 trans->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003085 }
3086
3087 /* find function for current state and message */
3088 for (i = 0; i < DATASLLEN; i++)
3089 if ((msg_type == datastatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02003090 && ((1 << trans->cc.state) & datastatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08003091 break;
3092 if (i == DATASLLEN) {
3093 DEBUGP(DCC, "Message unhandled at this state.\n");
3094 return 0;
3095 }
3096
3097 rc = datastatelist[i].rout(trans, msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00003098
3099 return rc;
3100}
3101
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003102/* Create a dummy to wait five seconds */
3103static void release_anchor(struct gsm_subscriber_connection *conn)
3104{
3105 if (!conn->anch_operation)
3106 return;
3107
3108 bsc_del_timer(&conn->anch_operation->timeout);
3109 talloc_free(conn->anch_operation);
3110 conn->anch_operation = NULL;
3111}
3112
3113static void anchor_timeout(void *_data)
3114{
3115 struct gsm_subscriber_connection *con = _data;
3116
3117 release_anchor(con);
3118 msc_release_connection(con);
3119}
3120
3121int gsm0408_new_conn(struct gsm_subscriber_connection *conn)
3122{
3123 conn->anch_operation = talloc_zero(conn, struct gsm_anchor_operation);
3124 if (!conn->anch_operation)
3125 return -1;
3126
3127 conn->anch_operation->timeout.data = conn;
3128 conn->anch_operation->timeout.cb = anchor_timeout;
3129 bsc_schedule_timer(&conn->anch_operation->timeout, 5, 0);
3130 return 0;
3131}
3132
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003133/* here we get data from the BSC level... */
3134int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00003135{
3136 struct gsm48_hdr *gh = msgb_l3(msg);
3137 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +00003138 int rc = 0;
Harald Welte51008772009-12-29 11:49:12 +01003139
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +08003140 if (silent_call_reroute(conn, msg))
3141 return silent_call_rx(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003142
3143 switch (pdisc) {
3144 case GSM48_PDISC_CC:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003145 release_anchor(conn);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003146 rc = gsm0408_rcv_cc(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003147 break;
3148 case GSM48_PDISC_MM:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003149 rc = gsm0408_rcv_mm(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003150 break;
3151 case GSM48_PDISC_RR:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003152 rc = gsm0408_rcv_rr(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003153 break;
Harald Weltebcae43f2008-12-27 21:45:37 +00003154 case GSM48_PDISC_SMS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003155 release_anchor(conn);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003156 rc = gsm0411_rcv_sms(conn, msg);
Harald Weltebcae43f2008-12-27 21:45:37 +00003157 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003158 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +00003159 case GSM48_PDISC_SM_GPRS:
Harald Welte5d24ba12009-12-24 12:13:17 +01003160 LOGP(DRLL, LOGL_NOTICE, "Unimplemented "
3161 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003162 break;
Harald Welte6eafe912009-10-16 08:32:58 +02003163 case GSM48_PDISC_NC_SS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003164 release_anchor(conn);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +08003165 rc = handle_rcv_ussd(conn, msg);
Harald Welte6eafe912009-10-16 08:32:58 +02003166 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003167 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01003168 LOGP(DRLL, LOGL_NOTICE, "Unknown "
3169 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003170 break;
3171 }
3172
3173 return rc;
3174}
Harald Welte8470bf22008-12-25 23:28:35 +00003175
Harald Welte805f6442009-07-28 18:25:29 +02003176/*
3177 * This will be ran by the linker when loading the DSO. We use it to
3178 * do system initialization, e.g. registration of signal handlers.
3179 */
3180static __attribute__((constructor)) void on_dso_load_0408(void)
3181{
Harald Welte805f6442009-07-28 18:25:29 +02003182 register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL);
3183}