blob: 23739657dc35072219a5fb083e1046e0438581d8 [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
2 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30#include <time.h>
31#include <netinet/in.h>
32
33#include <openbsc/db.h>
34#include <openbsc/msgb.h>
35#include <openbsc/tlv.h>
36#include <openbsc/debug.h>
37#include <openbsc/gsm_data.h>
Daniel Willmannc8188202009-08-13 03:42:07 +020038#include <openbsc/gsm_utils.h>
Harald Welte59b04682009-06-10 05:40:52 +080039#include <openbsc/gsm_subscriber.h>
40#include <openbsc/gsm_04_11.h>
41#include <openbsc/gsm_04_08.h>
42#include <openbsc/abis_rsl.h>
43#include <openbsc/chan_alloc.h>
44#include <openbsc/paging.h>
45#include <openbsc/signal.h>
46#include <openbsc/trau_frame.h>
47#include <openbsc/trau_mux.h>
Harald Welte3c062072009-07-28 18:25:29 +020048#include <openbsc/rtp_proxy.h>
Harald Weltea8379772009-06-20 22:36:41 +020049#include <openbsc/talloc.h>
Harald Weltec2189a62009-07-23 18:56:43 +020050#include <openbsc/transaction.h>
Harald Welte03115042009-10-16 08:32:58 +020051#include <openbsc/ussd.h>
Harald Welte59b04682009-06-10 05:40:52 +080052
Harald Welteb8a18b52009-06-10 12:08:54 +080053#define GSM_MAX_FACILITY 128
54#define GSM_MAX_SSVERSION 128
55#define GSM_MAX_USERUSER 128
56
Harald Welte (local)8751ee92009-08-15 02:30:58 +020057void *tall_locop_ctx;
Harald Weltea8379772009-06-20 22:36:41 +020058
Holger Hans Peter Freyther36897102009-08-01 07:26:59 +020059extern int ipacc_rtp_direct;
Harald Welte3c062072009-07-28 18:25:29 +020060
Harald Welte59b04682009-06-10 05:40:52 +080061static const struct tlv_definition rsl_att_tlvdef = {
62 .def = {
63 [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV },
64 [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV },
65 [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV },
66 [GSM48_IE_UTC] = { TLV_TYPE_TV },
67 [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 },
68 [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV },
69
70 [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV },
71 [GSM48_IE_CAUSE] = { TLV_TYPE_TLV },
72 [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV },
73 [GSM48_IE_ALERT] = { TLV_TYPE_TLV },
74 [GSM48_IE_FACILITY] = { TLV_TYPE_TLV },
75 [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV },
76 [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV },
Harald Welteb8a18b52009-06-10 12:08:54 +080077 [GSM48_IE_NOTIFY] = { TLV_TYPE_TV },
Harald Welte59b04682009-06-10 05:40:52 +080078 [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV },
79 [GSM48_IE_SIGNAL] = { TLV_TYPE_TV },
Harald Welteb8a18b52009-06-10 12:08:54 +080080 [GSM48_IE_CONN_BCD] = { TLV_TYPE_TLV },
81 [GSM48_IE_CONN_SUB] = { TLV_TYPE_TLV },
Harald Welte59b04682009-06-10 05:40:52 +080082 [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV },
83 [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV },
84 [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV },
85 [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV },
86 [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV },
87 [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV },
88 [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV },
89 [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV },
90 [GSM48_IE_USER_USER] = { TLV_TYPE_TLV },
91 [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV },
92 [GSM48_IE_MORE_DATA] = { TLV_TYPE_T },
93 [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T },
94 [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T },
95 [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T },
Harald Welteb8a18b52009-06-10 12:08:54 +080096 [GSM48_IE_REPEAT_CIR] = { TLV_TYPE_T },
97 [GSM48_IE_REPEAT_SEQ] = { TLV_TYPE_T },
Harald Welte59b04682009-06-10 05:40:52 +080098 /* FIXME: more elements */
99 },
100};
101
102static const char *rr_cause_names[] = {
103 [GSM48_RR_CAUSE_NORMAL] = "Normal event",
104 [GSM48_RR_CAUSE_ABNORMAL_UNSPEC] = "Abnormal release, unspecified",
105 [GSM48_RR_CAUSE_ABNORMAL_UNACCT] = "Abnormal release, channel unacceptable",
106 [GSM48_RR_CAUSE_ABNORMAL_TIMER] = "Abnormal release, timer expired",
107 [GSM48_RR_CAUSE_ABNORMAL_NOACT] = "Abnormal release, no activity on radio path",
108 [GSM48_RR_CAUSE_PREMPTIVE_REL] = "Preemptive release",
109 [GSM48_RR_CAUSE_HNDOVER_IMP] = "Handover impossible, timing advance out of range",
110 [GSM48_RR_CAUSE_CHAN_MODE_UNACCT] = "Channel mode unacceptable",
111 [GSM48_RR_CAUSE_FREQ_NOT_IMPL] = "Frequency not implemented",
112 [GSM48_RR_CAUSE_CALL_CLEARED] = "Call already cleared",
113 [GSM48_RR_CAUSE_SEMANT_INCORR] = "Semantically incorrect message",
114 [GSM48_RR_CAUSE_INVALID_MAND_INF] = "Invalid mandatory information",
115 [GSM48_RR_CAUSE_MSG_TYPE_N] = "Message type non-existant or not implemented",
116 [GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT] = "Message type not compatible with protocol state",
117 [GSM48_RR_CAUSE_COND_IE_ERROR] = "Conditional IE error",
118 [GSM48_RR_CAUSE_NO_CELL_ALLOC_A] = "No cell allocation available",
119 [GSM48_RR_CAUSE_PROT_ERROR_UNSPC] = "Protocol error unspecified",
120};
121
Harald Welte03740842009-06-10 23:11:52 +0800122static const char *cc_state_names[] = {
123 "NULL",
124 "INITIATED",
125 "illegal state 2",
126 "MO_CALL_PROC",
127 "CALL_DELIVERED",
128 "illegal state 5",
129 "CALL_PRESENT",
130 "CALL_RECEIVED",
131 "CONNECT_REQUEST",
132 "MO_TERM_CALL_CONF",
133 "ACTIVE",
134 "DISCONNECT_REQ",
135 "DISCONNECT_IND",
136 "illegal state 13",
137 "illegal state 14",
138 "illegal state 15",
139 "illegal state 16",
140 "illegal state 17",
141 "illegal state 18",
142 "RELEASE_REQ",
143 "illegal state 20",
144 "illegal state 21",
145 "illegal state 22",
146 "illegal state 23",
147 "illegal state 24",
148 "illegal state 25",
149 "MO_ORIG_MODIFY",
150 "MO_TERM_MODIFY",
151 "CONNECT_IND",
152 "illegal state 29",
153 "illegal state 30",
154 "illegal state 31",
155};
156
Harald Welte59b04682009-06-10 05:40:52 +0800157static char strbuf[64];
158
159static const char *rr_cause_name(u_int8_t cause)
160{
161 if (cause < ARRAY_SIZE(rr_cause_names) &&
162 rr_cause_names[cause])
163 return rr_cause_names[cause];
164
165 snprintf(strbuf, sizeof(strbuf), "0x%02x", cause);
166 return strbuf;
167}
168
169static void parse_meas_rep(struct gsm_meas_rep *rep, const u_int8_t *data,
170 int len)
171{
172 memset(rep, 0, sizeof(*rep));
173
174 if (data[0] & 0x80)
175 rep->flags |= MEAS_REP_F_BA1;
176 if (data[0] & 0x40)
177 rep->flags |= MEAS_REP_F_DTX;
Harald Welteba6589d2009-07-05 04:05:44 +0200178 if ((data[1] & 0x40) == 0x00)
Harald Welte59b04682009-06-10 05:40:52 +0800179 rep->flags |= MEAS_REP_F_VALID;
180
181 rep->rxlev_full = data[0] & 0x3f;
182 rep->rxlev_sub = data[1] & 0x3f;
183 rep->rxqual_full = (data[3] >> 4) & 0x7;
184 rep->rxqual_sub = (data[3] >> 1) & 0x7;
185 rep->num_cell = data[4] >> 6 | ((data[3] & 0x01) << 2);
186 if (rep->num_cell < 1)
187 return;
188
189 /* an encoding nightmare in perfection */
190
191 rep->cell[0].rxlev = data[4] & 0x3f;
192 rep->cell[0].bcch_freq = data[5] >> 2;
193 rep->cell[0].bsic = ((data[5] & 0x03) << 3) | (data[6] >> 5);
194 if (rep->num_cell < 2)
195 return;
196
197 rep->cell[1].rxlev = ((data[6] & 0x1f) << 1) | (data[7] >> 7);
198 rep->cell[1].bcch_freq = (data[7] >> 2) & 0x1f;
199 rep->cell[1].bsic = ((data[7] & 0x03) << 4) | (data[8] >> 4);
200 if (rep->num_cell < 3)
201 return;
202
203 rep->cell[2].rxlev = ((data[8] & 0x0f) << 2) | (data[9] >> 6);
204 rep->cell[2].bcch_freq = (data[9] >> 1) & 0x1f;
205 rep->cell[2].bsic = ((data[9] & 0x01) << 6) | (data[10] >> 3);
206 if (rep->num_cell < 4)
207 return;
208
209 rep->cell[3].rxlev = ((data[10] & 0x07) << 3) | (data[11] >> 5);
210 rep->cell[3].bcch_freq = data[11] & 0x1f;
211 rep->cell[3].bsic = data[12] >> 2;
212 if (rep->num_cell < 5)
213 return;
214
215 rep->cell[4].rxlev = ((data[12] & 0x03) << 4) | (data[13] >> 4);
216 rep->cell[4].bcch_freq = ((data[13] & 0xf) << 1) | (data[14] >> 7);
217 rep->cell[4].bsic = (data[14] >> 1) & 0x3f;
218 if (rep->num_cell < 6)
219 return;
220
221 rep->cell[5].rxlev = ((data[14] & 0x01) << 5) | (data[15] >> 3);
222 rep->cell[5].bcch_freq = ((data[15] & 0x07) << 2) | (data[16] >> 6);
223 rep->cell[5].bsic = data[16] & 0x3f;
224}
225
226int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi);
227static int gsm48_tx_simple(struct gsm_lchan *lchan,
228 u_int8_t pdisc, u_int8_t msg_type);
229static void schedule_reject(struct gsm_lchan *lchan);
230
231struct gsm_lai {
232 u_int16_t mcc;
233 u_int16_t mnc;
234 u_int16_t lac;
235};
236
Harald Welte59b04682009-06-10 05:40:52 +0800237static int reject_cause = 0;
238void gsm0408_set_reject_cause(int cause)
239{
240 reject_cause = cause;
241}
242
Harald Welte03740842009-06-10 23:11:52 +0800243static u_int32_t new_callref = 0x80000001;
244
Harald Welte59b04682009-06-10 05:40:52 +0800245static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
246 struct gsm_subscriber *subscriber)
247{
248 if (!subscriber)
249 return 0;
250
251 /*
252 * Do not send accept yet as more information should arrive. Some
253 * phones will not send us the information and we will have to check
254 * what we want to do with that.
255 */
256 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
257 return 0;
258
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200259 switch (subscriber->net->auth_policy) {
260 case GSM_AUTH_POLICY_CLOSED:
261 return subscriber->authorized;
Harald Welte (local)16480eb2009-08-13 13:49:51 +0200262 case GSM_AUTH_POLICY_TOKEN:
Harald Welte (local)272f5c72009-08-13 20:44:23 +0200263 if (subscriber->authorized)
264 return subscriber->authorized;
Harald Welte (local)16480eb2009-08-13 13:49:51 +0200265 return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200266 case GSM_AUTH_POLICY_ACCEPT_ALL:
Harald Welte59b04682009-06-10 05:40:52 +0800267 return 1;
Jan Luebbe3d6294e2009-08-12 12:48:00 +0200268 default:
269 return 0;
270 }
Harald Welte59b04682009-06-10 05:40:52 +0800271}
272
273static void release_loc_updating_req(struct gsm_lchan *lchan)
274{
275 if (!lchan->loc_operation)
276 return;
277
278 bsc_del_timer(&lchan->loc_operation->updating_timer);
Harald Weltea8379772009-06-20 22:36:41 +0200279 talloc_free(lchan->loc_operation);
Harald Welte59b04682009-06-10 05:40:52 +0800280 lchan->loc_operation = 0;
281 put_lchan(lchan);
282}
283
284static void allocate_loc_updating_req(struct gsm_lchan *lchan)
285{
286 use_lchan(lchan);
287 release_loc_updating_req(lchan);
288
Harald Welte857e00d2009-06-26 20:25:23 +0200289 lchan->loc_operation = talloc_zero(tall_locop_ctx,
290 struct gsm_loc_updating_operation);
Harald Welte59b04682009-06-10 05:40:52 +0800291}
292
293static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg)
294{
Harald Welte59b04682009-06-10 05:40:52 +0800295 if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) {
Harald Welte5070e942009-08-09 19:07:00 +0200296 int rc;
297
Harald Welte59b04682009-06-10 05:40:52 +0800298 db_subscriber_alloc_tmsi(lchan->subscr);
Harald Welte59b04682009-06-10 05:40:52 +0800299 release_loc_updating_req(lchan);
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +0200300 rc = gsm0408_loc_upd_acc(msg->lchan, lchan->subscr->tmsi);
Harald Welte5070e942009-08-09 19:07:00 +0200301 /* call subscr_update after putting the loc_upd_acc
302 * in the transmit queue, since S_SUBSCR_ATTACHED might
303 * trigger further action like SMS delivery */
304 subscr_update(lchan->subscr, msg->trx->bts,
305 GSM_SUBSCRIBER_UPDATE_ATTACHED);
306 return rc;
Harald Welte59b04682009-06-10 05:40:52 +0800307 }
308
309 return 0;
310}
311
312static int gsm0408_handle_lchan_signal(unsigned int subsys, unsigned int signal,
313 void *handler_data, void *signal_data)
314{
Harald Welte03740842009-06-10 23:11:52 +0800315 struct gsm_trans *trans, *temp;
316
Harald Welte59b04682009-06-10 05:40:52 +0800317 if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE)
318 return 0;
319
320 /*
321 * Cancel any outstanding location updating request
322 * operation taking place on the lchan.
323 */
Harald Welte12560da2009-07-04 09:35:21 +0200324 struct gsm_lchan *lchan = (struct gsm_lchan *)signal_data;
Harald Welte1ff81b52009-06-26 20:17:06 +0200325 if (!lchan)
326 return 0;
327
Harald Welte59b04682009-06-10 05:40:52 +0800328 release_loc_updating_req(lchan);
329
Harald Welte03740842009-06-10 23:11:52 +0800330 /* Free all transactions that are associated with the released lchan */
Harald Weltec2189a62009-07-23 18:56:43 +0200331 /* FIXME: this is not neccessarily the right thing to do, we should
332 * only set trans->lchan to NULL and wait for another lchan to be
333 * established to the same MM entity (phone/subscriber) */
Harald Welte03740842009-06-10 23:11:52 +0800334 llist_for_each_entry_safe(trans, temp, &lchan->ts->trx->bts->network->trans_list, entry) {
335 if (trans->lchan == lchan)
Harald Weltec2189a62009-07-23 18:56:43 +0200336 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +0800337 }
338
Harald Welte59b04682009-06-10 05:40:52 +0800339 return 0;
340}
341
Harald Welte59b04682009-06-10 05:40:52 +0800342static const char bcd_num_digits[] = {
343 '0', '1', '2', '3', '4', '5', '6', '7',
344 '8', '9', '*', '#', 'a', 'b', 'c', '\0'
345};
346
Harald Welteb8a18b52009-06-10 12:08:54 +0800347/* decode a 'called/calling/connect party BCD number' as in 10.5.4.7 */
348int decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv,
349 int h_len)
Harald Welte59b04682009-06-10 05:40:52 +0800350{
351 u_int8_t in_len = bcd_lv[0];
352 int i;
353
Harald Welteb8a18b52009-06-10 12:08:54 +0800354 for (i = 1 + h_len; i <= in_len; i++) {
Harald Welte59b04682009-06-10 05:40:52 +0800355 /* lower nibble */
356 output_len--;
357 if (output_len <= 1)
358 break;
359 *output++ = bcd_num_digits[bcd_lv[i] & 0xf];
360
361 /* higher nibble */
362 output_len--;
363 if (output_len <= 1)
364 break;
365 *output++ = bcd_num_digits[bcd_lv[i] >> 4];
366 }
367 if (output_len >= 1)
368 *output++ = '\0';
369
Harald Welteb8a18b52009-06-10 12:08:54 +0800370 return 0;
Harald Welte59b04682009-06-10 05:40:52 +0800371}
372
373/* convert a single ASCII character to call-control BCD */
374static int asc_to_bcd(const char asc)
375{
376 int i;
377
378 for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) {
379 if (bcd_num_digits[i] == asc)
380 return i;
381 }
382 return -EINVAL;
383}
384
Harald Welteb8a18b52009-06-10 12:08:54 +0800385/* convert a ASCII phone number to 'called/calling/connect party BCD number' */
Harald Welte59b04682009-06-10 05:40:52 +0800386int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len,
Harald Welteb8a18b52009-06-10 12:08:54 +0800387 int h_len, const char *input)
Harald Welte59b04682009-06-10 05:40:52 +0800388{
389 int in_len = strlen(input);
390 int i;
Harald Welteb8a18b52009-06-10 12:08:54 +0800391 u_int8_t *bcd_cur = bcd_lv + 1 + h_len;
Harald Welte59b04682009-06-10 05:40:52 +0800392
393 /* two digits per byte, plus type byte */
Harald Welteb8a18b52009-06-10 12:08:54 +0800394 bcd_lv[0] = in_len/2 + h_len;
Harald Welte59b04682009-06-10 05:40:52 +0800395 if (in_len % 2)
396 bcd_lv[0]++;
397
Harald Welteb8a18b52009-06-10 12:08:54 +0800398 if (bcd_lv[0] > max_len)
399 return -EIO;
Harald Welte59b04682009-06-10 05:40:52 +0800400
401 for (i = 0; i < in_len; i++) {
402 int rc = asc_to_bcd(input[i]);
403 if (rc < 0)
404 return rc;
405 if (i % 2 == 0)
406 *bcd_cur = rc;
407 else
408 *bcd_cur++ |= (rc << 4);
409 }
410 /* append padding nibble in case of odd length */
411 if (i % 2)
412 *bcd_cur++ |= 0xf0;
413
414 /* return how many bytes we used */
415 return (bcd_cur - bcd_lv);
416}
417
Harald Welteb8a18b52009-06-10 12:08:54 +0800418/* decode 'bearer capability' */
Harald Welte03740842009-06-10 23:11:52 +0800419static int decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap,
Harald Welteb8a18b52009-06-10 12:08:54 +0800420 const u_int8_t *lv)
421{
422 u_int8_t in_len = lv[0];
423 int i, s;
424
425 if (in_len < 1)
426 return -EINVAL;
427
Harald Welte03740842009-06-10 23:11:52 +0800428 bcap->speech_ver[0] = -1; /* end of list, of maximum 7 values */
Harald Welteb8a18b52009-06-10 12:08:54 +0800429
430 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800431 bcap->transfer = lv[1] & 0x07;
432 bcap->mode = (lv[1] & 0x08) >> 3;
433 bcap->coding = (lv[1] & 0x10) >> 4;
434 bcap->radio = (lv[1] & 0x60) >> 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800435
436 i = 1;
437 s = 0;
438 while(!(lv[i] & 0x80)) {
439 i++; /* octet 3a etc */
440 if (in_len < i)
441 return 0;
Harald Welte03740842009-06-10 23:11:52 +0800442 bcap->speech_ver[s++] = lv[i] & 0x0f;
443 bcap->speech_ver[s] = -1; /* end of list */
Harald Welteb8a18b52009-06-10 12:08:54 +0800444 if (i == 2) /* octet 3a */
Harald Welte03740842009-06-10 23:11:52 +0800445 bcap->speech_ctm = (lv[i] & 0x20) >> 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800446 if (s == 7) /* maximum speech versions + end of list */
447 return 0;
448 }
449
450 return 0;
451}
452
453/* encode 'bearer capability' */
Harald Welte03740842009-06-10 23:11:52 +0800454static int encode_bearer_cap(struct msgb *msg, int lv_only,
455 const struct gsm_mncc_bearer_cap *bcap)
Harald Welteb8a18b52009-06-10 12:08:54 +0800456{
457 u_int8_t lv[32 + 1];
458 int i, s;
459
Harald Welte03740842009-06-10 23:11:52 +0800460 lv[1] = bcap->transfer;
461 lv[1] |= bcap->mode << 3;
462 lv[1] |= bcap->coding << 4;
463 lv[1] |= bcap->radio << 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800464
465 i = 1;
Harald Welte03740842009-06-10 23:11:52 +0800466 for (s = 0; bcap->speech_ver[s] >= 0; s++) {
Harald Welteb8a18b52009-06-10 12:08:54 +0800467 i++; /* octet 3a etc */
Harald Welte03740842009-06-10 23:11:52 +0800468 lv[i] = bcap->speech_ver[s];
Harald Welteb8a18b52009-06-10 12:08:54 +0800469 if (i == 2) /* octet 3a */
Harald Welte03740842009-06-10 23:11:52 +0800470 lv[i] |= bcap->speech_ctm << 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800471 }
472 lv[i] |= 0x80; /* last IE of octet 3 etc */
473
474 lv[0] = i;
475 if (lv_only)
476 msgb_lv_put(msg, lv[0], lv+1);
477 else
478 msgb_tlv_put(msg, GSM48_IE_BEARER_CAP, lv[0], lv+1);
479
480 return 0;
481}
482
483/* decode 'call control cap' */
Harald Welte03740842009-06-10 23:11:52 +0800484static int decode_cccap(struct gsm_mncc_cccap *ccap, const u_int8_t *lv)
Harald Welteb8a18b52009-06-10 12:08:54 +0800485{
486 u_int8_t in_len = lv[0];
487
488 if (in_len < 1)
489 return -EINVAL;
490
491 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800492 ccap->dtmf = lv[1] & 0x01;
493 ccap->pcp = (lv[1] & 0x02) >> 1;
Harald Welteb8a18b52009-06-10 12:08:54 +0800494
495 return 0;
496}
497
498/* decode 'called party BCD number' */
Harald Welte03740842009-06-10 23:11:52 +0800499static int decode_called(struct gsm_mncc_number *called,
500 const u_int8_t *lv)
Harald Welteb8a18b52009-06-10 12:08:54 +0800501{
502 u_int8_t in_len = lv[0];
503
504 if (in_len < 1)
505 return -EINVAL;
506
507 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800508 called->plan = lv[1] & 0x0f;
509 called->type = (lv[1] & 0x70) >> 4;
Harald Welteb8a18b52009-06-10 12:08:54 +0800510
511 /* octet 4..N */
Harald Welte03740842009-06-10 23:11:52 +0800512 decode_bcd_number(called->number, sizeof(called->number), lv, 1);
Harald Welteb8a18b52009-06-10 12:08:54 +0800513
514 return 0;
515}
516
517/* encode 'called party BCD number' */
Harald Welte03740842009-06-10 23:11:52 +0800518static int encode_called(struct msgb *msg,
519 const struct gsm_mncc_number *called)
Harald Welteb8a18b52009-06-10 12:08:54 +0800520{
521 u_int8_t lv[18];
522 int ret;
523
524 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800525 lv[1] = called->plan;
526 lv[1] |= called->type << 4;
Harald Welteb8a18b52009-06-10 12:08:54 +0800527
528 /* octet 4..N, octet 2 */
Harald Welte03740842009-06-10 23:11:52 +0800529 ret = encode_bcd_number(lv, sizeof(lv), 1, called->number);
Harald Welteb8a18b52009-06-10 12:08:54 +0800530 if (ret < 0)
531 return ret;
532
533 msgb_tlv_put(msg, GSM48_IE_CALLED_BCD, lv[0], lv+1);
534
535 return 0;
536}
537
538/* encode callerid of various IEs */
Harald Welte03740842009-06-10 23:11:52 +0800539static int encode_callerid(struct msgb *msg, int ie,
540 const struct gsm_mncc_number *callerid)
Harald Welteb8a18b52009-06-10 12:08:54 +0800541{
542 u_int8_t lv[13];
543 int h_len = 1;
544 int ret;
545
546 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800547 lv[1] = callerid->plan;
548 lv[1] |= callerid->type << 4;
Harald Welteb8a18b52009-06-10 12:08:54 +0800549
Harald Welte03740842009-06-10 23:11:52 +0800550 if (callerid->present || callerid->screen) {
Harald Welteb8a18b52009-06-10 12:08:54 +0800551 /* octet 3a */
Harald Welte03740842009-06-10 23:11:52 +0800552 lv[2] = callerid->screen;
553 lv[2] |= callerid->present << 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800554 lv[2] |= 0x80;
555 h_len++;
556 } else
557 lv[1] |= 0x80;
558
559 /* octet 4..N, octet 2 */
Harald Welte03740842009-06-10 23:11:52 +0800560 ret = encode_bcd_number(lv, sizeof(lv), h_len, callerid->number);
Harald Welteb8a18b52009-06-10 12:08:54 +0800561 if (ret < 0)
562 return ret;
563
564 msgb_tlv_put(msg, ie, lv[0], lv+1);
565
566 return 0;
567}
568
569/* decode 'cause' */
Harald Welte03740842009-06-10 23:11:52 +0800570static int decode_cause(struct gsm_mncc_cause *cause,
Harald Welteb8a18b52009-06-10 12:08:54 +0800571 const u_int8_t *lv)
572{
573 u_int8_t in_len = lv[0];
574 int i;
575
576 if (in_len < 2)
577 return -EINVAL;
578
Harald Welte03740842009-06-10 23:11:52 +0800579 cause->diag_len = 0;
Harald Welteb8a18b52009-06-10 12:08:54 +0800580
581 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800582 cause->location = lv[1] & 0x0f;
583 cause->coding = (lv[1] & 0x60) >> 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800584
585 i = 1;
586 if (!(lv[i] & 0x80)) {
587 i++; /* octet 3a */
588 if (in_len < i+1)
589 return 0;
Harald Welte03740842009-06-10 23:11:52 +0800590 cause->rec = 1;
591 cause->rec_val = lv[i] & 0x7f;
Harald Welteb8a18b52009-06-10 12:08:54 +0800592
593 }
594 i++;
595
596 /* octet 4 */
Harald Welte03740842009-06-10 23:11:52 +0800597 cause->value = lv[i] & 0x7f;
Harald Welteb8a18b52009-06-10 12:08:54 +0800598 i++;
599
600 if (in_len < i) /* no diag */
601 return 0;
602
603 if (in_len - (i-1) > 32) /* maximum 32 octets */
604 return 0;
605
606 /* octet 5-N */
Harald Welte03740842009-06-10 23:11:52 +0800607 memcpy(cause->diag, lv + i, in_len - (i-1));
608 cause->diag_len = in_len - (i-1);
Harald Welteb8a18b52009-06-10 12:08:54 +0800609
610 return 0;
611}
612
613/* encode 'cause' */
Harald Welte03740842009-06-10 23:11:52 +0800614static int encode_cause(struct msgb *msg, int lv_only,
615 const struct gsm_mncc_cause *cause)
Harald Welteb8a18b52009-06-10 12:08:54 +0800616{
617 u_int8_t lv[32+4];
618 int i;
619
Harald Welte03740842009-06-10 23:11:52 +0800620 if (cause->diag_len > 32)
Harald Welteb8a18b52009-06-10 12:08:54 +0800621 return -EINVAL;
622
623 /* octet 3 */
Harald Welte03740842009-06-10 23:11:52 +0800624 lv[1] = cause->location;
625 lv[1] |= cause->coding << 5;
Harald Welteb8a18b52009-06-10 12:08:54 +0800626
627 i = 1;
Harald Welte03740842009-06-10 23:11:52 +0800628 if (cause->rec) {
Harald Welteb8a18b52009-06-10 12:08:54 +0800629 i++; /* octet 3a */
Harald Welte03740842009-06-10 23:11:52 +0800630 lv[i] = cause->rec_val;
Harald Welteb8a18b52009-06-10 12:08:54 +0800631 }
632 lv[i] |= 0x80; /* end of octet 3 */
633
634 /* octet 4 */
635 i++;
Harald Welte03740842009-06-10 23:11:52 +0800636 lv[i] = 0x80 | cause->value;
Harald Welteb8a18b52009-06-10 12:08:54 +0800637
638 /* octet 5-N */
Harald Welte03740842009-06-10 23:11:52 +0800639 if (cause->diag_len) {
640 memcpy(lv + i, cause->diag, cause->diag_len);
641 i += cause->diag_len;
Harald Welteb8a18b52009-06-10 12:08:54 +0800642 }
643
644 lv[0] = i;
645 if (lv_only)
646 msgb_lv_put(msg, lv[0], lv+1);
647 else
648 msgb_tlv_put(msg, GSM48_IE_CAUSE, lv[0], lv+1);
649
650 return 0;
651}
652
653/* encode 'calling number' */
Harald Welte03740842009-06-10 23:11:52 +0800654static int encode_calling(struct msgb *msg,
655 const struct gsm_mncc_number *calling)
Harald Welteb8a18b52009-06-10 12:08:54 +0800656{
Harald Welte03740842009-06-10 23:11:52 +0800657 return encode_callerid(msg, GSM48_IE_CALLING_BCD, calling);
Harald Welteb8a18b52009-06-10 12:08:54 +0800658}
659
660/* encode 'connected number' */
Harald Welte03740842009-06-10 23:11:52 +0800661static int encode_connected(struct msgb *msg,
662 const struct gsm_mncc_number *connected)
Harald Welteb8a18b52009-06-10 12:08:54 +0800663{
Harald Welte03740842009-06-10 23:11:52 +0800664 return encode_callerid(msg, GSM48_IE_CONN_BCD, connected);
Harald Welteb8a18b52009-06-10 12:08:54 +0800665}
666
667/* encode 'redirecting number' */
Harald Welte03740842009-06-10 23:11:52 +0800668static int encode_redirecting(struct msgb *msg,
669 const struct gsm_mncc_number *redirecting)
Harald Welteb8a18b52009-06-10 12:08:54 +0800670{
Harald Welte03740842009-06-10 23:11:52 +0800671 return encode_callerid(msg, GSM48_IE_REDIR_BCD, redirecting);
Harald Welteb8a18b52009-06-10 12:08:54 +0800672}
673
674/* decode 'facility' */
Harald Welte03740842009-06-10 23:11:52 +0800675static int decode_facility(struct gsm_mncc_facility *facility,
Harald Welteb8a18b52009-06-10 12:08:54 +0800676 const u_int8_t *lv)
677{
678 u_int8_t in_len = lv[0];
679
680 if (in_len < 1)
681 return -EINVAL;
682
Harald Welte03740842009-06-10 23:11:52 +0800683 if (in_len > sizeof(facility->info))
Harald Welteb8a18b52009-06-10 12:08:54 +0800684 return -EINVAL;
685
Harald Welte03740842009-06-10 23:11:52 +0800686 memcpy(facility->info, lv+1, in_len);
687 facility->len = in_len;
Harald Welteb8a18b52009-06-10 12:08:54 +0800688
689 return 0;
690}
691
692/* encode 'facility' */
Harald Welte03740842009-06-10 23:11:52 +0800693static int encode_facility(struct msgb *msg, int lv_only,
694 const struct gsm_mncc_facility *facility)
Harald Welteb8a18b52009-06-10 12:08:54 +0800695{
696 u_int8_t lv[GSM_MAX_FACILITY + 1];
697
Harald Welte03740842009-06-10 23:11:52 +0800698 if (facility->len < 1 || facility->len > GSM_MAX_FACILITY)
Harald Welteb8a18b52009-06-10 12:08:54 +0800699 return -EINVAL;
700
Harald Welte03740842009-06-10 23:11:52 +0800701 memcpy(lv+1, facility->info, facility->len);
702 lv[0] = facility->len;
Harald Welteb8a18b52009-06-10 12:08:54 +0800703 if (lv_only)
704 msgb_lv_put(msg, lv[0], lv+1);
705 else
706 msgb_tlv_put(msg, GSM48_IE_FACILITY, lv[0], lv+1);
707
708 return 0;
709}
710
711/* decode 'notify' */
712static int decode_notify(int *notify, const u_int8_t *v)
713{
714 *notify = v[0] & 0x7f;
715
716 return 0;
717}
718
719/* encode 'notify' */
720static int encode_notify(struct msgb *msg, int notify)
721{
722 msgb_v_put(msg, notify | 0x80);
723
724 return 0;
725}
726
727/* encode 'signal' */
728static int encode_signal(struct msgb *msg, int signal)
729{
730 msgb_tv_put(msg, GSM48_IE_SIGNAL, signal);
731
732 return 0;
733}
734
735/* decode 'keypad' */
736static int decode_keypad(int *keypad, const u_int8_t *lv)
737{
738 u_int8_t in_len = lv[0];
739
740 if (in_len < 1)
741 return -EINVAL;
742
743 *keypad = lv[1] & 0x7f;
744
745 return 0;
746}
747
748/* encode 'keypad' */
749static int encode_keypad(struct msgb *msg, int keypad)
750{
751 msgb_tv_put(msg, GSM48_IE_KPD_FACILITY, keypad);
752
753 return 0;
754}
755
756/* decode 'progress' */
Harald Welte03740842009-06-10 23:11:52 +0800757static int decode_progress(struct gsm_mncc_progress *progress,
Harald Welteb8a18b52009-06-10 12:08:54 +0800758 const u_int8_t *lv)
759{
760 u_int8_t in_len = lv[0];
761
762 if (in_len < 2)
763 return -EINVAL;
764
Harald Welte03740842009-06-10 23:11:52 +0800765 progress->coding = (lv[1] & 0x60) >> 5;
766 progress->location = lv[1] & 0x0f;
767 progress->descr = lv[2] & 0x7f;
Harald Welteb8a18b52009-06-10 12:08:54 +0800768
769 return 0;
770}
771
772/* encode 'progress' */
Harald Welte03740842009-06-10 23:11:52 +0800773static int encode_progress(struct msgb *msg, int lv_only,
774 const struct gsm_mncc_progress *p)
Harald Welteb8a18b52009-06-10 12:08:54 +0800775{
776 u_int8_t lv[3];
777
778 lv[0] = 2;
Harald Welte03740842009-06-10 23:11:52 +0800779 lv[1] = 0x80 | ((p->coding & 0x3) << 5) | (p->location & 0xf);
780 lv[2] = 0x80 | (p->descr & 0x7f);
Harald Welteb8a18b52009-06-10 12:08:54 +0800781 if (lv_only)
782 msgb_lv_put(msg, lv[0], lv+1);
783 else
784 msgb_tlv_put(msg, GSM48_IE_PROGR_IND, lv[0], lv+1);
785
786 return 0;
787}
788
789/* decode 'user-user' */
Harald Welte03740842009-06-10 23:11:52 +0800790static int decode_useruser(struct gsm_mncc_useruser *uu,
Harald Welteb8a18b52009-06-10 12:08:54 +0800791 const u_int8_t *lv)
792{
793 u_int8_t in_len = lv[0];
Harald Welte03740842009-06-10 23:11:52 +0800794 char *info = uu->info;
795 int info_len = sizeof(uu->info);
Harald Welteb8a18b52009-06-10 12:08:54 +0800796 int i;
797
798 if (in_len < 1)
799 return -EINVAL;
800
Harald Welte03740842009-06-10 23:11:52 +0800801 uu->proto = lv[1];
Harald Welteb8a18b52009-06-10 12:08:54 +0800802
803 for (i = 2; i <= in_len; i++) {
804 info_len--;
805 if (info_len <= 1)
806 break;
807 *info++ = lv[i];
808 }
809 if (info_len >= 1)
810 *info++ = '\0';
811
812 return 0;
813}
814
815/* encode 'useruser' */
Harald Welte03740842009-06-10 23:11:52 +0800816static int encode_useruser(struct msgb *msg, int lv_only,
817 const struct gsm_mncc_useruser *uu)
Harald Welteb8a18b52009-06-10 12:08:54 +0800818{
819 u_int8_t lv[GSM_MAX_USERUSER + 2];
820
Harald Welte03740842009-06-10 23:11:52 +0800821 if (strlen(uu->info) > GSM_MAX_USERUSER)
Harald Welteb8a18b52009-06-10 12:08:54 +0800822 return -EINVAL;
823
Harald Welte03740842009-06-10 23:11:52 +0800824 lv[0] = 1 + strlen(uu->info);
825 lv[1] = uu->proto;
826 memcpy(lv + 2, uu->info, strlen(uu->info));
Harald Welteb8a18b52009-06-10 12:08:54 +0800827 if (lv_only)
828 msgb_lv_put(msg, lv[0], lv+1);
829 else
830 msgb_tlv_put(msg, GSM48_IE_USER_USER, lv[0], lv+1);
831
832 return 0;
833}
834
835/* decode 'ss version' */
Harald Welte03740842009-06-10 23:11:52 +0800836static int decode_ssversion(struct gsm_mncc_ssversion *ssv,
Harald Welteb8a18b52009-06-10 12:08:54 +0800837 const u_int8_t *lv)
838{
839 u_int8_t in_len = lv[0];
840
Harald Welte03740842009-06-10 23:11:52 +0800841 if (in_len < 1 || in_len < sizeof(ssv->info))
Harald Welteb8a18b52009-06-10 12:08:54 +0800842 return -EINVAL;
843
Harald Welte03740842009-06-10 23:11:52 +0800844 memcpy(ssv->info, lv + 1, in_len);
845 ssv->len = in_len;
Harald Welteb8a18b52009-06-10 12:08:54 +0800846
847 return 0;
848}
849
850/* encode 'more data' */
851static int encode_more(struct msgb *msg)
852{
853 u_int8_t *ie;
854
855 ie = msgb_put(msg, 1);
856 ie[0] = GSM48_IE_MORE_DATA;
857
858 return 0;
859}
860
Harald Welte59b04682009-06-10 05:40:52 +0800861/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
862int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
863{
864 struct msgb *msg = gsm48_msgb_alloc();
865 struct gsm48_hdr *gh;
866
867 msg->lchan = lchan;
868
869 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
870 gh->proto_discr = GSM48_PDISC_MM;
871 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
872 gh->data[0] = cause;
873
874 DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr);
875
Harald Welte36fe2e82009-07-23 21:13:03 +0200876 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800877}
878
879/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
880int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
881{
882 struct gsm_bts *bts = lchan->ts->trx->bts;
883 struct msgb *msg = gsm48_msgb_alloc();
884 struct gsm48_hdr *gh;
885 struct gsm48_loc_area_id *lai;
886 u_int8_t *mid;
887 int ret;
888
889 msg->lchan = lchan;
890
891 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
892 gh->proto_discr = GSM48_PDISC_MM;
893 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
894
895 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
896 gsm0408_generate_lai(lai, bts->network->country_code,
897 bts->network->network_code, bts->location_area_code);
898
Holger Hans Peter Freyther36897102009-08-01 07:26:59 +0200899 mid = msgb_put(msg, GSM48_MID_TMSI_LEN);
Holger Hans Peter Freyther20a0f322009-08-20 08:41:24 +0200900 gsm48_generate_mid_from_tmsi(mid, tmsi);
Harald Welte59b04682009-06-10 05:40:52 +0800901
902 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
903
Harald Welte36fe2e82009-07-23 21:13:03 +0200904 ret = gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800905
Harald Welte5070e942009-08-09 19:07:00 +0200906 /* send MM INFO with network name */
Harald Welte59b04682009-06-10 05:40:52 +0800907 ret = gsm48_tx_mm_info(lchan);
908
909 return ret;
910}
911
Harald Welte59b04682009-06-10 05:40:52 +0800912/* Transmit Chapter 9.2.10 Identity Request */
913static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
914{
915 struct msgb *msg = gsm48_msgb_alloc();
916 struct gsm48_hdr *gh;
917
918 msg->lchan = lchan;
919
920 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
921 gh->proto_discr = GSM48_PDISC_MM;
922 gh->msg_type = GSM48_MT_MM_ID_REQ;
923 gh->data[0] = id_type;
924
Harald Welte36fe2e82009-07-23 21:13:03 +0200925 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +0800926}
927
Harald Welte59b04682009-06-10 05:40:52 +0800928
929/* Parse Chapter 9.2.11 Identity Response */
930static int mm_rx_id_resp(struct msgb *msg)
931{
932 struct gsm48_hdr *gh = msgb_l3(msg);
933 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75350412009-07-23 18:46:00 +0200934 struct gsm_bts *bts = lchan->ts->trx->bts;
935 struct gsm_network *net = bts->network;
Harald Welte59b04682009-06-10 05:40:52 +0800936 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200937 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +0800938
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +0200939 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte59b04682009-06-10 05:40:52 +0800940 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
941 mi_type, mi_string);
942
Harald Welte59b04682009-06-10 05:40:52 +0800943 switch (mi_type) {
944 case GSM_MI_TYPE_IMSI:
Jan Luebbe9bdbd622009-08-12 10:19:34 +0200945 /* look up subscriber based on IMSI, create if not found */
946 if (!lchan->subscr) {
947 lchan->subscr = subscr_get_by_imsi(net, mi_string);
Harald Welte (local)16480eb2009-08-13 13:49:51 +0200948 if (!lchan->subscr)
949 lchan->subscr = db_create_subscriber(net, mi_string);
Jan Luebbee2974032009-08-12 10:12:52 +0200950 }
Harald Welte59b04682009-06-10 05:40:52 +0800951 if (lchan->loc_operation)
952 lchan->loc_operation->waiting_for_imsi = 0;
953 break;
954 case GSM_MI_TYPE_IMEI:
955 case GSM_MI_TYPE_IMEISV:
956 /* update subscribe <-> IMEI mapping */
Harald Welte (local)ced09ed2009-08-17 09:39:55 +0200957 if (lchan->subscr) {
Harald Welte59b04682009-06-10 05:40:52 +0800958 db_subscriber_assoc_imei(lchan->subscr, mi_string);
Harald Welte (local)ced09ed2009-08-17 09:39:55 +0200959 db_sync_equipment(&lchan->subscr->equipment);
960 }
Harald Welte59b04682009-06-10 05:40:52 +0800961 if (lchan->loc_operation)
962 lchan->loc_operation->waiting_for_imei = 0;
963 break;
964 }
965
966 /* Check if we can let the mobile station enter */
967 return gsm0408_authorize(lchan, msg);
968}
969
970
971static void loc_upd_rej_cb(void *data)
972{
973 struct gsm_lchan *lchan = data;
974
975 release_loc_updating_req(lchan);
976 gsm0408_loc_upd_rej(lchan, reject_cause);
977 lchan_auto_release(lchan);
978}
979
980static void schedule_reject(struct gsm_lchan *lchan)
981{
982 lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb;
983 lchan->loc_operation->updating_timer.data = lchan;
984 bsc_schedule_timer(&lchan->loc_operation->updating_timer, 5, 0);
985}
986
987static const char *lupd_name(u_int8_t type)
988{
989 switch (type) {
990 case GSM48_LUPD_NORMAL:
991 return "NORMAL";
992 case GSM48_LUPD_PERIODIC:
993 return "PEROIDOC";
994 case GSM48_LUPD_IMSI_ATT:
995 return "IMSI ATTACH";
996 default:
997 return "UNKNOWN";
998 }
999}
1000
Harald Welte59b04682009-06-10 05:40:52 +08001001/* Chapter 9.2.15: Receive Location Updating Request */
1002static int mm_rx_loc_upd_req(struct msgb *msg)
1003{
1004 struct gsm48_hdr *gh = msgb_l3(msg);
1005 struct gsm48_loc_upd_req *lu;
Harald Welte03740842009-06-10 23:11:52 +08001006 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +08001007 struct gsm_lchan *lchan = msg->lchan;
Harald Welte75350412009-07-23 18:46:00 +02001008 struct gsm_bts *bts = lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +08001009 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001010 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +08001011 int rc;
1012
1013 lu = (struct gsm48_loc_upd_req *) gh->data;
1014
1015 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
1016
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001017 gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
Harald Welte59b04682009-06-10 05:40:52 +08001018
Harald Welte79639662009-06-27 02:58:43 +02001019 DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
Harald Welte59b04682009-06-10 05:40:52 +08001020 lupd_name(lu->type));
1021
1022 /*
1023 * Pseudo Spoof detection: Just drop a second/concurrent
1024 * location updating request.
1025 */
1026 if (lchan->loc_operation) {
Harald Welte79639662009-06-27 02:58:43 +02001027 DEBUGPC(DMM, "ignoring request due an existing one: %p.\n",
Harald Welte59b04682009-06-10 05:40:52 +08001028 lchan->loc_operation);
1029 gsm0408_loc_upd_rej(lchan, GSM48_REJECT_PROTOCOL_ERROR);
1030 return 0;
1031 }
1032
1033 allocate_loc_updating_req(lchan);
1034
1035 switch (mi_type) {
1036 case GSM_MI_TYPE_IMSI:
Harald Welte79639662009-06-27 02:58:43 +02001037 DEBUGPC(DMM, "\n");
Harald Welte59b04682009-06-10 05:40:52 +08001038 /* we always want the IMEI, too */
Harald Welte59b04682009-06-10 05:40:52 +08001039 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
1040 lchan->loc_operation->waiting_for_imei = 1;
1041
Jan Luebbe9bdbd622009-08-12 10:19:34 +02001042 /* look up subscriber based on IMSI, create if not found */
1043 subscr = subscr_get_by_imsi(bts->network, mi_string);
1044 if (!subscr) {
1045 subscr = db_create_subscriber(bts->network, mi_string);
1046 }
Harald Welte59b04682009-06-10 05:40:52 +08001047 break;
1048 case GSM_MI_TYPE_TMSI:
Harald Welte79639662009-06-27 02:58:43 +02001049 DEBUGPC(DMM, "\n");
Harald Welte59b04682009-06-10 05:40:52 +08001050 /* we always want the IMEI, too */
Harald Welte59b04682009-06-10 05:40:52 +08001051 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
1052 lchan->loc_operation->waiting_for_imei = 1;
1053
1054 /* look up the subscriber based on TMSI, request IMSI if it fails */
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +02001055 subscr = subscr_get_by_tmsi(bts->network,
1056 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +08001057 if (!subscr) {
1058 /* send IDENTITY REQUEST message to get IMSI */
Harald Welte59b04682009-06-10 05:40:52 +08001059 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
1060 lchan->loc_operation->waiting_for_imsi = 1;
1061 }
1062 break;
1063 case GSM_MI_TYPE_IMEI:
1064 case GSM_MI_TYPE_IMEISV:
1065 /* no sim card... FIXME: what to do ? */
Harald Welte79639662009-06-27 02:58:43 +02001066 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte59b04682009-06-10 05:40:52 +08001067 break;
1068 default:
Harald Welte79639662009-06-27 02:58:43 +02001069 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte59b04682009-06-10 05:40:52 +08001070 break;
1071 }
1072
Harald Welteccd69362009-07-04 10:18:00 +02001073 /* schedule the reject timer */
1074 schedule_reject(lchan);
1075
Harald Welte03740842009-06-10 23:11:52 +08001076 if (!subscr) {
Harald Welte79639662009-06-27 02:58:43 +02001077 DEBUGPC(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte03740842009-06-10 23:11:52 +08001078 /* FIXME: request id? close channel? */
1079 return -EINVAL;
1080 }
1081
Harald Welte59b04682009-06-10 05:40:52 +08001082 lchan->subscr = subscr;
Harald Welte (local)ced09ed2009-08-17 09:39:55 +02001083 lchan->subscr->equipment.classmark1 = lu->classmark1;
Harald Welte59b04682009-06-10 05:40:52 +08001084
Harald Welteccd69362009-07-04 10:18:00 +02001085 /* check if we can let the subscriber into our network immediately
1086 * or if we need to wait for identity responses. */
Harald Welte59b04682009-06-10 05:40:52 +08001087 return gsm0408_authorize(lchan, msg);
1088}
1089
Harald Welteca745e22009-07-29 12:10:35 +02001090/* 9.1.5 Channel mode modify: Modify the mode on the MS side */
Harald Welte59b04682009-06-10 05:40:52 +08001091int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode)
1092{
1093 struct msgb *msg = gsm48_msgb_alloc();
1094 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1095 struct gsm48_chan_mode_modify *cmm =
1096 (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm));
1097 u_int16_t arfcn = lchan->ts->trx->arfcn & 0x3ff;
1098
1099 DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode);
1100
1101 lchan->tch_mode = mode;
1102 msg->lchan = lchan;
1103 gh->proto_discr = GSM48_PDISC_RR;
1104 gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF;
1105
1106 /* fill the channel information element, this code
1107 * should probably be shared with rsl_rx_chan_rqd() */
1108 cmm->chan_desc.chan_nr = lchan2chan_nr(lchan);
1109 cmm->chan_desc.h0.tsc = lchan->ts->trx->bts->tsc;
1110 cmm->chan_desc.h0.h = 0;
1111 cmm->chan_desc.h0.arfcn_high = arfcn >> 8;
1112 cmm->chan_desc.h0.arfcn_low = arfcn & 0xff;
1113 cmm->mode = mode;
1114
Harald Welte36fe2e82009-07-23 21:13:03 +02001115 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +08001116}
1117
Harald Welte03740842009-06-10 23:11:52 +08001118#if 0
1119static u_int8_t to_bcd8(u_int8_t val)
1120{
1121 return ((val / 10) << 4) | (val % 10);
1122}
1123#endif
1124
Harald Welte59b04682009-06-10 05:40:52 +08001125/* Section 9.2.15a */
1126int gsm48_tx_mm_info(struct gsm_lchan *lchan)
1127{
1128 struct msgb *msg = gsm48_msgb_alloc();
1129 struct gsm48_hdr *gh;
1130 struct gsm_network *net = lchan->ts->trx->bts->network;
1131 u_int8_t *ptr8;
Daniel Willmannc8188202009-08-13 03:42:07 +02001132 int name_len, name_pad;
Harald Welte03740842009-06-10 23:11:52 +08001133#if 0
1134 time_t cur_t;
1135 struct tm* cur_time;
1136 int tz15min;
1137#endif
Harald Welte59b04682009-06-10 05:40:52 +08001138
1139 msg->lchan = lchan;
1140
1141 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1142 gh->proto_discr = GSM48_PDISC_MM;
1143 gh->msg_type = GSM48_MT_MM_INFO;
1144
1145 if (net->name_long) {
Daniel Willmannc8188202009-08-13 03:42:07 +02001146#if 0
Harald Welte59b04682009-06-10 05:40:52 +08001147 name_len = strlen(net->name_long);
1148 /* 10.5.3.5a */
1149 ptr8 = msgb_put(msg, 3);
1150 ptr8[0] = GSM48_IE_NAME_LONG;
1151 ptr8[1] = name_len*2 +1;
1152 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
1153
1154 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
1155 for (i = 0; i < name_len; i++)
1156 ptr16[i] = htons(net->name_long[i]);
1157
1158 /* FIXME: Use Cell Broadcast, not UCS-2, since
1159 * UCS-2 is only supported by later revisions of the spec */
Daniel Willmannc8188202009-08-13 03:42:07 +02001160#endif
1161 name_len = (strlen(net->name_long)*7)/8;
1162 name_pad = (8 - strlen(net->name_long)*7)%8;
1163 if (name_pad > 0)
1164 name_len++;
1165 /* 10.5.3.5a */
1166 ptr8 = msgb_put(msg, 3);
1167 ptr8[0] = GSM48_IE_NAME_LONG;
1168 ptr8[1] = name_len +1;
1169 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
1170
1171 ptr8 = msgb_put(msg, name_len);
1172 gsm_7bit_encode(ptr8, net->name_long);
1173
Harald Welte59b04682009-06-10 05:40:52 +08001174 }
1175
1176 if (net->name_short) {
Daniel Willmannc8188202009-08-13 03:42:07 +02001177#if 0
Harald Welte59b04682009-06-10 05:40:52 +08001178 name_len = strlen(net->name_short);
1179 /* 10.5.3.5a */
1180 ptr8 = (u_int8_t *) msgb_put(msg, 3);
Harald Weltef6284712009-07-19 17:51:36 +02001181 ptr8[0] = GSM48_IE_NAME_SHORT;
Harald Welte59b04682009-06-10 05:40:52 +08001182 ptr8[1] = name_len*2 + 1;
1183 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
1184
1185 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
1186 for (i = 0; i < name_len; i++)
1187 ptr16[i] = htons(net->name_short[i]);
Daniel Willmannc8188202009-08-13 03:42:07 +02001188#endif
1189 name_len = (strlen(net->name_short)*7)/8;
1190 name_pad = (8 - strlen(net->name_short)*7)%8;
1191 if (name_pad > 0)
1192 name_len++;
1193 /* 10.5.3.5a */
1194 ptr8 = (u_int8_t *) msgb_put(msg, 3);
1195 ptr8[0] = GSM48_IE_NAME_SHORT;
1196 ptr8[1] = name_len +1;
1197 ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
1198
1199 ptr8 = msgb_put(msg, name_len);
1200 gsm_7bit_encode(ptr8, net->name_short);
1201
Harald Welte59b04682009-06-10 05:40:52 +08001202 }
1203
1204#if 0
Harald Welte59b04682009-06-10 05:40:52 +08001205 /* Section 10.5.3.9 */
1206 cur_t = time(NULL);
Harald Welte03740842009-06-10 23:11:52 +08001207 cur_time = gmtime(&cur_t);
Harald Welte59b04682009-06-10 05:40:52 +08001208 ptr8 = msgb_put(msg, 8);
1209 ptr8[0] = GSM48_IE_NET_TIME_TZ;
1210 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
1211 ptr8[2] = to_bcd8(cur_time->tm_mon);
1212 ptr8[3] = to_bcd8(cur_time->tm_mday);
1213 ptr8[4] = to_bcd8(cur_time->tm_hour);
1214 ptr8[5] = to_bcd8(cur_time->tm_min);
1215 ptr8[6] = to_bcd8(cur_time->tm_sec);
1216 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
1217 tz15min = (cur_time->tm_gmtoff)/(60*15);
Harald Welte03740842009-06-10 23:11:52 +08001218 ptr8[7] = to_bcd8(tz15min);
Harald Welte59b04682009-06-10 05:40:52 +08001219 if (tz15min < 0)
Harald Welte03740842009-06-10 23:11:52 +08001220 ptr8[7] |= 0x80;
Harald Welte59b04682009-06-10 05:40:52 +08001221#endif
1222
Daniel Willmannc8188202009-08-13 03:42:07 +02001223 DEBUGP(DMM, "-> MM INFO\n");
1224
Harald Welte36fe2e82009-07-23 21:13:03 +02001225 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +08001226}
1227
Harald Welte36970f62009-08-12 22:56:50 +02001228/* Section 9.2.2 */
1229int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand)
1230{
1231 struct msgb *msg = gsm48_msgb_alloc();
1232 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Sylvain Munaut6de6dc12009-09-27 11:10:17 +02001233 struct gsm48_auth_req *ar = (struct gsm48_auth_req *) msgb_put(msg, sizeof(*ar));
Harald Welte36970f62009-08-12 22:56:50 +02001234
1235 DEBUGP(DMM, "-> AUTH REQ\n");
1236
1237 msg->lchan = lchan;
1238 gh->proto_discr = GSM48_PDISC_MM;
1239 gh->msg_type = GSM48_MT_MM_AUTH_REQ;
1240
Sylvain Munaut6de6dc12009-09-27 11:10:17 +02001241 /* Key Sequence: FIXME fixed to 0 */
1242 ar->key_seq = 0;
1243
Harald Welte36970f62009-08-12 22:56:50 +02001244 /* 16 bytes RAND parameters */
Harald Welte36970f62009-08-12 22:56:50 +02001245 if (rand)
Sylvain Munaut6de6dc12009-09-27 11:10:17 +02001246 memcpy(ar->rand, rand, 16);
Harald Welte36970f62009-08-12 22:56:50 +02001247
1248 return gsm48_sendmsg(msg, NULL);
1249}
1250
1251/* Section 9.2.1 */
1252int gsm48_tx_mm_auth_rej(struct gsm_lchan *lchan)
1253{
1254 DEBUGP(DMM, "-> AUTH REJECT\n");
1255 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_AUTH_REJ);
1256}
1257
Harald Welte59b04682009-06-10 05:40:52 +08001258static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
1259{
1260 DEBUGP(DMM, "-> CM SERVICE ACK\n");
1261 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
1262}
1263
1264/* 9.2.6 CM service reject */
1265static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan,
1266 enum gsm48_reject_value value)
1267{
1268 struct msgb *msg = gsm48_msgb_alloc();
1269 struct gsm48_hdr *gh;
1270
1271 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
1272
1273 msg->lchan = lchan;
1274 use_lchan(lchan);
1275
1276 gh->proto_discr = GSM48_PDISC_MM;
1277 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
1278 gh->data[0] = value;
1279 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
1280
Harald Welte36fe2e82009-07-23 21:13:03 +02001281 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +08001282}
1283
Harald Welte59b04682009-06-10 05:40:52 +08001284/*
1285 * Handle CM Service Requests
1286 * a) Verify that the packet is long enough to contain the information
1287 * we require otherwsie reject with INCORRECT_MESSAGE
1288 * b) Try to parse the TMSI. If we do not have one reject
1289 * c) Check that we know the subscriber with the TMSI otherwise reject
1290 * with a HLR cause
1291 * d) Set the subscriber on the gsm_lchan and accept
1292 */
1293static int gsm48_rx_mm_serv_req(struct msgb *msg)
1294{
1295 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001296 char mi_string[GSM48_MI_SIZE];
Harald Welte59b04682009-06-10 05:40:52 +08001297
Harald Welte75350412009-07-23 18:46:00 +02001298 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +08001299 struct gsm_subscriber *subscr;
1300 struct gsm48_hdr *gh = msgb_l3(msg);
1301 struct gsm48_service_request *req =
1302 (struct gsm48_service_request *)gh->data;
1303 /* unfortunately in Phase1 the classmar2 length is variable */
1304 u_int8_t classmark2_len = gh->data[1];
1305 u_int8_t *classmark2 = gh->data+2;
1306 u_int8_t mi_len = *(classmark2 + classmark2_len);
1307 u_int8_t *mi = (classmark2 + classmark2_len + 1);
1308
1309 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
1310 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
1311 DEBUGPC(DMM, "wrong sized message\n");
1312 return gsm48_tx_mm_serv_rej(msg->lchan,
1313 GSM48_REJECT_INCORRECT_MESSAGE);
1314 }
1315
1316 if (msg->data_len < req->mi_len + 6) {
1317 DEBUGPC(DMM, "does not fit in packet\n");
1318 return gsm48_tx_mm_serv_rej(msg->lchan,
1319 GSM48_REJECT_INCORRECT_MESSAGE);
1320 }
1321
1322 mi_type = mi[0] & GSM_MI_TYPE_MASK;
1323 if (mi_type != GSM_MI_TYPE_TMSI) {
1324 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
1325 return gsm48_tx_mm_serv_rej(msg->lchan,
1326 GSM48_REJECT_INCORRECT_MESSAGE);
1327 }
1328
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001329 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Welte59b04682009-06-10 05:40:52 +08001330 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
1331 req->cm_service_type, mi_type, mi_string);
1332
Harald Welte583ceaf2009-08-10 10:12:45 +02001333 if (is_siemens_bts(bts))
1334 send_siemens_mrpci(msg->lchan, classmark2-1);
1335
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +02001336 subscr = subscr_get_by_tmsi(bts->network,
1337 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +08001338
1339 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
1340 if (!subscr)
1341 return gsm48_tx_mm_serv_rej(msg->lchan,
1342 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
1343
1344 if (!msg->lchan->subscr)
1345 msg->lchan->subscr = subscr;
1346 else if (msg->lchan->subscr != subscr) {
1347 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
1348 subscr_put(subscr);
1349 }
1350
Harald Weltef6845a72009-07-05 14:08:13 +02001351 subscr->equipment.classmark2_len = classmark2_len;
1352 memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
1353 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +08001354
1355 return gsm48_tx_mm_serv_ack(msg->lchan);
1356}
1357
1358static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
1359{
Harald Welte75350412009-07-23 18:46:00 +02001360 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +08001361 struct gsm48_hdr *gh = msgb_l3(msg);
1362 struct gsm48_imsi_detach_ind *idi =
1363 (struct gsm48_imsi_detach_ind *) gh->data;
1364 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001365 char mi_string[GSM48_MI_SIZE];
Harald Welte03740842009-06-10 23:11:52 +08001366 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +08001367
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001368 gsm48_mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
Harald Welte59b04682009-06-10 05:40:52 +08001369 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
1370 mi_type, mi_string);
1371
1372 switch (mi_type) {
1373 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +02001374 subscr = subscr_get_by_tmsi(bts->network,
1375 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +08001376 break;
1377 case GSM_MI_TYPE_IMSI:
Harald Welte75350412009-07-23 18:46:00 +02001378 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte59b04682009-06-10 05:40:52 +08001379 break;
1380 case GSM_MI_TYPE_IMEI:
1381 case GSM_MI_TYPE_IMEISV:
1382 /* no sim card... FIXME: what to do ? */
1383 DEBUGPC(DMM, "unimplemented mobile identity type\n");
1384 break;
1385 default:
1386 DEBUGPC(DMM, "unknown mobile identity type\n");
1387 break;
1388 }
1389
1390 if (subscr) {
1391 subscr_update(subscr, msg->trx->bts,
1392 GSM_SUBSCRIBER_UPDATE_DETACHED);
1393 DEBUGP(DMM, "Subscriber: %s\n",
1394 subscr->name ? subscr->name : subscr->imsi);
Harald Welte (local)ced09ed2009-08-17 09:39:55 +02001395
1396 subscr->equipment.classmark1 = idi->classmark1;
1397 db_sync_equipment(&subscr->equipment);
1398
Harald Welte59b04682009-06-10 05:40:52 +08001399 subscr_put(subscr);
1400 } else
1401 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
1402
Harald Welte59b04682009-06-10 05:40:52 +08001403 return 0;
1404}
1405
1406static int gsm48_rx_mm_status(struct msgb *msg)
1407{
1408 struct gsm48_hdr *gh = msgb_l3(msg);
1409
1410 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
1411
1412 return 0;
1413}
1414
1415/* Receive a GSM 04.08 Mobility Management (MM) message */
1416static int gsm0408_rcv_mm(struct msgb *msg)
1417{
1418 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte03740842009-06-10 23:11:52 +08001419 int rc = 0;
Harald Welte59b04682009-06-10 05:40:52 +08001420
1421 switch (gh->msg_type & 0xbf) {
1422 case GSM48_MT_MM_LOC_UPD_REQUEST:
Harald Welte79639662009-06-27 02:58:43 +02001423 DEBUGP(DMM, "LOCATION UPDATING REQUEST: ");
Harald Welte59b04682009-06-10 05:40:52 +08001424 rc = mm_rx_loc_upd_req(msg);
1425 break;
1426 case GSM48_MT_MM_ID_RESP:
1427 rc = mm_rx_id_resp(msg);
1428 break;
1429 case GSM48_MT_MM_CM_SERV_REQ:
1430 rc = gsm48_rx_mm_serv_req(msg);
1431 break;
1432 case GSM48_MT_MM_STATUS:
1433 rc = gsm48_rx_mm_status(msg);
1434 break;
1435 case GSM48_MT_MM_TMSI_REALL_COMPL:
1436 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
1437 msg->lchan->subscr ?
1438 msg->lchan->subscr->imsi :
1439 "unknown subscriber");
1440 break;
1441 case GSM48_MT_MM_IMSI_DETACH_IND:
1442 rc = gsm48_rx_mm_imsi_detach_ind(msg);
1443 break;
1444 case GSM48_MT_MM_CM_REEST_REQ:
1445 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
1446 break;
1447 case GSM48_MT_MM_AUTH_RESP:
1448 DEBUGP(DMM, "AUTHENTICATION RESPONSE: Not implemented\n");
1449 break;
1450 default:
1451 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
1452 gh->msg_type);
1453 break;
1454 }
1455
1456 return rc;
1457}
1458
1459/* Receive a PAGING RESPONSE message from the MS */
Holger Hans Peter Freytherf10170e2009-10-23 13:48:54 +02001460static int gsm48_rx_rr_pag_resp(struct msgb *msg)
Harald Welte59b04682009-06-10 05:40:52 +08001461{
Harald Welte75350412009-07-23 18:46:00 +02001462 struct gsm_bts *bts = msg->lchan->ts->trx->bts;
Harald Welte59b04682009-06-10 05:40:52 +08001463 struct gsm48_hdr *gh = msgb_l3(msg);
1464 u_int8_t *classmark2_lv = gh->data + 1;
Holger Hans Peter Freyther1e43b8d2009-08-21 05:18:21 +02001465 u_int8_t mi_type;
Holger Hans Peter Freyther1e6ef9f2009-08-19 07:54:59 +02001466 char mi_string[GSM48_MI_SIZE];
Harald Welte03740842009-06-10 23:11:52 +08001467 struct gsm_subscriber *subscr = NULL;
Harald Welte59b04682009-06-10 05:40:52 +08001468 int rc = 0;
1469
Holger Hans Peter Freyther1e43b8d2009-08-21 05:18:21 +02001470 gsm48_paging_extract_mi(msg, mi_string, &mi_type);
Harald Welte59b04682009-06-10 05:40:52 +08001471 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
1472 mi_type, mi_string);
Harald Welte583ceaf2009-08-10 10:12:45 +02001473
Harald Welte59b04682009-06-10 05:40:52 +08001474 switch (mi_type) {
1475 case GSM_MI_TYPE_TMSI:
Holger Hans Peter Freythercd8bacf2009-08-19 12:53:57 +02001476 subscr = subscr_get_by_tmsi(bts->network,
1477 tmsi_from_string(mi_string));
Harald Welte59b04682009-06-10 05:40:52 +08001478 break;
1479 case GSM_MI_TYPE_IMSI:
Harald Welte75350412009-07-23 18:46:00 +02001480 subscr = subscr_get_by_imsi(bts->network, mi_string);
Harald Welte59b04682009-06-10 05:40:52 +08001481 break;
1482 }
1483
1484 if (!subscr) {
1485 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
1486 /* FIXME: request id? close channel? */
1487 return -EINVAL;
1488 }
1489 DEBUGP(DRR, "<- Channel was requested by %s\n",
Harald Welte68b7df22009-08-08 16:03:15 +02001490 subscr->name && strlen(subscr->name) ? subscr->name : subscr->imsi);
Harald Welte59b04682009-06-10 05:40:52 +08001491
Harald Weltef6845a72009-07-05 14:08:13 +02001492 subscr->equipment.classmark2_len = *classmark2_lv;
1493 memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
1494 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +08001495
Holger Hans Peter Freyther1e43b8d2009-08-21 05:18:21 +02001496 rc = gsm48_handle_paging_resp(msg, subscr);
Harald Welte59b04682009-06-10 05:40:52 +08001497 return rc;
1498}
1499
1500static int gsm48_rx_rr_classmark(struct msgb *msg)
1501{
1502 struct gsm48_hdr *gh = msgb_l3(msg);
1503 struct gsm_subscriber *subscr = msg->lchan->subscr;
1504 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1505 u_int8_t cm2_len, cm3_len = 0;
1506 u_int8_t *cm2, *cm3 = NULL;
1507
1508 DEBUGP(DRR, "CLASSMARK CHANGE ");
1509
1510 /* classmark 2 */
1511 cm2_len = gh->data[0];
1512 cm2 = &gh->data[1];
1513 DEBUGPC(DRR, "CM2(len=%u) ", cm2_len);
1514
1515 if (payload_len > cm2_len + 1) {
1516 /* we must have a classmark3 */
1517 if (gh->data[cm2_len+1] != 0x20) {
1518 DEBUGPC(DRR, "ERR CM3 TAG\n");
1519 return -EINVAL;
1520 }
1521 if (cm2_len > 3) {
1522 DEBUGPC(DRR, "CM2 too long!\n");
1523 return -EINVAL;
1524 }
1525
1526 cm3_len = gh->data[cm2_len+2];
1527 cm3 = &gh->data[cm2_len+3];
1528 if (cm3_len > 14) {
1529 DEBUGPC(DRR, "CM3 len %u too long!\n", cm3_len);
1530 return -EINVAL;
1531 }
1532 DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
1533 }
1534 if (subscr) {
Harald Weltef6845a72009-07-05 14:08:13 +02001535 subscr->equipment.classmark2_len = cm2_len;
1536 memcpy(subscr->equipment.classmark2, cm2, cm2_len);
Harald Welte59b04682009-06-10 05:40:52 +08001537 if (cm3) {
Harald Weltef6845a72009-07-05 14:08:13 +02001538 subscr->equipment.classmark3_len = cm3_len;
1539 memcpy(subscr->equipment.classmark3, cm3, cm3_len);
Harald Welte59b04682009-06-10 05:40:52 +08001540 }
Harald Weltef6845a72009-07-05 14:08:13 +02001541 db_sync_equipment(&subscr->equipment);
Harald Welte59b04682009-06-10 05:40:52 +08001542 }
1543
Harald Welte59b04682009-06-10 05:40:52 +08001544 return 0;
1545}
1546
1547static int gsm48_rx_rr_status(struct msgb *msg)
1548{
1549 struct gsm48_hdr *gh = msgb_l3(msg);
1550
1551 DEBUGP(DRR, "STATUS rr_cause = %s\n",
1552 rr_cause_name(gh->data[0]));
1553
1554 return 0;
1555}
1556
1557static int gsm48_rx_rr_meas_rep(struct msgb *msg)
1558{
1559 struct gsm48_hdr *gh = msgb_l3(msg);
1560 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
1561 static struct gsm_meas_rep meas_rep;
1562
Harald Welte02993682009-06-27 02:53:10 +02001563 DEBUGP(DMEAS, "MEASUREMENT REPORT ");
Harald Welte59b04682009-06-10 05:40:52 +08001564 parse_meas_rep(&meas_rep, gh->data, payload_len);
1565 if (meas_rep.flags & MEAS_REP_F_DTX)
Harald Welte02993682009-06-27 02:53:10 +02001566 DEBUGPC(DMEAS, "DTX ");
Harald Welte59b04682009-06-10 05:40:52 +08001567 if (meas_rep.flags & MEAS_REP_F_BA1)
Harald Welte02993682009-06-27 02:53:10 +02001568 DEBUGPC(DMEAS, "BA1 ");
Harald Welte59b04682009-06-10 05:40:52 +08001569 if (!(meas_rep.flags & MEAS_REP_F_VALID))
Harald Welte02993682009-06-27 02:53:10 +02001570 DEBUGPC(DMEAS, "NOT VALID ");
Harald Welte59b04682009-06-10 05:40:52 +08001571 else
Harald Welte02993682009-06-27 02:53:10 +02001572 DEBUGPC(DMEAS, "FULL(lev=%u, qual=%u) SUB(lev=%u, qual=%u) ",
Harald Welte59b04682009-06-10 05:40:52 +08001573 meas_rep.rxlev_full, meas_rep.rxqual_full, meas_rep.rxlev_sub,
1574 meas_rep.rxqual_sub);
1575
Harald Welte02993682009-06-27 02:53:10 +02001576 DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", meas_rep.num_cell);
Harald Welte59b04682009-06-10 05:40:52 +08001577
1578 /* FIXME: put the results somwhere */
1579
1580 return 0;
1581}
1582
Harald Welte (local)b5103922009-08-15 23:32:44 +02001583static int gsm48_rx_rr_app_info(struct msgb *msg)
1584{
1585 struct gsm48_hdr *gh = msgb_l3(msg);
1586 u_int8_t apdu_id_flags;
1587 u_int8_t apdu_len;
1588 u_int8_t *apdu_data;
1589
1590 apdu_id_flags = gh->data[0];
1591 apdu_len = gh->data[1];
1592 apdu_data = gh->data+2;
1593
1594 DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s",
1595 apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len));
1596
Harald Welte (local)bd72aa22009-08-16 10:40:10 +02001597 return db_apdu_blob_store(msg->lchan->subscr, apdu_id_flags, apdu_len, apdu_data);
Harald Welte (local)b5103922009-08-15 23:32:44 +02001598}
1599
1600
Harald Welte59b04682009-06-10 05:40:52 +08001601/* Receive a GSM 04.08 Radio Resource (RR) message */
1602static int gsm0408_rcv_rr(struct msgb *msg)
1603{
1604 struct gsm48_hdr *gh = msgb_l3(msg);
1605 int rc = 0;
1606
1607 switch (gh->msg_type) {
1608 case GSM48_MT_RR_CLSM_CHG:
1609 rc = gsm48_rx_rr_classmark(msg);
1610 break;
1611 case GSM48_MT_RR_GPRS_SUSP_REQ:
1612 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1613 break;
1614 case GSM48_MT_RR_PAG_RESP:
Holger Hans Peter Freytherf10170e2009-10-23 13:48:54 +02001615 rc = gsm48_rx_rr_pag_resp(msg);
Harald Welte59b04682009-06-10 05:40:52 +08001616 break;
1617 case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
1618 DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n");
Harald Welteca745e22009-07-29 12:10:35 +02001619 /* We've successfully modified the MS side of the channel,
1620 * now go on to modify the BTS side of the channel */
Harald Welte39274f42009-07-29 15:41:29 +02001621 msg->lchan->rsl_cmode = RSL_CMOD_SPD_SPEECH;
Harald Welte59b04682009-06-10 05:40:52 +08001622 rc = rsl_chan_mode_modify_req(msg->lchan);
1623 break;
1624 case GSM48_MT_RR_STATUS:
1625 rc = gsm48_rx_rr_status(msg);
1626 break;
1627 case GSM48_MT_RR_MEAS_REP:
1628 rc = gsm48_rx_rr_meas_rep(msg);
1629 break;
Harald Welte (local)b5103922009-08-15 23:32:44 +02001630 case GSM48_MT_RR_APP_INFO:
1631 rc = gsm48_rx_rr_app_info(msg);
1632 break;
Harald Welted2dd9de2009-08-30 15:37:11 +09001633 case GSM48_MT_RR_CIPH_M_COMPL:
1634 DEBUGP(DRR, "CIPHERING MODE COMPLETE\n");
1635 /* FIXME: check for MI (if any) */
1636 break;
Harald Welte59b04682009-06-10 05:40:52 +08001637 default:
1638 fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n",
1639 gh->msg_type);
1640 break;
1641 }
1642
1643 return rc;
1644}
1645
Harald Welte (local)b5103922009-08-15 23:32:44 +02001646int gsm48_send_rr_app_info(struct gsm_lchan *lchan, u_int8_t apdu_id,
Holger Hans Peter Freytherd70da872009-10-22 15:42:19 +02001647 u_int8_t apdu_len, const u_int8_t *apdu)
Harald Welte (local)b5103922009-08-15 23:32:44 +02001648{
1649 struct msgb *msg = gsm48_msgb_alloc();
1650 struct gsm48_hdr *gh;
1651
1652 msg->lchan = lchan;
1653
1654 DEBUGP(DRR, "TX APPLICATION INFO id=0x%02x, len=%u\n",
1655 apdu_id, apdu_len);
1656
1657 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2 + apdu_len);
1658 gh->proto_discr = GSM48_PDISC_RR;
1659 gh->msg_type = GSM48_MT_RR_APP_INFO;
1660 gh->data[0] = apdu_id;
1661 gh->data[1] = apdu_len;
1662 memcpy(gh->data+2, apdu, apdu_len);
1663
1664 return gsm48_sendmsg(msg, NULL);
1665}
1666
Harald Welte59b04682009-06-10 05:40:52 +08001667/* Call Control */
1668
1669/* The entire call control code is written in accordance with Figure 7.10c
1670 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1671 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1672 * it for voice */
1673
Harald Welte03740842009-06-10 23:11:52 +08001674static void new_cc_state(struct gsm_trans *trans, int state)
1675{
1676 if (state > 31 || state < 0)
1677 return;
1678
1679 DEBUGP(DCC, "new state %s -> %s\n",
Harald Weltec2189a62009-07-23 18:56:43 +02001680 cc_state_names[trans->cc.state], cc_state_names[state]);
Harald Welte03740842009-06-10 23:11:52 +08001681
Harald Weltec2189a62009-07-23 18:56:43 +02001682 trans->cc.state = state;
Harald Welte03740842009-06-10 23:11:52 +08001683}
1684
1685static int gsm48_cc_tx_status(struct gsm_trans *trans, void *arg)
Harald Welte59b04682009-06-10 05:40:52 +08001686{
1687 struct msgb *msg = gsm48_msgb_alloc();
1688 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1689 u_int8_t *cause, *call_state;
1690
Harald Welte59b04682009-06-10 05:40:52 +08001691 gh->msg_type = GSM48_MT_CC_STATUS;
1692
1693 cause = msgb_put(msg, 3);
1694 cause[0] = 2;
1695 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1696 cause[2] = 0x80 | 30; /* response to status inquiry */
1697
1698 call_state = msgb_put(msg, 1);
1699 call_state[0] = 0xc0 | 0x00;
1700
Harald Welte36fe2e82009-07-23 21:13:03 +02001701 return gsm48_sendmsg(msg, trans);
Harald Welte59b04682009-06-10 05:40:52 +08001702}
1703
1704static int gsm48_tx_simple(struct gsm_lchan *lchan,
1705 u_int8_t pdisc, u_int8_t msg_type)
1706{
1707 struct msgb *msg = gsm48_msgb_alloc();
1708 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1709
1710 msg->lchan = lchan;
1711
1712 gh->proto_discr = pdisc;
1713 gh->msg_type = msg_type;
1714
Harald Welte36fe2e82009-07-23 21:13:03 +02001715 return gsm48_sendmsg(msg, NULL);
Harald Welte59b04682009-06-10 05:40:52 +08001716}
1717
Harald Welte03740842009-06-10 23:11:52 +08001718static void gsm48_stop_cc_timer(struct gsm_trans *trans)
1719{
Harald Weltec2189a62009-07-23 18:56:43 +02001720 if (bsc_timer_pending(&trans->cc.timer)) {
1721 DEBUGP(DCC, "stopping pending timer T%x\n", trans->cc.Tcurrent);
1722 bsc_del_timer(&trans->cc.timer);
1723 trans->cc.Tcurrent = 0;
Harald Welte03740842009-06-10 23:11:52 +08001724 }
1725}
1726
1727static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
1728 int msg_type, struct gsm_mncc *mncc)
1729{
1730 struct msgb *msg;
1731
1732 if (trans)
1733 if (trans->lchan)
Harald Welte4861c822009-07-23 21:21:14 +02001734 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte03740842009-06-10 23:11:52 +08001735 "Sending '%s' to MNCC.\n",
1736 trans->lchan->ts->trx->bts->nr,
1737 trans->lchan->ts->trx->nr,
1738 trans->lchan->ts->nr, trans->transaction_id,
1739 (trans->subscr)?(trans->subscr->extension):"-",
1740 get_mncc_name(msg_type));
1741 else
1742 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
1743 "Sending '%s' to MNCC.\n",
1744 (trans->subscr)?(trans->subscr->extension):"-",
1745 get_mncc_name(msg_type));
1746 else
1747 DEBUGP(DCC, "(bts - trx - ts - ti -- sub -) "
1748 "Sending '%s' to MNCC.\n", get_mncc_name(msg_type));
1749
1750 mncc->msg_type = msg_type;
1751
Harald Welte9cfc9352009-06-26 19:39:35 +02001752 msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
Harald Welte03740842009-06-10 23:11:52 +08001753 if (!msg)
1754 return -ENOMEM;
1755 memcpy(msg->data, mncc, sizeof(struct gsm_mncc));
1756 msgb_enqueue(&net->upqueue, msg);
1757
1758 return 0;
1759}
1760
1761int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans,
1762 u_int32_t callref, int location, int value)
1763{
1764 struct gsm_mncc rel;
1765
Harald Weltecb0595f2009-06-12 01:54:08 +08001766 memset(&rel, 0, sizeof(rel));
Harald Welte03740842009-06-10 23:11:52 +08001767 rel.callref = callref;
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001768 mncc_set_cause(&rel, location, value);
Harald Welte03740842009-06-10 23:11:52 +08001769 return mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
1770}
1771
Harald Weltec2189a62009-07-23 18:56:43 +02001772/* Call Control Specific transaction release.
1773 * gets called by trans_free, DO NOT CALL YOURSELF! */
1774void _gsm48_cc_trans_free(struct gsm_trans *trans)
Harald Welte03740842009-06-10 23:11:52 +08001775{
Harald Welte03740842009-06-10 23:11:52 +08001776 gsm48_stop_cc_timer(trans);
1777
1778 /* send release to L4, if callref still exists */
1779 if (trans->callref) {
1780 /* Ressource unavailable */
Harald Welte0abe5a62009-07-23 19:06:52 +02001781 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001782 GSM48_CAUSE_LOC_PRN_S_LU,
1783 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08001784 }
Harald Weltec2189a62009-07-23 18:56:43 +02001785 if (trans->cc.state != GSM_CSTATE_NULL)
Harald Welte03740842009-06-10 23:11:52 +08001786 new_cc_state(trans, GSM_CSTATE_NULL);
Harald Weltec2189a62009-07-23 18:56:43 +02001787 if (trans->lchan)
1788 trau_mux_unmap(&trans->lchan->ts->e1_link, trans->callref);
Harald Welte03740842009-06-10 23:11:52 +08001789}
1790
1791static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg);
1792
Harald Welte59b04682009-06-10 05:40:52 +08001793/* call-back from paging the B-end of the connection */
1794static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
1795 struct msgb *msg, void *_lchan, void *param)
1796{
1797 struct gsm_lchan *lchan = _lchan;
Harald Welte03740842009-06-10 23:11:52 +08001798 struct gsm_subscriber *subscr = param;
1799 struct gsm_trans *transt, *tmp;
1800 struct gsm_network *net;
Harald Welte1ff81b52009-06-26 20:17:06 +02001801
Harald Welte59b04682009-06-10 05:40:52 +08001802 if (hooknum != GSM_HOOK_RR_PAGING)
1803 return -EINVAL;
Harald Welte03740842009-06-10 23:11:52 +08001804
1805 if (!subscr)
1806 return -EINVAL;
1807 net = subscr->net;
1808 if (!net) {
1809 DEBUGP(DCC, "Error Network not set!\n");
1810 return -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08001811 }
1812
Harald Welte03740842009-06-10 23:11:52 +08001813 /* check all tranactions (without lchan) for subscriber */
1814 llist_for_each_entry_safe(transt, tmp, &net->trans_list, entry) {
1815 if (transt->subscr != subscr || transt->lchan)
1816 continue;
1817 switch (event) {
1818 case GSM_PAGING_SUCCEEDED:
1819 if (!lchan) // paranoid
1820 break;
1821 DEBUGP(DCC, "Paging subscr %s succeeded!\n",
1822 subscr->extension);
1823 /* Assign lchan */
1824 if (!transt->lchan) {
1825 transt->lchan = lchan;
1826 use_lchan(lchan);
1827 }
1828 /* send SETUP request to called party */
Harald Weltec2189a62009-07-23 18:56:43 +02001829 gsm48_cc_tx_setup(transt, &transt->cc.msg);
Harald Welte03740842009-06-10 23:11:52 +08001830 break;
1831 case GSM_PAGING_EXPIRED:
1832 DEBUGP(DCC, "Paging subscr %s expired!\n",
1833 subscr->extension);
1834 /* Temporarily out of order */
Harald Welte0abe5a62009-07-23 19:06:52 +02001835 mncc_release_ind(transt->subscr->net, transt,
1836 transt->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08001837 GSM48_CAUSE_LOC_PRN_S_LU,
1838 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte03740842009-06-10 23:11:52 +08001839 transt->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02001840 trans_free(transt);
Harald Welte03740842009-06-10 23:11:52 +08001841 break;
1842 }
1843 }
Harald Welte59b04682009-06-10 05:40:52 +08001844 return 0;
1845}
1846
Harald Welte3c062072009-07-28 18:25:29 +02001847/* some other part of the code sends us a signal */
1848static int handle_abisip_signal(unsigned int subsys, unsigned int signal,
1849 void *handler_data, void *signal_data)
1850{
1851 struct gsm_lchan *lchan = signal_data;
1852 struct gsm_bts_trx_ts *ts;
1853 int rc;
1854
1855 if (subsys != SS_ABISIP)
1856 return 0;
1857
1858 /* in case we use direct BTS-to-BTS RTP */
1859 if (ipacc_rtp_direct)
1860 return 0;
1861
1862 ts = lchan->ts;
1863
1864 switch (signal) {
1865 case S_ABISIP_BIND_ACK:
1866 /* the BTS has successfully bound a TCH to a local ip/port,
1867 * which means we can connect our UDP socket to it */
1868 if (ts->abis_ip.rtp_socket) {
1869 rtp_socket_free(ts->abis_ip.rtp_socket);
1870 ts->abis_ip.rtp_socket = NULL;
1871 }
1872
1873 ts->abis_ip.rtp_socket = rtp_socket_create();
1874 if (!ts->abis_ip.rtp_socket)
1875 goto out_err;
1876
1877 rc = rtp_socket_connect(ts->abis_ip.rtp_socket,
1878 ts->abis_ip.bound_ip,
1879 ts->abis_ip.bound_port);
1880 if (rc < 0)
1881 goto out_err;
1882 break;
1883 case S_ABISIP_DISC_IND:
1884 /* the BTS tells us a RTP stream has been disconnected */
1885 if (ts->abis_ip.rtp_socket) {
1886 rtp_socket_free(ts->abis_ip.rtp_socket);
1887 ts->abis_ip.rtp_socket = NULL;
1888 }
1889 break;
1890 }
1891
1892 return 0;
1893out_err:
1894 /* FIXME: do something */
1895 return 0;
1896}
1897
1898/* bind rtp proxy to local IP/port and tell BTS to connect to it */
1899static int ipacc_connect_proxy_bind(struct gsm_lchan *lchan)
1900{
1901 struct gsm_bts_trx_ts *ts = lchan->ts;
1902 struct rtp_socket *rs = ts->abis_ip.rtp_socket;
1903 int rc;
1904
1905 rc = rsl_ipacc_connect(lchan, ntohl(rs->rtp.sin_local.sin_addr.s_addr),
1906 ntohs(rs->rtp.sin_local.sin_port),
1907 ts->abis_ip.conn_id,
1908 /* FIXME: use RTP payload of bound socket, not BTS*/
1909 ts->abis_ip.rtp_payload2);
1910
1911 return rc;
1912}
1913
Harald Welte59b04682009-06-10 05:40:52 +08001914/* map two ipaccess RTP streams onto each other */
1915static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
1916{
1917 struct gsm_bts *bts = lchan->ts->trx->bts;
1918 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
1919 struct gsm_bts_trx_ts *ts;
Harald Welte3c062072009-07-28 18:25:29 +02001920 int rc;
Harald Welte59b04682009-06-10 05:40:52 +08001921
1922 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1923 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1924 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1925
1926 if (bts->type != remote_bts->type) {
1927 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1928 return -EINVAL;
1929 }
1930
1931 switch (bts->type) {
Mike Haben66e0ba02009-10-02 12:19:34 +01001932 case GSM_BTS_TYPE_NANOBTS:
Harald Welte3c062072009-07-28 18:25:29 +02001933 if (!ipacc_rtp_direct) {
1934 /* connect the TCH's to our RTP proxy */
1935 rc = ipacc_connect_proxy_bind(lchan);
1936 if (rc < 0)
1937 return rc;
1938 rc = ipacc_connect_proxy_bind(remote_lchan);
1939
1940 /* connect them with each other */
1941 rtp_socket_proxy(lchan->ts->abis_ip.rtp_socket,
1942 remote_lchan->ts->abis_ip.rtp_socket);
1943 } else {
1944 /* directly connect TCH RTP streams to each other */
1945 ts = remote_lchan->ts;
1946 rc = rsl_ipacc_connect(lchan, ts->abis_ip.bound_ip,
1947 ts->abis_ip.bound_port,
1948 lchan->ts->abis_ip.conn_id,
1949 ts->abis_ip.rtp_payload2);
1950 if (rc < 0)
1951 return rc;
1952 ts = lchan->ts;
1953 rc = rsl_ipacc_connect(remote_lchan, ts->abis_ip.bound_ip,
1954 ts->abis_ip.bound_port,
1955 remote_lchan->ts->abis_ip.conn_id,
1956 ts->abis_ip.rtp_payload2);
1957 }
Harald Welte59b04682009-06-10 05:40:52 +08001958 break;
1959 case GSM_BTS_TYPE_BS11:
1960 trau_mux_map_lchan(lchan, remote_lchan);
1961 break;
1962 default:
1963 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
Harald Welte3c062072009-07-28 18:25:29 +02001964 rc = -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08001965 break;
1966 }
1967
1968 return 0;
1969}
1970
Harald Welte03740842009-06-10 23:11:52 +08001971/* bridge channels of two transactions */
1972static int tch_bridge(struct gsm_network *net, u_int32_t *refs)
Harald Welte59b04682009-06-10 05:40:52 +08001973{
Harald Weltec2189a62009-07-23 18:56:43 +02001974 struct gsm_trans *trans1 = trans_find_by_callref(net, refs[0]);
1975 struct gsm_trans *trans2 = trans_find_by_callref(net, refs[1]);
Harald Welte59b04682009-06-10 05:40:52 +08001976
Harald Welte03740842009-06-10 23:11:52 +08001977 if (!trans1 || !trans2)
Harald Welte59b04682009-06-10 05:40:52 +08001978 return -EIO;
1979
Harald Welte03740842009-06-10 23:11:52 +08001980 if (!trans1->lchan || !trans2->lchan)
1981 return -EIO;
1982
1983 /* through-connect channel */
1984 return tch_map(trans1->lchan, trans2->lchan);
Harald Welte59b04682009-06-10 05:40:52 +08001985}
1986
Harald Welte03740842009-06-10 23:11:52 +08001987/* enable receive of channels to upqueue */
1988static int tch_recv(struct gsm_network *net, struct gsm_mncc *data, int enable)
1989{
1990 struct gsm_trans *trans;
Harald Welte59b04682009-06-10 05:40:52 +08001991
Harald Welte03740842009-06-10 23:11:52 +08001992 /* Find callref */
Harald Weltec2189a62009-07-23 18:56:43 +02001993 trans = trans_find_by_callref(net, data->callref);
Harald Welte03740842009-06-10 23:11:52 +08001994 if (!trans)
1995 return -EIO;
1996 if (!trans->lchan)
1997 return 0;
1998
1999 // todo IPACCESS
2000 if (enable)
2001 return trau_recv_lchan(trans->lchan, data->callref);
2002 return trau_mux_unmap(NULL, data->callref);
2003}
2004
2005/* send a frame to channel */
2006static int tch_frame(struct gsm_network *net, struct gsm_trau_frame *frame)
2007{
2008 struct gsm_trans *trans;
2009
2010 /* Find callref */
Harald Weltec2189a62009-07-23 18:56:43 +02002011 trans = trans_find_by_callref(net, frame->callref);
Harald Welte03740842009-06-10 23:11:52 +08002012 if (!trans)
2013 return -EIO;
2014 if (!trans->lchan)
2015 return 0;
2016 if (trans->lchan->type != GSM_LCHAN_TCH_F &&
2017 trans->lchan->type != GSM_LCHAN_TCH_H)
2018 return 0;
2019
2020 // todo IPACCESS
2021 return trau_send_lchan(trans->lchan,
2022 (struct decoded_trau_frame *)frame->data);
2023}
2024
2025
2026static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
2027{
2028 DEBUGP(DCC, "-> STATUS ENQ\n");
2029 return gsm48_cc_tx_status(trans, msg);
2030}
2031
2032static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
2033static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg);
2034
2035static void gsm48_cc_timeout(void *arg)
2036{
2037 struct gsm_trans *trans = arg;
2038 int disconnect = 0, release = 0;
Harald Weltebbc636a2009-06-11 14:23:20 +08002039 int mo_cause = GSM48_CC_CAUSE_RECOVERY_TIMER;
2040 int mo_location = GSM48_CAUSE_LOC_USER;
2041 int l4_cause = GSM48_CC_CAUSE_NORMAL_UNSPEC;
2042 int l4_location = GSM48_CAUSE_LOC_PRN_S_LU;
Harald Welte03740842009-06-10 23:11:52 +08002043 struct gsm_mncc mo_rel, l4_rel;
2044
2045 memset(&mo_rel, 0, sizeof(struct gsm_mncc));
2046 mo_rel.callref = trans->callref;
2047 memset(&l4_rel, 0, sizeof(struct gsm_mncc));
2048 l4_rel.callref = trans->callref;
2049
Harald Weltec2189a62009-07-23 18:56:43 +02002050 switch(trans->cc.Tcurrent) {
Harald Welte03740842009-06-10 23:11:52 +08002051 case 0x303:
2052 release = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08002053 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08002054 break;
2055 case 0x310:
2056 disconnect = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08002057 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08002058 break;
2059 case 0x313:
2060 disconnect = 1;
2061 /* unknown, did not find it in the specs */
2062 break;
2063 case 0x301:
2064 disconnect = 1;
Harald Weltebbc636a2009-06-11 14:23:20 +08002065 l4_cause = GSM48_CC_CAUSE_USER_NOTRESPOND;
Harald Welte03740842009-06-10 23:11:52 +08002066 break;
2067 case 0x308:
Harald Weltec2189a62009-07-23 18:56:43 +02002068 if (!trans->cc.T308_second) {
Harald Welte03740842009-06-10 23:11:52 +08002069 /* restart T308 a second time */
Harald Weltec2189a62009-07-23 18:56:43 +02002070 gsm48_cc_tx_release(trans, &trans->cc.msg);
2071 trans->cc.T308_second = 1;
Harald Welte03740842009-06-10 23:11:52 +08002072 break; /* stay in release state */
2073 }
Harald Weltec2189a62009-07-23 18:56:43 +02002074 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002075 return;
2076// release = 1;
2077// l4_cause = 14;
2078// break;
2079 case 0x306:
2080 release = 1;
Harald Weltec2189a62009-07-23 18:56:43 +02002081 mo_cause = trans->cc.msg.cause.value;
2082 mo_location = trans->cc.msg.cause.location;
Harald Welte03740842009-06-10 23:11:52 +08002083 break;
2084 case 0x323:
2085 disconnect = 1;
2086 break;
2087 default:
2088 release = 1;
2089 }
2090
2091 if (release && trans->callref) {
2092 /* process release towards layer 4 */
Harald Welte0abe5a62009-07-23 19:06:52 +02002093 mncc_release_ind(trans->subscr->net, trans, trans->callref,
Harald Welte03740842009-06-10 23:11:52 +08002094 l4_location, l4_cause);
2095 trans->callref = 0;
2096 }
2097
2098 if (disconnect && trans->callref) {
2099 /* process disconnect towards layer 4 */
2100 mncc_set_cause(&l4_rel, l4_location, l4_cause);
Harald Welte0abe5a62009-07-23 19:06:52 +02002101 mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &l4_rel);
Harald Welte03740842009-06-10 23:11:52 +08002102 }
2103
2104 /* process disconnect towards mobile station */
2105 if (disconnect || release) {
2106 mncc_set_cause(&mo_rel, mo_location, mo_cause);
Harald Weltec2189a62009-07-23 18:56:43 +02002107 mo_rel.cause.diag[0] = ((trans->cc.Tcurrent & 0xf00) >> 8) + '0';
2108 mo_rel.cause.diag[1] = ((trans->cc.Tcurrent & 0x0f0) >> 4) + '0';
2109 mo_rel.cause.diag[2] = (trans->cc.Tcurrent & 0x00f) + '0';
Harald Welte03740842009-06-10 23:11:52 +08002110 mo_rel.cause.diag_len = 3;
2111
2112 if (disconnect)
2113 gsm48_cc_tx_disconnect(trans, &mo_rel);
2114 if (release)
2115 gsm48_cc_tx_release(trans, &mo_rel);
2116 }
2117
2118}
2119
2120static void gsm48_start_cc_timer(struct gsm_trans *trans, int current,
2121 int sec, int micro)
2122{
2123 DEBUGP(DCC, "starting timer T%x with %d seconds\n", current, sec);
Harald Weltec2189a62009-07-23 18:56:43 +02002124 trans->cc.timer.cb = gsm48_cc_timeout;
2125 trans->cc.timer.data = trans;
2126 bsc_schedule_timer(&trans->cc.timer, sec, micro);
2127 trans->cc.Tcurrent = current;
Harald Welte03740842009-06-10 23:11:52 +08002128}
2129
2130static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
2131{
2132 struct gsm48_hdr *gh = msgb_l3(msg);
2133 u_int8_t msg_type = gh->msg_type & 0xbf;
2134 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2135 struct tlv_parsed tp;
2136 struct gsm_mncc setup;
2137
2138 memset(&setup, 0, sizeof(struct gsm_mncc));
2139 setup.callref = trans->callref;
2140 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2141 /* emergency setup is identified by msg_type */
2142 if (msg_type == GSM48_MT_CC_EMERG_SETUP)
2143 setup.emergency = 1;
2144
2145 /* use subscriber as calling party number */
2146 if (trans->subscr) {
2147 setup.fields |= MNCC_F_CALLING;
2148 strncpy(setup.calling.number, trans->subscr->extension,
2149 sizeof(setup.calling.number)-1);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002150 strncpy(setup.imsi, trans->subscr->imsi,
2151 sizeof(setup.imsi)-1);
Harald Welte03740842009-06-10 23:11:52 +08002152 }
2153 /* bearer capability */
2154 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2155 setup.fields |= MNCC_F_BEARER_CAP;
2156 decode_bearer_cap(&setup.bearer_cap,
2157 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2158 }
2159 /* facility */
2160 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2161 setup.fields |= MNCC_F_FACILITY;
2162 decode_facility(&setup.facility,
2163 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2164 }
2165 /* called party bcd number */
2166 if (TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD)) {
2167 setup.fields |= MNCC_F_CALLED;
2168 decode_called(&setup.called,
2169 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
2170 }
2171 /* user-user */
2172 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2173 setup.fields |= MNCC_F_USERUSER;
2174 decode_useruser(&setup.useruser,
2175 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2176 }
2177 /* ss-version */
2178 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2179 setup.fields |= MNCC_F_SSVERSION;
2180 decode_ssversion(&setup.ssversion,
2181 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2182 }
2183 /* CLIR suppression */
2184 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_SUPP))
2185 setup.clir.sup = 1;
2186 /* CLIR invocation */
2187 if (TLVP_PRESENT(&tp, GSM48_IE_CLIR_INVOC))
2188 setup.clir.inv = 1;
2189 /* cc cap */
2190 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
2191 setup.fields |= MNCC_F_CCCAP;
2192 decode_cccap(&setup.cccap,
2193 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
2194 }
2195
Harald Welte03740842009-06-10 23:11:52 +08002196 new_cc_state(trans, GSM_CSTATE_INITIATED);
2197
2198 /* indicate setup to MNCC */
Harald Welte0abe5a62009-07-23 19:06:52 +02002199 mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_IND, &setup);
Harald Welte03740842009-06-10 23:11:52 +08002200
Harald Welteca745e22009-07-29 12:10:35 +02002201 /* MNCC code will modify the channel asynchronously, we should
2202 * ipaccess-bind only after the modification has been made to the
2203 * lchan->tch_mode */
Harald Welte03740842009-06-10 23:11:52 +08002204 return 0;
2205}
2206
2207static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg)
Harald Welte59b04682009-06-10 05:40:52 +08002208{
2209 struct msgb *msg = gsm48_msgb_alloc();
2210 struct gsm48_hdr *gh;
Harald Welte03740842009-06-10 23:11:52 +08002211 struct gsm_mncc *setup = arg;
Harald Welte165fc332009-07-23 21:36:44 +02002212 int rc, trans_id;
Harald Welte59b04682009-06-10 05:40:52 +08002213
2214 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2215
Harald Welte03740842009-06-10 23:11:52 +08002216 /* transaction id must not be assigned */
2217 if (trans->transaction_id != 0xff) { /* unasssigned */
2218 DEBUGP(DCC, "TX Setup with assigned transaction. "
2219 "This is not allowed!\n");
2220 /* Temporarily out of order */
Harald Welte0abe5a62009-07-23 19:06:52 +02002221 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002222 GSM48_CAUSE_LOC_PRN_S_LU,
2223 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08002224 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002225 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002226 return rc;
2227 }
2228
2229 /* Get free transaction_id */
Harald Welte165fc332009-07-23 21:36:44 +02002230 trans_id = trans_assign_trans_id(trans->subscr, GSM48_PDISC_CC, 0);
2231 if (trans_id < 0) {
Harald Welte03740842009-06-10 23:11:52 +08002232 /* no free transaction ID */
Harald Welte0abe5a62009-07-23 19:06:52 +02002233 rc = mncc_release_ind(trans->subscr->net, trans, trans->callref,
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08002234 GSM48_CAUSE_LOC_PRN_S_LU,
2235 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08002236 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002237 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002238 return rc;
2239 }
Harald Welte165fc332009-07-23 21:36:44 +02002240 trans->transaction_id = trans_id;
Harald Welte59b04682009-06-10 05:40:52 +08002241
Harald Welte59b04682009-06-10 05:40:52 +08002242 gh->msg_type = GSM48_MT_CC_SETUP;
2243
Harald Welte03740842009-06-10 23:11:52 +08002244 gsm48_start_cc_timer(trans, 0x303, GSM48_T303);
Harald Welte59b04682009-06-10 05:40:52 +08002245
Harald Welte03740842009-06-10 23:11:52 +08002246 /* bearer capability */
2247 if (setup->fields & MNCC_F_BEARER_CAP)
2248 encode_bearer_cap(msg, 0, &setup->bearer_cap);
2249 /* facility */
2250 if (setup->fields & MNCC_F_FACILITY)
2251 encode_facility(msg, 0, &setup->facility);
2252 /* progress */
2253 if (setup->fields & MNCC_F_PROGRESS)
2254 encode_progress(msg, 0, &setup->progress);
2255 /* calling party BCD number */
2256 if (setup->fields & MNCC_F_CALLING)
2257 encode_calling(msg, &setup->calling);
2258 /* called party BCD number */
2259 if (setup->fields & MNCC_F_CALLED)
2260 encode_called(msg, &setup->called);
2261 /* user-user */
2262 if (setup->fields & MNCC_F_USERUSER)
2263 encode_useruser(msg, 0, &setup->useruser);
2264 /* redirecting party BCD number */
2265 if (setup->fields & MNCC_F_REDIRECTING)
2266 encode_redirecting(msg, &setup->redirecting);
2267 /* signal */
2268 if (setup->fields & MNCC_F_SIGNAL)
2269 encode_signal(msg, setup->signal);
2270
2271 new_cc_state(trans, GSM_CSTATE_CALL_PRESENT);
Harald Welte59b04682009-06-10 05:40:52 +08002272
Harald Welte36fe2e82009-07-23 21:13:03 +02002273 return gsm48_sendmsg(msg, trans);
Harald Welte59b04682009-06-10 05:40:52 +08002274}
2275
Harald Welte03740842009-06-10 23:11:52 +08002276static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
2277{
2278 struct gsm48_hdr *gh = msgb_l3(msg);
2279 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2280 struct tlv_parsed tp;
2281 struct gsm_mncc call_conf;
2282
2283 gsm48_stop_cc_timer(trans);
2284 gsm48_start_cc_timer(trans, 0x310, GSM48_T310);
2285
2286 memset(&call_conf, 0, sizeof(struct gsm_mncc));
2287 call_conf.callref = trans->callref;
2288 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2289#if 0
2290 /* repeat */
2291 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_CIR))
2292 call_conf.repeat = 1;
2293 if (TLVP_PRESENT(&tp, GSM48_IE_REPEAT_SEQ))
2294 call_conf.repeat = 2;
2295#endif
2296 /* bearer capability */
2297 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2298 call_conf.fields |= MNCC_F_BEARER_CAP;
2299 decode_bearer_cap(&call_conf.bearer_cap,
2300 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2301 }
2302 /* cause */
2303 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2304 call_conf.fields |= MNCC_F_CAUSE;
2305 decode_cause(&call_conf.cause,
2306 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2307 }
2308 /* cc cap */
2309 if (TLVP_PRESENT(&tp, GSM48_IE_CC_CAP)) {
2310 call_conf.fields |= MNCC_F_CCCAP;
2311 decode_cccap(&call_conf.cccap,
2312 TLVP_VAL(&tp, GSM48_IE_CC_CAP)-1);
2313 }
2314
2315 new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
2316
Harald Welte0abe5a62009-07-23 19:06:52 +02002317 return mncc_recvmsg(trans->subscr->net, trans, MNCC_CALL_CONF_IND,
2318 &call_conf);
Harald Welte03740842009-06-10 23:11:52 +08002319}
2320
2321static int gsm48_cc_tx_call_proc(struct gsm_trans *trans, void *arg)
2322{
2323 struct gsm_mncc *proceeding = arg;
2324 struct msgb *msg = gsm48_msgb_alloc();
2325 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2326
Harald Welte03740842009-06-10 23:11:52 +08002327 gh->msg_type = GSM48_MT_CC_CALL_PROC;
2328
2329 new_cc_state(trans, GSM_CSTATE_MO_CALL_PROC);
2330
2331 /* bearer capability */
2332 if (proceeding->fields & MNCC_F_BEARER_CAP)
2333 encode_bearer_cap(msg, 0, &proceeding->bearer_cap);
2334 /* facility */
2335 if (proceeding->fields & MNCC_F_FACILITY)
2336 encode_facility(msg, 0, &proceeding->facility);
2337 /* progress */
2338 if (proceeding->fields & MNCC_F_PROGRESS)
2339 encode_progress(msg, 0, &proceeding->progress);
2340
Harald Welte36fe2e82009-07-23 21:13:03 +02002341 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002342}
2343
2344static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
2345{
2346 struct gsm48_hdr *gh = msgb_l3(msg);
2347 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2348 struct tlv_parsed tp;
2349 struct gsm_mncc alerting;
2350
2351 gsm48_stop_cc_timer(trans);
2352 gsm48_start_cc_timer(trans, 0x301, GSM48_T301);
2353
2354 memset(&alerting, 0, sizeof(struct gsm_mncc));
2355 alerting.callref = trans->callref;
2356 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2357 /* facility */
2358 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2359 alerting.fields |= MNCC_F_FACILITY;
2360 decode_facility(&alerting.facility,
2361 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2362 }
2363
2364 /* progress */
2365 if (TLVP_PRESENT(&tp, GSM48_IE_PROGR_IND)) {
2366 alerting.fields |= MNCC_F_PROGRESS;
2367 decode_progress(&alerting.progress,
2368 TLVP_VAL(&tp, GSM48_IE_PROGR_IND)-1);
2369 }
2370 /* ss-version */
2371 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2372 alerting.fields |= MNCC_F_SSVERSION;
2373 decode_ssversion(&alerting.ssversion,
2374 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2375 }
2376
2377 new_cc_state(trans, GSM_CSTATE_CALL_RECEIVED);
2378
Harald Welte0abe5a62009-07-23 19:06:52 +02002379 return mncc_recvmsg(trans->subscr->net, trans, MNCC_ALERT_IND,
2380 &alerting);
Harald Welte03740842009-06-10 23:11:52 +08002381}
2382
2383static int gsm48_cc_tx_alerting(struct gsm_trans *trans, void *arg)
2384{
2385 struct gsm_mncc *alerting = arg;
2386 struct msgb *msg = gsm48_msgb_alloc();
2387 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2388
Harald Welte03740842009-06-10 23:11:52 +08002389 gh->msg_type = GSM48_MT_CC_ALERTING;
2390
2391 /* facility */
2392 if (alerting->fields & MNCC_F_FACILITY)
2393 encode_facility(msg, 0, &alerting->facility);
2394 /* progress */
2395 if (alerting->fields & MNCC_F_PROGRESS)
2396 encode_progress(msg, 0, &alerting->progress);
2397 /* user-user */
2398 if (alerting->fields & MNCC_F_USERUSER)
2399 encode_useruser(msg, 0, &alerting->useruser);
2400
2401 new_cc_state(trans, GSM_CSTATE_CALL_DELIVERED);
2402
Harald Welte36fe2e82009-07-23 21:13:03 +02002403 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002404}
2405
2406static int gsm48_cc_tx_progress(struct gsm_trans *trans, void *arg)
2407{
2408 struct gsm_mncc *progress = arg;
2409 struct msgb *msg = gsm48_msgb_alloc();
2410 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2411
Harald Welte03740842009-06-10 23:11:52 +08002412 gh->msg_type = GSM48_MT_CC_PROGRESS;
2413
2414 /* progress */
2415 encode_progress(msg, 1, &progress->progress);
2416 /* user-user */
2417 if (progress->fields & MNCC_F_USERUSER)
2418 encode_useruser(msg, 0, &progress->useruser);
2419
Harald Welte36fe2e82009-07-23 21:13:03 +02002420 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002421}
2422
2423static int gsm48_cc_tx_connect(struct gsm_trans *trans, void *arg)
2424{
2425 struct gsm_mncc *connect = arg;
2426 struct msgb *msg = gsm48_msgb_alloc();
2427 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2428
Harald Welte03740842009-06-10 23:11:52 +08002429 gh->msg_type = GSM48_MT_CC_CONNECT;
2430
2431 gsm48_stop_cc_timer(trans);
2432 gsm48_start_cc_timer(trans, 0x313, GSM48_T313);
2433
2434 /* facility */
2435 if (connect->fields & MNCC_F_FACILITY)
2436 encode_facility(msg, 0, &connect->facility);
2437 /* progress */
2438 if (connect->fields & MNCC_F_PROGRESS)
2439 encode_progress(msg, 0, &connect->progress);
2440 /* connected number */
2441 if (connect->fields & MNCC_F_CONNECTED)
2442 encode_connected(msg, &connect->connected);
2443 /* user-user */
2444 if (connect->fields & MNCC_F_USERUSER)
2445 encode_useruser(msg, 0, &connect->useruser);
2446
2447 new_cc_state(trans, GSM_CSTATE_CONNECT_IND);
2448
Harald Welte36fe2e82009-07-23 21:13:03 +02002449 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002450}
2451
2452static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
2453{
2454 struct gsm48_hdr *gh = msgb_l3(msg);
2455 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2456 struct tlv_parsed tp;
2457 struct gsm_mncc connect;
2458
2459 gsm48_stop_cc_timer(trans);
2460
2461 memset(&connect, 0, sizeof(struct gsm_mncc));
2462 connect.callref = trans->callref;
2463 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2464 /* use subscriber as connected party number */
2465 if (trans->subscr) {
2466 connect.fields |= MNCC_F_CONNECTED;
2467 strncpy(connect.connected.number, trans->subscr->extension,
2468 sizeof(connect.connected.number)-1);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02002469 strncpy(connect.imsi, trans->subscr->imsi,
2470 sizeof(connect.imsi)-1);
Harald Welte03740842009-06-10 23:11:52 +08002471 }
2472 /* facility */
2473 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2474 connect.fields |= MNCC_F_FACILITY;
2475 decode_facility(&connect.facility,
2476 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2477 }
2478 /* user-user */
2479 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2480 connect.fields |= MNCC_F_USERUSER;
2481 decode_useruser(&connect.useruser,
2482 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2483 }
2484 /* ss-version */
2485 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2486 connect.fields |= MNCC_F_SSVERSION;
2487 decode_ssversion(&connect.ssversion,
2488 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2489 }
2490
2491 new_cc_state(trans, GSM_CSTATE_CONNECT_REQUEST);
2492
Harald Welte0abe5a62009-07-23 19:06:52 +02002493 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_CNF, &connect);
Harald Welte03740842009-06-10 23:11:52 +08002494}
2495
2496
2497static int gsm48_cc_rx_connect_ack(struct gsm_trans *trans, struct msgb *msg)
2498{
2499 struct gsm_mncc connect_ack;
2500
2501 gsm48_stop_cc_timer(trans);
2502
2503 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2504
2505 memset(&connect_ack, 0, sizeof(struct gsm_mncc));
2506 connect_ack.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002507 return mncc_recvmsg(trans->subscr->net, trans, MNCC_SETUP_COMPL_IND,
Harald Welte03740842009-06-10 23:11:52 +08002508 &connect_ack);
2509}
2510
2511static int gsm48_cc_tx_connect_ack(struct gsm_trans *trans, void *arg)
2512{
2513 struct msgb *msg = gsm48_msgb_alloc();
2514 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2515
Harald Welte03740842009-06-10 23:11:52 +08002516 gh->msg_type = GSM48_MT_CC_CONNECT_ACK;
2517
2518 new_cc_state(trans, GSM_CSTATE_ACTIVE);
2519
Harald Welte36fe2e82009-07-23 21:13:03 +02002520 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002521}
2522
2523static int gsm48_cc_rx_disconnect(struct gsm_trans *trans, struct msgb *msg)
2524{
2525 struct gsm48_hdr *gh = msgb_l3(msg);
2526 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2527 struct tlv_parsed tp;
2528 struct gsm_mncc disc;
2529
2530 gsm48_stop_cc_timer(trans);
2531
2532 new_cc_state(trans, GSM_CSTATE_DISCONNECT_REQ);
2533
2534 memset(&disc, 0, sizeof(struct gsm_mncc));
2535 disc.callref = trans->callref;
2536 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_CAUSE, 0);
2537 /* cause */
2538 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2539 disc.fields |= MNCC_F_CAUSE;
2540 decode_cause(&disc.cause,
2541 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2542 }
2543 /* facility */
2544 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2545 disc.fields |= MNCC_F_FACILITY;
2546 decode_facility(&disc.facility,
2547 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2548 }
2549 /* user-user */
2550 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2551 disc.fields |= MNCC_F_USERUSER;
2552 decode_useruser(&disc.useruser,
2553 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2554 }
2555 /* ss-version */
2556 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2557 disc.fields |= MNCC_F_SSVERSION;
2558 decode_ssversion(&disc.ssversion,
2559 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2560 }
2561
Harald Welte0abe5a62009-07-23 19:06:52 +02002562 return mncc_recvmsg(trans->subscr->net, trans, MNCC_DISC_IND, &disc);
Harald Welte03740842009-06-10 23:11:52 +08002563
2564}
2565
Harald Weltebbc636a2009-06-11 14:23:20 +08002566static struct gsm_mncc_cause default_cause = {
2567 .location = GSM48_CAUSE_LOC_PRN_S_LU,
2568 .coding = 0,
2569 .rec = 0,
2570 .rec_val = 0,
2571 .value = GSM48_CC_CAUSE_NORMAL_UNSPEC,
2572 .diag_len = 0,
2573 .diag = { 0 },
2574};
Harald Welte03740842009-06-10 23:11:52 +08002575
2576static int gsm48_cc_tx_disconnect(struct gsm_trans *trans, void *arg)
2577{
2578 struct gsm_mncc *disc = arg;
2579 struct msgb *msg = gsm48_msgb_alloc();
2580 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2581
Harald Welte03740842009-06-10 23:11:52 +08002582 gh->msg_type = GSM48_MT_CC_DISCONNECT;
2583
2584 gsm48_stop_cc_timer(trans);
2585 gsm48_start_cc_timer(trans, 0x306, GSM48_T306);
2586
2587 /* cause */
2588 if (disc->fields & MNCC_F_CAUSE)
2589 encode_cause(msg, 1, &disc->cause);
2590 else
2591 encode_cause(msg, 1, &default_cause);
2592
2593 /* facility */
2594 if (disc->fields & MNCC_F_FACILITY)
2595 encode_facility(msg, 0, &disc->facility);
2596 /* progress */
2597 if (disc->fields & MNCC_F_PROGRESS)
2598 encode_progress(msg, 0, &disc->progress);
2599 /* user-user */
2600 if (disc->fields & MNCC_F_USERUSER)
2601 encode_useruser(msg, 0, &disc->useruser);
2602
2603 /* store disconnect cause for T306 expiry */
Harald Weltec2189a62009-07-23 18:56:43 +02002604 memcpy(&trans->cc.msg, disc, sizeof(struct gsm_mncc));
Harald Welte03740842009-06-10 23:11:52 +08002605
2606 new_cc_state(trans, GSM_CSTATE_DISCONNECT_IND);
2607
Harald Welte36fe2e82009-07-23 21:13:03 +02002608 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002609}
2610
2611static int gsm48_cc_rx_release(struct gsm_trans *trans, struct msgb *msg)
2612{
2613 struct gsm48_hdr *gh = msgb_l3(msg);
2614 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2615 struct tlv_parsed tp;
2616 struct gsm_mncc rel;
2617 int rc;
2618
2619 gsm48_stop_cc_timer(trans);
2620
2621 memset(&rel, 0, sizeof(struct gsm_mncc));
2622 rel.callref = trans->callref;
2623 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2624 /* cause */
2625 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2626 rel.fields |= MNCC_F_CAUSE;
2627 decode_cause(&rel.cause,
2628 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2629 }
2630 /* facility */
2631 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2632 rel.fields |= MNCC_F_FACILITY;
2633 decode_facility(&rel.facility,
2634 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2635 }
2636 /* user-user */
2637 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2638 rel.fields |= MNCC_F_USERUSER;
2639 decode_useruser(&rel.useruser,
2640 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2641 }
2642 /* ss-version */
2643 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2644 rel.fields |= MNCC_F_SSVERSION;
2645 decode_ssversion(&rel.ssversion,
2646 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2647 }
2648
Harald Weltec2189a62009-07-23 18:56:43 +02002649 if (trans->cc.state == GSM_CSTATE_RELEASE_REQ) {
Harald Welte03740842009-06-10 23:11:52 +08002650 /* release collision 5.4.5 */
Harald Welte0abe5a62009-07-23 19:06:52 +02002651 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_CNF, &rel);
Harald Welte03740842009-06-10 23:11:52 +08002652 } else {
Harald Welte0abe5a62009-07-23 19:06:52 +02002653 rc = gsm48_tx_simple(msg->lchan,
Harald Welte4861c822009-07-23 21:21:14 +02002654 GSM48_PDISC_CC | (trans->transaction_id << 4),
Harald Welte0abe5a62009-07-23 19:06:52 +02002655 GSM48_MT_CC_RELEASE_COMPL);
2656 rc = mncc_recvmsg(trans->subscr->net, trans, MNCC_REL_IND, &rel);
Harald Welte03740842009-06-10 23:11:52 +08002657 }
2658
2659 new_cc_state(trans, GSM_CSTATE_NULL);
2660
2661 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002662 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002663
2664 return rc;
2665}
2666
2667static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg)
2668{
2669 struct gsm_mncc *rel = arg;
2670 struct msgb *msg = gsm48_msgb_alloc();
2671 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2672
Harald Welte03740842009-06-10 23:11:52 +08002673 gh->msg_type = GSM48_MT_CC_RELEASE;
2674
2675 trans->callref = 0;
2676
2677 gsm48_stop_cc_timer(trans);
2678 gsm48_start_cc_timer(trans, 0x308, GSM48_T308);
2679
2680 /* cause */
2681 if (rel->fields & MNCC_F_CAUSE)
2682 encode_cause(msg, 0, &rel->cause);
2683 /* facility */
2684 if (rel->fields & MNCC_F_FACILITY)
2685 encode_facility(msg, 0, &rel->facility);
2686 /* user-user */
2687 if (rel->fields & MNCC_F_USERUSER)
2688 encode_useruser(msg, 0, &rel->useruser);
2689
Harald Weltec2189a62009-07-23 18:56:43 +02002690 trans->cc.T308_second = 0;
2691 memcpy(&trans->cc.msg, rel, sizeof(struct gsm_mncc));
Harald Welte03740842009-06-10 23:11:52 +08002692
Harald Weltec2189a62009-07-23 18:56:43 +02002693 if (trans->cc.state != GSM_CSTATE_RELEASE_REQ)
Harald Welte03740842009-06-10 23:11:52 +08002694 new_cc_state(trans, GSM_CSTATE_RELEASE_REQ);
2695
Harald Welte36fe2e82009-07-23 21:13:03 +02002696 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002697}
2698
2699static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
2700{
2701 struct gsm48_hdr *gh = msgb_l3(msg);
2702 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2703 struct tlv_parsed tp;
2704 struct gsm_mncc rel;
2705 int rc = 0;
2706
2707 gsm48_stop_cc_timer(trans);
2708
2709 memset(&rel, 0, sizeof(struct gsm_mncc));
2710 rel.callref = trans->callref;
2711 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2712 /* cause */
2713 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
2714 rel.fields |= MNCC_F_CAUSE;
2715 decode_cause(&rel.cause,
2716 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
2717 }
2718 /* facility */
2719 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2720 rel.fields |= MNCC_F_FACILITY;
2721 decode_facility(&rel.facility,
2722 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2723 }
2724 /* user-user */
2725 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
2726 rel.fields |= MNCC_F_USERUSER;
2727 decode_useruser(&rel.useruser,
2728 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
2729 }
2730 /* ss-version */
2731 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2732 rel.fields |= MNCC_F_SSVERSION;
2733 decode_ssversion(&rel.ssversion,
2734 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2735 }
2736
2737 if (trans->callref) {
Harald Weltec2189a62009-07-23 18:56:43 +02002738 switch (trans->cc.state) {
Harald Welte03740842009-06-10 23:11:52 +08002739 case GSM_CSTATE_CALL_PRESENT:
Harald Welte0abe5a62009-07-23 19:06:52 +02002740 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002741 MNCC_REJ_IND, &rel);
2742 break;
2743 case GSM_CSTATE_RELEASE_REQ:
Harald Welte0abe5a62009-07-23 19:06:52 +02002744 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002745 MNCC_REL_CNF, &rel);
2746 break;
2747 default:
Harald Welte0abe5a62009-07-23 19:06:52 +02002748 rc = mncc_recvmsg(trans->subscr->net, trans,
Harald Welte03740842009-06-10 23:11:52 +08002749 MNCC_REL_IND, &rel);
2750 }
2751 }
2752
2753 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02002754 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002755
2756 return rc;
2757}
2758
2759static int gsm48_cc_tx_release_compl(struct gsm_trans *trans, void *arg)
2760{
2761 struct gsm_mncc *rel = arg;
2762 struct msgb *msg = gsm48_msgb_alloc();
2763 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2764
Harald Welte03740842009-06-10 23:11:52 +08002765 gh->msg_type = GSM48_MT_CC_RELEASE_COMPL;
2766
2767 trans->callref = 0;
2768
2769 gsm48_stop_cc_timer(trans);
2770
2771 /* cause */
2772 if (rel->fields & MNCC_F_CAUSE)
2773 encode_cause(msg, 0, &rel->cause);
2774 /* facility */
2775 if (rel->fields & MNCC_F_FACILITY)
2776 encode_facility(msg, 0, &rel->facility);
2777 /* user-user */
2778 if (rel->fields & MNCC_F_USERUSER)
2779 encode_useruser(msg, 0, &rel->useruser);
2780
Harald Weltec2189a62009-07-23 18:56:43 +02002781 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08002782
Harald Welte36fe2e82009-07-23 21:13:03 +02002783 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002784}
2785
2786static int gsm48_cc_rx_facility(struct gsm_trans *trans, struct msgb *msg)
2787{
2788 struct gsm48_hdr *gh = msgb_l3(msg);
2789 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2790 struct tlv_parsed tp;
2791 struct gsm_mncc fac;
2792
2793 memset(&fac, 0, sizeof(struct gsm_mncc));
2794 fac.callref = trans->callref;
2795 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_FACILITY, 0);
2796 /* facility */
2797 if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
2798 fac.fields |= MNCC_F_FACILITY;
2799 decode_facility(&fac.facility,
2800 TLVP_VAL(&tp, GSM48_IE_FACILITY)-1);
2801 }
2802 /* ss-version */
2803 if (TLVP_PRESENT(&tp, GSM48_IE_SS_VERS)) {
2804 fac.fields |= MNCC_F_SSVERSION;
2805 decode_ssversion(&fac.ssversion,
2806 TLVP_VAL(&tp, GSM48_IE_SS_VERS)-1);
2807 }
2808
Harald Welte0abe5a62009-07-23 19:06:52 +02002809 return mncc_recvmsg(trans->subscr->net, trans, MNCC_FACILITY_IND, &fac);
Harald Welte03740842009-06-10 23:11:52 +08002810}
2811
2812static int gsm48_cc_tx_facility(struct gsm_trans *trans, void *arg)
2813{
2814 struct gsm_mncc *fac = arg;
2815 struct msgb *msg = gsm48_msgb_alloc();
2816 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2817
Harald Welte03740842009-06-10 23:11:52 +08002818 gh->msg_type = GSM48_MT_CC_FACILITY;
2819
2820 /* facility */
2821 encode_facility(msg, 1, &fac->facility);
2822
Harald Welte36fe2e82009-07-23 21:13:03 +02002823 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002824}
2825
2826static int gsm48_cc_rx_hold(struct gsm_trans *trans, struct msgb *msg)
2827{
2828 struct gsm_mncc hold;
2829
2830 memset(&hold, 0, sizeof(struct gsm_mncc));
2831 hold.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002832 return mncc_recvmsg(trans->subscr->net, trans, MNCC_HOLD_IND, &hold);
Harald Welte03740842009-06-10 23:11:52 +08002833}
2834
2835static int gsm48_cc_tx_hold_ack(struct gsm_trans *trans, void *arg)
2836{
2837 struct msgb *msg = gsm48_msgb_alloc();
2838 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2839
Harald Welte03740842009-06-10 23:11:52 +08002840 gh->msg_type = GSM48_MT_CC_HOLD_ACK;
2841
Harald Welte36fe2e82009-07-23 21:13:03 +02002842 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002843}
2844
2845static int gsm48_cc_tx_hold_rej(struct gsm_trans *trans, void *arg)
2846{
2847 struct gsm_mncc *hold_rej = arg;
2848 struct msgb *msg = gsm48_msgb_alloc();
2849 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2850
Harald Welte03740842009-06-10 23:11:52 +08002851 gh->msg_type = GSM48_MT_CC_HOLD_REJ;
2852
2853 /* cause */
2854 if (hold_rej->fields & MNCC_F_CAUSE)
2855 encode_cause(msg, 1, &hold_rej->cause);
2856 else
2857 encode_cause(msg, 1, &default_cause);
2858
Harald Welte36fe2e82009-07-23 21:13:03 +02002859 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002860}
2861
2862static int gsm48_cc_rx_retrieve(struct gsm_trans *trans, struct msgb *msg)
2863{
2864 struct gsm_mncc retrieve;
2865
2866 memset(&retrieve, 0, sizeof(struct gsm_mncc));
2867 retrieve.callref = trans->callref;
Harald Welte0abe5a62009-07-23 19:06:52 +02002868 return mncc_recvmsg(trans->subscr->net, trans, MNCC_RETRIEVE_IND,
2869 &retrieve);
Harald Welte03740842009-06-10 23:11:52 +08002870}
2871
2872static int gsm48_cc_tx_retrieve_ack(struct gsm_trans *trans, void *arg)
2873{
2874 struct msgb *msg = gsm48_msgb_alloc();
2875 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2876
Harald Welte03740842009-06-10 23:11:52 +08002877 gh->msg_type = GSM48_MT_CC_RETR_ACK;
2878
Harald Welte36fe2e82009-07-23 21:13:03 +02002879 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002880}
2881
2882static int gsm48_cc_tx_retrieve_rej(struct gsm_trans *trans, void *arg)
2883{
2884 struct gsm_mncc *retrieve_rej = arg;
2885 struct msgb *msg = gsm48_msgb_alloc();
2886 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2887
Harald Welte03740842009-06-10 23:11:52 +08002888 gh->msg_type = GSM48_MT_CC_RETR_REJ;
2889
2890 /* cause */
2891 if (retrieve_rej->fields & MNCC_F_CAUSE)
2892 encode_cause(msg, 1, &retrieve_rej->cause);
2893 else
2894 encode_cause(msg, 1, &default_cause);
2895
Harald Welte36fe2e82009-07-23 21:13:03 +02002896 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002897}
2898
2899static int gsm48_cc_rx_start_dtmf(struct gsm_trans *trans, struct msgb *msg)
2900{
2901 struct gsm48_hdr *gh = msgb_l3(msg);
2902 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2903 struct tlv_parsed tp;
2904 struct gsm_mncc dtmf;
2905
2906 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2907 dtmf.callref = trans->callref;
2908 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
2909 /* keypad facility */
2910 if (TLVP_PRESENT(&tp, GSM48_IE_KPD_FACILITY)) {
2911 dtmf.fields |= MNCC_F_KEYPAD;
2912 decode_keypad(&dtmf.keypad,
2913 TLVP_VAL(&tp, GSM48_IE_KPD_FACILITY)-1);
2914 }
2915
Harald Welte0abe5a62009-07-23 19:06:52 +02002916 return mncc_recvmsg(trans->subscr->net, trans, MNCC_START_DTMF_IND, &dtmf);
Harald Welte03740842009-06-10 23:11:52 +08002917}
2918
2919static int gsm48_cc_tx_start_dtmf_ack(struct gsm_trans *trans, void *arg)
2920{
2921 struct gsm_mncc *dtmf = arg;
2922 struct msgb *msg = gsm48_msgb_alloc();
2923 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2924
Harald Welte03740842009-06-10 23:11:52 +08002925 gh->msg_type = GSM48_MT_CC_START_DTMF_ACK;
2926
2927 /* keypad */
2928 if (dtmf->fields & MNCC_F_KEYPAD)
2929 encode_keypad(msg, dtmf->keypad);
2930
Harald Welte36fe2e82009-07-23 21:13:03 +02002931 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002932}
2933
2934static int gsm48_cc_tx_start_dtmf_rej(struct gsm_trans *trans, void *arg)
2935{
2936 struct gsm_mncc *dtmf = arg;
2937 struct msgb *msg = gsm48_msgb_alloc();
2938 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2939
Harald Welte03740842009-06-10 23:11:52 +08002940 gh->msg_type = GSM48_MT_CC_START_DTMF_REJ;
2941
2942 /* cause */
2943 if (dtmf->fields & MNCC_F_CAUSE)
2944 encode_cause(msg, 1, &dtmf->cause);
2945 else
2946 encode_cause(msg, 1, &default_cause);
2947
Harald Welte36fe2e82009-07-23 21:13:03 +02002948 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002949}
2950
2951static int gsm48_cc_tx_stop_dtmf_ack(struct gsm_trans *trans, void *arg)
2952{
2953 struct msgb *msg = gsm48_msgb_alloc();
2954 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2955
Harald Welte03740842009-06-10 23:11:52 +08002956 gh->msg_type = GSM48_MT_CC_STOP_DTMF_ACK;
2957
Harald Welte36fe2e82009-07-23 21:13:03 +02002958 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08002959}
2960
2961static int gsm48_cc_rx_stop_dtmf(struct gsm_trans *trans, struct msgb *msg)
2962{
2963 struct gsm_mncc dtmf;
2964
2965 memset(&dtmf, 0, sizeof(struct gsm_mncc));
2966 dtmf.callref = trans->callref;
2967
Harald Welte0abe5a62009-07-23 19:06:52 +02002968 return mncc_recvmsg(trans->subscr->net, trans, MNCC_STOP_DTMF_IND, &dtmf);
Harald Welte03740842009-06-10 23:11:52 +08002969}
2970
2971static int gsm48_cc_rx_modify(struct gsm_trans *trans, struct msgb *msg)
2972{
2973 struct gsm48_hdr *gh = msgb_l3(msg);
2974 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
2975 struct tlv_parsed tp;
2976 struct gsm_mncc modify;
2977
2978 memset(&modify, 0, sizeof(struct gsm_mncc));
2979 modify.callref = trans->callref;
2980 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
2981 /* bearer capability */
2982 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
2983 modify.fields |= MNCC_F_BEARER_CAP;
2984 decode_bearer_cap(&modify.bearer_cap,
2985 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
2986 }
2987
2988 new_cc_state(trans, GSM_CSTATE_MO_ORIG_MODIFY);
2989
Harald Welte0abe5a62009-07-23 19:06:52 +02002990 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_IND, &modify);
Harald Welte03740842009-06-10 23:11:52 +08002991}
2992
2993static int gsm48_cc_tx_modify(struct gsm_trans *trans, void *arg)
2994{
2995 struct gsm_mncc *modify = arg;
2996 struct msgb *msg = gsm48_msgb_alloc();
2997 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
2998
Harald Welte03740842009-06-10 23:11:52 +08002999 gh->msg_type = GSM48_MT_CC_MODIFY;
3000
3001 gsm48_start_cc_timer(trans, 0x323, GSM48_T323);
3002
3003 /* bearer capability */
3004 encode_bearer_cap(msg, 1, &modify->bearer_cap);
3005
3006 new_cc_state(trans, GSM_CSTATE_MO_TERM_MODIFY);
3007
Harald Welte36fe2e82009-07-23 21:13:03 +02003008 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08003009}
3010
3011static int gsm48_cc_rx_modify_complete(struct gsm_trans *trans, struct msgb *msg)
3012{
3013 struct gsm48_hdr *gh = msgb_l3(msg);
3014 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
3015 struct tlv_parsed tp;
3016 struct gsm_mncc modify;
3017
3018 gsm48_stop_cc_timer(trans);
3019
3020 memset(&modify, 0, sizeof(struct gsm_mncc));
3021 modify.callref = trans->callref;
3022 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, 0);
3023 /* bearer capability */
3024 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
3025 modify.fields |= MNCC_F_BEARER_CAP;
3026 decode_bearer_cap(&modify.bearer_cap,
3027 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
3028 }
3029
3030 new_cc_state(trans, GSM_CSTATE_ACTIVE);
3031
Harald Welte0abe5a62009-07-23 19:06:52 +02003032 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_CNF, &modify);
Harald Welte03740842009-06-10 23:11:52 +08003033}
3034
3035static int gsm48_cc_tx_modify_complete(struct gsm_trans *trans, void *arg)
3036{
3037 struct gsm_mncc *modify = arg;
3038 struct msgb *msg = gsm48_msgb_alloc();
3039 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
3040
Harald Welte03740842009-06-10 23:11:52 +08003041 gh->msg_type = GSM48_MT_CC_MODIFY_COMPL;
3042
3043 /* bearer capability */
3044 encode_bearer_cap(msg, 1, &modify->bearer_cap);
3045
3046 new_cc_state(trans, GSM_CSTATE_ACTIVE);
3047
Harald Welte36fe2e82009-07-23 21:13:03 +02003048 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08003049}
3050
3051static int gsm48_cc_rx_modify_reject(struct gsm_trans *trans, struct msgb *msg)
3052{
3053 struct gsm48_hdr *gh = msgb_l3(msg);
3054 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
3055 struct tlv_parsed tp;
3056 struct gsm_mncc modify;
3057
3058 gsm48_stop_cc_timer(trans);
3059
3060 memset(&modify, 0, sizeof(struct gsm_mncc));
3061 modify.callref = trans->callref;
3062 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_BEARER_CAP, GSM48_IE_CAUSE);
3063 /* bearer capability */
3064 if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
3065 modify.fields |= GSM48_IE_BEARER_CAP;
3066 decode_bearer_cap(&modify.bearer_cap,
3067 TLVP_VAL(&tp, GSM48_IE_BEARER_CAP)-1);
3068 }
3069 /* cause */
3070 if (TLVP_PRESENT(&tp, GSM48_IE_CAUSE)) {
3071 modify.fields |= MNCC_F_CAUSE;
3072 decode_cause(&modify.cause,
3073 TLVP_VAL(&tp, GSM48_IE_CAUSE)-1);
3074 }
3075
3076 new_cc_state(trans, GSM_CSTATE_ACTIVE);
3077
Harald Welte0abe5a62009-07-23 19:06:52 +02003078 return mncc_recvmsg(trans->subscr->net, trans, MNCC_MODIFY_REJ, &modify);
Harald Welte03740842009-06-10 23:11:52 +08003079}
3080
3081static int gsm48_cc_tx_modify_reject(struct gsm_trans *trans, void *arg)
3082{
3083 struct gsm_mncc *modify = arg;
3084 struct msgb *msg = gsm48_msgb_alloc();
3085 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
3086
Harald Welte03740842009-06-10 23:11:52 +08003087 gh->msg_type = GSM48_MT_CC_MODIFY_REJECT;
3088
3089 /* bearer capability */
3090 encode_bearer_cap(msg, 1, &modify->bearer_cap);
3091 /* cause */
3092 encode_cause(msg, 1, &modify->cause);
3093
3094 new_cc_state(trans, GSM_CSTATE_ACTIVE);
3095
Harald Welte36fe2e82009-07-23 21:13:03 +02003096 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08003097}
3098
3099static int gsm48_cc_tx_notify(struct gsm_trans *trans, void *arg)
3100{
3101 struct gsm_mncc *notify = arg;
3102 struct msgb *msg = gsm48_msgb_alloc();
3103 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
3104
Harald Welte03740842009-06-10 23:11:52 +08003105 gh->msg_type = GSM48_MT_CC_NOTIFY;
3106
3107 /* notify */
3108 encode_notify(msg, notify->notify);
3109
Harald Welte36fe2e82009-07-23 21:13:03 +02003110 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08003111}
3112
3113static int gsm48_cc_rx_notify(struct gsm_trans *trans, struct msgb *msg)
3114{
3115 struct gsm48_hdr *gh = msgb_l3(msg);
3116 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
3117// struct tlv_parsed tp;
3118 struct gsm_mncc notify;
3119
3120 memset(&notify, 0, sizeof(struct gsm_mncc));
3121 notify.callref = trans->callref;
3122// tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len);
3123 if (payload_len >= 1)
3124 decode_notify(&notify.notify, gh->data);
3125
Harald Welte0abe5a62009-07-23 19:06:52 +02003126 return mncc_recvmsg(trans->subscr->net, trans, MNCC_NOTIFY_IND, &notify);
Harald Welte03740842009-06-10 23:11:52 +08003127}
3128
3129static int gsm48_cc_tx_userinfo(struct gsm_trans *trans, void *arg)
3130{
3131 struct gsm_mncc *user = arg;
3132 struct msgb *msg = gsm48_msgb_alloc();
3133 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
3134
Harald Welte03740842009-06-10 23:11:52 +08003135 gh->msg_type = GSM48_MT_CC_USER_INFO;
3136
3137 /* user-user */
3138 if (user->fields & MNCC_F_USERUSER)
3139 encode_useruser(msg, 1, &user->useruser);
3140 /* more data */
3141 if (user->more)
3142 encode_more(msg);
3143
Harald Welte36fe2e82009-07-23 21:13:03 +02003144 return gsm48_sendmsg(msg, trans);
Harald Welte03740842009-06-10 23:11:52 +08003145}
3146
3147static int gsm48_cc_rx_userinfo(struct gsm_trans *trans, struct msgb *msg)
3148{
3149 struct gsm48_hdr *gh = msgb_l3(msg);
3150 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
3151 struct tlv_parsed tp;
3152 struct gsm_mncc user;
3153
3154 memset(&user, 0, sizeof(struct gsm_mncc));
3155 user.callref = trans->callref;
3156 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, GSM48_IE_USER_USER, 0);
3157 /* user-user */
3158 if (TLVP_PRESENT(&tp, GSM48_IE_USER_USER)) {
3159 user.fields |= MNCC_F_USERUSER;
3160 decode_useruser(&user.useruser,
3161 TLVP_VAL(&tp, GSM48_IE_USER_USER)-1);
3162 }
3163 /* more data */
3164 if (TLVP_PRESENT(&tp, GSM48_IE_MORE_DATA))
3165 user.more = 1;
3166
Harald Welte0abe5a62009-07-23 19:06:52 +02003167 return mncc_recvmsg(trans->subscr->net, trans, MNCC_USERINFO_IND, &user);
Harald Welte03740842009-06-10 23:11:52 +08003168}
3169
3170static int gsm48_lchan_modify(struct gsm_trans *trans, void *arg)
3171{
3172 struct gsm_mncc *mode = arg;
Harald Welteca745e22009-07-29 12:10:35 +02003173 int rc;
Harald Welte03740842009-06-10 23:11:52 +08003174
Harald Welteca745e22009-07-29 12:10:35 +02003175 rc = gsm48_tx_chan_mode_modify(trans->lchan, mode->lchan_mode);
3176 if (rc < 0)
3177 return rc;
3178
3179 /* FIXME: we not only need to do this after mode modify, but
3180 * also after channel activation */
3181 if (is_ipaccess_bts(trans->lchan->ts->trx->bts) &&
3182 mode->lchan_mode != GSM48_CMODE_SIGN)
3183 rc = rsl_ipacc_bind(trans->lchan);
3184
3185 return rc;
Harald Welte03740842009-06-10 23:11:52 +08003186}
3187
3188static struct downstate {
3189 u_int32_t states;
3190 int type;
3191 int (*rout) (struct gsm_trans *trans, void *arg);
3192} downstatelist[] = {
3193 /* mobile originating call establishment */
3194 {SBIT(GSM_CSTATE_INITIATED), /* 5.2.1.2 */
3195 MNCC_CALL_PROC_REQ, gsm48_cc_tx_call_proc},
3196 {SBIT(GSM_CSTATE_INITIATED) | SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.2 | 5.2.1.5 */
3197 MNCC_ALERT_REQ, gsm48_cc_tx_alerting},
3198 {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 */
3199 MNCC_SETUP_RSP, gsm48_cc_tx_connect},
3200 {SBIT(GSM_CSTATE_MO_CALL_PROC), /* 5.2.1.4.2 */
3201 MNCC_PROGRESS_REQ, gsm48_cc_tx_progress},
3202 /* mobile terminating call establishment */
3203 {SBIT(GSM_CSTATE_NULL), /* 5.2.2.1 */
3204 MNCC_SETUP_REQ, gsm48_cc_tx_setup},
3205 {SBIT(GSM_CSTATE_CONNECT_REQUEST),
3206 MNCC_SETUP_COMPL_REQ, gsm48_cc_tx_connect_ack},
3207 /* signalling during call */
3208 {SBIT(GSM_CSTATE_ACTIVE),
3209 MNCC_NOTIFY_REQ, gsm48_cc_tx_notify},
3210 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ),
3211 MNCC_FACILITY_REQ, gsm48_cc_tx_facility},
3212 {ALL_STATES,
3213 MNCC_START_DTMF_RSP, gsm48_cc_tx_start_dtmf_ack},
3214 {ALL_STATES,
3215 MNCC_START_DTMF_REJ, gsm48_cc_tx_start_dtmf_rej},
3216 {ALL_STATES,
3217 MNCC_STOP_DTMF_RSP, gsm48_cc_tx_stop_dtmf_ack},
3218 {SBIT(GSM_CSTATE_ACTIVE),
3219 MNCC_HOLD_CNF, gsm48_cc_tx_hold_ack},
3220 {SBIT(GSM_CSTATE_ACTIVE),
3221 MNCC_HOLD_REJ, gsm48_cc_tx_hold_rej},
3222 {SBIT(GSM_CSTATE_ACTIVE),
3223 MNCC_RETRIEVE_CNF, gsm48_cc_tx_retrieve_ack},
3224 {SBIT(GSM_CSTATE_ACTIVE),
3225 MNCC_RETRIEVE_REJ, gsm48_cc_tx_retrieve_rej},
3226 {SBIT(GSM_CSTATE_ACTIVE),
3227 MNCC_MODIFY_REQ, gsm48_cc_tx_modify},
3228 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
3229 MNCC_MODIFY_RSP, gsm48_cc_tx_modify_complete},
3230 {SBIT(GSM_CSTATE_MO_ORIG_MODIFY),
3231 MNCC_MODIFY_REJ, gsm48_cc_tx_modify_reject},
3232 {SBIT(GSM_CSTATE_ACTIVE),
3233 MNCC_USERINFO_REQ, gsm48_cc_tx_userinfo},
3234 /* clearing */
3235 {SBIT(GSM_CSTATE_INITIATED),
3236 MNCC_REJ_REQ, gsm48_cc_tx_release_compl},
3237 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_DISCONNECT_IND) - SBIT(GSM_CSTATE_RELEASE_REQ) - SBIT(GSM_CSTATE_DISCONNECT_REQ), /* 5.4.4 */
3238 MNCC_DISC_REQ, gsm48_cc_tx_disconnect},
3239 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3240 MNCC_REL_REQ, gsm48_cc_tx_release},
3241 /* special */
3242 {ALL_STATES,
3243 MNCC_LCHAN_MODIFY, gsm48_lchan_modify},
3244};
3245
3246#define DOWNSLLEN \
3247 (sizeof(downstatelist) / sizeof(struct downstate))
3248
3249
3250int mncc_send(struct gsm_network *net, int msg_type, void *arg)
3251{
Harald Welteaa60edb2009-08-09 18:52:33 +02003252 int i, rc = 0;
Harald Welte03740842009-06-10 23:11:52 +08003253 struct gsm_trans *trans = NULL, *transt;
3254 struct gsm_subscriber *subscr;
Harald Welteaa60edb2009-08-09 18:52:33 +02003255 struct gsm_lchan *lchan = NULL;
Harald Welte03740842009-06-10 23:11:52 +08003256 struct gsm_bts *bts = NULL;
Harald Welte03740842009-06-10 23:11:52 +08003257 struct gsm_mncc *data = arg, rel;
3258
3259 /* handle special messages */
3260 switch(msg_type) {
3261 case MNCC_BRIDGE:
3262 return tch_bridge(net, arg);
3263 case MNCC_FRAME_DROP:
3264 return tch_recv(net, arg, 0);
3265 case MNCC_FRAME_RECV:
3266 return tch_recv(net, arg, 1);
3267 case GSM_TRAU_FRAME:
3268 return tch_frame(net, arg);
3269 }
3270
3271 memset(&rel, 0, sizeof(struct gsm_mncc));
3272 rel.callref = data->callref;
3273
3274 /* Find callref */
Harald Weltec2189a62009-07-23 18:56:43 +02003275 trans = trans_find_by_callref(net, data->callref);
Harald Welte03740842009-06-10 23:11:52 +08003276
3277 /* Callref unknown */
3278 if (!trans) {
Harald Welte6e1536e2009-07-04 10:11:24 +02003279 if (msg_type != MNCC_SETUP_REQ) {
Harald Welte03740842009-06-10 23:11:52 +08003280 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
3281 "Received '%s' from MNCC with "
3282 "unknown callref %d\n", data->called.number,
3283 get_mncc_name(msg_type), data->callref);
3284 /* Invalid call reference */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08003285 return mncc_release_ind(net, NULL, data->callref,
3286 GSM48_CAUSE_LOC_PRN_S_LU,
3287 GSM48_CC_CAUSE_INVAL_TRANS_ID);
Harald Welte03740842009-06-10 23:11:52 +08003288 }
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02003289 if (!data->called.number[0] && !data->imsi[0]) {
3290 DEBUGP(DCC, "(bts - trx - ts - ti) "
3291 "Received '%s' from MNCC with "
3292 "no number or IMSI\n", get_mncc_name(msg_type));
3293 /* Invalid number */
3294 return mncc_release_ind(net, NULL, data->callref,
3295 GSM48_CAUSE_LOC_PRN_S_LU,
3296 GSM48_CC_CAUSE_INV_NR_FORMAT);
3297 }
Harald Welte03740842009-06-10 23:11:52 +08003298 /* New transaction due to setup, find subscriber */
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02003299 if (data->called.number[0])
Harald Welte75350412009-07-23 18:46:00 +02003300 subscr = subscr_get_by_extension(net,
3301 data->called.number);
Andreas Eversberg9eaa5da2009-06-15 23:22:09 +02003302 else
Harald Welte75350412009-07-23 18:46:00 +02003303 subscr = subscr_get_by_imsi(net, data->imsi);
Harald Welte03740842009-06-10 23:11:52 +08003304 /* If subscriber is not found */
3305 if (!subscr) {
3306 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
3307 "Received '%s' from MNCC with "
3308 "unknown subscriber %s\n", data->called.number,
3309 get_mncc_name(msg_type), data->called.number);
3310 /* Unknown subscriber */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08003311 return mncc_release_ind(net, NULL, data->callref,
3312 GSM48_CAUSE_LOC_PRN_S_LU,
3313 GSM48_CC_CAUSE_UNASSIGNED_NR);
Harald Welte03740842009-06-10 23:11:52 +08003314 }
3315 /* If subscriber is not "attached" */
3316 if (!subscr->lac) {
3317 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
3318 "Received '%s' from MNCC with "
3319 "detached subscriber %s\n", data->called.number,
3320 get_mncc_name(msg_type), data->called.number);
3321 subscr_put(subscr);
3322 /* Temporarily out of order */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08003323 return mncc_release_ind(net, NULL, data->callref,
3324 GSM48_CAUSE_LOC_PRN_S_LU,
3325 GSM48_CC_CAUSE_DEST_OOO);
Harald Welte03740842009-06-10 23:11:52 +08003326 }
3327 /* Create transaction */
Harald Weltec2189a62009-07-23 18:56:43 +02003328 trans = trans_alloc(subscr, GSM48_PDISC_CC, 0xff, data->callref);
3329 if (!trans) {
Harald Welte03740842009-06-10 23:11:52 +08003330 DEBUGP(DCC, "No memory for trans.\n");
3331 subscr_put(subscr);
3332 /* Ressource unavailable */
Andreas Eversbergb992a8a2009-06-14 22:14:12 +08003333 mncc_release_ind(net, NULL, data->callref,
3334 GSM48_CAUSE_LOC_PRN_S_LU,
3335 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
Harald Welte03740842009-06-10 23:11:52 +08003336 return -ENOMEM;
3337 }
Harald Welte03740842009-06-10 23:11:52 +08003338 /* Find lchan */
Harald Welteaa60edb2009-08-09 18:52:33 +02003339 lchan = lchan_for_subscr(subscr);
Harald Welte03740842009-06-10 23:11:52 +08003340 /* If subscriber has no lchan */
3341 if (!lchan) {
3342 /* find transaction with this subscriber already paging */
3343 llist_for_each_entry(transt, &net->trans_list, entry) {
3344 /* Transaction of our lchan? */
3345 if (transt == trans ||
3346 transt->subscr != subscr)
3347 continue;
3348 DEBUGP(DCC, "(bts %d trx - ts - ti -- sub %s) "
3349 "Received '%s' from MNCC with "
3350 "unallocated channel, paging already "
3351 "started.\n", bts->nr,
3352 data->called.number,
3353 get_mncc_name(msg_type));
3354 return 0;
3355 }
3356 /* store setup informations until paging was successfull */
Harald Weltec2189a62009-07-23 18:56:43 +02003357 memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
Harald Welte2a3a81b2009-08-01 19:31:47 +02003358 /* Trigger paging */
3359 paging_request(net, subscr, RSL_CHANNEED_TCH_F,
3360 setup_trig_pag_evt, subscr);
Harald Welte03740842009-06-10 23:11:52 +08003361 return 0;
3362 }
3363 /* Assign lchan */
3364 trans->lchan = lchan;
3365 use_lchan(lchan);
3366 }
3367 lchan = trans->lchan;
3368
3369 /* if paging did not respond yet */
3370 if (!lchan) {
3371 DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
3372 "Received '%s' from MNCC in paging state\n",
3373 (trans->subscr)?(trans->subscr->extension):"-",
3374 get_mncc_name(msg_type));
Harald Weltebbc636a2009-06-11 14:23:20 +08003375 mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU,
3376 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
Harald Welte03740842009-06-10 23:11:52 +08003377 if (msg_type == MNCC_REL_REQ)
3378 rc = mncc_recvmsg(net, trans, MNCC_REL_CNF, &rel);
3379 else
3380 rc = mncc_recvmsg(net, trans, MNCC_REL_IND, &rel);
3381 trans->callref = 0;
Harald Weltec2189a62009-07-23 18:56:43 +02003382 trans_free(trans);
Harald Welte03740842009-06-10 23:11:52 +08003383 return rc;
3384 }
3385
3386 DEBUGP(DCC, "(bts %d trx %d ts %d ti %02x sub %s) "
3387 "Received '%s' from MNCC in state %d (%s)\n",
3388 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
3389 trans->transaction_id,
3390 (lchan->subscr)?(lchan->subscr->extension):"-",
Harald Weltec2189a62009-07-23 18:56:43 +02003391 get_mncc_name(msg_type), trans->cc.state,
3392 cc_state_names[trans->cc.state]);
Harald Welte03740842009-06-10 23:11:52 +08003393
3394 /* Find function for current state and message */
3395 for (i = 0; i < DOWNSLLEN; i++)
3396 if ((msg_type == downstatelist[i].type)
Harald Weltec2189a62009-07-23 18:56:43 +02003397 && ((1 << trans->cc.state) & downstatelist[i].states))
Harald Welte03740842009-06-10 23:11:52 +08003398 break;
3399 if (i == DOWNSLLEN) {
3400 DEBUGP(DCC, "Message unhandled at this state.\n");
3401 return 0;
3402 }
3403
3404 rc = downstatelist[i].rout(trans, arg);
3405
3406 return rc;
3407}
3408
3409
3410static struct datastate {
3411 u_int32_t states;
3412 int type;
3413 int (*rout) (struct gsm_trans *trans, struct msgb *msg);
3414} datastatelist[] = {
3415 /* mobile originating call establishment */
3416 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
3417 GSM48_MT_CC_SETUP, gsm48_cc_rx_setup},
3418 {SBIT(GSM_CSTATE_NULL), /* 5.2.1.2 */
3419 GSM48_MT_CC_EMERG_SETUP, gsm48_cc_rx_setup},
3420 {SBIT(GSM_CSTATE_CONNECT_IND), /* 5.2.1.2 */
3421 GSM48_MT_CC_CONNECT_ACK, gsm48_cc_rx_connect_ack},
3422 /* mobile terminating call establishment */
3423 {SBIT(GSM_CSTATE_CALL_PRESENT), /* 5.2.2.3.2 */
3424 GSM48_MT_CC_CALL_CONF, gsm48_cc_rx_call_conf},
3425 {SBIT(GSM_CSTATE_CALL_PRESENT) | SBIT(GSM_CSTATE_MO_TERM_CALL_CONF), /* ???? | 5.2.2.3.2 */
3426 GSM48_MT_CC_ALERTING, gsm48_cc_rx_alerting},
3427 {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 */
3428 GSM48_MT_CC_CONNECT, gsm48_cc_rx_connect},
3429 /* signalling during call */
3430 {ALL_STATES - SBIT(GSM_CSTATE_NULL),
3431 GSM48_MT_CC_FACILITY, gsm48_cc_rx_facility},
3432 {SBIT(GSM_CSTATE_ACTIVE),
3433 GSM48_MT_CC_NOTIFY, gsm48_cc_rx_notify},
3434 {ALL_STATES,
3435 GSM48_MT_CC_START_DTMF, gsm48_cc_rx_start_dtmf},
3436 {ALL_STATES,
3437 GSM48_MT_CC_STOP_DTMF, gsm48_cc_rx_stop_dtmf},
3438 {ALL_STATES,
3439 GSM48_MT_CC_STATUS_ENQ, gsm48_cc_rx_status_enq},
3440 {SBIT(GSM_CSTATE_ACTIVE),
3441 GSM48_MT_CC_HOLD, gsm48_cc_rx_hold},
3442 {SBIT(GSM_CSTATE_ACTIVE),
3443 GSM48_MT_CC_RETR, gsm48_cc_rx_retrieve},
3444 {SBIT(GSM_CSTATE_ACTIVE),
3445 GSM48_MT_CC_MODIFY, gsm48_cc_rx_modify},
3446 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3447 GSM48_MT_CC_MODIFY_COMPL, gsm48_cc_rx_modify_complete},
3448 {SBIT(GSM_CSTATE_MO_TERM_MODIFY),
3449 GSM48_MT_CC_MODIFY_REJECT, gsm48_cc_rx_modify_reject},
3450 {SBIT(GSM_CSTATE_ACTIVE),
3451 GSM48_MT_CC_USER_INFO, gsm48_cc_rx_userinfo},
3452 /* clearing */
3453 {ALL_STATES - SBIT(GSM_CSTATE_NULL) - SBIT(GSM_CSTATE_RELEASE_REQ), /* 5.4.3.2 */
3454 GSM48_MT_CC_DISCONNECT, gsm48_cc_rx_disconnect},
3455 {ALL_STATES - SBIT(GSM_CSTATE_NULL), /* 5.4.4.1.2.2 */
3456 GSM48_MT_CC_RELEASE, gsm48_cc_rx_release},
3457 {ALL_STATES, /* 5.4.3.4 */
3458 GSM48_MT_CC_RELEASE_COMPL, gsm48_cc_rx_release_compl},
3459};
3460
3461#define DATASLLEN \
3462 (sizeof(datastatelist) / sizeof(struct datastate))
3463
Harald Welte59b04682009-06-10 05:40:52 +08003464static int gsm0408_rcv_cc(struct msgb *msg)
3465{
3466 struct gsm48_hdr *gh = msgb_l3(msg);
3467 u_int8_t msg_type = gh->msg_type & 0xbf;
Harald Welte4861c822009-07-23 21:21:14 +02003468 u_int8_t transaction_id = ((gh->proto_discr & 0xf0) ^ 0x80) >> 4; /* flip */
Harald Welte03740842009-06-10 23:11:52 +08003469 struct gsm_lchan *lchan = msg->lchan;
Harald Weltec2189a62009-07-23 18:56:43 +02003470 struct gsm_trans *trans = NULL;
Harald Welte03740842009-06-10 23:11:52 +08003471 int i, rc = 0;
Harald Welte59b04682009-06-10 05:40:52 +08003472
Harald Welte03740842009-06-10 23:11:52 +08003473 if (msg_type & 0x80) {
3474 DEBUGP(DCC, "MSG 0x%2x not defined for PD error\n", msg_type);
3475 return -EINVAL;
Harald Welte59b04682009-06-10 05:40:52 +08003476 }
Harald Welte03740842009-06-10 23:11:52 +08003477
3478 /* Find transaction */
Harald Welte0d824162009-07-23 21:58:40 +02003479 trans = trans_find_by_id(lchan->subscr, GSM48_PDISC_CC, transaction_id);
Harald Weltec2189a62009-07-23 18:56:43 +02003480
Harald Welte4861c822009-07-23 21:21:14 +02003481 DEBUGP(DCC, "(bts %d trx %d ts %d ti %x sub %s) "
Harald Welte03740842009-06-10 23:11:52 +08003482 "Received '%s' from MS in state %d (%s)\n",
3483 lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
3484 transaction_id, (lchan->subscr)?(lchan->subscr->extension):"-",
Holger Hans Peter Freyther36897102009-08-01 07:26:59 +02003485 gsm0408_cc_msg_names[msg_type], trans?(trans->cc.state):0,
Harald Weltec2189a62009-07-23 18:56:43 +02003486 cc_state_names[trans?(trans->cc.state):0]);
Harald Welte03740842009-06-10 23:11:52 +08003487
3488 /* Create transaction */
3489 if (!trans) {
Harald Welte4861c822009-07-23 21:21:14 +02003490 DEBUGP(DCC, "Unknown transaction ID %x, "
Harald Welte03740842009-06-10 23:11:52 +08003491 "creating new trans.\n", transaction_id);
3492 /* Create transaction */
Harald Weltec2189a62009-07-23 18:56:43 +02003493 trans = trans_alloc(lchan->subscr, GSM48_PDISC_CC,
3494 transaction_id, new_callref++);
3495 if (!trans) {
Harald Welte03740842009-06-10 23:11:52 +08003496 DEBUGP(DCC, "No memory for trans.\n");
3497 rc = gsm48_tx_simple(msg->lchan,
Harald Welte4861c822009-07-23 21:21:14 +02003498 GSM48_PDISC_CC | (transaction_id << 4),
Harald Welte03740842009-06-10 23:11:52 +08003499 GSM48_MT_CC_RELEASE_COMPL);
3500 return -ENOMEM;
3501 }
Harald Welte03740842009-06-10 23:11:52 +08003502 /* Assign transaction */
Harald Welte03740842009-06-10 23:11:52 +08003503 trans->lchan = lchan;
3504 use_lchan(lchan);
Harald Welte03740842009-06-10 23:11:52 +08003505 }
3506
3507 /* find function for current state and message */
3508 for (i = 0; i < DATASLLEN; i++)
3509 if ((msg_type == datastatelist[i].type)
Harald Weltec2189a62009-07-23 18:56:43 +02003510 && ((1 << trans->cc.state) & datastatelist[i].states))
Harald Welte03740842009-06-10 23:11:52 +08003511 break;
3512 if (i == DATASLLEN) {
3513 DEBUGP(DCC, "Message unhandled at this state.\n");
3514 return 0;
3515 }
3516
3517 rc = datastatelist[i].rout(trans, msg);
Harald Welte59b04682009-06-10 05:40:52 +08003518
3519 return rc;
3520}
3521
3522/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
Harald Welte (local)64994ce2009-08-14 11:41:12 +02003523int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
Harald Welte59b04682009-06-10 05:40:52 +08003524{
3525 struct gsm48_hdr *gh = msgb_l3(msg);
3526 u_int8_t pdisc = gh->proto_discr & 0x0f;
3527 int rc = 0;
3528
3529 switch (pdisc) {
3530 case GSM48_PDISC_CC:
3531 rc = gsm0408_rcv_cc(msg);
3532 break;
3533 case GSM48_PDISC_MM:
3534 rc = gsm0408_rcv_mm(msg);
3535 break;
3536 case GSM48_PDISC_RR:
3537 rc = gsm0408_rcv_rr(msg);
3538 break;
3539 case GSM48_PDISC_SMS:
Harald Welte (local)64994ce2009-08-14 11:41:12 +02003540 rc = gsm0411_rcv_sms(msg, link_id);
Harald Welte59b04682009-06-10 05:40:52 +08003541 break;
3542 case GSM48_PDISC_MM_GPRS:
3543 case GSM48_PDISC_SM_GPRS:
Mike Haben2f8a6852009-09-26 19:00:03 +02003544 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +08003545 pdisc);
3546 break;
Harald Welte03115042009-10-16 08:32:58 +02003547 case GSM48_PDISC_NC_SS:
3548 rc = handle_rcv_ussd(msg);
3549 break;
Harald Welte59b04682009-06-10 05:40:52 +08003550 default:
Mike Haben2f8a6852009-09-26 19:00:03 +02003551 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02x\n",
Harald Welte59b04682009-06-10 05:40:52 +08003552 pdisc);
3553 break;
3554 }
3555
3556 return rc;
3557}
3558
Harald Welte03740842009-06-10 23:11:52 +08003559/* dequeue messages to layer 4 */
3560int bsc_upqueue(struct gsm_network *net)
3561{
3562 struct gsm_mncc *mncc;
3563 struct msgb *msg;
3564 int work = 0;
3565
3566 if (net)
3567 while ((msg = msgb_dequeue(&net->upqueue))) {
3568 mncc = (struct gsm_mncc *)msg->data;
3569 if (net->mncc_recv)
3570 net->mncc_recv(net, mncc->msg_type, mncc);
3571 work = 1; /* work done */
Harald Weltebaf4d3a2009-06-26 19:40:48 +02003572 talloc_free(msg);
Harald Welte03740842009-06-10 23:11:52 +08003573 }
3574
3575 return work;
3576}
Harald Weltec2189a62009-07-23 18:56:43 +02003577
Harald Welte3c062072009-07-28 18:25:29 +02003578/*
3579 * This will be ran by the linker when loading the DSO. We use it to
3580 * do system initialization, e.g. registration of signal handlers.
3581 */
3582static __attribute__((constructor)) void on_dso_load_0408(void)
3583{
Harald Welte3c062072009-07-28 18:25:29 +02003584 register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL);
3585 register_signal_handler(SS_ABISIP, handle_abisip_signal, NULL);
3586}