blob: 1f4f4f015671cef348841810c02bc4422adebbe9 [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
4/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
Holger Freytherba4d28a2008-12-29 06:23:44 +00005 * (C) 2008 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>
35#include <openbsc/debug.h>
36#include <openbsc/gsm_data.h>
37#include <openbsc/gsm_subscriber.h>
Daniel Willmann8b3390e2008-12-28 00:31:09 +000038#include <openbsc/gsm_04_11.h>
Harald Welte8470bf22008-12-25 23:28:35 +000039#include <openbsc/gsm_04_08.h>
40#include <openbsc/abis_rsl.h>
Harald Welte52b1f982008-12-23 20:25:15 +000041
Harald Welte8470bf22008-12-25 23:28:35 +000042#define GSM48_ALLOC_SIZE 1024
43#define GSM48_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000044
Harald Welte65e74cc2008-12-29 01:55:35 +000045static int gsm48_tx_simple(struct gsm_lchan *lchan,
46 u_int8_t pdisc, u_int8_t msg_type);
Holger Freytherb7193e42008-12-29 17:44:08 +000047static void schedule_reject(struct gsm_lchan *lchan);
Harald Welte65e74cc2008-12-29 01:55:35 +000048
Harald Welte52b1f982008-12-23 20:25:15 +000049struct gsm_lai {
50 u_int16_t mcc;
51 u_int16_t mnc;
52 u_int16_t lac;
53};
54
Holger Freyther89824fc2008-12-30 16:18:18 +000055static int authorize_everonye = 0;
56void gsm0408_allow_everyone(int everyone)
57{
58 printf("Allowing everyone?\n");
59 authorize_everonye = everyone;
60}
61
62static int authorize_subscriber(struct gsm_subscriber *subscriber)
63{
64 if (!subscriber)
65 return 0;
66
67 if (authorize_everonye)
68 return 1;
69
70 return subscriber->authorized;
71}
Holger Freyther07cc8d82008-12-29 06:23:46 +000072
73
Harald Welte52b1f982008-12-23 20:25:15 +000074static void parse_lai(struct gsm_lai *lai, const struct gsm48_loc_area_id *lai48)
75{
76 u_int8_t dig[4];
77
78 /* MCC */
79 dig[1] = lai48->digits[0] & 0x0f;
80 dig[2] = lai48->digits[0] >> 4;
81 dig[3] = lai48->digits[1] & 0x0f;
82 lai->mcc = dig[3] * 100 + dig[2];
83
84 /* MNC */
85 dig[1] = lai48->digits[1] >> 4;
86 dig[2] = lai48->digits[2] & 0x0f;
87 dig[3] = lai48->digits[2] >> 4;
88 lai->mnc = dig[3] * 100 + dig[2];
89
90 lai->lac = lai48->lac;
91}
92
93static void to_bcd(u_int8_t *bcd, u_int16_t val)
94{
Harald Welte4b634542008-12-27 01:55:51 +000095 bcd[2] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +000096 val = val / 10;
97 bcd[1] = val % 10;
98 val = val / 10;
Harald Welte4b634542008-12-27 01:55:51 +000099 bcd[0] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000100 val = val / 10;
101}
102
Harald Weltedb253af2008-12-30 17:56:55 +0000103static u_int8_t to_bcd8(unsigned int val)
104{
105 u_int8_t bcd;
106
107 bcd = (val % 10) & 0x0f;
108 val = val / 10;
109 bcd |= (val % 10) << 4;
110
111 return bcd;
112}
113
Holger Freyther17746612008-12-28 16:32:44 +0000114void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
Harald Welte52b1f982008-12-23 20:25:15 +0000115 u_int16_t mnc, u_int16_t lac)
116{
117 u_int8_t bcd[3];
118
119 to_bcd(bcd, mcc);
120 lai48->digits[0] = bcd[0] | (bcd[1] << 4);
121 lai48->digits[1] = bcd[2];
122
123 to_bcd(bcd, mnc);
Harald Welte4b634542008-12-27 01:55:51 +0000124 /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
125#if 0
Harald Welte8470bf22008-12-25 23:28:35 +0000126 lai48->digits[1] |= bcd[2] << 4;
127 lai48->digits[2] = bcd[0] | (bcd[1] << 4);
Harald Welte4b634542008-12-27 01:55:51 +0000128#else
129 lai48->digits[1] |= 0xf << 4;
130 lai48->digits[2] = bcd[1] | (bcd[2] << 4);
131#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000132
Harald Welte4b634542008-12-27 01:55:51 +0000133 lai48->lac = htons(lac);
Harald Welte52b1f982008-12-23 20:25:15 +0000134}
135
Harald Welte255539c2008-12-28 02:26:27 +0000136#define TMSI_LEN 5
Harald Welte52b1f982008-12-23 20:25:15 +0000137#define MID_TMSI_LEN (TMSI_LEN + 2)
138
Harald Welte255539c2008-12-28 02:26:27 +0000139int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000140{
Harald Welte65e74cc2008-12-29 01:55:35 +0000141 u_int32_t *tptr = (u_int32_t *) &buf[3];
Harald Welte255539c2008-12-28 02:26:27 +0000142
Harald Welte4b634542008-12-27 01:55:51 +0000143 buf[0] = GSM48_IE_MOBILE_ID;
Harald Welte1a412182008-12-27 22:13:43 +0000144 buf[1] = TMSI_LEN;
Harald Welte4b634542008-12-27 01:55:51 +0000145 buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
Harald Welte255539c2008-12-28 02:26:27 +0000146 *tptr = htonl(tmsi);
147
148 return 7;
Harald Welte52b1f982008-12-23 20:25:15 +0000149}
150
Harald Welte8470bf22008-12-25 23:28:35 +0000151static struct msgb *gsm48_msgb_alloc(void)
152{
153 return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
154}
155
Harald Welte65e74cc2008-12-29 01:55:35 +0000156static int gsm48_sendmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000157{
Harald Welte65e74cc2008-12-29 01:55:35 +0000158 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
159
160 if (msg->lchan) {
Harald Welte8470bf22008-12-25 23:28:35 +0000161 msg->trx = msg->lchan->ts->trx;
Harald Welte52b1f982008-12-23 20:25:15 +0000162
Harald Welte65e74cc2008-12-29 01:55:35 +0000163 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) {
164 /* Send a 04.08 call control message, add transaction
165 * ID and TI flag */
166 gh->proto_discr |= msg->lchan->call.transaction_id;
167
168 /* GSM 04.07 Section 11.2.3.1.3 */
169 switch (msg->lchan->call.type) {
170 case GSM_CT_MO:
171 gh->proto_discr |= 0x80;
172 break;
173 case GSM_CT_MT:
174 break;
175 }
176 }
177 }
178
Harald Welte4b634542008-12-27 01:55:51 +0000179 msg->l3h = msg->data;
180
Harald Welte8470bf22008-12-25 23:28:35 +0000181 return rsl_data_request(msg, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000182}
183
Harald Welte52b1f982008-12-23 20:25:15 +0000184
Holger Freyther429e7762008-12-30 13:28:30 +0000185/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Harald Welte8470bf22008-12-25 23:28:35 +0000186int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000187{
Harald Welte8470bf22008-12-25 23:28:35 +0000188 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000189 struct gsm48_hdr *gh;
190
Harald Welte8470bf22008-12-25 23:28:35 +0000191 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000192
193 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
194 gh->proto_discr = GSM48_PDISC_MM;
Harald Welte10b487b2008-12-27 19:53:37 +0000195 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
Harald Welte52b1f982008-12-23 20:25:15 +0000196 gh->data[0] = cause;
197
Harald Weltedb253af2008-12-30 17:56:55 +0000198 DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr);
199
200 //gsm0411_send_sms(lchan, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000201
Harald Welte65e74cc2008-12-29 01:55:35 +0000202 return gsm48_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000203}
204
205/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Harald Welte75a983f2008-12-27 21:34:06 +0000206int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000207{
Harald Welte8470bf22008-12-25 23:28:35 +0000208 struct gsm_bts *bts = lchan->ts->trx->bts;
209 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000210 struct gsm48_hdr *gh;
211 struct gsm48_loc_area_id *lai;
212 u_int8_t *mid;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000213 int ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000214
Harald Welte8470bf22008-12-25 23:28:35 +0000215 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000216
217 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
218 gh->proto_discr = GSM48_PDISC_MM;
219 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
220
221 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Holger Freyther17746612008-12-28 16:32:44 +0000222 gsm0408_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000223 bts->network->network_code, bts->location_area_code);
224
225 mid = msgb_put(msg, MID_TMSI_LEN);
226 generate_mid_from_tmsi(mid, tmsi);
227
Holger Freytherb7193e42008-12-29 17:44:08 +0000228 lchan->pending_update_request = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000229 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
230
Holger Freyther07cc8d82008-12-29 06:23:46 +0000231 /* inform the upper layer on the progress */
Holger Freytherb7193e42008-12-29 17:44:08 +0000232 if (bts->network->update_request)
233 (*bts->network->update_request)(bts, tmsi, 1);
Holger Freyther07cc8d82008-12-29 06:23:46 +0000234
Harald Weltedb253af2008-12-30 17:56:55 +0000235 ret = gsm48_sendmsg(msg);
236
237 /* return gsm48_cc_tx_setup(lchan); */
238 ret = gsm48_tx_mm_info(lchan);
239 ret = gsm0411_send_sms(lchan, NULL);
240
Holger Freyther07cc8d82008-12-29 06:23:46 +0000241 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000242}
243
Harald Weltefc977a82008-12-27 10:19:37 +0000244static char bcd2char(u_int8_t bcd)
245{
246 if (bcd < 0xa)
247 return '0' + bcd;
248 else
249 return 'A' + (bcd - 0xa);
250}
251
252/* 10.5.1.4 */
253static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len)
254{
255 int i;
256 u_int8_t mi_type;
257 char *str_cur = string;
258
259 mi_type = mi[0] & GSM_MI_TYPE_MASK;
260
261 switch (mi_type) {
262 case GSM_MI_TYPE_NONE:
263 break;
264 case GSM_MI_TYPE_TMSI:
Harald Weltedb253af2008-12-30 17:56:55 +0000265 /* skip padding nibble at the beginning, start at offset 1... */
266 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000267 if (str_cur + 2 >= string + str_len)
268 return str_cur - string;
269 *str_cur++ = bcd2char(mi[i] >> 4);
270 *str_cur++ = bcd2char(mi[i] & 0xf);
271 }
272 break;
273 case GSM_MI_TYPE_IMSI:
274 case GSM_MI_TYPE_IMEI:
275 case GSM_MI_TYPE_IMEISV:
Harald Weltedb253af2008-12-30 17:56:55 +0000276 *str_cur++ = bcd2char(mi[0] >> 4);
277
278 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000279 if (str_cur + 2 >= string + str_len)
280 return str_cur - string;
281 *str_cur++ = bcd2char(mi[i] & 0xf);
Harald Weltedb253af2008-12-30 17:56:55 +0000282 /* skip last nibble in last input byte when GSM_EVEN */
283 if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD))
284 *str_cur++ = bcd2char(mi[i] >> 4);
Harald Weltefc977a82008-12-27 10:19:37 +0000285 }
286 break;
287 default:
288 break;
289 }
Harald Weltefc977a82008-12-27 10:19:37 +0000290 *str_cur++ = '\0';
Harald Weltedb253af2008-12-30 17:56:55 +0000291
Harald Weltefc977a82008-12-27 10:19:37 +0000292 return str_cur - string;
293}
294
Harald Welte231ad4f2008-12-27 11:15:38 +0000295/* Chapter 9.2.10 */
296static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
297{
298 struct msgb *msg = gsm48_msgb_alloc();
299 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000300
Harald Welte231ad4f2008-12-27 11:15:38 +0000301 msg->lchan = lchan;
302
303 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
304 gh->proto_discr = GSM48_PDISC_MM;
305 gh->msg_type = GSM48_MT_MM_ID_REQ;
306 gh->data[0] = id_type;
307
Harald Welte65e74cc2008-12-29 01:55:35 +0000308 return gsm48_sendmsg(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000309}
310
311#define MI_SIZE 32
312
313/* Chapter 9.2.11 */
314static int mm_rx_id_resp(struct msgb *msg)
315{
316 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000317 struct gsm_lchan *lchan = msg->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000318 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
319 char mi_string[MI_SIZE];
Harald Welte75a983f2008-12-27 21:34:06 +0000320 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000321
322 mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000323 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000324 mi_type, mi_string);
325
Harald Welte75a983f2008-12-27 21:34:06 +0000326 switch (mi_type) {
327 case GSM_MI_TYPE_IMSI:
328 if (!lchan->subscr)
329 lchan->subscr = db_create_subscriber(mi_string);
Holger Freytherb7193e42008-12-29 17:44:08 +0000330
Holger Freyther429e7762008-12-30 13:28:30 +0000331 /* We have a pending UPDATING REQUEST handle it now */
Holger Freytherb7193e42008-12-29 17:44:08 +0000332 if (lchan->pending_update_request) {
Holger Freyther89824fc2008-12-30 16:18:18 +0000333 if (authorize_subscriber(lchan->subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000334 db_subscriber_alloc_tmsi(lchan->subscr);
335 tmsi = strtoul(lchan->subscr->tmsi, NULL, 10);
Harald Weltedb253af2008-12-30 17:56:55 +0000336 del_timer(&lchan->timer);
Holger Freytherb7193e42008-12-29 17:44:08 +0000337 return gsm0408_loc_upd_acc(msg->lchan, tmsi);
338 } else {
339 schedule_reject(lchan);
340 }
Harald Welte75a983f2008-12-27 21:34:06 +0000341 }
342 break;
343 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000344 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000345 /* update subscribe <-> IMEI mapping */
346 if (lchan->subscr)
347 db_subscriber_assoc_imei(lchan->subscr, mi_string);
348 break;
349 }
350 return 0;
Harald Welte231ad4f2008-12-27 11:15:38 +0000351}
352
Harald Welte255539c2008-12-28 02:26:27 +0000353
354static void loc_upd_rej_cb(void *data)
355{
356 struct gsm_lchan *lchan = data;
357
Harald Weltedb253af2008-12-30 17:56:55 +0000358 /* 0x16 is congestion */
359 gsm0408_loc_upd_rej(lchan, 0x04);
Harald Welte255539c2008-12-28 02:26:27 +0000360 rsl_chan_release(lchan);
361}
362
Holger Freytherb7193e42008-12-29 17:44:08 +0000363static void schedule_reject(struct gsm_lchan *lchan)
364{
Holger Freytherea889022008-12-30 19:10:47 +0000365 lchan->timer.cb = loc_upd_rej_cb;
366 lchan->timer.data = lchan;
367 lchan->pending_update_request = 0;
368 schedule_timer(&lchan->timer, 1, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000369}
370
Harald Welte231ad4f2008-12-27 11:15:38 +0000371#define MI_SIZE 32
Harald Welte52b1f982008-12-23 20:25:15 +0000372/* Chapter 9.2.15 */
Harald Welte231ad4f2008-12-27 11:15:38 +0000373static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000374{
Harald Welte8470bf22008-12-25 23:28:35 +0000375 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000376 struct gsm_bts *bts = msg->trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000377 struct gsm48_loc_upd_req *lu;
378 struct gsm_subscriber *subscr;
Harald Welte255539c2008-12-28 02:26:27 +0000379 struct gsm_lchan *lchan = msg->lchan;
Harald Welte8470bf22008-12-25 23:28:35 +0000380 u_int8_t mi_type;
Harald Welte75a983f2008-12-27 21:34:06 +0000381 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000382 char mi_string[MI_SIZE];
383 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000384
Harald Welte8470bf22008-12-25 23:28:35 +0000385 lu = (struct gsm48_loc_upd_req *) gh->data;
386
387 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000388
Harald Weltefc977a82008-12-27 10:19:37 +0000389 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
390
Harald Welte231ad4f2008-12-27 11:15:38 +0000391 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000392 switch (mi_type) {
393 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000394 /* we always want the IMEI, too */
Harald Welte255539c2008-12-28 02:26:27 +0000395 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Harald Welte52b1f982008-12-23 20:25:15 +0000396 /* look up subscriber based on IMSI */
Harald Welte75a983f2008-12-27 21:34:06 +0000397 subscr = db_create_subscriber(mi_string);
Harald Welte4b634542008-12-27 01:55:51 +0000398 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000399 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000400 /* we always want the IMEI, too */
Harald Welte255539c2008-12-28 02:26:27 +0000401 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Harald Welte52b1f982008-12-23 20:25:15 +0000402 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Weltefc977a82008-12-27 10:19:37 +0000403 subscr = subscr_get_by_tmsi(lu->mi);
Harald Welte52b1f982008-12-23 20:25:15 +0000404 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000405 /* send IDENTITY REQUEST message to get IMSI */
Harald Welte255539c2008-12-28 02:26:27 +0000406 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Harald Welte52b1f982008-12-23 20:25:15 +0000407 }
408 break;
409 case GSM_MI_TYPE_IMEI:
410 case GSM_MI_TYPE_IMEISV:
411 /* no sim card... FIXME: what to do ? */
412 fprintf(stderr, "Unimplemented mobile identity type\n");
413 break;
414 default:
415 fprintf(stderr, "Unknown mobile identity type\n");
416 break;
417 }
418
Harald Welte255539c2008-12-28 02:26:27 +0000419 lchan->subscr = subscr;
420
Holger Freytherb7193e42008-12-29 17:44:08 +0000421 /* we know who we deal with and don't want him */
Holger Freyther89824fc2008-12-30 16:18:18 +0000422 if (subscr && !authorize_subscriber(subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000423 schedule_reject(lchan);
424 return 0;
425 } else if (!subscr) {
426 /* we have asked for the imsi and should get a
427 * IDENTITY RESPONSE */
428 lchan->pending_update_request = 1;
Harald Welte255539c2008-12-28 02:26:27 +0000429 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000430 }
431
Harald Welte75a983f2008-12-27 21:34:06 +0000432 db_subscriber_alloc_tmsi(subscr);
Harald Welte52b1f982008-12-23 20:25:15 +0000433 subscr_update(subscr, bts);
Harald Welte8470bf22008-12-25 23:28:35 +0000434
Harald Welte255539c2008-12-28 02:26:27 +0000435 tmsi = strtoul(subscr->tmsi, NULL, 10);
436
Harald Weltedb253af2008-12-30 17:56:55 +0000437 del_timer(&lchan->timer);
Harald Welte255539c2008-12-28 02:26:27 +0000438 return gsm0408_loc_upd_acc(lchan, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000439}
440
Harald Weltedb253af2008-12-30 17:56:55 +0000441/* Section 9.2.15a */
442int gsm48_tx_mm_info(struct gsm_lchan *lchan)
443{
444 struct msgb *msg = gsm48_msgb_alloc();
445 struct gsm48_hdr *gh;
446 struct gsm_network *net = lchan->ts->trx->bts->network;
447 time_t cur_t;
448 struct tm* cur_time;
449 u_int8_t *ptr8;
450 u_int16_t *ptr16;
451 int name_len;
452 int tz15min;
453 int i;
454
455 msg->lchan = lchan;
456
457 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
458 gh->proto_discr = GSM48_PDISC_MM;
459 gh->msg_type = GSM48_MT_MM_INFO;
460
461 if (net->name_long) {
462 name_len = strlen(net->name_long);
463 /* 10.5.3.5a */
464 ptr8 = msgb_put(msg, 3);
465 ptr8[0] = GSM48_IE_NAME_LONG;
466 ptr8[1] = name_len*2 +1;
467 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
468
469 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
470 for (i = 0; i < name_len; i++)
471 ptr16[i] = net->name_long[i];
472
473 /* FIXME: Use Cell Broadcast, not UCS-2, since
474 * UCS-2 is only supported by later revisions of the spec */
475 }
476
477 if (net->name_short) {
478 name_len = strlen(net->name_short);
479 /* 10.5.3.5a */
480 ptr8 = (u_int8_t *) msgb_put(msg, 3);
481 ptr8[0] = GSM48_IE_NAME_LONG;
482 ptr8[1] = name_len*2 + 1;
483 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
484
485 ptr16 = msgb_put(msg, name_len*2);
486 for (i = 0; i < name_len; i++)
487 ptr16[i] = net->name_short[i];
488 }
489
490#if 0
491 /* Section 10.5.3.9 */
492 cur_t = time(NULL);
493 cur_time = gmtime(cur_t);
494 ptr8 = msgb_put(msg, 8);
495 ptr8[0] = GSM48_IE_NET_TIME_TZ;
496 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
497 ptr8[2] = to_bcd8(cur_time->tm_mon);
498 ptr8[3] = to_bcd8(cur_time->tm_mday);
499 ptr8[4] = to_bcd8(cur_time->tm_hour);
500 ptr8[5] = to_bcd8(cur_time->tm_min);
501 ptr8[6] = to_bcd8(cur_time->tm_sec);
502 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
503 tz15min = (cur_time->tm_gmtoff)/(60*15);
504 ptr8[6] = to_bcd8(tz15min);
505 if (tz15min < 0)
506 ptr8[6] |= 0x80;
507#endif
508
509 return gsm48_sendmsg(msg);
510}
511
Harald Welte4b634542008-12-27 01:55:51 +0000512static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
513{
Harald Welte4b634542008-12-27 01:55:51 +0000514 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Harald Welte65e74cc2008-12-29 01:55:35 +0000515 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000516}
517
518static int gsm48_rx_mm_serv_req(struct msgb *msg)
519{
520 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000521 u_int8_t serv_type = gh->data[0] & 0x0f;
Harald Welte4b634542008-12-27 01:55:51 +0000522
Harald Welte65e74cc2008-12-29 01:55:35 +0000523 DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x\n", serv_type);
Harald Weltebcae43f2008-12-27 21:45:37 +0000524
Harald Welte4b634542008-12-27 01:55:51 +0000525 return gsm48_tx_mm_serv_ack(msg->lchan);
526}
527
Harald Welte52b1f982008-12-23 20:25:15 +0000528static int gsm0408_rcv_mm(struct msgb *msg)
529{
530 struct gsm48_hdr *gh = msgb_l3(msg);
531 int rc;
532
533 switch (gh->msg_type & 0xbf) {
534 case GSM48_MT_MM_LOC_UPD_REQUEST:
Holger Freyther429e7762008-12-30 13:28:30 +0000535 DEBUGP(DMM, "LOCATION UPDATING REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000536 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000537 break;
538 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000539 rc = mm_rx_id_resp(msg);
540 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000541 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000542 rc = gsm48_rx_mm_serv_req(msg);
543 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000544 case GSM48_MT_MM_STATUS:
545 DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n");
546 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000547 case GSM48_MT_MM_CM_REEST_REQ:
Harald Welte231ad4f2008-12-27 11:15:38 +0000548 case GSM48_MT_MM_TMSI_REALL_COMPL:
549 case GSM48_MT_MM_AUTH_RESP:
550 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte52b1f982008-12-23 20:25:15 +0000551 fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n",
552 gh->msg_type);
553 break;
554 default:
555 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
556 gh->msg_type);
557 break;
558 }
559
560 return rc;
561}
562static int gsm0408_rcv_rr(struct msgb *msg)
563{
564 struct gsm48_hdr *gh = msgb_l3(msg);
565
566 switch (gh->msg_type) {
567 case GSM48_MT_RR_CLSM_CHG:
568 DEBUGP(DRR, "CLASSMARK CHANGE\n");
569 /* FIXME: what to do ?!? */
570 break;
Harald Weltefc977a82008-12-27 10:19:37 +0000571 case GSM48_MT_RR_GPRS_SUSP_REQ:
572 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
573 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000574 case GSM48_MT_RR_PAG_RESP:
575 default:
576 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
577 gh->msg_type);
578 break;
579 }
580
581 return 0;
582}
583
Harald Welte4bc90a12008-12-27 16:32:52 +0000584/* Call Control */
585
Harald Welte4bc90a12008-12-27 16:32:52 +0000586static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
587{
588 struct msgb *msg = gsm48_msgb_alloc();
589 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
590 u_int8_t *cause, *call_state;
591
Harald Welte65e74cc2008-12-29 01:55:35 +0000592 gh->proto_discr = GSM48_PDISC_CC;
593
Harald Welte4bc90a12008-12-27 16:32:52 +0000594 msg->lchan = lchan;
595
Harald Welte4bc90a12008-12-27 16:32:52 +0000596 gh->msg_type = GSM48_MT_CC_STATUS;
597
598 cause = msgb_put(msg, 3);
599 cause[0] = 2;
600 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
601 cause[2] = 0x80 | 30; /* response to status inquiry */
602
603 call_state = msgb_put(msg, 1);
604 call_state[0] = 0xc0 | 0x00;
605
Harald Welte65e74cc2008-12-29 01:55:35 +0000606 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000607}
608
Harald Welte6f4b7532008-12-29 00:39:37 +0000609static int gsm48_tx_simple(struct gsm_lchan *lchan,
610 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +0000611{
612 struct msgb *msg = gsm48_msgb_alloc();
613 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
614
615 msg->lchan = lchan;
616
Harald Welte6f4b7532008-12-29 00:39:37 +0000617 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +0000618 gh->msg_type = msg_type;
619
Harald Welte65e74cc2008-12-29 01:55:35 +0000620 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000621}
622
623static int gsm48_cc_rx_status_enq(struct msgb *msg)
624{
625 return gsm48_cc_tx_status(msg->lchan);
626}
627
628static int gsm48_cc_rx_setup(struct msgb *msg)
629{
Harald Welte6f4b7532008-12-29 00:39:37 +0000630 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
631 GSM48_MT_CC_CALL_CONF);
Harald Welte4bc90a12008-12-27 16:32:52 +0000632}
633
Harald Welte65e74cc2008-12-29 01:55:35 +0000634int gsm48_cc_tx_setup(struct gsm_lchan *lchan)
635{
636 struct msgb *msg = gsm48_msgb_alloc();
637 struct gsm48_hdr *gh;
638 struct gsm_call *call = &lchan->call;
639
640 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8);
641
642 call->type = GSM_CT_MT;
643 msg->lchan = lchan;
644
645 gh->proto_discr = GSM48_PDISC_CC;
646 gh->msg_type = GSM48_MT_CC_SETUP;
647 gh->data[0] = 0x34;
648 gh->data[1] = 0x00;
649 gh->data[2] = 0x5c;
650 gh->data[3] = 0x04;
651 gh->data[4] = 0xb9;
652 gh->data[5] = 0x83;
653 gh->data[6] = 0x32;
654 gh->data[7] = 0x24;
655
656 DEBUGP(DCC, "Sending SETUP\n");
657
658 return gsm48_sendmsg(msg);
659}
660
Harald Welte4bc90a12008-12-27 16:32:52 +0000661static int gsm0408_rcv_cc(struct msgb *msg)
662{
663 struct gsm48_hdr *gh = msgb_l3(msg);
664 u_int8_t msg_type = gh->msg_type & 0xbf;
665 struct gsm_call *call = &msg->lchan->call;
Holger Freyther2eafef52008-12-29 06:42:17 +0000666 struct gsm_network *network = msg->lchan->ts->trx->bts->network;
Harald Welte4bc90a12008-12-27 16:32:52 +0000667 int rc = 0;
668
669 switch (msg_type) {
670 case GSM48_MT_CC_CALL_CONF:
671 /* Response to SETUP */
672 DEBUGP(DCC, "CALL CONFIRM\n");
673 break;
674 case GSM48_MT_CC_RELEASE_COMPL:
675 /* Answer from MS to RELEASE */
676 DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n");
Holger Freytherb7193e42008-12-29 17:44:08 +0000677 if (network->call_state_changed)
678 (*network->call_state_changed)(msg->lchan, call->state);
Harald Welte4bc90a12008-12-27 16:32:52 +0000679 call->state = GSM_CSTATE_NULL;
680 break;
681 case GSM48_MT_CC_ALERTING:
682 DEBUGP(DCC, "ALERTING\n");
683 break;
684 case GSM48_MT_CC_CONNECT:
685 DEBUGP(DCC, "CONNECT\n");
686 /* MT: need to respond with CONNECT_ACK */
Harald Welte6f4b7532008-12-29 00:39:37 +0000687 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
688 GSM48_MT_CC_CONNECT_ACK);
Harald Welte4bc90a12008-12-27 16:32:52 +0000689 break;
690 case GSM48_MT_CC_CONNECT_ACK:
691 /* MO: Answer to CONNECT */
692 call->state = GSM_CSTATE_ACTIVE;
693 DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n");
694 break;
695 case GSM48_MT_CC_RELEASE:
696 DEBUGP(DCC, "RELEASE\n");
697 /* need to respond with RELEASE_COMPLETE */
698 break;
699 case GSM48_MT_CC_STATUS_ENQ:
700 rc = gsm48_cc_rx_status_enq(msg);
701 break;
702 case GSM48_MT_CC_DISCONNECT:
703 /* Section 5.4.3.2 */
704 DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n");
705 call->state = GSM_CSTATE_RELEASE_REQ;
706 /* FIXME: clear the network connection */
Harald Welte6f4b7532008-12-29 00:39:37 +0000707 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
708 GSM48_MT_CC_RELEASE);
Harald Welte4bc90a12008-12-27 16:32:52 +0000709 break;
710 case GSM48_MT_CC_SETUP:
711 call->type = GSM_CT_MO;
712 call->state = GSM_CSTATE_INITIATED;
713 call->transaction_id = gh->proto_discr & 0xf0;
714 DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id);
Harald Welte6f4b7532008-12-29 00:39:37 +0000715 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
716 GSM48_MT_CC_CONNECT);
Harald Welte4bc90a12008-12-27 16:32:52 +0000717 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
718 break;
719 case GSM48_MT_CC_EMERG_SETUP:
720 DEBUGP(DCC, "EMERGENCY SETUP\n");
721 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
722 break;
723 default:
724 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
725 msg_type);
726 break;
727 }
728
729 return rc;
730}
731
Harald Welte52b1f982008-12-23 20:25:15 +0000732/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
733int gsm0408_rcvmsg(struct msgb *msg)
734{
735 struct gsm48_hdr *gh = msgb_l3(msg);
736 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +0000737 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000738
739 switch (pdisc) {
740 case GSM48_PDISC_CC:
741 rc = gsm0408_rcv_cc(msg);
742 break;
743 case GSM48_PDISC_MM:
744 rc = gsm0408_rcv_mm(msg);
745 break;
746 case GSM48_PDISC_RR:
747 rc = gsm0408_rcv_rr(msg);
748 break;
Harald Weltebcae43f2008-12-27 21:45:37 +0000749 case GSM48_PDISC_SMS:
Daniel Willmann8b3390e2008-12-28 00:31:09 +0000750 rc = gsm0411_rcv_sms(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000751 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000752 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +0000753 case GSM48_PDISC_SM_GPRS:
Harald Welte52b1f982008-12-23 20:25:15 +0000754 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
755 pdisc);
756 break;
757 default:
758 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
759 pdisc);
760 break;
761 }
762
763 return rc;
764}
Harald Welte8470bf22008-12-25 23:28:35 +0000765
766enum chreq_type {
767 CHREQ_T_EMERG_CALL,
768 CHREQ_T_CALL_REEST_TCH_F,
769 CHREQ_T_CALL_REEST_TCH_H,
770 CHREQ_T_CALL_REEST_TCH_H_DBL,
771 CHREQ_T_SDCCH,
772 CHREQ_T_TCH_F,
773 CHREQ_T_VOICE_CALL_TCH_H,
774 CHREQ_T_DATA_CALL_TCH_H,
775 CHREQ_T_LOCATION_UPD,
776 CHREQ_T_PAG_R_ANY,
777 CHREQ_T_PAG_R_TCH_F,
778 CHREQ_T_PAG_R_TCH_FH,
779};
780
781/* Section 9.1.8 / Table 9.9 */
782struct chreq {
783 u_int8_t val;
784 u_int8_t mask;
785 enum chreq_type type;
786};
787
788/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
789static const struct chreq chreq_type_neci1[] = {
790 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
791 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
792 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
793 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
794 { 0xe0, 0xe0, CHREQ_T_SDCCH },
795 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
796 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
797 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
798 { 0x10, 0xf0, CHREQ_T_SDCCH },
799 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
800 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
801 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
802};
803
804/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
805static const struct chreq chreq_type_neci0[] = {
806 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
807 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
808 { 0xe0, 0xe0, CHREQ_T_TCH_F },
809 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
810 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
811 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
812 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
813 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
814};
815
816static const enum gsm_chan_t ctype_by_chreq[] = {
817 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
818 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
819 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
820 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
821 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
822 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
823 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
824 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
825 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
826 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
827 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
828 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
829};
830
Harald Weltee14a57c2008-12-29 04:08:28 +0000831static const enum gsm_chreq_reason_t reason_by_chreq[] = {
832 [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
833 [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
834 [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
835 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
836 [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
837 [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
838 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
839 [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
840 [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
841 [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG,
842 [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
843 [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
844};
845
Harald Welte8470bf22008-12-25 23:28:35 +0000846enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
847{
848 int i;
849 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
850
851 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
852 const struct chreq *chr = &chreq_type_neci0[i];
853 if ((ra & chr->mask) == chr->val)
854 return ctype_by_chreq[chr->type];
855 }
856 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
857 return GSM_LCHAN_SDCCH;
858}
Harald Weltee14a57c2008-12-29 04:08:28 +0000859
860enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra)
861{
862 int i;
863 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
864
865 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
866 const struct chreq *chr = &chreq_type_neci0[i];
867 if ((ra & chr->mask) == chr->val)
868 return reason_by_chreq[chr->type];
869 }
870 fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
871 return GSM_CHREQ_REASON_OTHER;
872}