blob: 80c3771dbebb98994e90df86a7bb1ffe48066363 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
2 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
Harald Weltebf5e8df2009-02-03 12:59:45 +00004/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Harald Welte498b0bb2009-01-09 21:27:43 +00005 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte8470bf22008-12-25 23:28:35 +00006 *
Harald Welte52b1f982008-12-23 20:25:15 +00007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
Harald Weltedb253af2008-12-30 17:56:55 +000030#include <time.h>
Harald Welte4b634542008-12-27 01:55:51 +000031#include <netinet/in.h>
Harald Welte52b1f982008-12-23 20:25:15 +000032
Harald Welte75a983f2008-12-27 21:34:06 +000033#include <openbsc/db.h>
Harald Welte8470bf22008-12-25 23:28:35 +000034#include <openbsc/msgb.h>
Harald Welte7584aea2009-02-11 11:44:12 +000035#include <openbsc/tlv.h>
Harald Welte8470bf22008-12-25 23:28:35 +000036#include <openbsc/debug.h>
37#include <openbsc/gsm_data.h>
38#include <openbsc/gsm_subscriber.h>
Daniel Willmann8b3390e2008-12-28 00:31:09 +000039#include <openbsc/gsm_04_11.h>
Harald Welte8470bf22008-12-25 23:28:35 +000040#include <openbsc/gsm_04_08.h>
41#include <openbsc/abis_rsl.h>
Holger Freytherca362a62009-01-04 21:05:01 +000042#include <openbsc/chan_alloc.h>
Harald Welte0b4c34e2009-02-09 17:54:43 +000043#include <openbsc/paging.h>
Holger Freyther053e09d2009-02-14 22:51:06 +000044#include <openbsc/signal.h>
Harald Welte45b407a2009-05-23 15:51:12 +000045#include <openbsc/trau_frame.h>
Harald Welte11fa29c2009-02-19 17:24:39 +000046#include <openbsc/trau_mux.h>
Harald Welte52b1f982008-12-23 20:25:15 +000047
Harald Welte8470bf22008-12-25 23:28:35 +000048#define GSM48_ALLOC_SIZE 1024
49#define GSM48_ALLOC_HEADROOM 128
Harald Welte52b1f982008-12-23 20:25:15 +000050
Harald Welte09e38af2009-02-16 22:52:23 +000051static const struct tlv_definition rsl_att_tlvdef = {
52 .def = {
53 [GSM48_IE_MOBILE_ID] = { TLV_TYPE_TLV },
54 [GSM48_IE_NAME_LONG] = { TLV_TYPE_TLV },
55 [GSM48_IE_NAME_SHORT] = { TLV_TYPE_TLV },
56 [GSM48_IE_UTC] = { TLV_TYPE_TV },
57 [GSM48_IE_NET_TIME_TZ] = { TLV_TYPE_FIXED, 7 },
58 [GSM48_IE_LSA_IDENT] = { TLV_TYPE_TLV },
59
60 [GSM48_IE_BEARER_CAP] = { TLV_TYPE_TLV },
61 [GSM48_IE_CAUSE] = { TLV_TYPE_TLV },
62 [GSM48_IE_CC_CAP] = { TLV_TYPE_TLV },
63 [GSM48_IE_ALERT] = { TLV_TYPE_TLV },
64 [GSM48_IE_FACILITY] = { TLV_TYPE_TLV },
65 [GSM48_IE_PROGR_IND] = { TLV_TYPE_TLV },
66 [GSM48_IE_AUX_STATUS] = { TLV_TYPE_TLV },
67 [GSM48_IE_KPD_FACILITY] = { TLV_TYPE_TV },
68 [GSM48_IE_SIGNAL] = { TLV_TYPE_TV },
69 [GSM48_IE_CONN_NUM] = { TLV_TYPE_TLV },
70 [GSM48_IE_CONN_SUBADDR] = { TLV_TYPE_TLV },
71 [GSM48_IE_CALLING_BCD] = { TLV_TYPE_TLV },
72 [GSM48_IE_CALLING_SUB] = { TLV_TYPE_TLV },
73 [GSM48_IE_CALLED_BCD] = { TLV_TYPE_TLV },
74 [GSM48_IE_CALLED_SUB] = { TLV_TYPE_TLV },
75 [GSM48_IE_REDIR_BCD] = { TLV_TYPE_TLV },
76 [GSM48_IE_REDIR_SUB] = { TLV_TYPE_TLV },
77 [GSM48_IE_LOWL_COMPAT] = { TLV_TYPE_TLV },
78 [GSM48_IE_HIGHL_COMPAT] = { TLV_TYPE_TLV },
79 [GSM48_IE_USER_USER] = { TLV_TYPE_TLV },
80 [GSM48_IE_SS_VERS] = { TLV_TYPE_TLV },
81 [GSM48_IE_MORE_DATA] = { TLV_TYPE_T },
82 [GSM48_IE_CLIR_SUPP] = { TLV_TYPE_T },
83 [GSM48_IE_CLIR_INVOC] = { TLV_TYPE_T },
84 [GSM48_IE_REV_C_SETUP] = { TLV_TYPE_T },
85 /* FIXME: more elements */
86 },
87};
Harald Weltecf5b3592009-05-01 18:28:42 +000088
89static const char *rr_cause_names[] = {
90 [GSM48_RR_CAUSE_NORMAL] = "Normal event",
91 [GSM48_RR_CAUSE_ABNORMAL_UNSPEC] = "Abnormal release, unspecified",
92 [GSM48_RR_CAUSE_ABNORMAL_UNACCT] = "Abnormal release, channel unacceptable",
93 [GSM48_RR_CAUSE_ABNORMAL_TIMER] = "Abnormal release, timer expired",
94 [GSM48_RR_CAUSE_ABNORMAL_NOACT] = "Abnormal release, no activity on radio path",
95 [GSM48_RR_CAUSE_PREMPTIVE_REL] = "Preemptive release",
96 [GSM48_RR_CAUSE_HNDOVER_IMP] = "Handover impossible, timing advance out of range",
97 [GSM48_RR_CAUSE_CHAN_MODE_UNACCT] = "Channel mode unacceptable",
98 [GSM48_RR_CAUSE_FREQ_NOT_IMPL] = "Frequency not implemented",
99 [GSM48_RR_CAUSE_CALL_CLEARED] = "Call already cleared",
100 [GSM48_RR_CAUSE_SEMANT_INCORR] = "Semantically incorrect message",
101 [GSM48_RR_CAUSE_INVALID_MAND_INF] = "Invalid mandatory information",
102 [GSM48_RR_CAUSE_MSG_TYPE_N] = "Message type non-existant or not implemented",
103 [GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT] = "Message type not compatible with protocol state",
104 [GSM48_RR_CAUSE_COND_IE_ERROR] = "Conditional IE error",
105 [GSM48_RR_CAUSE_NO_CELL_ALLOC_A] = "No cell allocation available",
106 [GSM48_RR_CAUSE_PROT_ERROR_UNSPC] = "Protocol error unspecified",
107};
108
109static char strbuf[64];
110
111static const char *rr_cause_name(u_int8_t cause)
112{
113 if (cause < ARRAY_SIZE(rr_cause_names) &&
114 rr_cause_names[cause])
115 return rr_cause_names[cause];
116
117 snprintf(strbuf, sizeof(strbuf), "0x%02x", cause);
118 return strbuf;
119}
120
Holger Freytherd51524f2009-06-09 08:27:07 +0000121int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi);
Harald Welte65e74cc2008-12-29 01:55:35 +0000122static int gsm48_tx_simple(struct gsm_lchan *lchan,
123 u_int8_t pdisc, u_int8_t msg_type);
Holger Freytherb7193e42008-12-29 17:44:08 +0000124static void schedule_reject(struct gsm_lchan *lchan);
Harald Welte65e74cc2008-12-29 01:55:35 +0000125
Harald Welte52b1f982008-12-23 20:25:15 +0000126struct gsm_lai {
127 u_int16_t mcc;
128 u_int16_t mnc;
129 u_int16_t lac;
130};
131
Holger Freyther89824fc2008-12-30 16:18:18 +0000132static int authorize_everonye = 0;
133void gsm0408_allow_everyone(int everyone)
134{
135 printf("Allowing everyone?\n");
136 authorize_everonye = everyone;
137}
138
Holger Freythere97f7fb2008-12-31 18:52:11 +0000139static int reject_cause = 0;
140void gsm0408_set_reject_cause(int cause)
141{
142 reject_cause = cause;
143}
144
Holger Freyther73487a22008-12-31 18:53:57 +0000145static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
146 struct gsm_subscriber *subscriber)
Holger Freyther89824fc2008-12-30 16:18:18 +0000147{
148 if (!subscriber)
149 return 0;
150
Holger Freyther73487a22008-12-31 18:53:57 +0000151 /*
152 * Do not send accept yet as more information should arrive. Some
153 * phones will not send us the information and we will have to check
154 * what we want to do with that.
155 */
156 if (loc && (loc->waiting_for_imsi || loc->waiting_for_imei))
157 return 0;
158
Holger Freyther89824fc2008-12-30 16:18:18 +0000159 if (authorize_everonye)
160 return 1;
161
162 return subscriber->authorized;
163}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000164
Holger Freyther73487a22008-12-31 18:53:57 +0000165static void release_loc_updating_req(struct gsm_lchan *lchan)
166{
Harald Welte179f0642008-12-31 23:59:18 +0000167 if (!lchan->loc_operation)
Holger Freyther73487a22008-12-31 18:53:57 +0000168 return;
169
Harald Welteff117a82009-05-23 05:22:08 +0000170 bsc_del_timer(&lchan->loc_operation->updating_timer);
Holger Freyther73487a22008-12-31 18:53:57 +0000171 free(lchan->loc_operation);
172 lchan->loc_operation = 0;
Holger Freyther3eaa7922009-01-01 02:59:03 +0000173 put_lchan(lchan);
Holger Freyther73487a22008-12-31 18:53:57 +0000174}
175
176static void allocate_loc_updating_req(struct gsm_lchan *lchan)
177{
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000178 use_lchan(lchan);
Holger Freyther73487a22008-12-31 18:53:57 +0000179 release_loc_updating_req(lchan);
180
181 lchan->loc_operation = (struct gsm_loc_updating_operation *)
182 malloc(sizeof(*lchan->loc_operation));
183 memset(lchan->loc_operation, 0, sizeof(*lchan->loc_operation));
184}
Holger Freyther07cc8d82008-12-29 06:23:46 +0000185
Holger Freytherd51524f2009-06-09 08:27:07 +0000186static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg)
187{
188 u_int32_t tmsi;
189
190 if (authorize_subscriber(lchan->loc_operation, lchan->subscr)) {
191 db_subscriber_alloc_tmsi(lchan->subscr);
192 subscr_update(lchan->subscr, msg->trx->bts, GSM_SUBSCRIBER_UPDATE_ATTACHED);
193 tmsi = strtoul(lchan->subscr->tmsi, NULL, 10);
194 release_loc_updating_req(lchan);
195 return gsm0408_loc_upd_acc(msg->lchan, tmsi);
196 }
197
198 return 0;
199}
200
Holger Freyther7c19f742009-06-06 13:54:35 +0000201static int gsm0408_handle_lchan_signal(unsigned int subsys, unsigned int signal,
202 void *handler_data, void *signal_data)
203{
204 if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE)
205 return 0;
206
207 /*
208 * Cancel any outstanding location updating request
209 * operation taking place on the lchan.
210 */
211 struct gsm_lchan *lchan = (struct gsm_lchan *)handler_data;
212 release_loc_updating_req(lchan);
213
214 return 0;
215}
216
217/*
218 * This will be ran by the linker when loading the DSO. We use it to
219 * do system initialization, e.g. registration of signal handlers.
220 */
221static __attribute__((constructor)) void on_dso_load_0408(void)
222{
223 register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL);
224}
225
Harald Welte52b1f982008-12-23 20:25:15 +0000226static void to_bcd(u_int8_t *bcd, u_int16_t val)
227{
Harald Welte4b634542008-12-27 01:55:51 +0000228 bcd[2] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000229 val = val / 10;
230 bcd[1] = val % 10;
231 val = val / 10;
Harald Welte4b634542008-12-27 01:55:51 +0000232 bcd[0] = val % 10;
Harald Welte52b1f982008-12-23 20:25:15 +0000233 val = val / 10;
234}
235
Holger Freyther17746612008-12-28 16:32:44 +0000236void gsm0408_generate_lai(struct gsm48_loc_area_id *lai48, u_int16_t mcc,
Harald Welte52b1f982008-12-23 20:25:15 +0000237 u_int16_t mnc, u_int16_t lac)
238{
239 u_int8_t bcd[3];
240
241 to_bcd(bcd, mcc);
242 lai48->digits[0] = bcd[0] | (bcd[1] << 4);
243 lai48->digits[1] = bcd[2];
244
245 to_bcd(bcd, mnc);
Harald Welte4b634542008-12-27 01:55:51 +0000246 /* FIXME: do we need three-digit MNC? See Table 10.5.3 */
247#if 0
Harald Welte8470bf22008-12-25 23:28:35 +0000248 lai48->digits[1] |= bcd[2] << 4;
249 lai48->digits[2] = bcd[0] | (bcd[1] << 4);
Harald Welte4b634542008-12-27 01:55:51 +0000250#else
251 lai48->digits[1] |= 0xf << 4;
252 lai48->digits[2] = bcd[1] | (bcd[2] << 4);
253#endif
Harald Welte52b1f982008-12-23 20:25:15 +0000254
Harald Welte4b634542008-12-27 01:55:51 +0000255 lai48->lac = htons(lac);
Harald Welte52b1f982008-12-23 20:25:15 +0000256}
257
Harald Welte255539c2008-12-28 02:26:27 +0000258#define TMSI_LEN 5
Harald Welte52b1f982008-12-23 20:25:15 +0000259#define MID_TMSI_LEN (TMSI_LEN + 2)
260
Harald Welte255539c2008-12-28 02:26:27 +0000261int generate_mid_from_tmsi(u_int8_t *buf, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000262{
Harald Welte65e74cc2008-12-29 01:55:35 +0000263 u_int32_t *tptr = (u_int32_t *) &buf[3];
Harald Welte255539c2008-12-28 02:26:27 +0000264
Harald Welte4b634542008-12-27 01:55:51 +0000265 buf[0] = GSM48_IE_MOBILE_ID;
Harald Welte1a412182008-12-27 22:13:43 +0000266 buf[1] = TMSI_LEN;
Harald Welte4b634542008-12-27 01:55:51 +0000267 buf[2] = 0xf0 | GSM_MI_TYPE_TMSI;
Harald Welte255539c2008-12-28 02:26:27 +0000268 *tptr = htonl(tmsi);
269
270 return 7;
Harald Welte52b1f982008-12-23 20:25:15 +0000271}
272
Harald Welte09e38af2009-02-16 22:52:23 +0000273static const char bcd_num_digits[] = {
274 '0', '1', '2', '3', '4', '5', '6', '7',
275 '8', '9', '*', '#', 'a', 'b', 'c', '\0'
276};
277
278/* decode a 'called party BCD number' as in 10.5.4.7 */
279u_int8_t decode_bcd_number(char *output, int output_len, const u_int8_t *bcd_lv)
280{
281 u_int8_t in_len = bcd_lv[0];
282 int i;
283
284 if (in_len < 1)
285 return 0;
286
287 for (i = 2; i <= in_len; i++) {
288 /* lower nibble */
289 output_len--;
290 if (output_len <= 1)
291 break;
292 *output++ = bcd_num_digits[bcd_lv[i] & 0xf];
293
294 /* higher nibble */
295 output_len--;
296 if (output_len <= 1)
297 break;
298 *output++ = bcd_num_digits[bcd_lv[i] >> 4];
299 }
300 if (output_len >= 1)
301 *output++ = '\0';
302
303 /* return number type / calling plan */
304 return bcd_lv[1] & 0x3f;
305}
306
307/* convert a single ASCII character to call-control BCD */
308static int asc_to_bcd(const char asc)
309{
310 int i;
311
312 for (i = 0; i < ARRAY_SIZE(bcd_num_digits); i++) {
313 if (bcd_num_digits[i] == asc)
314 return i;
315 }
316 return -EINVAL;
317}
318
319/* convert a ASCII phone number to 'called party BCD number' */
320int encode_bcd_number(u_int8_t *bcd_lv, u_int8_t max_len,
321 u_int8_t type, const char *input)
322{
323 int in_len = strlen(input);
324 int i;
325 u_int8_t *bcd_cur = bcd_lv + 2;
326
327 if (in_len/2 + 1 > max_len)
328 return -EIO;
329
330 /* two digits per byte, plus type byte */
331 bcd_lv[0] = in_len/2 + 1;
332 if (in_len % 2)
333 bcd_lv[0]++;
334
335 /* if the caller wants to create a valid 'calling party BCD
336 * number', then the extension bit MUST NOT be set. For the
337 * 'called party BCD number' it MUST be set. *sigh */
338 bcd_lv[1] = type;
339
340 for (i = 0; i < in_len; i++) {
341 int rc = asc_to_bcd(input[i]);
342 if (rc < 0)
343 return rc;
344 if (i % 2 == 0)
345 *bcd_cur = rc;
346 else
347 *bcd_cur++ |= (rc << 4);
348 }
349 /* append padding nibble in case of odd length */
350 if (i % 2)
351 *bcd_cur++ |= 0xf0;
352
353 /* return how many bytes we used */
354 return (bcd_cur - bcd_lv);
355}
356
Holger Freyther819dd202009-01-04 03:52:50 +0000357struct msgb *gsm48_msgb_alloc(void)
Harald Welte8470bf22008-12-25 23:28:35 +0000358{
359 return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
360}
361
Holger Freyther3e2c3232009-01-04 03:55:31 +0000362int gsm48_sendmsg(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000363{
Harald Welte65e74cc2008-12-29 01:55:35 +0000364 struct gsm48_hdr *gh = (struct gsm48_hdr *) msg->data;
365
366 if (msg->lchan) {
Harald Welte8470bf22008-12-25 23:28:35 +0000367 msg->trx = msg->lchan->ts->trx;
Harald Welte52b1f982008-12-23 20:25:15 +0000368
Harald Welte65e74cc2008-12-29 01:55:35 +0000369 if ((gh->proto_discr & GSM48_PDISC_MASK) == GSM48_PDISC_CC) {
370 /* Send a 04.08 call control message, add transaction
371 * ID and TI flag */
372 gh->proto_discr |= msg->lchan->call.transaction_id;
373
374 /* GSM 04.07 Section 11.2.3.1.3 */
375 switch (msg->lchan->call.type) {
376 case GSM_CT_MO:
377 gh->proto_discr |= 0x80;
378 break;
379 case GSM_CT_MT:
380 break;
Holger Freytherca362a62009-01-04 21:05:01 +0000381 case GSM_CT_NONE:
382 break;
Harald Welte65e74cc2008-12-29 01:55:35 +0000383 }
384 }
385 }
386
Harald Welte4b634542008-12-27 01:55:51 +0000387 msg->l3h = msg->data;
388
Harald Welte8470bf22008-12-25 23:28:35 +0000389 return rsl_data_request(msg, 0);
Harald Welte52b1f982008-12-23 20:25:15 +0000390}
391
Harald Welte52b1f982008-12-23 20:25:15 +0000392
Holger Freyther429e7762008-12-30 13:28:30 +0000393/* Chapter 9.2.14 : Send LOCATION UPDATING REJECT */
Harald Welte8470bf22008-12-25 23:28:35 +0000394int gsm0408_loc_upd_rej(struct gsm_lchan *lchan, u_int8_t cause)
Harald Welte52b1f982008-12-23 20:25:15 +0000395{
Harald Welte8470bf22008-12-25 23:28:35 +0000396 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000397 struct gsm48_hdr *gh;
398
Harald Welte8470bf22008-12-25 23:28:35 +0000399 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000400
401 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
402 gh->proto_discr = GSM48_PDISC_MM;
Harald Welte10b487b2008-12-27 19:53:37 +0000403 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
Harald Welte52b1f982008-12-23 20:25:15 +0000404 gh->data[0] = cause;
405
Harald Weltedb253af2008-12-30 17:56:55 +0000406 DEBUGP(DMM, "-> LOCATION UPDATING REJECT on channel: %d\n", lchan->nr);
407
Harald Welte65e74cc2008-12-29 01:55:35 +0000408 return gsm48_sendmsg(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000409}
410
411/* Chapter 9.2.13 : Send LOCATION UPDATE ACCEPT */
Harald Welte75a983f2008-12-27 21:34:06 +0000412int gsm0408_loc_upd_acc(struct gsm_lchan *lchan, u_int32_t tmsi)
Harald Welte52b1f982008-12-23 20:25:15 +0000413{
Harald Welte8470bf22008-12-25 23:28:35 +0000414 struct gsm_bts *bts = lchan->ts->trx->bts;
415 struct msgb *msg = gsm48_msgb_alloc();
Harald Welte52b1f982008-12-23 20:25:15 +0000416 struct gsm48_hdr *gh;
417 struct gsm48_loc_area_id *lai;
418 u_int8_t *mid;
Holger Freyther07cc8d82008-12-29 06:23:46 +0000419 int ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000420
Harald Welte8470bf22008-12-25 23:28:35 +0000421 msg->lchan = lchan;
Harald Welte52b1f982008-12-23 20:25:15 +0000422
423 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
424 gh->proto_discr = GSM48_PDISC_MM;
425 gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
426
427 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
Holger Freyther17746612008-12-28 16:32:44 +0000428 gsm0408_generate_lai(lai, bts->network->country_code,
Harald Welte52b1f982008-12-23 20:25:15 +0000429 bts->network->network_code, bts->location_area_code);
430
431 mid = msgb_put(msg, MID_TMSI_LEN);
432 generate_mid_from_tmsi(mid, tmsi);
433
434 DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
435
Harald Weltedb253af2008-12-30 17:56:55 +0000436 ret = gsm48_sendmsg(msg);
437
Harald Weltedb253af2008-12-30 17:56:55 +0000438 ret = gsm48_tx_mm_info(lchan);
Harald Weltedb253af2008-12-30 17:56:55 +0000439
Holger Freyther07cc8d82008-12-29 06:23:46 +0000440 return ret;
Harald Welte52b1f982008-12-23 20:25:15 +0000441}
442
Harald Weltefc977a82008-12-27 10:19:37 +0000443static char bcd2char(u_int8_t bcd)
444{
445 if (bcd < 0xa)
446 return '0' + bcd;
447 else
448 return 'A' + (bcd - 0xa);
449}
450
Harald Weltebf5e8df2009-02-03 12:59:45 +0000451/* Convert Mobile Identity (10.5.1.4) to string */
Harald Weltefc977a82008-12-27 10:19:37 +0000452static int mi_to_string(char *string, int str_len, u_int8_t *mi, int mi_len)
453{
454 int i;
455 u_int8_t mi_type;
456 char *str_cur = string;
Harald Welte4ed0e922009-01-10 03:17:30 +0000457 u_int32_t tmsi;
Harald Weltefc977a82008-12-27 10:19:37 +0000458
459 mi_type = mi[0] & GSM_MI_TYPE_MASK;
460
461 switch (mi_type) {
462 case GSM_MI_TYPE_NONE:
463 break;
464 case GSM_MI_TYPE_TMSI:
Harald Welte4ed0e922009-01-10 03:17:30 +0000465 /* Table 10.5.4.3, reverse generate_mid_from_tmsi */
466 if (mi_len == TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
467 memcpy(&tmsi, &mi[1], 4);
468 tmsi = ntohl(tmsi);
469 return snprintf(string, str_len, "%u", tmsi);
Harald Weltefc977a82008-12-27 10:19:37 +0000470 }
471 break;
472 case GSM_MI_TYPE_IMSI:
473 case GSM_MI_TYPE_IMEI:
474 case GSM_MI_TYPE_IMEISV:
Harald Weltedb253af2008-12-30 17:56:55 +0000475 *str_cur++ = bcd2char(mi[0] >> 4);
476
477 for (i = 1; i < mi_len; i++) {
Harald Weltefc977a82008-12-27 10:19:37 +0000478 if (str_cur + 2 >= string + str_len)
479 return str_cur - string;
480 *str_cur++ = bcd2char(mi[i] & 0xf);
Harald Weltedb253af2008-12-30 17:56:55 +0000481 /* skip last nibble in last input byte when GSM_EVEN */
482 if( (i != mi_len-1) || (mi[0] & GSM_MI_ODD))
483 *str_cur++ = bcd2char(mi[i] >> 4);
Harald Weltefc977a82008-12-27 10:19:37 +0000484 }
485 break;
486 default:
487 break;
488 }
Harald Weltefc977a82008-12-27 10:19:37 +0000489 *str_cur++ = '\0';
Harald Weltedb253af2008-12-30 17:56:55 +0000490
Harald Weltefc977a82008-12-27 10:19:37 +0000491 return str_cur - string;
492}
493
Harald Weltebf5e8df2009-02-03 12:59:45 +0000494/* Transmit Chapter 9.2.10 Identity Request */
Harald Welte231ad4f2008-12-27 11:15:38 +0000495static int mm_tx_identity_req(struct gsm_lchan *lchan, u_int8_t id_type)
496{
497 struct msgb *msg = gsm48_msgb_alloc();
498 struct gsm48_hdr *gh;
Harald Weltefc977a82008-12-27 10:19:37 +0000499
Harald Welte231ad4f2008-12-27 11:15:38 +0000500 msg->lchan = lchan;
501
502 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
503 gh->proto_discr = GSM48_PDISC_MM;
504 gh->msg_type = GSM48_MT_MM_ID_REQ;
505 gh->data[0] = id_type;
506
Harald Welte65e74cc2008-12-29 01:55:35 +0000507 return gsm48_sendmsg(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000508}
509
510#define MI_SIZE 32
511
Harald Weltebf5e8df2009-02-03 12:59:45 +0000512/* Parse Chapter 9.2.11 Identity Response */
Harald Welte231ad4f2008-12-27 11:15:38 +0000513static int mm_rx_id_resp(struct msgb *msg)
514{
515 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte75a983f2008-12-27 21:34:06 +0000516 struct gsm_lchan *lchan = msg->lchan;
Harald Welte231ad4f2008-12-27 11:15:38 +0000517 u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
518 char mi_string[MI_SIZE];
519
520 mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte61253062008-12-27 11:25:50 +0000521 DEBUGP(DMM, "IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
Harald Welte231ad4f2008-12-27 11:15:38 +0000522 mi_type, mi_string);
523
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000524 /*
525 * Rogue messages could trick us but so is life
526 */
527 put_lchan(lchan);
528
Harald Welte75a983f2008-12-27 21:34:06 +0000529 switch (mi_type) {
530 case GSM_MI_TYPE_IMSI:
531 if (!lchan->subscr)
532 lchan->subscr = db_create_subscriber(mi_string);
Holger Freyther73487a22008-12-31 18:53:57 +0000533 if (lchan->loc_operation)
534 lchan->loc_operation->waiting_for_imsi = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000535 break;
536 case GSM_MI_TYPE_IMEI:
Harald Welte255539c2008-12-28 02:26:27 +0000537 case GSM_MI_TYPE_IMEISV:
Harald Welte75a983f2008-12-27 21:34:06 +0000538 /* update subscribe <-> IMEI mapping */
539 if (lchan->subscr)
540 db_subscriber_assoc_imei(lchan->subscr, mi_string);
Holger Freyther73487a22008-12-31 18:53:57 +0000541 if (lchan->loc_operation)
542 lchan->loc_operation->waiting_for_imei = 0;
Harald Welte75a983f2008-12-27 21:34:06 +0000543 break;
544 }
Holger Freyther73487a22008-12-31 18:53:57 +0000545
546 /* Check if we can let the mobile station enter */
Holger Freytherd51524f2009-06-09 08:27:07 +0000547 return gsm0408_authorize(lchan, msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000548}
549
Harald Welte255539c2008-12-28 02:26:27 +0000550
551static void loc_upd_rej_cb(void *data)
552{
553 struct gsm_lchan *lchan = data;
554
Holger Freyther73487a22008-12-31 18:53:57 +0000555 release_loc_updating_req(lchan);
Holger Freythere97f7fb2008-12-31 18:52:11 +0000556 gsm0408_loc_upd_rej(lchan, reject_cause);
Holger Freyther67b4b9a2009-01-01 03:46:11 +0000557 lchan_auto_release(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000558}
559
Holger Freytherb7193e42008-12-29 17:44:08 +0000560static void schedule_reject(struct gsm_lchan *lchan)
561{
Holger Freyther73487a22008-12-31 18:53:57 +0000562 lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb;
563 lchan->loc_operation->updating_timer.data = lchan;
Harald Welteff117a82009-05-23 05:22:08 +0000564 bsc_schedule_timer(&lchan->loc_operation->updating_timer, 5, 0);
Holger Freytherb7193e42008-12-29 17:44:08 +0000565}
566
Harald Welte2a139372009-02-22 21:14:55 +0000567static const char *lupd_name(u_int8_t type)
568{
569 switch (type) {
570 case GSM48_LUPD_NORMAL:
571 return "NORMAL";
572 case GSM48_LUPD_PERIODIC:
573 return "PEROIDOC";
574 case GSM48_LUPD_IMSI_ATT:
575 return "IMSI ATTACH";
576 default:
577 return "UNKNOWN";
578 }
579}
580
Harald Welte231ad4f2008-12-27 11:15:38 +0000581#define MI_SIZE 32
Harald Weltebf5e8df2009-02-03 12:59:45 +0000582/* Chapter 9.2.15: Receive Location Updating Request */
Harald Welte231ad4f2008-12-27 11:15:38 +0000583static int mm_rx_loc_upd_req(struct msgb *msg)
Harald Welte52b1f982008-12-23 20:25:15 +0000584{
Harald Welte8470bf22008-12-25 23:28:35 +0000585 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000586 struct gsm48_loc_upd_req *lu;
587 struct gsm_subscriber *subscr;
Harald Welte255539c2008-12-28 02:26:27 +0000588 struct gsm_lchan *lchan = msg->lchan;
Harald Welte8470bf22008-12-25 23:28:35 +0000589 u_int8_t mi_type;
Harald Welte231ad4f2008-12-27 11:15:38 +0000590 char mi_string[MI_SIZE];
591 int rc;
Harald Welte52b1f982008-12-23 20:25:15 +0000592
Harald Welte8470bf22008-12-25 23:28:35 +0000593 lu = (struct gsm48_loc_upd_req *) gh->data;
594
595 mi_type = lu->mi[0] & GSM_MI_TYPE_MASK;
Harald Welte52b1f982008-12-23 20:25:15 +0000596
Harald Weltefc977a82008-12-27 10:19:37 +0000597 mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
598
Holger Freyther79f4ae62009-06-02 03:25:04 +0000599 DEBUGP(DMM, "LUPDREQ: mi_type=0x%02x MI(%s) type=%s\n", mi_type, mi_string,
Harald Welte2a139372009-02-22 21:14:55 +0000600 lupd_name(lu->type));
Holger Freyther73487a22008-12-31 18:53:57 +0000601
Holger Freythereaf04692009-06-06 13:54:44 +0000602 /*
603 * Pseudo Spoof detection: Just drop a second/concurrent
604 * location updating request.
605 */
606 if (lchan->loc_operation) {
607 DEBUGP(DMM, "LUPDREQ: ignoring request due an existing one: %p.\n",
608 lchan->loc_operation);
609 gsm0408_loc_upd_rej(lchan, GSM48_REJECT_PROTOCOL_ERROR);
610 return 0;
611 }
612
Holger Freyther73487a22008-12-31 18:53:57 +0000613 allocate_loc_updating_req(lchan);
614
Harald Welte52b1f982008-12-23 20:25:15 +0000615 switch (mi_type) {
616 case GSM_MI_TYPE_IMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000617 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000618 use_lchan(lchan);
Harald Welte015b9ad2009-02-28 18:22:03 +0000619 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
Holger Freyther73487a22008-12-31 18:53:57 +0000620 lchan->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000621
Harald Welte52b1f982008-12-23 20:25:15 +0000622 /* look up subscriber based on IMSI */
Harald Welte75a983f2008-12-27 21:34:06 +0000623 subscr = db_create_subscriber(mi_string);
Harald Welte4b634542008-12-27 01:55:51 +0000624 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000625 case GSM_MI_TYPE_TMSI:
Harald Welte231ad4f2008-12-27 11:15:38 +0000626 /* we always want the IMEI, too */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000627 use_lchan(lchan);
Harald Welte015b9ad2009-02-28 18:22:03 +0000628 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMEI);
Holger Freyther73487a22008-12-31 18:53:57 +0000629 lchan->loc_operation->waiting_for_imei = 1;
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000630
Harald Welte52b1f982008-12-23 20:25:15 +0000631 /* look up the subscriber based on TMSI, request IMSI if it fails */
Harald Welteba4cf162009-01-10 01:49:35 +0000632 subscr = subscr_get_by_tmsi(mi_string);
Harald Welte52b1f982008-12-23 20:25:15 +0000633 if (!subscr) {
Harald Welte231ad4f2008-12-27 11:15:38 +0000634 /* send IDENTITY REQUEST message to get IMSI */
Holger Freytherc6ea9db2008-12-30 19:18:21 +0000635 use_lchan(lchan);
Harald Welte255539c2008-12-28 02:26:27 +0000636 rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
Holger Freyther73487a22008-12-31 18:53:57 +0000637 lchan->loc_operation->waiting_for_imsi = 1;
Harald Welte52b1f982008-12-23 20:25:15 +0000638 }
639 break;
640 case GSM_MI_TYPE_IMEI:
641 case GSM_MI_TYPE_IMEISV:
642 /* no sim card... FIXME: what to do ? */
Harald Welte2a139372009-02-22 21:14:55 +0000643 DEBUGP(DMM, "unimplemented mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000644 break;
645 default:
Harald Welte2a139372009-02-22 21:14:55 +0000646 DEBUGP(DMM, "unknown mobile identity type\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000647 break;
648 }
649
Harald Welte255539c2008-12-28 02:26:27 +0000650 lchan->subscr = subscr;
651
Holger Freyther73487a22008-12-31 18:53:57 +0000652 /*
653 * Schedule the reject timer and check if we can let the
654 * subscriber into our network immediately or if we need to wait
655 * for identity responses.
656 */
657 schedule_reject(lchan);
Holger Freytherd51524f2009-06-09 08:27:07 +0000658 return gsm0408_authorize(lchan, msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000659}
660
Harald Welte7584aea2009-02-11 11:44:12 +0000661/* 9.1.5 Channel mode modify */
662int gsm48_tx_chan_mode_modify(struct gsm_lchan *lchan, u_int8_t mode)
663{
664 struct msgb *msg = gsm48_msgb_alloc();
665 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
666 struct gsm48_chan_mode_modify *cmm =
667 (struct gsm48_chan_mode_modify *) msgb_put(msg, sizeof(*cmm));
Harald Welte4a543e82009-02-28 13:17:55 +0000668 u_int16_t arfcn = lchan->ts->trx->arfcn & 0x3ff;
Harald Welte7584aea2009-02-11 11:44:12 +0000669
Harald Welte4a543e82009-02-28 13:17:55 +0000670 DEBUGP(DRR, "-> CHANNEL MODE MODIFY mode=0x%02x\n", mode);
Harald Welte7ccf7782009-02-17 01:43:01 +0000671
Harald Welte45b407a2009-05-23 15:51:12 +0000672 lchan->tch_mode = mode;
Harald Welte7584aea2009-02-11 11:44:12 +0000673 msg->lchan = lchan;
674 gh->proto_discr = GSM48_PDISC_RR;
675 gh->msg_type = GSM48_MT_RR_CHAN_MODE_MODIF;
676
677 /* fill the channel information element, this code
678 * should probably be shared with rsl_rx_chan_rqd() */
679 cmm->chan_desc.chan_nr = lchan2chan_nr(lchan);
Harald Welte02b0e092009-02-28 13:11:07 +0000680 cmm->chan_desc.h0.tsc = lchan->ts->trx->bts->tsc;
Harald Welte7584aea2009-02-11 11:44:12 +0000681 cmm->chan_desc.h0.h = 0;
682 cmm->chan_desc.h0.arfcn_high = arfcn >> 8;
683 cmm->chan_desc.h0.arfcn_low = arfcn & 0xff;
684 cmm->mode = mode;
685
686 return gsm48_sendmsg(msg);
687}
688
Harald Weltedb253af2008-12-30 17:56:55 +0000689/* Section 9.2.15a */
690int gsm48_tx_mm_info(struct gsm_lchan *lchan)
691{
692 struct msgb *msg = gsm48_msgb_alloc();
693 struct gsm48_hdr *gh;
694 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Weltedb253af2008-12-30 17:56:55 +0000695 u_int8_t *ptr8;
696 u_int16_t *ptr16;
697 int name_len;
Harald Weltedb253af2008-12-30 17:56:55 +0000698 int i;
699
700 msg->lchan = lchan;
701
702 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
703 gh->proto_discr = GSM48_PDISC_MM;
704 gh->msg_type = GSM48_MT_MM_INFO;
705
706 if (net->name_long) {
707 name_len = strlen(net->name_long);
708 /* 10.5.3.5a */
709 ptr8 = msgb_put(msg, 3);
710 ptr8[0] = GSM48_IE_NAME_LONG;
711 ptr8[1] = name_len*2 +1;
712 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
713
714 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
715 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000716 ptr16[i] = htons(net->name_long[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000717
718 /* FIXME: Use Cell Broadcast, not UCS-2, since
719 * UCS-2 is only supported by later revisions of the spec */
720 }
721
722 if (net->name_short) {
723 name_len = strlen(net->name_short);
724 /* 10.5.3.5a */
725 ptr8 = (u_int8_t *) msgb_put(msg, 3);
726 ptr8[0] = GSM48_IE_NAME_LONG;
727 ptr8[1] = name_len*2 + 1;
728 ptr8[2] = 0x90; /* UCS2, no spare bits, no CI */
729
Harald Weltee872cb12009-01-01 00:33:37 +0000730 ptr16 = (u_int16_t *) msgb_put(msg, name_len*2);
Harald Weltedb253af2008-12-30 17:56:55 +0000731 for (i = 0; i < name_len; i++)
Harald Welte179f0642008-12-31 23:59:18 +0000732 ptr16[i] = htons(net->name_short[i]);
Harald Weltedb253af2008-12-30 17:56:55 +0000733 }
734
735#if 0
Holger Freytherca362a62009-01-04 21:05:01 +0000736 /* move back to the top */
737 time_t cur_t;
738 struct tm* cur_time;
739 int tz15min;
Harald Weltedb253af2008-12-30 17:56:55 +0000740 /* Section 10.5.3.9 */
741 cur_t = time(NULL);
742 cur_time = gmtime(cur_t);
743 ptr8 = msgb_put(msg, 8);
744 ptr8[0] = GSM48_IE_NET_TIME_TZ;
745 ptr8[1] = to_bcd8(cur_time->tm_year % 100);
746 ptr8[2] = to_bcd8(cur_time->tm_mon);
747 ptr8[3] = to_bcd8(cur_time->tm_mday);
748 ptr8[4] = to_bcd8(cur_time->tm_hour);
749 ptr8[5] = to_bcd8(cur_time->tm_min);
750 ptr8[6] = to_bcd8(cur_time->tm_sec);
751 /* 02.42: coded as BCD encoded signed value in units of 15 minutes */
752 tz15min = (cur_time->tm_gmtoff)/(60*15);
753 ptr8[6] = to_bcd8(tz15min);
754 if (tz15min < 0)
755 ptr8[6] |= 0x80;
756#endif
757
758 return gsm48_sendmsg(msg);
759}
760
Harald Welte4b634542008-12-27 01:55:51 +0000761static int gsm48_tx_mm_serv_ack(struct gsm_lchan *lchan)
762{
Harald Welte4b634542008-12-27 01:55:51 +0000763 DEBUGP(DMM, "-> CM SERVICE ACK\n");
Harald Welte65e74cc2008-12-29 01:55:35 +0000764 return gsm48_tx_simple(lchan, GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_ACC);
Harald Welte4b634542008-12-27 01:55:51 +0000765}
Harald Welteba4cf162009-01-10 01:49:35 +0000766
767/* 9.2.6 CM service reject */
768static int gsm48_tx_mm_serv_rej(struct gsm_lchan *lchan,
769 enum gsm48_reject_value value)
770{
771 struct msgb *msg = gsm48_msgb_alloc();
772 struct gsm48_hdr *gh;
773
774 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
775
776 msg->lchan = lchan;
777 use_lchan(lchan);
778
779 gh->proto_discr = GSM48_PDISC_MM;
780 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
781 gh->data[0] = value;
782 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
783
784 return gsm48_sendmsg(msg);
785}
786
Harald Welte4ed0e922009-01-10 03:17:30 +0000787
788/*
789 * Handle CM Service Requests
790 * a) Verify that the packet is long enough to contain the information
791 * we require otherwsie reject with INCORRECT_MESSAGE
792 * b) Try to parse the TMSI. If we do not have one reject
793 * c) Check that we know the subscriber with the TMSI otherwise reject
794 * with a HLR cause
795 * d) Set the subscriber on the gsm_lchan and accept
796 */
Harald Welte4b634542008-12-27 01:55:51 +0000797static int gsm48_rx_mm_serv_req(struct msgb *msg)
798{
Harald Welteba4cf162009-01-10 01:49:35 +0000799 u_int8_t mi_type;
Harald Welte4ed0e922009-01-10 03:17:30 +0000800 char mi_string[MI_SIZE];
Harald Welte4b634542008-12-27 01:55:51 +0000801
Harald Welteba4cf162009-01-10 01:49:35 +0000802 struct gsm_subscriber *subscr;
803 struct gsm48_hdr *gh = msgb_l3(msg);
804 struct gsm48_service_request *req =
805 (struct gsm48_service_request *)gh->data;
Harald Weltec9e02182009-05-01 19:07:53 +0000806 /* unfortunately in Phase1 the classmar2 length is variable */
807 u_int8_t classmark2_len = gh->data[1];
808 u_int8_t *classmark2 = gh->data+2;
809 u_int8_t mi_len = *(classmark2 + classmark2_len);
810 u_int8_t *mi = (classmark2 + classmark2_len + 1);
Harald Welteba4cf162009-01-10 01:49:35 +0000811
Harald Weltec9e02182009-05-01 19:07:53 +0000812 DEBUGP(DMM, "<- CM SERVICE REQUEST ");
Harald Welteba4cf162009-01-10 01:49:35 +0000813 if (msg->data_len < sizeof(struct gsm48_service_request*)) {
Harald Weltec9e02182009-05-01 19:07:53 +0000814 DEBUGPC(DMM, "wrong sized message\n");
Harald Welteba4cf162009-01-10 01:49:35 +0000815 return gsm48_tx_mm_serv_rej(msg->lchan,
816 GSM48_REJECT_INCORRECT_MESSAGE);
817 }
818
819 if (msg->data_len < req->mi_len + 6) {
Harald Weltec9e02182009-05-01 19:07:53 +0000820 DEBUGPC(DMM, "does not fit in packet\n");
Harald Welteba4cf162009-01-10 01:49:35 +0000821 return gsm48_tx_mm_serv_rej(msg->lchan,
822 GSM48_REJECT_INCORRECT_MESSAGE);
823 }
824
Harald Weltec9e02182009-05-01 19:07:53 +0000825 mi_type = mi[0] & GSM_MI_TYPE_MASK;
Harald Welteba4cf162009-01-10 01:49:35 +0000826 if (mi_type != GSM_MI_TYPE_TMSI) {
Harald Weltec9e02182009-05-01 19:07:53 +0000827 DEBUGPC(DMM, "mi_type is not TMSI: %d\n", mi_type);
Harald Welteba4cf162009-01-10 01:49:35 +0000828 return gsm48_tx_mm_serv_rej(msg->lchan,
829 GSM48_REJECT_INCORRECT_MESSAGE);
830 }
831
Harald Weltec9e02182009-05-01 19:07:53 +0000832 mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
Harald Weltec9e02182009-05-01 19:07:53 +0000833 DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
Harald Welte4ed0e922009-01-10 03:17:30 +0000834 req->cm_service_type, mi_type, mi_string);
Harald Weltebcae43f2008-12-27 21:45:37 +0000835
Holger Freythereb443982009-06-04 13:58:42 +0000836 subscr = subscr_get_by_tmsi(mi_string);
837
Harald Welte2a139372009-02-22 21:14:55 +0000838 /* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
Harald Welte4ed0e922009-01-10 03:17:30 +0000839 if (!subscr)
840 return gsm48_tx_mm_serv_rej(msg->lchan,
841 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR);
842
843 if (!msg->lchan->subscr)
844 msg->lchan->subscr = subscr;
Harald Welte9bb7c702009-01-10 03:21:41 +0000845 else if (msg->lchan->subscr != subscr) {
846 DEBUGP(DMM, "<- CM Channel already owned by someone else?\n");
847 subscr_put(subscr);
848 }
849
Harald Welte4b634542008-12-27 01:55:51 +0000850 return gsm48_tx_mm_serv_ack(msg->lchan);
851}
852
Harald Welte2a139372009-02-22 21:14:55 +0000853static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
854{
855 struct gsm48_hdr *gh = msgb_l3(msg);
856 struct gsm48_imsi_detach_ind *idi =
857 (struct gsm48_imsi_detach_ind *) gh->data;
858 u_int8_t mi_type = idi->mi[0] & GSM_MI_TYPE_MASK;
859 char mi_string[MI_SIZE];
860 struct gsm_subscriber *subscr;
861
862 mi_to_string(mi_string, sizeof(mi_string), idi->mi, idi->mi_len);
863 DEBUGP(DMM, "IMSI DETACH INDICATION: mi_type=0x%02x MI(%s): ",
864 mi_type, mi_string);
865
866 switch (mi_type) {
867 case GSM_MI_TYPE_TMSI:
868 subscr = subscr_get_by_tmsi(mi_string);
869 break;
870 case GSM_MI_TYPE_IMSI:
871 subscr = subscr_get_by_imsi(mi_string);
872 break;
873 case GSM_MI_TYPE_IMEI:
874 case GSM_MI_TYPE_IMEISV:
875 /* no sim card... FIXME: what to do ? */
Holger Freyther79f4ae62009-06-02 03:25:04 +0000876 DEBUGPC(DMM, "unimplemented mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000877 break;
878 default:
Holger Freyther79f4ae62009-06-02 03:25:04 +0000879 DEBUGPC(DMM, "unknown mobile identity type\n");
Harald Welte2a139372009-02-22 21:14:55 +0000880 break;
881 }
882
Holger Freyther4a49e772009-04-12 05:37:29 +0000883 if (subscr) {
884 subscr_update(subscr, msg->trx->bts,
885 GSM_SUBSCRIBER_UPDATE_DETACHED);
Harald Welte2a139372009-02-22 21:14:55 +0000886 DEBUGP(DMM, "Subscriber: %s\n",
887 subscr->name ? subscr->name : subscr->imsi);
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000888 subscr_put(subscr);
Holger Freyther4a49e772009-04-12 05:37:29 +0000889 } else
Harald Welte2a139372009-02-22 21:14:55 +0000890 DEBUGP(DMM, "Unknown Subscriber ?!?\n");
891
892 put_lchan(msg->lchan);
893
894 return 0;
895}
896
Harald Welted2a7f5a2009-06-05 20:08:20 +0000897static int gsm48_rx_mm_status(struct msgb *msg)
898{
899 struct gsm48_hdr *gh = msgb_l3(msg);
900
901 DEBUGP(DMM, "MM STATUS (reject cause 0x%02x)\n", gh->data[0]);
902
903 return 0;
904}
905
Harald Weltebf5e8df2009-02-03 12:59:45 +0000906/* Receive a GSM 04.08 Mobility Management (MM) message */
Harald Welte52b1f982008-12-23 20:25:15 +0000907static int gsm0408_rcv_mm(struct msgb *msg)
908{
909 struct gsm48_hdr *gh = msgb_l3(msg);
910 int rc;
911
912 switch (gh->msg_type & 0xbf) {
913 case GSM48_MT_MM_LOC_UPD_REQUEST:
Holger Freyther429e7762008-12-30 13:28:30 +0000914 DEBUGP(DMM, "LOCATION UPDATING REQUEST\n");
Harald Welte231ad4f2008-12-27 11:15:38 +0000915 rc = mm_rx_loc_upd_req(msg);
Harald Welte52b1f982008-12-23 20:25:15 +0000916 break;
917 case GSM48_MT_MM_ID_RESP:
Harald Welte231ad4f2008-12-27 11:15:38 +0000918 rc = mm_rx_id_resp(msg);
919 break;
Harald Welte52b1f982008-12-23 20:25:15 +0000920 case GSM48_MT_MM_CM_SERV_REQ:
Harald Welte4b634542008-12-27 01:55:51 +0000921 rc = gsm48_rx_mm_serv_req(msg);
922 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000923 case GSM48_MT_MM_STATUS:
Harald Welted2a7f5a2009-06-05 20:08:20 +0000924 rc = gsm48_rx_mm_status(msg);
Harald Welte231ad4f2008-12-27 11:15:38 +0000925 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000926 case GSM48_MT_MM_TMSI_REALL_COMPL:
Harald Welte69b2af22009-01-06 19:47:00 +0000927 DEBUGP(DMM, "TMSI Reallocation Completed. Subscriber: %s\n",
928 msg->lchan->subscr ?
929 msg->lchan->subscr->imsi :
930 "unknown subscriber");
931 break;
Harald Welte231ad4f2008-12-27 11:15:38 +0000932 case GSM48_MT_MM_IMSI_DETACH_IND:
Harald Welte2a139372009-02-22 21:14:55 +0000933 rc = gsm48_rx_mm_imsi_detach_ind(msg);
934 break;
935 case GSM48_MT_MM_CM_REEST_REQ:
936 DEBUGP(DMM, "CM REESTABLISH REQUEST: Not implemented\n");
937 break;
938 case GSM48_MT_MM_AUTH_RESP:
939 DEBUGP(DMM, "AUTHENTICATION RESPONSE: Not implemented\n");
Harald Welte52b1f982008-12-23 20:25:15 +0000940 break;
941 default:
942 fprintf(stderr, "Unknown GSM 04.08 MM msg type 0x%02x\n",
943 gh->msg_type);
944 break;
945 }
946
947 return rc;
948}
Harald Weltebf5e8df2009-02-03 12:59:45 +0000949
Harald Welte2d35ae62009-02-06 12:02:13 +0000950/* Receive a PAGING RESPONSE message from the MS */
951static int gsm48_rr_rx_pag_resp(struct msgb *msg)
952{
953 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte61548982009-02-22 21:26:29 +0000954 u_int8_t *classmark2_lv = gh->data + 1;
955 u_int8_t *mi_lv = gh->data + 2 + *classmark2_lv;
956 u_int8_t mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
Harald Welte2d35ae62009-02-06 12:02:13 +0000957 char mi_string[MI_SIZE];
958 struct gsm_subscriber *subscr;
Harald Welte595ad7b2009-02-16 22:05:44 +0000959 struct paging_signal_data sig_data;
Harald Welte2d35ae62009-02-06 12:02:13 +0000960 int rc = 0;
961
Harald Welte61548982009-02-22 21:26:29 +0000962 mi_to_string(mi_string, sizeof(mi_string), mi_lv+1, *mi_lv);
Harald Welte2d35ae62009-02-06 12:02:13 +0000963 DEBUGP(DRR, "PAGING RESPONSE: mi_type=0x%02x MI(%s)\n",
964 mi_type, mi_string);
Harald Weltefe18d8f2009-02-22 21:14:24 +0000965 switch (mi_type) {
966 case GSM_MI_TYPE_TMSI:
967 subscr = subscr_get_by_tmsi(mi_string);
968 break;
969 case GSM_MI_TYPE_IMSI:
970 subscr = subscr_get_by_imsi(mi_string);
971 break;
972 }
Harald Welte2d35ae62009-02-06 12:02:13 +0000973
974 if (!subscr) {
975 DEBUGP(DRR, "<- Can't find any subscriber for this ID\n");
Harald Welte09e38af2009-02-16 22:52:23 +0000976 /* FIXME: request id? close channel? */
Harald Welte2d35ae62009-02-06 12:02:13 +0000977 return -EINVAL;
978 }
979 DEBUGP(DRR, "<- Channel was requested by %s\n",
980 subscr->name ? subscr->name : subscr->imsi);
Holger Freyther053e09d2009-02-14 22:51:06 +0000981
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000982 if (!msg->lchan->subscr) {
Holger Freyther2fa4cb52009-02-14 23:53:15 +0000983 msg->lchan->subscr = subscr;
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000984 } else if (msg->lchan->subscr != subscr) {
Holger Freyther2fa4cb52009-02-14 23:53:15 +0000985 DEBUGP(DRR, "<- Channel already owned by someone else?\n");
986 subscr_put(subscr);
Holger Freytherc21cfbc2009-06-02 02:54:57 +0000987 return -EINVAL;
988 } else {
989 DEBUGP(DRR, "<- Channel already owned by us\n");
990 subscr_put(subscr);
991 subscr = msg->lchan->subscr;
Holger Freyther2fa4cb52009-02-14 23:53:15 +0000992 }
993
Harald Welte595ad7b2009-02-16 22:05:44 +0000994 sig_data.subscr = subscr;
995 sig_data.bts = msg->lchan->ts->trx->bts;
996 sig_data.lchan = msg->lchan;
997
998 dispatch_signal(SS_PAGING, S_PAGING_COMPLETED, &sig_data);
Harald Welte7ccf7782009-02-17 01:43:01 +0000999 paging_request_stop(msg->trx->bts, subscr, msg->lchan);
Harald Welte2d35ae62009-02-06 12:02:13 +00001000
Harald Welte7584aea2009-02-11 11:44:12 +00001001 /* FIXME: somehow signal the completion of the PAGING to
1002 * the entity that requested the paging */
1003
Harald Welte2d35ae62009-02-06 12:02:13 +00001004 return rc;
1005}
1006
Harald Weltecf5b3592009-05-01 18:28:42 +00001007static int gsm48_rx_rr_status(struct msgb *msg)
1008{
1009 struct gsm48_hdr *gh = msgb_l3(msg);
1010
1011 DEBUGP(DRR, "STATUS rr_cause = %s\n",
1012 rr_cause_name(gh->data[0]));
1013
1014 return 0;
1015}
1016
Harald Weltebf5e8df2009-02-03 12:59:45 +00001017/* Receive a GSM 04.08 Radio Resource (RR) message */
Harald Welte52b1f982008-12-23 20:25:15 +00001018static int gsm0408_rcv_rr(struct msgb *msg)
1019{
1020 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte2d35ae62009-02-06 12:02:13 +00001021 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001022
1023 switch (gh->msg_type) {
1024 case GSM48_MT_RR_CLSM_CHG:
1025 DEBUGP(DRR, "CLASSMARK CHANGE\n");
1026 /* FIXME: what to do ?!? */
1027 break;
Harald Weltefc977a82008-12-27 10:19:37 +00001028 case GSM48_MT_RR_GPRS_SUSP_REQ:
1029 DEBUGP(DRR, "GRPS SUSPEND REQUEST\n");
1030 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001031 case GSM48_MT_RR_PAG_RESP:
Harald Welte2d35ae62009-02-06 12:02:13 +00001032 rc = gsm48_rr_rx_pag_resp(msg);
1033 break;
Harald Welte7ccf7782009-02-17 01:43:01 +00001034 case GSM48_MT_RR_CHAN_MODE_MODIF_ACK:
1035 DEBUGP(DRR, "CHANNEL MODE MODIFY ACK\n");
Harald Welte2c38aa82009-02-18 03:44:24 +00001036 rc = rsl_chan_mode_modify_req(msg->lchan);
Harald Welte7ccf7782009-02-17 01:43:01 +00001037 break;
Harald Weltecf5b3592009-05-01 18:28:42 +00001038 case GSM48_MT_RR_STATUS:
1039 rc = gsm48_rx_rr_status(msg);
1040 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001041 default:
Harald Welte2d35ae62009-02-06 12:02:13 +00001042 fprintf(stderr, "Unimplemented GSM 04.08 RR msg type 0x%02x\n",
Harald Welte52b1f982008-12-23 20:25:15 +00001043 gh->msg_type);
1044 break;
1045 }
1046
Harald Welte2d35ae62009-02-06 12:02:13 +00001047 return rc;
Harald Welte52b1f982008-12-23 20:25:15 +00001048}
1049
Holger Freythere64a7a32009-02-06 21:55:37 +00001050/* 7.1.7 and 9.1.7 Channel release*/
1051int gsm48_send_rr_release(struct gsm_lchan *lchan)
1052{
1053 struct msgb *msg = gsm48_msgb_alloc();
1054 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1055 u_int8_t *cause;
1056
1057 msg->lchan = lchan;
1058 gh->proto_discr = GSM48_PDISC_RR;
1059 gh->msg_type = GSM48_MT_RR_CHAN_REL;
1060
1061 cause = msgb_put(msg, 1);
1062 cause[0] = GSM48_RR_CAUSE_NORMAL;
1063
1064 DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n",
1065 lchan->nr, lchan->type);
1066
1067 return gsm48_sendmsg(msg);
1068}
1069
Harald Welte4bc90a12008-12-27 16:32:52 +00001070/* Call Control */
1071
Harald Welte7584aea2009-02-11 11:44:12 +00001072/* The entire call control code is written in accordance with Figure 7.10c
1073 * for 'very early assignment', i.e. we allocate a TCH/F during IMMEDIATE
1074 * ASSIGN, then first use that TCH/F for signalling and later MODE MODIFY
1075 * it for voice */
1076
Harald Welte4bc90a12008-12-27 16:32:52 +00001077static int gsm48_cc_tx_status(struct gsm_lchan *lchan)
1078{
1079 struct msgb *msg = gsm48_msgb_alloc();
1080 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1081 u_int8_t *cause, *call_state;
1082
Harald Welte65e74cc2008-12-29 01:55:35 +00001083 gh->proto_discr = GSM48_PDISC_CC;
1084
Harald Welte4bc90a12008-12-27 16:32:52 +00001085 msg->lchan = lchan;
1086
Harald Welte4bc90a12008-12-27 16:32:52 +00001087 gh->msg_type = GSM48_MT_CC_STATUS;
1088
1089 cause = msgb_put(msg, 3);
1090 cause[0] = 2;
1091 cause[1] = GSM48_CAUSE_CS_GSM | GSM48_CAUSE_LOC_USER;
1092 cause[2] = 0x80 | 30; /* response to status inquiry */
1093
1094 call_state = msgb_put(msg, 1);
1095 call_state[0] = 0xc0 | 0x00;
1096
Harald Welte65e74cc2008-12-29 01:55:35 +00001097 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001098}
1099
Harald Welte6f4b7532008-12-29 00:39:37 +00001100static int gsm48_tx_simple(struct gsm_lchan *lchan,
1101 u_int8_t pdisc, u_int8_t msg_type)
Harald Welte4bc90a12008-12-27 16:32:52 +00001102{
1103 struct msgb *msg = gsm48_msgb_alloc();
1104 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
1105
1106 msg->lchan = lchan;
1107
Harald Welte6f4b7532008-12-29 00:39:37 +00001108 gh->proto_discr = pdisc;
Harald Welte4bc90a12008-12-27 16:32:52 +00001109 gh->msg_type = msg_type;
1110
Harald Welte65e74cc2008-12-29 01:55:35 +00001111 return gsm48_sendmsg(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001112}
1113
Harald Welte09e38af2009-02-16 22:52:23 +00001114/* call-back from paging the B-end of the connection */
1115static int setup_trig_pag_evt(unsigned int hooknum, unsigned int event,
Harald Welte7ccf7782009-02-17 01:43:01 +00001116 struct msgb *msg, void *_lchan, void *param)
Harald Welte09e38af2009-02-16 22:52:23 +00001117{
Harald Welte7ccf7782009-02-17 01:43:01 +00001118 struct gsm_lchan *lchan = _lchan;
Harald Welte49f48b82009-02-17 15:29:33 +00001119 struct gsm_call *remote_call = param;
1120 struct gsm_call *call = &lchan->call;
Harald Welte7ccf7782009-02-17 01:43:01 +00001121 int rc = 0;
Harald Welte09e38af2009-02-16 22:52:23 +00001122
1123 if (hooknum != GSM_HOOK_RR_PAGING)
1124 return -EINVAL;
1125
1126 switch (event) {
1127 case GSM_PAGING_SUCCEEDED:
Harald Welte7ccf7782009-02-17 01:43:01 +00001128 DEBUGP(DCC, "paging succeeded!\n");
Harald Welte49f48b82009-02-17 15:29:33 +00001129 remote_call->remote_lchan = lchan;
1130 call->remote_lchan = remote_call->local_lchan;
Harald Welte09e38af2009-02-16 22:52:23 +00001131 /* send SETUP request to called party */
Harald Welte49f48b82009-02-17 15:29:33 +00001132 rc = gsm48_cc_tx_setup(lchan, call->remote_lchan->subscr);
1133 if (is_ipaccess_bts(lchan->ts->trx->bts))
1134 rsl_ipacc_bind(lchan);
Harald Welte09e38af2009-02-16 22:52:23 +00001135 break;
1136 case GSM_PAGING_EXPIRED:
Harald Welte7ccf7782009-02-17 01:43:01 +00001137 DEBUGP(DCC, "paging expired!\n");
Harald Welte09e38af2009-02-16 22:52:23 +00001138 /* notify caller that we cannot reach called party */
Harald Welte7ccf7782009-02-17 01:43:01 +00001139 /* FIXME: correct cause, etc */
Harald Weltebfaf0972009-02-17 17:43:33 +00001140 rc = gsm48_tx_simple(remote_call->local_lchan, GSM48_PDISC_CC,
Harald Welte7ccf7782009-02-17 01:43:01 +00001141 GSM48_MT_CC_RELEASE_COMPL);
Harald Welte09e38af2009-02-16 22:52:23 +00001142 break;
1143 }
Harald Welte7ccf7782009-02-17 01:43:01 +00001144 return rc;
Harald Welte09e38af2009-02-16 22:52:23 +00001145}
1146
Harald Welte4bc90a12008-12-27 16:32:52 +00001147static int gsm48_cc_rx_status_enq(struct msgb *msg)
1148{
Harald Welte4a543e82009-02-28 13:17:55 +00001149 DEBUGP(DCC, "-> STATUS ENQ\n");
Harald Welte4bc90a12008-12-27 16:32:52 +00001150 return gsm48_cc_tx_status(msg->lchan);
1151}
1152
1153static int gsm48_cc_rx_setup(struct msgb *msg)
1154{
Harald Welte7584aea2009-02-11 11:44:12 +00001155 struct gsm_call *call = &msg->lchan->call;
1156 struct gsm48_hdr *gh = msgb_l3(msg);
Harald Welte09e38af2009-02-16 22:52:23 +00001157 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
Harald Welte7584aea2009-02-11 11:44:12 +00001158 struct gsm_subscriber *called_subscr;
Harald Welte09e38af2009-02-16 22:52:23 +00001159 char called_number[(43-2)*2 + 1] = "\0";
1160 struct tlv_parsed tp;
1161 u_int8_t num_type;
Harald Welte7584aea2009-02-11 11:44:12 +00001162 int ret;
1163
1164 if (call->state == GSM_CSTATE_NULL ||
1165 call->state == GSM_CSTATE_RELEASE_REQ)
1166 use_lchan(msg->lchan);
1167
1168 call->type = GSM_CT_MO;
1169 call->state = GSM_CSTATE_INITIATED;
Harald Welte49f48b82009-02-17 15:29:33 +00001170 call->local_lchan = msg->lchan;
Harald Welte7584aea2009-02-11 11:44:12 +00001171 call->transaction_id = gh->proto_discr & 0xf0;
1172
Harald Weltea4d49e92009-05-23 06:39:58 +00001173 tlv_parse(&tp, &rsl_att_tlvdef, gh->data, payload_len, 0, 0);
Harald Welte09e38af2009-02-16 22:52:23 +00001174 if (!TLVP_PRESENT(&tp, GSM48_IE_CALLED_BCD))
1175 goto err;
Harald Welte7584aea2009-02-11 11:44:12 +00001176
Harald Welte09e38af2009-02-16 22:52:23 +00001177 /* Parse the number that was dialed and lookup subscriber */
1178 num_type = decode_bcd_number(called_number, sizeof(called_number),
1179 TLVP_VAL(&tp, GSM48_IE_CALLED_BCD)-1);
Harald Welte7ccf7782009-02-17 01:43:01 +00001180
Harald Welte4b458152009-02-17 13:23:06 +00001181 DEBUGP(DCC, "A -> SETUP(tid=0x%02x,number='%s')\n", call->transaction_id,
Harald Welte7ccf7782009-02-17 01:43:01 +00001182 called_number);
1183
Harald Welte09e38af2009-02-16 22:52:23 +00001184 called_subscr = subscr_get_by_extension(called_number);
Harald Welte7584aea2009-02-11 11:44:12 +00001185 if (!called_subscr) {
1186 DEBUGP(DCC, "could not find subscriber, RELEASE\n");
1187 put_lchan(msg->lchan);
1188 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
Harald Welte4b458152009-02-17 13:23:06 +00001189 GSM48_MT_CC_RELEASE_COMPL);
Harald Welte7584aea2009-02-11 11:44:12 +00001190 }
Harald Welte5a065df2009-02-22 21:13:18 +00001191 if (called_subscr == msg->lchan->subscr) {
1192 DEBUGP(DCC, "subscriber calling himself ?!?\n");
1193 put_lchan(msg->lchan);
1194 subscr_put(called_subscr);
1195 return gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1196 GSM48_MT_CC_RELEASE_COMPL);
1197 }
Harald Welte7584aea2009-02-11 11:44:12 +00001198
Harald Welte09e38af2009-02-16 22:52:23 +00001199 subscr_get(msg->lchan->subscr);
Harald Welte09e38af2009-02-16 22:52:23 +00001200 call->called_subscr = called_subscr;
1201
Harald Welte7584aea2009-02-11 11:44:12 +00001202 /* start paging of the receiving end of the call */
Harald Weltee7b452a2009-05-23 06:34:37 +00001203 /* FIXME: we're assuming that the receiver is at the same BTS
1204 * than we are, which is obviously a wrong assumption in multi-BTS
1205 * case */
Harald Welte09e38af2009-02-16 22:52:23 +00001206 paging_request(msg->trx->bts, called_subscr, RSL_CHANNEED_TCH_F,
1207 setup_trig_pag_evt, call);
Harald Welte7584aea2009-02-11 11:44:12 +00001208
1209 /* send a CALL PROCEEDING message to the MO */
1210 ret = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1211 GSM48_MT_CC_CALL_PROC);
1212
Harald Welte49f48b82009-02-17 15:29:33 +00001213 if (is_ipaccess_bts(msg->trx->bts))
1214 rsl_ipacc_bind(msg->lchan);
1215
Harald Welte7584aea2009-02-11 11:44:12 +00001216 /* change TCH/F mode to voice */
Harald Welte2c38aa82009-02-18 03:44:24 +00001217 return gsm48_tx_chan_mode_modify(msg->lchan, GSM48_CMODE_SPEECH_EFR);
Harald Welte09e38af2009-02-16 22:52:23 +00001218
1219err:
1220 /* FIXME: send some kind of RELEASE */
1221 return 0;
Harald Welte4bc90a12008-12-27 16:32:52 +00001222}
Harald Welte7584aea2009-02-11 11:44:12 +00001223
Harald Welte7ccf7782009-02-17 01:43:01 +00001224static int gsm48_cc_rx_alerting(struct msgb *msg)
1225{
1226 struct gsm_call *call = &msg->lchan->call;
Harald Welte4bc90a12008-12-27 16:32:52 +00001227
Harald Welte4b458152009-02-17 13:23:06 +00001228 DEBUGP(DCC, "A -> ALERTING\n");
Harald Welte7ccf7782009-02-17 01:43:01 +00001229
1230 /* forward ALERTING to other party */
Harald Welte49f48b82009-02-17 15:29:33 +00001231 if (!call->remote_lchan)
Harald Welte7ccf7782009-02-17 01:43:01 +00001232 return -EIO;
1233
Harald Welte4b458152009-02-17 13:23:06 +00001234 DEBUGP(DCC, "B <- ALERTING\n");
Harald Welte49f48b82009-02-17 15:29:33 +00001235 return gsm48_tx_simple(call->remote_lchan, GSM48_PDISC_CC,
Harald Welte7ccf7782009-02-17 01:43:01 +00001236 GSM48_MT_CC_ALERTING);
1237}
1238
Harald Welte49f48b82009-02-17 15:29:33 +00001239/* map two ipaccess RTP streams onto each other */
Harald Welte11fa29c2009-02-19 17:24:39 +00001240static int tch_map(struct gsm_lchan *lchan, struct gsm_lchan *remote_lchan)
Harald Welte49f48b82009-02-17 15:29:33 +00001241{
Harald Welte11fa29c2009-02-19 17:24:39 +00001242 struct gsm_bts *bts = lchan->ts->trx->bts;
1243 struct gsm_bts *remote_bts = remote_lchan->ts->trx->bts;
Harald Welte49f48b82009-02-17 15:29:33 +00001244 struct gsm_bts_trx_ts *ts;
1245
Harald Welte11fa29c2009-02-19 17:24:39 +00001246 DEBUGP(DCC, "Setting up TCH map between (bts=%u,trx=%u,ts=%u) and (bts=%u,trx=%u,ts=%u)\n",
1247 bts->nr, lchan->ts->trx->nr, lchan->ts->nr,
1248 remote_bts->nr, remote_lchan->ts->trx->nr, remote_lchan->ts->nr);
1249
1250 if (bts->type != remote_bts->type) {
1251 DEBUGP(DCC, "Cannot switch calls between different BTS types yet\n");
1252 return -EINVAL;
1253 }
Harald Welte49f48b82009-02-17 15:29:33 +00001254
Harald Welte11fa29c2009-02-19 17:24:39 +00001255 switch (bts->type) {
1256 case GSM_BTS_TYPE_NANOBTS_900:
1257 case GSM_BTS_TYPE_NANOBTS_1800:
1258 ts = remote_lchan->ts;
1259 rsl_ipacc_connect(lchan, ts->abis_ip.bound_ip, ts->abis_ip.bound_port,
1260 lchan->ts->abis_ip.attr_f8, ts->abis_ip.attr_fc);
1261
1262 ts = lchan->ts;
1263 rsl_ipacc_connect(remote_lchan, ts->abis_ip.bound_ip, ts->abis_ip.bound_port,
1264 remote_lchan->ts->abis_ip.attr_f8, ts->abis_ip.attr_fc);
1265 break;
1266 case GSM_BTS_TYPE_BS11:
1267 trau_mux_map_lchan(lchan, remote_lchan);
1268 break;
1269 default:
1270 DEBUGP(DCC, "Unknown BTS type %u\n", bts->type);
1271 break;
1272 }
Harald Welte49f48b82009-02-17 15:29:33 +00001273
1274 return 0;
1275}
1276
Harald Welte7ccf7782009-02-17 01:43:01 +00001277static int gsm48_cc_rx_connect(struct msgb *msg)
1278{
1279 struct gsm_call *call = &msg->lchan->call;
Harald Welte7ccf7782009-02-17 01:43:01 +00001280 int rc;
1281
Harald Welte4b458152009-02-17 13:23:06 +00001282 DEBUGP(DCC, "A -> CONNECT\n");
Harald Welte11fa29c2009-02-19 17:24:39 +00001283
1284 rc = tch_map(msg->lchan, call->remote_lchan);
1285 if (rc)
1286 return -EIO;
1287
1288 if (!call->remote_lchan)
1289 return -EIO;
1290
Harald Welte4b458152009-02-17 13:23:06 +00001291 DEBUGP(DCC, "A <- CONNECT ACK\n");
Harald Welte7ccf7782009-02-17 01:43:01 +00001292 /* MT+MO: need to respond with CONNECT_ACK and pass on */
1293 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
Harald Welte4b458152009-02-17 13:23:06 +00001294 GSM48_MT_CC_CONNECT_ACK);
Harald Welte7ccf7782009-02-17 01:43:01 +00001295
Harald Welte49f48b82009-02-17 15:29:33 +00001296
1297 /* forward CONNECT to other party */
Harald Welte4b458152009-02-17 13:23:06 +00001298 DEBUGP(DCC, "B <- CONNECT\n");
Harald Welte49f48b82009-02-17 15:29:33 +00001299 return gsm48_tx_simple(call->remote_lchan, GSM48_PDISC_CC,
Harald Welte4b458152009-02-17 13:23:06 +00001300 GSM48_MT_CC_CONNECT);
Harald Welte7ccf7782009-02-17 01:43:01 +00001301}
1302
1303static int gsm48_cc_rx_disconnect(struct msgb *msg)
1304{
1305 struct gsm_call *call = &msg->lchan->call;
Harald Welte7ccf7782009-02-17 01:43:01 +00001306 int rc;
1307
1308
1309 /* Section 5.4.3.2 */
Harald Welte4b458152009-02-17 13:23:06 +00001310 DEBUGP(DCC, "A -> DISCONNECT (state->RELEASE_REQ)\n");
Harald Welte7ccf7782009-02-17 01:43:01 +00001311 call->state = GSM_CSTATE_RELEASE_REQ;
Harald Welte7ccf7782009-02-17 01:43:01 +00001312 /* FIXME: clear the network connection */
Harald Welte4b458152009-02-17 13:23:06 +00001313 DEBUGP(DCC, "A <- RELEASE\n");
Harald Welte7ccf7782009-02-17 01:43:01 +00001314 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1315 GSM48_MT_CC_RELEASE);
Holger Freythera1f92f02009-04-12 05:37:52 +00001316
1317 /*
1318 * FIXME: This looks wrong! We should have a single
1319 * place to do MMCC-REL-CNF/-REQ/-IND and then switch
1320 * to the NULL state and relase the call
1321 */
1322 subscr_put_channel(msg->lchan);
Harald Welte7ccf7782009-02-17 01:43:01 +00001323
1324 /* forward DISCONNECT to other party */
Harald Welte49f48b82009-02-17 15:29:33 +00001325 if (!call->remote_lchan)
Harald Welte7ccf7782009-02-17 01:43:01 +00001326 return -EIO;
1327
Harald Welte4b458152009-02-17 13:23:06 +00001328 DEBUGP(DCC, "B <- DISCONNECT\n");
Harald Welte49f48b82009-02-17 15:29:33 +00001329 return gsm48_tx_simple(call->remote_lchan, GSM48_PDISC_CC,
Harald Welte7ccf7782009-02-17 01:43:01 +00001330 GSM48_MT_CC_DISCONNECT);
1331}
1332
1333static const u_int8_t calling_bcd[] = { 0xb9, 0x32, 0x24 };
1334
Harald Welte49f48b82009-02-17 15:29:33 +00001335int gsm48_cc_tx_setup(struct gsm_lchan *lchan,
1336 struct gsm_subscriber *calling_subscr)
Harald Welte65e74cc2008-12-29 01:55:35 +00001337{
1338 struct msgb *msg = gsm48_msgb_alloc();
1339 struct gsm48_hdr *gh;
1340 struct gsm_call *call = &lchan->call;
Harald Welte7ccf7782009-02-17 01:43:01 +00001341 u_int8_t bcd_lv[19];
Harald Welte65e74cc2008-12-29 01:55:35 +00001342
Harald Welte7ccf7782009-02-17 01:43:01 +00001343 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Harald Welte65e74cc2008-12-29 01:55:35 +00001344
1345 call->type = GSM_CT_MT;
Harald Welte49f48b82009-02-17 15:29:33 +00001346
1347 call->local_lchan = msg->lchan = lchan;
Harald Welte498b0bb2009-01-09 21:27:43 +00001348 use_lchan(lchan);
Harald Welte65e74cc2008-12-29 01:55:35 +00001349
1350 gh->proto_discr = GSM48_PDISC_CC;
1351 gh->msg_type = GSM48_MT_CC_SETUP;
Harald Welte09e38af2009-02-16 22:52:23 +00001352
Harald Welte7584aea2009-02-11 11:44:12 +00001353 msgb_tv_put(msg, GSM48_IE_SIGNAL, GSM48_SIGNAL_DIALTONE);
Harald Welte49f48b82009-02-17 15:29:33 +00001354 if (calling_subscr) {
Harald Welte7ccf7782009-02-17 01:43:01 +00001355 encode_bcd_number(bcd_lv, sizeof(bcd_lv), 0xb9,
Harald Welte49f48b82009-02-17 15:29:33 +00001356 calling_subscr->extension);
Harald Welte7ccf7782009-02-17 01:43:01 +00001357 msgb_tlv_put(msg, GSM48_IE_CALLING_BCD,
1358 bcd_lv[0], bcd_lv+1);
1359 }
Harald Welte49f48b82009-02-17 15:29:33 +00001360 if (lchan->subscr) {
Harald Welte7ccf7782009-02-17 01:43:01 +00001361 encode_bcd_number(bcd_lv, sizeof(bcd_lv), 0xb9,
Harald Welte49f48b82009-02-17 15:29:33 +00001362 lchan->subscr->extension);
Harald Welte7ccf7782009-02-17 01:43:01 +00001363 msgb_tlv_put(msg, GSM48_IE_CALLED_BCD,
1364 bcd_lv[0], bcd_lv+1);
1365 }
Harald Welte65e74cc2008-12-29 01:55:35 +00001366
Harald Welte4b458152009-02-17 13:23:06 +00001367 DEBUGP(DCC, "B <- SETUP\n");
Harald Welte65e74cc2008-12-29 01:55:35 +00001368
1369 return gsm48_sendmsg(msg);
1370}
1371
Harald Welte4bc90a12008-12-27 16:32:52 +00001372static int gsm0408_rcv_cc(struct msgb *msg)
1373{
1374 struct gsm48_hdr *gh = msgb_l3(msg);
1375 u_int8_t msg_type = gh->msg_type & 0xbf;
1376 struct gsm_call *call = &msg->lchan->call;
1377 int rc = 0;
1378
1379 switch (msg_type) {
1380 case GSM48_MT_CC_CALL_CONF:
1381 /* Response to SETUP */
Harald Welte7ccf7782009-02-17 01:43:01 +00001382 DEBUGP(DCC, "-> CALL CONFIRM\n");
Harald Welte4b458152009-02-17 13:23:06 +00001383 /* we now need to MODIFY the channel */
Harald Welte2c38aa82009-02-18 03:44:24 +00001384 rc = gsm48_tx_chan_mode_modify(msg->lchan, GSM48_CMODE_SPEECH_EFR);
Harald Welte4bc90a12008-12-27 16:32:52 +00001385 break;
1386 case GSM48_MT_CC_RELEASE_COMPL:
1387 /* Answer from MS to RELEASE */
Harald Welte7ccf7782009-02-17 01:43:01 +00001388 DEBUGP(DCC, "-> RELEASE COMPLETE (state->NULL)\n");
Harald Welte4bc90a12008-12-27 16:32:52 +00001389 call->state = GSM_CSTATE_NULL;
1390 break;
1391 case GSM48_MT_CC_ALERTING:
Harald Welte7ccf7782009-02-17 01:43:01 +00001392 rc = gsm48_cc_rx_alerting(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001393 break;
1394 case GSM48_MT_CC_CONNECT:
Harald Welte7ccf7782009-02-17 01:43:01 +00001395 rc = gsm48_cc_rx_connect(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001396 break;
1397 case GSM48_MT_CC_CONNECT_ACK:
1398 /* MO: Answer to CONNECT */
1399 call->state = GSM_CSTATE_ACTIVE;
Harald Welte7ccf7782009-02-17 01:43:01 +00001400 DEBUGP(DCC, "-> CONNECT_ACK (state->ACTIVE)\n");
Harald Welte4bc90a12008-12-27 16:32:52 +00001401 break;
1402 case GSM48_MT_CC_RELEASE:
Harald Welte7ccf7782009-02-17 01:43:01 +00001403 DEBUGP(DCC, "-> RELEASE\n");
Harald Welte49f48b82009-02-17 15:29:33 +00001404 DEBUGP(DCC, "<- RELEASE_COMPLETE\n");
Harald Welte4bc90a12008-12-27 16:32:52 +00001405 /* need to respond with RELEASE_COMPLETE */
Harald Welte7ccf7782009-02-17 01:43:01 +00001406 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1407 GSM48_MT_CC_RELEASE_COMPL);
Holger Freythera1f92f02009-04-12 05:37:52 +00001408 subscr_put_channel(msg->lchan);
Harald Welte49f48b82009-02-17 15:29:33 +00001409 call->state = GSM_CSTATE_NULL;
Harald Welte4bc90a12008-12-27 16:32:52 +00001410 break;
1411 case GSM48_MT_CC_STATUS_ENQ:
1412 rc = gsm48_cc_rx_status_enq(msg);
1413 break;
1414 case GSM48_MT_CC_DISCONNECT:
Harald Welte7ccf7782009-02-17 01:43:01 +00001415 rc = gsm48_cc_rx_disconnect(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001416 break;
1417 case GSM48_MT_CC_SETUP:
Harald Welte4a543e82009-02-28 13:17:55 +00001418 /* MO: wants to establish a call */
Harald Welte7584aea2009-02-11 11:44:12 +00001419 rc = gsm48_cc_rx_setup(msg);
Harald Welte4bc90a12008-12-27 16:32:52 +00001420 break;
1421 case GSM48_MT_CC_EMERG_SETUP:
Harald Welte7ccf7782009-02-17 01:43:01 +00001422 DEBUGP(DCC, "-> EMERGENCY SETUP\n");
Harald Welte4bc90a12008-12-27 16:32:52 +00001423 /* FIXME: continue with CALL_PROCEEDING, ALERTING, CONNECT, RELEASE_COMPLETE */
1424 break;
Harald Welte4a543e82009-02-28 13:17:55 +00001425 case GSM48_MT_CC_HOLD:
1426 DEBUGP(DCC, "-> HOLD (rejecting)\n");
1427 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1428 GSM48_MT_CC_HOLD_REJ);
1429 break;
1430 case GSM48_MT_CC_RETR:
1431 DEBUGP(DCC, "-> RETR (rejecting)\n");
1432 rc = gsm48_tx_simple(msg->lchan, GSM48_PDISC_CC,
1433 GSM48_MT_CC_RETR_REJ);
1434 break;
Harald Welte4bc90a12008-12-27 16:32:52 +00001435 default:
Harald Welte2d35ae62009-02-06 12:02:13 +00001436 fprintf(stderr, "Unimplemented GSM 04.08 CC msg type 0x%02x\n",
Harald Welte4bc90a12008-12-27 16:32:52 +00001437 msg_type);
1438 break;
1439 }
1440
1441 return rc;
1442}
1443
Harald Welte52b1f982008-12-23 20:25:15 +00001444/* here we pass in a msgb from the RSL->RLL. We expect the l3 pointer to be set */
1445int gsm0408_rcvmsg(struct msgb *msg)
1446{
1447 struct gsm48_hdr *gh = msgb_l3(msg);
1448 u_int8_t pdisc = gh->proto_discr & 0x0f;
Harald Welte8470bf22008-12-25 23:28:35 +00001449 int rc = 0;
Harald Welte52b1f982008-12-23 20:25:15 +00001450
1451 switch (pdisc) {
1452 case GSM48_PDISC_CC:
1453 rc = gsm0408_rcv_cc(msg);
1454 break;
1455 case GSM48_PDISC_MM:
1456 rc = gsm0408_rcv_mm(msg);
1457 break;
1458 case GSM48_PDISC_RR:
1459 rc = gsm0408_rcv_rr(msg);
1460 break;
Harald Weltebcae43f2008-12-27 21:45:37 +00001461 case GSM48_PDISC_SMS:
Daniel Willmann8b3390e2008-12-28 00:31:09 +00001462 rc = gsm0411_rcv_sms(msg);
Harald Weltebcae43f2008-12-27 21:45:37 +00001463 break;
Harald Welte52b1f982008-12-23 20:25:15 +00001464 case GSM48_PDISC_MM_GPRS:
Harald Weltebcae43f2008-12-27 21:45:37 +00001465 case GSM48_PDISC_SM_GPRS:
Harald Welte52b1f982008-12-23 20:25:15 +00001466 fprintf(stderr, "Unimplemented GSM 04.08 discriminator 0x%02d\n",
1467 pdisc);
1468 break;
1469 default:
1470 fprintf(stderr, "Unknown GSM 04.08 discriminator 0x%02d\n",
1471 pdisc);
1472 break;
1473 }
1474
1475 return rc;
1476}
Harald Welte8470bf22008-12-25 23:28:35 +00001477
1478enum chreq_type {
1479 CHREQ_T_EMERG_CALL,
1480 CHREQ_T_CALL_REEST_TCH_F,
1481 CHREQ_T_CALL_REEST_TCH_H,
1482 CHREQ_T_CALL_REEST_TCH_H_DBL,
1483 CHREQ_T_SDCCH,
1484 CHREQ_T_TCH_F,
1485 CHREQ_T_VOICE_CALL_TCH_H,
1486 CHREQ_T_DATA_CALL_TCH_H,
1487 CHREQ_T_LOCATION_UPD,
1488 CHREQ_T_PAG_R_ANY,
1489 CHREQ_T_PAG_R_TCH_F,
1490 CHREQ_T_PAG_R_TCH_FH,
1491};
1492
1493/* Section 9.1.8 / Table 9.9 */
1494struct chreq {
1495 u_int8_t val;
1496 u_int8_t mask;
1497 enum chreq_type type;
1498};
1499
1500/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
1501static const struct chreq chreq_type_neci1[] = {
1502 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
1503 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
1504 { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
1505 { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
1506 { 0xe0, 0xe0, CHREQ_T_SDCCH },
1507 { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
1508 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
1509 { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
1510 { 0x10, 0xf0, CHREQ_T_SDCCH },
1511 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
1512 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
1513 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
1514};
1515
1516/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
1517static const struct chreq chreq_type_neci0[] = {
1518 { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
1519 { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
1520 { 0xe0, 0xe0, CHREQ_T_TCH_F },
1521 { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
1522 { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
1523 { 0x80, 0xe0, CHREQ_T_PAG_R_ANY },
1524 { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
1525 { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
1526};
1527
1528static const enum gsm_chan_t ctype_by_chreq[] = {
1529 [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
1530 [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
1531 [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
1532 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
1533 [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
1534 [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
1535 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
1536 [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
1537 [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
1538 [CHREQ_T_PAG_R_ANY] = GSM_LCHAN_SDCCH,
1539 [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
1540 [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
1541};
1542
Harald Weltee14a57c2008-12-29 04:08:28 +00001543static const enum gsm_chreq_reason_t reason_by_chreq[] = {
1544 [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
1545 [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
1546 [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
1547 [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
1548 [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
1549 [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
1550 [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
1551 [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
1552 [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
1553 [CHREQ_T_PAG_R_ANY] = GSM_CHREQ_REASON_PAG,
1554 [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
1555 [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
1556};
1557
Harald Welte8470bf22008-12-25 23:28:35 +00001558enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra)
1559{
1560 int i;
1561 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
1562
1563 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
1564 const struct chreq *chr = &chreq_type_neci0[i];
1565 if ((ra & chr->mask) == chr->val)
1566 return ctype_by_chreq[chr->type];
1567 }
1568 fprintf(stderr, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
1569 return GSM_LCHAN_SDCCH;
1570}
Harald Weltee14a57c2008-12-29 04:08:28 +00001571
1572enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra)
1573{
1574 int i;
1575 /* FIXME: determine if we set NECI = 0 in the BTS SI4 */
1576
1577 for (i = 0; i < ARRAY_SIZE(chreq_type_neci0); i++) {
1578 const struct chreq *chr = &chreq_type_neci0[i];
1579 if ((ra & chr->mask) == chr->val)
1580 return reason_by_chreq[chr->type];
1581 }
1582 fprintf(stderr, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
1583 return GSM_CHREQ_REASON_OTHER;
1584}