blob: 65d2f647a09e9dc4fa26e7aed0fac545ba4a0bb8 [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
Holger Freythere97f7fb2008-12-31 18:52:11 +000062static int reject_cause = 0;
63void gsm0408_set_reject_cause(int cause)
64{
65 reject_cause = cause;
66}
67
Holger Freyther89824fc2008-12-30 16:18:18 +000068static int authorize_subscriber(struct gsm_subscriber *subscriber)
69{
70 if (!subscriber)
71 return 0;
72
73 if (authorize_everonye)
74 return 1;
75
76 return subscriber->authorized;
77}
Holger Freyther07cc8d82008-12-29 06:23:46 +000078
79
Harald Welte52b1f982008-12-23 20:25:15 +000080static void parse_lai(struct gsm_lai *lai, const struct gsm48_loc_area_id *lai48)
81{
82 u_int8_t dig[4];
83
84 /* MCC */
85 dig[1] = lai48->digits[0] & 0x0f;
86 dig[2] = lai48->digits[0] >> 4;
87 dig[3] = lai48->digits[1] & 0x0f;
88 lai->mcc = dig[3] * 100 + dig[2];
89
90 /* MNC */
91 dig[1] = lai48->digits[1] >> 4;
92 dig[2] = lai48->digits[2] & 0x0f;
93 dig[3] = lai48->digits[2] >> 4;
94 lai->mnc = dig[3] * 100 + dig[2];
95
96 lai->lac = lai48->lac;
97}
98
99static void to_bcd(u_int8_t *bcd, u_int16_t val)
100{
Harald Welte4b634542008-12-27 01:55:51 +0000101 bcd[2] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000102 val = val / 10;
103 bcd[1] = val % 10;
104 val = val / 10;
Harald Welte4b634542008-12-27 01:55:51 +0000105 bcd[0] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000106 val = val / 10;
107}
108
Harald Weltedb253af2008-12-30 17:56:55 +0000109static u_int8_t to_bcd8(unsigned int val)
110{
111 u_int8_t bcd;
112
113 bcd = (val % 10) & 0x0f;
114 val = val / 10;
115 bcd |= (val % 10) << 4;
116
117 return bcd;
118}
119
Holger Freyther17746612008-12-28 16:32:44 +0000120void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
Harald Welte52b1f982008-12-23 20:25:15 +0000121 u_int16_t mnc, u_int16_t lac)
122{
123 u_int8_t bcd[3];
124
125 to_bcd(bcd, mcc);
126 lai48->digits[0] = bcd[0] | (bcd[1] << 4);
127 lai48->digits[1] = bcd[2];
128
129 to_bcd(bcd, mnc);
Harald Welte4b634542008-12-27 01:55:51 +0000130 /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
131#if 0
Harald Welte8470bf22008-12-25 23:28:35 +0000132 lai48->digits[1] |= bcd[2] << 4;
133 lai48->digits[2] = bcd[0] | (bcd[1] << 4);
Harald Welte4b634542008-12-27 01:55:51 +0000134#else
135 lai48->digits[1] |= 0xf << 4;
136 lai48->digits[2] = bcd[1] | (bcd[2] << 4);
137#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000138
Harald Welte4b634542008-12-27 01:55:51 +0000139 lai48->lac = htons(lac);
Harald Welte52b1f982008-12-23 20:25:15 +0000140}
141
Harald Welte255539c2008-12-28 02:26:27 +0000142#define TMSI_LEN 5
Harald Welte52b1f982008-12-23 20:25:15 +0000143#define MID_TMSI_LEN (TMSI_LEN + 2)
144
Harald Welte255539c2008-12-28 02:26:27 +0000145int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000146{
Harald Welte65e74cc2008-12-29 01:55:35 +0000147 u_int32_t *tptr = (u_int32_t *) &buf[3];
Harald Welte255539c2008-12-28 02:26:27 +0000148
Harald Welte4b634542008-12-27 01:55:51 +0000149 buf[0] = GSM48_IE_MOBILE_ID;
Harald Welte1a412182008-12-27 22:13:43 +0000150 buf[1] = TMSI_LEN;
Harald Welte4b634542008-12-27 01:55:51 +0000151 buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
Harald Welte255539c2008-12-28 02:26:27 +0000152 *tptr = htonl(tmsi);
153
154 return 7;
Harald Welte52b1f982008-12-23 20:25:15 +0000155}
156
Harald Welte8470bf22008-12-25 23:28:35 +0000157static struct msgb *gsm48_msgb_alloc(void)
158{
159 return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
160}
161
Harald Welte65e74cc2008-12-29 01:55:35 +0000162static int gsm48_sendmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000163{
Harald Welte65e74cc2008-12-29 01:55:35 +0000164 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
165
166 if (msg->lchan) {
Harald Welte8470bf22008-12-25 23:28:35 +0000167 msg->trx = msg->lchan->ts->trx;
Harald Welte52b1f982008-12-23 20:25:15 +0000168
Harald Welte65e74cc2008-12-29 01:55:35 +0000169 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) {
170 /* Send a 04.08 call control message, add transaction
171 * ID and TI flag */
172 gh->proto_discr |= msg->lchan->call.transaction_id;
173
174 /* GSM 04.07 Section 11.2.3.1.3 */
175 switch (msg->lchan->call.type) {
176 case GSM_CT_MO:
177 gh->proto_discr |= 0x80;
178 break;
179 case GSM_CT_MT:
180 break;
181 }
182 }
183 }
184
Harald Welte4b634542008-12-27 01:55:51 +0000185 msg->l3h = msg->data;
186
Harald Welte8470bf22008-12-25 23:28:35 +0000187 return rsl_data_request(msg, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000188}
189
Harald Welte52b1f982008-12-23 20:25:15 +0000190
Holger Freyther429e7762008-12-30 13:28:30 +0000191/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Harald Welte8470bf22008-12-25 23:28:35 +0000192int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000193{
Harald Welte8470bf22008-12-25 23:28:35 +0000194 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000195 struct gsm48_hdr *gh;
196
Harald Welte8470bf22008-12-25 23:28:35 +0000197 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000198
199 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
200 gh->proto_discr = GSM48_PDISC_MM;
Harald Welte10b487b2008-12-27 19:53:37 +0000201 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
Harald Welte52b1f982008-12-23 20:25:15 +0000202 gh->data[0] = cause;
203
Harald Weltedb253af2008-12-30 17:56:55 +0000204 DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr);
205
206 //gsm0411_send_sms(lchan, NULL);
Harald Welte52b1f982008-12-23 20:25:15 +0000207
Harald Welte65e74cc2008-12-29 01:55:35 +0000208 return gsm48_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000209}
210
211/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Harald Welte75a983f2008-12-27 21:34:06 +0000212int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000213{
Harald Welte8470bf22008-12-25 23:28:35 +0000214 struct gsm_bts *bts = lchan->ts->trx->bts;
215 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000216 struct gsm48_hdr *gh;
217 struct gsm48_loc_area_id *lai;
218 u_int8_t *mid;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000219 int ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000220
Harald Welte8470bf22008-12-25 23:28:35 +0000221 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000222
223 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
224 gh->proto_discr = GSM48_PDISC_MM;
225 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
226
227 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Holger Freyther17746612008-12-28 16:32:44 +0000228 gsm0408_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000229 bts->network->network_code, bts->location_area_code);
230
231 mid = msgb_put(msg, MID_TMSI_LEN);
232 generate_mid_from_tmsi(mid, tmsi);
233
Holger Freytherb7193e42008-12-29 17:44:08 +0000234 lchan->pending_update_request = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000235 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
236
Holger Freyther07cc8d82008-12-29 06:23:46 +0000237 /* inform the upper layer on the progress */
Holger Freytherb7193e42008-12-29 17:44:08 +0000238 if (bts->network->update_request)
239 (*bts->network->update_request)(bts, tmsi, 1);
Holger Freyther07cc8d82008-12-29 06:23:46 +0000240
Harald Weltedb253af2008-12-30 17:56:55 +0000241 ret = gsm48_sendmsg(msg);
242
243 /* return gsm48_cc_tx_setup(lchan); */
244 ret = gsm48_tx_mm_info(lchan);
245 ret = gsm0411_send_sms(lchan, NULL);
246
Holger Freyther07cc8d82008-12-29 06:23:46 +0000247 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000248}
249
Harald Weltefc977a82008-12-27 10:19:37 +0000250static char bcd2char(u_int8_t bcd)
251{
252 if (bcd < 0xa)
253 return '0' + bcd;
254 else
255 return 'A' + (bcd - 0xa);
256}
257
258/* 10.5.1.4 */
259static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len)
260{
261 int i;
262 u_int8_t mi_type;
263 char *str_cur = string;
264
265 mi_type = mi[0] & GSM_MI_TYPE_MASK;
266
267 switch (mi_type) {
268 case GSM_MI_TYPE_NONE:
269 break;
270 case GSM_MI_TYPE_TMSI:
Harald Weltedb253af2008-12-30 17:56:55 +0000271 /* skip padding nibble at the beginning, start at offset 1... */
272 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000273 if (str_cur + 2 >= string + str_len)
274 return str_cur - string;
275 *str_cur++ = bcd2char(mi[i] >> 4);
276 *str_cur++ = bcd2char(mi[i] & 0xf);
277 }
278 break;
279 case GSM_MI_TYPE_IMSI:
280 case GSM_MI_TYPE_IMEI:
281 case GSM_MI_TYPE_IMEISV:
Harald Weltedb253af2008-12-30 17:56:55 +0000282 *str_cur++ = bcd2char(mi[0] >> 4);
283
284 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000285 if (str_cur + 2 >= string + str_len)
286 return str_cur - string;
287 *str_cur++ = bcd2char(mi[i] & 0xf);
Harald Weltedb253af2008-12-30 17:56:55 +0000288 /* skip last nibble in last input byte when GSM_EVEN */
289 if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD))
290 *str_cur++ = bcd2char(mi[i] >> 4);
Harald Weltefc977a82008-12-27 10:19:37 +0000291 }
292 break;
293 default:
294 break;
295 }
Harald Weltefc977a82008-12-27 10:19:37 +0000296 *str_cur++ = '\0';
Harald Weltedb253af2008-12-30 17:56:55 +0000297
Harald Weltefc977a82008-12-27 10:19:37 +0000298 return str_cur - string;
299}
300
Harald Welte231ad4f2008-12-27 11:15:38 +0000301/* Chapter 9.2.10 */
302static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
303{
304 struct msgb *msg = gsm48_msgb_alloc();
305 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000306
Harald Welte231ad4f2008-12-27 11:15:38 +0000307 msg->lchan = lchan;
308
309 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
310 gh->proto_discr = GSM48_PDISC_MM;
311 gh->msg_type = GSM48_MT_MM_ID_REQ;
312 gh->data[0] = id_type;
313
Harald Welte65e74cc2008-12-29 01:55:35 +0000314 return gsm48_sendmsg(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000315}
316
317#define MI_SIZE 32
318
319/* Chapter 9.2.11 */
320static int mm_rx_id_resp(struct msgb *msg)
321{
322 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000323 struct gsm_lchan *lchan = msg->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000324 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
325 char mi_string[MI_SIZE];
Harald Welte75a983f2008-12-27 21:34:06 +0000326 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000327
328 mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000329 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000330 mi_type, mi_string);
331
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000332 /*
333 * Rogue messages could trick us but so is life
334 */
335 put_lchan(lchan);
336
Harald Welte75a983f2008-12-27 21:34:06 +0000337 switch (mi_type) {
338 case GSM_MI_TYPE_IMSI:
339 if (!lchan->subscr)
340 lchan->subscr = db_create_subscriber(mi_string);
Holger Freytherb7193e42008-12-29 17:44:08 +0000341
Holger Freyther429e7762008-12-30 13:28:30 +0000342 /* We have a pending UPDATING REQUEST handle it now */
Holger Freytherb7193e42008-12-29 17:44:08 +0000343 if (lchan->pending_update_request) {
Holger Freyther89824fc2008-12-30 16:18:18 +0000344 if (authorize_subscriber(lchan->subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000345 db_subscriber_alloc_tmsi(lchan->subscr);
346 tmsi = strtoul(lchan->subscr->tmsi, NULL, 10);
Holger Freyther1bc7de52008-12-31 18:50:58 +0000347 del_timer(&lchan->updating_timer);
Holger Freytherb7193e42008-12-29 17:44:08 +0000348 return gsm0408_loc_upd_acc(msg->lchan, tmsi);
349 } else {
350 schedule_reject(lchan);
351 }
Harald Welte75a983f2008-12-27 21:34:06 +0000352 }
353 break;
354 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000355 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000356 /* update subscribe <-> IMEI mapping */
357 if (lchan->subscr)
358 db_subscriber_assoc_imei(lchan->subscr, mi_string);
359 break;
360 }
361 return 0;
Harald Welte231ad4f2008-12-27 11:15:38 +0000362}
363
Harald Welte255539c2008-12-28 02:26:27 +0000364
365static void loc_upd_rej_cb(void *data)
366{
367 struct gsm_lchan *lchan = data;
368
Holger Freythere97f7fb2008-12-31 18:52:11 +0000369 gsm0408_loc_upd_rej(lchan, reject_cause);
Harald Welte255539c2008-12-28 02:26:27 +0000370 rsl_chan_release(lchan);
371}
372
Holger Freytherb7193e42008-12-29 17:44:08 +0000373static void schedule_reject(struct gsm_lchan *lchan)
374{
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000375 lchan->updating_timer.cb = loc_upd_rej_cb;
376 lchan->updating_timer.data = lchan;
Holger Freytherea889022008-12-30 19:10:47 +0000377 lchan->pending_update_request = 0;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000378 schedule_timer(&lchan->updating_timer, 1, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000379}
380
Harald Welte231ad4f2008-12-27 11:15:38 +0000381#define MI_SIZE 32
Harald Welte52b1f982008-12-23 20:25:15 +0000382/* Chapter 9.2.15 */
Harald Welte231ad4f2008-12-27 11:15:38 +0000383static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000384{
Harald Welte8470bf22008-12-25 23:28:35 +0000385 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000386 struct gsm_bts *bts = msg->trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000387 struct gsm48_loc_upd_req *lu;
388 struct gsm_subscriber *subscr;
Harald Welte255539c2008-12-28 02:26:27 +0000389 struct gsm_lchan *lchan = msg->lchan;
Harald Welte8470bf22008-12-25 23:28:35 +0000390 u_int8_t mi_type;
Harald Welte75a983f2008-12-27 21:34:06 +0000391 u_int32_t tmsi;
Harald Welte231ad4f2008-12-27 11:15:38 +0000392 char mi_string[MI_SIZE];
393 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000394
Harald Welte8470bf22008-12-25 23:28:35 +0000395 lu = (struct gsm48_loc_upd_req *) gh->data;
396
397 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000398
Harald Weltefc977a82008-12-27 10:19:37 +0000399 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
400
Harald Welte231ad4f2008-12-27 11:15:38 +0000401 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000402 switch (mi_type) {
403 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000404 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000405 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000406 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000407
Harald Welte52b1f982008-12-23 20:25:15 +0000408 /* look up subscriber based on IMSI */
Harald Welte75a983f2008-12-27 21:34:06 +0000409 subscr = db_create_subscriber(mi_string);
Harald Welte4b634542008-12-27 01:55:51 +0000410 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000411 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000412 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000413 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000414 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEISV);
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000415
Harald Welte52b1f982008-12-23 20:25:15 +0000416 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Weltefc977a82008-12-27 10:19:37 +0000417 subscr = subscr_get_by_tmsi(lu->mi);
Harald Welte52b1f982008-12-23 20:25:15 +0000418 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000419 /* send IDENTITY REQUEST message to get IMSI */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000420 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000421 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Harald Welte52b1f982008-12-23 20:25:15 +0000422 }
423 break;
424 case GSM_MI_TYPE_IMEI:
425 case GSM_MI_TYPE_IMEISV:
426 /* no sim card... FIXME: what to do ? */
427 fprintf(stderr, "Unimplemented mobile identity type\n");
428 break;
429 default:
430 fprintf(stderr, "Unknown mobile identity type\n");
431 break;
432 }
433
Harald Welte255539c2008-12-28 02:26:27 +0000434 lchan->subscr = subscr;
435
Holger Freytherb7193e42008-12-29 17:44:08 +0000436 /* we know who we deal with and don't want him */
Holger Freyther89824fc2008-12-30 16:18:18 +0000437 if (subscr && !authorize_subscriber(subscr)) {
Holger Freytherb7193e42008-12-29 17:44:08 +0000438 schedule_reject(lchan);
439 return 0;
440 } else if (!subscr) {
441 /* we have asked for the imsi and should get a
442 * IDENTITY RESPONSE */
443 lchan->pending_update_request = 1;
Harald Welte255539c2008-12-28 02:26:27 +0000444 return 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000445 }
446
Harald Welte75a983f2008-12-27 21:34:06 +0000447 db_subscriber_alloc_tmsi(subscr);
Harald Welte52b1f982008-12-23 20:25:15 +0000448 subscr_update(subscr, bts);
Harald Welte8470bf22008-12-25 23:28:35 +0000449
Harald Welte255539c2008-12-28 02:26:27 +0000450 tmsi = strtoul(subscr->tmsi, NULL, 10);
451
Holger Freyther1bc7de52008-12-31 18:50:58 +0000452 del_timer(&lchan->updating_timer);
Harald Welte255539c2008-12-28 02:26:27 +0000453 return gsm0408_loc_upd_acc(lchan, tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000454}
455
Harald Weltedb253af2008-12-30 17:56:55 +0000456/* Section 9.2.15a */
457int gsm48_tx_mm_info(struct gsm_lchan *lchan)
458{
459 struct msgb *msg = gsm48_msgb_alloc();
460 struct gsm48_hdr *gh;
461 struct gsm_network *net = lchan->ts->trx->bts->network;
462 time_t cur_t;
463 struct tm* cur_time;
464 u_int8_t *ptr8;
465 u_int16_t *ptr16;
466 int name_len;
467 int tz15min;
468 int i;
469
470 msg->lchan = lchan;
471
472 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
473 gh->proto_discr = GSM48_PDISC_MM;
474 gh->msg_type = GSM48_MT_MM_INFO;
475
476 if (net->name_long) {
477 name_len = strlen(net->name_long);
478 /* 10.5.3.5a */
479 ptr8 = msgb_put(msg, 3);
480 ptr8[0] = GSM48_IE_NAME_LONG;
481 ptr8[1] = name_len*2 +1;
482 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
483
484 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
485 for (i = 0; i < name_len; i++)
486 ptr16[i] = net->name_long[i];
487
488 /* FIXME: Use Cell Broadcast, not UCS-2, since
489 * UCS-2 is only supported by later revisions of the spec */
490 }
491
492 if (net->name_short) {
493 name_len = strlen(net->name_short);
494 /* 10.5.3.5a */
495 ptr8 = (u_int8_t *) msgb_put(msg, 3);
496 ptr8[0] = GSM48_IE_NAME_LONG;
497 ptr8[1] = name_len*2 + 1;
498 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
499
500 ptr16 = msgb_put(msg, name_len*2);
501 for (i = 0; i < name_len; i++)
502 ptr16[i] = net->name_short[i];
503 }
504
505#if 0
506 /* Section 10.5.3.9 */
507 cur_t = time(NULL);
508 cur_time = gmtime(cur_t);
509 ptr8 = msgb_put(msg, 8);
510 ptr8[0] = GSM48_IE_NET_TIME_TZ;
511 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
512 ptr8[2] = to_bcd8(cur_time->tm_mon);
513 ptr8[3] = to_bcd8(cur_time->tm_mday);
514 ptr8[4] = to_bcd8(cur_time->tm_hour);
515 ptr8[5] = to_bcd8(cur_time->tm_min);
516 ptr8[6] = to_bcd8(cur_time->tm_sec);
517 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
518 tz15min = (cur_time->tm_gmtoff)/(60*15);
519 ptr8[6] = to_bcd8(tz15min);
520 if (tz15min < 0)
521 ptr8[6] |= 0x80;
522#endif
523
524 return gsm48_sendmsg(msg);
525}
526
Harald Welte4b634542008-12-27 01:55:51 +0000527static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
528{
Harald Welte4b634542008-12-27 01:55:51 +0000529 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Harald Welte65e74cc2008-12-29 01:55:35 +0000530 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000531}
532
533static int gsm48_rx_mm_serv_req(struct msgb *msg)
534{
535 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000536 u_int8_t serv_type = gh->data[0] & 0x0f;
Harald Welte4b634542008-12-27 01:55:51 +0000537
Harald Welte65e74cc2008-12-29 01:55:35 +0000538 DEBUGP(DMM, "<- CM SERVICE REQUEST serv_type=0x%02x\n", serv_type);
Harald Weltebcae43f2008-12-27 21:45:37 +0000539
Harald Welte4b634542008-12-27 01:55:51 +0000540 return gsm48_tx_mm_serv_ack(msg->lchan);
541}
542
Harald Welte52b1f982008-12-23 20:25:15 +0000543static int gsm0408_rcv_mm(struct msgb *msg)
544{
545 struct gsm48_hdr *gh = msgb_l3(msg);
546 int rc;
547
548 switch (gh->msg_type & 0xbf) {
549 case GSM48_MT_MM_LOC_UPD_REQUEST:
Holger Freyther429e7762008-12-30 13:28:30 +0000550 DEBUGP(DMM, "LOCATION UPDATING REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000551 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000552 break;
553 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000554 rc = mm_rx_id_resp(msg);
555 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000556 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000557 rc = gsm48_rx_mm_serv_req(msg);
558 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000559 case GSM48_MT_MM_STATUS:
560 DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n");
561 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000562 case GSM48_MT_MM_CM_REEST_REQ:
Harald Welte231ad4f2008-12-27 11:15:38 +0000563 case GSM48_MT_MM_TMSI_REALL_COMPL:
564 case GSM48_MT_MM_AUTH_RESP:
565 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte52b1f982008-12-23 20:25:15 +0000566 fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n",
567 gh->msg_type);
568 break;
569 default:
570 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
571 gh->msg_type);
572 break;
573 }
574
575 return rc;
576}
577static int gsm0408_rcv_rr(struct msgb *msg)
578{
579 struct gsm48_hdr *gh = msgb_l3(msg);
580
581 switch (gh->msg_type) {
582 case GSM48_MT_RR_CLSM_CHG:
583 DEBUGP(DRR, "CLASSMARK CHANGE\n");
584 /* FIXME: what to do ?!? */
585 break;
Harald Weltefc977a82008-12-27 10:19:37 +0000586 case GSM48_MT_RR_GPRS_SUSP_REQ:
587 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
588 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000589 case GSM48_MT_RR_PAG_RESP:
590 default:
591 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
592 gh->msg_type);
593 break;
594 }
595
596 return 0;
597}
598
Harald Welte4bc90a12008-12-27 16:32:52 +0000599/* Call Control */
600
Harald Welte4bc90a12008-12-27 16:32:52 +0000601static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
602{
603 struct msgb *msg = gsm48_msgb_alloc();
604 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
605 u_int8_t *cause, *call_state;
606
Harald Welte65e74cc2008-12-29 01:55:35 +0000607 gh->proto_discr = GSM48_PDISC_CC;
608
Harald Welte4bc90a12008-12-27 16:32:52 +0000609 msg->lchan = lchan;
610
Harald Welte4bc90a12008-12-27 16:32:52 +0000611 gh->msg_type = GSM48_MT_CC_STATUS;
612
613 cause = msgb_put(msg, 3);
614 cause[0] = 2;
615 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
616 cause[2] = 0x80 | 30; /* response to status inquiry */
617
618 call_state = msgb_put(msg, 1);
619 call_state[0] = 0xc0 | 0x00;
620
Harald Welte65e74cc2008-12-29 01:55:35 +0000621 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000622}
623
Harald Welte6f4b7532008-12-29 00:39:37 +0000624static int gsm48_tx_simple(struct gsm_lchan *lchan,
625 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +0000626{
627 struct msgb *msg = gsm48_msgb_alloc();
628 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
629
630 msg->lchan = lchan;
631
Harald Welte6f4b7532008-12-29 00:39:37 +0000632 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +0000633 gh->msg_type = msg_type;
634
Harald Welte65e74cc2008-12-29 01:55:35 +0000635 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +0000636}
637
638static int gsm48_cc_rx_status_enq(struct msgb *msg)
639{
640 return gsm48_cc_tx_status(msg->lchan);
641}
642
643static int gsm48_cc_rx_setup(struct msgb *msg)
644{
Harald Welte6f4b7532008-12-29 00:39:37 +0000645 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
646 GSM48_MT_CC_CALL_CONF);
Harald Welte4bc90a12008-12-27 16:32:52 +0000647}
648
Harald Welte65e74cc2008-12-29 01:55:35 +0000649int gsm48_cc_tx_setup(struct gsm_lchan *lchan)
650{
651 struct msgb *msg = gsm48_msgb_alloc();
652 struct gsm48_hdr *gh;
653 struct gsm_call *call = &lchan->call;
654
655 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 8);
656
657 call->type = GSM_CT_MT;
658 msg->lchan = lchan;
659
660 gh->proto_discr = GSM48_PDISC_CC;
661 gh->msg_type = GSM48_MT_CC_SETUP;
662 gh->data[0] = 0x34;
663 gh->data[1] = 0x00;
664 gh->data[2] = 0x5c;
665 gh->data[3] = 0x04;
666 gh->data[4] = 0xb9;
667 gh->data[5] = 0x83;
668 gh->data[6] = 0x32;
669 gh->data[7] = 0x24;
670
671 DEBUGP(DCC, "Sending SETUP\n");
672
673 return gsm48_sendmsg(msg);
674}
675
Harald Welte4bc90a12008-12-27 16:32:52 +0000676static int gsm0408_rcv_cc(struct msgb *msg)
677{
678 struct gsm48_hdr *gh = msgb_l3(msg);
679 u_int8_t msg_type = gh->msg_type & 0xbf;
680 struct gsm_call *call = &msg->lchan->call;
Holger Freyther2eafef52008-12-29 06:42:17 +0000681 struct gsm_network *network = msg->lchan->ts->trx->bts->network;
Harald Welte4bc90a12008-12-27 16:32:52 +0000682 int rc = 0;
683
684 switch (msg_type) {
685 case GSM48_MT_CC_CALL_CONF:
686 /* Response to SETUP */
687 DEBUGP(DCC, "CALL CONFIRM\n");
688 break;
689 case GSM48_MT_CC_RELEASE_COMPL:
690 /* Answer from MS to RELEASE */
691 DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n");
Holger Freytherb7193e42008-12-29 17:44:08 +0000692 if (network->call_state_changed)
693 (*network->call_state_changed)(msg->lchan, call->state);
Harald Welte4bc90a12008-12-27 16:32:52 +0000694 call->state = GSM_CSTATE_NULL;
695 break;
696 case GSM48_MT_CC_ALERTING:
697 DEBUGP(DCC, "ALERTING\n");
698 break;
699 case GSM48_MT_CC_CONNECT:
700 DEBUGP(DCC, "CONNECT\n");
701 /* MT: need to respond with CONNECT_ACK */
Harald Welte6f4b7532008-12-29 00:39:37 +0000702 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
703 GSM48_MT_CC_CONNECT_ACK);
Harald Welte4bc90a12008-12-27 16:32:52 +0000704 break;
705 case GSM48_MT_CC_CONNECT_ACK:
706 /* MO: Answer to CONNECT */
707 call->state = GSM_CSTATE_ACTIVE;
708 DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n");
709 break;
710 case GSM48_MT_CC_RELEASE:
711 DEBUGP(DCC, "RELEASE\n");
712 /* need to respond with RELEASE_COMPLETE */
713 break;
714 case GSM48_MT_CC_STATUS_ENQ:
715 rc = gsm48_cc_rx_status_enq(msg);
716 break;
717 case GSM48_MT_CC_DISCONNECT:
718 /* Section 5.4.3.2 */
719 DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n");
720 call->state = GSM_CSTATE_RELEASE_REQ;
721 /* FIXME: clear the network connection */
Harald Welte6f4b7532008-12-29 00:39:37 +0000722 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
723 GSM48_MT_CC_RELEASE);
Harald Welte4bc90a12008-12-27 16:32:52 +0000724 break;
725 case GSM48_MT_CC_SETUP:
726 call->type = GSM_CT_MO;
727 call->state = GSM_CSTATE_INITIATED;
728 call->transaction_id = gh->proto_discr & 0xf0;
729 DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id);
Harald Welte6f4b7532008-12-29 00:39:37 +0000730 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
731 GSM48_MT_CC_CONNECT);
Harald Welte4bc90a12008-12-27 16:32:52 +0000732 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
733 break;
734 case GSM48_MT_CC_EMERG_SETUP:
735 DEBUGP(DCC, "EMERGENCY SETUP\n");
736 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
737 break;
738 default:
739 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
740 msg_type);
741 break;
742 }
743
744 return rc;
745}
746
Harald Welte52b1f982008-12-23 20:25:15 +0000747/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
748int gsm0408_rcvmsg(struct msgb *msg)
749{
750 struct gsm48_hdr *gh = msgb_l3(msg);
751 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +0000752 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000753
754 switch (pdisc) {
755 case GSM48_PDISC_CC:
756 rc = gsm0408_rcv_cc(msg);
757 break;
758 case GSM48_PDISC_MM:
759 rc = gsm0408_rcv_mm(msg);
760 break;
761 case GSM48_PDISC_RR:
762 rc = gsm0408_rcv_rr(msg);
763 break;
Harald Weltebcae43f2008-12-27 21:45:37 +0000764 case GSM48_PDISC_SMS:
Daniel Willmann8b3390e2008-12-28 00:31:09 +0000765 rc = gsm0411_rcv_sms(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +0000766 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000767 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +0000768 case GSM48_PDISC_SM_GPRS:
Harald Welte52b1f982008-12-23 20:25:15 +0000769 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
770 pdisc);
771 break;
772 default:
773 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
774 pdisc);
775 break;
776 }
777
778 return rc;
779}
Harald Welte8470bf22008-12-25 23:28:35 +0000780
781enum chreq_type {
782 CHREQ_T_EMERG_CALL,
783 CHREQ_T_CALL_REEST_TCH_F,
784 CHREQ_T_CALL_REEST_TCH_H,
785 CHREQ_T_CALL_REEST_TCH_H_DBL,
786 CHREQ_T_SDCCH,
787 CHREQ_T_TCH_F,
788 CHREQ_T_VOICE_CALL_TCH_H,
789 CHREQ_T_DATA_CALL_TCH_H,
790 CHREQ_T_LOCATION_UPD,
791 CHREQ_T_PAG_R_ANY,
792 CHREQ_T_PAG_R_TCH_F,
793 CHREQ_T_PAG_R_TCH_FH,
794};
795
796/* Section 9.1.8 / Table 9.9 */
797struct chreq {
798 u_int8_t val;
799 u_int8_t mask;
800 enum chreq_type type;
801};
802
803/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
804static const struct chreq chreq_type_neci1[] = {
805 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
806 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
807 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
808 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
809 { 0xe0, 0xe0, CHREQ_T_SDCCH },
810 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
811 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
812 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
813 { 0x10, 0xf0, CHREQ_T_SDCCH },
814 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
815 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
816 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
817};
818
819/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
820static const struct chreq chreq_type_neci0[] = {
821 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
822 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
823 { 0xe0, 0xe0, CHREQ_T_TCH_F },
824 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
825 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
826 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
827 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
828 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
829};
830
831static const enum gsm_chan_t ctype_by_chreq[] = {
832 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
833 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
834 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
835 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
836 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
837 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
838 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
839 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
840 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
841 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
842 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
843 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
844};
845
Harald Weltee14a57c2008-12-29 04:08:28 +0000846static const enum gsm_chreq_reason_t reason_by_chreq[] = {
847 [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
848 [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
849 [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
850 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
851 [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
852 [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
853 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
854 [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
855 [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
856 [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG,
857 [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
858 [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
859};
860
Harald Welte8470bf22008-12-25 23:28:35 +0000861enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
862{
863 int i;
864 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
865
866 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
867 const struct chreq *chr = &chreq_type_neci0[i];
868 if ((ra & chr->mask) == chr->val)
869 return ctype_by_chreq[chr->type];
870 }
871 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
872 return GSM_LCHAN_SDCCH;
873}
Harald Weltee14a57c2008-12-29 04:08:28 +0000874
875enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra)
876{
877 int i;
878 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
879
880 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
881 const struct chreq *chr = &chreq_type_neci0[i];
882 if ((ra & chr->mask) == chr->val)
883 return reason_by_chreq[chr->type];
884 }
885 fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
886 return GSM_CHREQ_REASON_OTHER;
887}