blob: 2cd2a1ff1cad8ceab3ab2436859200bc9242197d [file] [log] [blame]
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
Harald Welte52b1f982008-12-23 20:25:15 +00002 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
Harald Weltebf5e8df2009-02-03 12:59:45 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +08005 * (C) 2008-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte8470bf22008-12-25 23:28:35 +00006 *
Harald Welte52b1f982008-12-23 20:25:15 +00007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
Harald Weltedb253af2008-12-30 17:56:55 +000030#include <time.h>
Harald Welte4b634542008-12-27 01:55:51 +000031#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000032
Sylvain Munaut30a15382009-12-24 00:27:26 +010033#include <openbsc/auth.h>
Harald Welte75a983f2008-12-27 21:34:06 +000034#include <openbsc/db.h>
Harald Welte8470bf22008-12-25 23:28:35 +000035#include <openbsc/debug.h>
36#include <openbsc/gsm_data.h>
37#include <openbsc/gsm_subscriber.h>
Daniel Willmann8b3390e2008-12-28 00:31:09 +000038#include <openbsc/gsm_04_11.h>
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +080040#include <openbsc/gsm_04_80.h>
Harald Welte8470bf22008-12-25 23:28:35 +000041#include <openbsc/abis_rsl.h>
Holger Freytherca362a62009-01-04 21:05:01 +000042#include <openbsc/chan_alloc.h>
Harald Welte0b4c34e2009-02-09 17:54:43 +000043#include <openbsc/paging.h>
Holger Freyther053e09d2009-02-14 22:51:06 +000044#include <openbsc/signal.h>
Harald Welte45b407a2009-05-23 15:51:12 +000045#include <openbsc/trau_frame.h>
Harald Welte11fa29c2009-02-19 17:24:39 +000046#include <openbsc/trau_mux.h>
Harald Welte805f6442009-07-28 18:25:29 +020047#include <openbsc/rtp_proxy.h>
Harald Weltedcaf5652009-07-23 18:56:43 +020048#include <openbsc/transaction.h>
Harald Welte6eafe912009-10-16 08:32:58 +020049#include <openbsc/ussd.h>
Harald Welte51008772009-12-29 11:49:12 +010050#include <openbsc/silent_call.h>
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +080051#include <openbsc/bsc_api.h>
Holger Hans Peter Freyther88519ea2010-06-30 12:44:07 +080052#include <openbsc/osmo_msc.h>
Holger Hans Peter Freyther841c2002010-09-30 18:52:23 +080053#include <osmocore/bitvec.h>
54
55#include <osmocore/gsm48.h>
56#include <osmocore/gsm_utils.h>
57#include <osmocore/msgb.h>
58#include <osmocore/talloc.h>
59#include <osmocore/tlv.h>
Harald Welte52b1f982008-12-23 20:25:15 +000060
Harald Welte (local)d19e58b2009-08-15 02:30:58 +020061void *tall_locop_ctx;
Sylvain Munaut30a15382009-12-24 00:27:26 +010062void *tall_authciphop_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +020063
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +080064int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +080065static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte65e74cc2008-12-29 01:55:35 +000066 u_int8_t pdisc, u_int8_t msg_type);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010067static void schedule_reject(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080068static void release_anchor(struct gsm_subscriber_connection *conn);
Harald Welte65e74cc2008-12-29 01:55:35 +000069
Harald Welte52b1f982008-12-23 20:25:15 +000070struct gsm_lai {
71 u_int16_t mcc;
72 u_int16_t mnc;
73 u_int16_t lac;
74};
75
Harald Welte4bfdfe72009-06-10 23:11:52 +080076static u_int32_t new_callref = 0x80000001;
77
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +080078static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn,
79 struct gsm_trans *trans)
80{
81 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
82
83 /* if we get passed a transaction reference, do some common
84 * work that the caller no longer has to do */
85 if (trans) {
86 gh->proto_discr = trans->protocol | (trans->transaction_id << 4);
87 msg->lchan = trans->conn->lchan;
88 }
89
90
91 if (msg->lchan) {
92 msg->trx = msg->lchan->ts->trx;
93 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC)
94 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) "
95 "Sending '%s' to MS.\n", msg->trx->bts->nr,
96 msg->trx->nr, msg->lchan->ts->nr,
97 gh->proto_discr & 0xf0,
98 gsm48_cc_msg_name(gh->msg_type));
99 else
100 DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) "
101 "Sending 0x%02x to MS.\n", msg->trx->bts->nr,
102 msg->trx->nr, msg->lchan->ts->nr,
103 gh->proto_discr, gh->msg_type);
104 }
105
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800106 return gsm0808_submit_dtap(conn, msg, 0);
107}
Sylvain Munaut30a15382009-12-24 00:27:26 +0100108
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +0800109int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message)
110{
111 struct gsm48_hdr *gh;
112 struct msgb *ss_notify;
113
114 ss_notify = gsm0480_create_notifySS(message);
115 if (!ss_notify)
116 return -1;
117
118 gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0);
119 uint8_t *data = msgb_push(ss_notify, 1);
120 data[0] = ss_notify->len - 1;
121 gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh));
122 gh->msg_type = GSM48_MT_CC_FACILITY;
123 return gsm48_conn_sendmsg(ss_notify, trans->conn, trans);
124}
125
Sylvain Munaut30a15382009-12-24 00:27:26 +0100126static void release_security_operation(struct gsm_subscriber_connection *conn)
127{
128 if (!conn->sec_operation)
129 return;
130
131 talloc_free(conn->sec_operation);
132 conn->sec_operation = NULL;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800133 msc_release_connection(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100134}
135
136static void allocate_security_operation(struct gsm_subscriber_connection *conn)
137{
Sylvain Munaut30a15382009-12-24 00:27:26 +0100138 conn->sec_operation = talloc_zero(tall_authciphop_ctx,
139 struct gsm_security_operation);
140}
141
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800142static int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq,
143 gsm_cbfn *cb, void *cb_data)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100144{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800145 struct gsm_network *net = conn->bts->network;
146 struct gsm_subscriber *subscr = conn->subscr;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100147 struct gsm_security_operation *op;
148 struct gsm_auth_tuple atuple;
149 int status = -1, rc;
150
151 /* Check if we _can_ enable encryption. Cases where we can't:
152 * - Encryption disabled in config
153 * - Channel already secured (nothing to do)
154 * - Subscriber equipment doesn't support configured encryption
155 */
156 if (!net->a5_encryption) {
157 status = GSM_SECURITY_NOAVAIL;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800158 } else if (conn->lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
Sylvain Munaut30a15382009-12-24 00:27:26 +0100159 DEBUGP(DMM, "Requesting to secure an already secure channel");
160 status = GSM_SECURITY_SUCCEEDED;
161 } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2,
162 net->a5_encryption)) {
163 DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption");
164 status = GSM_SECURITY_NOAVAIL;
165 }
166
167 /* If not done yet, try to get info for this user */
168 if (status < 0) {
169 rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq);
170 if (rc <= 0)
171 status = GSM_SECURITY_NOAVAIL;
172 }
173
174 /* Are we done yet ? */
175 if (status >= 0)
176 return cb ?
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800177 cb(GSM_HOOK_RR_SECURITY, status, NULL, conn, cb_data) :
Sylvain Munaut30a15382009-12-24 00:27:26 +0100178 0;
179
180 /* Start an operation (can't have more than one pending !!!) */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800181 if (conn->sec_operation)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100182 return -EBUSY;
183
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800184 allocate_security_operation(conn);
185 op = conn->sec_operation;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100186 op->cb = cb;
187 op->cb_data = cb_data;
188 memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple));
189
190 /* FIXME: Should start a timer for completion ... */
191
192 /* Then do whatever is needed ... */
193 if (rc == 1) {
194 /* Start authentication */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800195 return gsm48_tx_mm_auth_req(conn, op->atuple.rand, op->atuple.key_seq);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100196 } else if (rc == 2) {
197 /* Start ciphering directly */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800198 conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
199 conn->lchan->encr.key_len = 8;
200 memcpy(conn->lchan->encr.key, op->atuple.kc, 8);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100201
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800202 return gsm48_send_rr_ciph_mode(conn->lchan, 0);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100203 }
204
205 return -EINVAL; /* not reached */
206}
207
Holger Freyther73487a22008-12-31 18:53:57 +0000208static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
209 struct gsm_subscriber *subscriber)
Holger Freyther89824fc2008-12-30 16:18:18 +0000210{
211 if (!subscriber)
212 return 0;
213
Holger Freyther73487a22008-12-31 18:53:57 +0000214 /*
215 * Do not send accept yet as more information should arrive. Some
216 * phones will not send us the information and we will have to check
217 * what we want to do with that.
218 */
219 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
220 return 0;
221
Jan Luebbe06513f22009-08-12 12:48:00 +0200222 switch (subscriber->net->auth_policy) {
223 case GSM_AUTH_POLICY_CLOSED:
224 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200225 case GSM_AUTH_POLICY_TOKEN:
Harald Welte (local)ee9afe32009-08-13 20:44:23 +0200226 if (subscriber->authorized)
227 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200228 return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
Jan Luebbe06513f22009-08-12 12:48:00 +0200229 case GSM_AUTH_POLICY_ACCEPT_ALL:
Holger Freyther89824fc2008-12-30 16:18:18 +0000230 return 1;
Jan Luebbe06513f22009-08-12 12:48:00 +0200231 default:
232 return 0;
233 }
Holger Freyther89824fc2008-12-30 16:18:18 +0000234}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000235
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100236static void release_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000237{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100238 if (!conn->loc_operation)
Holger Freyther73487a22008-12-31 18:53:57 +0000239 return;
240
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800241 /* No need to keep the connection up */
242 release_anchor(conn);
243
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100244 bsc_del_timer(&conn->loc_operation->updating_timer);
245 talloc_free(conn->loc_operation);
246 conn->loc_operation = 0;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800247 msc_release_connection(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000248}
249
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100250static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000251{
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800252 if (conn->loc_operation)
253 LOGP(DMM, LOGL_ERROR, "Connection already had operation.\n");
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100254 release_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000255
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100256 conn->loc_operation = talloc_zero(tall_locop_ctx,
Harald Welte470ec292009-06-26 20:25:23 +0200257 struct gsm_loc_updating_operation);
Holger Freyther73487a22008-12-31 18:53:57 +0000258}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000259
Sylvain Munaut267fba02009-12-24 00:28:01 +0100260static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event,
261 struct msgb *msg, void *data, void *param)
262{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800263 struct gsm_subscriber_connection *conn = data;
Sylvain Munaut267fba02009-12-24 00:28:01 +0100264 int rc = 0;
265
266 switch (event) {
267 case GSM_SECURITY_AUTH_FAILED:
268 release_loc_updating_req(conn);
269 break;
270
271 case GSM_SECURITY_NOAVAIL:
272 case GSM_SECURITY_SUCCEEDED:
273 /* We're all good */
274 db_subscriber_alloc_tmsi(conn->subscr);
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800275 rc = gsm0408_loc_upd_acc(conn, conn->subscr->tmsi);
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800276 if (conn->bts->network->send_mm_info) {
Sylvain Munaut267fba02009-12-24 00:28:01 +0100277 /* send MM INFO with network name */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800278 rc = gsm48_tx_mm_info(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100279 }
280
281 /* call subscr_update after putting the loc_upd_acc
282 * in the transmit queue, since S_SUBSCR_ATTACHED might
283 * trigger further action like SMS delivery */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800284 subscr_update(conn->subscr, conn->bts,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100285 GSM_SUBSCRIBER_UPDATE_ATTACHED);
286
287 /* try to close channel ASAP */
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800288 release_loc_updating_req(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100289 break;
290
291 default:
292 rc = -EINVAL;
293 };
294
295 return rc;
296}
297
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100298static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg)
Holger Freytherd51524f2009-06-09 08:27:07 +0000299{
Sylvain Munaut267fba02009-12-24 00:28:01 +0100300 if (authorize_subscriber(conn->loc_operation, conn->subscr))
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800301 return gsm48_secure_channel(conn,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100302 conn->loc_operation->key_seq,
303 _gsm0408_authorize_sec_cb, NULL);
Holger Freytherd51524f2009-06-09 08:27:07 +0000304 return 0;
305}
306
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +0800307void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
Holger Freyther7c19f742009-06-06 13:54:35 +0000308{
Harald Welte4bfdfe72009-06-10 23:11:52 +0800309 struct gsm_trans *trans, *temp;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800310
311 /* avoid someone issuing a clear */
312 conn->in_release = 1;
313
Holger Freyther7c19f742009-06-06 13:54:35 +0000314 /*
315 * Cancel any outstanding location updating request
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800316 * operation taking place on the subscriber connection.
Holger Freyther7c19f742009-06-06 13:54:35 +0000317 */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800318 release_loc_updating_req(conn);
319 release_security_operation(conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800320 release_anchor(conn);
Holger Freyther7c19f742009-06-06 13:54:35 +0000321
Harald Welte4bfdfe72009-06-10 23:11:52 +0800322 /* Free all transactions that are associated with the released lchan */
Harald Weltedcaf5652009-07-23 18:56:43 +0200323 /* FIXME: this is not neccessarily the right thing to do, we should
324 * only set trans->lchan to NULL and wait for another lchan to be
325 * established to the same MM entity (phone/subscriber) */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800326 llist_for_each_entry_safe(trans, temp, &conn->bts->network->trans_list, entry) {
327 if (trans->conn == conn)
Harald Weltedcaf5652009-07-23 18:56:43 +0200328 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800329 }
Holger Hans Peter Freytheraaa40b82010-09-16 20:48:15 +0800330
331 subscr_con_free(conn);
Holger Freyther7c19f742009-06-06 13:54:35 +0000332}
333
Holger Freyther429e7762008-12-30 13:28:30 +0000334/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800335int gsm0408_loc_upd_rej(struct gsm_subscriber_connection *conn, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000336{
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800337 struct gsm_bts *bts = conn->bts;
Holger Hans Peter Freyther230a4d82010-06-15 19:40:05 +0800338 struct msgb *msg;
339
340 counter_inc(bts->network->stats.loc_upd_resp.reject);
341
342 msg = gsm48_create_loc_upd_rej(cause);
343 if (!msg) {
344 LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n");
345 return -1;
346 }
Harald Welte52b1f982008-12-23 20:25:15 +0000347
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800348 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000349
Harald Welte (local)198d5ad2009-12-26 22:15:28 +0100350 LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT "
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100351 "LAC=%u BTS=%u\n", conn->subscr ?
352 subscr_name(conn->subscr) : "unknown",
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800353 bts->location_area_code, bts->nr);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100354
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800355 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000356}
357
358/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800359int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000360{
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800361 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000362 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000363 struct gsm48_hdr *gh;
364 struct gsm48_loc_area_id *lai;
365 u_int8_t *mid;
366
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800367 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000368
369 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
370 gh->proto_discr = GSM48_PDISC_MM;
371 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
372
373 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Harald Welteafedeab2010-03-04 10:55:40 +0100374 gsm48_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000375 bts->network->network_code, bts->location_area_code);
376
Holger Hans Peter Freyther1494a762009-08-01 07:26:59 +0200377 mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200378 gsm48_generate_mid_from_tmsi(mid, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000379
380 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
381
Harald Welteffa55a42009-12-22 19:07:32 +0100382 counter_inc(bts->network->stats.loc_upd_resp.accept);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100383
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800384 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000385}
386
Harald Weltebf5e8df2009-02-03 12:59:45 +0000387/* Transmit Chapter 9.2.10 Identity Request */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800388static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, u_int8_t id_type)
Harald Welte231ad4f2008-12-27 11:15:38 +0000389{
390 struct msgb *msg = gsm48_msgb_alloc();
391 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000392
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800393 msg->lchan = conn->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000394
395 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
396 gh->proto_discr = GSM48_PDISC_MM;
397 gh->msg_type = GSM48_MT_MM_ID_REQ;
398 gh->data[0] = id_type;
399
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800400 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte231ad4f2008-12-27 11:15:38 +0000401}
402
Harald Welte231ad4f2008-12-27 11:15:38 +0000403
Harald Weltebf5e8df2009-02-03 12:59:45 +0000404/* Parse Chapter 9.2.11 Identity Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800405static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte231ad4f2008-12-27 11:15:38 +0000406{
407 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000408 struct gsm_lchan *lchan = msg->lchan;
Harald Welte9176bd42009-07-23 18:46:00 +0200409 struct gsm_bts *bts = lchan->ts->trx->bts;
410 struct gsm_network *net = bts->network;
Harald Welte231ad4f2008-12-27 11:15:38 +0000411 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200412 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000413
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200414 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000415 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000416 mi_type, mi_string);
417
Harald Welte7659de12009-12-13 12:39:18 +0100418 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data);
419
Harald Welte75a983f2008-12-27 21:34:06 +0000420 switch (mi_type) {
421 case GSM_MI_TYPE_IMSI:
Jan Luebbe370b41d2009-08-12 10:19:34 +0200422 /* look up subscriber based on IMSI, create if not found */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100423 if (!conn->subscr) {
424 conn->subscr = subscr_get_by_imsi(net, mi_string);
425 if (!conn->subscr)
426 conn->subscr = db_create_subscriber(net, mi_string);
Jan Luebbeb0dfc312009-08-12 10:12:52 +0200427 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100428 if (conn->loc_operation)
429 conn->loc_operation->waiting_for_imsi = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000430 break;
431 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000432 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000433 /* update subscribe <-> IMEI mapping */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100434 if (conn->subscr) {
435 db_subscriber_assoc_imei(conn->subscr, mi_string);
436 db_sync_equipment(&conn->subscr->equipment);
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200437 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100438 if (conn->loc_operation)
439 conn->loc_operation->waiting_for_imei = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000440 break;
441 }
Holger Freyther73487a22008-12-31 18:53:57 +0000442
443 /* Check if we can let the mobile station enter */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100444 return gsm0408_authorize(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000445}
446
Harald Welte255539c2008-12-28 02:26:27 +0000447
448static void loc_upd_rej_cb(void *data)
449{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100450 struct gsm_subscriber_connection *conn = data;
451 struct gsm_lchan *lchan = conn->lchan;
Harald Welte1085c092009-11-18 20:33:19 +0100452 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte255539c2008-12-28 02:26:27 +0000453
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800454 gsm0408_loc_upd_rej(conn, bts->network->reject_cause);
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800455 release_loc_updating_req(conn);
Harald Welte255539c2008-12-28 02:26:27 +0000456}
457
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100458static void schedule_reject(struct gsm_subscriber_connection *conn)
Holger Freytherb7193e42008-12-29 17:44:08 +0000459{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100460 conn->loc_operation->updating_timer.cb = loc_upd_rej_cb;
461 conn->loc_operation->updating_timer.data = conn;
462 bsc_schedule_timer(&conn->loc_operation->updating_timer, 5, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000463}
464
Harald Welte2a139372009-02-22 21:14:55 +0000465static const char *lupd_name(u_int8_t type)
466{
467 switch (type) {
468 case GSM48_LUPD_NORMAL:
469 return "NORMAL";
470 case GSM48_LUPD_PERIODIC:
471 return "PEROIDOC";
472 case GSM48_LUPD_IMSI_ATT:
473 return "IMSI ATTACH";
474 default:
475 return "UNKNOWN";
476 }
477}
478
Harald Weltebf5e8df2009-02-03 12:59:45 +0000479/* Chapter 9.2.15: Receive Location Updating Request */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800480static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000481{
Harald Welte8470bf22008-12-25 23:28:35 +0000482 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000483 struct gsm48_loc_upd_req *lu;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800484 struct gsm_subscriber *subscr = NULL;
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800485 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000486 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200487 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000488 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000489
Harald Welte8470bf22008-12-25 23:28:35 +0000490 lu = (struct gsm48_loc_upd_req *) gh->data;
491
492 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000493
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200494 gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
Harald Weltefc977a82008-12-27 10:19:37 +0000495
Harald Weltea0368542009-06-27 02:58:43 +0200496 DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
Harald Welte2a139372009-02-22 21:14:55 +0000497 lupd_name(lu->type));
Holger Freyther73487a22008-12-31 18:53:57 +0000498
Harald Welte7659de12009-12-13 12:39:18 +0100499 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len);
500
Harald Welte24ff6ee2009-12-22 00:41:05 +0100501 switch (lu->type) {
502 case GSM48_LUPD_NORMAL:
Harald Welteffa55a42009-12-22 19:07:32 +0100503 counter_inc(bts->network->stats.loc_upd_type.normal);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100504 break;
505 case GSM48_LUPD_IMSI_ATT:
Harald Welteffa55a42009-12-22 19:07:32 +0100506 counter_inc(bts->network->stats.loc_upd_type.attach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100507 break;
508 case GSM48_LUPD_PERIODIC:
Harald Welteffa55a42009-12-22 19:07:32 +0100509 counter_inc(bts->network->stats.loc_upd_type.periodic);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100510 break;
511 }
512
Holger Freythereaf04692009-06-06 13:54:44 +0000513 /*
514 * Pseudo Spoof detection: Just drop a second/concurrent
515 * location updating request.
516 */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100517 if (conn->loc_operation) {
Harald Weltea0368542009-06-27 02:58:43 +0200518 DEBUGPC(DMM, "ignoring request due an existing one: %p.\n",
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100519 conn->loc_operation);
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800520 gsm0408_loc_upd_rej(conn, GSM48_REJECT_PROTOCOL_ERROR);
Holger Freythereaf04692009-06-06 13:54:44 +0000521 return 0;
522 }
523
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800524 allocate_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000525
Sylvain Munaut2030a2a2010-06-10 13:36:59 +0200526 conn->loc_operation->key_seq = lu->key_seq;
527
Harald Welte52b1f982008-12-23 20:25:15 +0000528 switch (mi_type) {
529 case GSM_MI_TYPE_IMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200530 DEBUGPC(DMM, "\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000531 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800532 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100533 conn->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000534
Jan Luebbe370b41d2009-08-12 10:19:34 +0200535 /* look up subscriber based on IMSI, create if not found */
536 subscr = subscr_get_by_imsi(bts->network, mi_string);
537 if (!subscr) {
538 subscr = db_create_subscriber(bts->network, mi_string);
539 }
Harald Welte4b634542008-12-27 01:55:51 +0000540 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000541 case GSM_MI_TYPE_TMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200542 DEBUGPC(DMM, "\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000543 /* look up the subscriber based on TMSI, request IMSI if it fails */
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200544 subscr = subscr_get_by_tmsi(bts->network,
545 tmsi_from_string(mi_string));
Harald Welte52b1f982008-12-23 20:25:15 +0000546 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000547 /* send IDENTITY REQUEST message to get IMSI */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800548 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMSI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100549 conn->loc_operation->waiting_for_imsi = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000550 }
Harald Weltef5f512c2010-06-07 17:56:32 +0200551 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800552 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Harald Weltef5f512c2010-06-07 17:56:32 +0200553 conn->loc_operation->waiting_for_imei = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000554 break;
555 case GSM_MI_TYPE_IMEI:
556 case GSM_MI_TYPE_IMEISV:
557 /* no sim card... FIXME: what to do ? */
Harald Weltea0368542009-06-27 02:58:43 +0200558 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000559 break;
560 default:
Harald Weltea0368542009-06-27 02:58:43 +0200561 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000562 break;
563 }
564
Harald Welte24516ea2009-07-04 10:18:00 +0200565 /* schedule the reject timer */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100566 schedule_reject(conn);
Harald Welte24516ea2009-07-04 10:18:00 +0200567
Harald Welte4bfdfe72009-06-10 23:11:52 +0800568 if (!subscr) {
Harald Weltea0368542009-06-27 02:58:43 +0200569 DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte4bfdfe72009-06-10 23:11:52 +0800570 /* FIXME: request id? close channel? */
571 return -EINVAL;
572 }
573
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100574 conn->subscr = subscr;
575 conn->subscr->equipment.classmark1 = lu->classmark1;
Harald Welte255539c2008-12-28 02:26:27 +0000576
Harald Welte24516ea2009-07-04 10:18:00 +0200577 /* check if we can let the subscriber into our network immediately
578 * or if we need to wait for identity responses. */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100579 return gsm0408_authorize(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000580}
581
Harald Welte4bfdfe72009-06-10 23:11:52 +0800582#if 0
583static u_int8_t to_bcd8(u_int8_t val)
584{
585 return ((val / 10) << 4) | (val % 10);
586}
587#endif
588
Harald Weltedb253af2008-12-30 17:56:55 +0000589/* Section 9.2.15a */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800590int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
Harald Weltedb253af2008-12-30 17:56:55 +0000591{
592 struct msgb *msg = gsm48_msgb_alloc();
593 struct gsm48_hdr *gh;
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800594 struct gsm_network *net = conn->bts->network;
Harald Weltedb253af2008-12-30 17:56:55 +0000595 u_int8_t *ptr8;
Daniel Willmanneea93372009-08-13 03:42:07 +0200596 int name_len, name_pad;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800597#if 0
598 time_t cur_t;
599 struct tm* cur_time;
600 int tz15min;
601#endif
Harald Weltedb253af2008-12-30 17:56:55 +0000602
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800603 msg->lchan = conn->lchan;
Harald Weltedb253af2008-12-30 17:56:55 +0000604
605 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
606 gh->proto_discr = GSM48_PDISC_MM;
607 gh->msg_type = GSM48_MT_MM_INFO;
608
609 if (net->name_long) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200610#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000611 name_len = strlen(net->name_long);
612 /* 10.5.3.5a */
613 ptr8 = msgb_put(msg, 3);
614 ptr8[0] = GSM48_IE_NAME_LONG;
615 ptr8[1] = name_len*2 +1;
616 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
617
618 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
619 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000620 ptr16[i] = htons(net->name_long[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000621
622 /* FIXME: Use Cell Broadcast, not UCS-2, since
623 * UCS-2 is only supported by later revisions of the spec */
Daniel Willmanneea93372009-08-13 03:42:07 +0200624#endif
625 name_len = (strlen(net->name_long)*7)/8;
626 name_pad = (8 - strlen(net->name_long)*7)%8;
627 if (name_pad > 0)
628 name_len++;
629 /* 10.5.3.5a */
630 ptr8 = msgb_put(msg, 3);
631 ptr8[0] = GSM48_IE_NAME_LONG;
632 ptr8[1] = name_len +1;
633 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
634
635 ptr8 = msgb_put(msg, name_len);
636 gsm_7bit_encode(ptr8, net->name_long);
637
Harald Weltedb253af2008-12-30 17:56:55 +0000638 }
639
640 if (net->name_short) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200641#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000642 name_len = strlen(net->name_short);
643 /* 10.5.3.5a */
644 ptr8 = (u_int8_t *) msgb_put(msg, 3);
Harald Welte7543eb72009-07-19 17:51:36 +0200645 ptr8[0] = GSM48_IE_NAME_SHORT;
Harald Weltedb253af2008-12-30 17:56:55 +0000646 ptr8[1] = name_len*2 + 1;
647 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
648
Harald Weltee872cb12009-01-01 00:33:37 +0000649 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
Harald Weltedb253af2008-12-30 17:56:55 +0000650 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000651 ptr16[i] = htons(net->name_short[i]);
Daniel Willmanneea93372009-08-13 03:42:07 +0200652#endif
653 name_len = (strlen(net->name_short)*7)/8;
654 name_pad = (8 - strlen(net->name_short)*7)%8;
655 if (name_pad > 0)
656 name_len++;
657 /* 10.5.3.5a */
658 ptr8 = (u_int8_t *) msgb_put(msg, 3);
659 ptr8[0] = GSM48_IE_NAME_SHORT;
660 ptr8[1] = name_len +1;
661 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
662
663 ptr8 = msgb_put(msg, name_len);
664 gsm_7bit_encode(ptr8, net->name_short);
665
Harald Weltedb253af2008-12-30 17:56:55 +0000666 }
667
668#if 0
669 /* Section 10.5.3.9 */
670 cur_t = time(NULL);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800671 cur_time = gmtime(&cur_t);
Harald Weltedb253af2008-12-30 17:56:55 +0000672 ptr8 = msgb_put(msg, 8);
673 ptr8[0] = GSM48_IE_NET_TIME_TZ;
674 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
675 ptr8[2] = to_bcd8(cur_time->tm_mon);
676 ptr8[3] = to_bcd8(cur_time->tm_mday);
677 ptr8[4] = to_bcd8(cur_time->tm_hour);
678 ptr8[5] = to_bcd8(cur_time->tm_min);
679 ptr8[6] = to_bcd8(cur_time->tm_sec);
680 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
681 tz15min = (cur_time->tm_gmtoff)/(60*15);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800682 ptr8[7] = to_bcd8(tz15min);
Harald Weltedb253af2008-12-30 17:56:55 +0000683 if (tz15min < 0)
Harald Welte4bfdfe72009-06-10 23:11:52 +0800684 ptr8[7] |= 0x80;
Harald Weltedb253af2008-12-30 17:56:55 +0000685#endif
686
Daniel Willmanneea93372009-08-13 03:42:07 +0200687 DEBUGP(DMM, "-> MM INFO\n");
688
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800689 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Weltedb253af2008-12-30 17:56:55 +0000690}
691
Harald Welte7984d5c2009-08-12 22:56:50 +0200692/* Section 9.2.2 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800693int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, u_int8_t *rand, int key_seq)
Harald Welte7984d5c2009-08-12 22:56:50 +0200694{
695 struct msgb *msg = gsm48_msgb_alloc();
696 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Sylvain Munaut849f5542009-09-27 11:10:17 +0200697 struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar));
Harald Welte7984d5c2009-08-12 22:56:50 +0200698
Sylvain Munaut8608e7c2009-12-24 00:24:29 +0100699 DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", hexdump(rand, 16));
Harald Welte7984d5c2009-08-12 22:56:50 +0200700
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800701 msg->lchan = conn->lchan;
Harald Welte7984d5c2009-08-12 22:56:50 +0200702 gh->proto_discr = GSM48_PDISC_MM;
703 gh->msg_type = GSM48_MT_MM_AUTH_REQ;
704
Sylvain Munautbd55a6d2009-12-24 00:23:46 +0100705 ar->key_seq = key_seq;
Sylvain Munaut849f5542009-09-27 11:10:17 +0200706
Harald Welte7984d5c2009-08-12 22:56:50 +0200707 /* 16 bytes RAND parameters */
Harald Welte7984d5c2009-08-12 22:56:50 +0200708 if (rand)
Sylvain Munaut849f5542009-09-27 11:10:17 +0200709 memcpy(ar->rand, rand, 16);
Harald Welte7984d5c2009-08-12 22:56:50 +0200710
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800711 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte7984d5c2009-08-12 22:56:50 +0200712}
713
714/* Section 9.2.1 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800715int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn)
Harald Welte7984d5c2009-08-12 22:56:50 +0200716{
717 DEBUGP(DMM, "-> AUTH REJECT\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800718 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ);
Harald Welte7984d5c2009-08-12 22:56:50 +0200719}
720
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800721static int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
Harald Welte4b634542008-12-27 01:55:51 +0000722{
Harald Welte4b634542008-12-27 01:55:51 +0000723 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800724 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000725}
Harald Welteba4cf162009-01-10 01:49:35 +0000726
727/* 9.2.6 CM service reject */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100728static int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000729 enum gsm48_reject_value value)
730{
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800731 struct msgb *msg;
Harald Welteba4cf162009-01-10 01:49:35 +0000732
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800733 msg = gsm48_create_mm_serv_rej(value);
734 if (!msg) {
735 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
736 return -1;
737 }
Harald Welteba4cf162009-01-10 01:49:35 +0000738
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800739 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100740 msg->lchan = conn->lchan;
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800741 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welteba4cf162009-01-10 01:49:35 +0000742}
743
Sylvain Munautba87f452009-12-24 00:28:46 +0100744static int _gsm48_rx_mm_serv_req_sec_cb(
745 unsigned int hooknum, unsigned int event,
746 struct msgb *msg, void *data, void *param)
747{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800748 struct gsm_subscriber_connection *conn = data;
Sylvain Munautba87f452009-12-24 00:28:46 +0100749 int rc = 0;
750
751 switch (event) {
752 case GSM_SECURITY_AUTH_FAILED:
753 /* Nothing to do */
754 break;
755
756 case GSM_SECURITY_NOAVAIL:
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800757 rc = gsm48_tx_mm_serv_ack(conn);
Sylvain Munautba87f452009-12-24 00:28:46 +0100758 break;
759
760 case GSM_SECURITY_SUCCEEDED:
761 /* nothing to do. CIPHER MODE COMMAND is
762 * implicit CM SERV ACK */
763 break;
764
765 default:
766 rc = -EINVAL;
767 };
768
769 return rc;
770}
771
Harald Welte4ed0e922009-01-10 03:17:30 +0000772/*
773 * Handle CM Service Requests
774 * a) Verify that the packet is long enough to contain the information
775 * we require otherwsie reject with INCORRECT_MESSAGE
776 * b) Try to parse the TMSI. If we do not have one reject
777 * c) Check that we know the subscriber with the TMSI otherwise reject
778 * with a HLR cause
779 * d) Set the subscriber on the gsm_lchan and accept
780 */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800781static int gsm48_rx_mm_serv_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4b634542008-12-27 01:55:51 +0000782{
Harald Welteba4cf162009-01-10 01:49:35 +0000783 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200784 char mi_string[GSM48_MI_SIZE];
Harald Welte4b634542008-12-27 01:55:51 +0000785
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800786 struct gsm_bts *bts = conn->bts;
Harald Welteba4cf162009-01-10 01:49:35 +0000787 struct gsm_subscriber *subscr;
788 struct gsm48_hdr *gh = msgb_l3(msg);
789 struct gsm48_service_request *req =
790 (struct gsm48_service_request *)gh->data;
Holger Hans Peter Freyther5d658062010-05-14 08:02:08 +0800791 /* unfortunately in Phase1 the classmark2 length is variable */
Harald Weltec9e02182009-05-01 19:07:53 +0000792 u_int8_t classmark2_len = gh->data[1];
793 u_int8_t *classmark2 = gh->data+2;
794 u_int8_t mi_len = *(classmark2 + classmark2_len);
795 u_int8_t *mi = (classmark2 + classmark2_len + 1);
Harald Welteba4cf162009-01-10 01:49:35 +0000796
Harald Weltec9e02182009-05-01 19:07:53 +0000797 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
Harald Welteba4cf162009-01-10 01:49:35 +0000798 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
Harald Weltec9e02182009-05-01 19:07:53 +0000799 DEBUGPC(DMM, "wrong sized message\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800800 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000801 GSM48_REJECT_INCORRECT_MESSAGE);
802 }
803
804 if (msg->data_len < req->mi_len + 6) {
Harald Weltec9e02182009-05-01 19:07:53 +0000805 DEBUGPC(DMM, "does not fit in packet\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800806 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000807 GSM48_REJECT_INCORRECT_MESSAGE);
808 }
809
Harald Weltec9e02182009-05-01 19:07:53 +0000810 mi_type = mi[0] & GSM_MI_TYPE_MASK;
Harald Welteba4cf162009-01-10 01:49:35 +0000811 if (mi_type != GSM_MI_TYPE_TMSI) {
Harald Weltec9e02182009-05-01 19:07:53 +0000812 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800813 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000814 GSM48_REJECT_INCORRECT_MESSAGE);
815 }
816
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200817 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Weltec9e02182009-05-01 19:07:53 +0000818 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
Harald Welte4ed0e922009-01-10 03:17:30 +0000819 req->cm_service_type, mi_type, mi_string);
Harald Weltebcae43f2008-12-27 21:45:37 +0000820
Harald Welte7659de12009-12-13 12:39:18 +0100821 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len));
822
Harald Welte3ac7f102009-08-10 10:12:45 +0200823 if (is_siemens_bts(bts))
824 send_siemens_mrpci(msg->lchan, classmark2-1);
825
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200826 subscr = subscr_get_by_tmsi(bts->network,
827 tmsi_from_string(mi_string));
Holger Freythereb443982009-06-04 13:58:42 +0000828
Harald Welte2a139372009-02-22 21:14:55 +0000829 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
Harald Welte4ed0e922009-01-10 03:17:30 +0000830 if (!subscr)
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800831 return gsm48_tx_mm_serv_rej(conn,
Harald Welte4ed0e922009-01-10 03:17:30 +0000832 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
833
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800834 if (!conn->subscr)
835 conn->subscr = subscr;
836 else if (conn->subscr == subscr)
Sylvain Munautea3f6742009-12-18 18:28:10 +0100837 subscr_put(subscr); /* lchan already has a ref, don't need another one */
838 else {
Harald Welte9bb7c702009-01-10 03:21:41 +0000839 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
840 subscr_put(subscr);
841 }
842
Harald Weltec2e302d2009-07-05 14:08:13 +0200843 subscr->equipment.classmark2_len = classmark2_len;
844 memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
845 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +0000846
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800847 return gsm48_secure_channel(conn, req->cipher_key_seq,
Sylvain Munautba87f452009-12-24 00:28:46 +0100848 _gsm48_rx_mm_serv_req_sec_cb, NULL);
Harald Welte4b634542008-12-27 01:55:51 +0000849}
850
Harald Welte2a139372009-02-22 21:14:55 +0000851static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
852{
Harald Welte9176bd42009-07-23 18:46:00 +0200853 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte2a139372009-02-22 21:14:55 +0000854 struct gsm48_hdr *gh = msgb_l3(msg);
855 struct gsm48_imsi_detach_ind *idi =
856 (struct gsm48_imsi_detach_ind *) gh->data;
857 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200858 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +0800859 struct gsm_subscriber *subscr = NULL;
Harald Welte2a139372009-02-22 21:14:55 +0000860
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200861 gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
Harald Welte2a139372009-02-22 21:14:55 +0000862 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
863 mi_type, mi_string);
864
Harald Welteffa55a42009-12-22 19:07:32 +0100865 counter_inc(bts->network->stats.loc_upd_type.detach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100866
Harald Welte2a139372009-02-22 21:14:55 +0000867 switch (mi_type) {
868 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200869 subscr = subscr_get_by_tmsi(bts->network,
870 tmsi_from_string(mi_string));
Harald Welte2a139372009-02-22 21:14:55 +0000871 break;
872 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +0200873 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte2a139372009-02-22 21:14:55 +0000874 break;
875 case GSM_MI_TYPE_IMEI:
876 case GSM_MI_TYPE_IMEISV:
877 /* no sim card... FIXME: what to do ? */
Holger Freyther79f4ae62009-06-02 03:25:04 +0000878 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000879 break;
880 default:
Holger Freyther79f4ae62009-06-02 03:25:04 +0000881 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000882 break;
883 }
884
Holger Freyther4a49e772009-04-12 05:37:29 +0000885 if (subscr) {
886 subscr_update(subscr, msg->trx->bts,
887 GSM_SUBSCRIBER_UPDATE_DETACHED);
Harald Welte2e6d4682009-12-24 14:50:24 +0100888 DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr));
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200889
890 subscr->equipment.classmark1 = idi->classmark1;
891 db_sync_equipment(&subscr->equipment);
892
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000893 subscr_put(subscr);
Holger Freyther4a49e772009-04-12 05:37:29 +0000894 } else
Harald Welte2a139372009-02-22 21:14:55 +0000895 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
896
Harald Welte31981a02009-12-20 09:58:40 +0100897 /* FIXME: iterate over all transactions and release them,
898 * imagine an IMSI DETACH happening during an active call! */
899
Harald Welteb83d9382009-12-12 21:00:48 +0100900 /* subscriber is detached: should we release lchan? */
Harald Welte2a139372009-02-22 21:14:55 +0000901 return 0;
902}
903
Harald Welted2a7f5a2009-06-05 20:08:20 +0000904static int gsm48_rx_mm_status(struct msgb *msg)
905{
906 struct gsm48_hdr *gh = msgb_l3(msg);
907
908 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
909
910 return 0;
911}
912
Sylvain Munaut30a15382009-12-24 00:27:26 +0100913/* Chapter 9.2.3: Authentication Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800914static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100915{
916 struct gsm48_hdr *gh = msgb_l3(msg);
917 struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800918 struct gsm_network *net = conn->bts->network;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100919
Sylvain Munautc593cf12010-06-10 23:51:41 +0200920 DEBUGP(DMM, "MM AUTHENTICATION RESPONSE (sres = %s): ",
Sylvain Munaut30a15382009-12-24 00:27:26 +0100921 hexdump(ar->sres, 4));
922
923 /* Safety check */
924 if (!conn->sec_operation) {
925 DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n");
926 return -EIO;
927 }
928
929 /* Validate SRES */
930 if (memcmp(conn->sec_operation->atuple.sres, ar->sres,4)) {
931 gsm_cbfn *cb = conn->sec_operation->cb;
Sylvain Munautc593cf12010-06-10 23:51:41 +0200932
933 DEBUGPC(DMM, "Invalid (expected %s)\n",
934 hexdump(conn->sec_operation->atuple.sres, 4));
935
Sylvain Munaut30a15382009-12-24 00:27:26 +0100936 if (cb)
937 cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800938 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100939
940 release_security_operation(conn);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800941 return gsm48_tx_mm_auth_rej(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100942 }
943
Sylvain Munautc593cf12010-06-10 23:51:41 +0200944 DEBUGPC(DMM, "OK\n");
945
Sylvain Munaut30a15382009-12-24 00:27:26 +0100946 /* Start ciphering */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800947 conn->lchan->encr.alg_id = RSL_ENC_ALG_A5(net->a5_encryption);
948 conn->lchan->encr.key_len = 8;
949 memcpy(conn->lchan->encr.key, conn->sec_operation->atuple.kc, 8);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100950
951 return gsm48_send_rr_ciph_mode(msg->lchan, 0);
952}
953
Harald Weltebf5e8df2009-02-03 12:59:45 +0000954/* Receive a GSM 04.08 Mobility Management (MM) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800955static int gsm0408_rcv_mm(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000956{
957 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800958 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000959
960 switch (gh->msg_type & 0xbf) {
961 case GSM48_MT_MM_LOC_UPD_REQUEST:
Harald Weltea0368542009-06-27 02:58:43 +0200962 DEBUGP(DMM, "LOCATION UPDATING REQUEST: ");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800963 rc = mm_rx_loc_upd_req(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000964 break;
965 case GSM48_MT_MM_ID_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800966 rc = mm_rx_id_resp(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000967 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000968 case GSM48_MT_MM_CM_SERV_REQ:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800969 rc = gsm48_rx_mm_serv_req(conn, msg);
Harald Welte4b634542008-12-27 01:55:51 +0000970 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000971 case GSM48_MT_MM_STATUS:
Harald Welted2a7f5a2009-06-05 20:08:20 +0000972 rc = gsm48_rx_mm_status(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000973 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000974 case GSM48_MT_MM_TMSI_REALL_COMPL:
Harald Welte69b2af22009-01-06 19:47:00 +0000975 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800976 conn->subscr ?
977 subscr_name(conn->subscr) :
Harald Welte69b2af22009-01-06 19:47:00 +0000978 "unknown subscriber");
979 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000980 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte2a139372009-02-22 21:14:55 +0000981 rc = gsm48_rx_mm_imsi_detach_ind(msg);
982 break;
983 case GSM48_MT_MM_CM_REEST_REQ:
984 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
985 break;
986 case GSM48_MT_MM_AUTH_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800987 rc = gsm48_rx_mm_auth_resp(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000988 break;
989 default:
Harald Welte5d24ba12009-12-24 12:13:17 +0100990 LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n",
Harald Welte52b1f982008-12-23 20:25:15 +0000991 gh->msg_type);
992 break;
993 }
994
995 return rc;
996}
Harald Weltebf5e8df2009-02-03 12:59:45 +0000997
Harald Welte2d35ae62009-02-06 12:02:13 +0000998/* Receive a PAGING RESPONSE message from the MS */
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +0800999static int gsm48_rx_rr_pag_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte2d35ae62009-02-06 12:02:13 +00001000{
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001001 struct gsm_bts *bts = conn->bts;
Harald Welte2d35ae62009-02-06 12:02:13 +00001002 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +08001003 struct gsm48_pag_resp *resp;
Harald Welte61548982009-02-22 21:26:29 +00001004 u_int8_t *classmark2_lv = gh->data + 1;
Holger Hans Peter Freyther3ee5d3e2009-08-21 05:18:21 +02001005 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +02001006 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +08001007 struct gsm_subscriber *subscr = NULL;
Harald Welte2d35ae62009-02-06 12:02:13 +00001008 int rc = 0;
1009
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +08001010 resp = (struct gsm48_pag_resp *) &gh->data[0];
1011 gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
1012 mi_string, &mi_type);
Harald Welte2d35ae62009-02-06 12:02:13 +00001013 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
1014 mi_type, mi_string);
Harald Welte3ac7f102009-08-10 10:12:45 +02001015
Harald Weltefe18d8f2009-02-22 21:14:24 +00001016 switch (mi_type) {
1017 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +02001018 subscr = subscr_get_by_tmsi(bts->network,
1019 tmsi_from_string(mi_string));
Harald Weltefe18d8f2009-02-22 21:14:24 +00001020 break;
1021 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +02001022 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Weltefe18d8f2009-02-22 21:14:24 +00001023 break;
1024 }
Harald Welte2d35ae62009-02-06 12:02:13 +00001025
1026 if (!subscr) {
1027 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001028 /* FIXME: request id? close channel? */
Harald Welte2d35ae62009-02-06 12:02:13 +00001029 return -EINVAL;
1030 }
1031 DEBUGP(DRR, "<- Channel was requested by %s\n",
Harald Welte76042182009-08-08 16:03:15 +02001032 subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi);
Holger Freyther053e09d2009-02-14 22:51:06 +00001033
Harald Weltec2e302d2009-07-05 14:08:13 +02001034 subscr->equipment.classmark2_len = *classmark2_lv;
1035 memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
1036 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001037
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001038 rc = gsm48_handle_paging_resp(conn, msg, subscr);
Harald Welte2d35ae62009-02-06 12:02:13 +00001039 return rc;
1040}
1041
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001042static int gsm48_rx_rr_classmark(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Weltef7c43522009-06-09 20:24:21 +00001043{
1044 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001045 struct gsm_subscriber *subscr = conn->subscr;
Harald Weltef7c43522009-06-09 20:24:21 +00001046 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1047 u_int8_t cm2_len, cm3_len = 0;
1048 u_int8_t *cm2, *cm3 = NULL;
1049
1050 DEBUGP(DRR, "CLASSMARK CHANGE ");
1051
1052 /* classmark 2 */
1053 cm2_len = gh->data[0];
1054 cm2 = &gh->data[1];
1055 DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
1056
1057 if (payload_len > cm2_len + 1) {
1058 /* we must have a classmark3 */
1059 if (gh->data[cm2_len+1] != 0x20) {
1060 DEBUGPC(DRR, "ERR CM3 TAG\n");
1061 return -EINVAL;
1062 }
1063 if (cm2_len > 3) {
1064 DEBUGPC(DRR, "CM2 too long!\n");
1065 return -EINVAL;
1066 }
1067
1068 cm3_len = gh->data[cm2_len+2];
1069 cm3 = &gh->data[cm2_len+3];
1070 if (cm3_len > 14) {
1071 DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
1072 return -EINVAL;
1073 }
1074 DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
1075 }
1076 if (subscr) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001077 subscr->equipment.classmark2_len = cm2_len;
1078 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001079 if (cm3) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001080 subscr->equipment.classmark3_len = cm3_len;
1081 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001082 }
Harald Weltec2e302d2009-07-05 14:08:13 +02001083 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001084 }
1085
Harald Weltef7c43522009-06-09 20:24:21 +00001086 return 0;
1087}
1088
Harald Weltecf5b3592009-05-01 18:28:42 +00001089static int gsm48_rx_rr_status(struct msgb *msg)
1090{
1091 struct gsm48_hdr *gh = msgb_l3(msg);
1092
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001093 DEBUGP(DRR, "STATUS rr_cause = %s\n",
Harald Weltecf5b3592009-05-01 18:28:42 +00001094 rr_cause_name(gh->data[0]));
1095
1096 return 0;
1097}
1098
Harald Weltef7c43522009-06-09 20:24:21 +00001099static int gsm48_rx_rr_meas_rep(struct msgb *msg)
1100{
Harald Welted12b0fd2009-12-15 21:36:05 +01001101 struct gsm_meas_rep *meas_rep = lchan_next_meas_rep(msg->lchan);
Harald Weltef7c43522009-06-09 20:24:21 +00001102
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001103 /* This shouldn't actually end up here, as RSL treats
1104 * L3 Info of 08.58 MEASUREMENT REPORT different by calling
1105 * directly into gsm48_parse_meas_rep */
1106 DEBUGP(DMEAS, "DIRECT GSM48 MEASUREMENT REPORT ?!? ");
Harald Welted12b0fd2009-12-15 21:36:05 +01001107 gsm48_parse_meas_rep(meas_rep, msg);
Harald Weltef7c43522009-06-09 20:24:21 +00001108
1109 return 0;
1110}
1111
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001112static int gsm48_rx_rr_app_info(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001113{
1114 struct gsm48_hdr *gh = msgb_l3(msg);
1115 u_int8_t apdu_id_flags;
1116 u_int8_t apdu_len;
1117 u_int8_t *apdu_data;
1118
1119 apdu_id_flags = gh->data[0];
1120 apdu_len = gh->data[1];
1121 apdu_data = gh->data+2;
1122
1123 DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s",
1124 apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len));
1125
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001126 return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001127}
1128
Sylvain Munaut30a15382009-12-24 00:27:26 +01001129/* Chapter 9.1.10 Ciphering Mode Complete */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001130static int gsm48_rx_rr_ciph_m_compl(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +01001131{
Sylvain Munaut30a15382009-12-24 00:27:26 +01001132 gsm_cbfn *cb;
1133 int rc = 0;
1134
1135 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
1136
1137 /* Safety check */
1138 if (!conn->sec_operation) {
1139 DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n");
1140 return -EIO;
1141 }
1142
1143 /* FIXME: check for MI (if any) */
1144
1145 /* Call back whatever was in progress (if anything) ... */
1146 cb = conn->sec_operation->cb;
1147 if (cb) {
1148 rc = cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +08001149 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +01001150 }
1151
1152 /* Complete the operation */
1153 release_security_operation(conn);
1154
1155 return rc;
1156}
1157
Harald Welted011e8b2009-11-29 22:45:52 +01001158/* Chapter 9.1.16 Handover complete */
Harald Welte1e191c52009-12-14 17:51:15 +01001159static int gsm48_rx_rr_ho_compl(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001160{
1161 struct gsm48_hdr *gh = msgb_l3(msg);
1162
1163 DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n",
1164 rr_cause_name(gh->data[0]));
1165
1166 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, msg->lchan);
1167 /* FIXME: release old channel */
1168
1169 return 0;
1170}
1171
1172/* Chapter 9.1.17 Handover Failure */
Harald Welte1e191c52009-12-14 17:51:15 +01001173static int gsm48_rx_rr_ho_fail(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001174{
1175 struct gsm48_hdr *gh = msgb_l3(msg);
1176
1177 DEBUGP(DRR, "HANDOVER FAILED cause = %s\n",
1178 rr_cause_name(gh->data[0]));
1179
1180 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, msg->lchan);
1181 /* FIXME: release allocated new channel */
1182
1183 return 0;
1184}
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001185
Harald Weltebf5e8df2009-02-03 12:59:45 +00001186/* Receive a GSM 04.08 Radio Resource (RR) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001187static int gsm0408_rcv_rr(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001188{
1189 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001190 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001191
1192 switch (gh->msg_type) {
1193 case GSM48_MT_RR_CLSM_CHG:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001194 rc = gsm48_rx_rr_classmark(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001195 break;
Harald Weltefc977a82008-12-27 10:19:37 +00001196 case GSM48_MT_RR_GPRS_SUSP_REQ:
1197 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1198 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001199 case GSM48_MT_RR_PAG_RESP:
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001200 rc = gsm48_rx_rr_pag_resp(conn, msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001201 break;
Harald Welte7ccf7782009-02-17 01:43:01 +00001202 case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
Holger Hans Peter Freytherf520e642009-10-22 15:23:11 +02001203 rc = gsm48_rx_rr_modif_ack(msg);
Harald Welte7ccf7782009-02-17 01:43:01 +00001204 break;
Harald Weltecf5b3592009-05-01 18:28:42 +00001205 case GSM48_MT_RR_STATUS:
1206 rc = gsm48_rx_rr_status(msg);
1207 break;
Harald Weltef7c43522009-06-09 20:24:21 +00001208 case GSM48_MT_RR_MEAS_REP:
1209 rc = gsm48_rx_rr_meas_rep(msg);
1210 break;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001211 case GSM48_MT_RR_APP_INFO:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001212 rc = gsm48_rx_rr_app_info(conn, msg);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001213 break;
Harald Welte08d91a52009-08-30 15:37:11 +09001214 case GSM48_MT_RR_CIPH_M_COMPL:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001215 rc = gsm48_rx_rr_ciph_m_compl(conn, msg);
Harald Welte08d91a52009-08-30 15:37:11 +09001216 break;
Harald Welteccd5a882009-11-29 20:02:20 +01001217 case GSM48_MT_RR_HANDO_COMPL:
Harald Welted011e8b2009-11-29 22:45:52 +01001218 rc = gsm48_rx_rr_ho_compl(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001219 break;
1220 case GSM48_MT_RR_HANDO_FAIL:
Harald Welted011e8b2009-11-29 22:45:52 +01001221 rc = gsm48_rx_rr_ho_fail(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001222 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001223 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01001224 LOGP(DRR, LOGL_NOTICE, "Unimplemented "
1225 "GSM 04.08 RR msg type 0x%02x\n", gh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001226 break;
1227 }
1228
Harald Welte2d35ae62009-02-06 12:02:13 +00001229 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001230}
1231
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001232int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, u_int8_t apdu_id,
Holger Hans Peter Freyther8b77a342009-10-22 15:42:19 +02001233 u_int8_t apdu_len, const u_int8_t *apdu)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001234{
1235 struct msgb *msg = gsm48_msgb_alloc();
1236 struct gsm48_hdr *gh;
1237
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001238 msg->lchan = conn->lchan;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001239
1240 DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n",
1241 apdu_id, apdu_len);
1242
1243 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len);
1244 gh->proto_discr = GSM48_PDISC_RR;
1245 gh->msg_type = GSM48_MT_RR_APP_INFO;
1246 gh->data[0] = apdu_id;
1247 gh->data[1] = apdu_len;
1248 memcpy(gh->data+2, apdu, apdu_len);
1249
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001250 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001251}
1252
Harald Welte4bc90a12008-12-27 16:32:52 +00001253/* Call Control */
1254
Harald Welte7584aea2009-02-11 11:44:12 +00001255/* The entire call control code is written in accordance with Figure 7.10c
1256 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1257 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1258 * it for voice */
1259
Harald Welte4bfdfe72009-06-10 23:11:52 +08001260static void new_cc_state(struct gsm_trans *trans, int state)
1261{
1262 if (state > 31 || state < 0)
1263 return;
1264
1265 DEBUGP(DCC, "new state %s -> %s\n",
Harald Weltee95daf12010-03-25 12:13:02 +08001266 gsm48_cc_state_name(trans->cc.state),
1267 gsm48_cc_state_name(state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001268
Harald Weltedcaf5652009-07-23 18:56:43 +02001269 trans->cc.state = state;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001270}
1271
1272static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
Harald Welte4bc90a12008-12-27 16:32:52 +00001273{
1274 struct msgb *msg = gsm48_msgb_alloc();
1275 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1276 u_int8_t *cause, *call_state;
1277
Harald Welte4bc90a12008-12-27 16:32:52 +00001278 gh->msg_type = GSM48_MT_CC_STATUS;
1279
1280 cause = msgb_put(msg, 3);
1281 cause[0] = 2;
1282 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1283 cause[2] = 0x80 | 30; /* response to status inquiry */
1284
1285 call_state = msgb_put(msg, 1);
1286 call_state[0] = 0xc0 | 0x00;
1287
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001288 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bc90a12008-12-27 16:32:52 +00001289}
1290
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001291static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte6f4b7532008-12-29 00:39:37 +00001292 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +00001293{
1294 struct msgb *msg = gsm48_msgb_alloc();
1295 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1296
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001297 msg->lchan = conn->lchan;
Harald Welte4bc90a12008-12-27 16:32:52 +00001298
Harald Welte6f4b7532008-12-29 00:39:37 +00001299 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +00001300 gh->msg_type = msg_type;
1301
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001302 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte4bc90a12008-12-27 16:32:52 +00001303}
1304
Harald Welte4bfdfe72009-06-10 23:11:52 +08001305static void gsm48_stop_cc_timer(struct gsm_trans *trans)
1306{
Harald Weltedcaf5652009-07-23 18:56:43 +02001307 if (bsc_timer_pending(&trans->cc.timer)) {
1308 DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent);
1309 bsc_del_timer(&trans->cc.timer);
1310 trans->cc.Tcurrent = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001311 }
1312}
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001313
Harald Welte4bfdfe72009-06-10 23:11:52 +08001314static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
1315 int msg_type, struct gsm_mncc *mncc)
1316{
1317 struct msgb *msg;
1318
1319 if (trans)
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001320 if (trans->conn)
Harald Welte6f5aee02009-07-23 21:21:14 +02001321 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08001322 "Sending '%s' to MNCC.\n",
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001323 trans->conn->lchan->ts->trx->bts->nr,
1324 trans->conn->lchan->ts->trx->nr,
1325 trans->conn->lchan->ts->nr, trans->transaction_id,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001326 (trans->subscr)?(trans->subscr->extension):"-",
1327 get_mncc_name(msg_type));
1328 else
1329 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
1330 "Sending '%s' to MNCC.\n",
1331 (trans->subscr)?(trans->subscr->extension):"-",
1332 get_mncc_name(msg_type));
1333 else
1334 DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) "
1335 "Sending '%s' to MNCC.\n", get_mncc_name(msg_type));
1336
1337 mncc->msg_type = msg_type;
1338
Harald Welte966636f2009-06-26 19:39:35 +02001339 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
Harald Welte4bfdfe72009-06-10 23:11:52 +08001340 if (!msg)
1341 return -ENOMEM;
1342 memcpy(msg->data, mncc, sizeof(struct gsm_mncc));
1343 msgb_enqueue(&net->upqueue, msg);
1344
1345 return 0;
1346}
1347
1348int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
1349 u_int32_t callref, int location, int value)
1350{
1351 struct gsm_mncc rel;
1352
Harald Welte92f70c52009-06-12 01:54:08 +08001353 memset(&rel, 0, sizeof(rel));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001354 rel.callref = callref;
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001355 mncc_set_cause(&rel, location, value);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001356 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1357}
1358
Harald Weltedcaf5652009-07-23 18:56:43 +02001359/* Call Control Specific transaction release.
1360 * gets called by trans_free, DO NOT CALL YOURSELF! */
1361void _gsm48_cc_trans_free(struct gsm_trans *trans)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001362{
Harald Welte4bfdfe72009-06-10 23:11:52 +08001363 gsm48_stop_cc_timer(trans);
1364
1365 /* send release to L4, if callref still exists */
1366 if (trans->callref) {
1367 /* Ressource unavailable */
Harald Welte596fed42009-07-23 19:06:52 +02001368 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001369 GSM48_CAUSE_LOC_PRN_S_LU,
1370 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001371 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001372 if (trans->cc.state != GSM_CSTATE_NULL)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001373 new_cc_state(trans, GSM_CSTATE_NULL);
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001374 if (trans->conn)
1375 trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001376}
1377
1378static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001379
Harald Welte09e38af2009-02-16 22:52:23 +00001380/* call-back from paging the B-end of the connection */
1381static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001382 struct msgb *msg, void *_conn, void *param)
Harald Welte09e38af2009-02-16 22:52:23 +00001383{
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001384 struct gsm_subscriber_connection *conn = _conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001385 struct gsm_subscriber *subscr = param;
1386 struct gsm_trans *transt, *tmp;
1387 struct gsm_network *net;
Harald Weltec05677b2009-06-26 20:17:06 +02001388
Harald Welte09e38af2009-02-16 22:52:23 +00001389 if (hooknum != GSM_HOOK_RR_PAGING)
1390 return -EINVAL;
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001391
Harald Welte4bfdfe72009-06-10 23:11:52 +08001392 if (!subscr)
1393 return -EINVAL;
1394 net = subscr->net;
1395 if (!net) {
1396 DEBUGP(DCC, "Error Network not set!\n");
1397 return -EINVAL;
Harald Welte5a065df2009-02-22 21:13:18 +00001398 }
Harald Welte7584aea2009-02-11 11:44:12 +00001399
Harald Welte4bfdfe72009-06-10 23:11:52 +08001400 /* check all tranactions (without lchan) for subscriber */
1401 llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001402 if (transt->subscr != subscr || transt->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001403 continue;
1404 switch (event) {
1405 case GSM_PAGING_SUCCEEDED:
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001406 if (!conn) // paranoid
Harald Welte4bfdfe72009-06-10 23:11:52 +08001407 break;
1408 DEBUGP(DCC, "Paging subscr %s succeeded!\n",
1409 subscr->extension);
1410 /* Assign lchan */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001411 if (!transt->conn) {
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001412 transt->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001413 }
1414 /* send SETUP request to called party */
Harald Weltedcaf5652009-07-23 18:56:43 +02001415 gsm48_cc_tx_setup(transt, &transt->cc.msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001416 break;
1417 case GSM_PAGING_EXPIRED:
1418 DEBUGP(DCC, "Paging subscr %s expired!\n",
1419 subscr->extension);
1420 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001421 mncc_release_ind(transt->subscr->net, transt,
1422 transt->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001423 GSM48_CAUSE_LOC_PRN_S_LU,
1424 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001425 transt->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001426 trans_free(transt);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001427 break;
1428 }
1429 }
Harald Welte09e38af2009-02-16 22:52:23 +00001430 return 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00001431}
Harald Welte7584aea2009-02-11 11:44:12 +00001432
Harald Welteda7ab742009-12-19 22:23:05 +01001433static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable);
1434
Harald Welte805f6442009-07-28 18:25:29 +02001435/* some other part of the code sends us a signal */
1436static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
1437 void *handler_data, void *signal_data)
1438{
1439 struct gsm_lchan *lchan = signal_data;
Harald Welte805f6442009-07-28 18:25:29 +02001440 int rc;
Harald Welteda7ab742009-12-19 22:23:05 +01001441 struct gsm_network *net;
1442 struct gsm_trans *trans;
Harald Welte805f6442009-07-28 18:25:29 +02001443
1444 if (subsys != SS_ABISIP)
1445 return 0;
1446
1447 /* in case we use direct BTS-to-BTS RTP */
1448 if (ipacc_rtp_direct)
1449 return 0;
1450
Harald Welte805f6442009-07-28 18:25:29 +02001451 switch (signal) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001452 case S_ABISIP_CRCX_ACK:
Harald Welteda7ab742009-12-19 22:23:05 +01001453 /* check if any transactions on this lchan still have
1454 * a tch_recv_mncc request pending */
1455 net = lchan->ts->trx->bts->network;
1456 llist_for_each_entry(trans, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001457 if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) {
Harald Welteda7ab742009-12-19 22:23:05 +01001458 DEBUGP(DCC, "pending tch_recv_mncc request\n");
1459 tch_recv_mncc(net, trans->callref, 1);
1460 }
1461 }
Harald Welte805f6442009-07-28 18:25:29 +02001462 break;
Harald Welte805f6442009-07-28 18:25:29 +02001463 }
1464
1465 return 0;
Harald Welte805f6442009-07-28 18:25:29 +02001466}
1467
Harald Welte49f48b82009-02-17 15:29:33 +00001468/* map two ipaccess RTP streams onto each other */
Harald Welte11fa29c2009-02-19 17:24:39 +00001469static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
Harald Welte49f48b82009-02-17 15:29:33 +00001470{
Harald Welte11fa29c2009-02-19 17:24:39 +00001471 struct gsm_bts *bts = lchan->ts->trx->bts;
1472 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
Harald Welte805f6442009-07-28 18:25:29 +02001473 int rc;
Harald Welte49f48b82009-02-17 15:29:33 +00001474
Harald Welte11fa29c2009-02-19 17:24:39 +00001475 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1476 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1477 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1478
1479 if (bts->type != remote_bts->type) {
1480 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1481 return -EINVAL;
1482 }
Harald Welteda7ab742009-12-19 22:23:05 +01001483
1484 // todo: map between different bts types
Harald Welte11fa29c2009-02-19 17:24:39 +00001485 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001486 case GSM_BTS_TYPE_NANOBTS:
Harald Welte805f6442009-07-28 18:25:29 +02001487 if (!ipacc_rtp_direct) {
1488 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001489 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welte805f6442009-07-28 18:25:29 +02001490 if (rc < 0)
1491 return rc;
Harald Weltea72273e2009-12-20 16:51:09 +01001492 rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001493#warning do we need a check of rc here?
Harald Welte805f6442009-07-28 18:25:29 +02001494
1495 /* connect them with each other */
Harald Welte2c828992009-12-02 01:56:49 +05301496 rtp_socket_proxy(lchan->abis_ip.rtp_socket,
1497 remote_lchan->abis_ip.rtp_socket);
Harald Welte805f6442009-07-28 18:25:29 +02001498 } else {
1499 /* directly connect TCH RTP streams to each other */
Harald Welte2c828992009-12-02 01:56:49 +05301500 rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip,
1501 remote_lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301502 remote_lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001503 if (rc < 0)
1504 return rc;
Harald Welte2c828992009-12-02 01:56:49 +05301505 rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip,
1506 lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301507 lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001508 }
Harald Welte11fa29c2009-02-19 17:24:39 +00001509 break;
1510 case GSM_BTS_TYPE_BS11:
1511 trau_mux_map_lchan(lchan, remote_lchan);
1512 break;
1513 default:
1514 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
Harald Welteda7ab742009-12-19 22:23:05 +01001515 return -EINVAL;
Harald Welte11fa29c2009-02-19 17:24:39 +00001516 }
Harald Welte49f48b82009-02-17 15:29:33 +00001517
1518 return 0;
1519}
1520
Harald Welte4bfdfe72009-06-10 23:11:52 +08001521/* bridge channels of two transactions */
1522static int tch_bridge(struct gsm_network *net, u_int32_t *refs)
Harald Welte7ccf7782009-02-17 01:43:01 +00001523{
Harald Weltedcaf5652009-07-23 18:56:43 +02001524 struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]);
1525 struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]);
Harald Welte7ccf7782009-02-17 01:43:01 +00001526
Harald Welte4bfdfe72009-06-10 23:11:52 +08001527 if (!trans1 || !trans2)
Harald Welte7ccf7782009-02-17 01:43:01 +00001528 return -EIO;
1529
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001530 if (!trans1->conn || !trans2->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001531 return -EIO;
1532
1533 /* through-connect channel */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001534 return tch_map(trans1->conn->lchan, trans2->conn->lchan);
Harald Welte7ccf7782009-02-17 01:43:01 +00001535}
1536
Harald Welteda7ab742009-12-19 22:23:05 +01001537/* enable receive of channels to MNCC upqueue */
1538static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001539{
1540 struct gsm_trans *trans;
Harald Welteda7ab742009-12-19 22:23:05 +01001541 struct gsm_lchan *lchan;
1542 struct gsm_bts *bts;
1543 int rc;
Harald Welte7ccf7782009-02-17 01:43:01 +00001544
Harald Welte4bfdfe72009-06-10 23:11:52 +08001545 /* Find callref */
Harald Welteda7ab742009-12-19 22:23:05 +01001546 trans = trans_find_by_callref(net, callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001547 if (!trans)
1548 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001549 if (!trans->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001550 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001551 lchan = trans->conn->lchan;
Harald Welteda7ab742009-12-19 22:23:05 +01001552 bts = lchan->ts->trx->bts;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001553
Harald Welteda7ab742009-12-19 22:23:05 +01001554 switch (bts->type) {
1555 case GSM_BTS_TYPE_NANOBTS:
1556 if (ipacc_rtp_direct) {
1557 DEBUGP(DCC, "Error: RTP proxy is disabled\n");
1558 return -EINVAL;
1559 }
1560 /* in case, we don't have a RTP socket yet, we note this
1561 * in the transaction and try later */
1562 if (!lchan->abis_ip.rtp_socket) {
1563 trans->tch_recv = enable;
1564 DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable);
1565 return 0;
1566 }
1567 if (enable) {
1568 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001569 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001570 if (rc < 0)
1571 return rc;
1572 /* assign socket to application interface */
1573 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1574 net, callref);
1575 } else
1576 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1577 net, 0);
1578 break;
1579 case GSM_BTS_TYPE_BS11:
1580 if (enable)
1581 return trau_recv_lchan(lchan, callref);
1582 return trau_mux_unmap(NULL, callref);
1583 break;
1584 default:
1585 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
1586 return -EINVAL;
1587 }
1588
1589 return 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001590}
1591
Harald Welte4bfdfe72009-06-10 23:11:52 +08001592static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
1593{
1594 DEBUGP(DCC, "-> STATUS ENQ\n");
1595 return gsm48_cc_tx_status(trans, msg);
1596}
1597
1598static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
1599static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
1600
1601static void gsm48_cc_timeout(void *arg)
1602{
1603 struct gsm_trans *trans = arg;
1604 int disconnect = 0, release = 0;
Harald Weltec66b71c2009-06-11 14:23:20 +08001605 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
1606 int mo_location = GSM48_CAUSE_LOC_USER;
1607 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
1608 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001609 struct gsm_mncc mo_rel, l4_rel;
1610
1611 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
1612 mo_rel.callref = trans->callref;
1613 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
1614 l4_rel.callref = trans->callref;
1615
Harald Weltedcaf5652009-07-23 18:56:43 +02001616 switch(trans->cc.Tcurrent) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001617 case 0x303:
1618 release = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001619 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001620 break;
1621 case 0x310:
1622 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001623 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001624 break;
1625 case 0x313:
1626 disconnect = 1;
1627 /* unknown, did not find it in the specs */
1628 break;
1629 case 0x301:
1630 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001631 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001632 break;
1633 case 0x308:
Harald Weltedcaf5652009-07-23 18:56:43 +02001634 if (!trans->cc.T308_second) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001635 /* restart T308 a second time */
Harald Weltedcaf5652009-07-23 18:56:43 +02001636 gsm48_cc_tx_release(trans, &trans->cc.msg);
1637 trans->cc.T308_second = 1;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001638 break; /* stay in release state */
1639 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001640 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001641 return;
1642// release = 1;
1643// l4_cause = 14;
1644// break;
1645 case 0x306:
1646 release = 1;
Harald Weltedcaf5652009-07-23 18:56:43 +02001647 mo_cause = trans->cc.msg.cause.value;
1648 mo_location = trans->cc.msg.cause.location;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001649 break;
1650 case 0x323:
1651 disconnect = 1;
1652 break;
1653 default:
1654 release = 1;
1655 }
1656
1657 if (release && trans->callref) {
1658 /* process release towards layer 4 */
Harald Welte596fed42009-07-23 19:06:52 +02001659 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001660 l4_location, l4_cause);
1661 trans->callref = 0;
1662 }
1663
1664 if (disconnect && trans->callref) {
1665 /* process disconnect towards layer 4 */
1666 mncc_set_cause(&l4_rel, l4_location, l4_cause);
Harald Welte596fed42009-07-23 19:06:52 +02001667 mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001668 }
1669
1670 /* process disconnect towards mobile station */
1671 if (disconnect || release) {
1672 mncc_set_cause(&mo_rel, mo_location, mo_cause);
Harald Weltedcaf5652009-07-23 18:56:43 +02001673 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
1674 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
1675 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
Harald Welte4bfdfe72009-06-10 23:11:52 +08001676 mo_rel.cause.diag_len = 3;
1677
1678 if (disconnect)
1679 gsm48_cc_tx_disconnect(trans, &mo_rel);
1680 if (release)
1681 gsm48_cc_tx_release(trans, &mo_rel);
1682 }
1683
1684}
1685
1686static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
1687 int sec, int micro)
1688{
1689 DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec);
Harald Weltedcaf5652009-07-23 18:56:43 +02001690 trans->cc.timer.cb = gsm48_cc_timeout;
1691 trans->cc.timer.data = trans;
1692 bsc_schedule_timer(&trans->cc.timer, sec, micro);
1693 trans->cc.Tcurrent = current;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001694}
1695
1696static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
1697{
1698 struct gsm48_hdr *gh = msgb_l3(msg);
1699 u_int8_t msg_type = gh->msg_type & 0xbf;
1700 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1701 struct tlv_parsed tp;
1702 struct gsm_mncc setup;
1703
1704 memset(&setup, 0, sizeof(struct gsm_mncc));
1705 setup.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001706 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001707 /* emergency setup is identified by msg_type */
1708 if (msg_type == GSM48_MT_CC_EMERG_SETUP)
1709 setup.emergency = 1;
1710
1711 /* use subscriber as calling party number */
1712 if (trans->subscr) {
1713 setup.fields |= MNCC_F_CALLING;
1714 strncpy(setup.calling.number, trans->subscr->extension,
1715 sizeof(setup.calling.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02001716 strncpy(setup.imsi, trans->subscr->imsi,
1717 sizeof(setup.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001718 }
1719 /* bearer capability */
1720 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1721 setup.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001722 gsm48_decode_bearer_cap(&setup.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001723 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1724 }
1725 /* facility */
1726 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1727 setup.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001728 gsm48_decode_facility(&setup.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001729 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1730 }
1731 /* called party bcd number */
1732 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
1733 setup.fields |= MNCC_F_CALLED;
Harald Welte55c8f352010-03-07 23:40:35 +01001734 gsm48_decode_called(&setup.called,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001735 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
1736 }
1737 /* user-user */
1738 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1739 setup.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01001740 gsm48_decode_useruser(&setup.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001741 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1742 }
1743 /* ss-version */
1744 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1745 setup.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001746 gsm48_decode_ssversion(&setup.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001747 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1748 }
1749 /* CLIR suppression */
1750 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
1751 setup.clir.sup = 1;
1752 /* CLIR invocation */
1753 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
1754 setup.clir.inv = 1;
1755 /* cc cap */
1756 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1757 setup.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001758 gsm48_decode_cccap(&setup.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001759 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1760 }
1761
Harald Welte4bfdfe72009-06-10 23:11:52 +08001762 new_cc_state(trans, GSM_CSTATE_INITIATED);
1763
Harald Welte (local)47df3992009-12-26 19:45:03 +01001764 LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n",
1765 subscr_name(trans->subscr), trans->subscr->extension,
1766 setup.called.number);
1767
Harald Welte4bfdfe72009-06-10 23:11:52 +08001768 /* indicate setup to MNCC */
Harald Welte596fed42009-07-23 19:06:52 +02001769 mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001770
Harald Welte13cac662009-07-29 12:10:35 +02001771 /* MNCC code will modify the channel asynchronously, we should
1772 * ipaccess-bind only after the modification has been made to the
1773 * lchan->tch_mode */
Harald Welte4bfdfe72009-06-10 23:11:52 +08001774 return 0;
1775}
1776
1777static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
Harald Welte65e74cc2008-12-29 01:55:35 +00001778{
1779 struct msgb *msg = gsm48_msgb_alloc();
1780 struct gsm48_hdr *gh;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001781 struct gsm_mncc *setup = arg;
Harald Welte78283ef2009-07-23 21:36:44 +02001782 int rc, trans_id;
Harald Welte65e74cc2008-12-29 01:55:35 +00001783
Harald Welte7ccf7782009-02-17 01:43:01 +00001784 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Harald Welte65e74cc2008-12-29 01:55:35 +00001785
Harald Welte4bfdfe72009-06-10 23:11:52 +08001786 /* transaction id must not be assigned */
1787 if (trans->transaction_id != 0xff) { /* unasssigned */
1788 DEBUGP(DCC, "TX Setup with assigned transaction. "
1789 "This is not allowed!\n");
1790 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001791 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001792 GSM48_CAUSE_LOC_PRN_S_LU,
1793 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001794 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001795 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001796 return rc;
1797 }
1798
1799 /* Get free transaction_id */
Harald Welte78283ef2009-07-23 21:36:44 +02001800 trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0);
1801 if (trans_id < 0) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001802 /* no free transaction ID */
Harald Welte596fed42009-07-23 19:06:52 +02001803 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001804 GSM48_CAUSE_LOC_PRN_S_LU,
1805 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001806 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001807 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001808 return rc;
1809 }
Harald Welte78283ef2009-07-23 21:36:44 +02001810 trans->transaction_id = trans_id;
Harald Welte49f48b82009-02-17 15:29:33 +00001811
Harald Welte65e74cc2008-12-29 01:55:35 +00001812 gh->msg_type = GSM48_MT_CC_SETUP;
Harald Welte09e38af2009-02-16 22:52:23 +00001813
Harald Welte4bfdfe72009-06-10 23:11:52 +08001814 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
Harald Welte65e74cc2008-12-29 01:55:35 +00001815
Harald Welte4bfdfe72009-06-10 23:11:52 +08001816 /* bearer capability */
1817 if (setup->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001818 gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001819 /* facility */
1820 if (setup->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001821 gsm48_encode_facility(msg, 0, &setup->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001822 /* progress */
1823 if (setup->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001824 gsm48_encode_progress(msg, 0, &setup->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001825 /* calling party BCD number */
1826 if (setup->fields & MNCC_F_CALLING)
Harald Welte55c8f352010-03-07 23:40:35 +01001827 gsm48_encode_calling(msg, &setup->calling);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001828 /* called party BCD number */
1829 if (setup->fields & MNCC_F_CALLED)
Harald Welte55c8f352010-03-07 23:40:35 +01001830 gsm48_encode_called(msg, &setup->called);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001831 /* user-user */
1832 if (setup->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001833 gsm48_encode_useruser(msg, 0, &setup->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001834 /* redirecting party BCD number */
1835 if (setup->fields & MNCC_F_REDIRECTING)
Harald Welte55c8f352010-03-07 23:40:35 +01001836 gsm48_encode_redirecting(msg, &setup->redirecting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001837 /* signal */
1838 if (setup->fields & MNCC_F_SIGNAL)
Harald Welte55c8f352010-03-07 23:40:35 +01001839 gsm48_encode_signal(msg, setup->signal);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001840
1841 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
Harald Welte65e74cc2008-12-29 01:55:35 +00001842
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001843 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte65e74cc2008-12-29 01:55:35 +00001844}
1845
Harald Welte4bfdfe72009-06-10 23:11:52 +08001846static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
1847{
1848 struct gsm48_hdr *gh = msgb_l3(msg);
1849 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1850 struct tlv_parsed tp;
1851 struct gsm_mncc call_conf;
1852
1853 gsm48_stop_cc_timer(trans);
1854 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
1855
1856 memset(&call_conf, 0, sizeof(struct gsm_mncc));
1857 call_conf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001858 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001859#if 0
1860 /* repeat */
1861 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
1862 call_conf.repeat = 1;
1863 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
1864 call_conf.repeat = 2;
1865#endif
1866 /* bearer capability */
1867 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1868 call_conf.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001869 gsm48_decode_bearer_cap(&call_conf.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001870 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1871 }
1872 /* cause */
1873 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1874 call_conf.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01001875 gsm48_decode_cause(&call_conf.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001876 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1877 }
1878 /* cc cap */
1879 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1880 call_conf.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001881 gsm48_decode_cccap(&call_conf.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001882 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1883 }
1884
1885 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
1886
Harald Welte596fed42009-07-23 19:06:52 +02001887 return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND,
1888 &call_conf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001889}
1890
1891static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg)
1892{
1893 struct gsm_mncc *proceeding = arg;
1894 struct msgb *msg = gsm48_msgb_alloc();
1895 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1896
Harald Welte4bfdfe72009-06-10 23:11:52 +08001897 gh->msg_type = GSM48_MT_CC_CALL_PROC;
1898
1899 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
1900
1901 /* bearer capability */
1902 if (proceeding->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001903 gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001904 /* facility */
1905 if (proceeding->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001906 gsm48_encode_facility(msg, 0, &proceeding->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001907 /* progress */
1908 if (proceeding->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001909 gsm48_encode_progress(msg, 0, &proceeding->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001910
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001911 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001912}
1913
1914static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
1915{
1916 struct gsm48_hdr *gh = msgb_l3(msg);
1917 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1918 struct tlv_parsed tp;
1919 struct gsm_mncc alerting;
1920
1921 gsm48_stop_cc_timer(trans);
1922 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
1923
1924 memset(&alerting, 0, sizeof(struct gsm_mncc));
1925 alerting.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001926 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001927 /* facility */
1928 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1929 alerting.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001930 gsm48_decode_facility(&alerting.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001931 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1932 }
1933
1934 /* progress */
1935 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
1936 alerting.fields |= MNCC_F_PROGRESS;
Harald Welte55c8f352010-03-07 23:40:35 +01001937 gsm48_decode_progress(&alerting.progress,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001938 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
1939 }
1940 /* ss-version */
1941 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1942 alerting.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001943 gsm48_decode_ssversion(&alerting.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001944 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1945 }
1946
1947 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
1948
Harald Welte596fed42009-07-23 19:06:52 +02001949 return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND,
1950 &alerting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001951}
1952
1953static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
1954{
1955 struct gsm_mncc *alerting = arg;
1956 struct msgb *msg = gsm48_msgb_alloc();
1957 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1958
Harald Welte4bfdfe72009-06-10 23:11:52 +08001959 gh->msg_type = GSM48_MT_CC_ALERTING;
1960
1961 /* facility */
1962 if (alerting->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001963 gsm48_encode_facility(msg, 0, &alerting->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001964 /* progress */
1965 if (alerting->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001966 gsm48_encode_progress(msg, 0, &alerting->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001967 /* user-user */
1968 if (alerting->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001969 gsm48_encode_useruser(msg, 0, &alerting->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001970
1971 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
1972
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001973 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001974}
1975
1976static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
1977{
1978 struct gsm_mncc *progress = arg;
1979 struct msgb *msg = gsm48_msgb_alloc();
1980 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1981
Harald Welte4bfdfe72009-06-10 23:11:52 +08001982 gh->msg_type = GSM48_MT_CC_PROGRESS;
1983
1984 /* progress */
Harald Welte55c8f352010-03-07 23:40:35 +01001985 gsm48_encode_progress(msg, 1, &progress->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001986 /* user-user */
1987 if (progress->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001988 gsm48_encode_useruser(msg, 0, &progress->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001989
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001990 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001991}
1992
1993static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
1994{
1995 struct gsm_mncc *connect = arg;
1996 struct msgb *msg = gsm48_msgb_alloc();
1997 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1998
Harald Welte4bfdfe72009-06-10 23:11:52 +08001999 gh->msg_type = GSM48_MT_CC_CONNECT;
2000
2001 gsm48_stop_cc_timer(trans);
2002 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
2003
2004 /* facility */
2005 if (connect->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002006 gsm48_encode_facility(msg, 0, &connect->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002007 /* progress */
2008 if (connect->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01002009 gsm48_encode_progress(msg, 0, &connect->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002010 /* connected number */
2011 if (connect->fields & MNCC_F_CONNECTED)
Harald Welte55c8f352010-03-07 23:40:35 +01002012 gsm48_encode_connected(msg, &connect->connected);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002013 /* user-user */
2014 if (connect->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002015 gsm48_encode_useruser(msg, 0, &connect->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002016
2017 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
2018
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002019 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002020}
2021
2022static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
2023{
2024 struct gsm48_hdr *gh = msgb_l3(msg);
2025 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2026 struct tlv_parsed tp;
2027 struct gsm_mncc connect;
2028
2029 gsm48_stop_cc_timer(trans);
2030
2031 memset(&connect, 0, sizeof(struct gsm_mncc));
2032 connect.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002033 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002034 /* use subscriber as connected party number */
2035 if (trans->subscr) {
2036 connect.fields |= MNCC_F_CONNECTED;
2037 strncpy(connect.connected.number, trans->subscr->extension,
2038 sizeof(connect.connected.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002039 strncpy(connect.imsi, trans->subscr->imsi,
2040 sizeof(connect.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002041 }
2042 /* facility */
2043 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2044 connect.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002045 gsm48_decode_facility(&connect.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002046 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2047 }
2048 /* user-user */
2049 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2050 connect.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002051 gsm48_decode_useruser(&connect.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002052 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2053 }
2054 /* ss-version */
2055 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2056 connect.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002057 gsm48_decode_ssversion(&connect.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002058 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2059 }
2060
2061 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
2062
Harald Welte596fed42009-07-23 19:06:52 +02002063 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002064}
2065
2066
2067static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
2068{
2069 struct gsm_mncc connect_ack;
2070
2071 gsm48_stop_cc_timer(trans);
2072
2073 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2074
2075 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
2076 connect_ack.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002077 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002078 &connect_ack);
2079}
2080
2081static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
2082{
2083 struct msgb *msg = gsm48_msgb_alloc();
2084 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2085
Harald Welte4bfdfe72009-06-10 23:11:52 +08002086 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
2087
2088 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2089
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002090 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002091}
2092
2093static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
2094{
2095 struct gsm48_hdr *gh = msgb_l3(msg);
2096 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2097 struct tlv_parsed tp;
2098 struct gsm_mncc disc;
2099
2100 gsm48_stop_cc_timer(trans);
2101
2102 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
2103
2104 memset(&disc, 0, sizeof(struct gsm_mncc));
2105 disc.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002106 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002107 /* cause */
2108 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2109 disc.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002110 gsm48_decode_cause(&disc.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002111 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2112 }
2113 /* facility */
2114 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2115 disc.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002116 gsm48_decode_facility(&disc.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002117 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2118 }
2119 /* user-user */
2120 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2121 disc.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002122 gsm48_decode_useruser(&disc.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002123 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2124 }
2125 /* ss-version */
2126 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2127 disc.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002128 gsm48_decode_ssversion(&disc.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002129 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2130 }
2131
Harald Welte596fed42009-07-23 19:06:52 +02002132 return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002133
2134}
2135
Harald Weltec66b71c2009-06-11 14:23:20 +08002136static struct gsm_mncc_cause default_cause = {
2137 .location = GSM48_CAUSE_LOC_PRN_S_LU,
2138 .coding = 0,
2139 .rec = 0,
2140 .rec_val = 0,
2141 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
2142 .diag_len = 0,
2143 .diag = { 0 },
2144};
Harald Welte4bfdfe72009-06-10 23:11:52 +08002145
2146static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
2147{
2148 struct gsm_mncc *disc = arg;
2149 struct msgb *msg = gsm48_msgb_alloc();
2150 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2151
Harald Welte4bfdfe72009-06-10 23:11:52 +08002152 gh->msg_type = GSM48_MT_CC_DISCONNECT;
2153
2154 gsm48_stop_cc_timer(trans);
2155 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
2156
2157 /* cause */
2158 if (disc->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002159 gsm48_encode_cause(msg, 1, &disc->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002160 else
Harald Welte55c8f352010-03-07 23:40:35 +01002161 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002162
2163 /* facility */
2164 if (disc->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002165 gsm48_encode_facility(msg, 0, &disc->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002166 /* progress */
2167 if (disc->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01002168 gsm48_encode_progress(msg, 0, &disc->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002169 /* user-user */
2170 if (disc->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002171 gsm48_encode_useruser(msg, 0, &disc->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002172
2173 /* store disconnect cause for T306 expiry */
Harald Weltedcaf5652009-07-23 18:56:43 +02002174 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002175
2176 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
2177
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002178 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002179}
2180
2181static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
2182{
2183 struct gsm48_hdr *gh = msgb_l3(msg);
2184 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2185 struct tlv_parsed tp;
2186 struct gsm_mncc rel;
2187 int rc;
2188
2189 gsm48_stop_cc_timer(trans);
2190
2191 memset(&rel, 0, sizeof(struct gsm_mncc));
2192 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002193 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002194 /* cause */
2195 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2196 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002197 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002198 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2199 }
2200 /* facility */
2201 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2202 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002203 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002204 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2205 }
2206 /* user-user */
2207 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2208 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002209 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002210 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2211 }
2212 /* ss-version */
2213 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2214 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002215 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002216 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2217 }
2218
Harald Weltedcaf5652009-07-23 18:56:43 +02002219 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002220 /* release collision 5.4.5 */
Harald Welte596fed42009-07-23 19:06:52 +02002221 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002222 } else {
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08002223 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02002224 GSM48_PDISC_CC | (trans->transaction_id << 4),
Harald Welte596fed42009-07-23 19:06:52 +02002225 GSM48_MT_CC_RELEASE_COMPL);
2226 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002227 }
2228
2229 new_cc_state(trans, GSM_CSTATE_NULL);
2230
2231 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002232 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002233
2234 return rc;
2235}
2236
2237static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
2238{
2239 struct gsm_mncc *rel = arg;
2240 struct msgb *msg = gsm48_msgb_alloc();
2241 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2242
Harald Welte4bfdfe72009-06-10 23:11:52 +08002243 gh->msg_type = GSM48_MT_CC_RELEASE;
2244
2245 trans->callref = 0;
2246
2247 gsm48_stop_cc_timer(trans);
2248 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
2249
2250 /* cause */
2251 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002252 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002253 /* facility */
2254 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002255 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002256 /* user-user */
2257 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002258 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002259
Harald Weltedcaf5652009-07-23 18:56:43 +02002260 trans->cc.T308_second = 0;
2261 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002262
Harald Weltedcaf5652009-07-23 18:56:43 +02002263 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002264 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
2265
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002266 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002267}
2268
2269static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
2270{
2271 struct gsm48_hdr *gh = msgb_l3(msg);
2272 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2273 struct tlv_parsed tp;
2274 struct gsm_mncc rel;
2275 int rc = 0;
2276
2277 gsm48_stop_cc_timer(trans);
2278
2279 memset(&rel, 0, sizeof(struct gsm_mncc));
2280 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002281 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002282 /* cause */
2283 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2284 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002285 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002286 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2287 }
2288 /* facility */
2289 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2290 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002291 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002292 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2293 }
2294 /* user-user */
2295 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2296 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002297 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002298 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2299 }
2300 /* ss-version */
2301 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2302 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002303 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002304 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2305 }
2306
2307 if (trans->callref) {
Harald Weltedcaf5652009-07-23 18:56:43 +02002308 switch (trans->cc.state) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002309 case GSM_CSTATE_CALL_PRESENT:
Harald Welte596fed42009-07-23 19:06:52 +02002310 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002311 MNCC_REJ_IND, &rel);
2312 break;
2313 case GSM_CSTATE_RELEASE_REQ:
Harald Welte596fed42009-07-23 19:06:52 +02002314 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002315 MNCC_REL_CNF, &rel);
2316 break;
2317 default:
Harald Welte596fed42009-07-23 19:06:52 +02002318 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002319 MNCC_REL_IND, &rel);
2320 }
2321 }
2322
2323 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002324 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002325
2326 return rc;
2327}
2328
2329static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
2330{
2331 struct gsm_mncc *rel = arg;
2332 struct msgb *msg = gsm48_msgb_alloc();
2333 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2334
Harald Welte4bfdfe72009-06-10 23:11:52 +08002335 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
2336
2337 trans->callref = 0;
2338
2339 gsm48_stop_cc_timer(trans);
2340
2341 /* cause */
2342 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002343 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002344 /* facility */
2345 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002346 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002347 /* user-user */
2348 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002349 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002350
Harald Weltedcaf5652009-07-23 18:56:43 +02002351 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002352
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002353 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002354}
2355
2356static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
2357{
2358 struct gsm48_hdr *gh = msgb_l3(msg);
2359 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2360 struct tlv_parsed tp;
2361 struct gsm_mncc fac;
2362
2363 memset(&fac, 0, sizeof(struct gsm_mncc));
2364 fac.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002365 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002366 /* facility */
2367 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2368 fac.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002369 gsm48_decode_facility(&fac.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002370 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2371 }
2372 /* ss-version */
2373 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2374 fac.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002375 gsm48_decode_ssversion(&fac.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002376 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2377 }
2378
Harald Welte596fed42009-07-23 19:06:52 +02002379 return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002380}
2381
2382static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
2383{
2384 struct gsm_mncc *fac = arg;
2385 struct msgb *msg = gsm48_msgb_alloc();
2386 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2387
Harald Welte4bfdfe72009-06-10 23:11:52 +08002388 gh->msg_type = GSM48_MT_CC_FACILITY;
2389
2390 /* facility */
Harald Welte55c8f352010-03-07 23:40:35 +01002391 gsm48_encode_facility(msg, 1, &fac->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002392
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002393 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002394}
2395
2396static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
2397{
2398 struct gsm_mncc hold;
2399
2400 memset(&hold, 0, sizeof(struct gsm_mncc));
2401 hold.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002402 return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002403}
2404
2405static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
2406{
2407 struct msgb *msg = gsm48_msgb_alloc();
2408 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2409
Harald Welte4bfdfe72009-06-10 23:11:52 +08002410 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
2411
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002412 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002413}
2414
2415static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
2416{
2417 struct gsm_mncc *hold_rej = arg;
2418 struct msgb *msg = gsm48_msgb_alloc();
2419 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2420
Harald Welte4bfdfe72009-06-10 23:11:52 +08002421 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
2422
2423 /* cause */
2424 if (hold_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002425 gsm48_encode_cause(msg, 1, &hold_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002426 else
Harald Welte55c8f352010-03-07 23:40:35 +01002427 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002428
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002429 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002430}
2431
2432static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
2433{
2434 struct gsm_mncc retrieve;
2435
2436 memset(&retrieve, 0, sizeof(struct gsm_mncc));
2437 retrieve.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002438 return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND,
2439 &retrieve);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002440}
2441
2442static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
2443{
2444 struct msgb *msg = gsm48_msgb_alloc();
2445 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2446
Harald Welte4bfdfe72009-06-10 23:11:52 +08002447 gh->msg_type = GSM48_MT_CC_RETR_ACK;
2448
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002449 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002450}
2451
2452static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
2453{
2454 struct gsm_mncc *retrieve_rej = arg;
2455 struct msgb *msg = gsm48_msgb_alloc();
2456 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2457
Harald Welte4bfdfe72009-06-10 23:11:52 +08002458 gh->msg_type = GSM48_MT_CC_RETR_REJ;
2459
2460 /* cause */
2461 if (retrieve_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002462 gsm48_encode_cause(msg, 1, &retrieve_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002463 else
Harald Welte55c8f352010-03-07 23:40:35 +01002464 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002465
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002466 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002467}
2468
2469static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
2470{
2471 struct gsm48_hdr *gh = msgb_l3(msg);
2472 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2473 struct tlv_parsed tp;
2474 struct gsm_mncc dtmf;
2475
2476 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2477 dtmf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002478 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002479 /* keypad facility */
2480 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
2481 dtmf.fields |= MNCC_F_KEYPAD;
Harald Welte55c8f352010-03-07 23:40:35 +01002482 gsm48_decode_keypad(&dtmf.keypad,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002483 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
2484 }
2485
Harald Welte596fed42009-07-23 19:06:52 +02002486 return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002487}
2488
2489static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
2490{
2491 struct gsm_mncc *dtmf = arg;
2492 struct msgb *msg = gsm48_msgb_alloc();
2493 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2494
Harald Welte4bfdfe72009-06-10 23:11:52 +08002495 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
2496
2497 /* keypad */
2498 if (dtmf->fields & MNCC_F_KEYPAD)
Harald Welte55c8f352010-03-07 23:40:35 +01002499 gsm48_encode_keypad(msg, dtmf->keypad);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002500
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002501 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002502}
2503
2504static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
2505{
2506 struct gsm_mncc *dtmf = arg;
2507 struct msgb *msg = gsm48_msgb_alloc();
2508 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2509
Harald Welte4bfdfe72009-06-10 23:11:52 +08002510 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
2511
2512 /* cause */
2513 if (dtmf->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002514 gsm48_encode_cause(msg, 1, &dtmf->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002515 else
Harald Welte55c8f352010-03-07 23:40:35 +01002516 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002517
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002518 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002519}
2520
2521static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
2522{
2523 struct msgb *msg = gsm48_msgb_alloc();
2524 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2525
Harald Welte4bfdfe72009-06-10 23:11:52 +08002526 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
2527
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002528 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002529}
2530
2531static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
2532{
2533 struct gsm_mncc dtmf;
2534
2535 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2536 dtmf.callref = trans->callref;
2537
Harald Welte596fed42009-07-23 19:06:52 +02002538 return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002539}
2540
2541static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
2542{
2543 struct gsm48_hdr *gh = msgb_l3(msg);
2544 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2545 struct tlv_parsed tp;
2546 struct gsm_mncc modify;
2547
2548 memset(&modify, 0, sizeof(struct gsm_mncc));
2549 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002550 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002551 /* bearer capability */
2552 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2553 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002554 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002555 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2556 }
2557
2558 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
2559
Harald Welte596fed42009-07-23 19:06:52 +02002560 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002561}
2562
2563static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
2564{
2565 struct gsm_mncc *modify = arg;
2566 struct msgb *msg = gsm48_msgb_alloc();
2567 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2568
Harald Welte4bfdfe72009-06-10 23:11:52 +08002569 gh->msg_type = GSM48_MT_CC_MODIFY;
2570
2571 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
2572
2573 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002574 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002575
2576 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
2577
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002578 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002579}
2580
2581static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
2582{
2583 struct gsm48_hdr *gh = msgb_l3(msg);
2584 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2585 struct tlv_parsed tp;
2586 struct gsm_mncc modify;
2587
2588 gsm48_stop_cc_timer(trans);
2589
2590 memset(&modify, 0, sizeof(struct gsm_mncc));
2591 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002592 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002593 /* bearer capability */
2594 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2595 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002596 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002597 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2598 }
2599
2600 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2601
Harald Welte596fed42009-07-23 19:06:52 +02002602 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002603}
2604
2605static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
2606{
2607 struct gsm_mncc *modify = arg;
2608 struct msgb *msg = gsm48_msgb_alloc();
2609 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2610
Harald Welte4bfdfe72009-06-10 23:11:52 +08002611 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
2612
2613 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002614 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002615
2616 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2617
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002618 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002619}
2620
2621static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
2622{
2623 struct gsm48_hdr *gh = msgb_l3(msg);
2624 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2625 struct tlv_parsed tp;
2626 struct gsm_mncc modify;
2627
2628 gsm48_stop_cc_timer(trans);
2629
2630 memset(&modify, 0, sizeof(struct gsm_mncc));
2631 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002632 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002633 /* bearer capability */
2634 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2635 modify.fields |= GSM48_IE_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002636 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002637 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2638 }
2639 /* cause */
2640 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2641 modify.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002642 gsm48_decode_cause(&modify.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002643 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2644 }
2645
2646 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2647
Harald Welte596fed42009-07-23 19:06:52 +02002648 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002649}
2650
2651static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
2652{
2653 struct gsm_mncc *modify = arg;
2654 struct msgb *msg = gsm48_msgb_alloc();
2655 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2656
Harald Welte4bfdfe72009-06-10 23:11:52 +08002657 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
2658
2659 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002660 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002661 /* cause */
Harald Welte55c8f352010-03-07 23:40:35 +01002662 gsm48_encode_cause(msg, 1, &modify->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002663
2664 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2665
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002666 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002667}
2668
2669static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
2670{
2671 struct gsm_mncc *notify = arg;
2672 struct msgb *msg = gsm48_msgb_alloc();
2673 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2674
Harald Welte4bfdfe72009-06-10 23:11:52 +08002675 gh->msg_type = GSM48_MT_CC_NOTIFY;
2676
2677 /* notify */
Harald Welte55c8f352010-03-07 23:40:35 +01002678 gsm48_encode_notify(msg, notify->notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002679
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002680 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002681}
2682
2683static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
2684{
2685 struct gsm48_hdr *gh = msgb_l3(msg);
2686 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2687// struct tlv_parsed tp;
2688 struct gsm_mncc notify;
2689
2690 memset(&notify, 0, sizeof(struct gsm_mncc));
2691 notify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002692// tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002693 if (payload_len >= 1)
Harald Welte55c8f352010-03-07 23:40:35 +01002694 gsm48_decode_notify(&notify.notify, gh->data);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002695
Harald Welte596fed42009-07-23 19:06:52 +02002696 return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, &notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002697}
2698
2699static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
2700{
2701 struct gsm_mncc *user = arg;
2702 struct msgb *msg = gsm48_msgb_alloc();
2703 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2704
Harald Welte4bfdfe72009-06-10 23:11:52 +08002705 gh->msg_type = GSM48_MT_CC_USER_INFO;
2706
2707 /* user-user */
2708 if (user->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002709 gsm48_encode_useruser(msg, 1, &user->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002710 /* more data */
2711 if (user->more)
Harald Welte55c8f352010-03-07 23:40:35 +01002712 gsm48_encode_more(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002713
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002714 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002715}
2716
2717static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
2718{
2719 struct gsm48_hdr *gh = msgb_l3(msg);
2720 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2721 struct tlv_parsed tp;
2722 struct gsm_mncc user;
2723
2724 memset(&user, 0, sizeof(struct gsm_mncc));
2725 user.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002726 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002727 /* user-user */
2728 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2729 user.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002730 gsm48_decode_useruser(&user.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002731 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2732 }
2733 /* more data */
2734 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
2735 user.more = 1;
2736
Harald Welte596fed42009-07-23 19:06:52 +02002737 return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002738}
2739
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002740static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002741{
2742 struct gsm_mncc *mode = arg;
2743
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002744 return gsm48_lchan_modify(trans->conn->lchan, mode->lchan_mode);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002745}
2746
2747static struct downstate {
2748 u_int32_t states;
2749 int type;
2750 int (*rout) (struct gsm_trans *trans, void *arg);
2751} downstatelist[] = {
2752 /* mobile originating call establishment */
2753 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
2754 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc},
2755 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
2756 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
2757 {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 */
2758 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
2759 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
2760 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
2761 /* mobile terminating call establishment */
2762 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
2763 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
2764 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
2765 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
2766 /* signalling during call */
2767 {SBIT(GSM_CSTATE_ACTIVE),
2768 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
2769 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
2770 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
2771 {ALL_STATES,
2772 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
2773 {ALL_STATES,
2774 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
2775 {ALL_STATES,
2776 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
2777 {SBIT(GSM_CSTATE_ACTIVE),
2778 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
2779 {SBIT(GSM_CSTATE_ACTIVE),
2780 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
2781 {SBIT(GSM_CSTATE_ACTIVE),
2782 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
2783 {SBIT(GSM_CSTATE_ACTIVE),
2784 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
2785 {SBIT(GSM_CSTATE_ACTIVE),
2786 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
2787 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2788 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
2789 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2790 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
2791 {SBIT(GSM_CSTATE_ACTIVE),
2792 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
2793 /* clearing */
2794 {SBIT(GSM_CSTATE_INITIATED),
2795 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
2796 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
2797 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
2798 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
2799 MNCC_REL_REQ, gsm48_cc_tx_release},
2800 /* special */
2801 {ALL_STATES,
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002802 MNCC_LCHAN_MODIFY, _gsm48_lchan_modify},
Harald Welte4bfdfe72009-06-10 23:11:52 +08002803};
2804
2805#define DOWNSLLEN \
2806 (sizeof(downstatelist) / sizeof(struct downstate))
2807
2808
2809int mncc_send(struct gsm_network *net, int msg_type, void *arg)
2810{
Harald Welte1a6f7982009-08-09 18:52:33 +02002811 int i, rc = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002812 struct gsm_trans *trans = NULL, *transt;
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002813 struct gsm_subscriber_connection *conn = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002814 struct gsm_bts *bts = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002815 struct gsm_mncc *data = arg, rel;
2816
2817 /* handle special messages */
2818 switch(msg_type) {
2819 case MNCC_BRIDGE:
2820 return tch_bridge(net, arg);
2821 case MNCC_FRAME_DROP:
Harald Welteda7ab742009-12-19 22:23:05 +01002822 return tch_recv_mncc(net, data->callref, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002823 case MNCC_FRAME_RECV:
Harald Welteda7ab742009-12-19 22:23:05 +01002824 return tch_recv_mncc(net, data->callref, 1);
2825 case GSM_TCHF_FRAME:
2826 /* Find callref */
2827 trans = trans_find_by_callref(net, data->callref);
2828 if (!trans)
2829 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002830 if (!trans->conn)
Harald Welteda7ab742009-12-19 22:23:05 +01002831 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002832 if (trans->conn->lchan->type != GSM_LCHAN_TCH_F)
Harald Welteda7ab742009-12-19 22:23:05 +01002833 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002834 bts = trans->conn->lchan->ts->trx->bts;
Harald Welteda7ab742009-12-19 22:23:05 +01002835 switch (bts->type) {
2836 case GSM_BTS_TYPE_NANOBTS:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002837 if (!trans->conn->lchan->abis_ip.rtp_socket)
Harald Welteda7ab742009-12-19 22:23:05 +01002838 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002839 return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002840 case GSM_BTS_TYPE_BS11:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002841 return trau_send_frame(trans->conn->lchan, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002842 default:
2843 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
2844 }
2845 return -EINVAL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002846 }
2847
2848 memset(&rel, 0, sizeof(struct gsm_mncc));
2849 rel.callref = data->callref;
2850
2851 /* Find callref */
Harald Weltedcaf5652009-07-23 18:56:43 +02002852 trans = trans_find_by_callref(net, data->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002853
2854 /* Callref unknown */
2855 if (!trans) {
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002856 struct gsm_subscriber *subscr;
2857
Harald Welte4a3464c2009-07-04 10:11:24 +02002858 if (msg_type != MNCC_SETUP_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002859 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2860 "Received '%s' from MNCC with "
2861 "unknown callref %d\n", data->called.number,
2862 get_mncc_name(msg_type), data->callref);
2863 /* Invalid call reference */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002864 return mncc_release_ind(net, NULL, data->callref,
2865 GSM48_CAUSE_LOC_PRN_S_LU,
2866 GSM48_CC_CAUSE_INVAL_TRANS_ID);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002867 }
Andreas Eversbergc079be42009-06-15 23:22:09 +02002868 if (!data->called.number[0] && !data->imsi[0]) {
2869 DEBUGP(DCC, "(bts - trx - ts - ti) "
2870 "Received '%s' from MNCC with "
2871 "no number or IMSI\n", get_mncc_name(msg_type));
2872 /* Invalid number */
2873 return mncc_release_ind(net, NULL, data->callref,
2874 GSM48_CAUSE_LOC_PRN_S_LU,
2875 GSM48_CC_CAUSE_INV_NR_FORMAT);
2876 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002877 /* New transaction due to setup, find subscriber */
Andreas Eversbergc079be42009-06-15 23:22:09 +02002878 if (data->called.number[0])
Harald Welte9176bd42009-07-23 18:46:00 +02002879 subscr = subscr_get_by_extension(net,
2880 data->called.number);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002881 else
Harald Welte9176bd42009-07-23 18:46:00 +02002882 subscr = subscr_get_by_imsi(net, data->imsi);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002883 /* If subscriber is not found */
2884 if (!subscr) {
2885 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2886 "Received '%s' from MNCC with "
2887 "unknown subscriber %s\n", data->called.number,
2888 get_mncc_name(msg_type), data->called.number);
2889 /* Unknown subscriber */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002890 return mncc_release_ind(net, NULL, data->callref,
2891 GSM48_CAUSE_LOC_PRN_S_LU,
2892 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002893 }
2894 /* If subscriber is not "attached" */
2895 if (!subscr->lac) {
2896 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2897 "Received '%s' from MNCC with "
2898 "detached subscriber %s\n", data->called.number,
2899 get_mncc_name(msg_type), data->called.number);
2900 subscr_put(subscr);
2901 /* Temporarily out of order */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002902 return mncc_release_ind(net, NULL, data->callref,
2903 GSM48_CAUSE_LOC_PRN_S_LU,
2904 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002905 }
2906 /* Create transaction */
Harald Weltedcaf5652009-07-23 18:56:43 +02002907 trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref);
2908 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002909 DEBUGP(DCC, "No memory for trans.\n");
2910 subscr_put(subscr);
2911 /* Ressource unavailable */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002912 mncc_release_ind(net, NULL, data->callref,
2913 GSM48_CAUSE_LOC_PRN_S_LU,
2914 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002915 return -ENOMEM;
2916 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002917 /* Find lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002918 conn = connection_for_subscr(subscr);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01002919
Harald Welte4bfdfe72009-06-10 23:11:52 +08002920 /* If subscriber has no lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002921 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002922 /* find transaction with this subscriber already paging */
2923 llist_for_each_entry(transt, &net->trans_list, entry) {
2924 /* Transaction of our lchan? */
2925 if (transt == trans ||
2926 transt->subscr != subscr)
2927 continue;
2928 DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) "
2929 "Received '%s' from MNCC with "
2930 "unallocated channel, paging already "
2931 "started.\n", bts->nr,
2932 data->called.number,
2933 get_mncc_name(msg_type));
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002934 subscr_put(subscr);
2935 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002936 return 0;
2937 }
2938 /* store setup informations until paging was successfull */
Harald Weltedcaf5652009-07-23 18:56:43 +02002939 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
Harald Weltea1b28582009-08-01 19:31:47 +02002940 /* Trigger paging */
2941 paging_request(net, subscr, RSL_CHANNEED_TCH_F,
2942 setup_trig_pag_evt, subscr);
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002943 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002944 return 0;
2945 }
2946 /* Assign lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002947 trans->conn = conn;
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002948 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002949 }
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002950
2951 if (trans->conn)
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002952 conn = trans->conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002953
2954 /* if paging did not respond yet */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002955 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002956 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02002957 "Received '%s' from MNCC in paging state\n",
Harald Welte4bfdfe72009-06-10 23:11:52 +08002958 (trans->subscr)?(trans->subscr->extension):"-",
2959 get_mncc_name(msg_type));
Harald Weltec66b71c2009-06-11 14:23:20 +08002960 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
2961 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002962 if (msg_type == MNCC_REL_REQ)
2963 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
2964 else
2965 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
2966 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002967 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002968 return rc;
2969 }
2970
2971 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) "
2972 "Received '%s' from MNCC in state %d (%s)\n",
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002973 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002974 trans->transaction_id,
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002975 (trans->conn->subscr)?(trans->conn->subscr->extension):"-",
Harald Weltedcaf5652009-07-23 18:56:43 +02002976 get_mncc_name(msg_type), trans->cc.state,
Harald Weltee95daf12010-03-25 12:13:02 +08002977 gsm48_cc_state_name(trans->cc.state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002978
2979 /* Find function for current state and message */
2980 for (i = 0; i < DOWNSLLEN; i++)
2981 if ((msg_type == downstatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02002982 && ((1 << trans->cc.state) & downstatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08002983 break;
2984 if (i == DOWNSLLEN) {
2985 DEBUGP(DCC, "Message unhandled at this state.\n");
2986 return 0;
2987 }
2988
2989 rc = downstatelist[i].rout(trans, arg);
2990
2991 return rc;
2992}
2993
2994
2995static struct datastate {
2996 u_int32_t states;
2997 int type;
2998 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
2999} datastatelist[] = {
3000 /* mobile originating call establishment */
3001 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
3002 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
3003 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
3004 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
3005 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
3006 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
3007 /* mobile terminating call establishment */
3008 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
3009 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
3010 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
3011 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02003012 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF) | SBIT(GSM_CSTATE_CALL_RECEIVED), /* (5.2.2.6) | 5.2.2.6 | 5.2.2.6 */
Harald Welte4bfdfe72009-06-10 23:11:52 +08003013 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
3014 /* signalling during call */
3015 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
3016 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
3017 {SBIT(GSM_CSTATE_ACTIVE),
3018 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
3019 {ALL_STATES,
3020 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
3021 {ALL_STATES,
3022 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
3023 {ALL_STATES,
3024 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
3025 {SBIT(GSM_CSTATE_ACTIVE),
3026 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
3027 {SBIT(GSM_CSTATE_ACTIVE),
3028 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
3029 {SBIT(GSM_CSTATE_ACTIVE),
3030 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
3031 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3032 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
3033 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3034 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
3035 {SBIT(GSM_CSTATE_ACTIVE),
3036 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
3037 /* clearing */
3038 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3039 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
3040 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
3041 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
3042 {ALL_STATES, /* 5.4.3.4 */
3043 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
3044};
3045
3046#define DATASLLEN \
3047 (sizeof(datastatelist) / sizeof(struct datastate))
3048
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003049static int gsm0408_rcv_cc(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4bc90a12008-12-27 16:32:52 +00003050{
3051 struct gsm48_hdr *gh = msgb_l3(msg);
3052 u_int8_t msg_type = gh->msg_type & 0xbf;
Harald Welte6f5aee02009-07-23 21:21:14 +02003053 u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */
Harald Weltedcaf5652009-07-23 18:56:43 +02003054 struct gsm_trans *trans = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003055 int i, rc = 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00003056
Harald Welte4bfdfe72009-06-10 23:11:52 +08003057 if (msg_type & 0x80) {
3058 DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type);
3059 return -EINVAL;
Harald Welte4bc90a12008-12-27 16:32:52 +00003060 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003061
Harald Welte4bfdfe72009-06-10 23:11:52 +08003062 /* Find transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003063 trans = trans_find_by_id(conn->subscr, GSM48_PDISC_CC, transaction_id);
Harald Weltedcaf5652009-07-23 18:56:43 +02003064
Harald Welte6f5aee02009-07-23 21:21:14 +02003065 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003066 "Received '%s' from MS in state %d (%s)\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003067 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003068 transaction_id, (conn->subscr)?(conn->subscr->extension):"-",
Harald Weltee95daf12010-03-25 12:13:02 +08003069 gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0,
3070 gsm48_cc_state_name(trans?(trans->cc.state):0));
Harald Welte4bfdfe72009-06-10 23:11:52 +08003071
3072 /* Create transaction */
3073 if (!trans) {
Harald Welte6f5aee02009-07-23 21:21:14 +02003074 DEBUGP(DCC, "Unknown transaction ID %x, "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003075 "creating new trans.\n", transaction_id);
3076 /* Create transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003077 trans = trans_alloc(conn->subscr, GSM48_PDISC_CC,
Harald Weltedcaf5652009-07-23 18:56:43 +02003078 transaction_id, new_callref++);
3079 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08003080 DEBUGP(DCC, "No memory for trans.\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08003081 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02003082 GSM48_PDISC_CC | (transaction_id << 4),
Harald Welte4bfdfe72009-06-10 23:11:52 +08003083 GSM48_MT_CC_RELEASE_COMPL);
3084 return -ENOMEM;
3085 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08003086 /* Assign transaction */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003087 trans->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003088 }
3089
3090 /* find function for current state and message */
3091 for (i = 0; i < DATASLLEN; i++)
3092 if ((msg_type == datastatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02003093 && ((1 << trans->cc.state) & datastatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08003094 break;
3095 if (i == DATASLLEN) {
3096 DEBUGP(DCC, "Message unhandled at this state.\n");
3097 return 0;
3098 }
3099
3100 rc = datastatelist[i].rout(trans, msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00003101
3102 return rc;
3103}
3104
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003105/* Create a dummy to wait five seconds */
3106static void release_anchor(struct gsm_subscriber_connection *conn)
3107{
3108 if (!conn->anch_operation)
3109 return;
3110
3111 bsc_del_timer(&conn->anch_operation->timeout);
3112 talloc_free(conn->anch_operation);
3113 conn->anch_operation = NULL;
3114}
3115
3116static void anchor_timeout(void *_data)
3117{
3118 struct gsm_subscriber_connection *con = _data;
3119
3120 release_anchor(con);
3121 msc_release_connection(con);
3122}
3123
3124int gsm0408_new_conn(struct gsm_subscriber_connection *conn)
3125{
3126 conn->anch_operation = talloc_zero(conn, struct gsm_anchor_operation);
3127 if (!conn->anch_operation)
3128 return -1;
3129
3130 conn->anch_operation->timeout.data = conn;
3131 conn->anch_operation->timeout.cb = anchor_timeout;
3132 bsc_schedule_timer(&conn->anch_operation->timeout, 5, 0);
3133 return 0;
3134}
3135
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003136/* here we get data from the BSC level... */
3137int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00003138{
3139 struct gsm48_hdr *gh = msgb_l3(msg);
3140 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +00003141 int rc = 0;
Harald Welte51008772009-12-29 11:49:12 +01003142
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +08003143 if (silent_call_reroute(conn, msg))
3144 return silent_call_rx(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003145
3146 switch (pdisc) {
3147 case GSM48_PDISC_CC:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003148 release_anchor(conn);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003149 rc = gsm0408_rcv_cc(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003150 break;
3151 case GSM48_PDISC_MM:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003152 rc = gsm0408_rcv_mm(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003153 break;
3154 case GSM48_PDISC_RR:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003155 rc = gsm0408_rcv_rr(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003156 break;
Harald Weltebcae43f2008-12-27 21:45:37 +00003157 case GSM48_PDISC_SMS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003158 release_anchor(conn);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003159 rc = gsm0411_rcv_sms(conn, msg);
Harald Weltebcae43f2008-12-27 21:45:37 +00003160 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003161 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +00003162 case GSM48_PDISC_SM_GPRS:
Harald Welte5d24ba12009-12-24 12:13:17 +01003163 LOGP(DRLL, LOGL_NOTICE, "Unimplemented "
3164 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003165 break;
Harald Welte6eafe912009-10-16 08:32:58 +02003166 case GSM48_PDISC_NC_SS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003167 release_anchor(conn);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +08003168 rc = handle_rcv_ussd(conn, msg);
Harald Welte6eafe912009-10-16 08:32:58 +02003169 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003170 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01003171 LOGP(DRLL, LOGL_NOTICE, "Unknown "
3172 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003173 break;
3174 }
3175
3176 return rc;
3177}
Harald Welte8470bf22008-12-25 23:28:35 +00003178
Harald Welte805f6442009-07-28 18:25:29 +02003179/*
3180 * This will be ran by the linker when loading the DSO. We use it to
3181 * do system initialization, e.g. registration of signal handlers.
3182 */
3183static __attribute__((constructor)) void on_dso_load_0408(void)
3184{
Harald Welte805f6442009-07-28 18:25:29 +02003185 register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL);
3186}