blob: 562c24d43976a6b4f5a8dc1dc7dba0ba3cab5132 [file] [log] [blame]
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
Harald Welte59b04682009-06-10 05:40:52 +08002 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30#include <time.h>
31#include <netinet/in.h>
32
Sylvain Munaut28c47162009-12-24 00:27:26 +010033#include <openbsc/auth.h>
Harald Welte59b04682009-06-10 05:40:52 +080034#include <openbsc/db.h>
Harald Weltef4625b12010-02-20 16:24:02 +010035#include <osmocore/msgb.h>
36#include <osmocore/bitvec.h>
37#include <osmocore/tlv.h>
Harald Welte59b04682009-06-10 05:40:52 +080038#include <openbsc/debug.h>
39#include <openbsc/gsm_data.h>
Harald Weltef4625b12010-02-20 16:24:02 +010040#include <osmocore/gsm_utils.h>
Harald Welte59b04682009-06-10 05:40:52 +080041#include <openbsc/gsm_subscriber.h>
42#include <openbsc/gsm_04_11.h>
43#include <openbsc/gsm_04_08.h>
44#include <openbsc/abis_rsl.h>
45#include <openbsc/chan_alloc.h>
46#include <openbsc/paging.h>
47#include <openbsc/signal.h>
48#include <openbsc/trau_frame.h>
49#include <openbsc/trau_mux.h>
Harald Welte3c062072009-07-28 18:25:29 +020050#include <openbsc/rtp_proxy.h>
Harald Weltef4625b12010-02-20 16:24:02 +010051#include <osmocore/talloc.h>
Harald Weltefdc93d92010-03-07 23:40:35 +010052#include <osmocore/gsm48.h>
Harald Weltec2189a62009-07-23 18:56:43 +020053#include <openbsc/transaction.h>
Harald Welte03115042009-10-16 08:32:58 +020054#include <openbsc/ussd.h>
Harald Weltef6a38ec2009-12-29 11:49:12 +010055#include <openbsc/silent_call.h>
Harald Welte59b04682009-06-10 05:40:52 +080056
Harald Welte (local)8751ee92009-08-15 02:30:58 +020057void *tall_locop_ctx;
Sylvain Munaut28c47162009-12-24 00:27:26 +010058void *tall_authciphop_ctx;
Harald Weltea8379772009-06-20 22:36:41 +020059
Harald Welte59b04682009-06-10 05:40:52 +080060int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi);
61static int gsm48_tx_simple(struct gsm_lchan *lchan,
62 u_int8_t pdisc, u_int8_t msg_type);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010063static void schedule_reject(struct gsm_subscriber_connection *conn);
Harald Welte59b04682009-06-10 05:40:52 +080064
65struct gsm_lai {
66 u_int16_t mcc;
67 u_int16_t mnc;
68 u_int16_t lac;
69};
70
Harald Welte03740842009-06-10 23:11:52 +080071static u_int32_t new_callref = 0x80000001;
72
Sylvain Munaut28c47162009-12-24 00:27:26 +010073
74static void release_security_operation(struct gsm_subscriber_connection *conn)
75{
76 if (!conn->sec_operation)
77 return;
78
79 talloc_free(conn->sec_operation);
80 conn->sec_operation = NULL;
81 put_subscr_con(conn);
82}
83
84static void allocate_security_operation(struct gsm_subscriber_connection *conn)
85{
86 use_subscr_con(conn)
87
88 conn->sec_operation = talloc_zero(tall_authciphop_ctx,
89 struct gsm_security_operation);
90}
91
92int gsm48_secure_channel(struct gsm_lchan *lchan, int key_seq,
93 gsm_cbfn *cb, void *cb_data)
94{
95 struct gsm_network *net = lchan->ts->trx->bts->network;
96 struct gsm_subscriber *subscr = lchan->conn.subscr;
97 struct gsm_security_operation *op;
98 struct gsm_auth_tuple atuple;
99 int status = -1, rc;
100
101 /* Check if we _can_ enable encryption. Cases where we can't:
102 * - Encryption disabled in config
103 * - Channel already secured (nothing to do)
104 * - Subscriber equipment doesn't support configured encryption
105 */
106 if (!net->a5_encryption) {
107 status = GSM_SECURITY_NOAVAIL;
108 } else if (lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
109 DEBUGP(DMM, "Requesting to secure an already secure channel");
110 status = GSM_SECURITY_SUCCEEDED;
111 } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2,
112 net->a5_encryption)) {
113 DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption");
114 status = GSM_SECURITY_NOAVAIL;
115 }
116
117 /* If not done yet, try to get info for this user */
118 if (status < 0) {
119 rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq);
120 if (rc <= 0)
121 status = GSM_SECURITY_NOAVAIL;
122 }
123
124 /* Are we done yet ? */
125 if (status >= 0)
126 return cb ?
127 cb(GSM_HOOK_RR_SECURITY, status, NULL, lchan, cb_data) :
128 0;
129
130 /* Start an operation (can't have more than one pending !!!) */
131 if (lchan->conn.sec_operation)
132 return -EBUSY;
133
134 allocate_security_operation(&lchan->conn);
135 op = lchan->conn.sec_operation;
136 op->cb = cb;
137 op->cb_data = cb_data;
138 memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple));
139
140 /* FIXME: Should start a timer for completion ... */
141
142 /* Then do whatever is needed ... */
143 if (rc == 1) {
144 /* Start authentication */
145 return gsm48_tx_mm_auth_req(lchan, op->atuple.rand, op->atuple.key_seq);
146 } else if (rc == 2) {
147 /* Start ciphering directly */
148 lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
149 lchan->encr.key_len = 8;
150 memcpy(lchan->encr.key, op->atuple.kc, 8);
151
152 return gsm48_send_rr_ciph_mode(lchan, 0);
153 }
154
155 return -EINVAL; /* not reached */
156}
157
Harald Welte59b04682009-06-10 05:40:52 +0800158static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
159 struct gsm_subscriber *subscriber)
160{
161 if (!subscriber)
162 return 0;
163
164 /*
165 * Do not send accept yet as more information should arrive. Some
166 * phones will not send us the information and we will have to check
167 * what we want to do with that.
168 */
169 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
170 return 0;
171
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200172 switch (subscriber->net->auth_policy) {
173 case GSM_AUTH_POLICY_CLOSED:
174 return subscriber->authorized;
Harald Welte (local)16480eb2009-08-13 13:49:51 +0200175 case GSM_AUTH_POLICY_TOKEN:
Harald Welte (local)272f5c72009-08-13 20:44:23 +0200176 if (subscriber->authorized)
177 return subscriber->authorized;
Harald Welte (local)16480eb2009-08-13 13:49:51 +0200178 return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200179 case GSM_AUTH_POLICY_ACCEPT_ALL:
Harald Welte59b04682009-06-10 05:40:52 +0800180 return 1;
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200181 default:
182 return 0;
183 }
Harald Welte59b04682009-06-10 05:40:52 +0800184}
185
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100186static void release_loc_updating_req(struct gsm_subscriber_connection *conn)
Harald Welte59b04682009-06-10 05:40:52 +0800187{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100188 if (!conn->loc_operation)
Harald Welte59b04682009-06-10 05:40:52 +0800189 return;
190
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100191 bsc_del_timer(&conn->loc_operation->updating_timer);
192 talloc_free(conn->loc_operation);
193 conn->loc_operation = 0;
194 put_subscr_con(conn);
Harald Welte59b04682009-06-10 05:40:52 +0800195}
196
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100197static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
Harald Welte59b04682009-06-10 05:40:52 +0800198{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100199 use_subscr_con(conn)
200 release_loc_updating_req(conn);
Harald Welte59b04682009-06-10 05:40:52 +0800201
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100202 conn->loc_operation = talloc_zero(tall_locop_ctx,
Harald Welte857e00d2009-06-26 20:25:23 +0200203 struct gsm_loc_updating_operation);
Harald Welte59b04682009-06-10 05:40:52 +0800204}
205
Sylvain Munautcb321fb2009-12-24 00:28:01 +0100206static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event,
207 struct msgb *msg, void *data, void *param)
208{
209 struct gsm_lchan *lchan = data;
210 struct gsm_subscriber_connection *conn = &lchan->conn;
211 int rc = 0;
212
213 switch (event) {
214 case GSM_SECURITY_AUTH_FAILED:
215 release_loc_updating_req(conn);
216 break;
217
218 case GSM_SECURITY_NOAVAIL:
219 case GSM_SECURITY_SUCCEEDED:
220 /* We're all good */
221 db_subscriber_alloc_tmsi(conn->subscr);
222 release_loc_updating_req(conn);
223 rc = gsm0408_loc_upd_acc(lchan, conn->subscr->tmsi);
224 if (lchan->ts->trx->bts->network->send_mm_info) {
225 /* send MM INFO with network name */
226 rc = gsm48_tx_mm_info(lchan);
227 }
228
229 /* call subscr_update after putting the loc_upd_acc
230 * in the transmit queue, since S_SUBSCR_ATTACHED might
231 * trigger further action like SMS delivery */
232 subscr_update(conn->subscr, lchan->ts->trx->bts,
233 GSM_SUBSCRIBER_UPDATE_ATTACHED);
234
235 /* try to close channel ASAP */
236 lchan_auto_release(lchan);
237
238 break;
239
240 default:
241 rc = -EINVAL;
242 };
243
244 return rc;
245}
246
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100247static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +0800248{
Sylvain Munautcb321fb2009-12-24 00:28:01 +0100249 if (authorize_subscriber(conn->loc_operation, conn->subscr))
250 return gsm48_secure_channel(conn->lchan,
251 conn->loc_operation->key_seq,
252 _gsm0408_authorize_sec_cb, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800253 return 0;
254}
255
256static int gsm0408_handle_lchan_signal(unsigned int subsys, unsigned int signal,
257 void *handler_data, void *signal_data)
258{
Harald Welte03740842009-06-10 23:11:52 +0800259 struct gsm_trans *trans, *temp;
260
Harald Welte59b04682009-06-10 05:40:52 +0800261 if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE)
262 return 0;
263
264 /*
265 * Cancel any outstanding location updating request
266 * operation taking place on the lchan.
267 */
Harald Welte12560da2009-07-04 09:35:21 +0200268 struct gsm_lchan *lchan = (struct gsm_lchan *)signal_data;
Harald Welte1ff81b52009-06-26 20:17:06 +0200269 if (!lchan)
270 return 0;
271
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100272 release_loc_updating_req(&lchan->conn);
Sylvain Munaut28c47162009-12-24 00:27:26 +0100273 release_security_operation(&lchan->conn);
Harald Welte59b04682009-06-10 05:40:52 +0800274
Harald Welte03740842009-06-10 23:11:52 +0800275 /* Free all transactions that are associated with the released lchan */
Harald Weltec2189a62009-07-23 18:56:43 +0200276 /* FIXME: this is not neccessarily the right thing to do, we should
277 * only set trans->lchan to NULL and wait for another lchan to be
278 * established to the same MM entity (phone/subscriber) */
Harald Welte03740842009-06-10 23:11:52 +0800279 llist_for_each_entry_safe(trans, temp, &lchan->ts->trx->bts->network->trans_list, entry) {
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +0100280 if (trans->conn && trans->conn->lchan == lchan)
Harald Weltec2189a62009-07-23 18:56:43 +0200281 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +0800282 }
283
Harald Welte59b04682009-06-10 05:40:52 +0800284 return 0;
285}
286
Harald Welte59b04682009-06-10 05:40:52 +0800287/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
288int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
289{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100290 struct gsm_subscriber_connection *conn;
Harald Welte3edc5a92009-12-22 00:41:05 +0100291 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800292 struct msgb *msg = gsm48_msgb_alloc();
293 struct gsm48_hdr *gh;
294
295 msg->lchan = lchan;
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100296 conn = &lchan->conn;
Harald Welte59b04682009-06-10 05:40:52 +0800297
298 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
299 gh->proto_discr = GSM48_PDISC_MM;
300 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
301 gh->data[0] = cause;
302
Harald Welte (local)38a9e5d2009-12-26 22:15:28 +0100303 LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT "
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100304 "LAC=%u BTS=%u\n", conn->subscr ?
305 subscr_name(conn->subscr) : "unknown",
Harald Welte (local)38a9e5d2009-12-26 22:15:28 +0100306 lchan->ts->trx->bts->location_area_code, lchan->ts->trx->bts->nr);
Harald Welte3edc5a92009-12-22 00:41:05 +0100307
Harald Weltebdbb7442009-12-22 19:07:32 +0100308 counter_inc(bts->network->stats.loc_upd_resp.reject);
Harald Welte59b04682009-06-10 05:40:52 +0800309
Harald Welte36fe2e82009-07-23 21:13:03 +0200310 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800311}
312
313/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
314int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
315{
316 struct gsm_bts *bts = lchan->ts->trx->bts;
317 struct msgb *msg = gsm48_msgb_alloc();
318 struct gsm48_hdr *gh;
319 struct gsm48_loc_area_id *lai;
320 u_int8_t *mid;
Harald Welte59b04682009-06-10 05:40:52 +0800321
322 msg->lchan = lchan;
323
324 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
325 gh->proto_discr = GSM48_PDISC_MM;
326 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
327
328 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Harald Welted8493ac2010-03-04 10:55:40 +0100329 gsm48_generate_lai(lai, bts->network->country_code,
Harald Welte59b04682009-06-10 05:40:52 +0800330 bts->network->network_code, bts->location_area_code);
331
Holger Hans Peter Freyther36897102009-08-01 07:26:59 +0200332 mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
Holger Hans Peter Freyther20a0f322009-08-20 08:41:24 +0200333 gsm48_generate_mid_from_tmsi(mid, tmsi);
Harald Welte59b04682009-06-10 05:40:52 +0800334
335 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
336
Harald Weltebdbb7442009-12-22 19:07:32 +0100337 counter_inc(bts->network->stats.loc_upd_resp.accept);
Harald Welte3edc5a92009-12-22 00:41:05 +0100338
Harald Welte9ed54ff2009-12-12 21:00:48 +0100339 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800340}
341
Harald Welte59b04682009-06-10 05:40:52 +0800342/* Transmit Chapter 9.2.10 Identity Request */
343static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
344{
345 struct msgb *msg = gsm48_msgb_alloc();
346 struct gsm48_hdr *gh;
347
348 msg->lchan = lchan;
349
350 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
351 gh->proto_discr = GSM48_PDISC_MM;
352 gh->msg_type = GSM48_MT_MM_ID_REQ;
353 gh->data[0] = id_type;
354
Harald Welte36fe2e82009-07-23 21:13:03 +0200355 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800356}
357
Harald Welte59b04682009-06-10 05:40:52 +0800358
359/* Parse Chapter 9.2.11 Identity Response */
360static int mm_rx_id_resp(struct msgb *msg)
361{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100362 struct gsm_subscriber_connection *conn;
Harald Welte59b04682009-06-10 05:40:52 +0800363 struct gsm48_hdr *gh = msgb_l3(msg);
364 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75350412009-07-23 18:46:00 +0200365 struct gsm_bts *bts = lchan->ts->trx->bts;
366 struct gsm_network *net = bts->network;
Harald Welte59b04682009-06-10 05:40:52 +0800367 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200368 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +0800369
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200370 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte59b04682009-06-10 05:40:52 +0800371 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
372 mi_type, mi_string);
373
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100374 conn = &lchan->conn;
375
Harald Welteedf48af2009-12-13 12:39:18 +0100376 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data);
377
Harald Welte59b04682009-06-10 05:40:52 +0800378 switch (mi_type) {
379 case GSM_MI_TYPE_IMSI:
Jan Luebbe9bdbd622009-08-12 10:19:34 +0200380 /* look up subscriber based on IMSI, create if not found */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100381 if (!conn->subscr) {
382 conn->subscr = subscr_get_by_imsi(net, mi_string);
383 if (!conn->subscr)
384 conn->subscr = db_create_subscriber(net, mi_string);
Jan Luebbee2974032009-08-12 10:12:52 +0200385 }
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100386 if (conn->loc_operation)
387 conn->loc_operation->waiting_for_imsi = 0;
Harald Welte59b04682009-06-10 05:40:52 +0800388 break;
389 case GSM_MI_TYPE_IMEI:
390 case GSM_MI_TYPE_IMEISV:
391 /* update subscribe <-> IMEI mapping */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100392 if (conn->subscr) {
393 db_subscriber_assoc_imei(conn->subscr, mi_string);
394 db_sync_equipment(&conn->subscr->equipment);
Harald Welte (local)ced09ed2009-08-17 09:39:55 +0200395 }
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100396 if (conn->loc_operation)
397 conn->loc_operation->waiting_for_imei = 0;
Harald Welte59b04682009-06-10 05:40:52 +0800398 break;
399 }
400
401 /* Check if we can let the mobile station enter */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100402 return gsm0408_authorize(conn, msg);
Harald Welte59b04682009-06-10 05:40:52 +0800403}
404
405
406static void loc_upd_rej_cb(void *data)
407{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100408 struct gsm_subscriber_connection *conn = data;
409 struct gsm_lchan *lchan = conn->lchan;
Harald Welte59936d72009-11-18 20:33:19 +0100410 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800411
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100412 release_loc_updating_req(conn);
Harald Welte59936d72009-11-18 20:33:19 +0100413 gsm0408_loc_upd_rej(lchan, bts->network->reject_cause);
Harald Welte59b04682009-06-10 05:40:52 +0800414 lchan_auto_release(lchan);
415}
416
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100417static void schedule_reject(struct gsm_subscriber_connection *conn)
Harald Welte59b04682009-06-10 05:40:52 +0800418{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100419 conn->loc_operation->updating_timer.cb = loc_upd_rej_cb;
420 conn->loc_operation->updating_timer.data = conn;
421 bsc_schedule_timer(&conn->loc_operation->updating_timer, 5, 0);
Harald Welte59b04682009-06-10 05:40:52 +0800422}
423
424static const char *lupd_name(u_int8_t type)
425{
426 switch (type) {
427 case GSM48_LUPD_NORMAL:
428 return "NORMAL";
429 case GSM48_LUPD_PERIODIC:
430 return "PEROIDOC";
431 case GSM48_LUPD_IMSI_ATT:
432 return "IMSI ATTACH";
433 default:
434 return "UNKNOWN";
435 }
436}
437
Harald Welte59b04682009-06-10 05:40:52 +0800438/* Chapter 9.2.15: Receive Location Updating Request */
439static int mm_rx_loc_upd_req(struct msgb *msg)
440{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100441 struct gsm_subscriber_connection *conn;
Harald Welte59b04682009-06-10 05:40:52 +0800442 struct gsm48_hdr *gh = msgb_l3(msg);
443 struct gsm48_loc_upd_req *lu;
Harald Welte03740842009-06-10 23:11:52 +0800444 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800445 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75350412009-07-23 18:46:00 +0200446 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800447 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200448 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +0800449 int rc;
450
451 lu = (struct gsm48_loc_upd_req *) gh->data;
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100452 conn = &lchan->conn;
Harald Welte59b04682009-06-10 05:40:52 +0800453
454 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
455
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200456 gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
Harald Welte59b04682009-06-10 05:40:52 +0800457
Harald Welte79639662009-06-27 02:58:43 +0200458 DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
Harald Welte59b04682009-06-10 05:40:52 +0800459 lupd_name(lu->type));
460
Harald Welteedf48af2009-12-13 12:39:18 +0100461 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len);
462
Harald Welte3edc5a92009-12-22 00:41:05 +0100463 switch (lu->type) {
464 case GSM48_LUPD_NORMAL:
Harald Weltebdbb7442009-12-22 19:07:32 +0100465 counter_inc(bts->network->stats.loc_upd_type.normal);
Harald Welte3edc5a92009-12-22 00:41:05 +0100466 break;
467 case GSM48_LUPD_IMSI_ATT:
Harald Weltebdbb7442009-12-22 19:07:32 +0100468 counter_inc(bts->network->stats.loc_upd_type.attach);
Harald Welte3edc5a92009-12-22 00:41:05 +0100469 break;
470 case GSM48_LUPD_PERIODIC:
Harald Weltebdbb7442009-12-22 19:07:32 +0100471 counter_inc(bts->network->stats.loc_upd_type.periodic);
Harald Welte3edc5a92009-12-22 00:41:05 +0100472 break;
473 }
474
Harald Welte59b04682009-06-10 05:40:52 +0800475 /*
476 * Pseudo Spoof detection: Just drop a second/concurrent
477 * location updating request.
478 */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100479 if (conn->loc_operation) {
Harald Welte79639662009-06-27 02:58:43 +0200480 DEBUGPC(DMM, "ignoring request due an existing one: %p.\n",
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100481 conn->loc_operation);
Harald Welte59b04682009-06-10 05:40:52 +0800482 gsm0408_loc_upd_rej(lchan, GSM48_REJECT_PROTOCOL_ERROR);
483 return 0;
484 }
485
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100486 allocate_loc_updating_req(&lchan->conn);
Harald Welte59b04682009-06-10 05:40:52 +0800487
Sylvain Munaut360fc582010-06-10 13:36:59 +0200488 conn->loc_operation->key_seq = lu->key_seq;
489
Harald Welte59b04682009-06-10 05:40:52 +0800490 switch (mi_type) {
491 case GSM_MI_TYPE_IMSI:
Harald Welte79639662009-06-27 02:58:43 +0200492 DEBUGPC(DMM, "\n");
Harald Welte59b04682009-06-10 05:40:52 +0800493 /* we always want the IMEI, too */
Harald Welte59b04682009-06-10 05:40:52 +0800494 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100495 conn->loc_operation->waiting_for_imei = 1;
Harald Welte59b04682009-06-10 05:40:52 +0800496
Jan Luebbe9bdbd622009-08-12 10:19:34 +0200497 /* look up subscriber based on IMSI, create if not found */
498 subscr = subscr_get_by_imsi(bts->network, mi_string);
499 if (!subscr) {
500 subscr = db_create_subscriber(bts->network, mi_string);
501 }
Harald Welte59b04682009-06-10 05:40:52 +0800502 break;
503 case GSM_MI_TYPE_TMSI:
Harald Welte79639662009-06-27 02:58:43 +0200504 DEBUGPC(DMM, "\n");
Harald Welte59b04682009-06-10 05:40:52 +0800505 /* look up the subscriber based on TMSI, request IMSI if it fails */
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200506 subscr = subscr_get_by_tmsi(bts->network,
507 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +0800508 if (!subscr) {
509 /* send IDENTITY REQUEST message to get IMSI */
Harald Welte59b04682009-06-10 05:40:52 +0800510 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100511 conn->loc_operation->waiting_for_imsi = 1;
Harald Welte59b04682009-06-10 05:40:52 +0800512 }
Harald Welteca6dfc02010-06-07 17:56:32 +0200513 /* we always want the IMEI, too */
514 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
515 conn->loc_operation->waiting_for_imei = 1;
Harald Welte59b04682009-06-10 05:40:52 +0800516 break;
517 case GSM_MI_TYPE_IMEI:
518 case GSM_MI_TYPE_IMEISV:
519 /* no sim card... FIXME: what to do ? */
Harald Welte79639662009-06-27 02:58:43 +0200520 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte59b04682009-06-10 05:40:52 +0800521 break;
522 default:
Harald Welte79639662009-06-27 02:58:43 +0200523 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte59b04682009-06-10 05:40:52 +0800524 break;
525 }
526
Harald Welteccd69362009-07-04 10:18:00 +0200527 /* schedule the reject timer */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100528 schedule_reject(conn);
Harald Welteccd69362009-07-04 10:18:00 +0200529
Harald Welte03740842009-06-10 23:11:52 +0800530 if (!subscr) {
Harald Welte79639662009-06-27 02:58:43 +0200531 DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte03740842009-06-10 23:11:52 +0800532 /* FIXME: request id? close channel? */
533 return -EINVAL;
534 }
535
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100536 conn->subscr = subscr;
537 conn->subscr->equipment.classmark1 = lu->classmark1;
Harald Welte59b04682009-06-10 05:40:52 +0800538
Harald Welteccd69362009-07-04 10:18:00 +0200539 /* check if we can let the subscriber into our network immediately
540 * or if we need to wait for identity responses. */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100541 return gsm0408_authorize(conn, msg);
Harald Welte59b04682009-06-10 05:40:52 +0800542}
543
Harald Welte03740842009-06-10 23:11:52 +0800544#if 0
545static u_int8_t to_bcd8(u_int8_t val)
546{
547 return ((val / 10) << 4) | (val % 10);
548}
549#endif
550
Harald Welte59b04682009-06-10 05:40:52 +0800551/* Section 9.2.15a */
552int gsm48_tx_mm_info(struct gsm_lchan *lchan)
553{
554 struct msgb *msg = gsm48_msgb_alloc();
555 struct gsm48_hdr *gh;
556 struct gsm_network *net = lchan->ts->trx->bts->network;
557 u_int8_t *ptr8;
Daniel Willmannc8188202009-08-13 03:42:07 +0200558 int name_len, name_pad;
Harald Welte03740842009-06-10 23:11:52 +0800559#if 0
560 time_t cur_t;
561 struct tm* cur_time;
562 int tz15min;
563#endif
Harald Welte59b04682009-06-10 05:40:52 +0800564
565 msg->lchan = lchan;
566
567 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
568 gh->proto_discr = GSM48_PDISC_MM;
569 gh->msg_type = GSM48_MT_MM_INFO;
570
571 if (net->name_long) {
Daniel Willmannc8188202009-08-13 03:42:07 +0200572#if 0
Harald Welte59b04682009-06-10 05:40:52 +0800573 name_len = strlen(net->name_long);
574 /* 10.5.3.5a */
575 ptr8 = msgb_put(msg, 3);
576 ptr8[0] = GSM48_IE_NAME_LONG;
577 ptr8[1] = name_len*2 +1;
578 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
579
580 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
581 for (i = 0; i < name_len; i++)
582 ptr16[i] = htons(net->name_long[i]);
583
584 /* FIXME: Use Cell Broadcast, not UCS-2, since
585 * UCS-2 is only supported by later revisions of the spec */
Daniel Willmannc8188202009-08-13 03:42:07 +0200586#endif
587 name_len = (strlen(net->name_long)*7)/8;
588 name_pad = (8 - strlen(net->name_long)*7)%8;
589 if (name_pad > 0)
590 name_len++;
591 /* 10.5.3.5a */
592 ptr8 = msgb_put(msg, 3);
593 ptr8[0] = GSM48_IE_NAME_LONG;
594 ptr8[1] = name_len +1;
595 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
596
597 ptr8 = msgb_put(msg, name_len);
598 gsm_7bit_encode(ptr8, net->name_long);
599
Harald Welte59b04682009-06-10 05:40:52 +0800600 }
601
602 if (net->name_short) {
Daniel Willmannc8188202009-08-13 03:42:07 +0200603#if 0
Harald Welte59b04682009-06-10 05:40:52 +0800604 name_len = strlen(net->name_short);
605 /* 10.5.3.5a */
606 ptr8 = (u_int8_t *) msgb_put(msg, 3);
Harald Weltef6284712009-07-19 17:51:36 +0200607 ptr8[0] = GSM48_IE_NAME_SHORT;
Harald Welte59b04682009-06-10 05:40:52 +0800608 ptr8[1] = name_len*2 + 1;
609 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
610
611 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
612 for (i = 0; i < name_len; i++)
613 ptr16[i] = htons(net->name_short[i]);
Daniel Willmannc8188202009-08-13 03:42:07 +0200614#endif
615 name_len = (strlen(net->name_short)*7)/8;
616 name_pad = (8 - strlen(net->name_short)*7)%8;
617 if (name_pad > 0)
618 name_len++;
619 /* 10.5.3.5a */
620 ptr8 = (u_int8_t *) msgb_put(msg, 3);
621 ptr8[0] = GSM48_IE_NAME_SHORT;
622 ptr8[1] = name_len +1;
623 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
624
625 ptr8 = msgb_put(msg, name_len);
626 gsm_7bit_encode(ptr8, net->name_short);
627
Harald Welte59b04682009-06-10 05:40:52 +0800628 }
629
630#if 0
Harald Welte59b04682009-06-10 05:40:52 +0800631 /* Section 10.5.3.9 */
632 cur_t = time(NULL);
Harald Welte03740842009-06-10 23:11:52 +0800633 cur_time = gmtime(&cur_t);
Harald Welte59b04682009-06-10 05:40:52 +0800634 ptr8 = msgb_put(msg, 8);
635 ptr8[0] = GSM48_IE_NET_TIME_TZ;
636 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
637 ptr8[2] = to_bcd8(cur_time->tm_mon);
638 ptr8[3] = to_bcd8(cur_time->tm_mday);
639 ptr8[4] = to_bcd8(cur_time->tm_hour);
640 ptr8[5] = to_bcd8(cur_time->tm_min);
641 ptr8[6] = to_bcd8(cur_time->tm_sec);
642 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
643 tz15min = (cur_time->tm_gmtoff)/(60*15);
Harald Welte03740842009-06-10 23:11:52 +0800644 ptr8[7] = to_bcd8(tz15min);
Harald Welte59b04682009-06-10 05:40:52 +0800645 if (tz15min < 0)
Harald Welte03740842009-06-10 23:11:52 +0800646 ptr8[7] |= 0x80;
Harald Welte59b04682009-06-10 05:40:52 +0800647#endif
648
Daniel Willmannc8188202009-08-13 03:42:07 +0200649 DEBUGP(DMM, "-> MM INFO\n");
650
Harald Welte36fe2e82009-07-23 21:13:03 +0200651 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800652}
653
Harald Welte36970f62009-08-12 22:56:50 +0200654/* Section 9.2.2 */
Sylvain Munaut0789c592009-12-24 00:23:46 +0100655int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand, int key_seq)
Harald Welte36970f62009-08-12 22:56:50 +0200656{
657 struct msgb *msg = gsm48_msgb_alloc();
658 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Sylvain Munaut6de6dc12009-09-27 11:10:17 +0200659 struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar));
Harald Welte36970f62009-08-12 22:56:50 +0200660
Sylvain Munautb1a4f282009-12-24 00:24:29 +0100661 DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", hexdump(rand, 16));
Harald Welte36970f62009-08-12 22:56:50 +0200662
663 msg->lchan = lchan;
664 gh->proto_discr = GSM48_PDISC_MM;
665 gh->msg_type = GSM48_MT_MM_AUTH_REQ;
666
Sylvain Munaut0789c592009-12-24 00:23:46 +0100667 ar->key_seq = key_seq;
Sylvain Munaut6de6dc12009-09-27 11:10:17 +0200668
Harald Welte36970f62009-08-12 22:56:50 +0200669 /* 16 bytes RAND parameters */
Harald Welte36970f62009-08-12 22:56:50 +0200670 if (rand)
Sylvain Munaut6de6dc12009-09-27 11:10:17 +0200671 memcpy(ar->rand, rand, 16);
Harald Welte36970f62009-08-12 22:56:50 +0200672
673 return gsm48_sendmsg(msg, NULL);
674}
675
676/* Section 9.2.1 */
677int gsm48_tx_mm_auth_rej(struct gsm_lchan *lchan)
678{
679 DEBUGP(DMM, "-> AUTH REJECT\n");
680 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ);
681}
682
Harald Welte59b04682009-06-10 05:40:52 +0800683static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
684{
685 DEBUGP(DMM, "-> CM SERVICE ACK\n");
686 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
687}
688
689/* 9.2.6 CM service reject */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100690static int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
Harald Welte59b04682009-06-10 05:40:52 +0800691 enum gsm48_reject_value value)
692{
693 struct msgb *msg = gsm48_msgb_alloc();
694 struct gsm48_hdr *gh;
695
696 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
697
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100698 msg->lchan = conn->lchan;
699 use_subscr_con(conn);
Harald Welte59b04682009-06-10 05:40:52 +0800700
701 gh->proto_discr = GSM48_PDISC_MM;
702 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
703 gh->data[0] = value;
704 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
705
Harald Welte36fe2e82009-07-23 21:13:03 +0200706 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800707}
708
Sylvain Munautbadc7112009-12-24 00:28:46 +0100709static int _gsm48_rx_mm_serv_req_sec_cb(
710 unsigned int hooknum, unsigned int event,
711 struct msgb *msg, void *data, void *param)
712{
713 struct gsm_lchan *lchan = data;
714 int rc = 0;
715
716 switch (event) {
717 case GSM_SECURITY_AUTH_FAILED:
718 /* Nothing to do */
719 break;
720
721 case GSM_SECURITY_NOAVAIL:
722 rc = gsm48_tx_mm_serv_ack(lchan);
723 break;
724
725 case GSM_SECURITY_SUCCEEDED:
726 /* nothing to do. CIPHER MODE COMMAND is
727 * implicit CM SERV ACK */
728 break;
729
730 default:
731 rc = -EINVAL;
732 };
733
734 return rc;
735}
736
Harald Welte59b04682009-06-10 05:40:52 +0800737/*
738 * Handle CM Service Requests
739 * a) Verify that the packet is long enough to contain the information
740 * we require otherwsie reject with INCORRECT_MESSAGE
741 * b) Try to parse the TMSI. If we do not have one reject
742 * c) Check that we know the subscriber with the TMSI otherwise reject
743 * with a HLR cause
744 * d) Set the subscriber on the gsm_lchan and accept
745 */
746static int gsm48_rx_mm_serv_req(struct msgb *msg)
747{
748 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200749 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +0800750
Harald Welte75350412009-07-23 18:46:00 +0200751 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800752 struct gsm_subscriber *subscr;
753 struct gsm48_hdr *gh = msgb_l3(msg);
754 struct gsm48_service_request *req =
755 (struct gsm48_service_request *)gh->data;
Holger Hans Peter Freyther05708322010-05-14 08:02:08 +0800756 /* unfortunately in Phase1 the classmark2 length is variable */
Harald Welte59b04682009-06-10 05:40:52 +0800757 u_int8_t classmark2_len = gh->data[1];
758 u_int8_t *classmark2 = gh->data+2;
759 u_int8_t mi_len = *(classmark2 + classmark2_len);
760 u_int8_t *mi = (classmark2 + classmark2_len + 1);
761
762 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
763 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
764 DEBUGPC(DMM, "wrong sized message\n");
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100765 return gsm48_tx_mm_serv_rej(&msg->lchan->conn,
Harald Welte59b04682009-06-10 05:40:52 +0800766 GSM48_REJECT_INCORRECT_MESSAGE);
767 }
768
769 if (msg->data_len < req->mi_len + 6) {
770 DEBUGPC(DMM, "does not fit in packet\n");
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100771 return gsm48_tx_mm_serv_rej(&msg->lchan->conn,
Harald Welte59b04682009-06-10 05:40:52 +0800772 GSM48_REJECT_INCORRECT_MESSAGE);
773 }
774
775 mi_type = mi[0] & GSM_MI_TYPE_MASK;
776 if (mi_type != GSM_MI_TYPE_TMSI) {
777 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100778 return gsm48_tx_mm_serv_rej(&msg->lchan->conn,
Harald Welte59b04682009-06-10 05:40:52 +0800779 GSM48_REJECT_INCORRECT_MESSAGE);
780 }
781
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200782 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Welte59b04682009-06-10 05:40:52 +0800783 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
784 req->cm_service_type, mi_type, mi_string);
785
Harald Welteedf48af2009-12-13 12:39:18 +0100786 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len));
787
Harald Welte583ceaf2009-08-10 10:12:45 +0200788 if (is_siemens_bts(bts))
789 send_siemens_mrpci(msg->lchan, classmark2-1);
790
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200791 subscr = subscr_get_by_tmsi(bts->network,
792 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +0800793
794 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
795 if (!subscr)
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100796 return gsm48_tx_mm_serv_rej(&msg->lchan->conn,
Harald Welte59b04682009-06-10 05:40:52 +0800797 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
798
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100799 if (!msg->lchan->conn.subscr)
800 msg->lchan->conn.subscr = subscr;
801 else if (msg->lchan->conn.subscr == subscr)
Sylvain Munaut7b9852c2009-12-18 18:28:10 +0100802 subscr_put(subscr); /* lchan already has a ref, don't need another one */
803 else {
Harald Welte59b04682009-06-10 05:40:52 +0800804 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
805 subscr_put(subscr);
806 }
807
Harald Weltef6845a72009-07-05 14:08:13 +0200808 subscr->equipment.classmark2_len = classmark2_len;
809 memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
810 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +0800811
Sylvain Munautbadc7112009-12-24 00:28:46 +0100812 return gsm48_secure_channel(msg->lchan, req->cipher_key_seq,
813 _gsm48_rx_mm_serv_req_sec_cb, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800814}
815
816static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
817{
Harald Welte75350412009-07-23 18:46:00 +0200818 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800819 struct gsm48_hdr *gh = msgb_l3(msg);
820 struct gsm48_imsi_detach_ind *idi =
821 (struct gsm48_imsi_detach_ind *) gh->data;
822 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200823 char mi_string[GSM48_MI_SIZE];
Harald Welte03740842009-06-10 23:11:52 +0800824 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800825
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200826 gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
Harald Welte59b04682009-06-10 05:40:52 +0800827 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
828 mi_type, mi_string);
829
Harald Weltebdbb7442009-12-22 19:07:32 +0100830 counter_inc(bts->network->stats.loc_upd_type.detach);
Harald Welte3edc5a92009-12-22 00:41:05 +0100831
Harald Welte59b04682009-06-10 05:40:52 +0800832 switch (mi_type) {
833 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200834 subscr = subscr_get_by_tmsi(bts->network,
835 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +0800836 break;
837 case GSM_MI_TYPE_IMSI:
Harald Welte75350412009-07-23 18:46:00 +0200838 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte59b04682009-06-10 05:40:52 +0800839 break;
840 case GSM_MI_TYPE_IMEI:
841 case GSM_MI_TYPE_IMEISV:
842 /* no sim card... FIXME: what to do ? */
843 DEBUGPC(DMM, "unimplemented mobile identity type\n");
844 break;
845 default:
846 DEBUGPC(DMM, "unknown mobile identity type\n");
847 break;
848 }
849
850 if (subscr) {
851 subscr_update(subscr, msg->trx->bts,
852 GSM_SUBSCRIBER_UPDATE_DETACHED);
Harald Welte0747c6a2009-12-24 14:50:24 +0100853 DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr));
Harald Welte (local)ced09ed2009-08-17 09:39:55 +0200854
855 subscr->equipment.classmark1 = idi->classmark1;
856 db_sync_equipment(&subscr->equipment);
857
Harald Welte59b04682009-06-10 05:40:52 +0800858 subscr_put(subscr);
859 } else
860 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
861
Harald Welte43250dd2009-12-20 09:58:40 +0100862 /* FIXME: iterate over all transactions and release them,
863 * imagine an IMSI DETACH happening during an active call! */
864
Harald Welte9ed54ff2009-12-12 21:00:48 +0100865 /* subscriber is detached: should we release lchan? */
Harald Welte92d88912009-12-21 13:30:17 +0100866 lchan_auto_release(msg->lchan);
Harald Welte9ed54ff2009-12-12 21:00:48 +0100867
Harald Welte59b04682009-06-10 05:40:52 +0800868 return 0;
869}
870
871static int gsm48_rx_mm_status(struct msgb *msg)
872{
873 struct gsm48_hdr *gh = msgb_l3(msg);
874
875 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
876
877 return 0;
878}
879
Sylvain Munaut28c47162009-12-24 00:27:26 +0100880/* Chapter 9.2.3: Authentication Response */
881static int gsm48_rx_mm_auth_resp(struct msgb *msg)
882{
883 struct gsm48_hdr *gh = msgb_l3(msg);
884 struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data;
885 struct gsm_lchan *lchan = msg->lchan;
886 struct gsm_subscriber_connection *conn = &msg->lchan->conn;
887 struct gsm_network *net = lchan->ts->trx->bts->network;
888
889 DEBUGP(DMM, "MM AUTHENTICATION RESPONSE (sres = %s)\n",
890 hexdump(ar->sres, 4));
891
892 /* Safety check */
893 if (!conn->sec_operation) {
894 DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n");
895 return -EIO;
896 }
897
898 /* Validate SRES */
899 if (memcmp(conn->sec_operation->atuple.sres, ar->sres,4)) {
900 gsm_cbfn *cb = conn->sec_operation->cb;
901 if (cb)
902 cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED,
903 NULL, lchan, conn->sec_operation->cb_data);
904
905 release_security_operation(conn);
906 return gsm48_tx_mm_auth_rej(lchan);
907 }
908
909 /* Start ciphering */
910 lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
911 lchan->encr.key_len = 8;
912 memcpy(msg->lchan->encr.key, conn->sec_operation->atuple.kc, 8);
913
914 return gsm48_send_rr_ciph_mode(msg->lchan, 0);
915}
916
Harald Welte59b04682009-06-10 05:40:52 +0800917/* Receive a GSM 04.08 Mobility Management (MM) message */
918static int gsm0408_rcv_mm(struct msgb *msg)
919{
920 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte03740842009-06-10 23:11:52 +0800921 int rc = 0;
Harald Welte59b04682009-06-10 05:40:52 +0800922
923 switch (gh->msg_type & 0xbf) {
924 case GSM48_MT_MM_LOC_UPD_REQUEST:
Harald Welte79639662009-06-27 02:58:43 +0200925 DEBUGP(DMM, "LOCATION UPDATING REQUEST: ");
Harald Welte59b04682009-06-10 05:40:52 +0800926 rc = mm_rx_loc_upd_req(msg);
927 break;
928 case GSM48_MT_MM_ID_RESP:
929 rc = mm_rx_id_resp(msg);
930 break;
931 case GSM48_MT_MM_CM_SERV_REQ:
932 rc = gsm48_rx_mm_serv_req(msg);
933 break;
934 case GSM48_MT_MM_STATUS:
935 rc = gsm48_rx_mm_status(msg);
936 break;
937 case GSM48_MT_MM_TMSI_REALL_COMPL:
938 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100939 msg->lchan->conn.subscr ?
940 subscr_name(msg->lchan->conn.subscr) :
Harald Welte59b04682009-06-10 05:40:52 +0800941 "unknown subscriber");
942 break;
943 case GSM48_MT_MM_IMSI_DETACH_IND:
944 rc = gsm48_rx_mm_imsi_detach_ind(msg);
945 break;
946 case GSM48_MT_MM_CM_REEST_REQ:
947 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
948 break;
949 case GSM48_MT_MM_AUTH_RESP:
Sylvain Munaut28c47162009-12-24 00:27:26 +0100950 rc = gsm48_rx_mm_auth_resp(msg);
Harald Welte59b04682009-06-10 05:40:52 +0800951 break;
952 default:
Harald Welte60e5f4f2009-12-24 12:13:17 +0100953 LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +0800954 gh->msg_type);
955 break;
956 }
957
958 return rc;
959}
960
961/* Receive a PAGING RESPONSE message from the MS */
Holger Hans Peter Freytherf10170e2009-10-23 13:48:54 +0200962static int gsm48_rx_rr_pag_resp(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +0800963{
Harald Welte75350412009-07-23 18:46:00 +0200964 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +0800965 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freythera943b2a2010-05-16 01:51:14 +0800966 struct gsm48_pag_resp *resp;
Harald Welte59b04682009-06-10 05:40:52 +0800967 u_int8_t *classmark2_lv = gh->data + 1;
Holger Hans Peter Freyther1e43b8d2009-08-21 05:18:21 +0200968 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200969 char mi_string[GSM48_MI_SIZE];
Harald Welte03740842009-06-10 23:11:52 +0800970 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +0800971 int rc = 0;
972
Holger Hans Peter Freythera943b2a2010-05-16 01:51:14 +0800973 resp = (struct gsm48_pag_resp *) &gh->data[0];
974 gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
975 mi_string, &mi_type);
Harald Welte59b04682009-06-10 05:40:52 +0800976 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
977 mi_type, mi_string);
Harald Welte583ceaf2009-08-10 10:12:45 +0200978
Harald Welte59b04682009-06-10 05:40:52 +0800979 switch (mi_type) {
980 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200981 subscr = subscr_get_by_tmsi(bts->network,
982 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +0800983 break;
984 case GSM_MI_TYPE_IMSI:
Harald Welte75350412009-07-23 18:46:00 +0200985 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte59b04682009-06-10 05:40:52 +0800986 break;
987 }
988
989 if (!subscr) {
990 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
991 /* FIXME: request id? close channel? */
992 return -EINVAL;
993 }
994 DEBUGP(DRR, "<- Channel was requested by %s\n",
Harald Welte68b7df22009-08-08 16:03:15 +0200995 subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi);
Harald Welte59b04682009-06-10 05:40:52 +0800996
Harald Weltef6845a72009-07-05 14:08:13 +0200997 subscr->equipment.classmark2_len = *classmark2_lv;
998 memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
999 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +08001000
Holger Hans Peter Freyther1e43b8d2009-08-21 05:18:21 +02001001 rc = gsm48_handle_paging_resp(msg, subscr);
Harald Welte59b04682009-06-10 05:40:52 +08001002 return rc;
1003}
1004
1005static int gsm48_rx_rr_classmark(struct msgb *msg)
1006{
1007 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01001008 struct gsm_subscriber *subscr = msg->lchan->conn.subscr;
Harald Welte59b04682009-06-10 05:40:52 +08001009 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1010 u_int8_t cm2_len, cm3_len = 0;
1011 u_int8_t *cm2, *cm3 = NULL;
1012
1013 DEBUGP(DRR, "CLASSMARK CHANGE ");
1014
1015 /* classmark 2 */
1016 cm2_len = gh->data[0];
1017 cm2 = &gh->data[1];
1018 DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
1019
1020 if (payload_len > cm2_len + 1) {
1021 /* we must have a classmark3 */
1022 if (gh->data[cm2_len+1] != 0x20) {
1023 DEBUGPC(DRR, "ERR CM3 TAG\n");
1024 return -EINVAL;
1025 }
1026 if (cm2_len > 3) {
1027 DEBUGPC(DRR, "CM2 too long!\n");
1028 return -EINVAL;
1029 }
1030
1031 cm3_len = gh->data[cm2_len+2];
1032 cm3 = &gh->data[cm2_len+3];
1033 if (cm3_len > 14) {
1034 DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
1035 return -EINVAL;
1036 }
1037 DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
1038 }
1039 if (subscr) {
Harald Weltef6845a72009-07-05 14:08:13 +02001040 subscr->equipment.classmark2_len = cm2_len;
1041 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
Harald Welte59b04682009-06-10 05:40:52 +08001042 if (cm3) {
Harald Weltef6845a72009-07-05 14:08:13 +02001043 subscr->equipment.classmark3_len = cm3_len;
1044 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
Harald Welte59b04682009-06-10 05:40:52 +08001045 }
Harald Weltef6845a72009-07-05 14:08:13 +02001046 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +08001047 }
1048
Harald Welte59b04682009-06-10 05:40:52 +08001049 return 0;
1050}
1051
1052static int gsm48_rx_rr_status(struct msgb *msg)
1053{
1054 struct gsm48_hdr *gh = msgb_l3(msg);
1055
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02001056 DEBUGP(DRR, "STATUS rr_cause = %s\n",
Harald Welte59b04682009-06-10 05:40:52 +08001057 rr_cause_name(gh->data[0]));
1058
1059 return 0;
1060}
1061
1062static int gsm48_rx_rr_meas_rep(struct msgb *msg)
1063{
Harald Weltef9476812009-12-15 21:36:05 +01001064 struct gsm_meas_rep *meas_rep = lchan_next_meas_rep(msg->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001065
Harald Weltec20bd1d2009-11-29 19:07:28 +01001066 /* This shouldn't actually end up here, as RSL treats
1067 * L3 Info of 08.58 MEASUREMENT REPORT different by calling
1068 * directly into gsm48_parse_meas_rep */
1069 DEBUGP(DMEAS, "DIRECT GSM48 MEASUREMENT REPORT ?!? ");
Harald Weltef9476812009-12-15 21:36:05 +01001070 gsm48_parse_meas_rep(meas_rep, msg);
Harald Welte59b04682009-06-10 05:40:52 +08001071
1072 return 0;
1073}
1074
Harald Welte (local)b5103922009-08-15 23:32:44 +02001075static int gsm48_rx_rr_app_info(struct msgb *msg)
1076{
1077 struct gsm48_hdr *gh = msgb_l3(msg);
1078 u_int8_t apdu_id_flags;
1079 u_int8_t apdu_len;
1080 u_int8_t *apdu_data;
1081
1082 apdu_id_flags = gh->data[0];
1083 apdu_len = gh->data[1];
1084 apdu_data = gh->data+2;
1085
1086 DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s",
1087 apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len));
1088
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01001089 return db_apdu_blob_store(msg->lchan->conn.subscr, apdu_id_flags, apdu_len, apdu_data);
Harald Welte (local)b5103922009-08-15 23:32:44 +02001090}
1091
Sylvain Munaut28c47162009-12-24 00:27:26 +01001092/* Chapter 9.1.10 Ciphering Mode Complete */
1093static int gsm48_rx_rr_ciph_m_compl(struct msgb *msg)
1094{
1095 struct gsm_lchan *lchan = msg->lchan;
1096 struct gsm_subscriber_connection *conn = &lchan->conn;
1097 gsm_cbfn *cb;
1098 int rc = 0;
1099
1100 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
1101
1102 /* Safety check */
1103 if (!conn->sec_operation) {
1104 DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n");
1105 return -EIO;
1106 }
1107
1108 /* FIXME: check for MI (if any) */
1109
1110 /* Call back whatever was in progress (if anything) ... */
1111 cb = conn->sec_operation->cb;
1112 if (cb) {
1113 rc = cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED,
1114 NULL, lchan, conn->sec_operation->cb_data);
1115 }
1116
1117 /* Complete the operation */
1118 release_security_operation(conn);
1119
1120 return rc;
1121}
1122
Harald Welte6720a432009-11-29 22:45:52 +01001123/* Chapter 9.1.16 Handover complete */
Harald Weltec6b3c8c2009-12-14 17:51:15 +01001124static int gsm48_rx_rr_ho_compl(struct msgb *msg)
Harald Welte6720a432009-11-29 22:45:52 +01001125{
1126 struct gsm48_hdr *gh = msgb_l3(msg);
1127
1128 DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n",
1129 rr_cause_name(gh->data[0]));
1130
1131 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, msg->lchan);
1132 /* FIXME: release old channel */
1133
1134 return 0;
1135}
1136
1137/* Chapter 9.1.17 Handover Failure */
Harald Weltec6b3c8c2009-12-14 17:51:15 +01001138static int gsm48_rx_rr_ho_fail(struct msgb *msg)
Harald Welte6720a432009-11-29 22:45:52 +01001139{
1140 struct gsm48_hdr *gh = msgb_l3(msg);
1141
1142 DEBUGP(DRR, "HANDOVER FAILED cause = %s\n",
1143 rr_cause_name(gh->data[0]));
1144
1145 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, msg->lchan);
1146 /* FIXME: release allocated new channel */
1147
1148 return 0;
1149}
Harald Welte (local)b5103922009-08-15 23:32:44 +02001150
Harald Welte59b04682009-06-10 05:40:52 +08001151/* Receive a GSM 04.08 Radio Resource (RR) message */
1152static int gsm0408_rcv_rr(struct msgb *msg)
1153{
1154 struct gsm48_hdr *gh = msgb_l3(msg);
1155 int rc = 0;
1156
1157 switch (gh->msg_type) {
1158 case GSM48_MT_RR_CLSM_CHG:
1159 rc = gsm48_rx_rr_classmark(msg);
1160 break;
1161 case GSM48_MT_RR_GPRS_SUSP_REQ:
1162 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1163 break;
1164 case GSM48_MT_RR_PAG_RESP:
Holger Hans Peter Freytherf10170e2009-10-23 13:48:54 +02001165 rc = gsm48_rx_rr_pag_resp(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001166 break;
1167 case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
Holger Hans Peter Freyther9e6d6ce2009-10-22 15:23:11 +02001168 rc = gsm48_rx_rr_modif_ack(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001169 break;
1170 case GSM48_MT_RR_STATUS:
1171 rc = gsm48_rx_rr_status(msg);
1172 break;
1173 case GSM48_MT_RR_MEAS_REP:
1174 rc = gsm48_rx_rr_meas_rep(msg);
1175 break;
Harald Welte (local)b5103922009-08-15 23:32:44 +02001176 case GSM48_MT_RR_APP_INFO:
1177 rc = gsm48_rx_rr_app_info(msg);
1178 break;
Harald Welted2dd9de2009-08-30 15:37:11 +09001179 case GSM48_MT_RR_CIPH_M_COMPL:
Sylvain Munaut28c47162009-12-24 00:27:26 +01001180 rc = gsm48_rx_rr_ciph_m_compl(msg);
Harald Welted2dd9de2009-08-30 15:37:11 +09001181 break;
Harald Welte323f4e02009-11-29 20:02:20 +01001182 case GSM48_MT_RR_HANDO_COMPL:
Harald Welte6720a432009-11-29 22:45:52 +01001183 rc = gsm48_rx_rr_ho_compl(msg);
Harald Welte323f4e02009-11-29 20:02:20 +01001184 break;
1185 case GSM48_MT_RR_HANDO_FAIL:
Harald Welte6720a432009-11-29 22:45:52 +01001186 rc = gsm48_rx_rr_ho_fail(msg);
Harald Welte323f4e02009-11-29 20:02:20 +01001187 break;
Harald Welte59b04682009-06-10 05:40:52 +08001188 default:
Harald Welte60e5f4f2009-12-24 12:13:17 +01001189 LOGP(DRR, LOGL_NOTICE, "Unimplemented "
1190 "GSM 04.08 RR msg type 0x%02x\n", gh->msg_type);
Harald Welte59b04682009-06-10 05:40:52 +08001191 break;
1192 }
1193
1194 return rc;
1195}
1196
Harald Welte (local)b5103922009-08-15 23:32:44 +02001197int gsm48_send_rr_app_info(struct gsm_lchan *lchan, u_int8_t apdu_id,
Holger Hans Peter Freytherd70da872009-10-22 15:42:19 +02001198 u_int8_t apdu_len, const u_int8_t *apdu)
Harald Welte (local)b5103922009-08-15 23:32:44 +02001199{
1200 struct msgb *msg = gsm48_msgb_alloc();
1201 struct gsm48_hdr *gh;
1202
1203 msg->lchan = lchan;
1204
1205 DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n",
1206 apdu_id, apdu_len);
1207
1208 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len);
1209 gh->proto_discr = GSM48_PDISC_RR;
1210 gh->msg_type = GSM48_MT_RR_APP_INFO;
1211 gh->data[0] = apdu_id;
1212 gh->data[1] = apdu_len;
1213 memcpy(gh->data+2, apdu, apdu_len);
1214
1215 return gsm48_sendmsg(msg, NULL);
1216}
1217
Harald Welte59b04682009-06-10 05:40:52 +08001218/* Call Control */
1219
1220/* The entire call control code is written in accordance with Figure 7.10c
1221 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1222 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1223 * it for voice */
1224
Harald Welte03740842009-06-10 23:11:52 +08001225static void new_cc_state(struct gsm_trans *trans, int state)
1226{
1227 if (state > 31 || state < 0)
1228 return;
1229
1230 DEBUGP(DCC, "new state %s -> %s\n",
Harald Welteb30935e2010-03-25 12:13:02 +08001231 gsm48_cc_state_name(trans->cc.state),
1232 gsm48_cc_state_name(state));
Harald Welte03740842009-06-10 23:11:52 +08001233
Harald Weltec2189a62009-07-23 18:56:43 +02001234 trans->cc.state = state;
Harald Welte03740842009-06-10 23:11:52 +08001235}
1236
1237static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
Harald Welte59b04682009-06-10 05:40:52 +08001238{
1239 struct msgb *msg = gsm48_msgb_alloc();
1240 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1241 u_int8_t *cause, *call_state;
1242
Harald Welte59b04682009-06-10 05:40:52 +08001243 gh->msg_type = GSM48_MT_CC_STATUS;
1244
1245 cause = msgb_put(msg, 3);
1246 cause[0] = 2;
1247 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1248 cause[2] = 0x80 | 30; /* response to status inquiry */
1249
1250 call_state = msgb_put(msg, 1);
1251 call_state[0] = 0xc0 | 0x00;
1252
Harald Welte36fe2e82009-07-23 21:13:03 +02001253 return gsm48_sendmsg(msg, trans);
Harald Welte59b04682009-06-10 05:40:52 +08001254}
1255
1256static int gsm48_tx_simple(struct gsm_lchan *lchan,
1257 u_int8_t pdisc, u_int8_t msg_type)
1258{
1259 struct msgb *msg = gsm48_msgb_alloc();
1260 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1261
1262 msg->lchan = lchan;
1263
1264 gh->proto_discr = pdisc;
1265 gh->msg_type = msg_type;
1266
Harald Welte36fe2e82009-07-23 21:13:03 +02001267 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +08001268}
1269
Harald Welte03740842009-06-10 23:11:52 +08001270static void gsm48_stop_cc_timer(struct gsm_trans *trans)
1271{
Harald Weltec2189a62009-07-23 18:56:43 +02001272 if (bsc_timer_pending(&trans->cc.timer)) {
1273 DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent);
1274 bsc_del_timer(&trans->cc.timer);
1275 trans->cc.Tcurrent = 0;
Harald Welte03740842009-06-10 23:11:52 +08001276 }
1277}
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02001278
Harald Welte03740842009-06-10 23:11:52 +08001279static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
1280 int msg_type, struct gsm_mncc *mncc)
1281{
1282 struct msgb *msg;
1283
1284 if (trans)
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001285 if (trans->conn)
Harald Welte4861c822009-07-23 21:21:14 +02001286 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte03740842009-06-10 23:11:52 +08001287 "Sending '%s' to MNCC.\n",
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001288 trans->conn->lchan->ts->trx->bts->nr,
1289 trans->conn->lchan->ts->trx->nr,
1290 trans->conn->lchan->ts->nr, trans->transaction_id,
Harald Welte03740842009-06-10 23:11:52 +08001291 (trans->subscr)?(trans->subscr->extension):"-",
1292 get_mncc_name(msg_type));
1293 else
1294 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
1295 "Sending '%s' to MNCC.\n",
1296 (trans->subscr)?(trans->subscr->extension):"-",
1297 get_mncc_name(msg_type));
1298 else
1299 DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) "
1300 "Sending '%s' to MNCC.\n", get_mncc_name(msg_type));
1301
1302 mncc->msg_type = msg_type;
1303
Harald Welte9cfc9352009-06-26 19:39:35 +02001304 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
Harald Welte03740842009-06-10 23:11:52 +08001305 if (!msg)
1306 return -ENOMEM;
1307 memcpy(msg->data, mncc, sizeof(struct gsm_mncc));
1308 msgb_enqueue(&net->upqueue, msg);
1309
1310 return 0;
1311}
1312
1313int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
1314 u_int32_t callref, int location, int value)
1315{
1316 struct gsm_mncc rel;
1317
Harald Weltecb0595f2009-06-12 01:54:08 +08001318 memset(&rel, 0, sizeof(rel));
Harald Welte03740842009-06-10 23:11:52 +08001319 rel.callref = callref;
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001320 mncc_set_cause(&rel, location, value);
Harald Welte03740842009-06-10 23:11:52 +08001321 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1322}
1323
Harald Weltec2189a62009-07-23 18:56:43 +02001324/* Call Control Specific transaction release.
1325 * gets called by trans_free, DO NOT CALL YOURSELF! */
1326void _gsm48_cc_trans_free(struct gsm_trans *trans)
Harald Welte03740842009-06-10 23:11:52 +08001327{
Harald Welte03740842009-06-10 23:11:52 +08001328 gsm48_stop_cc_timer(trans);
1329
1330 /* send release to L4, if callref still exists */
1331 if (trans->callref) {
1332 /* Ressource unavailable */
Harald Welte0abe5a62009-07-23 19:06:52 +02001333 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001334 GSM48_CAUSE_LOC_PRN_S_LU,
1335 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08001336 }
Harald Weltec2189a62009-07-23 18:56:43 +02001337 if (trans->cc.state != GSM_CSTATE_NULL)
Harald Welte03740842009-06-10 23:11:52 +08001338 new_cc_state(trans, GSM_CSTATE_NULL);
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001339 if (trans->conn)
1340 trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref);
Harald Welte03740842009-06-10 23:11:52 +08001341}
1342
1343static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02001344
Harald Welte59b04682009-06-10 05:40:52 +08001345/* call-back from paging the B-end of the connection */
1346static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
1347 struct msgb *msg, void *_lchan, void *param)
1348{
1349 struct gsm_lchan *lchan = _lchan;
Harald Welte03740842009-06-10 23:11:52 +08001350 struct gsm_subscriber *subscr = param;
1351 struct gsm_trans *transt, *tmp;
1352 struct gsm_network *net;
Harald Welte1ff81b52009-06-26 20:17:06 +02001353
Harald Welte59b04682009-06-10 05:40:52 +08001354 if (hooknum != GSM_HOOK_RR_PAGING)
1355 return -EINVAL;
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02001356
Harald Welte03740842009-06-10 23:11:52 +08001357 if (!subscr)
1358 return -EINVAL;
1359 net = subscr->net;
1360 if (!net) {
1361 DEBUGP(DCC, "Error Network not set!\n");
1362 return -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08001363 }
1364
Harald Welte03740842009-06-10 23:11:52 +08001365 /* check all tranactions (without lchan) for subscriber */
1366 llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) {
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001367 if (transt->subscr != subscr || transt->conn)
Harald Welte03740842009-06-10 23:11:52 +08001368 continue;
1369 switch (event) {
1370 case GSM_PAGING_SUCCEEDED:
1371 if (!lchan) // paranoid
1372 break;
1373 DEBUGP(DCC, "Paging subscr %s succeeded!\n",
1374 subscr->extension);
1375 /* Assign lchan */
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001376 if (!transt->conn) {
1377 transt->conn = &lchan->conn;
1378 use_subscr_con(transt->conn);
Harald Welte03740842009-06-10 23:11:52 +08001379 }
1380 /* send SETUP request to called party */
Harald Weltec2189a62009-07-23 18:56:43 +02001381 gsm48_cc_tx_setup(transt, &transt->cc.msg);
Harald Welte03740842009-06-10 23:11:52 +08001382 break;
1383 case GSM_PAGING_EXPIRED:
1384 DEBUGP(DCC, "Paging subscr %s expired!\n",
1385 subscr->extension);
1386 /* Temporarily out of order */
Harald Welte0abe5a62009-07-23 19:06:52 +02001387 mncc_release_ind(transt->subscr->net, transt,
1388 transt->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001389 GSM48_CAUSE_LOC_PRN_S_LU,
1390 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte03740842009-06-10 23:11:52 +08001391 transt->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02001392 trans_free(transt);
Harald Welte03740842009-06-10 23:11:52 +08001393 break;
1394 }
1395 }
Harald Welte59b04682009-06-10 05:40:52 +08001396 return 0;
1397}
1398
Harald Welte3971ad52009-12-19 22:23:05 +01001399static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable);
1400
Harald Welte3c062072009-07-28 18:25:29 +02001401/* some other part of the code sends us a signal */
1402static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
1403 void *handler_data, void *signal_data)
1404{
1405 struct gsm_lchan *lchan = signal_data;
Harald Welte3c062072009-07-28 18:25:29 +02001406 int rc;
Harald Welte3971ad52009-12-19 22:23:05 +01001407 struct gsm_network *net;
1408 struct gsm_trans *trans;
Harald Welte3c062072009-07-28 18:25:29 +02001409
1410 if (subsys != SS_ABISIP)
1411 return 0;
1412
1413 /* in case we use direct BTS-to-BTS RTP */
1414 if (ipacc_rtp_direct)
1415 return 0;
1416
Harald Welte3c062072009-07-28 18:25:29 +02001417 switch (signal) {
Holger Hans Peter Freyther5ea7ea62009-11-18 21:06:12 +01001418 case S_ABISIP_CRCX_ACK:
Harald Welte3971ad52009-12-19 22:23:05 +01001419 /* check if any transactions on this lchan still have
1420 * a tch_recv_mncc request pending */
1421 net = lchan->ts->trx->bts->network;
1422 llist_for_each_entry(trans, &net->trans_list, entry) {
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001423 if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) {
Harald Welte3971ad52009-12-19 22:23:05 +01001424 DEBUGP(DCC, "pending tch_recv_mncc request\n");
1425 tch_recv_mncc(net, trans->callref, 1);
1426 }
1427 }
Harald Welte3c062072009-07-28 18:25:29 +02001428 break;
Harald Welte3c062072009-07-28 18:25:29 +02001429 }
1430
1431 return 0;
Harald Welte3c062072009-07-28 18:25:29 +02001432}
1433
Harald Welte59b04682009-06-10 05:40:52 +08001434/* map two ipaccess RTP streams onto each other */
1435static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
1436{
1437 struct gsm_bts *bts = lchan->ts->trx->bts;
1438 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
Harald Welte3c062072009-07-28 18:25:29 +02001439 int rc;
Harald Welte59b04682009-06-10 05:40:52 +08001440
1441 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1442 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1443 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1444
1445 if (bts->type != remote_bts->type) {
1446 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1447 return -EINVAL;
1448 }
Harald Welte3971ad52009-12-19 22:23:05 +01001449
1450 // todo: map between different bts types
Harald Welte59b04682009-06-10 05:40:52 +08001451 switch (bts->type) {
Mike Haben66e0ba02009-10-02 12:19:34 +01001452 case GSM_BTS_TYPE_NANOBTS:
Harald Welte3c062072009-07-28 18:25:29 +02001453 if (!ipacc_rtp_direct) {
1454 /* connect the TCH's to our RTP proxy */
Harald Welte9947d9f2009-12-20 16:51:09 +01001455 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welte3c062072009-07-28 18:25:29 +02001456 if (rc < 0)
1457 return rc;
Harald Welte9947d9f2009-12-20 16:51:09 +01001458 rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan);
Harald Welte3971ad52009-12-19 22:23:05 +01001459#warning do we need a check of rc here?
Harald Welte3c062072009-07-28 18:25:29 +02001460
1461 /* connect them with each other */
Harald Welte87504212009-12-02 01:56:49 +05301462 rtp_socket_proxy(lchan->abis_ip.rtp_socket,
1463 remote_lchan->abis_ip.rtp_socket);
Harald Welte3c062072009-07-28 18:25:29 +02001464 } else {
1465 /* directly connect TCH RTP streams to each other */
Harald Welte87504212009-12-02 01:56:49 +05301466 rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip,
1467 remote_lchan->abis_ip.bound_port,
Harald Welte87504212009-12-02 01:56:49 +05301468 remote_lchan->abis_ip.rtp_payload2);
Harald Welte3c062072009-07-28 18:25:29 +02001469 if (rc < 0)
1470 return rc;
Harald Welte87504212009-12-02 01:56:49 +05301471 rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip,
1472 lchan->abis_ip.bound_port,
Harald Welte87504212009-12-02 01:56:49 +05301473 lchan->abis_ip.rtp_payload2);
Harald Welte3c062072009-07-28 18:25:29 +02001474 }
Harald Welte59b04682009-06-10 05:40:52 +08001475 break;
1476 case GSM_BTS_TYPE_BS11:
1477 trau_mux_map_lchan(lchan, remote_lchan);
1478 break;
1479 default:
1480 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
Harald Welte3971ad52009-12-19 22:23:05 +01001481 return -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08001482 }
1483
1484 return 0;
1485}
1486
Harald Welte03740842009-06-10 23:11:52 +08001487/* bridge channels of two transactions */
1488static int tch_bridge(struct gsm_network *net, u_int32_t *refs)
Harald Welte59b04682009-06-10 05:40:52 +08001489{
Harald Weltec2189a62009-07-23 18:56:43 +02001490 struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]);
1491 struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]);
Harald Welte59b04682009-06-10 05:40:52 +08001492
Harald Welte03740842009-06-10 23:11:52 +08001493 if (!trans1 || !trans2)
Harald Welte59b04682009-06-10 05:40:52 +08001494 return -EIO;
1495
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001496 if (!trans1->conn || !trans2->conn)
Harald Welte03740842009-06-10 23:11:52 +08001497 return -EIO;
1498
1499 /* through-connect channel */
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001500 return tch_map(trans1->conn->lchan, trans2->conn->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001501}
1502
Harald Welte3971ad52009-12-19 22:23:05 +01001503/* enable receive of channels to MNCC upqueue */
1504static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable)
Harald Welte03740842009-06-10 23:11:52 +08001505{
1506 struct gsm_trans *trans;
Harald Welte3971ad52009-12-19 22:23:05 +01001507 struct gsm_lchan *lchan;
1508 struct gsm_bts *bts;
1509 int rc;
Harald Welte59b04682009-06-10 05:40:52 +08001510
Harald Welte03740842009-06-10 23:11:52 +08001511 /* Find callref */
Harald Welte3971ad52009-12-19 22:23:05 +01001512 trans = trans_find_by_callref(net, callref);
Harald Welte03740842009-06-10 23:11:52 +08001513 if (!trans)
1514 return -EIO;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001515 if (!trans->conn)
Harald Welte03740842009-06-10 23:11:52 +08001516 return 0;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01001517 lchan = trans->conn->lchan;
Harald Welte3971ad52009-12-19 22:23:05 +01001518 bts = lchan->ts->trx->bts;
Harald Welte03740842009-06-10 23:11:52 +08001519
Harald Welte3971ad52009-12-19 22:23:05 +01001520 switch (bts->type) {
1521 case GSM_BTS_TYPE_NANOBTS:
1522 if (ipacc_rtp_direct) {
1523 DEBUGP(DCC, "Error: RTP proxy is disabled\n");
1524 return -EINVAL;
1525 }
1526 /* in case, we don't have a RTP socket yet, we note this
1527 * in the transaction and try later */
1528 if (!lchan->abis_ip.rtp_socket) {
1529 trans->tch_recv = enable;
1530 DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable);
1531 return 0;
1532 }
1533 if (enable) {
1534 /* connect the TCH's to our RTP proxy */
Harald Welte9947d9f2009-12-20 16:51:09 +01001535 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welte3971ad52009-12-19 22:23:05 +01001536 if (rc < 0)
1537 return rc;
1538 /* assign socket to application interface */
1539 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1540 net, callref);
1541 } else
1542 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1543 net, 0);
1544 break;
1545 case GSM_BTS_TYPE_BS11:
1546 if (enable)
1547 return trau_recv_lchan(lchan, callref);
1548 return trau_mux_unmap(NULL, callref);
1549 break;
1550 default:
1551 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
1552 return -EINVAL;
1553 }
1554
1555 return 0;
Harald Welte03740842009-06-10 23:11:52 +08001556}
1557
Harald Welte03740842009-06-10 23:11:52 +08001558static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
1559{
1560 DEBUGP(DCC, "-> STATUS ENQ\n");
1561 return gsm48_cc_tx_status(trans, msg);
1562}
1563
1564static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
1565static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
1566
1567static void gsm48_cc_timeout(void *arg)
1568{
1569 struct gsm_trans *trans = arg;
1570 int disconnect = 0, release = 0;
Harald Weltebbc636a2009-06-11 14:23:20 +08001571 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
1572 int mo_location = GSM48_CAUSE_LOC_USER;
1573 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
1574 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
Harald Welte03740842009-06-10 23:11:52 +08001575 struct gsm_mncc mo_rel, l4_rel;
1576
1577 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
1578 mo_rel.callref = trans->callref;
1579 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
1580 l4_rel.callref = trans->callref;
1581
Harald Weltec2189a62009-07-23 18:56:43 +02001582 switch(trans->cc.Tcurrent) {
Harald Welte03740842009-06-10 23:11:52 +08001583 case 0x303:
1584 release = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08001585 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08001586 break;
1587 case 0x310:
1588 disconnect = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08001589 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08001590 break;
1591 case 0x313:
1592 disconnect = 1;
1593 /* unknown, did not find it in the specs */
1594 break;
1595 case 0x301:
1596 disconnect = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08001597 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08001598 break;
1599 case 0x308:
Harald Weltec2189a62009-07-23 18:56:43 +02001600 if (!trans->cc.T308_second) {
Harald Welte03740842009-06-10 23:11:52 +08001601 /* restart T308 a second time */
Harald Weltec2189a62009-07-23 18:56:43 +02001602 gsm48_cc_tx_release(trans, &trans->cc.msg);
1603 trans->cc.T308_second = 1;
Harald Welte03740842009-06-10 23:11:52 +08001604 break; /* stay in release state */
1605 }
Harald Weltec2189a62009-07-23 18:56:43 +02001606 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08001607 return;
1608// release = 1;
1609// l4_cause = 14;
1610// break;
1611 case 0x306:
1612 release = 1;
Harald Weltec2189a62009-07-23 18:56:43 +02001613 mo_cause = trans->cc.msg.cause.value;
1614 mo_location = trans->cc.msg.cause.location;
Harald Welte03740842009-06-10 23:11:52 +08001615 break;
1616 case 0x323:
1617 disconnect = 1;
1618 break;
1619 default:
1620 release = 1;
1621 }
1622
1623 if (release && trans->callref) {
1624 /* process release towards layer 4 */
Harald Welte0abe5a62009-07-23 19:06:52 +02001625 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Harald Welte03740842009-06-10 23:11:52 +08001626 l4_location, l4_cause);
1627 trans->callref = 0;
1628 }
1629
1630 if (disconnect && trans->callref) {
1631 /* process disconnect towards layer 4 */
1632 mncc_set_cause(&l4_rel, l4_location, l4_cause);
Harald Welte0abe5a62009-07-23 19:06:52 +02001633 mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel);
Harald Welte03740842009-06-10 23:11:52 +08001634 }
1635
1636 /* process disconnect towards mobile station */
1637 if (disconnect || release) {
1638 mncc_set_cause(&mo_rel, mo_location, mo_cause);
Harald Weltec2189a62009-07-23 18:56:43 +02001639 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
1640 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
1641 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
Harald Welte03740842009-06-10 23:11:52 +08001642 mo_rel.cause.diag_len = 3;
1643
1644 if (disconnect)
1645 gsm48_cc_tx_disconnect(trans, &mo_rel);
1646 if (release)
1647 gsm48_cc_tx_release(trans, &mo_rel);
1648 }
1649
1650}
1651
1652static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
1653 int sec, int micro)
1654{
1655 DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec);
Harald Weltec2189a62009-07-23 18:56:43 +02001656 trans->cc.timer.cb = gsm48_cc_timeout;
1657 trans->cc.timer.data = trans;
1658 bsc_schedule_timer(&trans->cc.timer, sec, micro);
1659 trans->cc.Tcurrent = current;
Harald Welte03740842009-06-10 23:11:52 +08001660}
1661
1662static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
1663{
1664 struct gsm48_hdr *gh = msgb_l3(msg);
1665 u_int8_t msg_type = gh->msg_type & 0xbf;
1666 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1667 struct tlv_parsed tp;
1668 struct gsm_mncc setup;
1669
1670 memset(&setup, 0, sizeof(struct gsm_mncc));
1671 setup.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01001672 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08001673 /* emergency setup is identified by msg_type */
1674 if (msg_type == GSM48_MT_CC_EMERG_SETUP)
1675 setup.emergency = 1;
1676
1677 /* use subscriber as calling party number */
1678 if (trans->subscr) {
1679 setup.fields |= MNCC_F_CALLING;
1680 strncpy(setup.calling.number, trans->subscr->extension,
1681 sizeof(setup.calling.number)-1);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02001682 strncpy(setup.imsi, trans->subscr->imsi,
1683 sizeof(setup.imsi)-1);
Harald Welte03740842009-06-10 23:11:52 +08001684 }
1685 /* bearer capability */
1686 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1687 setup.fields |= MNCC_F_BEARER_CAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01001688 gsm48_decode_bearer_cap(&setup.bearer_cap,
Harald Welte03740842009-06-10 23:11:52 +08001689 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1690 }
1691 /* facility */
1692 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1693 setup.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01001694 gsm48_decode_facility(&setup.facility,
Harald Welte03740842009-06-10 23:11:52 +08001695 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1696 }
1697 /* called party bcd number */
1698 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
1699 setup.fields |= MNCC_F_CALLED;
Harald Weltefdc93d92010-03-07 23:40:35 +01001700 gsm48_decode_called(&setup.called,
Harald Welte03740842009-06-10 23:11:52 +08001701 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
1702 }
1703 /* user-user */
1704 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1705 setup.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01001706 gsm48_decode_useruser(&setup.useruser,
Harald Welte03740842009-06-10 23:11:52 +08001707 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1708 }
1709 /* ss-version */
1710 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1711 setup.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01001712 gsm48_decode_ssversion(&setup.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08001713 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1714 }
1715 /* CLIR suppression */
1716 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
1717 setup.clir.sup = 1;
1718 /* CLIR invocation */
1719 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
1720 setup.clir.inv = 1;
1721 /* cc cap */
1722 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1723 setup.fields |= MNCC_F_CCCAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01001724 gsm48_decode_cccap(&setup.cccap,
Harald Welte03740842009-06-10 23:11:52 +08001725 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1726 }
1727
Harald Welte03740842009-06-10 23:11:52 +08001728 new_cc_state(trans, GSM_CSTATE_INITIATED);
1729
Harald Welte (local)5b722d42009-12-26 19:45:03 +01001730 LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n",
1731 subscr_name(trans->subscr), trans->subscr->extension,
1732 setup.called.number);
1733
Harald Welte03740842009-06-10 23:11:52 +08001734 /* indicate setup to MNCC */
Harald Welte0abe5a62009-07-23 19:06:52 +02001735 mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup);
Harald Welte03740842009-06-10 23:11:52 +08001736
Harald Welteca745e22009-07-29 12:10:35 +02001737 /* MNCC code will modify the channel asynchronously, we should
1738 * ipaccess-bind only after the modification has been made to the
1739 * lchan->tch_mode */
Harald Welte03740842009-06-10 23:11:52 +08001740 return 0;
1741}
1742
1743static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
Harald Welte59b04682009-06-10 05:40:52 +08001744{
1745 struct msgb *msg = gsm48_msgb_alloc();
1746 struct gsm48_hdr *gh;
Harald Welte03740842009-06-10 23:11:52 +08001747 struct gsm_mncc *setup = arg;
Harald Welte165fc332009-07-23 21:36:44 +02001748 int rc, trans_id;
Harald Welte59b04682009-06-10 05:40:52 +08001749
1750 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1751
Harald Welte03740842009-06-10 23:11:52 +08001752 /* transaction id must not be assigned */
1753 if (trans->transaction_id != 0xff) { /* unasssigned */
1754 DEBUGP(DCC, "TX Setup with assigned transaction. "
1755 "This is not allowed!\n");
1756 /* Temporarily out of order */
Harald Welte0abe5a62009-07-23 19:06:52 +02001757 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001758 GSM48_CAUSE_LOC_PRN_S_LU,
1759 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08001760 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02001761 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08001762 return rc;
1763 }
1764
1765 /* Get free transaction_id */
Harald Welte165fc332009-07-23 21:36:44 +02001766 trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0);
1767 if (trans_id < 0) {
Harald Welte03740842009-06-10 23:11:52 +08001768 /* no free transaction ID */
Harald Welte0abe5a62009-07-23 19:06:52 +02001769 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001770 GSM48_CAUSE_LOC_PRN_S_LU,
1771 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08001772 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02001773 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08001774 return rc;
1775 }
Harald Welte165fc332009-07-23 21:36:44 +02001776 trans->transaction_id = trans_id;
Harald Welte59b04682009-06-10 05:40:52 +08001777
Harald Welte59b04682009-06-10 05:40:52 +08001778 gh->msg_type = GSM48_MT_CC_SETUP;
1779
Harald Welte03740842009-06-10 23:11:52 +08001780 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
Harald Welte59b04682009-06-10 05:40:52 +08001781
Harald Welte03740842009-06-10 23:11:52 +08001782 /* bearer capability */
1783 if (setup->fields & MNCC_F_BEARER_CAP)
Harald Weltefdc93d92010-03-07 23:40:35 +01001784 gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap);
Harald Welte03740842009-06-10 23:11:52 +08001785 /* facility */
1786 if (setup->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01001787 gsm48_encode_facility(msg, 0, &setup->facility);
Harald Welte03740842009-06-10 23:11:52 +08001788 /* progress */
1789 if (setup->fields & MNCC_F_PROGRESS)
Harald Weltefdc93d92010-03-07 23:40:35 +01001790 gsm48_encode_progress(msg, 0, &setup->progress);
Harald Welte03740842009-06-10 23:11:52 +08001791 /* calling party BCD number */
1792 if (setup->fields & MNCC_F_CALLING)
Harald Weltefdc93d92010-03-07 23:40:35 +01001793 gsm48_encode_calling(msg, &setup->calling);
Harald Welte03740842009-06-10 23:11:52 +08001794 /* called party BCD number */
1795 if (setup->fields & MNCC_F_CALLED)
Harald Weltefdc93d92010-03-07 23:40:35 +01001796 gsm48_encode_called(msg, &setup->called);
Harald Welte03740842009-06-10 23:11:52 +08001797 /* user-user */
1798 if (setup->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01001799 gsm48_encode_useruser(msg, 0, &setup->useruser);
Harald Welte03740842009-06-10 23:11:52 +08001800 /* redirecting party BCD number */
1801 if (setup->fields & MNCC_F_REDIRECTING)
Harald Weltefdc93d92010-03-07 23:40:35 +01001802 gsm48_encode_redirecting(msg, &setup->redirecting);
Harald Welte03740842009-06-10 23:11:52 +08001803 /* signal */
1804 if (setup->fields & MNCC_F_SIGNAL)
Harald Weltefdc93d92010-03-07 23:40:35 +01001805 gsm48_encode_signal(msg, setup->signal);
Harald Welte03740842009-06-10 23:11:52 +08001806
1807 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
Harald Welte59b04682009-06-10 05:40:52 +08001808
Harald Welte36fe2e82009-07-23 21:13:03 +02001809 return gsm48_sendmsg(msg, trans);
Harald Welte59b04682009-06-10 05:40:52 +08001810}
1811
Harald Welte03740842009-06-10 23:11:52 +08001812static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
1813{
1814 struct gsm48_hdr *gh = msgb_l3(msg);
1815 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1816 struct tlv_parsed tp;
1817 struct gsm_mncc call_conf;
1818
1819 gsm48_stop_cc_timer(trans);
1820 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
1821
1822 memset(&call_conf, 0, sizeof(struct gsm_mncc));
1823 call_conf.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01001824 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08001825#if 0
1826 /* repeat */
1827 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
1828 call_conf.repeat = 1;
1829 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
1830 call_conf.repeat = 2;
1831#endif
1832 /* bearer capability */
1833 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1834 call_conf.fields |= MNCC_F_BEARER_CAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01001835 gsm48_decode_bearer_cap(&call_conf.bearer_cap,
Harald Welte03740842009-06-10 23:11:52 +08001836 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1837 }
1838 /* cause */
1839 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1840 call_conf.fields |= MNCC_F_CAUSE;
Harald Weltefdc93d92010-03-07 23:40:35 +01001841 gsm48_decode_cause(&call_conf.cause,
Harald Welte03740842009-06-10 23:11:52 +08001842 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1843 }
1844 /* cc cap */
1845 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1846 call_conf.fields |= MNCC_F_CCCAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01001847 gsm48_decode_cccap(&call_conf.cccap,
Harald Welte03740842009-06-10 23:11:52 +08001848 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1849 }
1850
1851 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
1852
Harald Welte0abe5a62009-07-23 19:06:52 +02001853 return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND,
1854 &call_conf);
Harald Welte03740842009-06-10 23:11:52 +08001855}
1856
1857static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg)
1858{
1859 struct gsm_mncc *proceeding = arg;
1860 struct msgb *msg = gsm48_msgb_alloc();
1861 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1862
Harald Welte03740842009-06-10 23:11:52 +08001863 gh->msg_type = GSM48_MT_CC_CALL_PROC;
1864
1865 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
1866
1867 /* bearer capability */
1868 if (proceeding->fields & MNCC_F_BEARER_CAP)
Harald Weltefdc93d92010-03-07 23:40:35 +01001869 gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
Harald Welte03740842009-06-10 23:11:52 +08001870 /* facility */
1871 if (proceeding->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01001872 gsm48_encode_facility(msg, 0, &proceeding->facility);
Harald Welte03740842009-06-10 23:11:52 +08001873 /* progress */
1874 if (proceeding->fields & MNCC_F_PROGRESS)
Harald Weltefdc93d92010-03-07 23:40:35 +01001875 gsm48_encode_progress(msg, 0, &proceeding->progress);
Harald Welte03740842009-06-10 23:11:52 +08001876
Harald Welte36fe2e82009-07-23 21:13:03 +02001877 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08001878}
1879
1880static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
1881{
1882 struct gsm48_hdr *gh = msgb_l3(msg);
1883 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1884 struct tlv_parsed tp;
1885 struct gsm_mncc alerting;
1886
1887 gsm48_stop_cc_timer(trans);
1888 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
1889
1890 memset(&alerting, 0, sizeof(struct gsm_mncc));
1891 alerting.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01001892 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08001893 /* facility */
1894 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1895 alerting.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01001896 gsm48_decode_facility(&alerting.facility,
Harald Welte03740842009-06-10 23:11:52 +08001897 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1898 }
1899
1900 /* progress */
1901 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
1902 alerting.fields |= MNCC_F_PROGRESS;
Harald Weltefdc93d92010-03-07 23:40:35 +01001903 gsm48_decode_progress(&alerting.progress,
Harald Welte03740842009-06-10 23:11:52 +08001904 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
1905 }
1906 /* ss-version */
1907 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1908 alerting.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01001909 gsm48_decode_ssversion(&alerting.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08001910 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1911 }
1912
1913 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
1914
Harald Welte0abe5a62009-07-23 19:06:52 +02001915 return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND,
1916 &alerting);
Harald Welte03740842009-06-10 23:11:52 +08001917}
1918
1919static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
1920{
1921 struct gsm_mncc *alerting = arg;
1922 struct msgb *msg = gsm48_msgb_alloc();
1923 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1924
Harald Welte03740842009-06-10 23:11:52 +08001925 gh->msg_type = GSM48_MT_CC_ALERTING;
1926
1927 /* facility */
1928 if (alerting->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01001929 gsm48_encode_facility(msg, 0, &alerting->facility);
Harald Welte03740842009-06-10 23:11:52 +08001930 /* progress */
1931 if (alerting->fields & MNCC_F_PROGRESS)
Harald Weltefdc93d92010-03-07 23:40:35 +01001932 gsm48_encode_progress(msg, 0, &alerting->progress);
Harald Welte03740842009-06-10 23:11:52 +08001933 /* user-user */
1934 if (alerting->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01001935 gsm48_encode_useruser(msg, 0, &alerting->useruser);
Harald Welte03740842009-06-10 23:11:52 +08001936
1937 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
1938
Harald Welte36fe2e82009-07-23 21:13:03 +02001939 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08001940}
1941
1942static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
1943{
1944 struct gsm_mncc *progress = arg;
1945 struct msgb *msg = gsm48_msgb_alloc();
1946 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1947
Harald Welte03740842009-06-10 23:11:52 +08001948 gh->msg_type = GSM48_MT_CC_PROGRESS;
1949
1950 /* progress */
Harald Weltefdc93d92010-03-07 23:40:35 +01001951 gsm48_encode_progress(msg, 1, &progress->progress);
Harald Welte03740842009-06-10 23:11:52 +08001952 /* user-user */
1953 if (progress->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01001954 gsm48_encode_useruser(msg, 0, &progress->useruser);
Harald Welte03740842009-06-10 23:11:52 +08001955
Harald Welte36fe2e82009-07-23 21:13:03 +02001956 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08001957}
1958
1959static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
1960{
1961 struct gsm_mncc *connect = arg;
1962 struct msgb *msg = gsm48_msgb_alloc();
1963 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1964
Harald Welte03740842009-06-10 23:11:52 +08001965 gh->msg_type = GSM48_MT_CC_CONNECT;
1966
1967 gsm48_stop_cc_timer(trans);
1968 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
1969
1970 /* facility */
1971 if (connect->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01001972 gsm48_encode_facility(msg, 0, &connect->facility);
Harald Welte03740842009-06-10 23:11:52 +08001973 /* progress */
1974 if (connect->fields & MNCC_F_PROGRESS)
Harald Weltefdc93d92010-03-07 23:40:35 +01001975 gsm48_encode_progress(msg, 0, &connect->progress);
Harald Welte03740842009-06-10 23:11:52 +08001976 /* connected number */
1977 if (connect->fields & MNCC_F_CONNECTED)
Harald Weltefdc93d92010-03-07 23:40:35 +01001978 gsm48_encode_connected(msg, &connect->connected);
Harald Welte03740842009-06-10 23:11:52 +08001979 /* user-user */
1980 if (connect->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01001981 gsm48_encode_useruser(msg, 0, &connect->useruser);
Harald Welte03740842009-06-10 23:11:52 +08001982
1983 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
1984
Harald Welte36fe2e82009-07-23 21:13:03 +02001985 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08001986}
1987
1988static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
1989{
1990 struct gsm48_hdr *gh = msgb_l3(msg);
1991 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1992 struct tlv_parsed tp;
1993 struct gsm_mncc connect;
1994
1995 gsm48_stop_cc_timer(trans);
1996
1997 memset(&connect, 0, sizeof(struct gsm_mncc));
1998 connect.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01001999 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08002000 /* use subscriber as connected party number */
2001 if (trans->subscr) {
2002 connect.fields |= MNCC_F_CONNECTED;
2003 strncpy(connect.connected.number, trans->subscr->extension,
2004 sizeof(connect.connected.number)-1);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002005 strncpy(connect.imsi, trans->subscr->imsi,
2006 sizeof(connect.imsi)-1);
Harald Welte03740842009-06-10 23:11:52 +08002007 }
2008 /* facility */
2009 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2010 connect.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01002011 gsm48_decode_facility(&connect.facility,
Harald Welte03740842009-06-10 23:11:52 +08002012 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2013 }
2014 /* user-user */
2015 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2016 connect.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01002017 gsm48_decode_useruser(&connect.useruser,
Harald Welte03740842009-06-10 23:11:52 +08002018 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2019 }
2020 /* ss-version */
2021 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2022 connect.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01002023 gsm48_decode_ssversion(&connect.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08002024 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2025 }
2026
2027 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
2028
Harald Welte0abe5a62009-07-23 19:06:52 +02002029 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect);
Harald Welte03740842009-06-10 23:11:52 +08002030}
2031
2032
2033static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
2034{
2035 struct gsm_mncc connect_ack;
2036
2037 gsm48_stop_cc_timer(trans);
2038
2039 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2040
2041 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
2042 connect_ack.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002043 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND,
Harald Welte03740842009-06-10 23:11:52 +08002044 &connect_ack);
2045}
2046
2047static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
2048{
2049 struct msgb *msg = gsm48_msgb_alloc();
2050 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2051
Harald Welte03740842009-06-10 23:11:52 +08002052 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
2053
2054 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2055
Harald Welte36fe2e82009-07-23 21:13:03 +02002056 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002057}
2058
2059static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
2060{
2061 struct gsm48_hdr *gh = msgb_l3(msg);
2062 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2063 struct tlv_parsed tp;
2064 struct gsm_mncc disc;
2065
2066 gsm48_stop_cc_timer(trans);
2067
2068 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
2069
2070 memset(&disc, 0, sizeof(struct gsm_mncc));
2071 disc.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002072 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
Harald Welte03740842009-06-10 23:11:52 +08002073 /* cause */
2074 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2075 disc.fields |= MNCC_F_CAUSE;
Harald Weltefdc93d92010-03-07 23:40:35 +01002076 gsm48_decode_cause(&disc.cause,
Harald Welte03740842009-06-10 23:11:52 +08002077 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2078 }
2079 /* facility */
2080 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2081 disc.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01002082 gsm48_decode_facility(&disc.facility,
Harald Welte03740842009-06-10 23:11:52 +08002083 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2084 }
2085 /* user-user */
2086 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2087 disc.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01002088 gsm48_decode_useruser(&disc.useruser,
Harald Welte03740842009-06-10 23:11:52 +08002089 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2090 }
2091 /* ss-version */
2092 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2093 disc.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01002094 gsm48_decode_ssversion(&disc.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08002095 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2096 }
2097
Harald Welte0abe5a62009-07-23 19:06:52 +02002098 return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc);
Harald Welte03740842009-06-10 23:11:52 +08002099
2100}
2101
Harald Weltebbc636a2009-06-11 14:23:20 +08002102static struct gsm_mncc_cause default_cause = {
2103 .location = GSM48_CAUSE_LOC_PRN_S_LU,
2104 .coding = 0,
2105 .rec = 0,
2106 .rec_val = 0,
2107 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
2108 .diag_len = 0,
2109 .diag = { 0 },
2110};
Harald Welte03740842009-06-10 23:11:52 +08002111
2112static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
2113{
2114 struct gsm_mncc *disc = arg;
2115 struct msgb *msg = gsm48_msgb_alloc();
2116 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2117
Harald Welte03740842009-06-10 23:11:52 +08002118 gh->msg_type = GSM48_MT_CC_DISCONNECT;
2119
2120 gsm48_stop_cc_timer(trans);
2121 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
2122
2123 /* cause */
2124 if (disc->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002125 gsm48_encode_cause(msg, 1, &disc->cause);
Harald Welte03740842009-06-10 23:11:52 +08002126 else
Harald Weltefdc93d92010-03-07 23:40:35 +01002127 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte03740842009-06-10 23:11:52 +08002128
2129 /* facility */
2130 if (disc->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01002131 gsm48_encode_facility(msg, 0, &disc->facility);
Harald Welte03740842009-06-10 23:11:52 +08002132 /* progress */
2133 if (disc->fields & MNCC_F_PROGRESS)
Harald Weltefdc93d92010-03-07 23:40:35 +01002134 gsm48_encode_progress(msg, 0, &disc->progress);
Harald Welte03740842009-06-10 23:11:52 +08002135 /* user-user */
2136 if (disc->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01002137 gsm48_encode_useruser(msg, 0, &disc->useruser);
Harald Welte03740842009-06-10 23:11:52 +08002138
2139 /* store disconnect cause for T306 expiry */
Harald Weltec2189a62009-07-23 18:56:43 +02002140 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
Harald Welte03740842009-06-10 23:11:52 +08002141
2142 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
2143
Harald Welte36fe2e82009-07-23 21:13:03 +02002144 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002145}
2146
2147static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
2148{
2149 struct gsm48_hdr *gh = msgb_l3(msg);
2150 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2151 struct tlv_parsed tp;
2152 struct gsm_mncc rel;
2153 int rc;
2154
2155 gsm48_stop_cc_timer(trans);
2156
2157 memset(&rel, 0, sizeof(struct gsm_mncc));
2158 rel.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002159 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08002160 /* cause */
2161 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2162 rel.fields |= MNCC_F_CAUSE;
Harald Weltefdc93d92010-03-07 23:40:35 +01002163 gsm48_decode_cause(&rel.cause,
Harald Welte03740842009-06-10 23:11:52 +08002164 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2165 }
2166 /* facility */
2167 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2168 rel.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01002169 gsm48_decode_facility(&rel.facility,
Harald Welte03740842009-06-10 23:11:52 +08002170 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2171 }
2172 /* user-user */
2173 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2174 rel.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01002175 gsm48_decode_useruser(&rel.useruser,
Harald Welte03740842009-06-10 23:11:52 +08002176 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2177 }
2178 /* ss-version */
2179 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2180 rel.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01002181 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08002182 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2183 }
2184
Harald Weltec2189a62009-07-23 18:56:43 +02002185 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
Harald Welte03740842009-06-10 23:11:52 +08002186 /* release collision 5.4.5 */
Harald Welte0abe5a62009-07-23 19:06:52 +02002187 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel);
Harald Welte03740842009-06-10 23:11:52 +08002188 } else {
Harald Welte0abe5a62009-07-23 19:06:52 +02002189 rc = gsm48_tx_simple(msg->lchan,
Harald Welte4861c822009-07-23 21:21:14 +02002190 GSM48_PDISC_CC | (trans->transaction_id << 4),
Harald Welte0abe5a62009-07-23 19:06:52 +02002191 GSM48_MT_CC_RELEASE_COMPL);
2192 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel);
Harald Welte03740842009-06-10 23:11:52 +08002193 }
2194
2195 new_cc_state(trans, GSM_CSTATE_NULL);
2196
2197 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002198 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002199
2200 return rc;
2201}
2202
2203static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
2204{
2205 struct gsm_mncc *rel = arg;
2206 struct msgb *msg = gsm48_msgb_alloc();
2207 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2208
Harald Welte03740842009-06-10 23:11:52 +08002209 gh->msg_type = GSM48_MT_CC_RELEASE;
2210
2211 trans->callref = 0;
2212
2213 gsm48_stop_cc_timer(trans);
2214 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
2215
2216 /* cause */
2217 if (rel->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002218 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte03740842009-06-10 23:11:52 +08002219 /* facility */
2220 if (rel->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01002221 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte03740842009-06-10 23:11:52 +08002222 /* user-user */
2223 if (rel->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01002224 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte03740842009-06-10 23:11:52 +08002225
Harald Weltec2189a62009-07-23 18:56:43 +02002226 trans->cc.T308_second = 0;
2227 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
Harald Welte03740842009-06-10 23:11:52 +08002228
Harald Weltec2189a62009-07-23 18:56:43 +02002229 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
Harald Welte03740842009-06-10 23:11:52 +08002230 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
2231
Harald Welte36fe2e82009-07-23 21:13:03 +02002232 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002233}
2234
2235static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
2236{
2237 struct gsm48_hdr *gh = msgb_l3(msg);
2238 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2239 struct tlv_parsed tp;
2240 struct gsm_mncc rel;
2241 int rc = 0;
2242
2243 gsm48_stop_cc_timer(trans);
2244
2245 memset(&rel, 0, sizeof(struct gsm_mncc));
2246 rel.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002247 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08002248 /* cause */
2249 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2250 rel.fields |= MNCC_F_CAUSE;
Harald Weltefdc93d92010-03-07 23:40:35 +01002251 gsm48_decode_cause(&rel.cause,
Harald Welte03740842009-06-10 23:11:52 +08002252 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2253 }
2254 /* facility */
2255 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2256 rel.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01002257 gsm48_decode_facility(&rel.facility,
Harald Welte03740842009-06-10 23:11:52 +08002258 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2259 }
2260 /* user-user */
2261 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2262 rel.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01002263 gsm48_decode_useruser(&rel.useruser,
Harald Welte03740842009-06-10 23:11:52 +08002264 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2265 }
2266 /* ss-version */
2267 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2268 rel.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01002269 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08002270 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2271 }
2272
2273 if (trans->callref) {
Harald Weltec2189a62009-07-23 18:56:43 +02002274 switch (trans->cc.state) {
Harald Welte03740842009-06-10 23:11:52 +08002275 case GSM_CSTATE_CALL_PRESENT:
Harald Welte0abe5a62009-07-23 19:06:52 +02002276 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002277 MNCC_REJ_IND, &rel);
2278 break;
2279 case GSM_CSTATE_RELEASE_REQ:
Harald Welte0abe5a62009-07-23 19:06:52 +02002280 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002281 MNCC_REL_CNF, &rel);
Harald Welte9ed54ff2009-12-12 21:00:48 +01002282 /* FIXME: in case of multiple calls, we can't simply
2283 * hang up here ! */
2284 lchan_auto_release(msg->lchan);
Harald Welte03740842009-06-10 23:11:52 +08002285 break;
2286 default:
Harald Welte0abe5a62009-07-23 19:06:52 +02002287 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002288 MNCC_REL_IND, &rel);
2289 }
2290 }
2291
2292 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002293 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002294
2295 return rc;
2296}
2297
2298static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
2299{
2300 struct gsm_mncc *rel = arg;
2301 struct msgb *msg = gsm48_msgb_alloc();
2302 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2303
Harald Welte03740842009-06-10 23:11:52 +08002304 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
2305
2306 trans->callref = 0;
2307
2308 gsm48_stop_cc_timer(trans);
2309
2310 /* cause */
2311 if (rel->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002312 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte03740842009-06-10 23:11:52 +08002313 /* facility */
2314 if (rel->fields & MNCC_F_FACILITY)
Harald Weltefdc93d92010-03-07 23:40:35 +01002315 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte03740842009-06-10 23:11:52 +08002316 /* user-user */
2317 if (rel->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01002318 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte03740842009-06-10 23:11:52 +08002319
Harald Weltec2189a62009-07-23 18:56:43 +02002320 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002321
Harald Welte36fe2e82009-07-23 21:13:03 +02002322 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002323}
2324
2325static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
2326{
2327 struct gsm48_hdr *gh = msgb_l3(msg);
2328 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2329 struct tlv_parsed tp;
2330 struct gsm_mncc fac;
2331
2332 memset(&fac, 0, sizeof(struct gsm_mncc));
2333 fac.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002334 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
Harald Welte03740842009-06-10 23:11:52 +08002335 /* facility */
2336 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2337 fac.fields |= MNCC_F_FACILITY;
Harald Weltefdc93d92010-03-07 23:40:35 +01002338 gsm48_decode_facility(&fac.facility,
Harald Welte03740842009-06-10 23:11:52 +08002339 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2340 }
2341 /* ss-version */
2342 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2343 fac.fields |= MNCC_F_SSVERSION;
Harald Weltefdc93d92010-03-07 23:40:35 +01002344 gsm48_decode_ssversion(&fac.ssversion,
Harald Welte03740842009-06-10 23:11:52 +08002345 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2346 }
2347
Harald Welte0abe5a62009-07-23 19:06:52 +02002348 return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac);
Harald Welte03740842009-06-10 23:11:52 +08002349}
2350
2351static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
2352{
2353 struct gsm_mncc *fac = arg;
2354 struct msgb *msg = gsm48_msgb_alloc();
2355 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2356
Harald Welte03740842009-06-10 23:11:52 +08002357 gh->msg_type = GSM48_MT_CC_FACILITY;
2358
2359 /* facility */
Harald Weltefdc93d92010-03-07 23:40:35 +01002360 gsm48_encode_facility(msg, 1, &fac->facility);
Harald Welte03740842009-06-10 23:11:52 +08002361
Harald Welte36fe2e82009-07-23 21:13:03 +02002362 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002363}
2364
2365static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
2366{
2367 struct gsm_mncc hold;
2368
2369 memset(&hold, 0, sizeof(struct gsm_mncc));
2370 hold.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002371 return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold);
Harald Welte03740842009-06-10 23:11:52 +08002372}
2373
2374static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
2375{
2376 struct msgb *msg = gsm48_msgb_alloc();
2377 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2378
Harald Welte03740842009-06-10 23:11:52 +08002379 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
2380
Harald Welte36fe2e82009-07-23 21:13:03 +02002381 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002382}
2383
2384static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
2385{
2386 struct gsm_mncc *hold_rej = arg;
2387 struct msgb *msg = gsm48_msgb_alloc();
2388 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2389
Harald Welte03740842009-06-10 23:11:52 +08002390 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
2391
2392 /* cause */
2393 if (hold_rej->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002394 gsm48_encode_cause(msg, 1, &hold_rej->cause);
Harald Welte03740842009-06-10 23:11:52 +08002395 else
Harald Weltefdc93d92010-03-07 23:40:35 +01002396 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte03740842009-06-10 23:11:52 +08002397
Harald Welte36fe2e82009-07-23 21:13:03 +02002398 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002399}
2400
2401static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
2402{
2403 struct gsm_mncc retrieve;
2404
2405 memset(&retrieve, 0, sizeof(struct gsm_mncc));
2406 retrieve.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002407 return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND,
2408 &retrieve);
Harald Welte03740842009-06-10 23:11:52 +08002409}
2410
2411static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
2412{
2413 struct msgb *msg = gsm48_msgb_alloc();
2414 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2415
Harald Welte03740842009-06-10 23:11:52 +08002416 gh->msg_type = GSM48_MT_CC_RETR_ACK;
2417
Harald Welte36fe2e82009-07-23 21:13:03 +02002418 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002419}
2420
2421static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
2422{
2423 struct gsm_mncc *retrieve_rej = arg;
2424 struct msgb *msg = gsm48_msgb_alloc();
2425 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2426
Harald Welte03740842009-06-10 23:11:52 +08002427 gh->msg_type = GSM48_MT_CC_RETR_REJ;
2428
2429 /* cause */
2430 if (retrieve_rej->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002431 gsm48_encode_cause(msg, 1, &retrieve_rej->cause);
Harald Welte03740842009-06-10 23:11:52 +08002432 else
Harald Weltefdc93d92010-03-07 23:40:35 +01002433 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte03740842009-06-10 23:11:52 +08002434
Harald Welte36fe2e82009-07-23 21:13:03 +02002435 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002436}
2437
2438static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
2439{
2440 struct gsm48_hdr *gh = msgb_l3(msg);
2441 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2442 struct tlv_parsed tp;
2443 struct gsm_mncc dtmf;
2444
2445 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2446 dtmf.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002447 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte03740842009-06-10 23:11:52 +08002448 /* keypad facility */
2449 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
2450 dtmf.fields |= MNCC_F_KEYPAD;
Harald Weltefdc93d92010-03-07 23:40:35 +01002451 gsm48_decode_keypad(&dtmf.keypad,
Harald Welte03740842009-06-10 23:11:52 +08002452 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
2453 }
2454
Harald Welte0abe5a62009-07-23 19:06:52 +02002455 return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf);
Harald Welte03740842009-06-10 23:11:52 +08002456}
2457
2458static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
2459{
2460 struct gsm_mncc *dtmf = arg;
2461 struct msgb *msg = gsm48_msgb_alloc();
2462 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2463
Harald Welte03740842009-06-10 23:11:52 +08002464 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
2465
2466 /* keypad */
2467 if (dtmf->fields & MNCC_F_KEYPAD)
Harald Weltefdc93d92010-03-07 23:40:35 +01002468 gsm48_encode_keypad(msg, dtmf->keypad);
Harald Welte03740842009-06-10 23:11:52 +08002469
Harald Welte36fe2e82009-07-23 21:13:03 +02002470 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002471}
2472
2473static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
2474{
2475 struct gsm_mncc *dtmf = arg;
2476 struct msgb *msg = gsm48_msgb_alloc();
2477 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2478
Harald Welte03740842009-06-10 23:11:52 +08002479 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
2480
2481 /* cause */
2482 if (dtmf->fields & MNCC_F_CAUSE)
Harald Weltefdc93d92010-03-07 23:40:35 +01002483 gsm48_encode_cause(msg, 1, &dtmf->cause);
Harald Welte03740842009-06-10 23:11:52 +08002484 else
Harald Weltefdc93d92010-03-07 23:40:35 +01002485 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte03740842009-06-10 23:11:52 +08002486
Harald Welte36fe2e82009-07-23 21:13:03 +02002487 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002488}
2489
2490static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
2491{
2492 struct msgb *msg = gsm48_msgb_alloc();
2493 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2494
Harald Welte03740842009-06-10 23:11:52 +08002495 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
2496
Harald Welte36fe2e82009-07-23 21:13:03 +02002497 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002498}
2499
2500static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
2501{
2502 struct gsm_mncc dtmf;
2503
2504 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2505 dtmf.callref = trans->callref;
2506
Harald Welte0abe5a62009-07-23 19:06:52 +02002507 return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
Harald Welte03740842009-06-10 23:11:52 +08002508}
2509
2510static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
2511{
2512 struct gsm48_hdr *gh = msgb_l3(msg);
2513 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2514 struct tlv_parsed tp;
2515 struct gsm_mncc modify;
2516
2517 memset(&modify, 0, sizeof(struct gsm_mncc));
2518 modify.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002519 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte03740842009-06-10 23:11:52 +08002520 /* bearer capability */
2521 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2522 modify.fields |= MNCC_F_BEARER_CAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01002523 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte03740842009-06-10 23:11:52 +08002524 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2525 }
2526
2527 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
2528
Harald Welte0abe5a62009-07-23 19:06:52 +02002529 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify);
Harald Welte03740842009-06-10 23:11:52 +08002530}
2531
2532static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
2533{
2534 struct gsm_mncc *modify = arg;
2535 struct msgb *msg = gsm48_msgb_alloc();
2536 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2537
Harald Welte03740842009-06-10 23:11:52 +08002538 gh->msg_type = GSM48_MT_CC_MODIFY;
2539
2540 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
2541
2542 /* bearer capability */
Harald Weltefdc93d92010-03-07 23:40:35 +01002543 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte03740842009-06-10 23:11:52 +08002544
2545 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
2546
Harald Welte36fe2e82009-07-23 21:13:03 +02002547 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002548}
2549
2550static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
2551{
2552 struct gsm48_hdr *gh = msgb_l3(msg);
2553 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2554 struct tlv_parsed tp;
2555 struct gsm_mncc modify;
2556
2557 gsm48_stop_cc_timer(trans);
2558
2559 memset(&modify, 0, sizeof(struct gsm_mncc));
2560 modify.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002561 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte03740842009-06-10 23:11:52 +08002562 /* bearer capability */
2563 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2564 modify.fields |= MNCC_F_BEARER_CAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01002565 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte03740842009-06-10 23:11:52 +08002566 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2567 }
2568
2569 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2570
Harald Welte0abe5a62009-07-23 19:06:52 +02002571 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify);
Harald Welte03740842009-06-10 23:11:52 +08002572}
2573
2574static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
2575{
2576 struct gsm_mncc *modify = arg;
2577 struct msgb *msg = gsm48_msgb_alloc();
2578 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2579
Harald Welte03740842009-06-10 23:11:52 +08002580 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
2581
2582 /* bearer capability */
Harald Weltefdc93d92010-03-07 23:40:35 +01002583 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte03740842009-06-10 23:11:52 +08002584
2585 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2586
Harald Welte36fe2e82009-07-23 21:13:03 +02002587 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002588}
2589
2590static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
2591{
2592 struct gsm48_hdr *gh = msgb_l3(msg);
2593 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2594 struct tlv_parsed tp;
2595 struct gsm_mncc modify;
2596
2597 gsm48_stop_cc_timer(trans);
2598
2599 memset(&modify, 0, sizeof(struct gsm_mncc));
2600 modify.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002601 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
Harald Welte03740842009-06-10 23:11:52 +08002602 /* bearer capability */
2603 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2604 modify.fields |= GSM48_IE_BEARER_CAP;
Harald Weltefdc93d92010-03-07 23:40:35 +01002605 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte03740842009-06-10 23:11:52 +08002606 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2607 }
2608 /* cause */
2609 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2610 modify.fields |= MNCC_F_CAUSE;
Harald Weltefdc93d92010-03-07 23:40:35 +01002611 gsm48_decode_cause(&modify.cause,
Harald Welte03740842009-06-10 23:11:52 +08002612 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2613 }
2614
2615 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2616
Harald Welte0abe5a62009-07-23 19:06:52 +02002617 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify);
Harald Welte03740842009-06-10 23:11:52 +08002618}
2619
2620static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
2621{
2622 struct gsm_mncc *modify = arg;
2623 struct msgb *msg = gsm48_msgb_alloc();
2624 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2625
Harald Welte03740842009-06-10 23:11:52 +08002626 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
2627
2628 /* bearer capability */
Harald Weltefdc93d92010-03-07 23:40:35 +01002629 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte03740842009-06-10 23:11:52 +08002630 /* cause */
Harald Weltefdc93d92010-03-07 23:40:35 +01002631 gsm48_encode_cause(msg, 1, &modify->cause);
Harald Welte03740842009-06-10 23:11:52 +08002632
2633 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2634
Harald Welte36fe2e82009-07-23 21:13:03 +02002635 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002636}
2637
2638static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
2639{
2640 struct gsm_mncc *notify = arg;
2641 struct msgb *msg = gsm48_msgb_alloc();
2642 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2643
Harald Welte03740842009-06-10 23:11:52 +08002644 gh->msg_type = GSM48_MT_CC_NOTIFY;
2645
2646 /* notify */
Harald Weltefdc93d92010-03-07 23:40:35 +01002647 gsm48_encode_notify(msg, notify->notify);
Harald Welte03740842009-06-10 23:11:52 +08002648
Harald Welte36fe2e82009-07-23 21:13:03 +02002649 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002650}
2651
2652static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
2653{
2654 struct gsm48_hdr *gh = msgb_l3(msg);
2655 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2656// struct tlv_parsed tp;
2657 struct gsm_mncc notify;
2658
2659 memset(&notify, 0, sizeof(struct gsm_mncc));
2660 notify.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002661// tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len);
Harald Welte03740842009-06-10 23:11:52 +08002662 if (payload_len >= 1)
Harald Weltefdc93d92010-03-07 23:40:35 +01002663 gsm48_decode_notify(&notify.notify, gh->data);
Harald Welte03740842009-06-10 23:11:52 +08002664
Harald Welte0abe5a62009-07-23 19:06:52 +02002665 return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, &notify);
Harald Welte03740842009-06-10 23:11:52 +08002666}
2667
2668static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
2669{
2670 struct gsm_mncc *user = arg;
2671 struct msgb *msg = gsm48_msgb_alloc();
2672 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2673
Harald Welte03740842009-06-10 23:11:52 +08002674 gh->msg_type = GSM48_MT_CC_USER_INFO;
2675
2676 /* user-user */
2677 if (user->fields & MNCC_F_USERUSER)
Harald Weltefdc93d92010-03-07 23:40:35 +01002678 gsm48_encode_useruser(msg, 1, &user->useruser);
Harald Welte03740842009-06-10 23:11:52 +08002679 /* more data */
2680 if (user->more)
Harald Weltefdc93d92010-03-07 23:40:35 +01002681 gsm48_encode_more(msg);
Harald Welte03740842009-06-10 23:11:52 +08002682
Harald Welte36fe2e82009-07-23 21:13:03 +02002683 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002684}
2685
2686static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
2687{
2688 struct gsm48_hdr *gh = msgb_l3(msg);
2689 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2690 struct tlv_parsed tp;
2691 struct gsm_mncc user;
2692
2693 memset(&user, 0, sizeof(struct gsm_mncc));
2694 user.callref = trans->callref;
Harald Welte705f2942010-03-02 23:18:30 +01002695 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
Harald Welte03740842009-06-10 23:11:52 +08002696 /* user-user */
2697 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2698 user.fields |= MNCC_F_USERUSER;
Harald Weltefdc93d92010-03-07 23:40:35 +01002699 gsm48_decode_useruser(&user.useruser,
Harald Welte03740842009-06-10 23:11:52 +08002700 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2701 }
2702 /* more data */
2703 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
2704 user.more = 1;
2705
Harald Welte0abe5a62009-07-23 19:06:52 +02002706 return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user);
Harald Welte03740842009-06-10 23:11:52 +08002707}
2708
Holger Hans Peter Freythercf0f3362009-10-22 15:13:00 +02002709static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg)
Harald Welte03740842009-06-10 23:11:52 +08002710{
2711 struct gsm_mncc *mode = arg;
2712
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002713 return gsm48_lchan_modify(trans->conn->lchan, mode->lchan_mode);
Harald Welte03740842009-06-10 23:11:52 +08002714}
2715
2716static struct downstate {
2717 u_int32_t states;
2718 int type;
2719 int (*rout) (struct gsm_trans *trans, void *arg);
2720} downstatelist[] = {
2721 /* mobile originating call establishment */
2722 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
2723 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc},
2724 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
2725 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
2726 {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 */
2727 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
2728 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
2729 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
2730 /* mobile terminating call establishment */
2731 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
2732 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
2733 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
2734 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
2735 /* signalling during call */
2736 {SBIT(GSM_CSTATE_ACTIVE),
2737 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
2738 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
2739 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
2740 {ALL_STATES,
2741 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
2742 {ALL_STATES,
2743 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
2744 {ALL_STATES,
2745 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
2746 {SBIT(GSM_CSTATE_ACTIVE),
2747 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
2748 {SBIT(GSM_CSTATE_ACTIVE),
2749 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
2750 {SBIT(GSM_CSTATE_ACTIVE),
2751 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
2752 {SBIT(GSM_CSTATE_ACTIVE),
2753 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
2754 {SBIT(GSM_CSTATE_ACTIVE),
2755 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
2756 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2757 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
2758 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2759 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
2760 {SBIT(GSM_CSTATE_ACTIVE),
2761 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
2762 /* clearing */
2763 {SBIT(GSM_CSTATE_INITIATED),
2764 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
2765 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
2766 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
2767 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
2768 MNCC_REL_REQ, gsm48_cc_tx_release},
2769 /* special */
2770 {ALL_STATES,
Holger Hans Peter Freythercf0f3362009-10-22 15:13:00 +02002771 MNCC_LCHAN_MODIFY, _gsm48_lchan_modify},
Harald Welte03740842009-06-10 23:11:52 +08002772};
2773
2774#define DOWNSLLEN \
2775 (sizeof(downstatelist) / sizeof(struct downstate))
2776
2777
2778int mncc_send(struct gsm_network *net, int msg_type, void *arg)
2779{
Harald Welteaa60edb2009-08-09 18:52:33 +02002780 int i, rc = 0;
Harald Welte03740842009-06-10 23:11:52 +08002781 struct gsm_trans *trans = NULL, *transt;
Harald Welteaa60edb2009-08-09 18:52:33 +02002782 struct gsm_lchan *lchan = NULL;
Harald Welte03740842009-06-10 23:11:52 +08002783 struct gsm_bts *bts = NULL;
Harald Welte03740842009-06-10 23:11:52 +08002784 struct gsm_mncc *data = arg, rel;
2785
2786 /* handle special messages */
2787 switch(msg_type) {
2788 case MNCC_BRIDGE:
2789 return tch_bridge(net, arg);
2790 case MNCC_FRAME_DROP:
Harald Welte3971ad52009-12-19 22:23:05 +01002791 return tch_recv_mncc(net, data->callref, 0);
Harald Welte03740842009-06-10 23:11:52 +08002792 case MNCC_FRAME_RECV:
Harald Welte3971ad52009-12-19 22:23:05 +01002793 return tch_recv_mncc(net, data->callref, 1);
2794 case GSM_TCHF_FRAME:
2795 /* Find callref */
2796 trans = trans_find_by_callref(net, data->callref);
2797 if (!trans)
2798 return -EIO;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002799 if (!trans->conn)
Harald Welte3971ad52009-12-19 22:23:05 +01002800 return 0;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002801 if (trans->conn->lchan->type != GSM_LCHAN_TCH_F)
Harald Welte3971ad52009-12-19 22:23:05 +01002802 return 0;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002803 bts = trans->conn->lchan->ts->trx->bts;
Harald Welte3971ad52009-12-19 22:23:05 +01002804 switch (bts->type) {
2805 case GSM_BTS_TYPE_NANOBTS:
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002806 if (!trans->conn->lchan->abis_ip.rtp_socket)
Harald Welte3971ad52009-12-19 22:23:05 +01002807 return 0;
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002808 return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg);
Harald Welte3971ad52009-12-19 22:23:05 +01002809 case GSM_BTS_TYPE_BS11:
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002810 return trau_send_frame(trans->conn->lchan, arg);
Harald Welte3971ad52009-12-19 22:23:05 +01002811 default:
2812 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
2813 }
2814 return -EINVAL;
Harald Welte03740842009-06-10 23:11:52 +08002815 }
2816
2817 memset(&rel, 0, sizeof(struct gsm_mncc));
2818 rel.callref = data->callref;
2819
2820 /* Find callref */
Harald Weltec2189a62009-07-23 18:56:43 +02002821 trans = trans_find_by_callref(net, data->callref);
Harald Welte03740842009-06-10 23:11:52 +08002822
2823 /* Callref unknown */
2824 if (!trans) {
Holger Hans Peter Freythere2a3c9f2009-10-27 14:21:14 +01002825 struct gsm_subscriber *subscr;
2826
Harald Welte6e1536e2009-07-04 10:11:24 +02002827 if (msg_type != MNCC_SETUP_REQ) {
Harald Welte03740842009-06-10 23:11:52 +08002828 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2829 "Received '%s' from MNCC with "
2830 "unknown callref %d\n", data->called.number,
2831 get_mncc_name(msg_type), data->callref);
2832 /* Invalid call reference */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002833 return mncc_release_ind(net, NULL, data->callref,
2834 GSM48_CAUSE_LOC_PRN_S_LU,
2835 GSM48_CC_CAUSE_INVAL_TRANS_ID);
Harald Welte03740842009-06-10 23:11:52 +08002836 }
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002837 if (!data->called.number[0] && !data->imsi[0]) {
2838 DEBUGP(DCC, "(bts - trx - ts - ti) "
2839 "Received '%s' from MNCC with "
2840 "no number or IMSI\n", get_mncc_name(msg_type));
2841 /* Invalid number */
2842 return mncc_release_ind(net, NULL, data->callref,
2843 GSM48_CAUSE_LOC_PRN_S_LU,
2844 GSM48_CC_CAUSE_INV_NR_FORMAT);
2845 }
Harald Welte03740842009-06-10 23:11:52 +08002846 /* New transaction due to setup, find subscriber */
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002847 if (data->called.number[0])
Harald Welte75350412009-07-23 18:46:00 +02002848 subscr = subscr_get_by_extension(net,
2849 data->called.number);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002850 else
Harald Welte75350412009-07-23 18:46:00 +02002851 subscr = subscr_get_by_imsi(net, data->imsi);
Harald Welte03740842009-06-10 23:11:52 +08002852 /* If subscriber is not found */
2853 if (!subscr) {
2854 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2855 "Received '%s' from MNCC with "
2856 "unknown subscriber %s\n", data->called.number,
2857 get_mncc_name(msg_type), data->called.number);
2858 /* Unknown subscriber */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002859 return mncc_release_ind(net, NULL, data->callref,
2860 GSM48_CAUSE_LOC_PRN_S_LU,
2861 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte03740842009-06-10 23:11:52 +08002862 }
2863 /* If subscriber is not "attached" */
2864 if (!subscr->lac) {
2865 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2866 "Received '%s' from MNCC with "
2867 "detached subscriber %s\n", data->called.number,
2868 get_mncc_name(msg_type), data->called.number);
2869 subscr_put(subscr);
2870 /* Temporarily out of order */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002871 return mncc_release_ind(net, NULL, data->callref,
2872 GSM48_CAUSE_LOC_PRN_S_LU,
2873 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte03740842009-06-10 23:11:52 +08002874 }
2875 /* Create transaction */
Harald Weltec2189a62009-07-23 18:56:43 +02002876 trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref);
2877 if (!trans) {
Harald Welte03740842009-06-10 23:11:52 +08002878 DEBUGP(DCC, "No memory for trans.\n");
2879 subscr_put(subscr);
2880 /* Ressource unavailable */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002881 mncc_release_ind(net, NULL, data->callref,
2882 GSM48_CAUSE_LOC_PRN_S_LU,
2883 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08002884 return -ENOMEM;
2885 }
Harald Welte03740842009-06-10 23:11:52 +08002886 /* Find lchan */
Harald Welteaa60edb2009-08-09 18:52:33 +02002887 lchan = lchan_for_subscr(subscr);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01002888
Harald Welte03740842009-06-10 23:11:52 +08002889 /* If subscriber has no lchan */
2890 if (!lchan) {
2891 /* find transaction with this subscriber already paging */
2892 llist_for_each_entry(transt, &net->trans_list, entry) {
2893 /* Transaction of our lchan? */
2894 if (transt == trans ||
2895 transt->subscr != subscr)
2896 continue;
2897 DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) "
2898 "Received '%s' from MNCC with "
2899 "unallocated channel, paging already "
2900 "started.\n", bts->nr,
2901 data->called.number,
2902 get_mncc_name(msg_type));
Holger Hans Peter Freythere2a3c9f2009-10-27 14:21:14 +01002903 subscr_put(subscr);
2904 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002905 return 0;
2906 }
2907 /* store setup informations until paging was successfull */
Harald Weltec2189a62009-07-23 18:56:43 +02002908 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
Harald Welte2a3a81b2009-08-01 19:31:47 +02002909 /* Trigger paging */
2910 paging_request(net, subscr, RSL_CHANNEED_TCH_F,
2911 setup_trig_pag_evt, subscr);
Holger Hans Peter Freythere2a3c9f2009-10-27 14:21:14 +01002912 subscr_put(subscr);
Harald Welte03740842009-06-10 23:11:52 +08002913 return 0;
2914 }
2915 /* Assign lchan */
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002916 trans->conn = &lchan->conn;
2917 use_subscr_con(trans->conn);
Holger Hans Peter Freythere2a3c9f2009-10-27 14:21:14 +01002918 subscr_put(subscr);
Harald Welte03740842009-06-10 23:11:52 +08002919 }
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002920
2921 if (trans->conn)
2922 lchan = trans->conn->lchan;
Harald Welte03740842009-06-10 23:11:52 +08002923
2924 /* if paging did not respond yet */
2925 if (!lchan) {
2926 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02002927 "Received '%s' from MNCC in paging state\n",
Harald Welte03740842009-06-10 23:11:52 +08002928 (trans->subscr)?(trans->subscr->extension):"-",
2929 get_mncc_name(msg_type));
Harald Weltebbc636a2009-06-11 14:23:20 +08002930 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
2931 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Harald Welte03740842009-06-10 23:11:52 +08002932 if (msg_type == MNCC_REL_REQ)
2933 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
2934 else
2935 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
2936 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002937 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002938 return rc;
2939 }
2940
2941 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) "
2942 "Received '%s' from MNCC in state %d (%s)\n",
2943 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
2944 trans->transaction_id,
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01002945 (trans->conn->subscr)?(trans->conn->subscr->extension):"-",
Harald Weltec2189a62009-07-23 18:56:43 +02002946 get_mncc_name(msg_type), trans->cc.state,
Harald Welteb30935e2010-03-25 12:13:02 +08002947 gsm48_cc_state_name(trans->cc.state));
Harald Welte03740842009-06-10 23:11:52 +08002948
2949 /* Find function for current state and message */
2950 for (i = 0; i < DOWNSLLEN; i++)
2951 if ((msg_type == downstatelist[i].type)
Harald Weltec2189a62009-07-23 18:56:43 +02002952 && ((1 << trans->cc.state) & downstatelist[i].states))
Harald Welte03740842009-06-10 23:11:52 +08002953 break;
2954 if (i == DOWNSLLEN) {
2955 DEBUGP(DCC, "Message unhandled at this state.\n");
2956 return 0;
2957 }
2958
2959 rc = downstatelist[i].rout(trans, arg);
2960
2961 return rc;
2962}
2963
2964
2965static struct datastate {
2966 u_int32_t states;
2967 int type;
2968 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
2969} datastatelist[] = {
2970 /* mobile originating call establishment */
2971 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2972 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
2973 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2974 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
2975 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
2976 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
2977 /* mobile terminating call establishment */
2978 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
2979 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
2980 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
2981 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +02002982 {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 Welte03740842009-06-10 23:11:52 +08002983 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
2984 /* signalling during call */
2985 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
2986 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
2987 {SBIT(GSM_CSTATE_ACTIVE),
2988 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
2989 {ALL_STATES,
2990 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
2991 {ALL_STATES,
2992 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
2993 {ALL_STATES,
2994 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
2995 {SBIT(GSM_CSTATE_ACTIVE),
2996 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
2997 {SBIT(GSM_CSTATE_ACTIVE),
2998 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
2999 {SBIT(GSM_CSTATE_ACTIVE),
3000 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
3001 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3002 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
3003 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3004 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
3005 {SBIT(GSM_CSTATE_ACTIVE),
3006 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
3007 /* clearing */
3008 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3009 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
3010 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
3011 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
3012 {ALL_STATES, /* 5.4.3.4 */
3013 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
3014};
3015
3016#define DATASLLEN \
3017 (sizeof(datastatelist) / sizeof(struct datastate))
3018
Harald Welte59b04682009-06-10 05:40:52 +08003019static int gsm0408_rcv_cc(struct msgb *msg)
3020{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01003021 struct gsm_subscriber_connection *conn;
Harald Welte59b04682009-06-10 05:40:52 +08003022 struct gsm48_hdr *gh = msgb_l3(msg);
3023 u_int8_t msg_type = gh->msg_type & 0xbf;
Harald Welte4861c822009-07-23 21:21:14 +02003024 u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */
Harald Welte03740842009-06-10 23:11:52 +08003025 struct gsm_lchan *lchan = msg->lchan;
Harald Weltec2189a62009-07-23 18:56:43 +02003026 struct gsm_trans *trans = NULL;
Harald Welte03740842009-06-10 23:11:52 +08003027 int i, rc = 0;
Harald Welte59b04682009-06-10 05:40:52 +08003028
Harald Welte03740842009-06-10 23:11:52 +08003029 if (msg_type & 0x80) {
3030 DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type);
3031 return -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08003032 }
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01003033
3034 conn = &lchan->conn;
3035
Harald Welte03740842009-06-10 23:11:52 +08003036 /* Find transaction */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01003037 trans = trans_find_by_id(conn->subscr, GSM48_PDISC_CC, transaction_id);
Harald Weltec2189a62009-07-23 18:56:43 +02003038
Harald Welte4861c822009-07-23 21:21:14 +02003039 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte03740842009-06-10 23:11:52 +08003040 "Received '%s' from MS in state %d (%s)\n",
3041 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01003042 transaction_id, (conn->subscr)?(conn->subscr->extension):"-",
Harald Welteb30935e2010-03-25 12:13:02 +08003043 gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0,
3044 gsm48_cc_state_name(trans?(trans->cc.state):0));
Harald Welte03740842009-06-10 23:11:52 +08003045
3046 /* Create transaction */
3047 if (!trans) {
Harald Welte4861c822009-07-23 21:21:14 +02003048 DEBUGP(DCC, "Unknown transaction ID %x, "
Harald Welte03740842009-06-10 23:11:52 +08003049 "creating new trans.\n", transaction_id);
3050 /* Create transaction */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +01003051 trans = trans_alloc(conn->subscr, GSM48_PDISC_CC,
Harald Weltec2189a62009-07-23 18:56:43 +02003052 transaction_id, new_callref++);
3053 if (!trans) {
Harald Welte03740842009-06-10 23:11:52 +08003054 DEBUGP(DCC, "No memory for trans.\n");
3055 rc = gsm48_tx_simple(msg->lchan,
Harald Welte4861c822009-07-23 21:21:14 +02003056 GSM48_PDISC_CC | (transaction_id << 4),
Harald Welte03740842009-06-10 23:11:52 +08003057 GSM48_MT_CC_RELEASE_COMPL);
3058 return -ENOMEM;
3059 }
Harald Welte03740842009-06-10 23:11:52 +08003060 /* Assign transaction */
Holger Hans Peter Freyther4009da42010-03-23 07:00:22 +01003061 trans->conn = &lchan->conn;
3062 use_subscr_con(trans->conn);
Harald Welte03740842009-06-10 23:11:52 +08003063 }
3064
3065 /* find function for current state and message */
3066 for (i = 0; i < DATASLLEN; i++)
3067 if ((msg_type == datastatelist[i].type)
Harald Weltec2189a62009-07-23 18:56:43 +02003068 && ((1 << trans->cc.state) & datastatelist[i].states))
Harald Welte03740842009-06-10 23:11:52 +08003069 break;
3070 if (i == DATASLLEN) {
3071 DEBUGP(DCC, "Message unhandled at this state.\n");
3072 return 0;
3073 }
3074
3075 rc = datastatelist[i].rout(trans, msg);
Harald Welte59b04682009-06-10 05:40:52 +08003076
3077 return rc;
3078}
3079
3080/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
Harald Welte (local)64994ce2009-08-14 11:41:12 +02003081int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
Harald Welte59b04682009-06-10 05:40:52 +08003082{
3083 struct gsm48_hdr *gh = msgb_l3(msg);
3084 u_int8_t pdisc = gh->proto_discr & 0x0f;
3085 int rc = 0;
Harald Weltef6a38ec2009-12-29 11:49:12 +01003086
3087 if (silent_call_reroute(msg))
3088 return silent_call_rx(msg);
Harald Welte59b04682009-06-10 05:40:52 +08003089
3090 switch (pdisc) {
3091 case GSM48_PDISC_CC:
3092 rc = gsm0408_rcv_cc(msg);
3093 break;
3094 case GSM48_PDISC_MM:
3095 rc = gsm0408_rcv_mm(msg);
3096 break;
3097 case GSM48_PDISC_RR:
3098 rc = gsm0408_rcv_rr(msg);
3099 break;
3100 case GSM48_PDISC_SMS:
Harald Welte (local)64994ce2009-08-14 11:41:12 +02003101 rc = gsm0411_rcv_sms(msg, link_id);
Harald Welte59b04682009-06-10 05:40:52 +08003102 break;
3103 case GSM48_PDISC_MM_GPRS:
3104 case GSM48_PDISC_SM_GPRS:
Harald Welte60e5f4f2009-12-24 12:13:17 +01003105 LOGP(DRLL, LOGL_NOTICE, "Unimplemented "
3106 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte59b04682009-06-10 05:40:52 +08003107 break;
Harald Welte03115042009-10-16 08:32:58 +02003108 case GSM48_PDISC_NC_SS:
3109 rc = handle_rcv_ussd(msg);
3110 break;
Harald Welte59b04682009-06-10 05:40:52 +08003111 default:
Harald Welte60e5f4f2009-12-24 12:13:17 +01003112 LOGP(DRLL, LOGL_NOTICE, "Unknown "
3113 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte59b04682009-06-10 05:40:52 +08003114 break;
3115 }
3116
3117 return rc;
3118}
3119
Harald Welte3c062072009-07-28 18:25:29 +02003120/*
3121 * This will be ran by the linker when loading the DSO. We use it to
3122 * do system initialization, e.g. registration of signal handlers.
3123 */
3124static __attribute__((constructor)) void on_dso_load_0408(void)
3125{
Harald Welte3c062072009-07-28 18:25:29 +02003126 register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL);
3127 register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL);
3128}