blob: 9c75a3d4ee8364d4363f642ba8b62019fb163687 [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001/* GPRS LLC protocol implementation as per 3GPP TS 04.64 */
2
Harald Weltea2665542010-05-02 09:28:11 +02003/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte9b455bf2010-03-14 15:45:01 +08004 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <errno.h>
Harald Welteeaa614c2010-05-02 11:26:34 +020024#include <stdint.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080025
Harald Welte9b455bf2010-03-14 15:45:01 +080026#include <osmocore/msgb.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080027#include <osmocore/linuxlist.h>
28#include <osmocore/timer.h>
Harald Weltea2665542010-05-02 09:28:11 +020029#include <osmocore/talloc.h>
30
31#include <openbsc/gsm_data.h>
32#include <openbsc/debug.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080033#include <openbsc/gprs_bssgp.h>
34#include <openbsc/gprs_llc.h>
35#include <openbsc/crc24.h>
36
37/* Section 4.5.2 Logical Link States + Annex C.2 */
38enum gprs_llc_ll_state {
39 GPRS_LLS_UNASSIGNED = 1, /* No TLLI yet */
40 GPRS_LLS_ASSIGNED_ADM = 2, /* TLLI assigned */
41 GPRS_LLS_LOCAL_EST = 3, /* Local Establishment */
42 GPRS_LLS_REMOTE_EST = 4, /* Remote Establishment */
43 GPRS_LLS_ABM = 5,
44 GPRS_LLS_LOCAL_REL = 6, /* Local Release */
45 GPRS_LLS_TIMER_REC = 7, /* Timer Recovery */
46};
47
48/* Section 4.7.1: Logical Link Entity: One per DLCI (TLLI + SAPI) */
49struct gprs_llc_lle {
50 struct llist_head list;
51 struct timer_list t200;
52 struct timer_list t201; /* wait for acknowledgement */
53
54 enum gprs_llc_ll_state state;
55
Harald Welteeaa614c2010-05-02 11:26:34 +020056 uint32_t tlli;
57 uint32_t sapi;
Harald Welte9b455bf2010-03-14 15:45:01 +080058
Harald Welteeaa614c2010-05-02 11:26:34 +020059 uint8_t v_sent;
60 uint8_t v_ack;
61 uint8_t v_recv;
Harald Welte9b455bf2010-03-14 15:45:01 +080062
63 unsigned int n200;
64 unsigned int retrans_ctr;
Harald Weltee6afd602010-05-02 11:19:37 +020065
66 /* over which BSSGP BTS ctx do we need to transmit */
67 uint16_t bvci;
68 uint16_t nsei;
Harald Welte9b455bf2010-03-14 15:45:01 +080069};
70
Harald Weltea2665542010-05-02 09:28:11 +020071static LLIST_HEAD(gprs_llc_lles);
72void *llc_tall_ctx;
73
74/* lookup LLC Entity based on DLCI (TLLI+SAPI tuple) */
75static struct gprs_llc_lle *lle_by_tlli_sapi(uint32_t tlli, uint32_t sapi)
76{
77 struct gprs_llc_lle *lle;
78
79 llist_for_each_entry(lle, &gprs_llc_lles, list) {
80 if (lle->tlli == tlli && lle->sapi == sapi)
81 return lle;
82 }
83 return NULL;
84}
85
86static struct gprs_llc_lle *lle_alloc(uint32_t tlli, uint32_t sapi)
87{
88 struct gprs_llc_lle *lle;
89
90 lle = talloc_zero(llc_tall_ctx, struct gprs_llc_lle);
91 if (!lle)
92 return NULL;
93
94 lle->tlli = tlli;
95 lle->sapi = sapi;
96 lle->state = GPRS_LLS_UNASSIGNED;
97 llist_add(&lle->list, &gprs_llc_lles);
98
99 return lle;
100}
101
Harald Welte9b455bf2010-03-14 15:45:01 +0800102enum gprs_llc_cmd {
103 GPRS_LLC_NULL,
104 GPRS_LLC_RR,
105 GPRS_LLC_ACK,
106 GPRS_LLC_RNR,
107 GPRS_LLC_SACK,
108 GPRS_LLC_DM,
109 GPRS_LLC_DISC,
110 GPRS_LLC_UA,
111 GPRS_LLC_SABM,
112 GPRS_LLC_FRMR,
113 GPRS_LLC_XID,
114};
115
116struct gprs_llc_hdr_parsed {
Harald Welteeaa614c2010-05-02 11:26:34 +0200117 uint8_t sapi;
118 uint8_t is_cmd:1,
Harald Welte9b455bf2010-03-14 15:45:01 +0800119 ack_req:1,
120 is_encrypted:1;
Harald Welteeaa614c2010-05-02 11:26:34 +0200121 uint32_t seq_rx;
122 uint32_t seq_tx;
123 uint32_t fcs;
124 uint32_t fcs_calc;
125 uint8_t *data;
Harald Welte5658a1a2010-05-03 13:25:07 +0200126 uint16_t data_len;
Harald Welte9b455bf2010-03-14 15:45:01 +0800127 enum gprs_llc_cmd cmd;
128};
129
130#define LLC_ALLOC_SIZE 16384
131#define UI_HDR_LEN 3
132#define N202 4
133#define CRC24_LENGTH 3
134
Harald Welteeaa614c2010-05-02 11:26:34 +0200135static int gprs_llc_fcs(uint8_t *data, unsigned int len)
Harald Welte9b455bf2010-03-14 15:45:01 +0800136{
Harald Welteeaa614c2010-05-02 11:26:34 +0200137 uint32_t fcs_calc;
Harald Welte9b455bf2010-03-14 15:45:01 +0800138
139 fcs_calc = crc24_calc(INIT_CRC24, data, len);
140 fcs_calc = ~fcs_calc;
141 fcs_calc &= 0xffffff;
142
143 return fcs_calc;
144}
145
Harald Welte9b455bf2010-03-14 15:45:01 +0800146static void t200_expired(void *data)
147{
148 struct gprs_llc_lle *lle = data;
149
150 /* 8.5.1.3: Expiry of T200 */
151
152 if (lle->retrans_ctr >= lle->n200) {
153 /* FIXME: LLGM-STATUS-IND, LL-RELEASE-IND/CNF */
154 lle->state = GPRS_LLS_ASSIGNED_ADM;
155 }
156
157 switch (lle->state) {
158 case GPRS_LLS_LOCAL_EST:
159 /* retransmit SABM */
160 /* re-start T200 */
161 lle->retrans_ctr++;
162 break;
163 case GPRS_LLS_LOCAL_REL:
164 /* retransmit DISC */
165 /* re-start T200 */
166 lle->retrans_ctr++;
167 break;
168 }
169
170}
171
172static void t201_expired(void *data)
173{
174 struct gprs_llc_lle *lle = data;
175
176 if (lle->retrans_ctr < lle->n200) {
177 /* transmit apropriate supervisory frame (8.6.4.1) */
178 /* set timer T201 */
179 lle->retrans_ctr++;
180 }
181}
182
Harald Welte10997d02010-05-03 12:28:12 +0200183int gprs_llc_tx_u(struct msgb *msg, uint8_t sapi, int command,
184 enum gprs_llc_u_cmd u_cmd, int pf_bit)
185{
186 uint8_t *fcs, *llch;
187 uint8_t addr, ctrl;
188 uint32_t fcs_calc;
189
190 /* Identifiers from UP: (TLLI, SAPI) + (BVCI, NSEI) */
191
192 /* Address Field */
193 addr = sapi & 0xf;
194 if (command)
195 addr |= 0x40;
196
197 /* 6.3 Figure 8 */
198 ctrl = 0xe0 | u_cmd;
199 if (pf_bit)
200 ctrl |= 0x10;
201
202 /* prepend LLC UI header */
203 llch = msgb_push(msg, 2);
204 llch[0] = addr;
205 llch[1] = ctrl;
206
207 /* append FCS to end of frame */
208 fcs = msgb_put(msg, 3);
209 fcs_calc = gprs_llc_fcs(llch, fcs - llch);
210 fcs[0] = fcs_calc & 0xff;
211 fcs[1] = (fcs_calc >> 8) & 0xff;
212 fcs[2] = (fcs_calc >> 16) & 0xff;
213
214 /* Identifiers passed down: (BVCI, NSEI) */
215
216 return gprs_bssgp_tx_dl_ud(msg);
217}
218
219/* Send XID response to LLE */
220static int gprs_llc_tx_xid(struct gprs_llc_lle *lle, struct msgb *msg)
221{
222 /* copy identifiers from LLE to ensure lower layers can route */
223 msgb_tlli(msg) = lle->tlli;
224 msgb_bvci(msg) = lle->bvci;
225 msgb_nsei(msg) = lle->nsei;
226
227 return gprs_llc_tx_u(msg, lle->sapi, 0, GPRS_LLC_U_XID, 1);
228}
229
Harald Welte9b455bf2010-03-14 15:45:01 +0800230/* Transmit a UI frame over the given SAPI */
Harald Welteeaa614c2010-05-02 11:26:34 +0200231int gprs_llc_tx_ui(struct msgb *msg, uint8_t sapi, int command)
Harald Welte9b455bf2010-03-14 15:45:01 +0800232{
Harald Weltee6afd602010-05-02 11:19:37 +0200233 struct gprs_llc_lle *lle;
Harald Welteeaa614c2010-05-02 11:26:34 +0200234 uint8_t *fcs, *llch;
235 uint8_t addr, ctrl[2];
236 uint32_t fcs_calc;
237 uint16_t nu = 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800238
Harald Weltee6afd602010-05-02 11:19:37 +0200239 /* Identifiers from UP: (TLLI, SAPI) + (BVCI, NSEI) */
240
241 /* look-up or create the LL Entity for this (TLLI, SAPI) tuple */
242 lle = lle_by_tlli_sapi(msgb_tlli(msg), sapi);
243 if (!lle)
244 lle = lle_alloc(msgb_tlli(msg), sapi);
245 /* Update LLE's (BVCI, NSEI) tuple */
246 lle->bvci = msgb_bvci(msg);
247 lle->nsei = msgb_nsei(msg);
248
Harald Welte9b455bf2010-03-14 15:45:01 +0800249 /* Address Field */
250 addr = sapi & 0xf;
251 if (command)
252 addr |= 0x40;
253
254 /* Control Field */
255 ctrl[0] = 0xc0;
256 ctrl[0] |= nu >> 6;
257 ctrl[1] = (nu << 2) & 0xfc;
258 ctrl[1] |= 0x01; /* Protected Mode */
259
260 /* prepend LLC UI header */
261 llch = msgb_push(msg, 3);
262 llch[0] = addr;
263 llch[1] = ctrl[0];
264 llch[2] = ctrl[1];
265
266 /* append FCS to end of frame */
267 fcs = msgb_put(msg, 3);
268 fcs_calc = gprs_llc_fcs(llch, fcs - llch);
269 fcs[0] = fcs_calc & 0xff;
270 fcs[1] = (fcs_calc >> 8) & 0xff;
271 fcs[2] = (fcs_calc >> 16) & 0xff;
272
Harald Weltee6afd602010-05-02 11:19:37 +0200273 /* Identifiers passed down: (BVCI, NSEI) */
274
Harald Welte9b455bf2010-03-14 15:45:01 +0800275 return gprs_bssgp_tx_dl_ud(msg);
276}
277
278static int gprs_llc_hdr_dump(struct gprs_llc_hdr_parsed *gph)
279{
280 DEBUGP(DGPRS, "LLC SAPI=%u %c %c FCS=0x%06x(%s) ",
281 gph->sapi, gph->is_cmd ? 'C' : 'R', gph->ack_req ? 'A' : ' ',
282 gph->fcs, gph->fcs_calc == gph->fcs ? "correct" : "WRONG");
283
284 if (gph->cmd)
285 DEBUGPC(DGPRS, "CMD=%u ", gph->cmd);
286
287 if (gph->data)
288 DEBUGPC(DGPRS, "DATA ");
289
290 DEBUGPC(DGPRS, "\n");
291}
292static int gprs_llc_hdr_rx(struct gprs_llc_hdr_parsed *gph,
293 struct gprs_llc_lle *lle)
294{
295 switch (gph->cmd) {
296 case GPRS_LLC_SABM: /* Section 6.4.1.1 */
297 lle->v_sent = lle->v_ack = lle->v_recv = 0;
298 if (lle->state == GPRS_LLS_ASSIGNED_ADM) {
299 /* start re-establishment (8.7.1) */
300 }
301 lle->state = GPRS_LLS_REMOTE_EST;
302 /* FIXME: Send UA */
303 lle->state = GPRS_LLS_ABM;
304 /* FIXME: process data */
305 break;
306 case GPRS_LLC_DISC: /* Section 6.4.1.2 */
307 /* FIXME: Send UA */
308 /* terminate ABM */
309 lle->state = GPRS_LLS_ASSIGNED_ADM;
310 break;
311 case GPRS_LLC_UA: /* Section 6.4.1.3 */
312 if (lle->state == GPRS_LLS_LOCAL_EST)
313 lle->state = GPRS_LLS_ABM;
314 break;
315 case GPRS_LLC_DM: /* Section 6.4.1.4: ABM cannot be performed */
316 if (lle->state == GPRS_LLS_LOCAL_EST)
317 lle->state = GPRS_LLS_ASSIGNED_ADM;
318 break;
319 case GPRS_LLC_FRMR: /* Section 6.4.1.5 */
320 break;
321 case GPRS_LLC_XID: /* Section 6.4.1.6 */
Harald Welte5658a1a2010-05-03 13:25:07 +0200322 /* FIXME: implement XID negotiation using SNDCP */
323 {
324 struct msgb *resp;
325 uint8_t *xid;
326 resp = msgb_alloc_headroom(4096, 1024, "LLC_XID");
327 xid = msgb_put(resp, gph->data_len);
328 memcpy(xid, gph->data, gph->data_len);
329 gprs_llc_tx_xid(lle, resp);
330 }
Harald Welte9b455bf2010-03-14 15:45:01 +0800331 break;
332 }
333
334 return 0;
335}
336
337/* parse a GPRS LLC header, also check for invalid frames */
338static int gprs_llc_hdr_parse(struct gprs_llc_hdr_parsed *ghp,
Harald Welteeaa614c2010-05-02 11:26:34 +0200339 const uint8_t *llc_hdr, int len)
Harald Welte9b455bf2010-03-14 15:45:01 +0800340{
Harald Welteeaa614c2010-05-02 11:26:34 +0200341 uint8_t *ctrl = llc_hdr+1;
Harald Welte9b455bf2010-03-14 15:45:01 +0800342 int is_sack = 0;
343 unsigned int crc_length;
Harald Welteeaa614c2010-05-02 11:26:34 +0200344 uint32_t fcs_calc;
Harald Welte9b455bf2010-03-14 15:45:01 +0800345
346 if (len <= CRC24_LENGTH)
347 return -EIO;
348
349 crc_length = len - CRC24_LENGTH;
350
351 ghp->ack_req = 0;
352
353 /* Section 5.5: FCS */
354 ghp->fcs = *(llc_hdr + len - 3);
355 ghp->fcs |= *(llc_hdr + len - 2) << 8;
356 ghp->fcs |= *(llc_hdr + len - 1) << 16;
357
358 /* Section 6.2.1: invalid PD field */
359 if (llc_hdr[0] & 0x80)
360 return -EIO;
361
362 /* This only works for the MS->SGSN direction */
363 if (llc_hdr[0] & 0x40)
364 ghp->is_cmd = 0;
365 else
366 ghp->is_cmd = 1;
367
368 ghp->sapi = llc_hdr[0] & 0xf;
369
370 /* Section 6.2.3: check for reserved SAPI */
371 switch (ghp->sapi) {
372 case 0:
373 case 4:
374 case 6:
375 case 0xa:
376 case 0xc:
377 case 0xd:
378 case 0xf:
379 return -EINVAL;
380 }
381
382 if ((ctrl[0] & 0x80) == 0) {
383 /* I (Information transfer + Supervisory) format */
Harald Welteeaa614c2010-05-02 11:26:34 +0200384 uint8_t k;
Harald Welte9b455bf2010-03-14 15:45:01 +0800385
386 ghp->data = ctrl + 3;
387
388 if (ctrl[0] & 0x40)
389 ghp->ack_req = 1;
390
391 ghp->seq_tx = (ctrl[0] & 0x1f) << 4;
392 ghp->seq_tx |= (ctrl[1] >> 4);
393
394 ghp->seq_rx = (ctrl[1] & 0x7) << 6;
395 ghp->seq_rx |= (ctrl[2] >> 2);
396
397 switch (ctrl[2] & 0x03) {
398 case 0:
399 ghp->cmd = GPRS_LLC_RR;
400 break;
401 case 1:
402 ghp->cmd = GPRS_LLC_ACK;
403 break;
404 case 2:
405 ghp->cmd = GPRS_LLC_RNR;
406 break;
407 case 3:
408 ghp->cmd = GPRS_LLC_SACK;
409 k = ctrl[3] & 0x1f;
410 ghp->data += 1 + k;
411 break;
412 }
Harald Welte5658a1a2010-05-03 13:25:07 +0200413 ghp->data_len = (llc_hdr + len - 3) - ghp->data;
Harald Welte9b455bf2010-03-14 15:45:01 +0800414 } else if ((ctrl[0] & 0xc0) == 0x80) {
415 /* S (Supervisory) format */
416 ghp->data = NULL;
Harald Welte5658a1a2010-05-03 13:25:07 +0200417 ghp->data_len = 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800418
419 if (ctrl[0] & 0x20)
420 ghp->ack_req = 1;
421 ghp->seq_rx = (ctrl[0] & 0x7) << 6;
422 ghp->seq_rx |= (ctrl[1] >> 2);
423
424 switch (ctrl[1] & 0x03) {
425 case 0:
426 ghp->cmd = GPRS_LLC_RR;
427 break;
428 case 1:
429 ghp->cmd = GPRS_LLC_ACK;
430 break;
431 case 2:
432 ghp->cmd = GPRS_LLC_RNR;
433 break;
434 case 3:
435 ghp->cmd = GPRS_LLC_SACK;
436 break;
437 }
438 } else if ((ctrl[0] & 0xe0) == 0xc0) {
439 /* UI (Unconfirmed Inforamtion) format */
440 ghp->data = ctrl + 2;
Harald Welte5658a1a2010-05-03 13:25:07 +0200441 ghp->data_len = (llc_hdr + len - 3) - ghp->data;
Harald Welte9b455bf2010-03-14 15:45:01 +0800442
443 ghp->seq_tx = (ctrl[0] & 0x7) << 6;
444 ghp->seq_tx |= (ctrl[1] >> 2);
445 if (ctrl[1] & 0x02) {
446 ghp->is_encrypted = 1;
447 /* FIXME: encryption */
448 }
449 if (ctrl[1] & 0x01) {
450 /* FCS over hdr + all inf fields */
451 } else {
452 /* FCS over hdr + N202 octets (4) */
453 if (crc_length > UI_HDR_LEN + N202)
454 crc_length = UI_HDR_LEN + N202;
455 }
456 } else {
457 /* U (Unnumbered) format: 1 1 1 P/F M4 M3 M2 M1 */
458 ghp->data = NULL;
Harald Welte5658a1a2010-05-03 13:25:07 +0200459 ghp->data_len = 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800460
461 switch (ctrl[0] & 0xf) {
Harald Welte5658a1a2010-05-03 13:25:07 +0200462 case GPRS_LLC_U_NULL_CMD:
Harald Welte9b455bf2010-03-14 15:45:01 +0800463 ghp->cmd = GPRS_LLC_NULL;
464 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200465 case GPRS_LLC_U_DM_RESP:
Harald Welte9b455bf2010-03-14 15:45:01 +0800466 ghp->cmd = GPRS_LLC_DM;
467 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200468 case GPRS_LLC_U_DISC_CMD:
Harald Welte9b455bf2010-03-14 15:45:01 +0800469 ghp->cmd = GPRS_LLC_DISC;
470 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200471 case GPRS_LLC_U_UA_RESP:
Harald Welte9b455bf2010-03-14 15:45:01 +0800472 ghp->cmd = GPRS_LLC_UA;
473 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200474 case GPRS_LLC_U_SABM_CMD:
Harald Welte9b455bf2010-03-14 15:45:01 +0800475 ghp->cmd = GPRS_LLC_SABM;
476 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200477 case GPRS_LLC_U_FRMR_RESP:
Harald Welte9b455bf2010-03-14 15:45:01 +0800478 ghp->cmd = GPRS_LLC_FRMR;
479 break;
Harald Welte5658a1a2010-05-03 13:25:07 +0200480 case GPRS_LLC_U_XID:
Harald Welte9b455bf2010-03-14 15:45:01 +0800481 ghp->cmd = GPRS_LLC_XID;
Harald Welte5658a1a2010-05-03 13:25:07 +0200482 ghp->data = ctrl + 1;
483 ghp->data_len = (llc_hdr + len - 3) - ghp->data;
Harald Welte9b455bf2010-03-14 15:45:01 +0800484 break;
485 default:
486 return -EIO;
487 }
488 }
489
490 /* calculate what FCS we expect */
491 ghp->fcs_calc = gprs_llc_fcs(llc_hdr, crc_length);
492
493 /* FIXME: parse sack frame */
494}
495
Harald Weltea2665542010-05-02 09:28:11 +0200496/* receive an incoming LLC PDU (BSSGP-UL-UNITDATA-IND, 7.2.4.2) */
Harald Welte9b455bf2010-03-14 15:45:01 +0800497int gprs_llc_rcvmsg(struct msgb *msg, struct tlv_parsed *tv)
498{
Harald Weltefd3fa1d2010-05-02 09:50:42 +0200499 struct bssgp_ud_hdr *udh = (struct bssgp_ud_hdr *) msgb_bssgph(msg);
Harald Welte943c5bc2010-04-30 16:33:12 +0200500 struct gprs_llc_hdr *lh = msgb_llch(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800501 struct gprs_llc_hdr_parsed llhp;
Harald Welte10997d02010-05-03 12:28:12 +0200502 struct gprs_llc_lle *lle;
Harald Weltea2665542010-05-02 09:28:11 +0200503 int rc = 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800504
Harald Welte11d7c102010-05-02 11:54:55 +0200505 /* Identifiers from DOWN: NSEI, BVCI, TLLI */
506
Harald Welte9b455bf2010-03-14 15:45:01 +0800507 rc = gprs_llc_hdr_parse(&llhp, lh, TLVP_LEN(tv, BSSGP_IE_LLC_PDU));
Harald Weltea2665542010-05-02 09:28:11 +0200508 /* FIXME */
Harald Welte9b455bf2010-03-14 15:45:01 +0800509
510 gprs_llc_hdr_dump(&llhp);
Harald Weltea2665542010-05-02 09:28:11 +0200511
512 /* find the LLC Entity for this TLLI+SAPI tuple */
513 lle = lle_by_tlli_sapi(msgb_tlli(msg), llhp.sapi);
514 /* allocate a new LLE if needed */
515 if (!lle)
516 lle = lle_alloc(msgb_tlli(msg), llhp.sapi);
517
Harald Welte10997d02010-05-03 12:28:12 +0200518 /* Update LLE's (BVCI, NSEI) tuple */
519 lle->bvci = msgb_bvci(msg);
520 lle->nsei = msgb_nsei(msg);
521
Harald Welte9b455bf2010-03-14 15:45:01 +0800522 rc = gprs_llc_hdr_rx(&llhp, lle);
Harald Weltea2665542010-05-02 09:28:11 +0200523 /* FIXME */
Harald Welte9b455bf2010-03-14 15:45:01 +0800524
525 if (llhp.data) {
Harald Welte943c5bc2010-04-30 16:33:12 +0200526 msgb_gmmh(msg) = llhp.data;
Harald Welte9b455bf2010-03-14 15:45:01 +0800527 switch (llhp.sapi) {
528 case GPRS_SAPI_GMM:
529 rc = gsm0408_gprs_rcvmsg(msg);
Harald Weltea2665542010-05-02 09:28:11 +0200530 break;
531 case GPRS_SAPI_TOM2:
532 case GPRS_SAPI_TOM8:
533 /* FIXME */
534 case GPRS_SAPI_SNDCP3:
535 case GPRS_SAPI_SNDCP5:
536 case GPRS_SAPI_SNDCP9:
537 case GPRS_SAPI_SNDCP11:
538 /* FIXME */
539 case GPRS_SAPI_SMS:
540 /* FIXME */
541 default:
542 LOGP(DGPRS, LOGL_NOTICE, "Unsupported SAPI %u\n", llhp.sapi);
543 rc = -EINVAL;
544 break;
Harald Welte9b455bf2010-03-14 15:45:01 +0800545 }
546 }
547
Harald Weltea2665542010-05-02 09:28:11 +0200548 return rc;
Harald Welte9b455bf2010-03-14 15:45:01 +0800549}