blob: d0c9ad5cdc0c329b9a662d00116b3a8c16ef1688 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* 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
Harald Weltebf5e8df2009-02-03 12:59:45 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte498b0bb2009-01-09 21:27:43 +00005 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte8470bf22008-12-25 23:28:35 +00006 *
Harald Welte52b1f982008-12-23 20:25:15 +00007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
Harald Weltedb253af2008-12-30 17:56:55 +000030#include <time.h>
Harald Welte4b634542008-12-27 01:55:51 +000031#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000032
Harald Welte75a983f2008-12-27 21:34:06 +000033#include <openbsc/db.h>
Harald Welte8470bf22008-12-25 23:28:35 +000034#include <openbsc/msgb.h>
Harald Welte7584aea2009-02-11 11:44:12 +000035#include <openbsc/tlv.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <openbsc/debug.h>
37#include <openbsc/gsm_data.h>
38#include <openbsc/gsm_subscriber.h>
Daniel Willmann8b3390e2008-12-28 00:31:09 +000039#include <openbsc/gsm_04_11.h>
Harald Welte8470bf22008-12-25 23:28:35 +000040#include <openbsc/gsm_04_08.h>
41#include <openbsc/abis_rsl.h>
Holger Freytherca362a62009-01-04 21:05:01 +000042#include <openbsc/chan_alloc.h>
Harald Welte0b4c34e2009-02-09 17:54:43 +000043#include <openbsc/paging.h>
Holger Freyther053e09d2009-02-14 22:51:06 +000044#include <openbsc/signal.h>
Harald Welte52b1f982008-12-23 20:25:15 +000045
Harald Welte8470bf22008-12-25 23:28:35 +000046#define GSM48_ALLOC_SIZE 1024
47#define GSM48_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000048
Harald Welte09e38af2009-02-16 22:52:23 +000049static const struct tlv_definition rsl_att_tlvdef = {
50 .def = {
51 [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV },
52 [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV },
53 [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV },
54 [GSM48_IE_UTC] = { TLV_TYPE_TV },
55 [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 },
56 [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV },
57
58 [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV },
59 [GSM48_IE_CAUSE] = { TLV_TYPE_TLV },
60 [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV },
61 [GSM48_IE_ALERT] = { TLV_TYPE_TLV },
62 [GSM48_IE_FACILITY] = { TLV_TYPE_TLV },
63 [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV },
64 [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV },
65 [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV },
66 [GSM48_IE_SIGNAL] = { TLV_TYPE_TV },
67 [GSM48_IE_CONN_NUM] = { TLV_TYPE_TLV },
68 [GSM48_IE_CONN_SUBADDR] = { TLV_TYPE_TLV },
69 [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV },
70 [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV },
71 [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV },
72 [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV },
73 [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV },
74 [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV },
75 [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV },
76 [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV },
77 [GSM48_IE_USER_USER] = { TLV_TYPE_TLV },
78 [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV },
79 [GSM48_IE_MORE_DATA] = { TLV_TYPE_T },
80 [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T },
81 [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T },
82 [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T },
83 /* FIXME: more elements */
84 },
85};
86
87
Harald Welte65e74cc2008-12-29 01:55:35 +000088static int gsm48_tx_simple(struct gsm_lchan *lchan,
89 u_int8_t pdisc, u_int8_t msg_type);
Holger Freytherb7193e42008-12-29 17:44:08 +000090static void schedule_reject(struct gsm_lchan *lchan);
Harald Welte65e74cc2008-12-29 01:55:35 +000091
Harald Welte52b1f982008-12-23 20:25:15 +000092struct gsm_lai {
93 u_int16_t mcc;
94 u_int16_t mnc;
95 u_int16_t lac;
96};
97
Holger Freyther89824fc2008-12-30 16:18:18 +000098static int authorize_everonye = 0;
99void gsm0408_allow_everyone(int everyone)
100{
101 printf("Allowing everyone?\n");
102 authorize_everonye = everyone;
103}
104
Holger Freythere97f7fb2008-12-31 18:52:11 +0000105static int reject_cause = 0;
106void gsm0408_set_reject_cause(int cause)
107{
108 reject_cause = cause;
109}
110
Holger Freyther73487a22008-12-31 18:53:57 +0000111static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
112 struct gsm_subscriber *subscriber)
Holger Freyther89824fc2008-12-30 16:18:18 +0000113{
114 if (!subscriber)
115 return 0;
116
Holger Freyther73487a22008-12-31 18:53:57 +0000117 /*
118 * Do not send accept yet as more information should arrive. Some
119 * phones will not send us the information and we will have to check
120 * what we want to do with that.
121 */
122 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
123 return 0;
124
Holger Freyther89824fc2008-12-30 16:18:18 +0000125 if (authorize_everonye)
126 return 1;
127
128 return subscriber->authorized;
129}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000130
Holger Freyther73487a22008-12-31 18:53:57 +0000131static void release_loc_updating_req(struct gsm_lchan *lchan)
132{
Harald Welte179f0642008-12-31 23:59:18 +0000133 if (!lchan->loc_operation)
Holger Freyther73487a22008-12-31 18:53:57 +0000134 return;
135
136 del_timer(&lchan->loc_operation->updating_timer);
137 free(lchan->loc_operation);
138 lchan->loc_operation = 0;
Holger Freyther3eaa7922009-01-01 02:59:03 +0000139 put_lchan(lchan);
Holger Freyther73487a22008-12-31 18:53:57 +0000140}
141
142static void allocate_loc_updating_req(struct gsm_lchan *lchan)
143{
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000144 use_lchan(lchan);
Holger Freyther73487a22008-12-31 18:53:57 +0000145 release_loc_updating_req(lchan);
146
147 lchan->loc_operation = (struct gsm_loc_updating_operation *)
148 malloc(sizeof(*lchan->loc_operation));
149 memset(lchan->loc_operation, 0, sizeof(*lchan->loc_operation));
150}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000151
Harald Welte52b1f982008-12-23 20:25:15 +0000152static void to_bcd(u_int8_t *bcd, u_int16_t val)
153{
Harald Welte4b634542008-12-27 01:55:51 +0000154 bcd[2] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000155 val = val / 10;
156 bcd[1] = val % 10;
157 val = val / 10;
Harald Welte4b634542008-12-27 01:55:51 +0000158 bcd[0] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000159 val = val / 10;
160}
161
Holger Freyther17746612008-12-28 16:32:44 +0000162void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
Harald Welte52b1f982008-12-23 20:25:15 +0000163 u_int16_t mnc, u_int16_t lac)
164{
165 u_int8_t bcd[3];
166
167 to_bcd(bcd, mcc);
168 lai48->digits[0] = bcd[0] | (bcd[1] << 4);
169 lai48->digits[1] = bcd[2];
170
171 to_bcd(bcd, mnc);
Harald Welte4b634542008-12-27 01:55:51 +0000172 /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
173#if 0
Harald Welte8470bf22008-12-25 23:28:35 +0000174 lai48->digits[1] |= bcd[2] << 4;
175 lai48->digits[2] = bcd[0] | (bcd[1] << 4);
Harald Welte4b634542008-12-27 01:55:51 +0000176#else
177 lai48->digits[1] |= 0xf << 4;
178 lai48->digits[2] = bcd[1] | (bcd[2] << 4);
179#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000180
Harald Welte4b634542008-12-27 01:55:51 +0000181 lai48->lac = htons(lac);
Harald Welte52b1f982008-12-23 20:25:15 +0000182}
183
Harald Welte255539c2008-12-28 02:26:27 +0000184#define TMSI_LEN 5
Harald Welte52b1f982008-12-23 20:25:15 +0000185#define MID_TMSI_LEN (TMSI_LEN + 2)
186
Harald Welte255539c2008-12-28 02:26:27 +0000187int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000188{
Harald Welte65e74cc2008-12-29 01:55:35 +0000189 u_int32_t *tptr = (u_int32_t *) &buf[3];
Harald Welte255539c2008-12-28 02:26:27 +0000190
Harald Welte4b634542008-12-27 01:55:51 +0000191 buf[0] = GSM48_IE_MOBILE_ID;
Harald Welte1a412182008-12-27 22:13:43 +0000192 buf[1] = TMSI_LEN;
Harald Welte4b634542008-12-27 01:55:51 +0000193 buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
Harald Welte255539c2008-12-28 02:26:27 +0000194 *tptr = htonl(tmsi);
195
196 return 7;
Harald Welte52b1f982008-12-23 20:25:15 +0000197}
198
Harald Welte09e38af2009-02-16 22:52:23 +0000199static const char bcd_num_digits[] = {
200 '0', '1', '2', '3', '4', '5', '6', '7',
201 '8', '9', '*', '#', 'a', 'b', 'c', '\0'
202};
203
204/* decode a 'called party BCD number' as in 10.5.4.7 */
205u_int8_t decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv)
206{
207 u_int8_t in_len = bcd_lv[0];
208 int i;
209
210 if (in_len < 1)
211 return 0;
212
213 for (i = 2; i <= in_len; i++) {
214 /* lower nibble */
215 output_len--;
216 if (output_len <= 1)
217 break;
218 *output++ = bcd_num_digits[bcd_lv[i] & 0xf];
219
220 /* higher nibble */
221 output_len--;
222 if (output_len <= 1)
223 break;
224 *output++ = bcd_num_digits[bcd_lv[i] >> 4];
225 }
226 if (output_len >= 1)
227 *output++ = '\0';
228
229 /* return number type / calling plan */
230 return bcd_lv[1] & 0x3f;
231}
232
233/* convert a single ASCII character to call-control BCD */
234static int asc_to_bcd(const char asc)
235{
236 int i;
237
238 for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) {
239 if (bcd_num_digits[i] == asc)
240 return i;
241 }
242 return -EINVAL;
243}
244
245/* convert a ASCII phone number to 'called party BCD number' */
246int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len,
247 u_int8_t type, const char *input)
248{
249 int in_len = strlen(input);
250 int i;
251 u_int8_t *bcd_cur = bcd_lv + 2;
252
253 if (in_len/2 + 1 > max_len)
254 return -EIO;
255
256 /* two digits per byte, plus type byte */
257 bcd_lv[0] = in_len/2 + 1;
258 if (in_len % 2)
259 bcd_lv[0]++;
260
261 /* if the caller wants to create a valid 'calling party BCD
262 * number', then the extension bit MUST NOT be set. For the
263 * 'called party BCD number' it MUST be set. *sigh */
264 bcd_lv[1] = type;
265
266 for (i = 0; i < in_len; i++) {
267 int rc = asc_to_bcd(input[i]);
268 if (rc < 0)
269 return rc;
270 if (i % 2 == 0)
271 *bcd_cur = rc;
272 else
273 *bcd_cur++ |= (rc << 4);
274 }
275 /* append padding nibble in case of odd length */
276 if (i % 2)
277 *bcd_cur++ |= 0xf0;
278
279 /* return how many bytes we used */
280 return (bcd_cur - bcd_lv);
281}
282
Holger Freyther819dd202009-01-04 03:52:50 +0000283struct msgb *gsm48_msgb_alloc(void)
Harald Welte8470bf22008-12-25 23:28:35 +0000284{
285 return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
286}
287
Holger Freyther3e2c3232009-01-04 03:55:31 +0000288int gsm48_sendmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000289{
Harald Welte65e74cc2008-12-29 01:55:35 +0000290 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
291
292 if (msg->lchan) {
Harald Welte8470bf22008-12-25 23:28:35 +0000293 msg->trx = msg->lchan->ts->trx;
Harald Welte52b1f982008-12-23 20:25:15 +0000294
Harald Welte65e74cc2008-12-29 01:55:35 +0000295 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) {
296 /* Send a 04.08 call control message, add transaction
297 * ID and TI flag */
298 gh->proto_discr |= msg->lchan->call.transaction_id;
299
300 /* GSM 04.07 Section 11.2.3.1.3 */
301 switch (msg->lchan->call.type) {
302 case GSM_CT_MO:
303 gh->proto_discr |= 0x80;
304 break;
305 case GSM_CT_MT:
306 break;
Holger Freytherca362a62009-01-04 21:05:01 +0000307 case GSM_CT_NONE:
308 break;
Harald Welte65e74cc2008-12-29 01:55:35 +0000309 }
310 }
311 }
312
Harald Welte4b634542008-12-27 01:55:51 +0000313 msg->l3h = msg->data;
314
Harald Welte8470bf22008-12-25 23:28:35 +0000315 return rsl_data_request(msg, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000316}
317
Harald Welte52b1f982008-12-23 20:25:15 +0000318
Holger Freyther429e7762008-12-30 13:28:30 +0000319/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Harald Welte8470bf22008-12-25 23:28:35 +0000320int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000321{
Harald Welte8470bf22008-12-25 23:28:35 +0000322 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000323 struct gsm48_hdr *gh;
324
Harald Welte8470bf22008-12-25 23:28:35 +0000325 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000326
327 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
328 gh->proto_discr = GSM48_PDISC_MM;
Harald Welte10b487b2008-12-27 19:53:37 +0000329 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
Harald Welte52b1f982008-12-23 20:25:15 +0000330 gh->data[0] = cause;
331
Harald Weltedb253af2008-12-30 17:56:55 +0000332 DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr);
333
Harald Welte65e74cc2008-12-29 01:55:35 +0000334 return gsm48_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000335}
336
337/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Harald Welte75a983f2008-12-27 21:34:06 +0000338int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000339{
Harald Welte8470bf22008-12-25 23:28:35 +0000340 struct gsm_bts *bts = lchan->ts->trx->bts;
341 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000342 struct gsm48_hdr *gh;
343 struct gsm48_loc_area_id *lai;
344 u_int8_t *mid;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000345 int ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000346
Harald Welte8470bf22008-12-25 23:28:35 +0000347 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000348
349 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
350 gh->proto_discr = GSM48_PDISC_MM;
351 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
352
353 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Holger Freyther17746612008-12-28 16:32:44 +0000354 gsm0408_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000355 bts->network->network_code, bts->location_area_code);
356
357 mid = msgb_put(msg, MID_TMSI_LEN);
358 generate_mid_from_tmsi(mid, tmsi);
359
360 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
361
Harald Weltedb253af2008-12-30 17:56:55 +0000362 ret = gsm48_sendmsg(msg);
363
Harald Welte09e38af2009-02-16 22:52:23 +0000364 //ret = gsm48_cc_tx_setup(lchan);
Harald Weltedb253af2008-12-30 17:56:55 +0000365 ret = gsm48_tx_mm_info(lchan);
Harald Weltedb253af2008-12-30 17:56:55 +0000366
Holger Freyther07cc8d82008-12-29 06:23:46 +0000367 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000368}
369
Harald Weltefc977a82008-12-27 10:19:37 +0000370static char bcd2char(u_int8_t bcd)
371{
372 if (bcd < 0xa)
373 return '0' + bcd;
374 else
375 return 'A' + (bcd - 0xa);
376}
377
Harald Weltebf5e8df2009-02-03 12:59:45 +0000378/* Convert Mobile Identity (10.5.1.4) to string */
Harald Weltefc977a82008-12-27 10:19:37 +0000379static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len)
380{
381 int i;
382 u_int8_t mi_type;
383 char *str_cur = string;
Harald Welte4ed0e922009-01-10 03:17:30 +0000384 u_int32_t tmsi;
Harald Weltefc977a82008-12-27 10:19:37 +0000385
386 mi_type = mi[0] & GSM_MI_TYPE_MASK;
387
388 switch (mi_type) {
389 case GSM_MI_TYPE_NONE:
390 break;
391 case GSM_MI_TYPE_TMSI:
Harald Welte4ed0e922009-01-10 03:17:30 +0000392 /* Table 10.5.4.3, reverse generate_mid_from_tmsi */
393 if (mi_len == TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
394 memcpy(&tmsi, &mi[1], 4);
395 tmsi = ntohl(tmsi);
396 return snprintf(string, str_len, "%u", tmsi);
Harald Weltefc977a82008-12-27 10:19:37 +0000397 }
398 break;
399 case GSM_MI_TYPE_IMSI:
400 case GSM_MI_TYPE_IMEI:
401 case GSM_MI_TYPE_IMEISV:
Harald Weltedb253af2008-12-30 17:56:55 +0000402 *str_cur++ = bcd2char(mi[0] >> 4);
403
404 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000405 if (str_cur + 2 >= string + str_len)
406 return str_cur - string;
407 *str_cur++ = bcd2char(mi[i] & 0xf);
Harald Weltedb253af2008-12-30 17:56:55 +0000408 /* skip last nibble in last input byte when GSM_EVEN */
409 if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD))
410 *str_cur++ = bcd2char(mi[i] >> 4);
Harald Weltefc977a82008-12-27 10:19:37 +0000411 }
412 break;
413 default:
414 break;
415 }
Harald Weltefc977a82008-12-27 10:19:37 +0000416 *str_cur++ = '\0';
Harald Weltedb253af2008-12-30 17:56:55 +0000417
Harald Weltefc977a82008-12-27 10:19:37 +0000418 return str_cur - string;
419}
420
Harald Weltebf5e8df2009-02-03 12:59:45 +0000421/* Transmit Chapter 9.2.10 Identity Request */
Harald Welte231ad4f2008-12-27 11:15:38 +0000422static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
423{
424 struct msgb *msg = gsm48_msgb_alloc();
425 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000426
Harald Welte231ad4f2008-12-27 11:15:38 +0000427 msg->lchan = lchan;
428
429 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
430 gh->proto_discr = GSM48_PDISC_MM;
431 gh->msg_type = GSM48_MT_MM_ID_REQ;
432 gh->data[0] = id_type;
433
Harald Welte65e74cc2008-12-29 01:55:35 +0000434 return gsm48_sendmsg(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000435}
436
437#define MI_SIZE 32
438
Harald Weltebf5e8df2009-02-03 12:59:45 +0000439/* Parse Chapter 9.2.11 Identity Response */
Harald Welte231ad4f2008-12-27 11:15:38 +0000440static int mm_rx_id_resp(struct msgb *msg)
441{
442 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000443 struct gsm_lchan *lchan = msg->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000444 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
445 char mi_string[MI_SIZE];
Harald Welte75a983f2008-12-27 21:34:06 +0000446 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000447
448 mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000449 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000450 mi_type, mi_string);
451
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000452 /*
453 * Rogue messages could trick us but so is life
454 */
455 put_lchan(lchan);
456
Harald Welte75a983f2008-12-27 21:34:06 +0000457 switch (mi_type) {
458 case GSM_MI_TYPE_IMSI:
459 if (!lchan->subscr)
460 lchan->subscr = db_create_subscriber(mi_string);
Holger Freyther73487a22008-12-31 18:53:57 +0000461 if (lchan->loc_operation)
462 lchan->loc_operation->waiting_for_imsi = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000463 break;
464 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000465 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000466 /* update subscribe <-> IMEI mapping */
467 if (lchan->subscr)
468 db_subscriber_assoc_imei(lchan->subscr, mi_string);
Holger Freyther73487a22008-12-31 18:53:57 +0000469 if (lchan->loc_operation)
470 lchan->loc_operation->waiting_for_imei = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000471 break;
472 }
Holger Freyther73487a22008-12-31 18:53:57 +0000473
474 /* Check if we can let the mobile station enter */
475 if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) {
476 db_subscriber_alloc_tmsi(lchan->subscr);
477 tmsi = strtoul(lchan->subscr->tmsi, NULL, 10);
478 release_loc_updating_req(lchan);
479 return gsm0408_loc_upd_acc(msg->lchan, tmsi);
480 }
481
Harald Welte75a983f2008-12-27 21:34:06 +0000482 return 0;
Harald Welte231ad4f2008-12-27 11:15:38 +0000483}
484
Harald Welte255539c2008-12-28 02:26:27 +0000485
486static void loc_upd_rej_cb(void *data)
487{
488 struct gsm_lchan *lchan = data;
489
Holger Freyther73487a22008-12-31 18:53:57 +0000490 release_loc_updating_req(lchan);
Holger Freythere97f7fb2008-12-31 18:52:11 +0000491 gsm0408_loc_upd_rej(lchan, reject_cause);
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000492 lchan_auto_release(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000493}
494
Holger Freytherb7193e42008-12-29 17:44:08 +0000495static void schedule_reject(struct gsm_lchan *lchan)
496{
Holger Freyther73487a22008-12-31 18:53:57 +0000497 lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb;
498 lchan->loc_operation->updating_timer.data = lchan;
499 schedule_timer(&lchan->loc_operation->updating_timer, 5, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000500}
501
Harald Welte231ad4f2008-12-27 11:15:38 +0000502#define MI_SIZE 32
Harald Weltebf5e8df2009-02-03 12:59:45 +0000503/* Chapter 9.2.15: Receive Location Updating Request */
Harald Welte231ad4f2008-12-27 11:15:38 +0000504static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000505{
Harald Welte8470bf22008-12-25 23:28:35 +0000506 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000507 struct gsm_bts *bts = msg->trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000508 struct gsm48_loc_upd_req *lu;
509 struct gsm_subscriber *subscr;
Harald Welte255539c2008-12-28 02:26:27 +0000510 struct gsm_lchan *lchan = msg->lchan;
Harald Welte8470bf22008-12-25 23:28:35 +0000511 u_int8_t mi_type;
Harald Welte75a983f2008-12-27 21:34:06 +0000512 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000513 char mi_string[MI_SIZE];
514 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000515
Harald Welte8470bf22008-12-25 23:28:35 +0000516 lu = (struct gsm48_loc_upd_req *) gh->data;
517
518 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000519
Harald Weltefc977a82008-12-27 10:19:37 +0000520 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
521
Harald Welte231ad4f2008-12-27 11:15:38 +0000522 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string);
Holger Freyther73487a22008-12-31 18:53:57 +0000523
524 allocate_loc_updating_req(lchan);
525
Harald Welte52b1f982008-12-23 20:25:15 +0000526 switch (mi_type) {
527 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000528 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000529 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000530 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freyther73487a22008-12-31 18:53:57 +0000531 lchan->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000532
Harald Welte52b1f982008-12-23 20:25:15 +0000533 /* look up subscriber based on IMSI */
Harald Welte75a983f2008-12-27 21:34:06 +0000534 subscr = db_create_subscriber(mi_string);
Harald Welte4b634542008-12-27 01:55:51 +0000535 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000536 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000537 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000538 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000539 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freyther73487a22008-12-31 18:53:57 +0000540 lchan->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000541
Harald Welte52b1f982008-12-23 20:25:15 +0000542 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Welteba4cf162009-01-10 01:49:35 +0000543 subscr = subscr_get_by_tmsi(mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000544 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000545 /* send IDENTITY REQUEST message to get IMSI */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000546 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000547 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Holger Freyther73487a22008-12-31 18:53:57 +0000548 lchan->loc_operation->waiting_for_imsi = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000549 }
550 break;
551 case GSM_MI_TYPE_IMEI:
552 case GSM_MI_TYPE_IMEISV:
553 /* no sim card... FIXME: what to do ? */
554 fprintf(stderr, "Unimplemented mobile identity type\n");
555 break;
556 default:
557 fprintf(stderr, "Unknown mobile identity type\n");
558 break;
559 }
560
Harald Welte255539c2008-12-28 02:26:27 +0000561 lchan->subscr = subscr;
562
Holger Freyther73487a22008-12-31 18:53:57 +0000563 /*
564 * Schedule the reject timer and check if we can let the
565 * subscriber into our network immediately or if we need to wait
566 * for identity responses.
567 */
568 schedule_reject(lchan);
569 if (!authorize_subscriber(lchan->loc_operation, subscr))
Harald Weltee872cb12009-01-01 00:33:37 +0000570 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000571
Harald Welte75a983f2008-12-27 21:34:06 +0000572 db_subscriber_alloc_tmsi(subscr);
Harald Welte52b1f982008-12-23 20:25:15 +0000573 subscr_update(subscr, bts);
Harald Welte8470bf22008-12-25 23:28:35 +0000574
Harald Welte255539c2008-12-28 02:26:27 +0000575 tmsi = strtoul(subscr->tmsi, NULL, 10);
576
Holger Freyther73487a22008-12-31 18:53:57 +0000577 release_loc_updating_req(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000578 return gsm0408_loc_upd_acc(lchan, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000579}
580
Harald Welte7584aea2009-02-11 11:44:12 +0000581/* 9.1.5 Channel mode modify */
582int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode)
583{
584 struct msgb *msg = gsm48_msgb_alloc();
585 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
586 struct gsm48_chan_mode_modify *cmm =
587 (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm));
588 u_int16_t arfcn = lchan->ts->trx->arfcn;
589
590 msg->lchan = lchan;
591 gh->proto_discr = GSM48_PDISC_RR;
592 gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF;
593
594 /* fill the channel information element, this code
595 * should probably be shared with rsl_rx_chan_rqd() */
596 cmm->chan_desc.chan_nr = lchan2chan_nr(lchan);
597 cmm->chan_desc.h0.h = 0;
598 cmm->chan_desc.h0.arfcn_high = arfcn >> 8;
599 cmm->chan_desc.h0.arfcn_low = arfcn & 0xff;
600 cmm->mode = mode;
601
602 return gsm48_sendmsg(msg);
603}
604
Harald Weltedb253af2008-12-30 17:56:55 +0000605/* Section 9.2.15a */
606int gsm48_tx_mm_info(struct gsm_lchan *lchan)
607{
608 struct msgb *msg = gsm48_msgb_alloc();
609 struct gsm48_hdr *gh;
610 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Weltedb253af2008-12-30 17:56:55 +0000611 u_int8_t *ptr8;
612 u_int16_t *ptr16;
613 int name_len;
Harald Weltedb253af2008-12-30 17:56:55 +0000614 int i;
615
616 msg->lchan = lchan;
617
618 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
619 gh->proto_discr = GSM48_PDISC_MM;
620 gh->msg_type = GSM48_MT_MM_INFO;
621
622 if (net->name_long) {
623 name_len = strlen(net->name_long);
624 /* 10.5.3.5a */
625 ptr8 = msgb_put(msg, 3);
626 ptr8[0] = GSM48_IE_NAME_LONG;
627 ptr8[1] = name_len*2 +1;
628 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
629
630 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
631 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000632 ptr16[i] = htons(net->name_long[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000633
634 /* FIXME: Use Cell Broadcast, not UCS-2, since
635 * UCS-2 is only supported by later revisions of the spec */
636 }
637
638 if (net->name_short) {
639 name_len = strlen(net->name_short);
640 /* 10.5.3.5a */
641 ptr8 = (u_int8_t *) msgb_put(msg, 3);
642 ptr8[0] = GSM48_IE_NAME_LONG;
643 ptr8[1] = name_len*2 + 1;
644 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
645
Harald Weltee872cb12009-01-01 00:33:37 +0000646 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
Harald Weltedb253af2008-12-30 17:56:55 +0000647 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000648 ptr16[i] = htons(net->name_short[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000649 }
650
651#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000652 /* move back to the top */
653 time_t cur_t;
654 struct tm* cur_time;
655 int tz15min;
Harald Weltedb253af2008-12-30 17:56:55 +0000656 /* Section 10.5.3.9 */
657 cur_t = time(NULL);
658 cur_time = gmtime(cur_t);
659 ptr8 = msgb_put(msg, 8);
660 ptr8[0] = GSM48_IE_NET_TIME_TZ;
661 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
662 ptr8[2] = to_bcd8(cur_time->tm_mon);
663 ptr8[3] = to_bcd8(cur_time->tm_mday);
664 ptr8[4] = to_bcd8(cur_time->tm_hour);
665 ptr8[5] = to_bcd8(cur_time->tm_min);
666 ptr8[6] = to_bcd8(cur_time->tm_sec);
667 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
668 tz15min = (cur_time->tm_gmtoff)/(60*15);
669 ptr8[6] = to_bcd8(tz15min);
670 if (tz15min < 0)
671 ptr8[6] |= 0x80;
672#endif
673
674 return gsm48_sendmsg(msg);
675}
676
Harald Welte4b634542008-12-27 01:55:51 +0000677static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
678{
Harald Welte4b634542008-12-27 01:55:51 +0000679 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Harald Welte65e74cc2008-12-29 01:55:35 +0000680 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000681}
Harald Welteba4cf162009-01-10 01:49:35 +0000682
683/* 9.2.6 CM service reject */
684static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan,
685 enum gsm48_reject_value value)
686{
687 struct msgb *msg = gsm48_msgb_alloc();
688 struct gsm48_hdr *gh;
689
690 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
691
692 msg->lchan = lchan;
693 use_lchan(lchan);
694
695 gh->proto_discr = GSM48_PDISC_MM;
696 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
697 gh->data[0] = value;
698 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
699
700 return gsm48_sendmsg(msg);
701}
702
Harald Welte4ed0e922009-01-10 03:17:30 +0000703
704/*
705 * Handle CM Service Requests
706 * a) Verify that the packet is long enough to contain the information
707 * we require otherwsie reject with INCORRECT_MESSAGE
708 * b) Try to parse the TMSI. If we do not have one reject
709 * c) Check that we know the subscriber with the TMSI otherwise reject
710 * with a HLR cause
711 * d) Set the subscriber on the gsm_lchan and accept
712 */
Harald Welte4b634542008-12-27 01:55:51 +0000713static int gsm48_rx_mm_serv_req(struct msgb *msg)
714{
Harald Welteba4cf162009-01-10 01:49:35 +0000715 u_int8_t mi_type;
Harald Welte4ed0e922009-01-10 03:17:30 +0000716 char mi_string[MI_SIZE];
Harald Welte4b634542008-12-27 01:55:51 +0000717
Harald Welteba4cf162009-01-10 01:49:35 +0000718 struct gsm_subscriber *subscr;
719 struct gsm48_hdr *gh = msgb_l3(msg);
720 struct gsm48_service_request *req =
721 (struct gsm48_service_request *)gh->data;
722
723 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
724 DEBUGP(DMM, "<- CM SERVICE REQUEST wrong sized message\n");
725 return gsm48_tx_mm_serv_rej(msg->lchan,
726 GSM48_REJECT_INCORRECT_MESSAGE);
727 }
728
729 if (msg->data_len < req->mi_len + 6) {
730 DEBUGP(DMM, "<- CM SERVICE REQUEST MI does not fit in package\n");
731 return gsm48_tx_mm_serv_rej(msg->lchan,
732 GSM48_REJECT_INCORRECT_MESSAGE);
733 }
734
735 mi_type = req->mi[0] & GSM_MI_TYPE_MASK;
736 if (mi_type != GSM_MI_TYPE_TMSI) {
737 DEBUGP(DMM, "<- CM SERVICE REQUEST mi type is not TMSI: %d\n", mi_type);
738 return gsm48_tx_mm_serv_rej(msg->lchan,
739 GSM48_REJECT_INCORRECT_MESSAGE);
740 }
741
Harald Welte4ed0e922009-01-10 03:17:30 +0000742 mi_to_string(mi_string, sizeof(mi_string), req->mi, req->mi_len);
743 subscr = subscr_get_by_tmsi(mi_string);
744 DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x mi_type=0x%02x M(%s)\n",
745 req->cm_service_type, mi_type, mi_string);
Harald Weltebcae43f2008-12-27 21:45:37 +0000746
Harald Welte4ed0e922009-01-10 03:17:30 +0000747 if (!subscr)
748 return gsm48_tx_mm_serv_rej(msg->lchan,
749 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
750
751 if (!msg->lchan->subscr)
752 msg->lchan->subscr = subscr;
Harald Welte9bb7c702009-01-10 03:21:41 +0000753 else if (msg->lchan->subscr != subscr) {
754 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
755 subscr_put(subscr);
756 }
757
Harald Welte4b634542008-12-27 01:55:51 +0000758 return gsm48_tx_mm_serv_ack(msg->lchan);
759}
760
Harald Weltebf5e8df2009-02-03 12:59:45 +0000761/* Receive a GSM 04.08 Mobility Management (MM) message */
Harald Welte52b1f982008-12-23 20:25:15 +0000762static int gsm0408_rcv_mm(struct msgb *msg)
763{
764 struct gsm48_hdr *gh = msgb_l3(msg);
765 int rc;
766
767 switch (gh->msg_type & 0xbf) {
768 case GSM48_MT_MM_LOC_UPD_REQUEST:
Holger Freyther429e7762008-12-30 13:28:30 +0000769 DEBUGP(DMM, "LOCATION UPDATING REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000770 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000771 break;
772 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000773 rc = mm_rx_id_resp(msg);
774 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000775 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000776 rc = gsm48_rx_mm_serv_req(msg);
777 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000778 case GSM48_MT_MM_STATUS:
779 DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n");
780 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000781 case GSM48_MT_MM_TMSI_REALL_COMPL:
Harald Welte69b2af22009-01-06 19:47:00 +0000782 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
783 msg->lchan->subscr ?
784 msg->lchan->subscr->imsi :
785 "unknown subscriber");
786 break;
787 case GSM48_MT_MM_CM_REEST_REQ:
Harald Welte231ad4f2008-12-27 11:15:38 +0000788 case GSM48_MT_MM_AUTH_RESP:
789 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte52b1f982008-12-23 20:25:15 +0000790 fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n",
791 gh->msg_type);
792 break;
793 default:
794 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
795 gh->msg_type);
796 break;
797 }
798
799 return rc;
800}
Harald Weltebf5e8df2009-02-03 12:59:45 +0000801
Harald Welte2d35ae62009-02-06 12:02:13 +0000802/* Receive a PAGING RESPONSE message from the MS */
803static int gsm48_rr_rx_pag_resp(struct msgb *msg)
804{
805 struct gsm48_hdr *gh = msgb_l3(msg);
806 struct gsm48_paging_response *pr =
807 (struct gsm48_paging_response *) gh->data;
808 u_int8_t mi_type = pr->mi[0] & GSM_MI_TYPE_MASK;
809 char mi_string[MI_SIZE];
810 struct gsm_subscriber *subscr;
Harald Welte595ad7b2009-02-16 22:05:44 +0000811 struct paging_signal_data sig_data;
Harald Welte2d35ae62009-02-06 12:02:13 +0000812 int rc = 0;
813
814 mi_to_string(mi_string, sizeof(mi_string), &pr->mi[0], pr->mi_len);
815 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
816 mi_type, mi_string);
817 subscr = subscr_get_by_tmsi(mi_string);
818
819 if (!subscr) {
820 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte09e38af2009-02-16 22:52:23 +0000821 /* FIXME: request id? close channel? */
Harald Welte2d35ae62009-02-06 12:02:13 +0000822 return -EINVAL;
823 }
824 DEBUGP(DRR, "<- Channel was requested by %s\n",
825 subscr->name ? subscr->name : subscr->imsi);
Holger Freyther053e09d2009-02-14 22:51:06 +0000826
Holger Freyther2fa4cb52009-02-14 23:53:15 +0000827 if (!msg->lchan->subscr)
828 msg->lchan->subscr = subscr;
829 else if (msg->lchan->subscr != subscr) {
830 DEBUGP(DRR, "<- Channel already owned by someone else?\n");
831 subscr_put(subscr);
832 }
833
Harald Welte595ad7b2009-02-16 22:05:44 +0000834 sig_data.subscr = subscr;
835 sig_data.bts = msg->lchan->ts->trx->bts;
836 sig_data.lchan = msg->lchan;
837
838 dispatch_signal(SS_PAGING, S_PAGING_COMPLETED, &sig_data);
Holger Freyther1fd34142009-02-09 23:42:03 +0000839 paging_request_stop(msg->trx->bts, subscr);
Harald Welte2d35ae62009-02-06 12:02:13 +0000840
Harald Welte7584aea2009-02-11 11:44:12 +0000841 /* FIXME: somehow signal the completion of the PAGING to
842 * the entity that requested the paging */
843
Harald Welte2d35ae62009-02-06 12:02:13 +0000844 return rc;
845}
846
Harald Weltebf5e8df2009-02-03 12:59:45 +0000847/* Receive a GSM 04.08 Radio Resource (RR) message */
Harald Welte52b1f982008-12-23 20:25:15 +0000848static int gsm0408_rcv_rr(struct msgb *msg)
849{
850 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte2d35ae62009-02-06 12:02:13 +0000851 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000852
853 switch (gh->msg_type) {
854 case GSM48_MT_RR_CLSM_CHG:
855 DEBUGP(DRR, "CLASSMARK CHANGE\n");
856 /* FIXME: what to do ?!? */
857 break;
Harald Weltefc977a82008-12-27 10:19:37 +0000858 case GSM48_MT_RR_GPRS_SUSP_REQ:
859 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
860 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000861 case GSM48_MT_RR_PAG_RESP:
Harald Welte2d35ae62009-02-06 12:02:13 +0000862 rc = gsm48_rr_rx_pag_resp(msg);
863 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000864 default:
Harald Welte2d35ae62009-02-06 12:02:13 +0000865 fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n",
Harald Welte52b1f982008-12-23 20:25:15 +0000866 gh->msg_type);
867 break;
868 }
869
Harald Welte2d35ae62009-02-06 12:02:13 +0000870 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000871}
872
Holger Freythere64a7a32009-02-06 21:55:37 +0000873/* 7.1.7 and 9.1.7 Channel release*/
874int gsm48_send_rr_release(struct gsm_lchan *lchan)
875{
876 struct msgb *msg = gsm48_msgb_alloc();
877 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
878 u_int8_t *cause;
879
880 msg->lchan = lchan;
881 gh->proto_discr = GSM48_PDISC_RR;
882 gh->msg_type = GSM48_MT_RR_CHAN_REL;
883
884 cause = msgb_put(msg, 1);
885 cause[0] = GSM48_RR_CAUSE_NORMAL;
886
887 DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n",
888 lchan->nr, lchan->type);
889
890 return gsm48_sendmsg(msg);
891}
892
Harald Welte4bc90a12008-12-27 16:32:52 +0000893/* Call Control */
894
Harald Welte7584aea2009-02-11 11:44:12 +0000895/* The entire call control code is written in accordance with Figure 7.10c
896 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
897 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
898 * it for voice */
899
Harald Welte4bc90a12008-12-27 16:32:52 +0000900static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
901{
902 struct msgb *msg = gsm48_msgb_alloc();
903 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
904 u_int8_t *cause, *call_state;
905
Harald Welte65e74cc2008-12-29 01:55:35 +0000906 gh->proto_discr = GSM48_PDISC_CC;
907
Harald Welte4bc90a12008-12-27 16:32:52 +0000908 msg->lchan = lchan;
909
Harald Welte4bc90a12008-12-27 16:32:52 +0000910 gh->msg_type = GSM48_MT_CC_STATUS;
911
912 cause = msgb_put(msg, 3);
913 cause[0] = 2;
914 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
915 cause[2] = 0x80 | 30; /* response to status inquiry */
916
917 call_state = msgb_put(msg, 1);
918 call_state[0] = 0xc0 | 0x00;
919
Harald Welte65e74cc2008-12-29 01:55:35 +0000920 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000921}
922
Harald Welte6f4b7532008-12-29 00:39:37 +0000923static int gsm48_tx_simple(struct gsm_lchan *lchan,
924 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +0000925{
926 struct msgb *msg = gsm48_msgb_alloc();
927 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
928
929 msg->lchan = lchan;
930
Harald Welte6f4b7532008-12-29 00:39:37 +0000931 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +0000932 gh->msg_type = msg_type;
933
Harald Welte65e74cc2008-12-29 01:55:35 +0000934 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000935}
936
Harald Welte09e38af2009-02-16 22:52:23 +0000937/* call-back from paging the B-end of the connection */
938static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
939 struct msgb *msg, void *data, void *param)
940{
941 struct gsm_call *call = param;
942
943 if (hooknum != GSM_HOOK_RR_PAGING)
944 return -EINVAL;
945
946 switch (event) {
947 case GSM_PAGING_SUCCEEDED:
948 /* send SETUP request to called party */
949 //gsm48_cc_tx_setup(lchan, call->subscr);
950 break;
951 case GSM_PAGING_EXPIRED:
952 /* notify caller that we cannot reach called party */
953 break;
954 }
955}
956
Harald Welte4bc90a12008-12-27 16:32:52 +0000957static int gsm48_cc_rx_status_enq(struct msgb *msg)
958{
959 return gsm48_cc_tx_status(msg->lchan);
960}
961
962static int gsm48_cc_rx_setup(struct msgb *msg)
963{
Harald Welte7584aea2009-02-11 11:44:12 +0000964 struct gsm_call *call = &msg->lchan->call;
965 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte09e38af2009-02-16 22:52:23 +0000966 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
Harald Welte7584aea2009-02-11 11:44:12 +0000967 struct gsm_subscriber *called_subscr;
Harald Welte09e38af2009-02-16 22:52:23 +0000968 char called_number[(43-2)*2 + 1] = "\0";
969 struct tlv_parsed tp;
970 u_int8_t num_type;
Harald Welte7584aea2009-02-11 11:44:12 +0000971 int ret;
972
973 if (call->state == GSM_CSTATE_NULL ||
974 call->state == GSM_CSTATE_RELEASE_REQ)
975 use_lchan(msg->lchan);
976
977 call->type = GSM_CT_MO;
978 call->state = GSM_CSTATE_INITIATED;
979 call->transaction_id = gh->proto_discr & 0xf0;
980
981 DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id);
982
Harald Welte09e38af2009-02-16 22:52:23 +0000983 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len);
984 if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD))
985 goto err;
Harald Welte7584aea2009-02-11 11:44:12 +0000986
Harald Welte09e38af2009-02-16 22:52:23 +0000987 /* Parse the number that was dialed and lookup subscriber */
988 num_type = decode_bcd_number(called_number, sizeof(called_number),
989 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
990 called_subscr = subscr_get_by_extension(called_number);
Harald Welte7584aea2009-02-11 11:44:12 +0000991 if (!called_subscr) {
992 DEBUGP(DCC, "could not find subscriber, RELEASE\n");
993 put_lchan(msg->lchan);
994 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
995 GSM48_MT_CC_RELEASE_COMPL);
996 }
997
Harald Welte09e38af2009-02-16 22:52:23 +0000998 subscr_get(msg->lchan->subscr);
999 call->subscr = msg->lchan->subscr;
1000 call->called_subscr = called_subscr;
1001
Harald Welte7584aea2009-02-11 11:44:12 +00001002 /* start paging of the receiving end of the call */
Harald Welte09e38af2009-02-16 22:52:23 +00001003 paging_request(msg->trx->bts, called_subscr, RSL_CHANNEED_TCH_F,
1004 setup_trig_pag_evt, call);
Harald Welte7584aea2009-02-11 11:44:12 +00001005
1006 /* send a CALL PROCEEDING message to the MO */
1007 ret = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1008 GSM48_MT_CC_CALL_PROC);
1009
1010 /* change TCH/F mode to voice */
1011 return gsm48_tx_chan_mode_modify(msg->lchan, 0x01);
Harald Welte09e38af2009-02-16 22:52:23 +00001012
1013err:
1014 /* FIXME: send some kind of RELEASE */
1015 return 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00001016}
Harald Welte7584aea2009-02-11 11:44:12 +00001017
1018static const u_int8_t calling_bcd[] = { 0xb9, 0x83, 0x32, 0x24 };
Harald Welte4bc90a12008-12-27 16:32:52 +00001019
Harald Welte09e38af2009-02-16 22:52:23 +00001020int gsm48_cc_tx_setup(struct gsm_lchan *lchan,
1021 struct gsm_subscriber *calling_subscriber)
Harald Welte65e74cc2008-12-29 01:55:35 +00001022{
1023 struct msgb *msg = gsm48_msgb_alloc();
1024 struct gsm48_hdr *gh;
1025 struct gsm_call *call = &lchan->call;
1026
Harald Welte7584aea2009-02-11 11:44:12 +00001027 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 4 +
1028 sizeof(calling_bcd));
Harald Welte65e74cc2008-12-29 01:55:35 +00001029
1030 call->type = GSM_CT_MT;
1031 msg->lchan = lchan;
Harald Welte498b0bb2009-01-09 21:27:43 +00001032 use_lchan(lchan);
Harald Welte65e74cc2008-12-29 01:55:35 +00001033
1034 gh->proto_discr = GSM48_PDISC_CC;
1035 gh->msg_type = GSM48_MT_CC_SETUP;
Harald Welte09e38af2009-02-16 22:52:23 +00001036
1037 /* FIXME: use actual number of the caller */
Harald Welte7584aea2009-02-11 11:44:12 +00001038 msgb_tv_put(msg, GSM48_IE_SIGNAL, GSM48_SIGNAL_DIALTONE);
1039 msgb_tlv_put(msg, GSM48_IE_CALLING_BCD,
1040 sizeof(calling_bcd), calling_bcd);
Harald Welte65e74cc2008-12-29 01:55:35 +00001041
1042 DEBUGP(DCC, "Sending SETUP\n");
1043
1044 return gsm48_sendmsg(msg);
1045}
1046
Harald Welte4bc90a12008-12-27 16:32:52 +00001047static int gsm0408_rcv_cc(struct msgb *msg)
1048{
1049 struct gsm48_hdr *gh = msgb_l3(msg);
1050 u_int8_t msg_type = gh->msg_type & 0xbf;
1051 struct gsm_call *call = &msg->lchan->call;
1052 int rc = 0;
1053
1054 switch (msg_type) {
1055 case GSM48_MT_CC_CALL_CONF:
1056 /* Response to SETUP */
1057 DEBUGP(DCC, "CALL CONFIRM\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001058 /* FIXME: we now need to MODIFY the channel */
Harald Welte4bc90a12008-12-27 16:32:52 +00001059 break;
1060 case GSM48_MT_CC_RELEASE_COMPL:
1061 /* Answer from MS to RELEASE */
1062 DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n");
1063 call->state = GSM_CSTATE_NULL;
1064 break;
1065 case GSM48_MT_CC_ALERTING:
1066 DEBUGP(DCC, "ALERTING\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001067 /* FIXME: forward ALERTING to other party */
Harald Welte4bc90a12008-12-27 16:32:52 +00001068 break;
1069 case GSM48_MT_CC_CONNECT:
1070 DEBUGP(DCC, "CONNECT\n");
1071 /* MT: need to respond with CONNECT_ACK */
Harald Welte6f4b7532008-12-29 00:39:37 +00001072 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1073 GSM48_MT_CC_CONNECT_ACK);
Harald Welte4bc90a12008-12-27 16:32:52 +00001074 break;
1075 case GSM48_MT_CC_CONNECT_ACK:
1076 /* MO: Answer to CONNECT */
1077 call->state = GSM_CSTATE_ACTIVE;
1078 DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n");
1079 break;
1080 case GSM48_MT_CC_RELEASE:
1081 DEBUGP(DCC, "RELEASE\n");
1082 /* need to respond with RELEASE_COMPLETE */
1083 break;
1084 case GSM48_MT_CC_STATUS_ENQ:
1085 rc = gsm48_cc_rx_status_enq(msg);
1086 break;
1087 case GSM48_MT_CC_DISCONNECT:
1088 /* Section 5.4.3.2 */
1089 DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n");
1090 call->state = GSM_CSTATE_RELEASE_REQ;
Harald Welte498b0bb2009-01-09 21:27:43 +00001091 if (call->state != GSM_CSTATE_NULL)
1092 put_lchan(msg->lchan);
Harald Welte4bc90a12008-12-27 16:32:52 +00001093 /* FIXME: clear the network connection */
Harald Welte6f4b7532008-12-29 00:39:37 +00001094 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1095 GSM48_MT_CC_RELEASE);
Harald Welte4bc90a12008-12-27 16:32:52 +00001096 break;
1097 case GSM48_MT_CC_SETUP:
Harald Welte7584aea2009-02-11 11:44:12 +00001098 rc = gsm48_cc_rx_setup(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001099 break;
1100 case GSM48_MT_CC_EMERG_SETUP:
1101 DEBUGP(DCC, "EMERGENCY SETUP\n");
1102 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
1103 break;
1104 default:
Harald Welte2d35ae62009-02-06 12:02:13 +00001105 fprintf(stderr, "Unimplemented GSM 04.08 CC msg type 0x%02x\n",
Harald Welte4bc90a12008-12-27 16:32:52 +00001106 msg_type);
1107 break;
1108 }
1109
1110 return rc;
1111}
1112
Harald Welte52b1f982008-12-23 20:25:15 +00001113/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
1114int gsm0408_rcvmsg(struct msgb *msg)
1115{
1116 struct gsm48_hdr *gh = msgb_l3(msg);
1117 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +00001118 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001119
1120 switch (pdisc) {
1121 case GSM48_PDISC_CC:
1122 rc = gsm0408_rcv_cc(msg);
1123 break;
1124 case GSM48_PDISC_MM:
1125 rc = gsm0408_rcv_mm(msg);
1126 break;
1127 case GSM48_PDISC_RR:
1128 rc = gsm0408_rcv_rr(msg);
1129 break;
Harald Weltebcae43f2008-12-27 21:45:37 +00001130 case GSM48_PDISC_SMS:
Daniel Willmann8b3390e2008-12-28 00:31:09 +00001131 rc = gsm0411_rcv_sms(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +00001132 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001133 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +00001134 case GSM48_PDISC_SM_GPRS:
Harald Welte52b1f982008-12-23 20:25:15 +00001135 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
1136 pdisc);
1137 break;
1138 default:
1139 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
1140 pdisc);
1141 break;
1142 }
1143
1144 return rc;
1145}
Harald Welte8470bf22008-12-25 23:28:35 +00001146
1147enum chreq_type {
1148 CHREQ_T_EMERG_CALL,
1149 CHREQ_T_CALL_REEST_TCH_F,
1150 CHREQ_T_CALL_REEST_TCH_H,
1151 CHREQ_T_CALL_REEST_TCH_H_DBL,
1152 CHREQ_T_SDCCH,
1153 CHREQ_T_TCH_F,
1154 CHREQ_T_VOICE_CALL_TCH_H,
1155 CHREQ_T_DATA_CALL_TCH_H,
1156 CHREQ_T_LOCATION_UPD,
1157 CHREQ_T_PAG_R_ANY,
1158 CHREQ_T_PAG_R_TCH_F,
1159 CHREQ_T_PAG_R_TCH_FH,
1160};
1161
1162/* Section 9.1.8 / Table 9.9 */
1163struct chreq {
1164 u_int8_t val;
1165 u_int8_t mask;
1166 enum chreq_type type;
1167};
1168
1169/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
1170static const struct chreq chreq_type_neci1[] = {
1171 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
1172 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
1173 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
1174 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
1175 { 0xe0, 0xe0, CHREQ_T_SDCCH },
1176 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
1177 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
1178 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
1179 { 0x10, 0xf0, CHREQ_T_SDCCH },
1180 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
1181 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
1182 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
1183};
1184
1185/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
1186static const struct chreq chreq_type_neci0[] = {
1187 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
1188 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
1189 { 0xe0, 0xe0, CHREQ_T_TCH_F },
1190 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
1191 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
1192 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
1193 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
1194 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
1195};
1196
1197static const enum gsm_chan_t ctype_by_chreq[] = {
1198 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
1199 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
1200 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
1201 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
1202 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
1203 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
1204 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
1205 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
1206 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
1207 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
1208 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
1209 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
1210};
1211
Harald Weltee14a57c2008-12-29 04:08:28 +00001212static const enum gsm_chreq_reason_t reason_by_chreq[] = {
1213 [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
1214 [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
1215 [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
1216 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
1217 [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
1218 [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
1219 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
1220 [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
1221 [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
1222 [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG,
1223 [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
1224 [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
1225};
1226
Harald Welte8470bf22008-12-25 23:28:35 +00001227enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
1228{
1229 int i;
1230 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
1231
1232 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
1233 const struct chreq *chr = &chreq_type_neci0[i];
1234 if ((ra & chr->mask) == chr->val)
1235 return ctype_by_chreq[chr->type];
1236 }
1237 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
1238 return GSM_LCHAN_SDCCH;
1239}
Harald Weltee14a57c2008-12-29 04:08:28 +00001240
1241enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra)
1242{
1243 int i;
1244 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
1245
1246 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
1247 const struct chreq *chr = &chreq_type_neci0[i];
1248 if ((ra & chr->mask) == chr->val)
1249 return reason_by_chreq[chr->type];
1250 }
1251 fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
1252 return GSM_CHREQ_REASON_OTHER;
1253}