blob: 7dccb14e493ca2f4072b13f6aee868dd38fe3fd1 [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
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000326 /*
327 * Rogue messages could trick us but so is life
328 */
329 put_lchan(lchan);
330
Harald Welte75a983f2008-12-27 21:34:06 +0000331 switch (mi_type) {
332 case GSM_MI_TYPE_IMSI:
333 if (!lchan->subscr)
334 lchan->subscr = db_create_subscriber(mi_string);
Holger Freytherb7193e42008-12-29 17:44:08 +0000335
Holger Freyther429e7762008-12-30 13:28:30 +0000336 /* We have a pending UPDATING REQUEST handle it now */
Holger Freytherb7193e42008-12-29 17:44:08 +0000337 if (lchan->pending_update_request) {
Holger Freyther89824fc2008-12-30 16:18:18 +0000338 if (authorize_subscriber(lchan->subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000339 db_subscriber_alloc_tmsi(lchan->subscr);
340 tmsi = strtoul(lchan->subscr->tmsi, NULL, 10);
Harald Weltedb253af2008-12-30 17:56:55 +0000341 del_timer(&lchan->timer);
Holger Freytherb7193e42008-12-29 17:44:08 +0000342 return gsm0408_loc_upd_acc(msg->lchan, tmsi);
343 } else {
344 schedule_reject(lchan);
345 }
Harald Welte75a983f2008-12-27 21:34:06 +0000346 }
347 break;
348 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000349 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000350 /* update subscribe <-> IMEI mapping */
351 if (lchan->subscr)
352 db_subscriber_assoc_imei(lchan->subscr, mi_string);
353 break;
354 }
355 return 0;
Harald Welte231ad4f2008-12-27 11:15:38 +0000356}
357
Harald Welte255539c2008-12-28 02:26:27 +0000358
359static void loc_upd_rej_cb(void *data)
360{
361 struct gsm_lchan *lchan = data;
362
Harald Weltedb253af2008-12-30 17:56:55 +0000363 /* 0x16 is congestion */
364 gsm0408_loc_upd_rej(lchan, 0x04);
Harald Welte255539c2008-12-28 02:26:27 +0000365 rsl_chan_release(lchan);
366}
367
Holger Freytherb7193e42008-12-29 17:44:08 +0000368static void schedule_reject(struct gsm_lchan *lchan)
369{
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000370 lchan->updating_timer.cb = loc_upd_rej_cb;
371 lchan->updating_timer.data = lchan;
Holger Freytherea889022008-12-30 19:10:47 +0000372 lchan->pending_update_request = 0;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000373 schedule_timer(&lchan->updating_timer, 1, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000374}
375
Harald Welte231ad4f2008-12-27 11:15:38 +0000376#define MI_SIZE 32
Harald Welte52b1f982008-12-23 20:25:15 +0000377/* Chapter 9.2.15 */
Harald Welte231ad4f2008-12-27 11:15:38 +0000378static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000379{
Harald Welte8470bf22008-12-25 23:28:35 +0000380 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000381 struct gsm_bts *bts = msg->trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000382 struct gsm48_loc_upd_req *lu;
383 struct gsm_subscriber *subscr;
Harald Welte255539c2008-12-28 02:26:27 +0000384 struct gsm_lchan *lchan = msg->lchan;
Harald Welte8470bf22008-12-25 23:28:35 +0000385 u_int8_t mi_type;
Harald Welte75a983f2008-12-27 21:34:06 +0000386 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000387 char mi_string[MI_SIZE];
388 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000389
Harald Welte8470bf22008-12-25 23:28:35 +0000390 lu = (struct gsm48_loc_upd_req *) gh->data;
391
392 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000393
Harald Weltefc977a82008-12-27 10:19:37 +0000394 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
395
Harald Welte231ad4f2008-12-27 11:15:38 +0000396 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000397 switch (mi_type) {
398 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000399 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000400 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000401 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000402
Harald Welte52b1f982008-12-23 20:25:15 +0000403 /* look up subscriber based on IMSI */
Harald Welte75a983f2008-12-27 21:34:06 +0000404 subscr = db_create_subscriber(mi_string);
Harald Welte4b634542008-12-27 01:55:51 +0000405 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000406 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000407 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000408 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000409 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000410
Harald Welte52b1f982008-12-23 20:25:15 +0000411 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Weltefc977a82008-12-27 10:19:37 +0000412 subscr = subscr_get_by_tmsi(lu->mi);
Harald Welte52b1f982008-12-23 20:25:15 +0000413 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000414 /* send IDENTITY REQUEST message to get IMSI */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000415 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000416 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Harald Welte52b1f982008-12-23 20:25:15 +0000417 }
418 break;
419 case GSM_MI_TYPE_IMEI:
420 case GSM_MI_TYPE_IMEISV:
421 /* no sim card... FIXME: what to do ? */
422 fprintf(stderr, "Unimplemented mobile identity type\n");
423 break;
424 default:
425 fprintf(stderr, "Unknown mobile identity type\n");
426 break;
427 }
428
Harald Welte255539c2008-12-28 02:26:27 +0000429 lchan->subscr = subscr;
430
Holger Freytherb7193e42008-12-29 17:44:08 +0000431 /* we know who we deal with and don't want him */
Holger Freyther89824fc2008-12-30 16:18:18 +0000432 if (subscr && !authorize_subscriber(subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000433 schedule_reject(lchan);
434 return 0;
435 } else if (!subscr) {
436 /* we have asked for the imsi and should get a
437 * IDENTITY RESPONSE */
438 lchan->pending_update_request = 1;
Harald Welte255539c2008-12-28 02:26:27 +0000439 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000440 }
441
Harald Welte75a983f2008-12-27 21:34:06 +0000442 db_subscriber_alloc_tmsi(subscr);
Harald Welte52b1f982008-12-23 20:25:15 +0000443 subscr_update(subscr, bts);
Harald Welte8470bf22008-12-25 23:28:35 +0000444
Harald Welte255539c2008-12-28 02:26:27 +0000445 tmsi = strtoul(subscr->tmsi, NULL, 10);
446
Harald Weltedb253af2008-12-30 17:56:55 +0000447 del_timer(&lchan->timer);
Harald Welte255539c2008-12-28 02:26:27 +0000448 return gsm0408_loc_upd_acc(lchan, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000449}
450
Harald Weltedb253af2008-12-30 17:56:55 +0000451/* Section 9.2.15a */
452int gsm48_tx_mm_info(struct gsm_lchan *lchan)
453{
454 struct msgb *msg = gsm48_msgb_alloc();
455 struct gsm48_hdr *gh;
456 struct gsm_network *net = lchan->ts->trx->bts->network;
457 time_t cur_t;
458 struct tm* cur_time;
459 u_int8_t *ptr8;
460 u_int16_t *ptr16;
461 int name_len;
462 int tz15min;
463 int i;
464
465 msg->lchan = lchan;
466
467 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
468 gh->proto_discr = GSM48_PDISC_MM;
469 gh->msg_type = GSM48_MT_MM_INFO;
470
471 if (net->name_long) {
472 name_len = strlen(net->name_long);
473 /* 10.5.3.5a */
474 ptr8 = msgb_put(msg, 3);
475 ptr8[0] = GSM48_IE_NAME_LONG;
476 ptr8[1] = name_len*2 +1;
477 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
478
479 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
480 for (i = 0; i < name_len; i++)
481 ptr16[i] = net->name_long[i];
482
483 /* FIXME: Use Cell Broadcast, not UCS-2, since
484 * UCS-2 is only supported by later revisions of the spec */
485 }
486
487 if (net->name_short) {
488 name_len = strlen(net->name_short);
489 /* 10.5.3.5a */
490 ptr8 = (u_int8_t *) msgb_put(msg, 3);
491 ptr8[0] = GSM48_IE_NAME_LONG;
492 ptr8[1] = name_len*2 + 1;
493 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
494
495 ptr16 = msgb_put(msg, name_len*2);
496 for (i = 0; i < name_len; i++)
497 ptr16[i] = net->name_short[i];
498 }
499
500#if 0
501 /* Section 10.5.3.9 */
502 cur_t = time(NULL);
503 cur_time = gmtime(cur_t);
504 ptr8 = msgb_put(msg, 8);
505 ptr8[0] = GSM48_IE_NET_TIME_TZ;
506 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
507 ptr8[2] = to_bcd8(cur_time->tm_mon);
508 ptr8[3] = to_bcd8(cur_time->tm_mday);
509 ptr8[4] = to_bcd8(cur_time->tm_hour);
510 ptr8[5] = to_bcd8(cur_time->tm_min);
511 ptr8[6] = to_bcd8(cur_time->tm_sec);
512 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
513 tz15min = (cur_time->tm_gmtoff)/(60*15);
514 ptr8[6] = to_bcd8(tz15min);
515 if (tz15min < 0)
516 ptr8[6] |= 0x80;
517#endif
518
519 return gsm48_sendmsg(msg);
520}
521
Harald Welte4b634542008-12-27 01:55:51 +0000522static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
523{
Harald Welte4b634542008-12-27 01:55:51 +0000524 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Harald Welte65e74cc2008-12-29 01:55:35 +0000525 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000526}
527
528static int gsm48_rx_mm_serv_req(struct msgb *msg)
529{
530 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000531 u_int8_t serv_type = gh->data[0] & 0x0f;
Harald Welte4b634542008-12-27 01:55:51 +0000532
Harald Welte65e74cc2008-12-29 01:55:35 +0000533 DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x\n", serv_type);
Harald Weltebcae43f2008-12-27 21:45:37 +0000534
Harald Welte4b634542008-12-27 01:55:51 +0000535 return gsm48_tx_mm_serv_ack(msg->lchan);
536}
537
Harald Welte52b1f982008-12-23 20:25:15 +0000538static int gsm0408_rcv_mm(struct msgb *msg)
539{
540 struct gsm48_hdr *gh = msgb_l3(msg);
541 int rc;
542
543 switch (gh->msg_type & 0xbf) {
544 case GSM48_MT_MM_LOC_UPD_REQUEST:
Holger Freyther429e7762008-12-30 13:28:30 +0000545 DEBUGP(DMM, "LOCATION UPDATING REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000546 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000547 break;
548 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000549 rc = mm_rx_id_resp(msg);
550 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000551 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000552 rc = gsm48_rx_mm_serv_req(msg);
553 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000554 case GSM48_MT_MM_STATUS:
555 DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n");
556 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000557 case GSM48_MT_MM_CM_REEST_REQ:
Harald Welte231ad4f2008-12-27 11:15:38 +0000558 case GSM48_MT_MM_TMSI_REALL_COMPL:
559 case GSM48_MT_MM_AUTH_RESP:
560 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte52b1f982008-12-23 20:25:15 +0000561 fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n",
562 gh->msg_type);
563 break;
564 default:
565 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
566 gh->msg_type);
567 break;
568 }
569
570 return rc;
571}
572static int gsm0408_rcv_rr(struct msgb *msg)
573{
574 struct gsm48_hdr *gh = msgb_l3(msg);
575
576 switch (gh->msg_type) {
577 case GSM48_MT_RR_CLSM_CHG:
578 DEBUGP(DRR, "CLASSMARK CHANGE\n");
579 /* FIXME: what to do ?!? */
580 break;
Harald Weltefc977a82008-12-27 10:19:37 +0000581 case GSM48_MT_RR_GPRS_SUSP_REQ:
582 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
583 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000584 case GSM48_MT_RR_PAG_RESP:
585 default:
586 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
587 gh->msg_type);
588 break;
589 }
590
591 return 0;
592}
593
Harald Welte4bc90a12008-12-27 16:32:52 +0000594/* Call Control */
595
Harald Welte4bc90a12008-12-27 16:32:52 +0000596static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
597{
598 struct msgb *msg = gsm48_msgb_alloc();
599 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
600 u_int8_t *cause, *call_state;
601
Harald Welte65e74cc2008-12-29 01:55:35 +0000602 gh->proto_discr = GSM48_PDISC_CC;
603
Harald Welte4bc90a12008-12-27 16:32:52 +0000604 msg->lchan = lchan;
605
Harald Welte4bc90a12008-12-27 16:32:52 +0000606 gh->msg_type = GSM48_MT_CC_STATUS;
607
608 cause = msgb_put(msg, 3);
609 cause[0] = 2;
610 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
611 cause[2] = 0x80 | 30; /* response to status inquiry */
612
613 call_state = msgb_put(msg, 1);
614 call_state[0] = 0xc0 | 0x00;
615
Harald Welte65e74cc2008-12-29 01:55:35 +0000616 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000617}
618
Harald Welte6f4b7532008-12-29 00:39:37 +0000619static int gsm48_tx_simple(struct gsm_lchan *lchan,
620 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +0000621{
622 struct msgb *msg = gsm48_msgb_alloc();
623 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
624
625 msg->lchan = lchan;
626
Harald Welte6f4b7532008-12-29 00:39:37 +0000627 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +0000628 gh->msg_type = msg_type;
629
Harald Welte65e74cc2008-12-29 01:55:35 +0000630 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000631}
632
633static int gsm48_cc_rx_status_enq(struct msgb *msg)
634{
635 return gsm48_cc_tx_status(msg->lchan);
636}
637
638static int gsm48_cc_rx_setup(struct msgb *msg)
639{
Harald Welte6f4b7532008-12-29 00:39:37 +0000640 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
641 GSM48_MT_CC_CALL_CONF);
Harald Welte4bc90a12008-12-27 16:32:52 +0000642}
643
Harald Welte65e74cc2008-12-29 01:55:35 +0000644int gsm48_cc_tx_setup(struct gsm_lchan *lchan)
645{
646 struct msgb *msg = gsm48_msgb_alloc();
647 struct gsm48_hdr *gh;
648 struct gsm_call *call = &lchan->call;
649
650 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8);
651
652 call->type = GSM_CT_MT;
653 msg->lchan = lchan;
654
655 gh->proto_discr = GSM48_PDISC_CC;
656 gh->msg_type = GSM48_MT_CC_SETUP;
657 gh->data[0] = 0x34;
658 gh->data[1] = 0x00;
659 gh->data[2] = 0x5c;
660 gh->data[3] = 0x04;
661 gh->data[4] = 0xb9;
662 gh->data[5] = 0x83;
663 gh->data[6] = 0x32;
664 gh->data[7] = 0x24;
665
666 DEBUGP(DCC, "Sending SETUP\n");
667
668 return gsm48_sendmsg(msg);
669}
670
Harald Welte4bc90a12008-12-27 16:32:52 +0000671static int gsm0408_rcv_cc(struct msgb *msg)
672{
673 struct gsm48_hdr *gh = msgb_l3(msg);
674 u_int8_t msg_type = gh->msg_type & 0xbf;
675 struct gsm_call *call = &msg->lchan->call;
Holger Freyther2eafef52008-12-29 06:42:17 +0000676 struct gsm_network *network = msg->lchan->ts->trx->bts->network;
Harald Welte4bc90a12008-12-27 16:32:52 +0000677 int rc = 0;
678
679 switch (msg_type) {
680 case GSM48_MT_CC_CALL_CONF:
681 /* Response to SETUP */
682 DEBUGP(DCC, "CALL CONFIRM\n");
683 break;
684 case GSM48_MT_CC_RELEASE_COMPL:
685 /* Answer from MS to RELEASE */
686 DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n");
Holger Freytherb7193e42008-12-29 17:44:08 +0000687 if (network->call_state_changed)
688 (*network->call_state_changed)(msg->lchan, call->state);
Harald Welte4bc90a12008-12-27 16:32:52 +0000689 call->state = GSM_CSTATE_NULL;
690 break;
691 case GSM48_MT_CC_ALERTING:
692 DEBUGP(DCC, "ALERTING\n");
693 break;
694 case GSM48_MT_CC_CONNECT:
695 DEBUGP(DCC, "CONNECT\n");
696 /* MT: need to respond with CONNECT_ACK */
Harald Welte6f4b7532008-12-29 00:39:37 +0000697 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
698 GSM48_MT_CC_CONNECT_ACK);
Harald Welte4bc90a12008-12-27 16:32:52 +0000699 break;
700 case GSM48_MT_CC_CONNECT_ACK:
701 /* MO: Answer to CONNECT */
702 call->state = GSM_CSTATE_ACTIVE;
703 DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n");
704 break;
705 case GSM48_MT_CC_RELEASE:
706 DEBUGP(DCC, "RELEASE\n");
707 /* need to respond with RELEASE_COMPLETE */
708 break;
709 case GSM48_MT_CC_STATUS_ENQ:
710 rc = gsm48_cc_rx_status_enq(msg);
711 break;
712 case GSM48_MT_CC_DISCONNECT:
713 /* Section 5.4.3.2 */
714 DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n");
715 call->state = GSM_CSTATE_RELEASE_REQ;
716 /* FIXME: clear the network connection */
Harald Welte6f4b7532008-12-29 00:39:37 +0000717 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
718 GSM48_MT_CC_RELEASE);
Harald Welte4bc90a12008-12-27 16:32:52 +0000719 break;
720 case GSM48_MT_CC_SETUP:
721 call->type = GSM_CT_MO;
722 call->state = GSM_CSTATE_INITIATED;
723 call->transaction_id = gh->proto_discr & 0xf0;
724 DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id);
Harald Welte6f4b7532008-12-29 00:39:37 +0000725 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
726 GSM48_MT_CC_CONNECT);
Harald Welte4bc90a12008-12-27 16:32:52 +0000727 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
728 break;
729 case GSM48_MT_CC_EMERG_SETUP:
730 DEBUGP(DCC, "EMERGENCY SETUP\n");
731 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
732 break;
733 default:
734 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
735 msg_type);
736 break;
737 }
738
739 return rc;
740}
741
Harald Welte52b1f982008-12-23 20:25:15 +0000742/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
743int gsm0408_rcvmsg(struct msgb *msg)
744{
745 struct gsm48_hdr *gh = msgb_l3(msg);
746 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +0000747 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000748
749 switch (pdisc) {
750 case GSM48_PDISC_CC:
751 rc = gsm0408_rcv_cc(msg);
752 break;
753 case GSM48_PDISC_MM:
754 rc = gsm0408_rcv_mm(msg);
755 break;
756 case GSM48_PDISC_RR:
757 rc = gsm0408_rcv_rr(msg);
758 break;
Harald Weltebcae43f2008-12-27 21:45:37 +0000759 case GSM48_PDISC_SMS:
Daniel Willmann8b3390e2008-12-28 00:31:09 +0000760 rc = gsm0411_rcv_sms(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000761 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000762 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +0000763 case GSM48_PDISC_SM_GPRS:
Harald Welte52b1f982008-12-23 20:25:15 +0000764 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
765 pdisc);
766 break;
767 default:
768 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
769 pdisc);
770 break;
771 }
772
773 return rc;
774}
Harald Welte8470bf22008-12-25 23:28:35 +0000775
776enum chreq_type {
777 CHREQ_T_EMERG_CALL,
778 CHREQ_T_CALL_REEST_TCH_F,
779 CHREQ_T_CALL_REEST_TCH_H,
780 CHREQ_T_CALL_REEST_TCH_H_DBL,
781 CHREQ_T_SDCCH,
782 CHREQ_T_TCH_F,
783 CHREQ_T_VOICE_CALL_TCH_H,
784 CHREQ_T_DATA_CALL_TCH_H,
785 CHREQ_T_LOCATION_UPD,
786 CHREQ_T_PAG_R_ANY,
787 CHREQ_T_PAG_R_TCH_F,
788 CHREQ_T_PAG_R_TCH_FH,
789};
790
791/* Section 9.1.8 / Table 9.9 */
792struct chreq {
793 u_int8_t val;
794 u_int8_t mask;
795 enum chreq_type type;
796};
797
798/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
799static const struct chreq chreq_type_neci1[] = {
800 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
801 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
802 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
803 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
804 { 0xe0, 0xe0, CHREQ_T_SDCCH },
805 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
806 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
807 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
808 { 0x10, 0xf0, CHREQ_T_SDCCH },
809 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
810 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
811 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
812};
813
814/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
815static const struct chreq chreq_type_neci0[] = {
816 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
817 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
818 { 0xe0, 0xe0, CHREQ_T_TCH_F },
819 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
820 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
821 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
822 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
823 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
824};
825
826static const enum gsm_chan_t ctype_by_chreq[] = {
827 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
828 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
829 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
830 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
831 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
832 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
833 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
834 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
835 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
836 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
837 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
838 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
839};
840
Harald Weltee14a57c2008-12-29 04:08:28 +0000841static const enum gsm_chreq_reason_t reason_by_chreq[] = {
842 [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
843 [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
844 [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
845 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
846 [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
847 [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
848 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
849 [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
850 [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
851 [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG,
852 [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
853 [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
854};
855
Harald Welte8470bf22008-12-25 23:28:35 +0000856enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
857{
858 int i;
859 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
860
861 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
862 const struct chreq *chr = &chreq_type_neci0[i];
863 if ((ra & chr->mask) == chr->val)
864 return ctype_by_chreq[chr->type];
865 }
866 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
867 return GSM_LCHAN_SDCCH;
868}
Harald Weltee14a57c2008-12-29 04:08:28 +0000869
870enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra)
871{
872 int i;
873 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
874
875 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
876 const struct chreq *chr = &chreq_type_neci0[i];
877 if ((ra & chr->mask) == chr->val)
878 return reason_by_chreq[chr->type];
879 }
880 fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
881 return GSM_CHREQ_REASON_OTHER;
882}