blob: e9ce881b8c856b0c7fcbb4834dc74333deb84a4d [file] [log] [blame]
Harald Welte1f0b8c22011-06-27 10:51:37 +02001/* GSM LAPDm (TS 04.06) implementation */
2
3/* (C) 2010-2011 by Harald Welte <laforge@gnumonks.org>
rootaf48bed2011-09-26 11:23:06 +02004 * (C) 2010-2011 by Andreas Eversberg <jolly@eversberg.eu>
Harald Welte1f0b8c22011-06-27 10:51:37 +02005 *
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
Harald Welte6bdf0b12011-08-17 18:22:08 +020024/*! \addtogroup lapdm
25 * @{
26 */
27
28/*! \file lapdm.c */
29
Harald Welte1f0b8c22011-06-27 10:51:37 +020030#include <stdio.h>
31#include <stdint.h>
32#include <string.h>
33#include <errno.h>
34#include <arpa/inet.h>
35
36#include <osmocom/core/logging.h>
37#include <osmocom/core/timer.h>
38#include <osmocom/core/msgb.h>
39#include <osmocom/core/utils.h>
40
41#include <osmocom/gsm/tlv.h>
42#include <osmocom/gsm/rsl.h>
43#include <osmocom/gsm/prim.h>
44#include <osmocom/gsm/gsm_utils.h>
45#include <osmocom/gsm/lapdm.h>
46
47#include <osmocom/gsm/protocol/gsm_04_08.h>
48#include <osmocom/gsm/protocol/gsm_08_58.h>
49
50/* TS 04.06 Figure 4 / Section 3.2 */
51#define LAPDm_LPD_NORMAL 0
52#define LAPDm_LPD_SMSCB 1
53#define LAPDm_SAPI_NORMAL 0
54#define LAPDm_SAPI_SMS 3
55#define LAPDm_ADDR(lpd, sapi, cr) ((((lpd) & 0x3) << 5) | (((sapi) & 0x7) << 2) | (((cr) & 0x1) << 1) | 0x1)
56
rootaf48bed2011-09-26 11:23:06 +020057#define LAPDm_ADDR_LPD(addr) (((addr) >> 5) & 0x3)
Harald Welte1f0b8c22011-06-27 10:51:37 +020058#define LAPDm_ADDR_SAPI(addr) (((addr) >> 2) & 0x7)
59#define LAPDm_ADDR_CR(addr) (((addr) >> 1) & 0x1)
60#define LAPDm_ADDR_EA(addr) ((addr) & 0x1)
61
62/* TS 04.06 Table 3 / Section 3.4.3 */
63#define LAPDm_CTRL_I(nr, ns, p) ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((ns) & 0x7) << 1))
64#define LAPDm_CTRL_S(nr, s, p) ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((s) & 0x3) << 2) | 0x1)
65#define LAPDm_CTRL_U(u, p) ((((u) & 0x1c) << (5-2)) | (((p) & 0x1) << 4) | (((u) & 0x3) << 2) | 0x3)
66
67#define LAPDm_CTRL_is_I(ctrl) (((ctrl) & 0x1) == 0)
68#define LAPDm_CTRL_is_S(ctrl) (((ctrl) & 0x3) == 1)
69#define LAPDm_CTRL_is_U(ctrl) (((ctrl) & 0x3) == 3)
70
71#define LAPDm_CTRL_U_BITS(ctrl) ((((ctrl) & 0xC) >> 2) | ((ctrl) & 0xE0) >> 3)
72#define LAPDm_CTRL_PF_BIT(ctrl) (((ctrl) >> 4) & 0x1)
73
74#define LAPDm_CTRL_S_BITS(ctrl) (((ctrl) & 0xC) >> 2)
75
76#define LAPDm_CTRL_I_Ns(ctrl) (((ctrl) & 0xE) >> 1)
77#define LAPDm_CTRL_Nr(ctrl) (((ctrl) & 0xE0) >> 5)
78
Harald Welte1f0b8c22011-06-27 10:51:37 +020079#define LAPDm_LEN(len) ((len << 2) | 0x1)
80#define LAPDm_MORE 0x2
rootaf48bed2011-09-26 11:23:06 +020081#define LAPDm_EL 0x1
82
83#define LAPDm_U_UI 0x0
Harald Welte1f0b8c22011-06-27 10:51:37 +020084
85/* TS 04.06 Section 5.8.3 */
86#define N201_AB_SACCH 18
87#define N201_AB_SDCCH 20
88#define N201_AB_FACCH 20
89#define N201_Bbis 23
90#define N201_Bter_SACCH 21
91#define N201_Bter_SDCCH 23
92#define N201_Bter_FACCH 23
93#define N201_B4 19
94
95/* 5.8.2.1 N200 during establish and release */
96#define N200_EST_REL 5
97/* 5.8.2.1 N200 during timer recovery state */
98#define N200_TR_SACCH 5
99#define N200_TR_SDCCH 23
100#define N200_TR_FACCH_FR 34
101#define N200_TR_EFACCH_FR 48
102#define N200_TR_FACCH_HR 29
rootaf48bed2011-09-26 11:23:06 +0200103/* FIXME: set N200 depending on chan_nr */
104#define N200 N200_TR_SDCCH
Harald Welte1f0b8c22011-06-27 10:51:37 +0200105
106enum lapdm_format {
107 LAPDm_FMT_A,
108 LAPDm_FMT_B,
109 LAPDm_FMT_Bbis,
110 LAPDm_FMT_Bter,
111 LAPDm_FMT_B4,
112};
113
rootaf48bed2011-09-26 11:23:06 +0200114static int lapdm_send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg);
115static int send_rslms_dlsap(struct osmo_dlsap_prim *dp,
116 struct lapd_msg_ctx *lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200117
118static void lapdm_dl_init(struct lapdm_datalink *dl,
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100119 struct lapdm_entity *entity, int t200)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200120{
121 memset(dl, 0, sizeof(*dl));
Harald Welte1f0b8c22011-06-27 10:51:37 +0200122 dl->entity = entity;
rootaf48bed2011-09-26 11:23:06 +0200123 lapd_dl_init(&dl->dl, 1, 8, 200);
124 dl->dl.reestablish = 0; /* GSM uses no reestablish */
125 dl->dl.send_ph_data_req = lapdm_send_ph_data_req;
126 dl->dl.send_dlsap = send_rslms_dlsap;
127 dl->dl.n200_est_rel = N200_EST_REL;
128 dl->dl.n200 = N200;
129 dl->dl.t203_sec = 0; dl->dl.t203_usec = 0;
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100130 dl->dl.t200_sec = t200; dl->dl.t200_usec = 0;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200131}
132
Harald Welte6bdf0b12011-08-17 18:22:08 +0200133/*! \brief initialize a LAPDm entity and all datalinks inside
134 * \param[in] le LAPDm entity
135 * \param[in] mode \ref lapdm_mode (BTS/MS)
136 */
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100137void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200138{
139 unsigned int i;
140
141 for (i = 0; i < ARRAY_SIZE(le->datalink); i++)
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100142 lapdm_dl_init(&le->datalink[i], le, t200);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200143
144 lapdm_entity_set_mode(le, mode);
145}
146
Harald Welte6bdf0b12011-08-17 18:22:08 +0200147/*! \brief initialize a LAPDm channel and all its channels
148 * \param[in] lc \ref lapdm_channel to be initialized
149 * \param[in] mode \ref lapdm_mode (BTS/MS)
150 *
151 * This really is a convenience wrapper around calling \ref
152 * lapdm_entity_init twice.
153 */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200154void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode)
155{
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100156 lapdm_entity_init(&lc->lapdm_acch, mode, 2);
rootaf48bed2011-09-26 11:23:06 +0200157 /* FIXME: this depends on chan type */
Andreas.Eversberg5ac44782011-11-06 20:35:48 +0100158 lapdm_entity_init(&lc->lapdm_dcch, mode, 1);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200159}
160
Harald Welte6bdf0b12011-08-17 18:22:08 +0200161/*! \brief flush and release all resoures in LAPDm entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200162void lapdm_entity_exit(struct lapdm_entity *le)
163{
164 unsigned int i;
165 struct lapdm_datalink *dl;
166
167 for (i = 0; i < ARRAY_SIZE(le->datalink); i++) {
168 dl = &le->datalink[i];
rootaf48bed2011-09-26 11:23:06 +0200169 lapd_dl_exit(&dl->dl);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200170 }
171}
172
Harald Welte6bdf0b12011-08-17 18:22:08 +0200173/* \brief lfush and release all resources in LAPDm channel
174 *
175 * A convenience wrapper calling \ref lapdm_entity_exit on both
176 * entities inside the \ref lapdm_channel
177 */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200178void lapdm_channel_exit(struct lapdm_channel *lc)
179{
180 lapdm_entity_exit(&lc->lapdm_acch);
181 lapdm_entity_exit(&lc->lapdm_dcch);
182}
183
Harald Welte1f0b8c22011-06-27 10:51:37 +0200184static struct lapdm_datalink *datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi)
185{
186 switch (sapi) {
187 case LAPDm_SAPI_NORMAL:
188 return &le->datalink[0];
189 case LAPDm_SAPI_SMS:
190 return &le->datalink[1];
191 default:
192 return NULL;
193 }
194}
195
196/* remove the L2 header from a MSGB */
197static inline unsigned char *msgb_pull_l2h(struct msgb *msg)
198{
199 unsigned char *ret = msgb_pull(msg, msg->l3h - msg->l2h);
200 msg->l2h = NULL;
201 return ret;
202}
203
204/* Append padding (if required) */
205static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201)
206{
207 int pad_len = n201 - msgb_l2len(msg);
208 uint8_t *data;
209
210 if (pad_len < 0) {
rootaf48bed2011-09-26 11:23:06 +0200211 LOGP(DLLAPD, LOGL_ERROR,
Harald Welte1f0b8c22011-06-27 10:51:37 +0200212 "cannot pad message that is already too big!\n");
213 return;
214 }
215
216 data = msgb_put(msg, pad_len);
217 memset(data, 0x2B, pad_len);
218}
219
220/* input function that L2 calls when sending messages up to L3 */
221static int rslms_sendmsg(struct msgb *msg, struct lapdm_entity *le)
222{
223 if (!le->l3_cb) {
224 msgb_free(msg);
225 return -EIO;
226 }
227
228 /* call the layer2 message handler that is registered */
229 return le->l3_cb(msg, le, le->l3_ctx);
230}
231
232/* write a frame into the tx queue */
233static int tx_ph_data_enqueue(struct lapdm_datalink *dl, struct msgb *msg,
rootaf48bed2011-09-26 11:23:06 +0200234 uint8_t chan_nr, uint8_t link_id, uint8_t pad)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200235{
236 struct lapdm_entity *le = dl->entity;
237 struct osmo_phsap_prim pp;
238
239 /* if there is a pending message, queue it */
240 if (le->tx_pending || le->flags & LAPDM_ENT_F_POLLING_ONLY) {
rootaf48bed2011-09-26 11:23:06 +0200241 *msgb_push(msg, 1) = pad;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200242 *msgb_push(msg, 1) = link_id;
243 *msgb_push(msg, 1) = chan_nr;
rootaf48bed2011-09-26 11:23:06 +0200244 msgb_enqueue(&dl->dl.tx_queue, msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200245 return -EBUSY;
246 }
247
248 osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA,
249 PRIM_OP_REQUEST, msg);
250 pp.u.data.chan_nr = chan_nr;
251 pp.u.data.link_id = link_id;
252
253 /* send the frame now */
254 le->tx_pending = 0; /* disabled flow control */
rootaf48bed2011-09-26 11:23:06 +0200255 lapdm_pad_msgb(msg, pad);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200256
257 return le->l1_prim_cb(&pp.oph, le->l1_ctx);
258}
259
260static struct msgb *tx_dequeue_msgb(struct lapdm_entity *le)
261{
262 struct lapdm_datalink *dl;
263 int last = le->last_tx_dequeue;
264 int i = last, n = ARRAY_SIZE(le->datalink);
265 struct msgb *msg = NULL;
266
267 /* round-robin dequeue */
268 do {
269 /* next */
270 i = (i + 1) % n;
271 dl = &le->datalink[i];
rootaf48bed2011-09-26 11:23:06 +0200272 if ((msg = msgb_dequeue(&dl->dl.tx_queue)))
Harald Welte1f0b8c22011-06-27 10:51:37 +0200273 break;
274 } while (i != last);
275
276 if (msg) {
277 /* Set last dequeue position */
278 le->last_tx_dequeue = i;
279 }
280
281 return msg;
282}
283
Harald Welte6bdf0b12011-08-17 18:22:08 +0200284/*! \brief dequeue a msg that's pending transmission via L1 and wrap it into
Harald Welte1f0b8c22011-06-27 10:51:37 +0200285 * a osmo_phsap_prim */
286int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp)
287{
288 struct msgb *msg;
rootaf48bed2011-09-26 11:23:06 +0200289 uint8_t pad;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200290
291 msg = tx_dequeue_msgb(le);
292 if (!msg)
293 return -ENODEV;
294
295 /* if we have a message, send PH-DATA.req */
296 osmo_prim_init(&pp->oph, SAP_GSM_PH, PRIM_PH_DATA,
297 PRIM_OP_REQUEST, msg);
298
299 /* Pull chan_nr and link_id */
300 pp->u.data.chan_nr = *msg->data;
301 msgb_pull(msg, 1);
302 pp->u.data.link_id = *msg->data;
303 msgb_pull(msg, 1);
rootaf48bed2011-09-26 11:23:06 +0200304 pad = *msg->data;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200305 msgb_pull(msg, 1);
306
307 /* Pad the frame, we can transmit now */
rootaf48bed2011-09-26 11:23:06 +0200308 lapdm_pad_msgb(msg, pad);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200309
310 return 0;
311}
312
313/* get next frame from the tx queue. because the ms has multiple datalinks,
314 * each datalink's queue is read round-robin.
315 */
316static int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le)
317{
318 struct osmo_phsap_prim pp;
319
320 /* we may send again */
321 le->tx_pending = 0;
322
323 /* free confirm message */
324 if (msg)
325 msgb_free(msg);
326
327 if (lapdm_phsap_dequeue_prim(le, &pp) < 0) {
328 /* no message in all queues */
329
330 /* If user didn't request PH-EMPTY_FRAME.req, abort */
331 if (!(le->flags & LAPDM_ENT_F_EMPTY_FRAME))
332 return 0;
333
334 /* otherwise, send PH-EMPTY_FRAME.req */
335 osmo_prim_init(&pp.oph, SAP_GSM_PH,
336 PRIM_PH_EMPTY_FRAME,
337 PRIM_OP_REQUEST, NULL);
338 } else {
339 le->tx_pending = 1;
340 }
341
342 return le->l1_prim_cb(&pp.oph, le->l1_ctx);
343}
344
345/* Create RSLms various RSLms messages */
346static int send_rslms_rll_l3(uint8_t msg_type, struct lapdm_msg_ctx *mctx,
347 struct msgb *msg)
348{
349 /* Add the RSL + RLL header */
350 rsl_rll_push_l3(msg, msg_type, mctx->chan_nr, mctx->link_id, 1);
351
352 /* send off the RSLms message to L3 */
353 return rslms_sendmsg(msg, mctx->dl->entity);
354}
355
356/* Take a B4 format message from L1 and create RSLms UNIT DATA IND */
357static int send_rslms_rll_l3_ui(struct lapdm_msg_ctx *mctx, struct msgb *msg)
358{
359 uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg);
360 struct abis_rsl_rll_hdr *rllh;
361
362 /* Add the RSL + RLL header */
363 msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len);
364 msgb_push(msg, 2 + 2);
365 rsl_rll_push_hdr(msg, RSL_MT_UNIT_DATA_IND, mctx->chan_nr,
366 mctx->link_id, 1);
367 rllh = (struct abis_rsl_rll_hdr *)msgb_l2(msg);
368
369 rllh->data[0] = RSL_IE_TIMING_ADVANCE;
370 rllh->data[1] = mctx->ta_ind;
371
372 rllh->data[2] = RSL_IE_MS_POWER;
373 rllh->data[3] = mctx->tx_power_ind;
374
375 return rslms_sendmsg(msg, mctx->dl->entity);
376}
377
378static int send_rll_simple(uint8_t msg_type, struct lapdm_msg_ctx *mctx)
379{
380 struct msgb *msg;
381
382 msg = rsl_rll_simple(msg_type, mctx->chan_nr, mctx->link_id, 1);
383
384 /* send off the RSLms message to L3 */
385 return rslms_sendmsg(msg, mctx->dl->entity);
386}
387
388static int rsl_rll_error(uint8_t cause, struct lapdm_msg_ctx *mctx)
389{
390 struct msgb *msg;
391
rootaf48bed2011-09-26 11:23:06 +0200392 LOGP(DLLAPD, LOGL_NOTICE, "sending MDL-ERROR-IND %d\n", cause);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200393 msg = rsl_rll_simple(RSL_MT_ERROR_IND, mctx->chan_nr, mctx->link_id, 1);
rootaf48bed2011-09-26 11:23:06 +0200394 msg->l2h = msgb_put(msg, sizeof(struct abis_rsl_rll_hdr));
Harald Welte1f0b8c22011-06-27 10:51:37 +0200395 msgb_tlv_put(msg, RSL_IE_RLM_CAUSE, 1, &cause);
396 return rslms_sendmsg(msg, mctx->dl->entity);
397}
398
rootaf48bed2011-09-26 11:23:06 +0200399/* DLSAP L2 -> L3 (RSLms) */
400static int send_rslms_dlsap(struct osmo_dlsap_prim *dp,
401 struct lapd_msg_ctx *lctx)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200402{
rootaf48bed2011-09-26 11:23:06 +0200403 struct lapd_datalink *dl = lctx->dl;
404 struct lapdm_datalink *mdl =
405 container_of(dl, struct lapdm_datalink, dl);
406 struct lapdm_msg_ctx *mctx = &mdl->mctx;
407 uint8_t rll_msg = 0;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200408
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200409 switch (OSMO_PRIM_HDR(&dp->oph)) {
410 case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_INDICATION):
411 rll_msg = RSL_MT_EST_IND;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200412 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200413 case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_CONFIRM):
414 rll_msg = RSL_MT_EST_CONF;
rootaf48bed2011-09-26 11:23:06 +0200415 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200416 case OSMO_PRIM(PRIM_DL_DATA, PRIM_OP_INDICATION):
417 rll_msg = RSL_MT_DATA_IND;
rootaf48bed2011-09-26 11:23:06 +0200418 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200419 case OSMO_PRIM(PRIM_DL_UNIT_DATA, PRIM_OP_INDICATION):
420 return send_rslms_rll_l3_ui(mctx, dp->oph.msg);
421 case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_INDICATION):
422 rll_msg = RSL_MT_REL_IND;
rootaf48bed2011-09-26 11:23:06 +0200423 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200424 case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_CONFIRM):
425 rll_msg = RSL_MT_REL_CONF;
rootaf48bed2011-09-26 11:23:06 +0200426 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200427 case OSMO_PRIM(PRIM_DL_SUSP, PRIM_OP_CONFIRM):
428 rll_msg = RSL_MT_SUSP_CONF;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200429 break;
Andreas Eversberg78122ab2011-09-27 12:06:55 +0200430 case OSMO_PRIM(PRIM_MDL_ERROR, PRIM_OP_INDICATION):
431 rsl_rll_error(dp->u.error_ind.cause, mctx);
432 if (dp->oph.msg)
433 msgb_free(dp->oph.msg);
434 return 0;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200435 }
rootaf48bed2011-09-26 11:23:06 +0200436
437 if (!rll_msg) {
438 LOGP(DLLAPD, LOGL_ERROR, "Unsupported op %d, prim %d. Please "
439 "fix!\n", dp->oph.primitive, dp->oph.operation);
440 return -EINVAL;
441 }
442
443 if (!dp->oph.msg)
444 return send_rll_simple(rll_msg, mctx);
445
446 return send_rslms_rll_l3(rll_msg, mctx, dp->oph.msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200447}
448
rootaf48bed2011-09-26 11:23:06 +0200449/* send a data frame to layer 1 */
450static int lapdm_send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200451{
rootaf48bed2011-09-26 11:23:06 +0200452 uint8_t l3_len = msg->tail - msg->data;
453 struct lapd_datalink *dl = lctx->dl;
454 struct lapdm_datalink *mdl =
455 container_of(dl, struct lapdm_datalink, dl);
456 struct lapdm_msg_ctx *mctx = &mdl->mctx;
457 int format = lctx->format;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200458
rootaf48bed2011-09-26 11:23:06 +0200459 /* prepend l2 header */
460 msg->l2h = msgb_push(msg, 3);
461 msg->l2h[0] = LAPDm_ADDR(lctx->lpd, lctx->sapi, lctx->cr);
462 /* EA is set here too */
463 switch (format) {
464 case LAPD_FORM_I:
465 msg->l2h[1] = LAPDm_CTRL_I(lctx->n_recv, lctx->n_send,
466 lctx->p_f);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200467 break;
rootaf48bed2011-09-26 11:23:06 +0200468 case LAPD_FORM_S:
469 msg->l2h[1] = LAPDm_CTRL_S(lctx->n_recv, lctx->s_u, lctx->p_f);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200470 break;
rootaf48bed2011-09-26 11:23:06 +0200471 case LAPD_FORM_U:
472 msg->l2h[1] = LAPDm_CTRL_U(lctx->s_u, lctx->p_f);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200473 break;
474 default:
Harald Welte1f0b8c22011-06-27 10:51:37 +0200475 msgb_free(msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200476 return -EINVAL;
477 }
rootaf48bed2011-09-26 11:23:06 +0200478 msg->l2h[2] = LAPDm_LEN(l3_len); /* EL is set here too */
479 if (lctx->more)
480 msg->l2h[2] |= LAPDm_MORE;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200481
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +0100482 /* add ACCH header with last indicated tx-power and TA */
483 if ((mctx->link_id & 0x40)) {
484 struct lapdm_entity *le = mdl->entity;
485
486 msg->l2h = msgb_push(msg, 2);
487 msg->l2h[0] = le->tx_power;
488 msg->l2h[1] = le->ta;
489 }
490
rootaf48bed2011-09-26 11:23:06 +0200491 return tx_ph_data_enqueue(mctx->dl, msg, mctx->chan_nr, mctx->link_id,
492 23);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200493}
494
495/* input into layer2 (from layer 1) */
rootaf48bed2011-09-26 11:23:06 +0200496static int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le,
497 uint8_t chan_nr, uint8_t link_id)
Harald Welte1f0b8c22011-06-27 10:51:37 +0200498{
499 uint8_t cbits = chan_nr >> 3;
Harald Welte64207742011-06-27 23:32:14 +0200500 uint8_t sapi; /* we cannot take SAPI from link_id, as L1 has no clue */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200501 struct lapdm_msg_ctx mctx;
rootaf48bed2011-09-26 11:23:06 +0200502 struct lapd_msg_ctx lctx;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200503 int rc = 0;
rootaf48bed2011-09-26 11:23:06 +0200504 int n201;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200505
506 /* when we reach here, we have a msgb with l2h pointing to the raw
507 * 23byte mac block. The l1h has already been purged. */
508
rootaf48bed2011-09-26 11:23:06 +0200509 memset(&mctx, 0, sizeof(mctx));
Harald Welte1f0b8c22011-06-27 10:51:37 +0200510 mctx.chan_nr = chan_nr;
511 mctx.link_id = link_id;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200512
Harald Welte1f0b8c22011-06-27 10:51:37 +0200513 /* check for L1 chan_nr/link_id and determine LAPDm hdr format */
514 if (cbits == 0x10 || cbits == 0x12) {
515 /* Format Bbis is used on BCCH and CCCH(PCH, NCH and AGCH) */
516 mctx.lapdm_fmt = LAPDm_FMT_Bbis;
rootaf48bed2011-09-26 11:23:06 +0200517 n201 = N201_Bbis;
Harald Welte64207742011-06-27 23:32:14 +0200518 sapi = 0;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200519 } else {
520 if (mctx.link_id & 0x40) {
Harald Welte7ca604b2011-06-29 12:13:51 +0200521 /* It was received from network on SACCH */
522
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100523 /* If UI on SACCH sent by BTS, lapdm_fmt must be B4 */
524 if (le->mode == LAPDM_MODE_MS
525 && LAPDm_CTRL_is_U(msg->l2h[3])
526 && LAPDm_CTRL_U_BITS(msg->l2h[3]) == 0) {
Harald Welte7ca604b2011-06-29 12:13:51 +0200527 mctx.lapdm_fmt = LAPDm_FMT_B4;
rootaf48bed2011-09-26 11:23:06 +0200528 n201 = N201_B4;
529 LOGP(DLLAPD, LOGL_INFO, "fmt=B4\n");
Harald Welte7ca604b2011-06-29 12:13:51 +0200530 } else {
531 mctx.lapdm_fmt = LAPDm_FMT_B;
rootaf48bed2011-09-26 11:23:06 +0200532 n201 = N201_AB_SACCH;
533 LOGP(DLLAPD, LOGL_INFO, "fmt=B\n");
Harald Welte7ca604b2011-06-29 12:13:51 +0200534 }
Harald Welte1f0b8c22011-06-27 10:51:37 +0200535 /* SACCH frames have a two-byte L1 header that
536 * OsmocomBB L1 doesn't strip */
537 mctx.tx_power_ind = msg->l2h[0] & 0x1f;
538 mctx.ta_ind = msg->l2h[1];
539 msgb_pull(msg, 2);
540 msg->l2h += 2;
Harald Welte64207742011-06-27 23:32:14 +0200541 sapi = (msg->l2h[0] >> 2) & 7;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200542 } else {
543 mctx.lapdm_fmt = LAPDm_FMT_B;
rootaf48bed2011-09-26 11:23:06 +0200544 LOGP(DLLAPD, LOGL_INFO, "fmt=B\n");
Andreas.Eversbergcbed3272011-11-06 20:43:08 +0100545 n201 = N201_AB_SDCCH;
Harald Welte64207742011-06-27 23:32:14 +0200546 sapi = (msg->l2h[0] >> 2) & 7;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200547 }
548 }
549
Harald Welte64207742011-06-27 23:32:14 +0200550 mctx.dl = datalink_for_sapi(le, sapi);
551 /* G.2.1 No action on frames containing an unallocated SAPI. */
552 if (!mctx.dl) {
rootaf48bed2011-09-26 11:23:06 +0200553 LOGP(DLLAPD, LOGL_NOTICE, "Received frame for unsupported "
Harald Welte64207742011-06-27 23:32:14 +0200554 "SAPI %d!\n", sapi);
Harald Welte64207742011-06-27 23:32:14 +0200555 msgb_free(msg);
556 return -EIO;
557 }
558
Harald Welte1f0b8c22011-06-27 10:51:37 +0200559 switch (mctx.lapdm_fmt) {
560 case LAPDm_FMT_A:
561 case LAPDm_FMT_B:
562 case LAPDm_FMT_B4:
rootaf48bed2011-09-26 11:23:06 +0200563 lctx.dl = &mctx.dl->dl;
564 /* obtain SAPI from address field */
565 mctx.link_id |= LAPDm_ADDR_SAPI(msg->l2h[0]);
566 /* G.2.3 EA bit set to "0" is not allowed in GSM */
567 if (!LAPDm_ADDR_EA(msg->l2h[0])) {
568 LOGP(DLLAPD, LOGL_NOTICE, "EA bit 0 is not allowed in "
569 "GSM\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200570 msgb_free(msg);
rootaf48bed2011-09-26 11:23:06 +0200571 rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200572 return -EINVAL;
573 }
rootaf48bed2011-09-26 11:23:06 +0200574 /* adress field */
575 lctx.lpd = LAPDm_ADDR_LPD(msg->l2h[0]);
576 lctx.sapi = LAPDm_ADDR_SAPI(msg->l2h[0]);
577 lctx.cr = LAPDm_ADDR_CR(msg->l2h[0]);
578 /* command field */
579 if (LAPDm_CTRL_is_I(msg->l2h[1])) {
580 lctx.format = LAPD_FORM_I;
581 lctx.n_send = LAPDm_CTRL_I_Ns(msg->l2h[1]);
582 lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]);
583 } else if (LAPDm_CTRL_is_S(msg->l2h[1])) {
584 lctx.format = LAPD_FORM_S;
585 lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]);
586 lctx.s_u = LAPDm_CTRL_S_BITS(msg->l2h[1]);
587 } else if (LAPDm_CTRL_is_U(msg->l2h[1])) {
588 lctx.format = LAPD_FORM_U;
589 lctx.s_u = LAPDm_CTRL_U_BITS(msg->l2h[1]);
590 } else
591 lctx.format = LAPD_FORM_UKN;
592 lctx.p_f = LAPDm_CTRL_PF_BIT(msg->l2h[1]);
593 if (lctx.sapi != LAPDm_SAPI_NORMAL
594 && lctx.sapi != LAPDm_SAPI_SMS
595 && lctx.format == LAPD_FORM_U
596 && lctx.s_u == LAPDm_U_UI) {
597 /* 5.3.3 UI frames with invalid SAPI values shall be
598 * discarded
599 */
600 LOGP(DLLAPD, LOGL_INFO, "sapi=%u (discarding)\n",
601 lctx.sapi);
602 msgb_free(msg);
603 return 0;
604 }
605 if (mctx.lapdm_fmt == LAPDm_FMT_B4) {
606 lctx.n201 = n201;
607 lctx.length = n201;
608 lctx.more = 0;
609 msg->l3h = msg->l2h + 2;
610 msgb_pull_l2h(msg);
611 } else {
612 /* length field */
613 if (!(msg->l2h[2] & LAPDm_EL)) {
614 /* G.4.1 If the EL bit is set to "0", an
615 * MDL-ERROR-INDICATION primitive with cause
616 * "frame not implemented" is sent to the
617 * mobile management entity. */
618 LOGP(DLLAPD, LOGL_NOTICE, "we don't support "
619 "multi-octet length\n");
620 msgb_free(msg);
621 rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx);
622 return -EINVAL;
623 }
624 lctx.n201 = n201;
625 lctx.length = msg->l2h[2] >> 2;
626 lctx.more = !!(msg->l2h[2] & LAPDm_MORE);
627 msg->l3h = msg->l2h + 3;
628 msgb_pull_l2h(msg);
629 }
630 /* store context for messages from lapd */
631 memcpy(&mctx.dl->mctx, &mctx, sizeof(mctx.dl->mctx));
632 /* send to LAPD */
633 rc = lapd_ph_data_ind(msg, &lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200634 break;
635 case LAPDm_FMT_Bter:
636 /* FIXME */
637 msgb_free(msg);
638 break;
639 case LAPDm_FMT_Bbis:
640 /* directly pass up to layer3 */
rootaf48bed2011-09-26 11:23:06 +0200641 LOGP(DLLAPD, LOGL_INFO, "fmt=Bbis UI\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200642 msg->l3h = msg->l2h;
643 msgb_pull_l2h(msg);
644 rc = send_rslms_rll_l3(RSL_MT_UNIT_DATA_IND, &mctx, msg);
645 break;
646 default:
647 msgb_free(msg);
648 }
649
650 return rc;
651}
652
653/* input into layer2 (from layer 1) */
654static int l2_ph_rach_ind(struct lapdm_entity *le, uint8_t ra, uint32_t fn, uint8_t acc_delay)
655{
656 struct abis_rsl_cchan_hdr *ch;
657 struct gsm48_req_ref req_ref;
658 struct gsm_time gt;
659 struct msgb *msg = msgb_alloc_headroom(512, 64, "RSL CHAN RQD");
660
661 msg->l2h = msgb_push(msg, sizeof(*ch));
662 ch = (struct abis_rsl_cchan_hdr *)msg->l2h;
663 rsl_init_cchan_hdr(ch, RSL_MT_CHAN_RQD);
664 ch->chan_nr = RSL_CHAN_RACH;
665
666 /* generate a RSL CHANNEL REQUIRED message */
667 gsm_fn2gsmtime(&gt, fn);
668 req_ref.ra = ra;
669 req_ref.t1 = gt.t1; /* FIXME: modulo? */
670 req_ref.t2 = gt.t2;
671 req_ref.t3_low = gt.t3 & 7;
672 req_ref.t3_high = gt.t3 >> 3;
673
674 msgb_tv_fixed_put(msg, RSL_IE_REQ_REFERENCE, 3, (uint8_t *) &req_ref);
675 msgb_tv_put(msg, RSL_IE_ACCESS_DELAY, acc_delay);
676
677 return rslms_sendmsg(msg, le);
678}
679
680static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr);
681
Harald Welte6bdf0b12011-08-17 18:22:08 +0200682/*! \brief Receive a PH-SAP primitive from L1 */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200683int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le)
684{
685 struct osmo_phsap_prim *pp = (struct osmo_phsap_prim *) oph;
686 int rc = 0;
687
688 if (oph->sap != SAP_GSM_PH) {
rootaf48bed2011-09-26 11:23:06 +0200689 LOGP(DLLAPD, LOGL_ERROR, "primitive for unknown SAP %u\n",
Harald Welte1f0b8c22011-06-27 10:51:37 +0200690 oph->sap);
691 return -ENODEV;
692 }
693
694 switch (oph->primitive) {
695 case PRIM_PH_DATA:
696 if (oph->operation != PRIM_OP_INDICATION) {
rootaf48bed2011-09-26 11:23:06 +0200697 LOGP(DLLAPD, LOGL_ERROR, "PH_DATA is not INDICATION %u\n",
Harald Welte1f0b8c22011-06-27 10:51:37 +0200698 oph->operation);
699 return -ENODEV;
700 }
701 rc = l2_ph_data_ind(oph->msg, le, pp->u.data.chan_nr,
702 pp->u.data.link_id);
703 break;
704 case PRIM_PH_RTS:
705 if (oph->operation != PRIM_OP_INDICATION) {
rootaf48bed2011-09-26 11:23:06 +0200706 LOGP(DLLAPD, LOGL_ERROR, "PH_RTS is not INDICATION %u\n",
Harald Welte1f0b8c22011-06-27 10:51:37 +0200707 oph->operation);
708 return -ENODEV;
709 }
710 rc = l2_ph_data_conf(oph->msg, le);
711 break;
712 case PRIM_PH_RACH:
713 switch (oph->operation) {
714 case PRIM_OP_INDICATION:
715 rc = l2_ph_rach_ind(le, pp->u.rach_ind.ra, pp->u.rach_ind.fn,
716 pp->u.rach_ind.acc_delay);
717 break;
718 case PRIM_OP_CONFIRM:
719 rc = l2_ph_chan_conf(oph->msg, le, pp->u.rach_ind.fn);
720 break;
721 default:
722 return -EIO;
723 }
724 break;
725 }
726
727 return rc;
728}
729
730
731/* L3 -> L2 / RSLMS -> LAPDm */
732
rootaf48bed2011-09-26 11:23:06 +0200733/* Set LAPDm context for established connection */
734static int set_lapdm_context(struct lapdm_datalink *dl, uint8_t chan_nr,
735 uint8_t link_id, int n201, uint8_t sapi)
736{
737 memset(&dl->mctx, 0, sizeof(dl->mctx));
738 dl->mctx.dl = dl;
739 dl->mctx.chan_nr = chan_nr;
740 dl->mctx.link_id = link_id;
741 dl->dl.lctx.dl = &dl->dl;
742 dl->dl.lctx.n201 = n201;
743 dl->dl.lctx.sapi = sapi;
744
745 return 0;
746}
747
Harald Welte1f0b8c22011-06-27 10:51:37 +0200748/* L3 requests establishment of data link */
749static int rslms_rx_rll_est_req(struct msgb *msg, struct lapdm_datalink *dl)
750{
Harald Welte1f0b8c22011-06-27 10:51:37 +0200751 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
752 uint8_t chan_nr = rllh->chan_nr;
753 uint8_t link_id = rllh->link_id;
754 uint8_t sapi = rllh->link_id & 7;
755 struct tlv_parsed tv;
756 uint8_t length;
Andreas.Eversbergcbed3272011-11-06 20:43:08 +0100757 uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH;
rootaf48bed2011-09-26 11:23:06 +0200758 struct osmo_dlsap_prim dp;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200759
rootaf48bed2011-09-26 11:23:06 +0200760 /* Set LAPDm context for established connection */
761 set_lapdm_context(dl, chan_nr, link_id, n201, sapi);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200762
rootaf48bed2011-09-26 11:23:06 +0200763 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg) - sizeof(*rllh));
Harald Welte1f0b8c22011-06-27 10:51:37 +0200764 if (TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
rootaf48bed2011-09-26 11:23:06 +0200765 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200766 /* contention resolution establishment procedure */
767 if (sapi != 0) {
768 /* According to clause 6, the contention resolution
769 * procedure is only permitted with SAPI value 0 */
rootaf48bed2011-09-26 11:23:06 +0200770 LOGP(DLLAPD, LOGL_ERROR, "SAPI != 0 but contention"
Harald Welte1f0b8c22011-06-27 10:51:37 +0200771 "resolution (discarding)\n");
772 msgb_free(msg);
773 return send_rll_simple(RSL_MT_REL_IND, &dl->mctx);
774 }
775 /* transmit a SABM command with the P bit set to "1". The SABM
776 * command shall contain the layer 3 message unit */
777 length = TLVP_LEN(&tv, RSL_IE_L3_INFO);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200778 } else {
779 /* normal establishment procedure */
rootaf48bed2011-09-26 11:23:06 +0200780 msg->l3h = msg->l2h + sizeof(*rllh);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200781 length = 0;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200782 }
783
784 /* check if the layer3 message length exceeds N201 */
Andreas.Eversbergcbed3272011-11-06 20:43:08 +0100785 if (length > n201) {
rootaf48bed2011-09-26 11:23:06 +0200786 LOGP(DLLAPD, LOGL_ERROR, "frame too large: %d > N201(%d) "
Andreas.Eversbergcbed3272011-11-06 20:43:08 +0100787 "(discarding)\n", length, n201);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200788 msgb_free(msg);
789 return send_rll_simple(RSL_MT_REL_IND, &dl->mctx);
790 }
791
rootaf48bed2011-09-26 11:23:06 +0200792 /* Remove RLL header from msgb and set length to L3-info */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200793 msgb_pull_l2h(msg);
rootaf48bed2011-09-26 11:23:06 +0200794 msg->len = length;
Holger Hans Peter Freyther3a5f08c2012-01-12 23:12:28 +0100795 msg->tail = msg->l3h + length;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200796
rootaf48bed2011-09-26 11:23:06 +0200797 /* prepare prim */
798 osmo_prim_init(&dp.oph, 0, PRIM_DL_EST, PRIM_OP_REQUEST, msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200799
rootaf48bed2011-09-26 11:23:06 +0200800 /* send to L2 */
801 return lapd_recv_dlsap(&dp, &dl->dl.lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200802}
803
804/* L3 requests transfer of unnumbered information */
805static int rslms_rx_rll_udata_req(struct msgb *msg, struct lapdm_datalink *dl)
806{
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100807 struct lapdm_entity *le = dl->entity;
808 int ui_bts = (le->mode == LAPDM_MODE_BTS);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200809 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
810 uint8_t chan_nr = rllh->chan_nr;
811 uint8_t link_id = rllh->link_id;
812 uint8_t sapi = link_id & 7;
813 struct tlv_parsed tv;
814 int length;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200815
816 /* check if the layer3 message length exceeds N201 */
817
818 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
819
820 if (TLVP_PRESENT(&tv, RSL_IE_TIMING_ADVANCE)) {
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +0100821 le->ta = *TLVP_VAL(&tv, RSL_IE_TIMING_ADVANCE);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200822 }
823 if (TLVP_PRESENT(&tv, RSL_IE_MS_POWER)) {
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +0100824 le->tx_power = *TLVP_VAL(&tv, RSL_IE_MS_POWER);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200825 }
826 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
rootaf48bed2011-09-26 11:23:06 +0200827 LOGP(DLLAPD, LOGL_ERROR, "unit data request without message "
Harald Welte1f0b8c22011-06-27 10:51:37 +0200828 "error\n");
829 msgb_free(msg);
830 return -EINVAL;
831 }
rootaf48bed2011-09-26 11:23:06 +0200832 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200833 length = TLVP_LEN(&tv, RSL_IE_L3_INFO);
834 /* check if the layer3 message length exceeds N201 */
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100835 if (length + 4 + !ui_bts > 23) {
rootaf48bed2011-09-26 11:23:06 +0200836 LOGP(DLLAPD, LOGL_ERROR, "frame too large: %d > N201(%d) "
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100837 "(discarding)\n", length, 18 + ui_bts);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200838 msgb_free(msg);
839 return -EIO;
840 }
841
rootaf48bed2011-09-26 11:23:06 +0200842 LOGP(DLLAPD, LOGL_INFO, "sending unit data (tx_power=%d, ta=%d)\n",
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +0100843 le->tx_power, le->ta);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200844
rootaf48bed2011-09-26 11:23:06 +0200845 /* Remove RLL header from msgb and set length to L3-info */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200846 msgb_pull_l2h(msg);
rootaf48bed2011-09-26 11:23:06 +0200847 msg->len = length;
Holger Hans Peter Freyther3a5f08c2012-01-12 23:12:28 +0100848 msg->tail = msg->l3h + length;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200849
850 /* Push L1 + LAPDm header on msgb */
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100851 msg->l2h = msgb_push(msg, 4 + !ui_bts);
Andreas.Eversbergf1f80de2011-11-06 20:45:29 +0100852 msg->l2h[0] = le->tx_power;
853 msg->l2h[1] = le->ta;
rootaf48bed2011-09-26 11:23:06 +0200854 msg->l2h[2] = LAPDm_ADDR(LAPDm_LPD_NORMAL, sapi, dl->dl.cr.loc2rem.cmd);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200855 msg->l2h[3] = LAPDm_CTRL_U(LAPDm_U_UI, 0);
Andreas.Eversberg816e1782011-11-06 20:46:30 +0100856 if (!ui_bts)
857 msg->l2h[4] = LAPDm_LEN(length);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200858
859 /* Tramsmit */
rootaf48bed2011-09-26 11:23:06 +0200860 return tx_ph_data_enqueue(dl, msg, chan_nr, link_id, 23);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200861}
862
863/* L3 requests transfer of acknowledged information */
864static int rslms_rx_rll_data_req(struct msgb *msg, struct lapdm_datalink *dl)
865{
866 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
867 struct tlv_parsed tv;
rootaf48bed2011-09-26 11:23:06 +0200868 int length;
869 struct osmo_dlsap_prim dp;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200870
871 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
872 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
rootaf48bed2011-09-26 11:23:06 +0200873 LOGP(DLLAPD, LOGL_ERROR, "data request without message "
Harald Welte1f0b8c22011-06-27 10:51:37 +0200874 "error\n");
875 msgb_free(msg);
876 return -EINVAL;
877 }
rootaf48bed2011-09-26 11:23:06 +0200878 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
879 length = TLVP_LEN(&tv, RSL_IE_L3_INFO);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200880
rootaf48bed2011-09-26 11:23:06 +0200881 /* Remove RLL header from msgb and set length to L3-info */
Harald Welte1f0b8c22011-06-27 10:51:37 +0200882 msgb_pull_l2h(msg);
rootaf48bed2011-09-26 11:23:06 +0200883 msg->len = length;
Holger Hans Peter Freyther3a5f08c2012-01-12 23:12:28 +0100884 msg->tail = msg->l3h + length;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200885
rootaf48bed2011-09-26 11:23:06 +0200886 /* prepare prim */
887 osmo_prim_init(&dp.oph, 0, PRIM_DL_DATA, PRIM_OP_REQUEST, msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200888
rootaf48bed2011-09-26 11:23:06 +0200889 /* send to L2 */
890 return lapd_recv_dlsap(&dp, &dl->dl.lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200891}
892
893/* L3 requests suspension of data link */
894static int rslms_rx_rll_susp_req(struct msgb *msg, struct lapdm_datalink *dl)
895{
896 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
897 uint8_t sapi = rllh->link_id & 7;
rootaf48bed2011-09-26 11:23:06 +0200898 struct osmo_dlsap_prim dp;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200899
900 if (sapi != 0) {
rootaf48bed2011-09-26 11:23:06 +0200901 LOGP(DLLAPD, LOGL_ERROR, "SAPI != 0 while suspending\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200902 msgb_free(msg);
903 return -EINVAL;
904 }
905
rootaf48bed2011-09-26 11:23:06 +0200906 /* prepare prim */
907 osmo_prim_init(&dp.oph, 0, PRIM_DL_SUSP, PRIM_OP_REQUEST, msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200908
rootaf48bed2011-09-26 11:23:06 +0200909 /* send to L2 */
910 return lapd_recv_dlsap(&dp, &dl->dl.lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200911}
912
913/* L3 requests resume of data link */
914static int rslms_rx_rll_res_req(struct msgb *msg, struct lapdm_datalink *dl)
915{
Harald Welte1f0b8c22011-06-27 10:51:37 +0200916 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
rootaf48bed2011-09-26 11:23:06 +0200917 int msg_type = rllh->c.msg_type;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200918 uint8_t chan_nr = rllh->chan_nr;
919 uint8_t link_id = rllh->link_id;
920 uint8_t sapi = rllh->link_id & 7;
921 struct tlv_parsed tv;
922 uint8_t length;
Andreas.Eversbergcbed3272011-11-06 20:43:08 +0100923 uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH;
rootaf48bed2011-09-26 11:23:06 +0200924 struct osmo_dlsap_prim dp;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200925
rootaf48bed2011-09-26 11:23:06 +0200926 /* Set LAPDm context for established connection */
927 set_lapdm_context(dl, chan_nr, link_id, n201, sapi);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200928
929 rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh));
930 if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) {
rootaf48bed2011-09-26 11:23:06 +0200931 LOGP(DLLAPD, LOGL_ERROR, "resume without message error\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200932 msgb_free(msg);
933 return send_rll_simple(RSL_MT_REL_IND, &dl->mctx);
934 }
rootaf48bed2011-09-26 11:23:06 +0200935 msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200936 length = TLVP_LEN(&tv, RSL_IE_L3_INFO);
937
rootaf48bed2011-09-26 11:23:06 +0200938 /* Remove RLL header from msgb and set length to L3-info */
939 msgb_pull_l2h(msg);
940 msg->len = length;
Holger Hans Peter Freyther3a5f08c2012-01-12 23:12:28 +0100941 msg->tail = msg->l3h + length;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200942
rootaf48bed2011-09-26 11:23:06 +0200943 /* prepare prim */
944 osmo_prim_init(&dp.oph, 0, (msg_type == RSL_MT_RES_REQ) ? PRIM_DL_RES
945 : PRIM_DL_RECON, PRIM_OP_REQUEST, msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200946
rootaf48bed2011-09-26 11:23:06 +0200947 /* send to L2 */
948 return lapd_recv_dlsap(&dp, &dl->dl.lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200949}
950
951/* L3 requests release of data link */
952static int rslms_rx_rll_rel_req(struct msgb *msg, struct lapdm_datalink *dl)
953{
Harald Welte1f0b8c22011-06-27 10:51:37 +0200954 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200955 uint8_t mode = 0;
rootaf48bed2011-09-26 11:23:06 +0200956 struct osmo_dlsap_prim dp;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200957
958 /* get release mode */
959 if (rllh->data[0] == RSL_IE_RELEASE_MODE)
960 mode = rllh->data[1] & 1;
961
Harald Welte1f0b8c22011-06-27 10:51:37 +0200962 /* Pull rllh */
963 msgb_pull(msg, msg->tail - msg->l2h);
964
rootaf48bed2011-09-26 11:23:06 +0200965 /* prepare prim */
966 osmo_prim_init(&dp.oph, 0, PRIM_DL_REL, PRIM_OP_REQUEST, msg);
967 dp.u.rel_req.mode = mode;
Harald Welte1f0b8c22011-06-27 10:51:37 +0200968
rootaf48bed2011-09-26 11:23:06 +0200969 /* send to L2 */
970 return lapd_recv_dlsap(&dp, &dl->dl.lctx);
Harald Welte1f0b8c22011-06-27 10:51:37 +0200971}
972
973/* L3 requests channel in idle state */
974static int rslms_rx_chan_rqd(struct lapdm_channel *lc, struct msgb *msg)
975{
976 struct abis_rsl_cchan_hdr *cch = msgb_l2(msg);
977 void *l1ctx = lc->lapdm_dcch.l1_ctx;
978 struct osmo_phsap_prim pp;
979
980 osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH,
981 PRIM_OP_REQUEST, NULL);
982
983 if (msgb_l2len(msg) < sizeof(*cch) + 4 + 2 + 2) {
rootaf48bed2011-09-26 11:23:06 +0200984 LOGP(DLLAPD, LOGL_ERROR, "Message too short for CHAN RQD!\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200985 return -EINVAL;
986 }
987 if (cch->data[0] != RSL_IE_REQ_REFERENCE) {
rootaf48bed2011-09-26 11:23:06 +0200988 LOGP(DLLAPD, LOGL_ERROR, "Missing REQ REFERENCE IE\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200989 return -EINVAL;
990 }
991 pp.u.rach_req.ra = cch->data[1];
992 pp.u.rach_req.offset = ((cch->data[2] & 0x7f) << 8) | cch->data[3];
993 pp.u.rach_req.is_combined_ccch = cch->data[2] >> 7;
994
995 if (cch->data[4] != RSL_IE_ACCESS_DELAY) {
rootaf48bed2011-09-26 11:23:06 +0200996 LOGP(DLLAPD, LOGL_ERROR, "Missing ACCESS_DELAY IE\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +0200997 return -EINVAL;
998 }
999 /* TA = 0 - delay */
1000 pp.u.rach_req.ta = 0 - cch->data[5];
1001
1002 if (cch->data[6] != RSL_IE_MS_POWER) {
rootaf48bed2011-09-26 11:23:06 +02001003 LOGP(DLLAPD, LOGL_ERROR, "Missing MS POWER IE\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +02001004 return -EINVAL;
1005 }
1006 pp.u.rach_req.tx_power = cch->data[7];
1007
1008 msgb_free(msg);
1009
1010 return lc->lapdm_dcch.l1_prim_cb(&pp.oph, l1ctx);
1011}
1012
1013/* L1 confirms channel request */
1014static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr)
1015{
1016 struct abis_rsl_cchan_hdr *ch;
1017 struct gsm_time tm;
1018 struct gsm48_req_ref *ref;
1019
1020 gsm_fn2gsmtime(&tm, frame_nr);
1021
1022 msgb_pull_l2h(msg);
1023 msg->l2h = msgb_push(msg, sizeof(*ch) + sizeof(*ref));
1024 ch = (struct abis_rsl_cchan_hdr *)msg->l2h;
1025 rsl_init_cchan_hdr(ch, RSL_MT_CHAN_CONF);
1026 ch->chan_nr = RSL_CHAN_RACH;
1027 ch->data[0] = RSL_IE_REQ_REFERENCE;
1028 ref = (struct gsm48_req_ref *) (ch->data + 1);
1029 ref->t1 = tm.t1;
1030 ref->t2 = tm.t2;
1031 ref->t3_low = tm.t3 & 0x7;
1032 ref->t3_high = tm.t3 >> 3;
1033
1034 return rslms_sendmsg(msg, le);
1035}
1036
Harald Welte1f0b8c22011-06-27 10:51:37 +02001037/* incoming RSLms RLL message from L3 */
1038static int rslms_rx_rll(struct msgb *msg, struct lapdm_channel *lc)
1039{
1040 struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
1041 int msg_type = rllh->c.msg_type;
1042 uint8_t sapi = rllh->link_id & 7;
1043 struct lapdm_entity *le;
1044 struct lapdm_datalink *dl;
Harald Welte1f0b8c22011-06-27 10:51:37 +02001045 int rc = 0;
1046
1047 if (msgb_l2len(msg) < sizeof(*rllh)) {
rootaf48bed2011-09-26 11:23:06 +02001048 LOGP(DLLAPD, LOGL_ERROR, "Message too short for RLL hdr!\n");
Andreas.Eversberga42b6992011-11-06 20:31:47 +01001049 msgb_free(msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +02001050 return -EINVAL;
1051 }
1052
1053 if (rllh->link_id & 0x40)
1054 le = &lc->lapdm_acch;
1055 else
1056 le = &lc->lapdm_dcch;
1057
1058 /* G.2.1 No action schall be taken on frames containing an unallocated
1059 * SAPI.
1060 */
1061 dl = datalink_for_sapi(le, sapi);
1062 if (!dl) {
rootaf48bed2011-09-26 11:23:06 +02001063 LOGP(DLLAPD, LOGL_ERROR, "No instance for SAPI %d!\n", sapi);
Andreas.Eversberga42b6992011-11-06 20:31:47 +01001064 msgb_free(msg);
Harald Welte1f0b8c22011-06-27 10:51:37 +02001065 return -EINVAL;
1066 }
1067
Andreas.Eversberg153903c2011-11-06 20:47:00 +01001068 LOGP(DLLAPD, LOGL_INFO, "(%p) RLL Message '%s' received. (sapi %d)\n",
1069 lc->name, rsl_msg_name(msg_type), sapi);
Harald Welte1f0b8c22011-06-27 10:51:37 +02001070
rootaf48bed2011-09-26 11:23:06 +02001071 switch (msg_type) {
1072 case RSL_MT_UNIT_DATA_REQ:
1073 rc = rslms_rx_rll_udata_req(msg, dl);
1074 break;
1075 case RSL_MT_EST_REQ:
1076 rc = rslms_rx_rll_est_req(msg, dl);
1077 break;
1078 case RSL_MT_DATA_REQ:
1079 rc = rslms_rx_rll_data_req(msg, dl);
1080 break;
1081 case RSL_MT_SUSP_REQ:
1082 rc = rslms_rx_rll_susp_req(msg, dl);
1083 break;
1084 case RSL_MT_RES_REQ:
1085 rc = rslms_rx_rll_res_req(msg, dl);
1086 break;
1087 case RSL_MT_RECON_REQ:
1088 rc = rslms_rx_rll_res_req(msg, dl);
1089 break;
1090 case RSL_MT_REL_REQ:
1091 rc = rslms_rx_rll_rel_req(msg, dl);
1092 break;
1093 default:
1094 LOGP(DLLAPD, LOGL_NOTICE, "Message unsupported.\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +02001095 msgb_free(msg);
rootaf48bed2011-09-26 11:23:06 +02001096 rc = -EINVAL;
Harald Welte1f0b8c22011-06-27 10:51:37 +02001097 }
Harald Welte1f0b8c22011-06-27 10:51:37 +02001098
1099 return rc;
1100}
1101
1102/* incoming RSLms COMMON CHANNEL message from L3 */
1103static int rslms_rx_com_chan(struct msgb *msg, struct lapdm_channel *lc)
1104{
1105 struct abis_rsl_cchan_hdr *cch = msgb_l2(msg);
1106 int msg_type = cch->c.msg_type;
1107 int rc = 0;
1108
1109 if (msgb_l2len(msg) < sizeof(*cch)) {
rootaf48bed2011-09-26 11:23:06 +02001110 LOGP(DLLAPD, LOGL_ERROR, "Message too short for COM CHAN hdr!\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +02001111 return -EINVAL;
1112 }
1113
1114 switch (msg_type) {
1115 case RSL_MT_CHAN_RQD:
1116 /* create and send RACH request */
1117 rc = rslms_rx_chan_rqd(lc, msg);
1118 break;
1119 default:
rootaf48bed2011-09-26 11:23:06 +02001120 LOGP(DLLAPD, LOGL_NOTICE, "Unknown COMMON CHANNEL msg %d!\n",
Harald Welte1f0b8c22011-06-27 10:51:37 +02001121 msg_type);
1122 msgb_free(msg);
1123 return 0;
1124 }
1125
1126 return rc;
1127}
1128
Harald Welte6bdf0b12011-08-17 18:22:08 +02001129/*! \brief Receive a RSLms \ref msgb from Layer 3 */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001130int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc)
1131{
1132 struct abis_rsl_common_hdr *rslh = msgb_l2(msg);
1133 int rc = 0;
1134
1135 if (msgb_l2len(msg) < sizeof(*rslh)) {
rootaf48bed2011-09-26 11:23:06 +02001136 LOGP(DLLAPD, LOGL_ERROR, "Message too short RSL hdr!\n");
Harald Welte1f0b8c22011-06-27 10:51:37 +02001137 return -EINVAL;
1138 }
1139
1140 switch (rslh->msg_discr & 0xfe) {
1141 case ABIS_RSL_MDISC_RLL:
1142 rc = rslms_rx_rll(msg, lc);
1143 break;
1144 case ABIS_RSL_MDISC_COM_CHAN:
1145 rc = rslms_rx_com_chan(msg, lc);
1146 break;
1147 default:
rootaf48bed2011-09-26 11:23:06 +02001148 LOGP(DLLAPD, LOGL_ERROR, "unknown RSLms message "
Harald Welte1f0b8c22011-06-27 10:51:37 +02001149 "discriminator 0x%02x", rslh->msg_discr);
1150 msgb_free(msg);
1151 return -EINVAL;
1152 }
1153
1154 return rc;
1155}
1156
Harald Welte6bdf0b12011-08-17 18:22:08 +02001157/*! \brief Set the \ref lapdm_mode of a LAPDm entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001158int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode)
1159{
rootaf48bed2011-09-26 11:23:06 +02001160 int i;
1161 enum lapd_mode lm;
1162
Harald Welte1f0b8c22011-06-27 10:51:37 +02001163 switch (mode) {
1164 case LAPDM_MODE_MS:
rootaf48bed2011-09-26 11:23:06 +02001165 lm = LAPD_MODE_USER;
Harald Welte1f0b8c22011-06-27 10:51:37 +02001166 break;
1167 case LAPDM_MODE_BTS:
rootaf48bed2011-09-26 11:23:06 +02001168 lm = LAPD_MODE_NETWORK;
Harald Welte1f0b8c22011-06-27 10:51:37 +02001169 break;
1170 default:
1171 return -EINVAL;
1172 }
1173
rootaf48bed2011-09-26 11:23:06 +02001174 for (i = 0; i < ARRAY_SIZE(le->datalink); i++) {
1175 lapd_set_mode(&le->datalink[i].dl, lm);
1176 }
1177
Harald Welte1f0b8c22011-06-27 10:51:37 +02001178 le->mode = mode;
1179
1180 return 0;
1181}
1182
Harald Welte6bdf0b12011-08-17 18:22:08 +02001183/*! \brief Set the \ref lapdm_mode of a LAPDm channel*/
Harald Welte1f0b8c22011-06-27 10:51:37 +02001184int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode)
1185{
1186 int rc;
1187
1188 rc = lapdm_entity_set_mode(&lc->lapdm_dcch, mode);
1189 if (rc < 0)
1190 return rc;
1191
1192 return lapdm_entity_set_mode(&lc->lapdm_acch, mode);
1193}
1194
Harald Welte6bdf0b12011-08-17 18:22:08 +02001195/*! \brief Set the L1 callback and context of a LAPDm channel */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001196void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx)
1197{
1198 lc->lapdm_dcch.l1_prim_cb = cb;
1199 lc->lapdm_acch.l1_prim_cb = cb;
1200 lc->lapdm_dcch.l1_ctx = ctx;
1201 lc->lapdm_acch.l1_ctx = ctx;
1202}
1203
Harald Welte6bdf0b12011-08-17 18:22:08 +02001204/*! \brief Set the L3 callback and context of a LAPDm channel */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001205void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx)
1206{
1207 lc->lapdm_dcch.l3_cb = cb;
1208 lc->lapdm_acch.l3_cb = cb;
1209 lc->lapdm_dcch.l3_ctx = ctx;
1210 lc->lapdm_acch.l3_ctx = ctx;
1211}
1212
Harald Welte6bdf0b12011-08-17 18:22:08 +02001213/*! \brief Reset an entire LAPDm entity and all its datalinks */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001214void lapdm_entity_reset(struct lapdm_entity *le)
1215{
1216 struct lapdm_datalink *dl;
1217 int i;
1218
1219 for (i = 0; i < ARRAY_SIZE(le->datalink); i++) {
1220 dl = &le->datalink[i];
rootaf48bed2011-09-26 11:23:06 +02001221 lapd_dl_reset(&dl->dl);
Harald Welte1f0b8c22011-06-27 10:51:37 +02001222 }
1223}
1224
Harald Welte6bdf0b12011-08-17 18:22:08 +02001225/*! \brief Reset a LAPDm channel with all its entities */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001226void lapdm_channel_reset(struct lapdm_channel *lc)
1227{
1228 lapdm_entity_reset(&lc->lapdm_dcch);
1229 lapdm_entity_reset(&lc->lapdm_acch);
1230}
1231
Harald Welte6bdf0b12011-08-17 18:22:08 +02001232/*! \brief Set the flags of a LAPDm entity */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001233void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags)
1234{
1235 le->flags = flags;
1236}
1237
Harald Welte6bdf0b12011-08-17 18:22:08 +02001238/*! \brief Set the flags of all LAPDm entities in a LAPDm channel */
Harald Welte1f0b8c22011-06-27 10:51:37 +02001239void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags)
1240{
1241 lapdm_entity_set_flags(&lc->lapdm_dcch, flags);
1242 lapdm_entity_set_flags(&lc->lapdm_acch, flags);
1243}
Harald Welte6bdf0b12011-08-17 18:22:08 +02001244
1245/*! }@ */