blob: 447c2631eabf8740bb0cf873e9737cc745a51b69 [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>
Harald Welte8470bf22008-12-25 23:28:35 +00005 *
Harald Welte52b1f982008-12-23 20:25:15 +00006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <errno.h>
Harald Welte4b634542008-12-27 01:55:51 +000029#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000030
Harald Welte8470bf22008-12-25 23:28:35 +000031#include <openbsc/msgb.h>
32#include <openbsc/debug.h>
33#include <openbsc/gsm_data.h>
34#include <openbsc/gsm_subscriber.h>
35#include <openbsc/gsm_04_08.h>
36#include <openbsc/abis_rsl.h>
Harald Welte52b1f982008-12-23 20:25:15 +000037
Harald Welte8470bf22008-12-25 23:28:35 +000038#define GSM48_ALLOC_SIZE 1024
39#define GSM48_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000040
41struct gsm_lai {
42 u_int16_t mcc;
43 u_int16_t mnc;
44 u_int16_t lac;
45};
46
47static void parse_lai(struct gsm_lai *lai, const struct gsm48_loc_area_id *lai48)
48{
49 u_int8_t dig[4];
50
51 /* MCC */
52 dig[1] = lai48->digits[0] & 0x0f;
53 dig[2] = lai48->digits[0] >> 4;
54 dig[3] = lai48->digits[1] & 0x0f;
55 lai->mcc = dig[3] * 100 + dig[2];
56
57 /* MNC */
58 dig[1] = lai48->digits[1] >> 4;
59 dig[2] = lai48->digits[2] & 0x0f;
60 dig[3] = lai48->digits[2] >> 4;
61 lai->mnc = dig[3] * 100 + dig[2];
62
63 lai->lac = lai48->lac;
64}
65
66static void to_bcd(u_int8_t *bcd, u_int16_t val)
67{
Harald Welte4b634542008-12-27 01:55:51 +000068 bcd[2] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +000069 val = val / 10;
70 bcd[1] = val % 10;
71 val = val / 10;
Harald Welte4b634542008-12-27 01:55:51 +000072 bcd[0] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +000073 val = val / 10;
74}
75
76static void generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
77 u_int16_t mnc, u_int16_t lac)
78{
79 u_int8_t bcd[3];
80
81 to_bcd(bcd, mcc);
82 lai48->digits[0] = bcd[0] | (bcd[1] << 4);
83 lai48->digits[1] = bcd[2];
84
85 to_bcd(bcd, mnc);
Harald Welte4b634542008-12-27 01:55:51 +000086 /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
87#if 0
Harald Welte8470bf22008-12-25 23:28:35 +000088 lai48->digits[1] |= bcd[2] << 4;
89 lai48->digits[2] = bcd[0] | (bcd[1] << 4);
Harald Welte4b634542008-12-27 01:55:51 +000090#else
91 lai48->digits[1] |= 0xf << 4;
92 lai48->digits[2] = bcd[1] | (bcd[2] << 4);
93#endif
Harald Welte52b1f982008-12-23 20:25:15 +000094
Harald Welte4b634542008-12-27 01:55:51 +000095 lai48->lac = htons(lac);
Harald Welte52b1f982008-12-23 20:25:15 +000096}
97
98#define TMSI_LEN 4
99#define MID_TMSI_LEN (TMSI_LEN + 2)
100
101static void generate_mid_from_tmsi(u_int8_t *buf, u_int8_t *tmsi_bcd)
102{
Harald Welte4b634542008-12-27 01:55:51 +0000103 buf[0] = GSM48_IE_MOBILE_ID;
104 buf[1] = MID_TMSI_LEN;
105 buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
106 buf[3] = tmsi_bcd[0];
107 buf[4] = tmsi_bcd[1];
108 buf[5] = tmsi_bcd[2];
109 buf[6] = tmsi_bcd[3];
Harald Welte52b1f982008-12-23 20:25:15 +0000110}
111
Harald Welte8470bf22008-12-25 23:28:35 +0000112static struct msgb *gsm48_msgb_alloc(void)
113{
114 return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
115}
116
Harald Welte52b1f982008-12-23 20:25:15 +0000117static int gsm0408_sendmsg(struct msgb *msg)
118{
Harald Welte8470bf22008-12-25 23:28:35 +0000119 if (msg->lchan)
120 msg->trx = msg->lchan->ts->trx;
Harald Welte52b1f982008-12-23 20:25:15 +0000121
Harald Welte4b634542008-12-27 01:55:51 +0000122 msg->l3h = msg->data;
123
Harald Welte8470bf22008-12-25 23:28:35 +0000124 return rsl_data_request(msg, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000125}
126
Harald Welte52b1f982008-12-23 20:25:15 +0000127
128/* Chapter 9.2.14 : Send LOCATION UPDATE REJECT */
Harald Welte8470bf22008-12-25 23:28:35 +0000129int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000130{
Harald Welte8470bf22008-12-25 23:28:35 +0000131 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000132 struct gsm48_hdr *gh;
133
Harald Welte8470bf22008-12-25 23:28:35 +0000134 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000135
136 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
137 gh->proto_discr = GSM48_PDISC_MM;
Harald Welte10b487b2008-12-27 19:53:37 +0000138 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
Harald Welte52b1f982008-12-23 20:25:15 +0000139 gh->data[0] = cause;
140
141 DEBUGP(DMM, "-> LOCATION UPDATE REJECT\n");
142
143 return gsm0408_sendmsg(msg);
144}
145
146/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Harald Welte8470bf22008-12-25 23:28:35 +0000147int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int8_t *tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000148{
Harald Welte8470bf22008-12-25 23:28:35 +0000149 struct gsm_bts *bts = lchan->ts->trx->bts;
150 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000151 struct gsm48_hdr *gh;
152 struct gsm48_loc_area_id *lai;
153 u_int8_t *mid;
154
Harald Welte8470bf22008-12-25 23:28:35 +0000155 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000156
157 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
158 gh->proto_discr = GSM48_PDISC_MM;
159 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
160
161 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
162 generate_lai(lai, bts->network->country_code,
163 bts->network->network_code, bts->location_area_code);
164
165 mid = msgb_put(msg, MID_TMSI_LEN);
166 generate_mid_from_tmsi(mid, tmsi);
167
168 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
169
170 return gsm0408_sendmsg(msg);
171}
172
Harald Weltefc977a82008-12-27 10:19:37 +0000173static char bcd2char(u_int8_t bcd)
174{
175 if (bcd < 0xa)
176 return '0' + bcd;
177 else
178 return 'A' + (bcd - 0xa);
179}
180
181/* 10.5.1.4 */
182static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len)
183{
184 int i;
185 u_int8_t mi_type;
186 char *str_cur = string;
187
188 mi_type = mi[0] & GSM_MI_TYPE_MASK;
189
190 switch (mi_type) {
191 case GSM_MI_TYPE_NONE:
192 break;
193 case GSM_MI_TYPE_TMSI:
194 for (i = 1; i < mi_len - 1; i++) {
195 if (str_cur + 2 >= string + str_len)
196 return str_cur - string;
197 *str_cur++ = bcd2char(mi[i] >> 4);
198 *str_cur++ = bcd2char(mi[i] & 0xf);
199 }
200 break;
201 case GSM_MI_TYPE_IMSI:
202 case GSM_MI_TYPE_IMEI:
203 case GSM_MI_TYPE_IMEISV:
204 if (mi[0] & GSM_MI_ODD)
205 *str_cur++ = bcd2char(mi[0] >> 4);
206
207 for (i = 1; i < mi_len - 1; i++) {
208 if (str_cur + 2 >= string + str_len)
209 return str_cur - string;
210 *str_cur++ = bcd2char(mi[i] & 0xf);
211 *str_cur++ = bcd2char(mi[i] >> 4);
212 }
213 break;
214 default:
215 break;
216 }
217
218 *str_cur++ = '\0';
219 return str_cur - string;
220}
221
Harald Welte231ad4f2008-12-27 11:15:38 +0000222/* Chapter 9.2.10 */
223static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
224{
225 struct msgb *msg = gsm48_msgb_alloc();
226 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000227
Harald Welte231ad4f2008-12-27 11:15:38 +0000228 msg->lchan = lchan;
229
230 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
231 gh->proto_discr = GSM48_PDISC_MM;
232 gh->msg_type = GSM48_MT_MM_ID_REQ;
233 gh->data[0] = id_type;
234
235 return gsm0408_sendmsg(msg);
236}
237
238#define MI_SIZE 32
239
240/* Chapter 9.2.11 */
241static int mm_rx_id_resp(struct msgb *msg)
242{
243 struct gsm48_hdr *gh = msgb_l3(msg);
244 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
245 char mi_string[MI_SIZE];
246
247 mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000248 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000249 mi_type, mi_string);
250
251 /* FIXME: update subscribe <-> IMEI mapping */
252}
253
254#define MI_SIZE 32
Harald Welte52b1f982008-12-23 20:25:15 +0000255/* Chapter 9.2.15 */
Harald Welte231ad4f2008-12-27 11:15:38 +0000256static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000257{
Harald Welte8470bf22008-12-25 23:28:35 +0000258 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte702d8702008-12-26 20:25:35 +0000259 struct gsm_bts *bts = msg->trx->bts;
Harald Welte52b1f982008-12-23 20:25:15 +0000260 struct gsm48_loc_upd_req *lu;
261 struct gsm_subscriber *subscr;
Harald Welte8470bf22008-12-25 23:28:35 +0000262 u_int8_t mi_type;
Harald Welte231ad4f2008-12-27 11:15:38 +0000263 char mi_string[MI_SIZE];
264 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000265
Harald Welte8470bf22008-12-25 23:28:35 +0000266 lu = (struct gsm48_loc_upd_req *) gh->data;
267
268 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000269
Harald Weltefc977a82008-12-27 10:19:37 +0000270 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
271
Harald Welte231ad4f2008-12-27 11:15:38 +0000272 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s)\n", mi_type, mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000273 switch (mi_type) {
274 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000275 /* we always want the IMEI, too */
276 rc = mm_tx_identity_req(msg->lchan, GSM_MI_TYPE_IMEISV);
Harald Welte52b1f982008-12-23 20:25:15 +0000277 /* look up subscriber based on IMSI */
Harald Weltefc977a82008-12-27 10:19:37 +0000278 subscr = subscr_get_by_imsi(lu->mi);
Harald Welte4b634542008-12-27 01:55:51 +0000279 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000280 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000281 /* we always want the IMEI, too */
282 rc = mm_tx_identity_req(msg->lchan, GSM_MI_TYPE_IMEISV);
Harald Welte52b1f982008-12-23 20:25:15 +0000283 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Weltefc977a82008-12-27 10:19:37 +0000284 subscr = subscr_get_by_tmsi(lu->mi);
Harald Welte52b1f982008-12-23 20:25:15 +0000285 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000286 /* send IDENTITY REQUEST message to get IMSI */
287 rc = mm_tx_identity_req(msg->lchan, GSM_MI_TYPE_IMSI);
Harald Welte52b1f982008-12-23 20:25:15 +0000288 }
289 break;
290 case GSM_MI_TYPE_IMEI:
291 case GSM_MI_TYPE_IMEISV:
292 /* no sim card... FIXME: what to do ? */
293 fprintf(stderr, "Unimplemented mobile identity type\n");
294 break;
295 default:
296 fprintf(stderr, "Unknown mobile identity type\n");
297 break;
298 }
299
300 if (!subscr) {
301 /* 0x16 is congestion */
Harald Welte8470bf22008-12-25 23:28:35 +0000302 gsm0408_loc_upd_rej(msg->lchan, 0x16);
Harald Welte98243f82008-12-27 19:46:41 +0000303 rsl_chan_release(msg->lchan);
Harald Welte52b1f982008-12-23 20:25:15 +0000304 return -EINVAL;
305 }
306
Harald Welte8470bf22008-12-25 23:28:35 +0000307 msg->lchan->subscr = subscr;
Harald Welte52b1f982008-12-23 20:25:15 +0000308 subscr_update(subscr, bts);
Harald Welte8470bf22008-12-25 23:28:35 +0000309
310 return gsm0408_loc_upd_acc(msg->lchan, subscr->tmsi);
Harald Welte52b1f982008-12-23 20:25:15 +0000311}
312
Harald Welte4b634542008-12-27 01:55:51 +0000313static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
314{
315 struct msgb *msg = gsm48_msgb_alloc();
316 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
317
318 msg->lchan = lchan;
319
320 gh->proto_discr = GSM48_PDISC_MM;
321 gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
322
323 DEBUGP(DMM, "-> CM SERVICE ACK\n");
324
325 return gsm0408_sendmsg(msg);
326}
327
328static int gsm48_rx_mm_serv_req(struct msgb *msg)
329{
330 struct gsm48_hdr *gh = msgb_l3(msg);
331
332 DEBUGP(DMM, "CM SERVICE REQUEST\n");
333 return gsm48_tx_mm_serv_ack(msg->lchan);
334}
335
Harald Welte52b1f982008-12-23 20:25:15 +0000336static int gsm0408_rcv_mm(struct msgb *msg)
337{
338 struct gsm48_hdr *gh = msgb_l3(msg);
339 int rc;
340
341 switch (gh->msg_type & 0xbf) {
342 case GSM48_MT_MM_LOC_UPD_REQUEST:
343 DEBUGP(DMM, "LOCATION UPDATE REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000344 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000345 break;
346 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000347 rc = mm_rx_id_resp(msg);
348 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000349 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000350 rc = gsm48_rx_mm_serv_req(msg);
351 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000352 case GSM48_MT_MM_STATUS:
353 DEBUGP(DMM, "MM STATUS: FIXME parse error cond.\n");
354 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000355 case GSM48_MT_MM_CM_REEST_REQ:
Harald Welte231ad4f2008-12-27 11:15:38 +0000356 case GSM48_MT_MM_TMSI_REALL_COMPL:
357 case GSM48_MT_MM_AUTH_RESP:
358 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte52b1f982008-12-23 20:25:15 +0000359 fprintf(stderr, "Unimplemented GSM 04.08 MM msg type 0x%02x\n",
360 gh->msg_type);
361 break;
362 default:
363 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
364 gh->msg_type);
365 break;
366 }
367
368 return rc;
369}
370static int gsm0408_rcv_rr(struct msgb *msg)
371{
372 struct gsm48_hdr *gh = msgb_l3(msg);
373
374 switch (gh->msg_type) {
375 case GSM48_MT_RR_CLSM_CHG:
376 DEBUGP(DRR, "CLASSMARK CHANGE\n");
377 /* FIXME: what to do ?!? */
378 break;
Harald Weltefc977a82008-12-27 10:19:37 +0000379 case GSM48_MT_RR_GPRS_SUSP_REQ:
380 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
381 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000382 case GSM48_MT_RR_PAG_RESP:
383 default:
384 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
385 gh->msg_type);
386 break;
387 }
388
389 return 0;
390}
391
Harald Welte4bc90a12008-12-27 16:32:52 +0000392/* Call Control */
393
394/* Send a 04.08 call control message, add transaction ID and TI flag */
395static int gsm48_cc_sendmsg(struct msgb *msg)
396{
397 struct gsm48_hdr *gh = msg->data;
398 struct gsm_call *call = &msg->lchan->call;
399
400 gh->proto_discr |= msg->lchan->call.transaction_id;
401
402 /* GSM 04.07 Section 11.2.3.1.3 */
403 switch (call->type) {
404 case GSM_CT_MO:
405 gh->proto_discr |= 0x80;
406 break;
407 case GSM_CT_MT:
408 break;
409 }
410
411 return gsm0408_sendmsg(msg);
412}
413
414
415static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
416{
417 struct msgb *msg = gsm48_msgb_alloc();
418 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
419 u_int8_t *cause, *call_state;
420
421 msg->lchan = lchan;
422
423 gh->proto_discr = GSM48_PDISC_CC;
424 gh->msg_type = GSM48_MT_CC_STATUS;
425
426 cause = msgb_put(msg, 3);
427 cause[0] = 2;
428 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
429 cause[2] = 0x80 | 30; /* response to status inquiry */
430
431 call_state = msgb_put(msg, 1);
432 call_state[0] = 0xc0 | 0x00;
433
434 return gsm48_cc_sendmsg(msg);
435}
436
437static int gsm48_cc_tx_simple(struct gsm_lchan *lchan, u_int8_t msg_type)
438{
439 struct msgb *msg = gsm48_msgb_alloc();
440 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
441
442 msg->lchan = lchan;
443
444 gh->proto_discr = GSM48_PDISC_CC;
445 gh->msg_type = msg_type;
446
447 return gsm48_cc_sendmsg(msg);
448}
449
450static int gsm48_cc_rx_status_enq(struct msgb *msg)
451{
452 return gsm48_cc_tx_status(msg->lchan);
453}
454
455static int gsm48_cc_rx_setup(struct msgb *msg)
456{
457 return gsm48_cc_tx_simple(msg->lchan, GSM48_MT_CC_CALL_CONF);
458}
459
460static int gsm0408_rcv_cc(struct msgb *msg)
461{
462 struct gsm48_hdr *gh = msgb_l3(msg);
463 u_int8_t msg_type = gh->msg_type & 0xbf;
464 struct gsm_call *call = &msg->lchan->call;
465 int rc = 0;
466
467 switch (msg_type) {
468 case GSM48_MT_CC_CALL_CONF:
469 /* Response to SETUP */
470 DEBUGP(DCC, "CALL CONFIRM\n");
471 break;
472 case GSM48_MT_CC_RELEASE_COMPL:
473 /* Answer from MS to RELEASE */
474 DEBUGP(DCC, "RELEASE COMPLETE (state->NULL)\n");
475 call->state = GSM_CSTATE_NULL;
476 break;
477 case GSM48_MT_CC_ALERTING:
478 DEBUGP(DCC, "ALERTING\n");
479 break;
480 case GSM48_MT_CC_CONNECT:
481 DEBUGP(DCC, "CONNECT\n");
482 /* MT: need to respond with CONNECT_ACK */
483 rc = gsm48_cc_tx_simple(msg->lchan, GSM48_MT_CC_CONNECT_ACK);
484 break;
485 case GSM48_MT_CC_CONNECT_ACK:
486 /* MO: Answer to CONNECT */
487 call->state = GSM_CSTATE_ACTIVE;
488 DEBUGP(DCC, "CONNECT_ACK (state->ACTIVE)\n");
489 break;
490 case GSM48_MT_CC_RELEASE:
491 DEBUGP(DCC, "RELEASE\n");
492 /* need to respond with RELEASE_COMPLETE */
493 break;
494 case GSM48_MT_CC_STATUS_ENQ:
495 rc = gsm48_cc_rx_status_enq(msg);
496 break;
497 case GSM48_MT_CC_DISCONNECT:
498 /* Section 5.4.3.2 */
499 DEBUGP(DCC, "DISCONNECT (state->RELEASE_REQ)\n");
500 call->state = GSM_CSTATE_RELEASE_REQ;
501 /* FIXME: clear the network connection */
502 rc = gsm48_cc_tx_simple(msg->lchan, GSM48_MT_CC_RELEASE);
503 break;
504 case GSM48_MT_CC_SETUP:
505 call->type = GSM_CT_MO;
506 call->state = GSM_CSTATE_INITIATED;
507 call->transaction_id = gh->proto_discr & 0xf0;
508 DEBUGP(DCC, "SETUP(tid=0x%02x)\n", call->transaction_id);
509 rc = gsm48_cc_tx_simple(msg->lchan, GSM48_MT_CC_CONNECT);
510 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
511 break;
512 case GSM48_MT_CC_EMERG_SETUP:
513 DEBUGP(DCC, "EMERGENCY SETUP\n");
514 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
515 break;
516 default:
517 fprintf(stderr, "Unimplemented GSM 04.08 msg type 0x%02x\n",
518 msg_type);
519 break;
520 }
521
522 return rc;
523}
524
Harald Welte52b1f982008-12-23 20:25:15 +0000525/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
526int gsm0408_rcvmsg(struct msgb *msg)
527{
528 struct gsm48_hdr *gh = msgb_l3(msg);
529 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +0000530 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +0000531
532 switch (pdisc) {
533 case GSM48_PDISC_CC:
534 rc = gsm0408_rcv_cc(msg);
535 break;
536 case GSM48_PDISC_MM:
537 rc = gsm0408_rcv_mm(msg);
538 break;
539 case GSM48_PDISC_RR:
540 rc = gsm0408_rcv_rr(msg);
541 break;
542 case GSM48_PDISC_MM_GPRS:
543 case GSM48_PDISC_SM:
544 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
545 pdisc);
546 break;
547 default:
548 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
549 pdisc);
550 break;
551 }
552
553 return rc;
554}
Harald Welte8470bf22008-12-25 23:28:35 +0000555
556enum chreq_type {
557 CHREQ_T_EMERG_CALL,
558 CHREQ_T_CALL_REEST_TCH_F,
559 CHREQ_T_CALL_REEST_TCH_H,
560 CHREQ_T_CALL_REEST_TCH_H_DBL,
561 CHREQ_T_SDCCH,
562 CHREQ_T_TCH_F,
563 CHREQ_T_VOICE_CALL_TCH_H,
564 CHREQ_T_DATA_CALL_TCH_H,
565 CHREQ_T_LOCATION_UPD,
566 CHREQ_T_PAG_R_ANY,
567 CHREQ_T_PAG_R_TCH_F,
568 CHREQ_T_PAG_R_TCH_FH,
569};
570
571/* Section 9.1.8 / Table 9.9 */
572struct chreq {
573 u_int8_t val;
574 u_int8_t mask;
575 enum chreq_type type;
576};
577
578/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
579static const struct chreq chreq_type_neci1[] = {
580 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
581 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
582 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
583 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
584 { 0xe0, 0xe0, CHREQ_T_SDCCH },
585 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
586 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
587 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
588 { 0x10, 0xf0, CHREQ_T_SDCCH },
589 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
590 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
591 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
592};
593
594/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
595static const struct chreq chreq_type_neci0[] = {
596 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
597 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
598 { 0xe0, 0xe0, CHREQ_T_TCH_F },
599 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
600 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
601 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
602 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
603 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
604};
605
606static const enum gsm_chan_t ctype_by_chreq[] = {
607 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
608 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
609 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
610 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
611 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
612 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
613 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
614 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
615 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
616 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
617 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
618 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
619};
620
621enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
622{
623 int i;
624 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
625
626 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
627 const struct chreq *chr = &chreq_type_neci0[i];
628 if ((ra & chr->mask) == chr->val)
629 return ctype_by_chreq[chr->type];
630 }
631 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
632 return GSM_LCHAN_SDCCH;
633}