blob: 5eb6a241c2feaf5498633b6a419c86593bffddfd [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>
Holger Hans Peter Freyther12eb9b72010-09-30 18:53:47 +080056#include <osmocore/gsm0480.h>
Holger Hans Peter Freyther841c2002010-09-30 18:52:23 +080057#include <osmocore/gsm_utils.h>
58#include <osmocore/msgb.h>
59#include <osmocore/talloc.h>
60#include <osmocore/tlv.h>
Harald Welte52b1f982008-12-23 20:25:15 +000061
Harald Welte (local)d19e58b2009-08-15 02:30:58 +020062void *tall_locop_ctx;
Sylvain Munaut30a15382009-12-24 00:27:26 +010063void *tall_authciphop_ctx;
Harald Welte2cf161b2009-06-20 22:36:41 +020064
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +080065int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +080066static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte65e74cc2008-12-29 01:55:35 +000067 u_int8_t pdisc, u_int8_t msg_type);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010068static void schedule_reject(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080069static void release_anchor(struct gsm_subscriber_connection *conn);
Harald Welte65e74cc2008-12-29 01:55:35 +000070
Harald Welte52b1f982008-12-23 20:25:15 +000071struct gsm_lai {
72 u_int16_t mcc;
73 u_int16_t mnc;
74 u_int16_t lac;
75};
76
Harald Welte4bfdfe72009-06-10 23:11:52 +080077static u_int32_t new_callref = 0x80000001;
78
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +080079static int gsm48_conn_sendmsg(struct msgb *msg, struct gsm_subscriber_connection *conn,
80 struct gsm_trans *trans)
81{
82 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
83
84 /* if we get passed a transaction reference, do some common
85 * work that the caller no longer has to do */
86 if (trans) {
87 gh->proto_discr = trans->protocol | (trans->transaction_id << 4);
88 msg->lchan = trans->conn->lchan;
89 }
90
91
92 if (msg->lchan) {
93 msg->trx = msg->lchan->ts->trx;
94 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC)
95 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x) "
96 "Sending '%s' to MS.\n", msg->trx->bts->nr,
97 msg->trx->nr, msg->lchan->ts->nr,
98 gh->proto_discr & 0xf0,
99 gsm48_cc_msg_name(gh->msg_type));
100 else
101 DEBUGP(DCC, "(bts %d trx %d ts %d pd %02x) "
102 "Sending 0x%02x to MS.\n", msg->trx->bts->nr,
103 msg->trx->nr, msg->lchan->ts->nr,
104 gh->proto_discr, gh->msg_type);
105 }
106
Holger Hans Peter Freyther8d380dc2010-11-10 10:16:02 +0100107 return gsm0808_submit_dtap(conn, msg, 0, 0);
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800108}
Sylvain Munaut30a15382009-12-24 00:27:26 +0100109
Holger Hans Peter Freythere0009f12010-08-12 01:41:57 +0800110int gsm48_cc_tx_notify_ss(struct gsm_trans *trans, const char *message)
111{
112 struct gsm48_hdr *gh;
113 struct msgb *ss_notify;
114
115 ss_notify = gsm0480_create_notifySS(message);
116 if (!ss_notify)
117 return -1;
118
119 gsm0480_wrap_invoke(ss_notify, GSM0480_OP_CODE_NOTIFY_SS, 0);
120 uint8_t *data = msgb_push(ss_notify, 1);
121 data[0] = ss_notify->len - 1;
122 gh = (struct gsm48_hdr *) msgb_push(ss_notify, sizeof(*gh));
123 gh->msg_type = GSM48_MT_CC_FACILITY;
124 return gsm48_conn_sendmsg(ss_notify, trans->conn, trans);
125}
126
Sylvain Munaut30a15382009-12-24 00:27:26 +0100127static void release_security_operation(struct gsm_subscriber_connection *conn)
128{
129 if (!conn->sec_operation)
130 return;
131
132 talloc_free(conn->sec_operation);
133 conn->sec_operation = NULL;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800134 msc_release_connection(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100135}
136
137static void allocate_security_operation(struct gsm_subscriber_connection *conn)
138{
Sylvain Munaut30a15382009-12-24 00:27:26 +0100139 conn->sec_operation = talloc_zero(tall_authciphop_ctx,
140 struct gsm_security_operation);
141}
142
Sylvain Munaut0fbfd1b2010-12-01 22:37:05 +0100143int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq,
144 gsm_cbfn *cb, void *cb_data)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100145{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800146 struct gsm_network *net = conn->bts->network;
147 struct gsm_subscriber *subscr = conn->subscr;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100148 struct gsm_security_operation *op;
149 struct gsm_auth_tuple atuple;
150 int status = -1, rc;
151
152 /* Check if we _can_ enable encryption. Cases where we can't:
153 * - Encryption disabled in config
154 * - Channel already secured (nothing to do)
155 * - Subscriber equipment doesn't support configured encryption
156 */
157 if (!net->a5_encryption) {
158 status = GSM_SECURITY_NOAVAIL;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800159 } else if (conn->lchan->encr.alg_id > RSL_ENC_ALG_A5(0)) {
Sylvain Munaut30a15382009-12-24 00:27:26 +0100160 DEBUGP(DMM, "Requesting to secure an already secure channel");
161 status = GSM_SECURITY_SUCCEEDED;
162 } else if (!ms_cm2_a5n_support(subscr->equipment.classmark2,
163 net->a5_encryption)) {
164 DEBUGP(DMM, "Subscriber equipment doesn't support requested encryption");
165 status = GSM_SECURITY_NOAVAIL;
166 }
167
168 /* If not done yet, try to get info for this user */
169 if (status < 0) {
170 rc = auth_get_tuple_for_subscr(&atuple, subscr, key_seq);
171 if (rc <= 0)
172 status = GSM_SECURITY_NOAVAIL;
173 }
174
175 /* Are we done yet ? */
176 if (status >= 0)
177 return cb ?
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800178 cb(GSM_HOOK_RR_SECURITY, status, NULL, conn, cb_data) :
Sylvain Munaut30a15382009-12-24 00:27:26 +0100179 0;
180
181 /* Start an operation (can't have more than one pending !!!) */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800182 if (conn->sec_operation)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100183 return -EBUSY;
184
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800185 allocate_security_operation(conn);
186 op = conn->sec_operation;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100187 op->cb = cb;
188 op->cb_data = cb_data;
189 memcpy(&op->atuple, &atuple, sizeof(struct gsm_auth_tuple));
190
191 /* FIXME: Should start a timer for completion ... */
192
193 /* Then do whatever is needed ... */
194 if (rc == 1) {
195 /* Start authentication */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800196 return gsm48_tx_mm_auth_req(conn, op->atuple.rand, op->atuple.key_seq);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100197 } else if (rc == 2) {
198 /* Start ciphering directly */
Sylvain Munaut67706df2010-11-29 08:19:04 +0100199 return gsm0808_cipher_mode(conn, net->a5_encryption,
200 op->atuple.kc, 8, 0);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100201 }
202
203 return -EINVAL; /* not reached */
204}
205
Holger Freyther73487a22008-12-31 18:53:57 +0000206static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
207 struct gsm_subscriber *subscriber)
Holger Freyther89824fc2008-12-30 16:18:18 +0000208{
209 if (!subscriber)
210 return 0;
211
Holger Freyther73487a22008-12-31 18:53:57 +0000212 /*
213 * Do not send accept yet as more information should arrive. Some
214 * phones will not send us the information and we will have to check
215 * what we want to do with that.
216 */
217 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
218 return 0;
219
Jan Luebbe06513f22009-08-12 12:48:00 +0200220 switch (subscriber->net->auth_policy) {
221 case GSM_AUTH_POLICY_CLOSED:
222 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200223 case GSM_AUTH_POLICY_TOKEN:
Harald Welte (local)ee9afe32009-08-13 20:44:23 +0200224 if (subscriber->authorized)
225 return subscriber->authorized;
Harald Welte (local)aa9dc192009-08-13 13:49:51 +0200226 return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
Jan Luebbe06513f22009-08-12 12:48:00 +0200227 case GSM_AUTH_POLICY_ACCEPT_ALL:
Holger Freyther89824fc2008-12-30 16:18:18 +0000228 return 1;
Jan Luebbe06513f22009-08-12 12:48:00 +0200229 default:
230 return 0;
231 }
Holger Freyther89824fc2008-12-30 16:18:18 +0000232}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000233
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100234static void release_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000235{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100236 if (!conn->loc_operation)
Holger Freyther73487a22008-12-31 18:53:57 +0000237 return;
238
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800239 /* No need to keep the connection up */
240 release_anchor(conn);
241
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100242 bsc_del_timer(&conn->loc_operation->updating_timer);
243 talloc_free(conn->loc_operation);
Holger Hans Peter Freytherf93e8fa2010-12-22 08:53:28 +0100244 conn->loc_operation = NULL;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800245 msc_release_connection(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000246}
247
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100248static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
Holger Freyther73487a22008-12-31 18:53:57 +0000249{
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800250 if (conn->loc_operation)
251 LOGP(DMM, LOGL_ERROR, "Connection already had operation.\n");
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100252 release_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000253
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100254 conn->loc_operation = talloc_zero(tall_locop_ctx,
Harald Welte470ec292009-06-26 20:25:23 +0200255 struct gsm_loc_updating_operation);
Holger Freyther73487a22008-12-31 18:53:57 +0000256}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000257
Sylvain Munaut267fba02009-12-24 00:28:01 +0100258static int _gsm0408_authorize_sec_cb(unsigned int hooknum, unsigned int event,
259 struct msgb *msg, void *data, void *param)
260{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800261 struct gsm_subscriber_connection *conn = data;
Sylvain Munaut267fba02009-12-24 00:28:01 +0100262 int rc = 0;
263
264 switch (event) {
265 case GSM_SECURITY_AUTH_FAILED:
266 release_loc_updating_req(conn);
267 break;
268
269 case GSM_SECURITY_NOAVAIL:
270 case GSM_SECURITY_SUCCEEDED:
271 /* We're all good */
272 db_subscriber_alloc_tmsi(conn->subscr);
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800273 rc = gsm0408_loc_upd_acc(conn, conn->subscr->tmsi);
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800274 if (conn->bts->network->send_mm_info) {
Sylvain Munaut267fba02009-12-24 00:28:01 +0100275 /* send MM INFO with network name */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800276 rc = gsm48_tx_mm_info(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100277 }
278
279 /* call subscr_update after putting the loc_upd_acc
280 * in the transmit queue, since S_SUBSCR_ATTACHED might
281 * trigger further action like SMS delivery */
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800282 subscr_update(conn->subscr, conn->bts,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100283 GSM_SUBSCRIBER_UPDATE_ATTACHED);
284
285 /* try to close channel ASAP */
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800286 release_loc_updating_req(conn);
Sylvain Munaut267fba02009-12-24 00:28:01 +0100287 break;
288
289 default:
290 rc = -EINVAL;
291 };
292
293 return rc;
294}
295
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100296static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb *msg)
Holger Freytherd51524f2009-06-09 08:27:07 +0000297{
Sylvain Munaut267fba02009-12-24 00:28:01 +0100298 if (authorize_subscriber(conn->loc_operation, conn->subscr))
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800299 return gsm48_secure_channel(conn,
Sylvain Munaut267fba02009-12-24 00:28:01 +0100300 conn->loc_operation->key_seq,
301 _gsm0408_authorize_sec_cb, NULL);
Holger Freytherd51524f2009-06-09 08:27:07 +0000302 return 0;
303}
304
Holger Hans Peter Freytheradb6e1c2010-09-18 06:44:24 +0800305void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
Holger Freyther7c19f742009-06-06 13:54:35 +0000306{
Harald Welte4bfdfe72009-06-10 23:11:52 +0800307 struct gsm_trans *trans, *temp;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800308
309 /* avoid someone issuing a clear */
310 conn->in_release = 1;
311
Holger Freyther7c19f742009-06-06 13:54:35 +0000312 /*
313 * Cancel any outstanding location updating request
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800314 * operation taking place on the subscriber connection.
Holger Freyther7c19f742009-06-06 13:54:35 +0000315 */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800316 release_loc_updating_req(conn);
317 release_security_operation(conn);
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800318 release_anchor(conn);
Holger Freyther7c19f742009-06-06 13:54:35 +0000319
Harald Welte4bfdfe72009-06-10 23:11:52 +0800320 /* Free all transactions that are associated with the released lchan */
Harald Weltedcaf5652009-07-23 18:56:43 +0200321 /* FIXME: this is not neccessarily the right thing to do, we should
322 * only set trans->lchan to NULL and wait for another lchan to be
323 * established to the same MM entity (phone/subscriber) */
Holger Hans Peter Freytherf6fb3ef2010-06-15 13:16:52 +0800324 llist_for_each_entry_safe(trans, temp, &conn->bts->network->trans_list, entry) {
325 if (trans->conn == conn)
Harald Weltedcaf5652009-07-23 18:56:43 +0200326 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800327 }
Holger Freyther7c19f742009-06-06 13:54:35 +0000328}
329
Holger Freyther429e7762008-12-30 13:28:30 +0000330/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800331int gsm0408_loc_upd_rej(struct gsm_subscriber_connection *conn, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000332{
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800333 struct gsm_bts *bts = conn->bts;
Holger Hans Peter Freyther230a4d82010-06-15 19:40:05 +0800334 struct msgb *msg;
335
336 counter_inc(bts->network->stats.loc_upd_resp.reject);
337
338 msg = gsm48_create_loc_upd_rej(cause);
339 if (!msg) {
340 LOGP(DMM, LOGL_ERROR, "Failed to create msg for LOCATION UPDATING REJECT.\n");
341 return -1;
342 }
Harald Welte52b1f982008-12-23 20:25:15 +0000343
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800344 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000345
Harald Welte (local)198d5ad2009-12-26 22:15:28 +0100346 LOGP(DMM, LOGL_INFO, "Subscriber %s: LOCATION UPDATING REJECT "
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100347 "LAC=%u BTS=%u\n", conn->subscr ?
348 subscr_name(conn->subscr) : "unknown",
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800349 bts->location_area_code, bts->nr);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100350
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800351 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000352}
353
354/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800355int gsm0408_loc_upd_acc(struct gsm_subscriber_connection *conn, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000356{
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800357 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000358 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000359 struct gsm48_hdr *gh;
360 struct gsm48_loc_area_id *lai;
361 u_int8_t *mid;
362
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800363 msg->lchan = conn->lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000364
365 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
366 gh->proto_discr = GSM48_PDISC_MM;
367 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
368
369 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Harald Welteafedeab2010-03-04 10:55:40 +0100370 gsm48_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000371 bts->network->network_code, bts->location_area_code);
372
Holger Hans Peter Freyther1494a762009-08-01 07:26:59 +0200373 mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
Holger Hans Peter Freyther5d0e56f2009-08-20 08:41:24 +0200374 gsm48_generate_mid_from_tmsi(mid, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000375
376 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
377
Harald Welteffa55a42009-12-22 19:07:32 +0100378 counter_inc(bts->network->stats.loc_upd_resp.accept);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100379
Holger Hans Peter Freytherdc5db242010-06-15 14:07:27 +0800380 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000381}
382
Harald Weltebf5e8df2009-02-03 12:59:45 +0000383/* Transmit Chapter 9.2.10 Identity Request */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800384static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, u_int8_t id_type)
Harald Welte231ad4f2008-12-27 11:15:38 +0000385{
386 struct msgb *msg = gsm48_msgb_alloc();
387 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000388
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800389 msg->lchan = conn->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000390
391 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
392 gh->proto_discr = GSM48_PDISC_MM;
393 gh->msg_type = GSM48_MT_MM_ID_REQ;
394 gh->data[0] = id_type;
395
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800396 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte231ad4f2008-12-27 11:15:38 +0000397}
398
Harald Welte231ad4f2008-12-27 11:15:38 +0000399
Harald Weltebf5e8df2009-02-03 12:59:45 +0000400/* Parse Chapter 9.2.11 Identity Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800401static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte231ad4f2008-12-27 11:15:38 +0000402{
403 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000404 struct gsm_lchan *lchan = msg->lchan;
Harald Welte9176bd42009-07-23 18:46:00 +0200405 struct gsm_bts *bts = lchan->ts->trx->bts;
406 struct gsm_network *net = bts->network;
Harald Welte231ad4f2008-12-27 11:15:38 +0000407 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200408 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000409
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200410 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000411 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000412 mi_type, mi_string);
413
Harald Welte7659de12009-12-13 12:39:18 +0100414 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, gh->data);
415
Harald Welte75a983f2008-12-27 21:34:06 +0000416 switch (mi_type) {
417 case GSM_MI_TYPE_IMSI:
Jan Luebbe370b41d2009-08-12 10:19:34 +0200418 /* look up subscriber based on IMSI, create if not found */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100419 if (!conn->subscr) {
420 conn->subscr = subscr_get_by_imsi(net, mi_string);
421 if (!conn->subscr)
422 conn->subscr = db_create_subscriber(net, mi_string);
Jan Luebbeb0dfc312009-08-12 10:12:52 +0200423 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100424 if (conn->loc_operation)
425 conn->loc_operation->waiting_for_imsi = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000426 break;
427 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000428 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000429 /* update subscribe <-> IMEI mapping */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100430 if (conn->subscr) {
431 db_subscriber_assoc_imei(conn->subscr, mi_string);
432 db_sync_equipment(&conn->subscr->equipment);
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200433 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100434 if (conn->loc_operation)
435 conn->loc_operation->waiting_for_imei = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000436 break;
437 }
Holger Freyther73487a22008-12-31 18:53:57 +0000438
439 /* Check if we can let the mobile station enter */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100440 return gsm0408_authorize(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000441}
442
Harald Welte255539c2008-12-28 02:26:27 +0000443
444static void loc_upd_rej_cb(void *data)
445{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100446 struct gsm_subscriber_connection *conn = data;
447 struct gsm_lchan *lchan = conn->lchan;
Harald Welte1085c092009-11-18 20:33:19 +0100448 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte255539c2008-12-28 02:26:27 +0000449
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800450 gsm0408_loc_upd_rej(conn, bts->network->reject_cause);
Holger Hans Peter Freyther01288432010-06-16 12:52:28 +0800451 release_loc_updating_req(conn);
Harald Welte255539c2008-12-28 02:26:27 +0000452}
453
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100454static void schedule_reject(struct gsm_subscriber_connection *conn)
Holger Freytherb7193e42008-12-29 17:44:08 +0000455{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100456 conn->loc_operation->updating_timer.cb = loc_upd_rej_cb;
457 conn->loc_operation->updating_timer.data = conn;
458 bsc_schedule_timer(&conn->loc_operation->updating_timer, 5, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000459}
460
Harald Welte2a139372009-02-22 21:14:55 +0000461static const char *lupd_name(u_int8_t type)
462{
463 switch (type) {
464 case GSM48_LUPD_NORMAL:
465 return "NORMAL";
466 case GSM48_LUPD_PERIODIC:
467 return "PEROIDOC";
468 case GSM48_LUPD_IMSI_ATT:
469 return "IMSI ATTACH";
470 default:
471 return "UNKNOWN";
472 }
473}
474
Harald Weltebf5e8df2009-02-03 12:59:45 +0000475/* Chapter 9.2.15: Receive Location Updating Request */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800476static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000477{
Harald Welte8470bf22008-12-25 23:28:35 +0000478 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000479 struct gsm48_loc_upd_req *lu;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800480 struct gsm_subscriber *subscr = NULL;
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800481 struct gsm_bts *bts = conn->bts;
Harald Welte8470bf22008-12-25 23:28:35 +0000482 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200483 char mi_string[GSM48_MI_SIZE];
Harald Welte231ad4f2008-12-27 11:15:38 +0000484 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000485
Harald Welte8470bf22008-12-25 23:28:35 +0000486 lu = (struct gsm48_loc_upd_req *) gh->data;
487
488 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000489
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200490 gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
Harald Weltefc977a82008-12-27 10:19:37 +0000491
Harald Weltea0368542009-06-27 02:58:43 +0200492 DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
Harald Welte2a139372009-02-22 21:14:55 +0000493 lupd_name(lu->type));
Holger Freyther73487a22008-12-31 18:53:57 +0000494
Harald Welte7659de12009-12-13 12:39:18 +0100495 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, &lu->mi_len);
496
Harald Welte24ff6ee2009-12-22 00:41:05 +0100497 switch (lu->type) {
498 case GSM48_LUPD_NORMAL:
Harald Welteffa55a42009-12-22 19:07:32 +0100499 counter_inc(bts->network->stats.loc_upd_type.normal);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100500 break;
501 case GSM48_LUPD_IMSI_ATT:
Harald Welteffa55a42009-12-22 19:07:32 +0100502 counter_inc(bts->network->stats.loc_upd_type.attach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100503 break;
504 case GSM48_LUPD_PERIODIC:
Harald Welteffa55a42009-12-22 19:07:32 +0100505 counter_inc(bts->network->stats.loc_upd_type.periodic);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100506 break;
507 }
508
Holger Freythereaf04692009-06-06 13:54:44 +0000509 /*
510 * Pseudo Spoof detection: Just drop a second/concurrent
511 * location updating request.
512 */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100513 if (conn->loc_operation) {
Harald Weltea0368542009-06-27 02:58:43 +0200514 DEBUGPC(DMM, "ignoring request due an existing one: %p.\n",
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100515 conn->loc_operation);
Holger Hans Peter Freyther7bc5ba32010-06-15 14:09:34 +0800516 gsm0408_loc_upd_rej(conn, GSM48_REJECT_PROTOCOL_ERROR);
Holger Freythereaf04692009-06-06 13:54:44 +0000517 return 0;
518 }
519
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800520 allocate_loc_updating_req(conn);
Holger Freyther73487a22008-12-31 18:53:57 +0000521
Sylvain Munaut2030a2a2010-06-10 13:36:59 +0200522 conn->loc_operation->key_seq = lu->key_seq;
523
Harald Welte52b1f982008-12-23 20:25:15 +0000524 switch (mi_type) {
525 case GSM_MI_TYPE_IMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200526 DEBUGPC(DMM, "\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000527 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800528 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100529 conn->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000530
Jan Luebbe370b41d2009-08-12 10:19:34 +0200531 /* look up subscriber based on IMSI, create if not found */
532 subscr = subscr_get_by_imsi(bts->network, mi_string);
533 if (!subscr) {
534 subscr = db_create_subscriber(bts->network, mi_string);
535 }
Harald Welte4b634542008-12-27 01:55:51 +0000536 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000537 case GSM_MI_TYPE_TMSI:
Harald Weltea0368542009-06-27 02:58:43 +0200538 DEBUGPC(DMM, "\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000539 /* look up the subscriber based on TMSI, request IMSI if it fails */
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200540 subscr = subscr_get_by_tmsi(bts->network,
541 tmsi_from_string(mi_string));
Harald Welte52b1f982008-12-23 20:25:15 +0000542 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000543 /* send IDENTITY REQUEST message to get IMSI */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800544 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMSI);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100545 conn->loc_operation->waiting_for_imsi = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000546 }
Harald Weltef5f512c2010-06-07 17:56:32 +0200547 /* we always want the IMEI, too */
Holger Hans Peter Freytherd521d972010-06-15 14:11:01 +0800548 rc = mm_tx_identity_req(conn, GSM_MI_TYPE_IMEI);
Harald Weltef5f512c2010-06-07 17:56:32 +0200549 conn->loc_operation->waiting_for_imei = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000550 break;
551 case GSM_MI_TYPE_IMEI:
552 case GSM_MI_TYPE_IMEISV:
553 /* no sim card... FIXME: what to do ? */
Harald Weltea0368542009-06-27 02:58:43 +0200554 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000555 break;
556 default:
Harald Weltea0368542009-06-27 02:58:43 +0200557 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000558 break;
559 }
560
Harald Welte24516ea2009-07-04 10:18:00 +0200561 /* schedule the reject timer */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100562 schedule_reject(conn);
Harald Welte24516ea2009-07-04 10:18:00 +0200563
Harald Welte4bfdfe72009-06-10 23:11:52 +0800564 if (!subscr) {
Harald Weltea0368542009-06-27 02:58:43 +0200565 DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte4bfdfe72009-06-10 23:11:52 +0800566 /* FIXME: request id? close channel? */
567 return -EINVAL;
568 }
569
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100570 conn->subscr = subscr;
571 conn->subscr->equipment.classmark1 = lu->classmark1;
Harald Welte255539c2008-12-28 02:26:27 +0000572
Harald Welte24516ea2009-07-04 10:18:00 +0200573 /* check if we can let the subscriber into our network immediately
574 * or if we need to wait for identity responses. */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100575 return gsm0408_authorize(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000576}
577
Harald Welte4bfdfe72009-06-10 23:11:52 +0800578#if 0
579static u_int8_t to_bcd8(u_int8_t val)
580{
581 return ((val / 10) << 4) | (val % 10);
582}
583#endif
584
Harald Weltedb253af2008-12-30 17:56:55 +0000585/* Section 9.2.15a */
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800586int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
Harald Weltedb253af2008-12-30 17:56:55 +0000587{
588 struct msgb *msg = gsm48_msgb_alloc();
589 struct gsm48_hdr *gh;
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800590 struct gsm_network *net = conn->bts->network;
Harald Weltedb253af2008-12-30 17:56:55 +0000591 u_int8_t *ptr8;
Daniel Willmanneea93372009-08-13 03:42:07 +0200592 int name_len, name_pad;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800593#if 0
594 time_t cur_t;
595 struct tm* cur_time;
596 int tz15min;
597#endif
Harald Weltedb253af2008-12-30 17:56:55 +0000598
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800599 msg->lchan = conn->lchan;
Harald Weltedb253af2008-12-30 17:56:55 +0000600
601 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
602 gh->proto_discr = GSM48_PDISC_MM;
603 gh->msg_type = GSM48_MT_MM_INFO;
604
605 if (net->name_long) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200606#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000607 name_len = strlen(net->name_long);
608 /* 10.5.3.5a */
609 ptr8 = msgb_put(msg, 3);
610 ptr8[0] = GSM48_IE_NAME_LONG;
611 ptr8[1] = name_len*2 +1;
612 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
613
614 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
615 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000616 ptr16[i] = htons(net->name_long[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000617
618 /* FIXME: Use Cell Broadcast, not UCS-2, since
619 * UCS-2 is only supported by later revisions of the spec */
Daniel Willmanneea93372009-08-13 03:42:07 +0200620#endif
621 name_len = (strlen(net->name_long)*7)/8;
622 name_pad = (8 - strlen(net->name_long)*7)%8;
623 if (name_pad > 0)
624 name_len++;
625 /* 10.5.3.5a */
626 ptr8 = msgb_put(msg, 3);
627 ptr8[0] = GSM48_IE_NAME_LONG;
628 ptr8[1] = name_len +1;
629 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
630
631 ptr8 = msgb_put(msg, name_len);
632 gsm_7bit_encode(ptr8, net->name_long);
633
Harald Weltedb253af2008-12-30 17:56:55 +0000634 }
635
636 if (net->name_short) {
Daniel Willmanneea93372009-08-13 03:42:07 +0200637#if 0
Harald Weltedb253af2008-12-30 17:56:55 +0000638 name_len = strlen(net->name_short);
639 /* 10.5.3.5a */
640 ptr8 = (u_int8_t *) msgb_put(msg, 3);
Harald Welte7543eb72009-07-19 17:51:36 +0200641 ptr8[0] = GSM48_IE_NAME_SHORT;
Harald Weltedb253af2008-12-30 17:56:55 +0000642 ptr8[1] = name_len*2 + 1;
643 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
644
Harald Weltee872cb12009-01-01 00:33:37 +0000645 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
Harald Weltedb253af2008-12-30 17:56:55 +0000646 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000647 ptr16[i] = htons(net->name_short[i]);
Daniel Willmanneea93372009-08-13 03:42:07 +0200648#endif
649 name_len = (strlen(net->name_short)*7)/8;
650 name_pad = (8 - strlen(net->name_short)*7)%8;
651 if (name_pad > 0)
652 name_len++;
653 /* 10.5.3.5a */
654 ptr8 = (u_int8_t *) msgb_put(msg, 3);
655 ptr8[0] = GSM48_IE_NAME_SHORT;
656 ptr8[1] = name_len +1;
657 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
658
659 ptr8 = msgb_put(msg, name_len);
660 gsm_7bit_encode(ptr8, net->name_short);
661
Harald Weltedb253af2008-12-30 17:56:55 +0000662 }
663
664#if 0
665 /* Section 10.5.3.9 */
666 cur_t = time(NULL);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800667 cur_time = gmtime(&cur_t);
Harald Weltedb253af2008-12-30 17:56:55 +0000668 ptr8 = msgb_put(msg, 8);
669 ptr8[0] = GSM48_IE_NET_TIME_TZ;
670 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
671 ptr8[2] = to_bcd8(cur_time->tm_mon);
672 ptr8[3] = to_bcd8(cur_time->tm_mday);
673 ptr8[4] = to_bcd8(cur_time->tm_hour);
674 ptr8[5] = to_bcd8(cur_time->tm_min);
675 ptr8[6] = to_bcd8(cur_time->tm_sec);
676 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
677 tz15min = (cur_time->tm_gmtoff)/(60*15);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800678 ptr8[7] = to_bcd8(tz15min);
Harald Weltedb253af2008-12-30 17:56:55 +0000679 if (tz15min < 0)
Harald Welte4bfdfe72009-06-10 23:11:52 +0800680 ptr8[7] |= 0x80;
Harald Weltedb253af2008-12-30 17:56:55 +0000681#endif
682
Daniel Willmanneea93372009-08-13 03:42:07 +0200683 DEBUGP(DMM, "-> MM INFO\n");
684
Holger Hans Peter Freyther91401742010-06-15 14:16:02 +0800685 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Weltedb253af2008-12-30 17:56:55 +0000686}
687
Harald Welte7984d5c2009-08-12 22:56:50 +0200688/* Section 9.2.2 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800689int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, u_int8_t *rand, int key_seq)
Harald Welte7984d5c2009-08-12 22:56:50 +0200690{
691 struct msgb *msg = gsm48_msgb_alloc();
692 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Sylvain Munaut849f5542009-09-27 11:10:17 +0200693 struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar));
Harald Welte7984d5c2009-08-12 22:56:50 +0200694
Sylvain Munaut8608e7c2009-12-24 00:24:29 +0100695 DEBUGP(DMM, "-> AUTH REQ (rand = %s)\n", hexdump(rand, 16));
Harald Welte7984d5c2009-08-12 22:56:50 +0200696
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800697 msg->lchan = conn->lchan;
Harald Welte7984d5c2009-08-12 22:56:50 +0200698 gh->proto_discr = GSM48_PDISC_MM;
699 gh->msg_type = GSM48_MT_MM_AUTH_REQ;
700
Sylvain Munautbd55a6d2009-12-24 00:23:46 +0100701 ar->key_seq = key_seq;
Sylvain Munaut849f5542009-09-27 11:10:17 +0200702
Harald Welte7984d5c2009-08-12 22:56:50 +0200703 /* 16 bytes RAND parameters */
Harald Welte7984d5c2009-08-12 22:56:50 +0200704 if (rand)
Sylvain Munaut849f5542009-09-27 11:10:17 +0200705 memcpy(ar->rand, rand, 16);
Harald Welte7984d5c2009-08-12 22:56:50 +0200706
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800707 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte7984d5c2009-08-12 22:56:50 +0200708}
709
710/* Section 9.2.1 */
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800711int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn)
Harald Welte7984d5c2009-08-12 22:56:50 +0200712{
713 DEBUGP(DMM, "-> AUTH REJECT\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800714 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ);
Harald Welte7984d5c2009-08-12 22:56:50 +0200715}
716
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800717static int gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
Harald Welte4b634542008-12-27 01:55:51 +0000718{
Harald Welte4b634542008-12-27 01:55:51 +0000719 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800720 return gsm48_tx_simple(conn, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000721}
Harald Welteba4cf162009-01-10 01:49:35 +0000722
723/* 9.2.6 CM service reject */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100724static int gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000725 enum gsm48_reject_value value)
726{
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800727 struct msgb *msg;
Harald Welteba4cf162009-01-10 01:49:35 +0000728
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800729 msg = gsm48_create_mm_serv_rej(value);
730 if (!msg) {
731 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
732 return -1;
733 }
Harald Welteba4cf162009-01-10 01:49:35 +0000734
Holger Hans Peter Freyther2c0f1662010-06-15 19:39:27 +0800735 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100736 msg->lchan = conn->lchan;
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +0800737 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welteba4cf162009-01-10 01:49:35 +0000738}
739
Sylvain Munautba87f452009-12-24 00:28:46 +0100740static int _gsm48_rx_mm_serv_req_sec_cb(
741 unsigned int hooknum, unsigned int event,
742 struct msgb *msg, void *data, void *param)
743{
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800744 struct gsm_subscriber_connection *conn = data;
Sylvain Munautba87f452009-12-24 00:28:46 +0100745 int rc = 0;
746
747 switch (event) {
748 case GSM_SECURITY_AUTH_FAILED:
749 /* Nothing to do */
750 break;
751
752 case GSM_SECURITY_NOAVAIL:
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800753 rc = gsm48_tx_mm_serv_ack(conn);
Sylvain Munautba87f452009-12-24 00:28:46 +0100754 break;
755
756 case GSM_SECURITY_SUCCEEDED:
757 /* nothing to do. CIPHER MODE COMMAND is
758 * implicit CM SERV ACK */
759 break;
760
761 default:
762 rc = -EINVAL;
763 };
764
765 return rc;
766}
767
Harald Welte4ed0e922009-01-10 03:17:30 +0000768/*
769 * Handle CM Service Requests
770 * a) Verify that the packet is long enough to contain the information
771 * we require otherwsie reject with INCORRECT_MESSAGE
772 * b) Try to parse the TMSI. If we do not have one reject
773 * c) Check that we know the subscriber with the TMSI otherwise reject
774 * with a HLR cause
775 * d) Set the subscriber on the gsm_lchan and accept
776 */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800777static int gsm48_rx_mm_serv_req(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4b634542008-12-27 01:55:51 +0000778{
Harald Welteba4cf162009-01-10 01:49:35 +0000779 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200780 char mi_string[GSM48_MI_SIZE];
Harald Welte4b634542008-12-27 01:55:51 +0000781
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800782 struct gsm_bts *bts = conn->bts;
Harald Welteba4cf162009-01-10 01:49:35 +0000783 struct gsm_subscriber *subscr;
784 struct gsm48_hdr *gh = msgb_l3(msg);
785 struct gsm48_service_request *req =
786 (struct gsm48_service_request *)gh->data;
Holger Hans Peter Freyther5d658062010-05-14 08:02:08 +0800787 /* unfortunately in Phase1 the classmark2 length is variable */
Harald Weltec9e02182009-05-01 19:07:53 +0000788 u_int8_t classmark2_len = gh->data[1];
789 u_int8_t *classmark2 = gh->data+2;
790 u_int8_t mi_len = *(classmark2 + classmark2_len);
791 u_int8_t *mi = (classmark2 + classmark2_len + 1);
Harald Welteba4cf162009-01-10 01:49:35 +0000792
Harald Weltec9e02182009-05-01 19:07:53 +0000793 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
Harald Welteba4cf162009-01-10 01:49:35 +0000794 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
Harald Weltec9e02182009-05-01 19:07:53 +0000795 DEBUGPC(DMM, "wrong sized message\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800796 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000797 GSM48_REJECT_INCORRECT_MESSAGE);
798 }
799
800 if (msg->data_len < req->mi_len + 6) {
Harald Weltec9e02182009-05-01 19:07:53 +0000801 DEBUGPC(DMM, "does not fit in packet\n");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800802 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000803 GSM48_REJECT_INCORRECT_MESSAGE);
804 }
805
Harald Weltec9e02182009-05-01 19:07:53 +0000806 mi_type = mi[0] & GSM_MI_TYPE_MASK;
Harald Welteba4cf162009-01-10 01:49:35 +0000807 if (mi_type != GSM_MI_TYPE_TMSI) {
Harald Weltec9e02182009-05-01 19:07:53 +0000808 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800809 return gsm48_tx_mm_serv_rej(conn,
Harald Welteba4cf162009-01-10 01:49:35 +0000810 GSM48_REJECT_INCORRECT_MESSAGE);
811 }
812
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200813 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Weltec9e02182009-05-01 19:07:53 +0000814 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
Harald Welte4ed0e922009-01-10 03:17:30 +0000815 req->cm_service_type, mi_type, mi_string);
Harald Weltebcae43f2008-12-27 21:45:37 +0000816
Harald Welte7659de12009-12-13 12:39:18 +0100817 dispatch_signal(SS_SUBSCR, S_SUBSCR_IDENTITY, (classmark2 + classmark2_len));
818
Harald Welte3ac7f102009-08-10 10:12:45 +0200819 if (is_siemens_bts(bts))
820 send_siemens_mrpci(msg->lchan, classmark2-1);
821
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200822 subscr = subscr_get_by_tmsi(bts->network,
823 tmsi_from_string(mi_string));
Holger Freythereb443982009-06-04 13:58:42 +0000824
Harald Welte2a139372009-02-22 21:14:55 +0000825 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
Harald Welte4ed0e922009-01-10 03:17:30 +0000826 if (!subscr)
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800827 return gsm48_tx_mm_serv_rej(conn,
Harald Welte4ed0e922009-01-10 03:17:30 +0000828 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
829
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800830 if (!conn->subscr)
831 conn->subscr = subscr;
832 else if (conn->subscr == subscr)
Sylvain Munautea3f6742009-12-18 18:28:10 +0100833 subscr_put(subscr); /* lchan already has a ref, don't need another one */
834 else {
Harald Welte9bb7c702009-01-10 03:21:41 +0000835 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
836 subscr_put(subscr);
837 }
838
Harald Weltec2e302d2009-07-05 14:08:13 +0200839 subscr->equipment.classmark2_len = classmark2_len;
840 memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
841 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +0000842
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800843 return gsm48_secure_channel(conn, req->cipher_key_seq,
Sylvain Munautba87f452009-12-24 00:28:46 +0100844 _gsm48_rx_mm_serv_req_sec_cb, NULL);
Harald Welte4b634542008-12-27 01:55:51 +0000845}
846
Harald Welte2a139372009-02-22 21:14:55 +0000847static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
848{
Harald Welte9176bd42009-07-23 18:46:00 +0200849 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte2a139372009-02-22 21:14:55 +0000850 struct gsm48_hdr *gh = msgb_l3(msg);
851 struct gsm48_imsi_detach_ind *idi =
852 (struct gsm48_imsi_detach_ind *) gh->data;
853 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200854 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +0800855 struct gsm_subscriber *subscr = NULL;
Harald Welte2a139372009-02-22 21:14:55 +0000856
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200857 gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
Harald Welte2a139372009-02-22 21:14:55 +0000858 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
859 mi_type, mi_string);
860
Harald Welteffa55a42009-12-22 19:07:32 +0100861 counter_inc(bts->network->stats.loc_upd_type.detach);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100862
Harald Welte2a139372009-02-22 21:14:55 +0000863 switch (mi_type) {
864 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +0200865 subscr = subscr_get_by_tmsi(bts->network,
866 tmsi_from_string(mi_string));
Harald Welte2a139372009-02-22 21:14:55 +0000867 break;
868 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +0200869 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte2a139372009-02-22 21:14:55 +0000870 break;
871 case GSM_MI_TYPE_IMEI:
872 case GSM_MI_TYPE_IMEISV:
873 /* no sim card... FIXME: what to do ? */
Holger Freyther79f4ae62009-06-02 03:25:04 +0000874 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000875 break;
876 default:
Holger Freyther79f4ae62009-06-02 03:25:04 +0000877 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000878 break;
879 }
880
Holger Freyther4a49e772009-04-12 05:37:29 +0000881 if (subscr) {
882 subscr_update(subscr, msg->trx->bts,
883 GSM_SUBSCRIBER_UPDATE_DETACHED);
Harald Welte2e6d4682009-12-24 14:50:24 +0100884 DEBUGP(DMM, "Subscriber: %s\n", subscr_name(subscr));
Harald Welte (local)ee4410a2009-08-17 09:39:55 +0200885
886 subscr->equipment.classmark1 = idi->classmark1;
887 db_sync_equipment(&subscr->equipment);
888
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000889 subscr_put(subscr);
Holger Freyther4a49e772009-04-12 05:37:29 +0000890 } else
Harald Welte2a139372009-02-22 21:14:55 +0000891 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
892
Harald Welte31981a02009-12-20 09:58:40 +0100893 /* FIXME: iterate over all transactions and release them,
894 * imagine an IMSI DETACH happening during an active call! */
895
Harald Welteb83d9382009-12-12 21:00:48 +0100896 /* subscriber is detached: should we release lchan? */
Harald Welte2a139372009-02-22 21:14:55 +0000897 return 0;
898}
899
Harald Welted2a7f5a2009-06-05 20:08:20 +0000900static int gsm48_rx_mm_status(struct msgb *msg)
901{
902 struct gsm48_hdr *gh = msgb_l3(msg);
903
904 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
905
906 return 0;
907}
908
Sylvain Munaut30a15382009-12-24 00:27:26 +0100909/* Chapter 9.2.3: Authentication Response */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800910static int gsm48_rx_mm_auth_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +0100911{
912 struct gsm48_hdr *gh = msgb_l3(msg);
913 struct gsm48_auth_resp *ar = (struct gsm48_auth_resp*) gh->data;
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800914 struct gsm_network *net = conn->bts->network;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100915
Sylvain Munautc593cf12010-06-10 23:51:41 +0200916 DEBUGP(DMM, "MM AUTHENTICATION RESPONSE (sres = %s): ",
Sylvain Munaut30a15382009-12-24 00:27:26 +0100917 hexdump(ar->sres, 4));
918
919 /* Safety check */
920 if (!conn->sec_operation) {
921 DEBUGP(DMM, "No authentication/cipher operation in progress !!!\n");
922 return -EIO;
923 }
924
925 /* Validate SRES */
926 if (memcmp(conn->sec_operation->atuple.sres, ar->sres,4)) {
927 gsm_cbfn *cb = conn->sec_operation->cb;
Sylvain Munautc593cf12010-06-10 23:51:41 +0200928
929 DEBUGPC(DMM, "Invalid (expected %s)\n",
930 hexdump(conn->sec_operation->atuple.sres, 4));
931
Sylvain Munaut30a15382009-12-24 00:27:26 +0100932 if (cb)
933 cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_AUTH_FAILED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +0800934 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100935
936 release_security_operation(conn);
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +0800937 return gsm48_tx_mm_auth_rej(conn);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100938 }
939
Sylvain Munautc593cf12010-06-10 23:51:41 +0200940 DEBUGPC(DMM, "OK\n");
941
Sylvain Munaut30a15382009-12-24 00:27:26 +0100942 /* Start ciphering */
Sylvain Munaut67706df2010-11-29 08:19:04 +0100943 return gsm0808_cipher_mode(conn, net->a5_encryption,
944 conn->sec_operation->atuple.kc, 8, 0);
Sylvain Munaut30a15382009-12-24 00:27:26 +0100945}
946
Harald Weltebf5e8df2009-02-03 12:59:45 +0000947/* Receive a GSM 04.08 Mobility Management (MM) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800948static int gsm0408_rcv_mm(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000949{
950 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +0800951 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000952
953 switch (gh->msg_type & 0xbf) {
954 case GSM48_MT_MM_LOC_UPD_REQUEST:
Harald Weltea0368542009-06-27 02:58:43 +0200955 DEBUGP(DMM, "LOCATION UPDATING REQUEST: ");
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800956 rc = mm_rx_loc_upd_req(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000957 break;
958 case GSM48_MT_MM_ID_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800959 rc = mm_rx_id_resp(conn, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000960 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000961 case GSM48_MT_MM_CM_SERV_REQ:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800962 rc = gsm48_rx_mm_serv_req(conn, msg);
Harald Welte4b634542008-12-27 01:55:51 +0000963 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000964 case GSM48_MT_MM_STATUS:
Harald Welted2a7f5a2009-06-05 20:08:20 +0000965 rc = gsm48_rx_mm_status(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000966 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000967 case GSM48_MT_MM_TMSI_REALL_COMPL:
Harald Welte69b2af22009-01-06 19:47:00 +0000968 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800969 conn->subscr ?
970 subscr_name(conn->subscr) :
Harald Welte69b2af22009-01-06 19:47:00 +0000971 "unknown subscriber");
972 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000973 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte2a139372009-02-22 21:14:55 +0000974 rc = gsm48_rx_mm_imsi_detach_ind(msg);
975 break;
976 case GSM48_MT_MM_CM_REEST_REQ:
977 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
978 break;
979 case GSM48_MT_MM_AUTH_RESP:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +0800980 rc = gsm48_rx_mm_auth_resp(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000981 break;
982 default:
Harald Welte5d24ba12009-12-24 12:13:17 +0100983 LOGP(DMM, LOGL_NOTICE, "Unknown GSM 04.08 MM msg type 0x%02x\n",
Harald Welte52b1f982008-12-23 20:25:15 +0000984 gh->msg_type);
985 break;
986 }
987
988 return rc;
989}
Harald Weltebf5e8df2009-02-03 12:59:45 +0000990
Harald Welte2d35ae62009-02-06 12:02:13 +0000991/* Receive a PAGING RESPONSE message from the MS */
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +0800992static int gsm48_rx_rr_pag_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte2d35ae62009-02-06 12:02:13 +0000993{
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +0800994 struct gsm_bts *bts = conn->bts;
Harald Welte2d35ae62009-02-06 12:02:13 +0000995 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +0800996 struct gsm48_pag_resp *resp;
Harald Welte61548982009-02-22 21:26:29 +0000997 u_int8_t *classmark2_lv = gh->data + 1;
Holger Hans Peter Freyther3ee5d3e2009-08-21 05:18:21 +0200998 u_int8_t mi_type;
Holger Hans Peter Freytherd1862d72009-08-19 07:54:59 +0200999 char mi_string[GSM48_MI_SIZE];
Harald Welte4bfdfe72009-06-10 23:11:52 +08001000 struct gsm_subscriber *subscr = NULL;
Harald Welte2d35ae62009-02-06 12:02:13 +00001001 int rc = 0;
1002
Holger Hans Peter Freytherf6903de2010-05-16 01:51:14 +08001003 resp = (struct gsm48_pag_resp *) &gh->data[0];
1004 gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh),
1005 mi_string, &mi_type);
Harald Welte2d35ae62009-02-06 12:02:13 +00001006 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
1007 mi_type, mi_string);
Harald Welte3ac7f102009-08-10 10:12:45 +02001008
Harald Weltefe18d8f2009-02-22 21:14:24 +00001009 switch (mi_type) {
1010 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +02001011 subscr = subscr_get_by_tmsi(bts->network,
1012 tmsi_from_string(mi_string));
Harald Weltefe18d8f2009-02-22 21:14:24 +00001013 break;
1014 case GSM_MI_TYPE_IMSI:
Harald Welte9176bd42009-07-23 18:46:00 +02001015 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Weltefe18d8f2009-02-22 21:14:24 +00001016 break;
1017 }
Harald Welte2d35ae62009-02-06 12:02:13 +00001018
1019 if (!subscr) {
1020 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001021 /* FIXME: request id? close channel? */
Harald Welte2d35ae62009-02-06 12:02:13 +00001022 return -EINVAL;
1023 }
1024 DEBUGP(DRR, "<- Channel was requested by %s\n",
Harald Welte76042182009-08-08 16:03:15 +02001025 subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi);
Holger Freyther053e09d2009-02-14 22:51:06 +00001026
Harald Weltec2e302d2009-07-05 14:08:13 +02001027 subscr->equipment.classmark2_len = *classmark2_lv;
1028 memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
1029 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001030
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001031 rc = gsm48_handle_paging_resp(conn, msg, subscr);
Harald Welte2d35ae62009-02-06 12:02:13 +00001032 return rc;
1033}
1034
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001035static int gsm48_rx_rr_classmark(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Weltef7c43522009-06-09 20:24:21 +00001036{
1037 struct gsm48_hdr *gh = msgb_l3(msg);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001038 struct gsm_subscriber *subscr = conn->subscr;
Harald Weltef7c43522009-06-09 20:24:21 +00001039 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1040 u_int8_t cm2_len, cm3_len = 0;
1041 u_int8_t *cm2, *cm3 = NULL;
1042
1043 DEBUGP(DRR, "CLASSMARK CHANGE ");
1044
1045 /* classmark 2 */
1046 cm2_len = gh->data[0];
1047 cm2 = &gh->data[1];
1048 DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
1049
1050 if (payload_len > cm2_len + 1) {
1051 /* we must have a classmark3 */
1052 if (gh->data[cm2_len+1] != 0x20) {
1053 DEBUGPC(DRR, "ERR CM3 TAG\n");
1054 return -EINVAL;
1055 }
1056 if (cm2_len > 3) {
1057 DEBUGPC(DRR, "CM2 too long!\n");
1058 return -EINVAL;
1059 }
1060
1061 cm3_len = gh->data[cm2_len+2];
1062 cm3 = &gh->data[cm2_len+3];
1063 if (cm3_len > 14) {
1064 DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
1065 return -EINVAL;
1066 }
1067 DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
1068 }
1069 if (subscr) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001070 subscr->equipment.classmark2_len = cm2_len;
1071 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001072 if (cm3) {
Harald Weltec2e302d2009-07-05 14:08:13 +02001073 subscr->equipment.classmark3_len = cm3_len;
1074 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
Harald Weltef7c43522009-06-09 20:24:21 +00001075 }
Harald Weltec2e302d2009-07-05 14:08:13 +02001076 db_sync_equipment(&subscr->equipment);
Harald Weltef7c43522009-06-09 20:24:21 +00001077 }
1078
Harald Weltef7c43522009-06-09 20:24:21 +00001079 return 0;
1080}
1081
Harald Weltecf5b3592009-05-01 18:28:42 +00001082static int gsm48_rx_rr_status(struct msgb *msg)
1083{
1084 struct gsm48_hdr *gh = msgb_l3(msg);
1085
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001086 DEBUGP(DRR, "STATUS rr_cause = %s\n",
Harald Weltecf5b3592009-05-01 18:28:42 +00001087 rr_cause_name(gh->data[0]));
1088
1089 return 0;
1090}
1091
Harald Weltef7c43522009-06-09 20:24:21 +00001092static int gsm48_rx_rr_meas_rep(struct msgb *msg)
1093{
Harald Welted12b0fd2009-12-15 21:36:05 +01001094 struct gsm_meas_rep *meas_rep = lchan_next_meas_rep(msg->lchan);
Harald Weltef7c43522009-06-09 20:24:21 +00001095
Harald Welte3c7dc6e2009-11-29 19:07:28 +01001096 /* This shouldn't actually end up here, as RSL treats
1097 * L3 Info of 08.58 MEASUREMENT REPORT different by calling
1098 * directly into gsm48_parse_meas_rep */
1099 DEBUGP(DMEAS, "DIRECT GSM48 MEASUREMENT REPORT ?!? ");
Harald Welted12b0fd2009-12-15 21:36:05 +01001100 gsm48_parse_meas_rep(meas_rep, msg);
Harald Weltef7c43522009-06-09 20:24:21 +00001101
1102 return 0;
1103}
1104
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001105static int gsm48_rx_rr_app_info(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001106{
1107 struct gsm48_hdr *gh = msgb_l3(msg);
1108 u_int8_t apdu_id_flags;
1109 u_int8_t apdu_len;
1110 u_int8_t *apdu_data;
1111
1112 apdu_id_flags = gh->data[0];
1113 apdu_len = gh->data[1];
1114 apdu_data = gh->data+2;
1115
1116 DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s",
1117 apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len));
1118
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001119 return db_apdu_blob_store(conn->subscr, apdu_id_flags, apdu_len, apdu_data);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001120}
1121
Sylvain Munaut30a15382009-12-24 00:27:26 +01001122/* Chapter 9.1.10 Ciphering Mode Complete */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001123static int gsm48_rx_rr_ciph_m_compl(struct gsm_subscriber_connection *conn, struct msgb *msg)
Sylvain Munaut30a15382009-12-24 00:27:26 +01001124{
Sylvain Munaut30a15382009-12-24 00:27:26 +01001125 gsm_cbfn *cb;
1126 int rc = 0;
1127
1128 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
1129
1130 /* Safety check */
1131 if (!conn->sec_operation) {
1132 DEBUGP(DRR, "No authentication/cipher operation in progress !!!\n");
1133 return -EIO;
1134 }
1135
1136 /* FIXME: check for MI (if any) */
1137
1138 /* Call back whatever was in progress (if anything) ... */
1139 cb = conn->sec_operation->cb;
1140 if (cb) {
1141 rc = cb(GSM_HOOK_RR_SECURITY, GSM_SECURITY_SUCCEEDED,
Holger Hans Peter Freyther228c1052010-06-16 12:47:59 +08001142 NULL, conn, conn->sec_operation->cb_data);
Sylvain Munaut30a15382009-12-24 00:27:26 +01001143 }
1144
1145 /* Complete the operation */
1146 release_security_operation(conn);
1147
1148 return rc;
1149}
1150
Harald Welted011e8b2009-11-29 22:45:52 +01001151/* Chapter 9.1.16 Handover complete */
Harald Welte1e191c52009-12-14 17:51:15 +01001152static int gsm48_rx_rr_ho_compl(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001153{
1154 struct gsm48_hdr *gh = msgb_l3(msg);
1155
1156 DEBUGP(DRR, "HANDOVER COMPLETE cause = %s\n",
1157 rr_cause_name(gh->data[0]));
1158
1159 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_COMPL, msg->lchan);
1160 /* FIXME: release old channel */
1161
1162 return 0;
1163}
1164
1165/* Chapter 9.1.17 Handover Failure */
Harald Welte1e191c52009-12-14 17:51:15 +01001166static int gsm48_rx_rr_ho_fail(struct msgb *msg)
Harald Welted011e8b2009-11-29 22:45:52 +01001167{
1168 struct gsm48_hdr *gh = msgb_l3(msg);
1169
1170 DEBUGP(DRR, "HANDOVER FAILED cause = %s\n",
1171 rr_cause_name(gh->data[0]));
1172
1173 dispatch_signal(SS_LCHAN, S_LCHAN_HANDOVER_FAIL, msg->lchan);
1174 /* FIXME: release allocated new channel */
1175
1176 return 0;
1177}
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001178
Harald Weltebf5e8df2009-02-03 12:59:45 +00001179/* Receive a GSM 04.08 Radio Resource (RR) message */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001180static int gsm0408_rcv_rr(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00001181{
1182 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001183 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001184
1185 switch (gh->msg_type) {
1186 case GSM48_MT_RR_CLSM_CHG:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001187 rc = gsm48_rx_rr_classmark(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00001188 break;
Harald Weltefc977a82008-12-27 10:19:37 +00001189 case GSM48_MT_RR_GPRS_SUSP_REQ:
1190 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1191 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001192 case GSM48_MT_RR_PAG_RESP:
Holger Hans Peter Freytherdb4ef0d2010-06-21 10:46:44 +08001193 rc = gsm48_rx_rr_pag_resp(conn, msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001194 break;
Harald Weltecf5b3592009-05-01 18:28:42 +00001195 case GSM48_MT_RR_STATUS:
1196 rc = gsm48_rx_rr_status(msg);
1197 break;
Harald Weltef7c43522009-06-09 20:24:21 +00001198 case GSM48_MT_RR_MEAS_REP:
1199 rc = gsm48_rx_rr_meas_rep(msg);
1200 break;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001201 case GSM48_MT_RR_APP_INFO:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001202 rc = gsm48_rx_rr_app_info(conn, msg);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001203 break;
Harald Welte08d91a52009-08-30 15:37:11 +09001204 case GSM48_MT_RR_CIPH_M_COMPL:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08001205 rc = gsm48_rx_rr_ciph_m_compl(conn, msg);
Harald Welte08d91a52009-08-30 15:37:11 +09001206 break;
Harald Welteccd5a882009-11-29 20:02:20 +01001207 case GSM48_MT_RR_HANDO_COMPL:
Harald Welted011e8b2009-11-29 22:45:52 +01001208 rc = gsm48_rx_rr_ho_compl(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001209 break;
1210 case GSM48_MT_RR_HANDO_FAIL:
Harald Welted011e8b2009-11-29 22:45:52 +01001211 rc = gsm48_rx_rr_ho_fail(msg);
Harald Welteccd5a882009-11-29 20:02:20 +01001212 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001213 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01001214 LOGP(DRR, LOGL_NOTICE, "Unimplemented "
1215 "GSM 04.08 RR msg type 0x%02x\n", gh->msg_type);
Harald Welte52b1f982008-12-23 20:25:15 +00001216 break;
1217 }
1218
Harald Welte2d35ae62009-02-06 12:02:13 +00001219 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001220}
1221
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001222int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, u_int8_t apdu_id,
Holger Hans Peter Freyther8b77a342009-10-22 15:42:19 +02001223 u_int8_t apdu_len, const u_int8_t *apdu)
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001224{
1225 struct msgb *msg = gsm48_msgb_alloc();
1226 struct gsm48_hdr *gh;
1227
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001228 msg->lchan = conn->lchan;
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001229
1230 DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n",
1231 apdu_id, apdu_len);
1232
1233 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len);
1234 gh->proto_discr = GSM48_PDISC_RR;
1235 gh->msg_type = GSM48_MT_RR_APP_INFO;
1236 gh->data[0] = apdu_id;
1237 gh->data[1] = apdu_len;
1238 memcpy(gh->data+2, apdu, apdu_len);
1239
Holger Hans Peter Freyther9ce1b272010-06-16 13:52:55 +08001240 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte (local)6eef5642009-08-15 23:32:44 +02001241}
1242
Harald Welte4bc90a12008-12-27 16:32:52 +00001243/* Call Control */
1244
Harald Welte7584aea2009-02-11 11:44:12 +00001245/* The entire call control code is written in accordance with Figure 7.10c
1246 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1247 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1248 * it for voice */
1249
Harald Welte4bfdfe72009-06-10 23:11:52 +08001250static void new_cc_state(struct gsm_trans *trans, int state)
1251{
1252 if (state > 31 || state < 0)
1253 return;
1254
1255 DEBUGP(DCC, "new state %s -> %s\n",
Harald Weltee95daf192010-03-25 12:13:02 +08001256 gsm48_cc_state_name(trans->cc.state),
1257 gsm48_cc_state_name(state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001258
Harald Weltedcaf5652009-07-23 18:56:43 +02001259 trans->cc.state = state;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001260}
1261
1262static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
Harald Welte4bc90a12008-12-27 16:32:52 +00001263{
1264 struct msgb *msg = gsm48_msgb_alloc();
1265 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1266 u_int8_t *cause, *call_state;
1267
Harald Welte4bc90a12008-12-27 16:32:52 +00001268 gh->msg_type = GSM48_MT_CC_STATUS;
1269
1270 cause = msgb_put(msg, 3);
1271 cause[0] = 2;
1272 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1273 cause[2] = 0x80 | 30; /* response to status inquiry */
1274
1275 call_state = msgb_put(msg, 1);
1276 call_state[0] = 0xc0 | 0x00;
1277
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001278 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bc90a12008-12-27 16:32:52 +00001279}
1280
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001281static int gsm48_tx_simple(struct gsm_subscriber_connection *conn,
Harald Welte6f4b7532008-12-29 00:39:37 +00001282 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +00001283{
1284 struct msgb *msg = gsm48_msgb_alloc();
1285 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1286
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001287 msg->lchan = conn->lchan;
Harald Welte4bc90a12008-12-27 16:32:52 +00001288
Harald Welte6f4b7532008-12-29 00:39:37 +00001289 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +00001290 gh->msg_type = msg_type;
1291
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08001292 return gsm48_conn_sendmsg(msg, conn, NULL);
Harald Welte4bc90a12008-12-27 16:32:52 +00001293}
1294
Harald Welte4bfdfe72009-06-10 23:11:52 +08001295static void gsm48_stop_cc_timer(struct gsm_trans *trans)
1296{
Harald Weltedcaf5652009-07-23 18:56:43 +02001297 if (bsc_timer_pending(&trans->cc.timer)) {
1298 DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent);
1299 bsc_del_timer(&trans->cc.timer);
1300 trans->cc.Tcurrent = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001301 }
1302}
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001303
Harald Welte4bfdfe72009-06-10 23:11:52 +08001304static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
1305 int msg_type, struct gsm_mncc *mncc)
1306{
1307 struct msgb *msg;
1308
1309 if (trans)
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001310 if (trans->conn)
Harald Welte6f5aee02009-07-23 21:21:14 +02001311 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08001312 "Sending '%s' to MNCC.\n",
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001313 trans->conn->lchan->ts->trx->bts->nr,
1314 trans->conn->lchan->ts->trx->nr,
1315 trans->conn->lchan->ts->nr, trans->transaction_id,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001316 (trans->subscr)?(trans->subscr->extension):"-",
1317 get_mncc_name(msg_type));
1318 else
1319 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
1320 "Sending '%s' to MNCC.\n",
1321 (trans->subscr)?(trans->subscr->extension):"-",
1322 get_mncc_name(msg_type));
1323 else
1324 DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) "
1325 "Sending '%s' to MNCC.\n", get_mncc_name(msg_type));
1326
1327 mncc->msg_type = msg_type;
1328
Harald Welte966636f2009-06-26 19:39:35 +02001329 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
Harald Welte4bfdfe72009-06-10 23:11:52 +08001330 if (!msg)
1331 return -ENOMEM;
1332 memcpy(msg->data, mncc, sizeof(struct gsm_mncc));
Harald Welte434bb3f2010-12-22 19:02:27 +01001333 mncc_upq_enqueue(net, msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001334
1335 return 0;
1336}
1337
1338int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
1339 u_int32_t callref, int location, int value)
1340{
1341 struct gsm_mncc rel;
1342
Harald Welte92f70c52009-06-12 01:54:08 +08001343 memset(&rel, 0, sizeof(rel));
Harald Welte4bfdfe72009-06-10 23:11:52 +08001344 rel.callref = callref;
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001345 mncc_set_cause(&rel, location, value);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001346 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1347}
1348
Harald Weltedcaf5652009-07-23 18:56:43 +02001349/* Call Control Specific transaction release.
1350 * gets called by trans_free, DO NOT CALL YOURSELF! */
1351void _gsm48_cc_trans_free(struct gsm_trans *trans)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001352{
Harald Welte4bfdfe72009-06-10 23:11:52 +08001353 gsm48_stop_cc_timer(trans);
1354
1355 /* send release to L4, if callref still exists */
1356 if (trans->callref) {
1357 /* Ressource unavailable */
Harald Welte596fed42009-07-23 19:06:52 +02001358 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001359 GSM48_CAUSE_LOC_PRN_S_LU,
1360 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001361 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001362 if (trans->cc.state != GSM_CSTATE_NULL)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001363 new_cc_state(trans, GSM_CSTATE_NULL);
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001364 if (trans->conn)
1365 trau_mux_unmap(&trans->conn->lchan->ts->e1_link, trans->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001366}
1367
1368static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001369
Harald Welte09e38af2009-02-16 22:52:23 +00001370/* call-back from paging the B-end of the connection */
1371static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001372 struct msgb *msg, void *_conn, void *param)
Harald Welte09e38af2009-02-16 22:52:23 +00001373{
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001374 struct gsm_subscriber_connection *conn = _conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001375 struct gsm_subscriber *subscr = param;
1376 struct gsm_trans *transt, *tmp;
1377 struct gsm_network *net;
Harald Weltec05677b2009-06-26 20:17:06 +02001378
Harald Welte09e38af2009-02-16 22:52:23 +00001379 if (hooknum != GSM_HOOK_RR_PAGING)
1380 return -EINVAL;
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02001381
Harald Welte4bfdfe72009-06-10 23:11:52 +08001382 if (!subscr)
1383 return -EINVAL;
1384 net = subscr->net;
1385 if (!net) {
1386 DEBUGP(DCC, "Error Network not set!\n");
1387 return -EINVAL;
Harald Welte5a065df2009-02-22 21:13:18 +00001388 }
Harald Welte7584aea2009-02-11 11:44:12 +00001389
Harald Welte4bfdfe72009-06-10 23:11:52 +08001390 /* check all tranactions (without lchan) for subscriber */
1391 llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001392 if (transt->subscr != subscr || transt->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001393 continue;
1394 switch (event) {
1395 case GSM_PAGING_SUCCEEDED:
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001396 if (!conn) // paranoid
Harald Welte4bfdfe72009-06-10 23:11:52 +08001397 break;
1398 DEBUGP(DCC, "Paging subscr %s succeeded!\n",
1399 subscr->extension);
1400 /* Assign lchan */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001401 if (!transt->conn) {
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +08001402 transt->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001403 }
1404 /* send SETUP request to called party */
Harald Weltedcaf5652009-07-23 18:56:43 +02001405 gsm48_cc_tx_setup(transt, &transt->cc.msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001406 break;
1407 case GSM_PAGING_EXPIRED:
1408 DEBUGP(DCC, "Paging subscr %s expired!\n",
1409 subscr->extension);
1410 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001411 mncc_release_ind(transt->subscr->net, transt,
1412 transt->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001413 GSM48_CAUSE_LOC_PRN_S_LU,
1414 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001415 transt->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001416 trans_free(transt);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001417 break;
1418 }
1419 }
Harald Welte09e38af2009-02-16 22:52:23 +00001420 return 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00001421}
Harald Welte7584aea2009-02-11 11:44:12 +00001422
Harald Welteda7ab742009-12-19 22:23:05 +01001423static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable);
1424
Harald Welte805f6442009-07-28 18:25:29 +02001425/* some other part of the code sends us a signal */
1426static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
1427 void *handler_data, void *signal_data)
1428{
1429 struct gsm_lchan *lchan = signal_data;
Harald Welte805f6442009-07-28 18:25:29 +02001430 int rc;
Harald Welteda7ab742009-12-19 22:23:05 +01001431 struct gsm_network *net;
1432 struct gsm_trans *trans;
Harald Welte805f6442009-07-28 18:25:29 +02001433
1434 if (subsys != SS_ABISIP)
1435 return 0;
1436
1437 /* in case we use direct BTS-to-BTS RTP */
1438 if (ipacc_rtp_direct)
1439 return 0;
1440
Harald Welte805f6442009-07-28 18:25:29 +02001441 switch (signal) {
Holger Hans Peter Freyther231163d2009-11-18 21:06:12 +01001442 case S_ABISIP_CRCX_ACK:
Harald Welteda7ab742009-12-19 22:23:05 +01001443 /* check if any transactions on this lchan still have
1444 * a tch_recv_mncc request pending */
1445 net = lchan->ts->trx->bts->network;
1446 llist_for_each_entry(trans, &net->trans_list, entry) {
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001447 if (trans->conn && trans->conn->lchan == lchan && trans->tch_recv) {
Harald Welteda7ab742009-12-19 22:23:05 +01001448 DEBUGP(DCC, "pending tch_recv_mncc request\n");
1449 tch_recv_mncc(net, trans->callref, 1);
1450 }
1451 }
Harald Welte805f6442009-07-28 18:25:29 +02001452 break;
Harald Welte805f6442009-07-28 18:25:29 +02001453 }
1454
1455 return 0;
Harald Welte805f6442009-07-28 18:25:29 +02001456}
1457
Harald Welte49f48b82009-02-17 15:29:33 +00001458/* map two ipaccess RTP streams onto each other */
Harald Welte11fa29c2009-02-19 17:24:39 +00001459static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
Harald Welte49f48b82009-02-17 15:29:33 +00001460{
Harald Welte11fa29c2009-02-19 17:24:39 +00001461 struct gsm_bts *bts = lchan->ts->trx->bts;
1462 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
Harald Welte805f6442009-07-28 18:25:29 +02001463 int rc;
Harald Welte49f48b82009-02-17 15:29:33 +00001464
Harald Welte11fa29c2009-02-19 17:24:39 +00001465 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1466 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1467 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1468
1469 if (bts->type != remote_bts->type) {
1470 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1471 return -EINVAL;
1472 }
Harald Welteda7ab742009-12-19 22:23:05 +01001473
1474 // todo: map between different bts types
Harald Welte11fa29c2009-02-19 17:24:39 +00001475 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +01001476 case GSM_BTS_TYPE_NANOBTS:
Harald Welte805f6442009-07-28 18:25:29 +02001477 if (!ipacc_rtp_direct) {
1478 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001479 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welte805f6442009-07-28 18:25:29 +02001480 if (rc < 0)
1481 return rc;
Harald Weltea72273e2009-12-20 16:51:09 +01001482 rc = rsl_ipacc_mdcx_to_rtpsock(remote_lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001483#warning do we need a check of rc here?
Harald Welte805f6442009-07-28 18:25:29 +02001484
1485 /* connect them with each other */
Harald Welte2c828992009-12-02 01:56:49 +05301486 rtp_socket_proxy(lchan->abis_ip.rtp_socket,
1487 remote_lchan->abis_ip.rtp_socket);
Harald Welte805f6442009-07-28 18:25:29 +02001488 } else {
1489 /* directly connect TCH RTP streams to each other */
Harald Welte2c828992009-12-02 01:56:49 +05301490 rc = rsl_ipacc_mdcx(lchan, remote_lchan->abis_ip.bound_ip,
1491 remote_lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301492 remote_lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001493 if (rc < 0)
1494 return rc;
Harald Welte2c828992009-12-02 01:56:49 +05301495 rc = rsl_ipacc_mdcx(remote_lchan, lchan->abis_ip.bound_ip,
1496 lchan->abis_ip.bound_port,
Harald Welte2c828992009-12-02 01:56:49 +05301497 lchan->abis_ip.rtp_payload2);
Harald Welte805f6442009-07-28 18:25:29 +02001498 }
Harald Welte11fa29c2009-02-19 17:24:39 +00001499 break;
1500 case GSM_BTS_TYPE_BS11:
1501 trau_mux_map_lchan(lchan, remote_lchan);
1502 break;
1503 default:
1504 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
Harald Welteda7ab742009-12-19 22:23:05 +01001505 return -EINVAL;
Harald Welte11fa29c2009-02-19 17:24:39 +00001506 }
Harald Welte49f48b82009-02-17 15:29:33 +00001507
1508 return 0;
1509}
1510
Harald Welte4bfdfe72009-06-10 23:11:52 +08001511/* bridge channels of two transactions */
1512static int tch_bridge(struct gsm_network *net, u_int32_t *refs)
Harald Welte7ccf7782009-02-17 01:43:01 +00001513{
Harald Weltedcaf5652009-07-23 18:56:43 +02001514 struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]);
1515 struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]);
Harald Welte7ccf7782009-02-17 01:43:01 +00001516
Harald Welte4bfdfe72009-06-10 23:11:52 +08001517 if (!trans1 || !trans2)
Harald Welte7ccf7782009-02-17 01:43:01 +00001518 return -EIO;
1519
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001520 if (!trans1->conn || !trans2->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001521 return -EIO;
1522
1523 /* through-connect channel */
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001524 return tch_map(trans1->conn->lchan, trans2->conn->lchan);
Harald Welte7ccf7782009-02-17 01:43:01 +00001525}
1526
Harald Welteda7ab742009-12-19 22:23:05 +01001527/* enable receive of channels to MNCC upqueue */
1528static int tch_recv_mncc(struct gsm_network *net, u_int32_t callref, int enable)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001529{
1530 struct gsm_trans *trans;
Harald Welteda7ab742009-12-19 22:23:05 +01001531 struct gsm_lchan *lchan;
1532 struct gsm_bts *bts;
1533 int rc;
Harald Welte7ccf7782009-02-17 01:43:01 +00001534
Harald Welte4bfdfe72009-06-10 23:11:52 +08001535 /* Find callref */
Harald Welteda7ab742009-12-19 22:23:05 +01001536 trans = trans_find_by_callref(net, callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001537 if (!trans)
1538 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001539 if (!trans->conn)
Harald Welte4bfdfe72009-06-10 23:11:52 +08001540 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01001541 lchan = trans->conn->lchan;
Harald Welteda7ab742009-12-19 22:23:05 +01001542 bts = lchan->ts->trx->bts;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001543
Harald Welteda7ab742009-12-19 22:23:05 +01001544 switch (bts->type) {
1545 case GSM_BTS_TYPE_NANOBTS:
1546 if (ipacc_rtp_direct) {
1547 DEBUGP(DCC, "Error: RTP proxy is disabled\n");
1548 return -EINVAL;
1549 }
1550 /* in case, we don't have a RTP socket yet, we note this
1551 * in the transaction and try later */
1552 if (!lchan->abis_ip.rtp_socket) {
1553 trans->tch_recv = enable;
1554 DEBUGP(DCC, "queue tch_recv_mncc request (%d)\n", enable);
1555 return 0;
1556 }
1557 if (enable) {
1558 /* connect the TCH's to our RTP proxy */
Harald Weltea72273e2009-12-20 16:51:09 +01001559 rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
Harald Welteda7ab742009-12-19 22:23:05 +01001560 if (rc < 0)
1561 return rc;
1562 /* assign socket to application interface */
1563 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1564 net, callref);
1565 } else
1566 rtp_socket_upstream(lchan->abis_ip.rtp_socket,
1567 net, 0);
1568 break;
1569 case GSM_BTS_TYPE_BS11:
1570 if (enable)
1571 return trau_recv_lchan(lchan, callref);
1572 return trau_mux_unmap(NULL, callref);
1573 break;
1574 default:
1575 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
1576 return -EINVAL;
1577 }
1578
1579 return 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001580}
1581
Harald Welte4bfdfe72009-06-10 23:11:52 +08001582static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
1583{
1584 DEBUGP(DCC, "-> STATUS ENQ\n");
1585 return gsm48_cc_tx_status(trans, msg);
1586}
1587
1588static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
1589static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
1590
1591static void gsm48_cc_timeout(void *arg)
1592{
1593 struct gsm_trans *trans = arg;
1594 int disconnect = 0, release = 0;
Harald Weltec66b71c2009-06-11 14:23:20 +08001595 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
1596 int mo_location = GSM48_CAUSE_LOC_USER;
1597 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
1598 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001599 struct gsm_mncc mo_rel, l4_rel;
1600
1601 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
1602 mo_rel.callref = trans->callref;
1603 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
1604 l4_rel.callref = trans->callref;
1605
Harald Weltedcaf5652009-07-23 18:56:43 +02001606 switch(trans->cc.Tcurrent) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001607 case 0x303:
1608 release = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001609 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001610 break;
1611 case 0x310:
1612 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001613 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001614 break;
1615 case 0x313:
1616 disconnect = 1;
1617 /* unknown, did not find it in the specs */
1618 break;
1619 case 0x301:
1620 disconnect = 1;
Harald Weltec66b71c2009-06-11 14:23:20 +08001621 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001622 break;
1623 case 0x308:
Harald Weltedcaf5652009-07-23 18:56:43 +02001624 if (!trans->cc.T308_second) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001625 /* restart T308 a second time */
Harald Weltedcaf5652009-07-23 18:56:43 +02001626 gsm48_cc_tx_release(trans, &trans->cc.msg);
1627 trans->cc.T308_second = 1;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001628 break; /* stay in release state */
1629 }
Harald Weltedcaf5652009-07-23 18:56:43 +02001630 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001631 return;
1632// release = 1;
1633// l4_cause = 14;
1634// break;
1635 case 0x306:
1636 release = 1;
Harald Weltedcaf5652009-07-23 18:56:43 +02001637 mo_cause = trans->cc.msg.cause.value;
1638 mo_location = trans->cc.msg.cause.location;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001639 break;
1640 case 0x323:
1641 disconnect = 1;
1642 break;
1643 default:
1644 release = 1;
1645 }
1646
1647 if (release && trans->callref) {
1648 /* process release towards layer 4 */
Harald Welte596fed42009-07-23 19:06:52 +02001649 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001650 l4_location, l4_cause);
1651 trans->callref = 0;
1652 }
1653
1654 if (disconnect && trans->callref) {
1655 /* process disconnect towards layer 4 */
1656 mncc_set_cause(&l4_rel, l4_location, l4_cause);
Harald Welte596fed42009-07-23 19:06:52 +02001657 mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001658 }
1659
1660 /* process disconnect towards mobile station */
1661 if (disconnect || release) {
1662 mncc_set_cause(&mo_rel, mo_location, mo_cause);
Harald Weltedcaf5652009-07-23 18:56:43 +02001663 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
1664 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
1665 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
Harald Welte4bfdfe72009-06-10 23:11:52 +08001666 mo_rel.cause.diag_len = 3;
1667
1668 if (disconnect)
1669 gsm48_cc_tx_disconnect(trans, &mo_rel);
1670 if (release)
1671 gsm48_cc_tx_release(trans, &mo_rel);
1672 }
1673
1674}
1675
1676static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
1677 int sec, int micro)
1678{
1679 DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec);
Harald Weltedcaf5652009-07-23 18:56:43 +02001680 trans->cc.timer.cb = gsm48_cc_timeout;
1681 trans->cc.timer.data = trans;
1682 bsc_schedule_timer(&trans->cc.timer, sec, micro);
1683 trans->cc.Tcurrent = current;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001684}
1685
1686static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
1687{
1688 struct gsm48_hdr *gh = msgb_l3(msg);
1689 u_int8_t msg_type = gh->msg_type & 0xbf;
1690 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1691 struct tlv_parsed tp;
1692 struct gsm_mncc setup;
1693
1694 memset(&setup, 0, sizeof(struct gsm_mncc));
1695 setup.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001696 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001697 /* emergency setup is identified by msg_type */
1698 if (msg_type == GSM48_MT_CC_EMERG_SETUP)
1699 setup.emergency = 1;
1700
1701 /* use subscriber as calling party number */
1702 if (trans->subscr) {
1703 setup.fields |= MNCC_F_CALLING;
1704 strncpy(setup.calling.number, trans->subscr->extension,
1705 sizeof(setup.calling.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02001706 strncpy(setup.imsi, trans->subscr->imsi,
1707 sizeof(setup.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001708 }
1709 /* bearer capability */
1710 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1711 setup.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001712 gsm48_decode_bearer_cap(&setup.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001713 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1714 }
1715 /* facility */
1716 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1717 setup.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001718 gsm48_decode_facility(&setup.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001719 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1720 }
1721 /* called party bcd number */
1722 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
1723 setup.fields |= MNCC_F_CALLED;
Harald Welte55c8f352010-03-07 23:40:35 +01001724 gsm48_decode_called(&setup.called,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001725 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
1726 }
1727 /* user-user */
1728 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
1729 setup.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01001730 gsm48_decode_useruser(&setup.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001731 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
1732 }
1733 /* ss-version */
1734 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1735 setup.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001736 gsm48_decode_ssversion(&setup.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001737 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1738 }
1739 /* CLIR suppression */
1740 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
1741 setup.clir.sup = 1;
1742 /* CLIR invocation */
1743 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
1744 setup.clir.inv = 1;
1745 /* cc cap */
1746 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1747 setup.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001748 gsm48_decode_cccap(&setup.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001749 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1750 }
1751
Harald Welte4bfdfe72009-06-10 23:11:52 +08001752 new_cc_state(trans, GSM_CSTATE_INITIATED);
1753
Harald Welte (local)47df3992009-12-26 19:45:03 +01001754 LOGP(DCC, LOGL_INFO, "Subscriber %s (%s) sends SETUP to %s\n",
1755 subscr_name(trans->subscr), trans->subscr->extension,
1756 setup.called.number);
1757
Harald Welte4bfdfe72009-06-10 23:11:52 +08001758 /* indicate setup to MNCC */
Harald Welte596fed42009-07-23 19:06:52 +02001759 mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001760
Harald Welte13cac662009-07-29 12:10:35 +02001761 /* MNCC code will modify the channel asynchronously, we should
1762 * ipaccess-bind only after the modification has been made to the
1763 * lchan->tch_mode */
Harald Welte4bfdfe72009-06-10 23:11:52 +08001764 return 0;
1765}
1766
1767static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
Harald Welte65e74cc2008-12-29 01:55:35 +00001768{
1769 struct msgb *msg = gsm48_msgb_alloc();
1770 struct gsm48_hdr *gh;
Harald Welte4bfdfe72009-06-10 23:11:52 +08001771 struct gsm_mncc *setup = arg;
Harald Welte78283ef2009-07-23 21:36:44 +02001772 int rc, trans_id;
Harald Welte65e74cc2008-12-29 01:55:35 +00001773
Harald Welte7ccf7782009-02-17 01:43:01 +00001774 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Harald Welte65e74cc2008-12-29 01:55:35 +00001775
Harald Welte4bfdfe72009-06-10 23:11:52 +08001776 /* transaction id must not be assigned */
1777 if (trans->transaction_id != 0xff) { /* unasssigned */
1778 DEBUGP(DCC, "TX Setup with assigned transaction. "
1779 "This is not allowed!\n");
1780 /* Temporarily out of order */
Harald Welte596fed42009-07-23 19:06:52 +02001781 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001782 GSM48_CAUSE_LOC_PRN_S_LU,
1783 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001784 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001785 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001786 return rc;
1787 }
1788
1789 /* Get free transaction_id */
Harald Welte78283ef2009-07-23 21:36:44 +02001790 trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0);
1791 if (trans_id < 0) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08001792 /* no free transaction ID */
Harald Welte596fed42009-07-23 19:06:52 +02001793 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversberg7563ac92009-06-14 22:14:12 +08001794 GSM48_CAUSE_LOC_PRN_S_LU,
1795 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001796 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02001797 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001798 return rc;
1799 }
Harald Welte78283ef2009-07-23 21:36:44 +02001800 trans->transaction_id = trans_id;
Harald Welte49f48b82009-02-17 15:29:33 +00001801
Harald Welte65e74cc2008-12-29 01:55:35 +00001802 gh->msg_type = GSM48_MT_CC_SETUP;
Harald Welte09e38af2009-02-16 22:52:23 +00001803
Harald Welte4bfdfe72009-06-10 23:11:52 +08001804 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
Harald Welte65e74cc2008-12-29 01:55:35 +00001805
Harald Welte4bfdfe72009-06-10 23:11:52 +08001806 /* bearer capability */
1807 if (setup->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001808 gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001809 /* facility */
1810 if (setup->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001811 gsm48_encode_facility(msg, 0, &setup->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001812 /* progress */
1813 if (setup->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001814 gsm48_encode_progress(msg, 0, &setup->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001815 /* calling party BCD number */
1816 if (setup->fields & MNCC_F_CALLING)
Harald Welte55c8f352010-03-07 23:40:35 +01001817 gsm48_encode_calling(msg, &setup->calling);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001818 /* called party BCD number */
1819 if (setup->fields & MNCC_F_CALLED)
Harald Welte55c8f352010-03-07 23:40:35 +01001820 gsm48_encode_called(msg, &setup->called);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001821 /* user-user */
1822 if (setup->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001823 gsm48_encode_useruser(msg, 0, &setup->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001824 /* redirecting party BCD number */
1825 if (setup->fields & MNCC_F_REDIRECTING)
Harald Welte55c8f352010-03-07 23:40:35 +01001826 gsm48_encode_redirecting(msg, &setup->redirecting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001827 /* signal */
1828 if (setup->fields & MNCC_F_SIGNAL)
Harald Welte55c8f352010-03-07 23:40:35 +01001829 gsm48_encode_signal(msg, setup->signal);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001830
1831 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
Harald Welte65e74cc2008-12-29 01:55:35 +00001832
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001833 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte65e74cc2008-12-29 01:55:35 +00001834}
1835
Harald Welte4bfdfe72009-06-10 23:11:52 +08001836static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
1837{
1838 struct gsm48_hdr *gh = msgb_l3(msg);
1839 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1840 struct tlv_parsed tp;
1841 struct gsm_mncc call_conf;
1842
1843 gsm48_stop_cc_timer(trans);
1844 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
1845
1846 memset(&call_conf, 0, sizeof(struct gsm_mncc));
1847 call_conf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001848 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001849#if 0
1850 /* repeat */
1851 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
1852 call_conf.repeat = 1;
1853 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
1854 call_conf.repeat = 2;
1855#endif
1856 /* bearer capability */
1857 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
1858 call_conf.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001859 gsm48_decode_bearer_cap(&call_conf.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001860 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
1861 }
1862 /* cause */
1863 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
1864 call_conf.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01001865 gsm48_decode_cause(&call_conf.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001866 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
1867 }
1868 /* cc cap */
1869 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
1870 call_conf.fields |= MNCC_F_CCCAP;
Harald Welte55c8f352010-03-07 23:40:35 +01001871 gsm48_decode_cccap(&call_conf.cccap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001872 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
1873 }
1874
1875 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
1876
Harald Welte596fed42009-07-23 19:06:52 +02001877 return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND,
1878 &call_conf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001879}
1880
1881static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg)
1882{
1883 struct gsm_mncc *proceeding = arg;
1884 struct msgb *msg = gsm48_msgb_alloc();
1885 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1886
Harald Welte4bfdfe72009-06-10 23:11:52 +08001887 gh->msg_type = GSM48_MT_CC_CALL_PROC;
1888
1889 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
1890
1891 /* bearer capability */
1892 if (proceeding->fields & MNCC_F_BEARER_CAP)
Harald Welte55c8f352010-03-07 23:40:35 +01001893 gsm48_encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001894 /* facility */
1895 if (proceeding->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001896 gsm48_encode_facility(msg, 0, &proceeding->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001897 /* progress */
1898 if (proceeding->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001899 gsm48_encode_progress(msg, 0, &proceeding->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001900
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001901 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001902}
1903
1904static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
1905{
1906 struct gsm48_hdr *gh = msgb_l3(msg);
1907 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1908 struct tlv_parsed tp;
1909 struct gsm_mncc alerting;
1910
1911 gsm48_stop_cc_timer(trans);
1912 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
1913
1914 memset(&alerting, 0, sizeof(struct gsm_mncc));
1915 alerting.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01001916 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001917 /* facility */
1918 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
1919 alerting.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01001920 gsm48_decode_facility(&alerting.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001921 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
1922 }
1923
1924 /* progress */
1925 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
1926 alerting.fields |= MNCC_F_PROGRESS;
Harald Welte55c8f352010-03-07 23:40:35 +01001927 gsm48_decode_progress(&alerting.progress,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001928 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
1929 }
1930 /* ss-version */
1931 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
1932 alerting.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01001933 gsm48_decode_ssversion(&alerting.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08001934 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
1935 }
1936
1937 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
1938
Harald Welte596fed42009-07-23 19:06:52 +02001939 return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND,
1940 &alerting);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001941}
1942
1943static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
1944{
1945 struct gsm_mncc *alerting = arg;
1946 struct msgb *msg = gsm48_msgb_alloc();
1947 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1948
Harald Welte4bfdfe72009-06-10 23:11:52 +08001949 gh->msg_type = GSM48_MT_CC_ALERTING;
1950
1951 /* facility */
1952 if (alerting->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001953 gsm48_encode_facility(msg, 0, &alerting->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001954 /* progress */
1955 if (alerting->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001956 gsm48_encode_progress(msg, 0, &alerting->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001957 /* user-user */
1958 if (alerting->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001959 gsm48_encode_useruser(msg, 0, &alerting->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001960
1961 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
1962
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001963 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001964}
1965
1966static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
1967{
1968 struct gsm_mncc *progress = arg;
1969 struct msgb *msg = gsm48_msgb_alloc();
1970 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1971
Harald Welte4bfdfe72009-06-10 23:11:52 +08001972 gh->msg_type = GSM48_MT_CC_PROGRESS;
1973
1974 /* progress */
Harald Welte55c8f352010-03-07 23:40:35 +01001975 gsm48_encode_progress(msg, 1, &progress->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001976 /* user-user */
1977 if (progress->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01001978 gsm48_encode_useruser(msg, 0, &progress->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001979
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08001980 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001981}
1982
1983static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
1984{
1985 struct gsm_mncc *connect = arg;
1986 struct msgb *msg = gsm48_msgb_alloc();
1987 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1988
Harald Welte4bfdfe72009-06-10 23:11:52 +08001989 gh->msg_type = GSM48_MT_CC_CONNECT;
1990
1991 gsm48_stop_cc_timer(trans);
1992 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
1993
1994 /* facility */
1995 if (connect->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01001996 gsm48_encode_facility(msg, 0, &connect->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08001997 /* progress */
1998 if (connect->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01001999 gsm48_encode_progress(msg, 0, &connect->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002000 /* connected number */
2001 if (connect->fields & MNCC_F_CONNECTED)
Harald Welte55c8f352010-03-07 23:40:35 +01002002 gsm48_encode_connected(msg, &connect->connected);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002003 /* user-user */
2004 if (connect->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002005 gsm48_encode_useruser(msg, 0, &connect->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002006
2007 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
2008
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002009 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002010}
2011
2012static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
2013{
2014 struct gsm48_hdr *gh = msgb_l3(msg);
2015 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2016 struct tlv_parsed tp;
2017 struct gsm_mncc connect;
2018
2019 gsm48_stop_cc_timer(trans);
2020
2021 memset(&connect, 0, sizeof(struct gsm_mncc));
2022 connect.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002023 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002024 /* use subscriber as connected party number */
2025 if (trans->subscr) {
2026 connect.fields |= MNCC_F_CONNECTED;
2027 strncpy(connect.connected.number, trans->subscr->extension,
2028 sizeof(connect.connected.number)-1);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002029 strncpy(connect.imsi, trans->subscr->imsi,
2030 sizeof(connect.imsi)-1);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002031 }
2032 /* facility */
2033 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2034 connect.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002035 gsm48_decode_facility(&connect.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002036 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2037 }
2038 /* user-user */
2039 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2040 connect.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002041 gsm48_decode_useruser(&connect.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002042 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2043 }
2044 /* ss-version */
2045 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2046 connect.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002047 gsm48_decode_ssversion(&connect.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002048 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2049 }
2050
2051 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
2052
Harald Welte596fed42009-07-23 19:06:52 +02002053 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002054}
2055
2056
2057static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
2058{
2059 struct gsm_mncc connect_ack;
2060
2061 gsm48_stop_cc_timer(trans);
2062
2063 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2064
2065 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
2066 connect_ack.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002067 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002068 &connect_ack);
2069}
2070
2071static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
2072{
2073 struct msgb *msg = gsm48_msgb_alloc();
2074 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2075
Harald Welte4bfdfe72009-06-10 23:11:52 +08002076 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
2077
2078 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2079
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002080 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002081}
2082
2083static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
2084{
2085 struct gsm48_hdr *gh = msgb_l3(msg);
2086 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2087 struct tlv_parsed tp;
2088 struct gsm_mncc disc;
2089
2090 gsm48_stop_cc_timer(trans);
2091
2092 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
2093
2094 memset(&disc, 0, sizeof(struct gsm_mncc));
2095 disc.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002096 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002097 /* cause */
2098 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2099 disc.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002100 gsm48_decode_cause(&disc.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002101 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2102 }
2103 /* facility */
2104 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2105 disc.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002106 gsm48_decode_facility(&disc.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002107 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2108 }
2109 /* user-user */
2110 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2111 disc.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002112 gsm48_decode_useruser(&disc.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002113 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2114 }
2115 /* ss-version */
2116 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2117 disc.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002118 gsm48_decode_ssversion(&disc.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002119 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2120 }
2121
Harald Welte596fed42009-07-23 19:06:52 +02002122 return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002123
2124}
2125
Harald Weltec66b71c2009-06-11 14:23:20 +08002126static struct gsm_mncc_cause default_cause = {
2127 .location = GSM48_CAUSE_LOC_PRN_S_LU,
2128 .coding = 0,
2129 .rec = 0,
2130 .rec_val = 0,
2131 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
2132 .diag_len = 0,
2133 .diag = { 0 },
2134};
Harald Welte4bfdfe72009-06-10 23:11:52 +08002135
2136static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
2137{
2138 struct gsm_mncc *disc = arg;
2139 struct msgb *msg = gsm48_msgb_alloc();
2140 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2141
Harald Welte4bfdfe72009-06-10 23:11:52 +08002142 gh->msg_type = GSM48_MT_CC_DISCONNECT;
2143
2144 gsm48_stop_cc_timer(trans);
2145 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
2146
2147 /* cause */
2148 if (disc->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002149 gsm48_encode_cause(msg, 1, &disc->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002150 else
Harald Welte55c8f352010-03-07 23:40:35 +01002151 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002152
2153 /* facility */
2154 if (disc->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002155 gsm48_encode_facility(msg, 0, &disc->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002156 /* progress */
2157 if (disc->fields & MNCC_F_PROGRESS)
Harald Welte55c8f352010-03-07 23:40:35 +01002158 gsm48_encode_progress(msg, 0, &disc->progress);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002159 /* user-user */
2160 if (disc->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002161 gsm48_encode_useruser(msg, 0, &disc->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002162
2163 /* store disconnect cause for T306 expiry */
Harald Weltedcaf5652009-07-23 18:56:43 +02002164 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002165
2166 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
2167
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002168 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002169}
2170
2171static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
2172{
2173 struct gsm48_hdr *gh = msgb_l3(msg);
2174 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2175 struct tlv_parsed tp;
2176 struct gsm_mncc rel;
2177 int rc;
2178
2179 gsm48_stop_cc_timer(trans);
2180
2181 memset(&rel, 0, sizeof(struct gsm_mncc));
2182 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002183 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002184 /* cause */
2185 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2186 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002187 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002188 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2189 }
2190 /* facility */
2191 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2192 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002193 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002194 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2195 }
2196 /* user-user */
2197 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2198 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002199 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002200 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2201 }
2202 /* ss-version */
2203 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2204 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002205 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002206 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2207 }
2208
Harald Weltedcaf5652009-07-23 18:56:43 +02002209 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002210 /* release collision 5.4.5 */
Harald Welte596fed42009-07-23 19:06:52 +02002211 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002212 } else {
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08002213 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02002214 GSM48_PDISC_CC | (trans->transaction_id << 4),
Harald Welte596fed42009-07-23 19:06:52 +02002215 GSM48_MT_CC_RELEASE_COMPL);
2216 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002217 }
2218
2219 new_cc_state(trans, GSM_CSTATE_NULL);
2220
2221 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002222 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002223
2224 return rc;
2225}
2226
2227static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
2228{
2229 struct gsm_mncc *rel = arg;
2230 struct msgb *msg = gsm48_msgb_alloc();
2231 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2232
Harald Welte4bfdfe72009-06-10 23:11:52 +08002233 gh->msg_type = GSM48_MT_CC_RELEASE;
2234
2235 trans->callref = 0;
2236
2237 gsm48_stop_cc_timer(trans);
2238 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
2239
2240 /* cause */
2241 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002242 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002243 /* facility */
2244 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002245 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002246 /* user-user */
2247 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002248 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002249
Harald Weltedcaf5652009-07-23 18:56:43 +02002250 trans->cc.T308_second = 0;
2251 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002252
Harald Weltedcaf5652009-07-23 18:56:43 +02002253 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002254 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
2255
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002256 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002257}
2258
2259static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
2260{
2261 struct gsm48_hdr *gh = msgb_l3(msg);
2262 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2263 struct tlv_parsed tp;
2264 struct gsm_mncc rel;
2265 int rc = 0;
2266
2267 gsm48_stop_cc_timer(trans);
2268
2269 memset(&rel, 0, sizeof(struct gsm_mncc));
2270 rel.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002271 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002272 /* cause */
2273 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2274 rel.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002275 gsm48_decode_cause(&rel.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002276 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2277 }
2278 /* facility */
2279 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2280 rel.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002281 gsm48_decode_facility(&rel.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002282 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2283 }
2284 /* user-user */
2285 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2286 rel.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002287 gsm48_decode_useruser(&rel.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002288 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2289 }
2290 /* ss-version */
2291 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2292 rel.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002293 gsm48_decode_ssversion(&rel.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002294 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2295 }
2296
2297 if (trans->callref) {
Harald Weltedcaf5652009-07-23 18:56:43 +02002298 switch (trans->cc.state) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002299 case GSM_CSTATE_CALL_PRESENT:
Harald Welte596fed42009-07-23 19:06:52 +02002300 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002301 MNCC_REJ_IND, &rel);
2302 break;
2303 case GSM_CSTATE_RELEASE_REQ:
Harald Welte596fed42009-07-23 19:06:52 +02002304 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002305 MNCC_REL_CNF, &rel);
2306 break;
2307 default:
Harald Welte596fed42009-07-23 19:06:52 +02002308 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002309 MNCC_REL_IND, &rel);
2310 }
2311 }
2312
2313 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002314 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002315
2316 return rc;
2317}
2318
2319static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
2320{
2321 struct gsm_mncc *rel = arg;
2322 struct msgb *msg = gsm48_msgb_alloc();
2323 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Harald Weltec7782de2010-12-21 19:31:41 +01002324 int ret;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002325
Harald Welte4bfdfe72009-06-10 23:11:52 +08002326 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
2327
2328 trans->callref = 0;
2329
2330 gsm48_stop_cc_timer(trans);
2331
2332 /* cause */
2333 if (rel->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002334 gsm48_encode_cause(msg, 0, &rel->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002335 /* facility */
2336 if (rel->fields & MNCC_F_FACILITY)
Harald Welte55c8f352010-03-07 23:40:35 +01002337 gsm48_encode_facility(msg, 0, &rel->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002338 /* user-user */
2339 if (rel->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002340 gsm48_encode_useruser(msg, 0, &rel->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002341
Harald Weltec7782de2010-12-21 19:31:41 +01002342 ret = gsm48_conn_sendmsg(msg, trans->conn, trans);
2343
Harald Weltedcaf5652009-07-23 18:56:43 +02002344 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002345
Harald Weltec7782de2010-12-21 19:31:41 +01002346 return ret;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002347}
2348
2349static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
2350{
2351 struct gsm48_hdr *gh = msgb_l3(msg);
2352 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2353 struct tlv_parsed tp;
2354 struct gsm_mncc fac;
2355
2356 memset(&fac, 0, sizeof(struct gsm_mncc));
2357 fac.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002358 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002359 /* facility */
2360 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2361 fac.fields |= MNCC_F_FACILITY;
Harald Welte55c8f352010-03-07 23:40:35 +01002362 gsm48_decode_facility(&fac.facility,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002363 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2364 }
2365 /* ss-version */
2366 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2367 fac.fields |= MNCC_F_SSVERSION;
Harald Welte55c8f352010-03-07 23:40:35 +01002368 gsm48_decode_ssversion(&fac.ssversion,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002369 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2370 }
2371
Harald Welte596fed42009-07-23 19:06:52 +02002372 return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002373}
2374
2375static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
2376{
2377 struct gsm_mncc *fac = arg;
2378 struct msgb *msg = gsm48_msgb_alloc();
2379 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2380
Harald Welte4bfdfe72009-06-10 23:11:52 +08002381 gh->msg_type = GSM48_MT_CC_FACILITY;
2382
2383 /* facility */
Harald Welte55c8f352010-03-07 23:40:35 +01002384 gsm48_encode_facility(msg, 1, &fac->facility);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002385
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002386 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002387}
2388
2389static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
2390{
2391 struct gsm_mncc hold;
2392
2393 memset(&hold, 0, sizeof(struct gsm_mncc));
2394 hold.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002395 return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002396}
2397
2398static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
2399{
2400 struct msgb *msg = gsm48_msgb_alloc();
2401 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2402
Harald Welte4bfdfe72009-06-10 23:11:52 +08002403 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
2404
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002405 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002406}
2407
2408static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
2409{
2410 struct gsm_mncc *hold_rej = arg;
2411 struct msgb *msg = gsm48_msgb_alloc();
2412 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2413
Harald Welte4bfdfe72009-06-10 23:11:52 +08002414 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
2415
2416 /* cause */
2417 if (hold_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002418 gsm48_encode_cause(msg, 1, &hold_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002419 else
Harald Welte55c8f352010-03-07 23:40:35 +01002420 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002421
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002422 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002423}
2424
2425static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
2426{
2427 struct gsm_mncc retrieve;
2428
2429 memset(&retrieve, 0, sizeof(struct gsm_mncc));
2430 retrieve.callref = trans->callref;
Harald Welte596fed42009-07-23 19:06:52 +02002431 return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND,
2432 &retrieve);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002433}
2434
2435static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
2436{
2437 struct msgb *msg = gsm48_msgb_alloc();
2438 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2439
Harald Welte4bfdfe72009-06-10 23:11:52 +08002440 gh->msg_type = GSM48_MT_CC_RETR_ACK;
2441
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002442 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002443}
2444
2445static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
2446{
2447 struct gsm_mncc *retrieve_rej = arg;
2448 struct msgb *msg = gsm48_msgb_alloc();
2449 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2450
Harald Welte4bfdfe72009-06-10 23:11:52 +08002451 gh->msg_type = GSM48_MT_CC_RETR_REJ;
2452
2453 /* cause */
2454 if (retrieve_rej->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002455 gsm48_encode_cause(msg, 1, &retrieve_rej->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002456 else
Harald Welte55c8f352010-03-07 23:40:35 +01002457 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002458
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002459 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002460}
2461
2462static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
2463{
2464 struct gsm48_hdr *gh = msgb_l3(msg);
2465 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2466 struct tlv_parsed tp;
2467 struct gsm_mncc dtmf;
2468
2469 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2470 dtmf.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002471 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002472 /* keypad facility */
2473 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
2474 dtmf.fields |= MNCC_F_KEYPAD;
Harald Welte55c8f352010-03-07 23:40:35 +01002475 gsm48_decode_keypad(&dtmf.keypad,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002476 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
2477 }
2478
Harald Welte596fed42009-07-23 19:06:52 +02002479 return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002480}
2481
2482static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
2483{
2484 struct gsm_mncc *dtmf = arg;
2485 struct msgb *msg = gsm48_msgb_alloc();
2486 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2487
Harald Welte4bfdfe72009-06-10 23:11:52 +08002488 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
2489
2490 /* keypad */
2491 if (dtmf->fields & MNCC_F_KEYPAD)
Harald Welte55c8f352010-03-07 23:40:35 +01002492 gsm48_encode_keypad(msg, dtmf->keypad);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002493
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002494 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002495}
2496
2497static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
2498{
2499 struct gsm_mncc *dtmf = arg;
2500 struct msgb *msg = gsm48_msgb_alloc();
2501 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2502
Harald Welte4bfdfe72009-06-10 23:11:52 +08002503 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
2504
2505 /* cause */
2506 if (dtmf->fields & MNCC_F_CAUSE)
Harald Welte55c8f352010-03-07 23:40:35 +01002507 gsm48_encode_cause(msg, 1, &dtmf->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002508 else
Harald Welte55c8f352010-03-07 23:40:35 +01002509 gsm48_encode_cause(msg, 1, &default_cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002510
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002511 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002512}
2513
2514static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
2515{
2516 struct msgb *msg = gsm48_msgb_alloc();
2517 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2518
Harald Welte4bfdfe72009-06-10 23:11:52 +08002519 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
2520
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002521 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002522}
2523
2524static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
2525{
2526 struct gsm_mncc dtmf;
2527
2528 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2529 dtmf.callref = trans->callref;
2530
Harald Welte596fed42009-07-23 19:06:52 +02002531 return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002532}
2533
2534static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
2535{
2536 struct gsm48_hdr *gh = msgb_l3(msg);
2537 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2538 struct tlv_parsed tp;
2539 struct gsm_mncc modify;
2540
2541 memset(&modify, 0, sizeof(struct gsm_mncc));
2542 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002543 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002544 /* bearer capability */
2545 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2546 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002547 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002548 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2549 }
2550
2551 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
2552
Harald Welte596fed42009-07-23 19:06:52 +02002553 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002554}
2555
2556static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
2557{
2558 struct gsm_mncc *modify = arg;
2559 struct msgb *msg = gsm48_msgb_alloc();
2560 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2561
Harald Welte4bfdfe72009-06-10 23:11:52 +08002562 gh->msg_type = GSM48_MT_CC_MODIFY;
2563
2564 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
2565
2566 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002567 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002568
2569 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
2570
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002571 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002572}
2573
2574static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
2575{
2576 struct gsm48_hdr *gh = msgb_l3(msg);
2577 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2578 struct tlv_parsed tp;
2579 struct gsm_mncc modify;
2580
2581 gsm48_stop_cc_timer(trans);
2582
2583 memset(&modify, 0, sizeof(struct gsm_mncc));
2584 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002585 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002586 /* bearer capability */
2587 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2588 modify.fields |= MNCC_F_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002589 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002590 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2591 }
2592
2593 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2594
Harald Welte596fed42009-07-23 19:06:52 +02002595 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002596}
2597
2598static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
2599{
2600 struct gsm_mncc *modify = arg;
2601 struct msgb *msg = gsm48_msgb_alloc();
2602 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2603
Harald Welte4bfdfe72009-06-10 23:11:52 +08002604 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
2605
2606 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002607 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002608
2609 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2610
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002611 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002612}
2613
2614static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
2615{
2616 struct gsm48_hdr *gh = msgb_l3(msg);
2617 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2618 struct tlv_parsed tp;
2619 struct gsm_mncc modify;
2620
2621 gsm48_stop_cc_timer(trans);
2622
2623 memset(&modify, 0, sizeof(struct gsm_mncc));
2624 modify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002625 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002626 /* bearer capability */
2627 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2628 modify.fields |= GSM48_IE_BEARER_CAP;
Harald Welte55c8f352010-03-07 23:40:35 +01002629 gsm48_decode_bearer_cap(&modify.bearer_cap,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002630 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2631 }
2632 /* cause */
2633 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2634 modify.fields |= MNCC_F_CAUSE;
Harald Welte55c8f352010-03-07 23:40:35 +01002635 gsm48_decode_cause(&modify.cause,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002636 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2637 }
2638
2639 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2640
Harald Welte596fed42009-07-23 19:06:52 +02002641 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002642}
2643
2644static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
2645{
2646 struct gsm_mncc *modify = arg;
2647 struct msgb *msg = gsm48_msgb_alloc();
2648 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2649
Harald Welte4bfdfe72009-06-10 23:11:52 +08002650 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
2651
2652 /* bearer capability */
Harald Welte55c8f352010-03-07 23:40:35 +01002653 gsm48_encode_bearer_cap(msg, 1, &modify->bearer_cap);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002654 /* cause */
Harald Welte55c8f352010-03-07 23:40:35 +01002655 gsm48_encode_cause(msg, 1, &modify->cause);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002656
2657 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2658
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002659 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002660}
2661
2662static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
2663{
2664 struct gsm_mncc *notify = arg;
2665 struct msgb *msg = gsm48_msgb_alloc();
2666 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2667
Harald Welte4bfdfe72009-06-10 23:11:52 +08002668 gh->msg_type = GSM48_MT_CC_NOTIFY;
2669
2670 /* notify */
Harald Welte55c8f352010-03-07 23:40:35 +01002671 gsm48_encode_notify(msg, notify->notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002672
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002673 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002674}
2675
2676static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
2677{
2678 struct gsm48_hdr *gh = msgb_l3(msg);
2679 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2680// struct tlv_parsed tp;
2681 struct gsm_mncc notify;
2682
2683 memset(&notify, 0, sizeof(struct gsm_mncc));
2684 notify.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002685// tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002686 if (payload_len >= 1)
Harald Welte55c8f352010-03-07 23:40:35 +01002687 gsm48_decode_notify(&notify.notify, gh->data);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002688
Harald Welte596fed42009-07-23 19:06:52 +02002689 return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, &notify);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002690}
2691
2692static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
2693{
2694 struct gsm_mncc *user = arg;
2695 struct msgb *msg = gsm48_msgb_alloc();
2696 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2697
Harald Welte4bfdfe72009-06-10 23:11:52 +08002698 gh->msg_type = GSM48_MT_CC_USER_INFO;
2699
2700 /* user-user */
2701 if (user->fields & MNCC_F_USERUSER)
Harald Welte55c8f352010-03-07 23:40:35 +01002702 gsm48_encode_useruser(msg, 1, &user->useruser);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002703 /* more data */
2704 if (user->more)
Harald Welte55c8f352010-03-07 23:40:35 +01002705 gsm48_encode_more(msg);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002706
Holger Hans Peter Freyther9c137a72010-06-15 13:57:40 +08002707 return gsm48_conn_sendmsg(msg, trans->conn, trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002708}
2709
2710static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
2711{
2712 struct gsm48_hdr *gh = msgb_l3(msg);
2713 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2714 struct tlv_parsed tp;
2715 struct gsm_mncc user;
2716
2717 memset(&user, 0, sizeof(struct gsm_mncc));
2718 user.callref = trans->callref;
Harald Welte474d19f2010-03-02 23:18:30 +01002719 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002720 /* user-user */
2721 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2722 user.fields |= MNCC_F_USERUSER;
Harald Welte55c8f352010-03-07 23:40:35 +01002723 gsm48_decode_useruser(&user.useruser,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002724 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2725 }
2726 /* more data */
2727 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
2728 user.more = 1;
2729
Harald Welte596fed42009-07-23 19:06:52 +02002730 return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002731}
2732
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002733static int _gsm48_lchan_modify(struct gsm_trans *trans, void *arg)
Harald Welte4bfdfe72009-06-10 23:11:52 +08002734{
2735 struct gsm_mncc *mode = arg;
2736
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002737 return gsm48_lchan_modify(trans->conn->lchan, mode->lchan_mode);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002738}
2739
2740static struct downstate {
2741 u_int32_t states;
2742 int type;
2743 int (*rout) (struct gsm_trans *trans, void *arg);
2744} downstatelist[] = {
2745 /* mobile originating call establishment */
2746 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
2747 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc},
2748 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
2749 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
2750 {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 */
2751 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
2752 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
2753 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
2754 /* mobile terminating call establishment */
2755 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
2756 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
2757 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
2758 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
2759 /* signalling during call */
2760 {SBIT(GSM_CSTATE_ACTIVE),
2761 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
2762 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
2763 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
2764 {ALL_STATES,
2765 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
2766 {ALL_STATES,
2767 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
2768 {ALL_STATES,
2769 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
2770 {SBIT(GSM_CSTATE_ACTIVE),
2771 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
2772 {SBIT(GSM_CSTATE_ACTIVE),
2773 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
2774 {SBIT(GSM_CSTATE_ACTIVE),
2775 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
2776 {SBIT(GSM_CSTATE_ACTIVE),
2777 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
2778 {SBIT(GSM_CSTATE_ACTIVE),
2779 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
2780 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2781 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
2782 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
2783 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
2784 {SBIT(GSM_CSTATE_ACTIVE),
2785 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
2786 /* clearing */
2787 {SBIT(GSM_CSTATE_INITIATED),
2788 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
2789 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
2790 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
2791 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
2792 MNCC_REL_REQ, gsm48_cc_tx_release},
2793 /* special */
2794 {ALL_STATES,
Holger Hans Peter Freytherff3f2602009-10-22 15:13:00 +02002795 MNCC_LCHAN_MODIFY, _gsm48_lchan_modify},
Harald Welte4bfdfe72009-06-10 23:11:52 +08002796};
2797
2798#define DOWNSLLEN \
2799 (sizeof(downstatelist) / sizeof(struct downstate))
2800
2801
2802int mncc_send(struct gsm_network *net, int msg_type, void *arg)
2803{
Harald Welte1a6f7982009-08-09 18:52:33 +02002804 int i, rc = 0;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002805 struct gsm_trans *trans = NULL, *transt;
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002806 struct gsm_subscriber_connection *conn = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002807 struct gsm_bts *bts = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002808 struct gsm_mncc *data = arg, rel;
2809
2810 /* handle special messages */
2811 switch(msg_type) {
2812 case MNCC_BRIDGE:
2813 return tch_bridge(net, arg);
2814 case MNCC_FRAME_DROP:
Harald Welteda7ab742009-12-19 22:23:05 +01002815 return tch_recv_mncc(net, data->callref, 0);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002816 case MNCC_FRAME_RECV:
Harald Welteda7ab742009-12-19 22:23:05 +01002817 return tch_recv_mncc(net, data->callref, 1);
2818 case GSM_TCHF_FRAME:
2819 /* Find callref */
2820 trans = trans_find_by_callref(net, data->callref);
2821 if (!trans)
2822 return -EIO;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002823 if (!trans->conn)
Harald Welteda7ab742009-12-19 22:23:05 +01002824 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002825 if (trans->conn->lchan->type != GSM_LCHAN_TCH_F)
Harald Welteda7ab742009-12-19 22:23:05 +01002826 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002827 bts = trans->conn->lchan->ts->trx->bts;
Harald Welteda7ab742009-12-19 22:23:05 +01002828 switch (bts->type) {
2829 case GSM_BTS_TYPE_NANOBTS:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002830 if (!trans->conn->lchan->abis_ip.rtp_socket)
Harald Welteda7ab742009-12-19 22:23:05 +01002831 return 0;
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002832 return rtp_send_frame(trans->conn->lchan->abis_ip.rtp_socket, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002833 case GSM_BTS_TYPE_BS11:
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002834 return trau_send_frame(trans->conn->lchan, arg);
Harald Welteda7ab742009-12-19 22:23:05 +01002835 default:
2836 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
2837 }
2838 return -EINVAL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002839 }
2840
2841 memset(&rel, 0, sizeof(struct gsm_mncc));
2842 rel.callref = data->callref;
2843
2844 /* Find callref */
Harald Weltedcaf5652009-07-23 18:56:43 +02002845 trans = trans_find_by_callref(net, data->callref);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002846
2847 /* Callref unknown */
2848 if (!trans) {
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002849 struct gsm_subscriber *subscr;
2850
Harald Welte4a3464c2009-07-04 10:11:24 +02002851 if (msg_type != MNCC_SETUP_REQ) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002852 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2853 "Received '%s' from MNCC with "
2854 "unknown callref %d\n", data->called.number,
2855 get_mncc_name(msg_type), data->callref);
2856 /* Invalid call reference */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002857 return mncc_release_ind(net, NULL, data->callref,
2858 GSM48_CAUSE_LOC_PRN_S_LU,
2859 GSM48_CC_CAUSE_INVAL_TRANS_ID);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002860 }
Andreas Eversbergc079be42009-06-15 23:22:09 +02002861 if (!data->called.number[0] && !data->imsi[0]) {
2862 DEBUGP(DCC, "(bts - trx - ts - ti) "
2863 "Received '%s' from MNCC with "
2864 "no number or IMSI\n", get_mncc_name(msg_type));
2865 /* Invalid number */
2866 return mncc_release_ind(net, NULL, data->callref,
2867 GSM48_CAUSE_LOC_PRN_S_LU,
2868 GSM48_CC_CAUSE_INV_NR_FORMAT);
2869 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002870 /* New transaction due to setup, find subscriber */
Andreas Eversbergc079be42009-06-15 23:22:09 +02002871 if (data->called.number[0])
Harald Welte9176bd42009-07-23 18:46:00 +02002872 subscr = subscr_get_by_extension(net,
2873 data->called.number);
Andreas Eversbergc079be42009-06-15 23:22:09 +02002874 else
Harald Welte9176bd42009-07-23 18:46:00 +02002875 subscr = subscr_get_by_imsi(net, data->imsi);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002876 /* If subscriber is not found */
2877 if (!subscr) {
2878 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2879 "Received '%s' from MNCC with "
2880 "unknown subscriber %s\n", data->called.number,
2881 get_mncc_name(msg_type), data->called.number);
2882 /* Unknown subscriber */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002883 return mncc_release_ind(net, NULL, data->callref,
2884 GSM48_CAUSE_LOC_PRN_S_LU,
2885 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002886 }
2887 /* If subscriber is not "attached" */
2888 if (!subscr->lac) {
2889 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
2890 "Received '%s' from MNCC with "
2891 "detached subscriber %s\n", data->called.number,
2892 get_mncc_name(msg_type), data->called.number);
2893 subscr_put(subscr);
2894 /* Temporarily out of order */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002895 return mncc_release_ind(net, NULL, data->callref,
2896 GSM48_CAUSE_LOC_PRN_S_LU,
2897 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002898 }
2899 /* Create transaction */
Harald Weltedcaf5652009-07-23 18:56:43 +02002900 trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref);
2901 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002902 DEBUGP(DCC, "No memory for trans.\n");
2903 subscr_put(subscr);
2904 /* Ressource unavailable */
Andreas Eversberg7563ac92009-06-14 22:14:12 +08002905 mncc_release_ind(net, NULL, data->callref,
2906 GSM48_CAUSE_LOC_PRN_S_LU,
2907 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002908 return -ENOMEM;
2909 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08002910 /* Find lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002911 conn = connection_for_subscr(subscr);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01002912
Harald Welte4bfdfe72009-06-10 23:11:52 +08002913 /* If subscriber has no lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002914 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002915 /* find transaction with this subscriber already paging */
2916 llist_for_each_entry(transt, &net->trans_list, entry) {
2917 /* Transaction of our lchan? */
2918 if (transt == trans ||
2919 transt->subscr != subscr)
2920 continue;
2921 DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) "
2922 "Received '%s' from MNCC with "
2923 "unallocated channel, paging already "
2924 "started.\n", bts->nr,
2925 data->called.number,
2926 get_mncc_name(msg_type));
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002927 subscr_put(subscr);
2928 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002929 return 0;
2930 }
2931 /* store setup informations until paging was successfull */
Harald Weltedcaf5652009-07-23 18:56:43 +02002932 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
Sylvain Munaut567c8dc2010-12-01 22:17:36 +01002933
2934 /* Get a channel */
2935 subscr_get_channel(subscr, RSL_CHANNEED_TCH_F, setup_trig_pag_evt, subscr);
2936
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002937 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002938 return 0;
2939 }
2940 /* Assign lchan */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002941 trans->conn = conn;
Holger Hans Peter Freytherccf53c62009-10-27 14:21:14 +01002942 subscr_put(subscr);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002943 }
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002944
2945 if (trans->conn)
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002946 conn = trans->conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08002947
2948 /* if paging did not respond yet */
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002949 if (!conn) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08002950 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02002951 "Received '%s' from MNCC in paging state\n",
Harald Welte4bfdfe72009-06-10 23:11:52 +08002952 (trans->subscr)?(trans->subscr->extension):"-",
2953 get_mncc_name(msg_type));
Harald Weltec66b71c2009-06-11 14:23:20 +08002954 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
2955 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002956 if (msg_type == MNCC_REL_REQ)
2957 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
2958 else
2959 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
2960 trans->callref = 0;
Harald Weltedcaf5652009-07-23 18:56:43 +02002961 trans_free(trans);
Harald Welte4bfdfe72009-06-10 23:11:52 +08002962 return rc;
2963 }
2964
2965 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) "
2966 "Received '%s' from MNCC in state %d (%s)\n",
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +08002967 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Harald Welte4bfdfe72009-06-10 23:11:52 +08002968 trans->transaction_id,
Holger Hans Peter Freythere95d4822010-03-23 07:00:22 +01002969 (trans->conn->subscr)?(trans->conn->subscr->extension):"-",
Harald Weltedcaf5652009-07-23 18:56:43 +02002970 get_mncc_name(msg_type), trans->cc.state,
Harald Weltee95daf192010-03-25 12:13:02 +08002971 gsm48_cc_state_name(trans->cc.state));
Harald Welte4bfdfe72009-06-10 23:11:52 +08002972
2973 /* Find function for current state and message */
2974 for (i = 0; i < DOWNSLLEN; i++)
2975 if ((msg_type == downstatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02002976 && ((1 << trans->cc.state) & downstatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08002977 break;
2978 if (i == DOWNSLLEN) {
2979 DEBUGP(DCC, "Message unhandled at this state.\n");
2980 return 0;
2981 }
2982
2983 rc = downstatelist[i].rout(trans, arg);
2984
2985 return rc;
2986}
2987
2988
2989static struct datastate {
2990 u_int32_t states;
2991 int type;
2992 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
2993} datastatelist[] = {
2994 /* mobile originating call establishment */
2995 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2996 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
2997 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
2998 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
2999 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
3000 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
3001 /* mobile terminating call establishment */
3002 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
3003 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
3004 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
3005 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
Holger Hans Peter Freytheracf8a0c2010-03-29 08:47:44 +02003006 {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 +08003007 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
3008 /* signalling during call */
3009 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
3010 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
3011 {SBIT(GSM_CSTATE_ACTIVE),
3012 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
3013 {ALL_STATES,
3014 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
3015 {ALL_STATES,
3016 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
3017 {ALL_STATES,
3018 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
3019 {SBIT(GSM_CSTATE_ACTIVE),
3020 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
3021 {SBIT(GSM_CSTATE_ACTIVE),
3022 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
3023 {SBIT(GSM_CSTATE_ACTIVE),
3024 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
3025 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3026 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
3027 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3028 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
3029 {SBIT(GSM_CSTATE_ACTIVE),
3030 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
3031 /* clearing */
3032 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3033 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
3034 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
3035 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
3036 {ALL_STATES, /* 5.4.3.4 */
3037 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
3038};
3039
3040#define DATASLLEN \
3041 (sizeof(datastatelist) / sizeof(struct datastate))
3042
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003043static int gsm0408_rcv_cc(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte4bc90a12008-12-27 16:32:52 +00003044{
3045 struct gsm48_hdr *gh = msgb_l3(msg);
3046 u_int8_t msg_type = gh->msg_type & 0xbf;
Harald Welte6f5aee02009-07-23 21:21:14 +02003047 u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */
Harald Weltedcaf5652009-07-23 18:56:43 +02003048 struct gsm_trans *trans = NULL;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003049 int i, rc = 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00003050
Harald Welte4bfdfe72009-06-10 23:11:52 +08003051 if (msg_type & 0x80) {
3052 DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type);
3053 return -EINVAL;
Harald Welte4bc90a12008-12-27 16:32:52 +00003054 }
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003055
Harald Welte4bfdfe72009-06-10 23:11:52 +08003056 /* Find transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003057 trans = trans_find_by_id(conn->subscr, GSM48_PDISC_CC, transaction_id);
Harald Weltedcaf5652009-07-23 18:56:43 +02003058
Harald Welte6f5aee02009-07-23 21:21:14 +02003059 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003060 "Received '%s' from MS in state %d (%s)\n",
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003061 conn->bts->nr, conn->lchan->ts->trx->nr, conn->lchan->ts->nr,
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003062 transaction_id, (conn->subscr)?(conn->subscr->extension):"-",
Harald Weltee95daf192010-03-25 12:13:02 +08003063 gsm48_cc_msg_name(msg_type), trans?(trans->cc.state):0,
3064 gsm48_cc_state_name(trans?(trans->cc.state):0));
Harald Welte4bfdfe72009-06-10 23:11:52 +08003065
3066 /* Create transaction */
3067 if (!trans) {
Harald Welte6f5aee02009-07-23 21:21:14 +02003068 DEBUGP(DCC, "Unknown transaction ID %x, "
Harald Welte4bfdfe72009-06-10 23:11:52 +08003069 "creating new trans.\n", transaction_id);
3070 /* Create transaction */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +01003071 trans = trans_alloc(conn->subscr, GSM48_PDISC_CC,
Harald Weltedcaf5652009-07-23 18:56:43 +02003072 transaction_id, new_callref++);
3073 if (!trans) {
Harald Welte4bfdfe72009-06-10 23:11:52 +08003074 DEBUGP(DCC, "No memory for trans.\n");
Holger Hans Peter Freythere9ed3402010-06-16 12:30:50 +08003075 rc = gsm48_tx_simple(trans->conn,
Harald Welte6f5aee02009-07-23 21:21:14 +02003076 GSM48_PDISC_CC | (transaction_id << 4),
Harald Welte4bfdfe72009-06-10 23:11:52 +08003077 GSM48_MT_CC_RELEASE_COMPL);
3078 return -ENOMEM;
3079 }
Harald Welte4bfdfe72009-06-10 23:11:52 +08003080 /* Assign transaction */
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003081 trans->conn = conn;
Harald Welte4bfdfe72009-06-10 23:11:52 +08003082 }
3083
3084 /* find function for current state and message */
3085 for (i = 0; i < DATASLLEN; i++)
3086 if ((msg_type == datastatelist[i].type)
Harald Weltedcaf5652009-07-23 18:56:43 +02003087 && ((1 << trans->cc.state) & datastatelist[i].states))
Harald Welte4bfdfe72009-06-10 23:11:52 +08003088 break;
3089 if (i == DATASLLEN) {
3090 DEBUGP(DCC, "Message unhandled at this state.\n");
3091 return 0;
3092 }
3093
3094 rc = datastatelist[i].rout(trans, msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00003095
3096 return rc;
3097}
3098
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003099/* Create a dummy to wait five seconds */
3100static void release_anchor(struct gsm_subscriber_connection *conn)
3101{
3102 if (!conn->anch_operation)
3103 return;
3104
3105 bsc_del_timer(&conn->anch_operation->timeout);
3106 talloc_free(conn->anch_operation);
3107 conn->anch_operation = NULL;
3108}
3109
3110static void anchor_timeout(void *_data)
3111{
3112 struct gsm_subscriber_connection *con = _data;
3113
3114 release_anchor(con);
3115 msc_release_connection(con);
3116}
3117
3118int gsm0408_new_conn(struct gsm_subscriber_connection *conn)
3119{
3120 conn->anch_operation = talloc_zero(conn, struct gsm_anchor_operation);
3121 if (!conn->anch_operation)
3122 return -1;
3123
3124 conn->anch_operation->timeout.data = conn;
3125 conn->anch_operation->timeout.cb = anchor_timeout;
3126 bsc_schedule_timer(&conn->anch_operation->timeout, 5, 0);
3127 return 0;
3128}
3129
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003130/* here we get data from the BSC level... */
3131int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +00003132{
3133 struct gsm48_hdr *gh = msgb_l3(msg);
3134 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +00003135 int rc = 0;
Harald Welte51008772009-12-29 11:49:12 +01003136
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +08003137 if (silent_call_reroute(conn, msg))
3138 return silent_call_rx(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003139
3140 switch (pdisc) {
3141 case GSM48_PDISC_CC:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003142 release_anchor(conn);
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003143 rc = gsm0408_rcv_cc(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003144 break;
3145 case GSM48_PDISC_MM:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003146 rc = gsm0408_rcv_mm(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003147 break;
3148 case GSM48_PDISC_RR:
Holger Hans Peter Freyther3f122be2010-06-17 17:14:35 +08003149 rc = gsm0408_rcv_rr(conn, msg);
Harald Welte52b1f982008-12-23 20:25:15 +00003150 break;
Harald Weltebcae43f2008-12-27 21:45:37 +00003151 case GSM48_PDISC_SMS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003152 release_anchor(conn);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +08003153 rc = gsm0411_rcv_sms(conn, msg);
Harald Weltebcae43f2008-12-27 21:45:37 +00003154 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003155 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +00003156 case GSM48_PDISC_SM_GPRS:
Harald Welte5d24ba12009-12-24 12:13:17 +01003157 LOGP(DRLL, LOGL_NOTICE, "Unimplemented "
3158 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003159 break;
Harald Welte6eafe912009-10-16 08:32:58 +02003160 case GSM48_PDISC_NC_SS:
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +08003161 release_anchor(conn);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +08003162 rc = handle_rcv_ussd(conn, msg);
Harald Welte6eafe912009-10-16 08:32:58 +02003163 break;
Harald Welte52b1f982008-12-23 20:25:15 +00003164 default:
Harald Welte5d24ba12009-12-24 12:13:17 +01003165 LOGP(DRLL, LOGL_NOTICE, "Unknown "
3166 "GSM 04.08 discriminator 0x%02x\n", pdisc);
Harald Welte52b1f982008-12-23 20:25:15 +00003167 break;
3168 }
3169
3170 return rc;
3171}
Harald Welte8470bf22008-12-25 23:28:35 +00003172
Harald Welte805f6442009-07-28 18:25:29 +02003173/*
3174 * This will be ran by the linker when loading the DSO. We use it to
3175 * do system initialization, e.g. registration of signal handlers.
3176 */
3177static __attribute__((constructor)) void on_dso_load_0408(void)
3178{
Harald Welte805f6442009-07-28 18:25:29 +02003179 register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL);
3180}