blob: e1a6deaca46913cf9f018f7268ebc4d87c19ff2e [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001/* 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 Welte9f1f3ad2010-05-02 12:56:57 +02004/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte9b455bf2010-03-14 15:45:01 +08005 *
6 * 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#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
Harald Welteeaa614c2010-05-02 11:26:34 +020027#include <stdint.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080028#include <errno.h>
29
30#include <netinet/in.h>
Harald Welte421cba42010-05-02 23:11:50 +020031#include <arpa/inet.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080032
33#include <openbsc/db.h>
34#include <osmocore/msgb.h>
35#include <osmocore/tlv.h>
Harald Welted6057092010-05-02 12:57:45 +020036#include <osmocore/gsm_utils.h>
37#include <osmocore/signal.h>
38#include <osmocore/talloc.h>
39
Harald Welte9b455bf2010-03-14 15:45:01 +080040#include <openbsc/debug.h>
41#include <openbsc/gsm_data.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080042#include <openbsc/gsm_subscriber.h>
43#include <openbsc/gsm_04_08.h>
44#include <openbsc/gsm_04_08_gprs.h>
45#include <openbsc/paging.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080046#include <openbsc/transaction.h>
Harald Welte11d7c102010-05-02 11:54:55 +020047#include <openbsc/gprs_bssgp.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080048#include <openbsc/gprs_llc.h>
49#include <openbsc/gprs_sgsn.h>
Harald Welted193cb32010-05-17 22:58:03 +020050#include <openbsc/sgsn.h>
51
52extern struct sgsn_instance *sgsn;
Harald Welte9b455bf2010-03-14 15:45:01 +080053
Harald Welte2720e732010-05-17 00:44:57 +020054/* Protocol related stuff, should go into libosmocore */
55
Harald Welte9b455bf2010-03-14 15:45:01 +080056/* 10.5.5.14 GPRS MM Cause / Table 10.5.147 */
Harald Welte2720e732010-05-17 00:44:57 +020057const struct value_string gmm_cause_names[] = {
Harald Welte9b455bf2010-03-14 15:45:01 +080058 /* FIXME */
59 { GMM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" },
60 { GMM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" },
61 { GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL,
62 "Message type non-existant or not implemented" },
63 { GMM_CAUSE_MSGT_INCOMP_P_STATE,
64 "Message type not compatible with protocol state" },
65 { GMM_CAUSE_IE_NOTEXIST_NOTIMPL,
66 "Information element non-existent or not implemented" },
67 { GMM_CAUSE_COND_IE_ERR, "Conditional IE error" },
68 { GMM_CAUSE_MSG_INCOMP_P_STATE,
69 "Message not compatible with protocol state " },
70 { GMM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" },
71 { 0, NULL }
72};
73
74/* 10.5.6.6 SM Cause / Table 10.5.157 */
Harald Welte2720e732010-05-17 00:44:57 +020075const struct value_string gsm_cause_names[] = {
Harald Welte9b455bf2010-03-14 15:45:01 +080076 { GSM_CAUSE_INSUFF_RSRC, "Insufficient resources" },
77 { GSM_CAUSE_MISSING_APN, "Missing or unknown APN" },
78 { GSM_CAUSE_UNKNOWN_PDP, "Unknown PDP address or PDP type" },
79 { GSM_CAUSE_AUTH_FAILED, "User Authentication failed" },
80 { GSM_CAUSE_ACT_REJ_GGSN, "Activation rejected by GGSN" },
81 { GSM_CAUSE_ACT_REJ_UNSPEC, "Activation rejected, unspecified" },
82 { GSM_CAUSE_SERV_OPT_NOTSUPP, "Service option not supported" },
83 { GSM_CAUSE_REQ_SERV_OPT_NOTSUB,
84 "Requested service option not subscribed" },
85 { GSM_CAUSE_SERV_OPT_TEMP_OOO,
86 "Service option temporarily out of order" },
87 { GSM_CAUSE_NSAPI_IN_USE, "NSAPI already used" },
88 { GSM_CAUSE_DEACT_REGULAR, "Regular deactivation" },
89 { GSM_CAUSE_QOS_NOT_ACCEPTED, "QoS not accepted" },
90 { GSM_CAUSE_NET_FAIL, "Network Failure" },
91 { GSM_CAUSE_REACT_RQD, "Reactivation required" },
92 { GSM_CAUSE_FEATURE_NOTSUPP, "Feature not supported " },
93 { GSM_CAUSE_INVALID_TRANS_ID, "Invalid transaction identifier" },
94 { GSM_CAUSE_SEM_INCORR_MSG, "Semantically incorrect message" },
95 { GSM_CAUSE_INV_MAND_INFO, "Invalid mandatory information" },
96 { GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL,
97 "Message type non-existant or not implemented" },
98 { GSM_CAUSE_MSGT_INCOMP_P_STATE,
99 "Message type not compatible with protocol state" },
100 { GSM_CAUSE_IE_NOTEXIST_NOTIMPL,
101 "Information element non-existent or not implemented" },
102 { GSM_CAUSE_COND_IE_ERR, "Conditional IE error" },
103 { GSM_CAUSE_MSG_INCOMP_P_STATE,
104 "Message not compatible with protocol state " },
105 { GSM_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" },
106 { 0, NULL }
107};
108
Harald Welte2720e732010-05-17 00:44:57 +0200109/* 10.5.5.2 */
110const struct value_string gprs_att_t_strs[] = {
111 { GPRS_ATT_T_ATTACH, "GPRS attach" },
112 { GPRS_ATT_T_ATT_WHILE_IMSI, "GPRS attach while IMSI attached" },
113 { GPRS_ATT_T_COMBINED, "Combined GPRS/IMSI attach" },
114 { 0, NULL }
115};
Harald Welte9b455bf2010-03-14 15:45:01 +0800116
Harald Welte2720e732010-05-17 00:44:57 +0200117const struct value_string gprs_upd_t_strs[] = {
118 { GPRS_UPD_T_RA, "RA updating" },
119 { GPRS_UPD_T_RA_LA, "combined RA/LA updating" },
120 { GPRS_UPD_T_RA_LA_IMSI_ATT, "combined RA/LA updating + IMSI attach" },
121 { GPRS_UPD_T_PERIODIC, "periodic updating" },
122 { 0, NULL }
123};
124
125/* 10.5.5.5 */
126const struct value_string gprs_det_t_mo_strs[] = {
127 { GPRS_DET_T_MO_GPRS, "GPRS detach" },
128 { GPRS_DET_T_MO_IMSI, "IMSI detach" },
129 { GPRS_DET_T_MO_COMBINED, "Combined GPRS/IMSI detach" },
130 { 0, NULL }
131};
132
133/* Our implementation, should be kept in SGSN */
Harald Welte9b455bf2010-03-14 15:45:01 +0800134
Harald Welte9b455bf2010-03-14 15:45:01 +0800135/* Send a message through the underlying layer */
136static int gsm48_gmm_sendmsg(struct msgb *msg, int command)
137{
Harald Welte11d7c102010-05-02 11:54:55 +0200138 /* caller needs to provide TLLI, BVCI and NSEI */
Harald Welte9b455bf2010-03-14 15:45:01 +0800139 return gprs_llc_tx_ui(msg, GPRS_SAPI_GMM, command);
140}
141
Harald Welte11d7c102010-05-02 11:54:55 +0200142/* copy identifiers from old message to new message, this
143 * is required so lower layers can route it correctly */
144static void gmm_copy_id(struct msgb *msg, const struct msgb *old)
145{
146 msgb_tlli(msg) = msgb_tlli(old);
147 msgb_bvci(msg) = msgb_bvci(old);
148 msgb_nsei(msg) = msgb_nsei(old);
149}
150
Harald Welte86fda902010-05-03 10:54:35 +0200151static struct gsm48_qos default_qos = {
152 .delay_class = 4, /* best effort */
153 .reliab_class = GSM48_QOS_RC_LLC_UN_RLC_ACK_DATA_PROT,
154 .peak_tput = GSM48_QOS_PEAK_TPUT_32000bps,
155 .preced_class = GSM48_QOS_PC_NORMAL,
156 .mean_tput = GSM48_QOS_MEAN_TPUT_BEST_EFFORT,
157 .traf_class = GSM48_QOS_TC_INTERACTIVE,
158 .deliv_order = GSM48_QOS_DO_UNORDERED,
159 .deliv_err_sdu = GSM48_QOS_ERRSDU_YES,
160 .max_sdu_size = GSM48_QOS_MAXSDU_1520,
161 .max_bitrate_up = GSM48_QOS_MBRATE_63k,
162 .max_bitrate_down = GSM48_QOS_MBRATE_63k,
163 .resid_ber = GSM48_QOS_RBER_5e_2,
164 .sdu_err_ratio = GSM48_QOS_SERR_1e_2,
165 .handling_prio = 3,
166 .xfer_delay = 0x10, /* 200ms */
167 .guar_bitrate_up = GSM48_QOS_MBRATE_0k,
168 .guar_bitrate_down = GSM48_QOS_MBRATE_0k,
169 .sig_ind = 0, /* not optimised for signalling */
170 .max_bitrate_down_ext = 0, /* use octet 9 */
171 .guar_bitrate_down_ext = 0, /* use octet 13 */
172};
173
Harald Welte9b455bf2010-03-14 15:45:01 +0800174/* Chapter 9.4.2: Attach accept */
175static int gsm48_tx_gmm_att_ack(struct msgb *old_msg)
176{
177 struct msgb *msg = gsm48_msgb_alloc();
178 struct gsm48_hdr *gh;
179 struct gsm48_attach_ack *aa;
Harald Welte11d7c102010-05-02 11:54:55 +0200180 struct gprs_ra_id ra_id;
Harald Welte9b455bf2010-03-14 15:45:01 +0800181
182 DEBUGP(DMM, "<- GPRS ATTACH ACCEPT\n");
183
Harald Welte11d7c102010-05-02 11:54:55 +0200184 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800185
186 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
187 gh->proto_discr = GSM48_PDISC_MM_GPRS;
188 gh->msg_type = GSM48_MT_GMM_ATTACH_ACK;
189
190 aa = (struct gsm48_attach_ack *) msgb_put(msg, sizeof(*aa));
191 aa->force_stby = 0; /* not indicated */
192 aa->att_result = 1; /* GPRS only */
193 aa->ra_upd_timer = GPRS_TMR_MINUTE | 10;
194 aa->radio_prio = 4; /* lowest */
Harald Welteba021102010-05-02 21:36:36 +0200195 bssgp_parse_cell_id(&ra_id, msgb_bcid(old_msg));
Harald Welte11d7c102010-05-02 11:54:55 +0200196 gsm48_construct_ra(aa->ra_id.digits, &ra_id);
Harald Welte9b455bf2010-03-14 15:45:01 +0800197
198 /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */
199 return gsm48_gmm_sendmsg(msg, 0);
200}
201
202/* Chapter 9.4.5: Attach reject */
Harald Welteeaa614c2010-05-02 11:26:34 +0200203static int gsm48_tx_gmm_att_rej(struct msgb *old_msg, uint8_t gmm_cause)
Harald Welte9b455bf2010-03-14 15:45:01 +0800204{
205 struct msgb *msg = gsm48_msgb_alloc();
206 struct gsm48_hdr *gh;
207
208 DEBUGP(DMM, "<- GPRS ATTACH REJECT\n");
209
Harald Welte11d7c102010-05-02 11:54:55 +0200210 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800211
212 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
213 gh->proto_discr = GSM48_PDISC_MM_GPRS;
214 gh->msg_type = GSM48_MT_GMM_ATTACH_REJ;
215 gh->data[0] = gmm_cause;
216
217 return gsm48_gmm_sendmsg(msg, 0);
218}
219
Harald Welte2720e732010-05-17 00:44:57 +0200220/* Chapter 9.4.6.2 Detach accept */
221static gsm48_tx_gmm_det_ack(struct msgb *old_msg, uint8_t force_stby)
222{
223 struct msgb *msg = gsm48_msgb_alloc();
224 struct gsm48_hdr *gh;
225
226 DEBUGP(DMM, "<- GPRS DETACH ACCEPT\n");
227
228 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
229 gh->proto_discr = GSM48_PDISC_MM_GPRS;
230 gh->msg_type = GSM48_MT_GMM_DETACH_ACK;
231 gh->data[0] = force_stby;
232
233 return gsm48_gmm_sendmsg(msg, 0);
234}
235
Harald Welte9b455bf2010-03-14 15:45:01 +0800236/* Transmit Chapter 9.4.12 Identity Request */
Harald Welteeaa614c2010-05-02 11:26:34 +0200237static int gsm48_tx_gmm_id_req(struct msgb *old_msg, uint8_t id_type)
Harald Welte9b455bf2010-03-14 15:45:01 +0800238{
239 struct msgb *msg = gsm48_msgb_alloc();
240 struct gsm48_hdr *gh;
241
242 DEBUGP(DMM, "-> GPRS IDENTITY REQUEST: mi_type=%02x\n", id_type);
243
Harald Welte11d7c102010-05-02 11:54:55 +0200244 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800245
246 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
247 gh->proto_discr = GSM48_PDISC_MM_GPRS;
248 gh->msg_type = GSM48_MT_GMM_ID_REQ;
249 /* 10.5.5.9 ID type 2 + identity type and 10.5.5.7 'force to standby' IE */
250 gh->data[0] = id_type & 0xf;
251
252 return gsm48_gmm_sendmsg(msg, 0);
253}
254
255/* Check if we can already authorize a subscriber */
256static int gsm48_gmm_authorize(struct sgsn_mm_ctx *ctx, struct msgb *msg)
257{
258 if (strlen(ctx->imei) && strlen(ctx->imsi)) {
259 ctx->mm_state = GMM_REGISTERED_NORMAL;
260 return gsm48_tx_gmm_att_ack(msg);
261 }
262 if (!strlen(ctx->imei))
263 return gsm48_tx_gmm_id_req(msg, GSM_MI_TYPE_IMEI);
264
265 if (!strlen(ctx->imsi))
266 return gsm48_tx_gmm_id_req(msg, GSM_MI_TYPE_IMSI);
267
268 return 0;
269}
270
271/* Parse Chapter 9.4.13 Identity Response */
Harald Welted193cb32010-05-17 22:58:03 +0200272static int gsm48_rx_gmm_id_resp(struct sgsn_mm_ctx *ctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800273{
Harald Welte943c5bc2010-04-30 16:33:12 +0200274 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welteeaa614c2010-05-02 11:26:34 +0200275 uint8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
Harald Welte9b455bf2010-03-14 15:45:01 +0800276 char mi_string[GSM48_MI_SIZE];
277 struct gprs_ra_id ra_id;
Harald Welte9b455bf2010-03-14 15:45:01 +0800278
279 gsm48_mi_to_string(mi_string, sizeof(mi_string), &gh->data[1], gh->data[0]);
Harald Welte2720e732010-05-17 00:44:57 +0200280 DEBUGP(DMM, "-> GMM IDENTITY RESPONSE: mi_type=0x%02x MI(%s) ",
Harald Welte9b455bf2010-03-14 15:45:01 +0800281 mi_type, mi_string);
282
Harald Welte9b455bf2010-03-14 15:45:01 +0800283 if (!ctx) {
Harald Welte943c5bc2010-04-30 16:33:12 +0200284 DEBUGP(DMM, "from unknown TLLI 0x%08x?!?\n", msgb_tlli(msg));
Harald Welte9b455bf2010-03-14 15:45:01 +0800285 return -EINVAL;
286 }
287
288 switch (mi_type) {
289 case GSM_MI_TYPE_IMSI:
290 /* we already have a mm context with current TLLI, but no
291 * P-TMSI / IMSI yet. What we now need to do is to fill
292 * this initial context with data from the HLR */
293 strncpy(ctx->imsi, mi_string, sizeof(ctx->imei));
294 break;
295 case GSM_MI_TYPE_IMEI:
296 strncpy(ctx->imei, mi_string, sizeof(ctx->imei));
297 break;
298 case GSM_MI_TYPE_IMEISV:
299 break;
300 }
301
302 DEBUGPC(DMM, "\n");
303 /* Check if we can let the mobile station enter */
304 return gsm48_gmm_authorize(ctx, msg);
305}
306
307static void attach_rej_cb(void *data)
308{
309 struct sgsn_mm_ctx *ctx = data;
310
311 /* FIXME: determine through which BTS/TRX to send this */
312 //gsm48_tx_gmm_att_rej(ctx->tlli, GMM_CAUSE_MS_ID_NOT_DERIVED);
313 ctx->mm_state = GMM_DEREGISTERED;
314 /* FIXME: release the context */
315}
316
317static void schedule_reject(struct sgsn_mm_ctx *ctx)
318{
319 ctx->T = 3370;
320 ctx->timer.cb = attach_rej_cb;
321 ctx->timer.data = ctx;
322 bsc_schedule_timer(&ctx->timer, 6, 0);
323}
324
325/* Section 9.4.1 Attach request */
Harald Welted193cb32010-05-17 22:58:03 +0200326static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800327{
Harald Welte943c5bc2010-04-30 16:33:12 +0200328 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welteeaa614c2010-05-02 11:26:34 +0200329 uint8_t *cur = gh->data, *msnc, *mi, *old_ra_info;
330 uint8_t msnc_len, att_type, mi_len, mi_type;
331 uint16_t drx_par;
332 uint32_t tmsi;
Harald Welte9b455bf2010-03-14 15:45:01 +0800333 char mi_string[GSM48_MI_SIZE];
334 struct gprs_ra_id ra_id;
Harald Welte9f1f3ad2010-05-02 12:56:57 +0200335 uint16_t cid;
Harald Welte9b455bf2010-03-14 15:45:01 +0800336 struct sgsn_mm_ctx *ctx;
337
Harald Welte2720e732010-05-17 00:44:57 +0200338 DEBUGP(DMM, "-> GMM ATTACH REQUEST ");
Harald Welte9b455bf2010-03-14 15:45:01 +0800339
340 /* As per TS 04.08 Chapter 4.7.1.4, the attach request arrives either
341 * with a foreign TLLI (P-TMSI that was allocated to the MS before),
342 * or with random TLLI. */
343
Harald Welte9f1f3ad2010-05-02 12:56:57 +0200344 cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));
Harald Welte9b455bf2010-03-14 15:45:01 +0800345
346 /* MS network capability 10.5.5.12 */
347 msnc_len = *cur++;
348 msnc = cur;
349 if (msnc_len > 2)
350 goto err_inval;
351 cur += msnc_len;
352
353 /* aTTACH Type 10.5.5.2 */
354 att_type = *cur++ & 0x0f;
355
356 /* DRX parameter 10.5.5.6 */
357 drx_par = *cur++;
358 drx_par |= *cur++ << 8;
359
360 /* Mobile Identity (P-TMSI or IMSI) 10.5.1.4 */
361 mi_len = *cur++;
362 mi = cur;
363 if (mi_len > 8)
364 goto err_inval;
365 mi_type = *mi & GSM_MI_TYPE_MASK;
366 cur += mi_len;
367
368 gsm48_mi_to_string(mi_string, sizeof(mi_string), mi, mi_len);
369
Harald Welte2720e732010-05-17 00:44:57 +0200370 DEBUGPC(DMM, "MI(%s) type=\"%s\" ", mi_string,
371 get_value_string(gprs_att_t_strs, att_type));
Harald Welte9b455bf2010-03-14 15:45:01 +0800372
373 /* Old routing area identification 10.5.5.15 */
374 old_ra_info = cur;
375 cur += 6;
376
377 /* MS Radio Access Capability 10.5.5.12a */
378
379 /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status */
380
381 switch (mi_type) {
382 case GSM_MI_TYPE_IMSI:
383 /* Try to find MM context based on IMSI */
384 ctx = sgsn_mm_ctx_by_imsi(mi_string);
385 if (!ctx) {
386#if 0
387 return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_IMSI_UNKNOWN);
388#else
389 /* As a temorary hack, we simply assume that the IMSI exists */
390 ctx = sgsn_mm_ctx_alloc(0, &ra_id);
391 if (!ctx)
392 return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_NET_FAIL);
393 strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi));
394#endif
395 }
396 /* FIXME: Start some timer */
397 ctx->mm_state = GMM_COMMON_PROC_INIT;
Harald Welte943c5bc2010-04-30 16:33:12 +0200398 ctx->tlli = msgb_tlli(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800399 break;
400 case GSM_MI_TYPE_TMSI:
401 tmsi = strtoul(mi_string, NULL, 10);
402 /* Try to find MM context based on P-TMSI */
403 ctx = sgsn_mm_ctx_by_ptmsi(tmsi);
404 if (!ctx) {
Harald Welte943c5bc2010-04-30 16:33:12 +0200405 ctx = sgsn_mm_ctx_alloc(msgb_tlli(msg), &ra_id);
Harald Welte9b455bf2010-03-14 15:45:01 +0800406 /* FIXME: Start some timer */
407 ctx->mm_state = GMM_COMMON_PROC_INIT;
Harald Welte943c5bc2010-04-30 16:33:12 +0200408 ctx->tlli = msgb_tlli(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800409 }
410 break;
411 default:
Harald Welte9f1f3ad2010-05-02 12:56:57 +0200412 return 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800413 }
Harald Welte9f1f3ad2010-05-02 12:56:57 +0200414 /* Update MM Context with currient RA and Cell ID */
415 ctx->ra = ra_id;
416 ctx->cell_id = cid;
Harald Welte9b455bf2010-03-14 15:45:01 +0800417
418 /* FIXME: allocate a new P-TMSI (+ P-TMSI signature) */
419 /* FIXME: update the TLLI with the new local TLLI based on the P-TMSI */
420
421 DEBUGPC(DMM, "\n");
422
423 return ctx ? gsm48_gmm_authorize(ctx, msg) : 0;
424
425err_inval:
426 DEBUGPC(DMM, "\n");
427 return gsm48_tx_gmm_att_rej(msg, GMM_CAUSE_SEM_INCORR_MSG);
428}
429
Harald Welte2720e732010-05-17 00:44:57 +0200430/* Section 4.7.4.1 / 9.4.5.2 MO Detach request */
Harald Welted193cb32010-05-17 22:58:03 +0200431static int gsm48_rx_gmm_det_req(struct sgsn_mm_ctx *ctx, struct msgb *msg)
Harald Welte2720e732010-05-17 00:44:57 +0200432{
433 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welte2720e732010-05-17 00:44:57 +0200434 uint8_t detach_type, power_off;
Harald Welte2720e732010-05-17 00:44:57 +0200435
436 detach_type = gh->data[0] & 0x7;
437 power_off = gh->data[0] & 0x8;
438
439 /* FIXME: In 24.008 there is an optional P-TMSI and P-TMSI signature IE */
440
441 DEBUGP(DMM, "-> GMM DETACH REQUEST TLLI=0x%08x type=%s %s\n",
442 msgb_tlli(msg), get_value_string(gprs_det_t_mo_strs, detach_type),
443 power_off ? "Power-off" : "");
444
445 /* Mark MM state as deregistered */
446 ctx->mm_state = GMM_DEREGISTERED;
447
448 /* force_stby = 0 */
449 return gsm48_tx_gmm_det_ack(msg, 0);
450}
451
Harald Welte9b455bf2010-03-14 15:45:01 +0800452/* Chapter 9.4.15: Routing area update accept */
453static int gsm48_tx_gmm_ra_upd_ack(struct msgb *old_msg)
454{
455 struct msgb *msg = gsm48_msgb_alloc();
456 struct gsm48_hdr *gh;
457 struct gsm48_ra_upd_ack *rua;
Harald Welte11d7c102010-05-02 11:54:55 +0200458 struct gprs_ra_id ra_id;
Harald Welte9b455bf2010-03-14 15:45:01 +0800459
460 DEBUGP(DMM, "<- ROUTING AREA UPDATE ACCEPT\n");
461
Harald Welte11d7c102010-05-02 11:54:55 +0200462 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800463
464 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
465 gh->proto_discr = GSM48_PDISC_MM_GPRS;
466 gh->msg_type = GSM48_MT_GMM_RA_UPD_ACK;
467
468 rua = (struct gsm48_ra_upd_ack *) msgb_put(msg, sizeof(*rua));
469 rua->force_stby = 0; /* not indicated */
470 rua->upd_result = 0; /* RA updated */
471 rua->ra_upd_timer = GPRS_TMR_MINUTE | 10;
Harald Welte11d7c102010-05-02 11:54:55 +0200472
Harald Welteba021102010-05-02 21:36:36 +0200473 bssgp_parse_cell_id(&ra_id, msgb_bcid(old_msg));
Harald Welte11d7c102010-05-02 11:54:55 +0200474 gsm48_construct_ra(rua->ra_id.digits, &ra_id);
Harald Welte9b455bf2010-03-14 15:45:01 +0800475
476 /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */
477 return gsm48_gmm_sendmsg(msg, 0);
478}
479
480/* Chapter 9.4.17: Routing area update reject */
Harald Welteeaa614c2010-05-02 11:26:34 +0200481static int gsm48_tx_gmm_ra_upd_rej(struct msgb *old_msg, uint8_t cause)
Harald Welte9b455bf2010-03-14 15:45:01 +0800482{
483 struct msgb *msg = gsm48_msgb_alloc();
484 struct gsm48_hdr *gh;
485
486 DEBUGP(DMM, "<- ROUTING AREA UPDATE REJECT\n");
487
Harald Welte11d7c102010-05-02 11:54:55 +0200488 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800489
490 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 2);
491 gh->proto_discr = GSM48_PDISC_MM_GPRS;
492 gh->msg_type = GSM48_MT_GMM_RA_UPD_REJ;
493 gh->data[0] = cause;
494 gh->data[1] = 0; /* ? */
495
496 /* Option: P-TMSI signature, allocated P-TMSI, MS ID, ... */
497 return gsm48_gmm_sendmsg(msg, 0);
498}
499
500/* Chapter 9.4.14: Routing area update request */
Harald Welted193cb32010-05-17 22:58:03 +0200501static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800502{
Harald Welte943c5bc2010-04-30 16:33:12 +0200503 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welteeaa614c2010-05-02 11:26:34 +0200504 uint8_t *cur = gh->data;
Harald Welte9b455bf2010-03-14 15:45:01 +0800505 struct gprs_ra_id old_ra_id;
Harald Welteeaa614c2010-05-02 11:26:34 +0200506 uint8_t upd_type;
Harald Welte9b455bf2010-03-14 15:45:01 +0800507
508 /* Update Type 10.5.5.18 */
509 upd_type = *cur++ & 0x0f;
510
Harald Welte2720e732010-05-17 00:44:57 +0200511 DEBUGP(DMM, "-> GMM RA UPDATE REQUEST type=\"%s\" ",
512 get_value_string(gprs_upd_t_strs, upd_type));
Harald Welte9b455bf2010-03-14 15:45:01 +0800513
514 /* Old routing area identification 10.5.5.15 */
515 gsm48_parse_ra(&old_ra_id, cur);
516 cur += 6;
517
518 /* MS Radio Access Capability 10.5.5.12a */
519
520 /* Optional: Old P-TMSI Signature, Requested READY timer, TMSI Status,
521 * DRX parameter, MS network capability */
522
523 switch (upd_type) {
524 case GPRS_UPD_T_RA_LA:
525 case GPRS_UPD_T_RA_LA_IMSI_ATT:
526 DEBUGPC(DMM, " unsupported in Mode III, is your SI13 corrupt?\n");
527 return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_PROTO_ERR_UNSPEC);
528 break;
529 case GPRS_UPD_T_RA:
530 case GPRS_UPD_T_PERIODIC:
531 break;
532 }
533
534 /* Look-up the MM context based on old RA-ID and TLLI */
Harald Welte9b455bf2010-03-14 15:45:01 +0800535 if (!mmctx || mmctx->mm_state == GMM_DEREGISTERED) {
536 /* The MS has to perform GPRS attach */
537 DEBUGPC(DMM, " REJECT\n");
538 return gsm48_tx_gmm_ra_upd_rej(msg, GMM_CAUSE_IMPL_DETACHED);
539 }
540
Harald Welte9f1f3ad2010-05-02 12:56:57 +0200541 /* Update the MM context with the new RA-ID */
542 bssgp_parse_cell_id(&mmctx->ra, msgb_bcid(msg));
543 /* Update the MM context with the new TLLI */
544 mmctx->tlli = msgb_tlli(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800545 /* FIXME: Update the MM context with the MS radio acc capabilities */
546 /* FIXME: Update the MM context with the MS network capabilities */
547
548 DEBUGPC(DMM, " ACCEPT\n");
549 return gsm48_tx_gmm_ra_upd_ack(msg);
550}
551
Harald Welted193cb32010-05-17 22:58:03 +0200552static int gsm48_rx_gmm_status(struct sgsn_mm_ctx *mmctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800553{
554 struct gsm48_hdr *gh = msgb_l3(msg);
555
Harald Welte2720e732010-05-17 00:44:57 +0200556 DEBUGP(DMM, "-> GPRS MM STATUS (cause: %s)\n",
Harald Welte9b455bf2010-03-14 15:45:01 +0800557 get_value_string(gmm_cause_names, gh->data[0]));
558
559 return 0;
560}
561
562/* GPRS Mobility Management */
Harald Welted193cb32010-05-17 22:58:03 +0200563static int gsm0408_rcv_gmm(struct sgsn_mm_ctx *mmctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800564{
Harald Welte943c5bc2010-04-30 16:33:12 +0200565 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800566 int rc;
567
Harald Welted193cb32010-05-17 22:58:03 +0200568 if (!mmctx &&
569 gh->msg_type != GSM48_MT_GMM_ATTACH_REQ &&
570 gh->msg_type != GSM48_MT_GMM_RA_UPD_REQ) {
571 LOGP(DMM, LOGL_NOTICE, "Cannot handle GMM for unknown MM CTX\n");
572 return -EINVAL;
573 }
574
575
Harald Welte9b455bf2010-03-14 15:45:01 +0800576 switch (gh->msg_type) {
577 case GSM48_MT_GMM_RA_UPD_REQ:
Harald Welted193cb32010-05-17 22:58:03 +0200578 rc = gsm48_rx_gmm_ra_upd_req(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800579 break;
580 case GSM48_MT_GMM_ATTACH_REQ:
Harald Welted193cb32010-05-17 22:58:03 +0200581 rc = gsm48_rx_gmm_att_req(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800582 break;
583 case GSM48_MT_GMM_ID_RESP:
Harald Welted193cb32010-05-17 22:58:03 +0200584 rc = gsm48_rx_gmm_id_resp(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800585 break;
586 case GSM48_MT_GMM_STATUS:
Harald Welted193cb32010-05-17 22:58:03 +0200587 rc = gsm48_rx_gmm_status(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800588 break;
Harald Welte2720e732010-05-17 00:44:57 +0200589 case GSM48_MT_GMM_DETACH_REQ:
Harald Welted193cb32010-05-17 22:58:03 +0200590 rc = gsm48_rx_gmm_det_req(mmctx, msg);
Harald Welte2720e732010-05-17 00:44:57 +0200591 break;
Harald Welte9b455bf2010-03-14 15:45:01 +0800592 case GSM48_MT_GMM_RA_UPD_COMPL:
593 /* only in case SGSN offered new P-TMSI */
594 case GSM48_MT_GMM_ATTACH_COMPL:
595 /* only in case SGSN offered new P-TMSI */
Harald Welte9b455bf2010-03-14 15:45:01 +0800596 case GSM48_MT_GMM_PTMSI_REALL_COMPL:
597 case GSM48_MT_GMM_AUTH_CIPH_RESP:
598 DEBUGP(DMM, "Unimplemented GSM 04.08 GMM msg type 0x%02x\n",
599 gh->msg_type);
Harald Welte2720e732010-05-17 00:44:57 +0200600 /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */
Harald Welte9b455bf2010-03-14 15:45:01 +0800601 break;
602 default:
603 DEBUGP(DMM, "Unknown GSM 04.08 GMM msg type 0x%02x\n",
604 gh->msg_type);
Harald Welte2720e732010-05-17 00:44:57 +0200605 /* FIXME: Send GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL */
Harald Welte9b455bf2010-03-14 15:45:01 +0800606 break;
607 }
608
609 return rc;
610}
611
Harald Welte421cba42010-05-02 23:11:50 +0200612static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr)
613{
614 uint8_t v[6];
615
616 v[0] = PDP_TYPE_ORG_IETF;
617 v[1] = PDP_TYPE_N_IETF_IPv4;
618 *(uint32_t *)(v+2) = htonl(ipaddr);
619
620 msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v);
621}
622
623static void msgb_put_pdp_addr_ppp(struct msgb *msg)
624{
625 uint8_t v[2];
626
627 v[0] = PDP_TYPE_ORG_ETSI;
628 v[1] = PDP_TYPE_N_ETSI_PPP;
629
630 msgb_tlv_put(msg, GSM48_IE_GSM_PDP_ADDR, sizeof(v), v);
631}
632
Harald Welte9b455bf2010-03-14 15:45:01 +0800633/* Section 9.5.2: Ativate PDP Context Accept */
634static int gsm48_tx_gsm_act_pdp_acc(struct msgb *old_msg, struct gsm48_act_pdp_ctx_req *req)
635{
Harald Welte943c5bc2010-04-30 16:33:12 +0200636 struct gsm48_hdr *old_gh = (struct gsm48_hdr *) msgb_gmmh(old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800637 struct msgb *msg = gsm48_msgb_alloc();
638 struct gsm48_act_pdp_ctx_ack *act_ack;
639 struct gsm48_hdr *gh;
Harald Welteeaa614c2010-05-02 11:26:34 +0200640 uint8_t transaction_id = ((old_gh->proto_discr >> 4) ^ 0x8); /* flip */
Harald Welte9b455bf2010-03-14 15:45:01 +0800641
642 DEBUGP(DMM, "<- ACTIVATE PDP CONTEXT ACK\n");
643
Harald Welte11d7c102010-05-02 11:54:55 +0200644 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800645
646 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
647 gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4);
648 gh->msg_type = GSM48_MT_GSM_ACT_PDP_ACK;
Harald Welte421cba42010-05-02 23:11:50 +0200649
650 /* Negotiated LLC SAPI */
651 msgb_v_put(msg, req->req_llc_sapi);
652 /* copy QoS parameters from original request */
Harald Welte86fda902010-05-03 10:54:35 +0200653 msgb_lv_put(msg, sizeof(default_qos), (uint8_t *)&default_qos);
Harald Welte421cba42010-05-02 23:11:50 +0200654 /* Radio priority 10.5.7.2 */
655 msgb_v_put(msg, 4);
656 /* PDP address */
657 msgb_put_pdp_addr_ipv4(msg, 0x01020304);
658 /* Optional: Protocol configuration options */
659 /* Optional: Packet Flow Identifier */
Harald Welte9b455bf2010-03-14 15:45:01 +0800660
661 return gsm48_gmm_sendmsg(msg, 0);
662}
663
664/* Section 9.5.9: Deactivate PDP Context Accept */
Harald Welted193cb32010-05-17 22:58:03 +0200665static int gsm48_tx_gsm_deact_pdp_acc(struct sgsn_mm_ctx *mmctx,
666 struct msgb *old_msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800667{
Harald Welte943c5bc2010-04-30 16:33:12 +0200668 struct gsm48_hdr *old_gh = (struct gsm48_hdr *) msgb_gmmh(old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800669 struct msgb *msg = gsm48_msgb_alloc();
670 struct gsm48_hdr *gh;
Harald Welteeaa614c2010-05-02 11:26:34 +0200671 uint8_t transaction_id = ((old_gh->proto_discr >> 4) ^ 0x8); /* flip */
Harald Welte9b455bf2010-03-14 15:45:01 +0800672
673 DEBUGP(DMM, "<- DEACTIVATE PDP CONTEXT ACK\n");
674
Harald Welte11d7c102010-05-02 11:54:55 +0200675 gmm_copy_id(msg, old_msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800676
677 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
678 gh->proto_discr = GSM48_PDISC_SM_GPRS | (transaction_id << 4);
679 gh->msg_type = GSM48_MT_GSM_DEACT_PDP_ACK;
680
681 return gsm48_gmm_sendmsg(msg, 0);
682}
683
684/* Section 9.5.1: Activate PDP Context Request */
Harald Welted193cb32010-05-17 22:58:03 +0200685static int gsm48_rx_gsm_act_pdp_req(struct sgsn_mm_ctx *mmctx,
686 struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800687{
Harald Welte943c5bc2010-04-30 16:33:12 +0200688 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800689 struct gsm48_act_pdp_ctx_req *act_req = (struct gsm48_act_pdp_ctx_req *) gh->data;
Harald Welteeaa614c2010-05-02 11:26:34 +0200690 uint8_t *pdp_addr_lv = act_req->data;
Harald Welte0c3eae02010-05-02 21:07:14 +0200691 uint8_t req_qos_len, req_pdpa_len;
692 uint8_t *req_qos, *req_pdpa;
693 struct tlv_parsed tp;
Harald Welte9b455bf2010-03-14 15:45:01 +0800694
Harald Welte2720e732010-05-17 00:44:57 +0200695 DEBUGP(DMM, "-> ACTIVATE PDP CONTEXT REQ: ");
Harald Welte0c3eae02010-05-02 21:07:14 +0200696 req_qos_len = act_req->data[0];
697 req_qos = act_req->data + 1; /* 10.5.6.5 */
698 req_pdpa_len = act_req->data[1 + req_qos_len];
699 req_pdpa = act_req->data + 1 + req_qos_len + 1; /* 10.5.6.4 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800700
Harald Welte0c3eae02010-05-02 21:07:14 +0200701 switch (req_pdpa[0] & 0xf) {
702 case 0x0:
703 DEBUGPC(DMM, "ETSI ");
704 break;
705 case 0x1:
706 DEBUGPC(DMM, "IETF ");
707 break;
708 case 0xf:
709 DEBUGPC(DMM, "Empty ");
710 break;
711 }
712
713 switch (req_pdpa[1]) {
714 case 0x21:
715 DEBUGPC(DMM, "IPv4 ");
716 if (req_pdpa_len >= 6) {
717 struct in_addr ia;
718 ia.s_addr = ntohl(*((uint32_t *) (req_pdpa+2)));
719 DEBUGPC(DMM, "%s ", inet_ntoa(ia));
720 }
721 break;
722 case 0x57:
723 DEBUGPC(DMM, "IPv6 ");
724 if (req_pdpa_len >= 18) {
725 /* FIXME: print IPv6 address */
726 }
727 break;
728 default:
729 DEBUGPC(DMM, "0x%02x ", req_pdpa[1]);
730 break;
731 }
732
Harald Welte2720e732010-05-17 00:44:57 +0200733 /* put the non-TLV elements in the TLV parser structure to
734 * pass them on to the SGSN / GTP code */
735 tp.lv[OSMO_IE_GSM_REQ_QOS].len = req_qos_len;
736 tp.lv[OSMO_IE_GSM_REQ_QOS].val = req_qos;
737 tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].len = req_pdpa_len;
738 tp.lv[OSMO_IE_GSM_REQ_PDP_ADDR].val = req_pdpa;
739
Harald Welte0c3eae02010-05-02 21:07:14 +0200740 /* FIXME: parse TLV for AP name and protocol config options */
741 if (TLVP_PRESENT(&tp, GSM48_IE_GSM_APN)) {}
742 if (TLVP_PRESENT(&tp, GSM48_IE_GSM_PROTO_CONF_OPT)) {}
Harald Welte9b455bf2010-03-14 15:45:01 +0800743
Harald Welted193cb32010-05-17 22:58:03 +0200744#if 1
745 {
746 struct ggsn_ctx ggsn;
747 ggsn.gtp_version = 1;
748 inet_aton("192.168.100.239", &ggsn.remote_addr);
749 ggsn.gsn = sgsn->gsn;
750 return sgsn_create_pdp_ctx(ggsn, mmctx, 5, &tp);
751 }
Harald Welte2720e732010-05-17 00:44:57 +0200752#else
Harald Welte9b455bf2010-03-14 15:45:01 +0800753 return gsm48_tx_gsm_act_pdp_acc(msg, act_req);
Harald Welte2720e732010-05-17 00:44:57 +0200754#endif
Harald Welte9b455bf2010-03-14 15:45:01 +0800755}
756
757/* Section 9.5.8: Deactivate PDP Context Request */
Harald Welted193cb32010-05-17 22:58:03 +0200758static int gsm48_rx_gsm_deact_pdp_req(struct sgsn_mm_ctx *ctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800759{
Harald Welte943c5bc2010-04-30 16:33:12 +0200760 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800761
Harald Welte2720e732010-05-17 00:44:57 +0200762 DEBUGP(DMM, "-> DEACTIVATE PDP CONTEXT REQ (cause: %s)\n",
Harald Welte9b455bf2010-03-14 15:45:01 +0800763 get_value_string(gsm_cause_names, gh->data[0]));
764
Harald Welted193cb32010-05-17 22:58:03 +0200765 return gsm48_tx_gsm_deact_pdp_acc(ctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800766}
767
Harald Welted193cb32010-05-17 22:58:03 +0200768static int gsm48_rx_gsm_status(struct sgsn_mm_ctx *ctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800769{
770 struct gsm48_hdr *gh = msgb_l3(msg);
771
Harald Welte2720e732010-05-17 00:44:57 +0200772 DEBUGP(DMM, "-> GPRS SM STATUS (cause: %s)\n",
Harald Welte9b455bf2010-03-14 15:45:01 +0800773 get_value_string(gsm_cause_names, gh->data[0]));
774
775 return 0;
776}
777
778/* GPRS Session Management */
Harald Welted193cb32010-05-17 22:58:03 +0200779static int gsm0408_rcv_gsm(struct sgsn_mm_ctx *mmctx, struct msgb *msg)
Harald Welte9b455bf2010-03-14 15:45:01 +0800780{
Harald Welte943c5bc2010-04-30 16:33:12 +0200781 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800782 int rc;
783
Harald Welted193cb32010-05-17 22:58:03 +0200784 if (!mmctx) {
785 LOGP(DMM, LOGL_NOTICE, "Cannot handle SM for unknown MM CTX\n");
786 return -EINVAL;
787 }
788
Harald Welte9b455bf2010-03-14 15:45:01 +0800789 switch (gh->msg_type) {
790 case GSM48_MT_GSM_ACT_PDP_REQ:
Harald Welted193cb32010-05-17 22:58:03 +0200791 rc = gsm48_rx_gsm_act_pdp_req(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800792 break;
793 case GSM48_MT_GSM_DEACT_PDP_REQ:
Harald Welted193cb32010-05-17 22:58:03 +0200794 rc = gsm48_rx_gsm_deact_pdp_req(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800795 case GSM48_MT_GSM_STATUS:
Harald Welted193cb32010-05-17 22:58:03 +0200796 rc = gsm48_rx_gsm_status(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800797 break;
798 case GSM48_MT_GSM_REQ_PDP_ACT_REJ:
799 case GSM48_MT_GSM_ACT_AA_PDP_REQ:
800 case GSM48_MT_GSM_DEACT_AA_PDP_REQ:
801 DEBUGP(DMM, "Unimplemented GSM 04.08 GSM msg type 0x%02x\n",
802 gh->msg_type);
803 break;
804 default:
805 DEBUGP(DMM, "Unknown GSM 04.08 GSM msg type 0x%02x\n",
806 gh->msg_type);
807 break;
808
809 }
810
811 return rc;
812}
813
814/* Main entry point for incoming 04.08 GPRS messages */
815int gsm0408_gprs_rcvmsg(struct msgb *msg)
816{
Harald Welte943c5bc2010-04-30 16:33:12 +0200817 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
Harald Welteeaa614c2010-05-02 11:26:34 +0200818 uint8_t pdisc = gh->proto_discr & 0x0f;
Harald Welted193cb32010-05-17 22:58:03 +0200819 struct sgsn_mm_ctx *mmctx;
820 struct gprs_ra_id ra_id;
Harald Welte9b455bf2010-03-14 15:45:01 +0800821 int rc = -EINVAL;
822
Harald Welted193cb32010-05-17 22:58:03 +0200823 bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));
824 mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id);
825
826 /* MMCTX can be NULL */
827
Harald Welte9b455bf2010-03-14 15:45:01 +0800828 switch (pdisc) {
829 case GSM48_PDISC_MM_GPRS:
Harald Welted193cb32010-05-17 22:58:03 +0200830 rc = gsm0408_rcv_gmm(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800831 break;
832 case GSM48_PDISC_SM_GPRS:
Harald Welted193cb32010-05-17 22:58:03 +0200833 rc = gsm0408_rcv_gsm(mmctx, msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800834 break;
835 default:
836 DEBUGP(DMM, "Unknown GSM 04.08 discriminator 0x%02x\n",
837 pdisc);
838 break;
839 }
840
841 return rc;
842}