blob: f351308d250ec4c8c2b7d4c66521bce30a3af995 [file] [log] [blame]
rootaf48bed2011-09-26 11:23:06 +02001/* LAPD core implementation */
2
3/* (C) 2010-2011 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2010-2011 by Andreas Eversberg <jolly@eversberg.eu>
5 *
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/*! \addtogroup lapd
25 * @{
26 */
27
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010028/*! \file lapd_core.c */
rootaf48bed2011-09-26 11:23:06 +020029
30/*!
31 * Notes on Buffering: rcv_buffer, tx_queue, tx_hist, send_buffer, send_queue
32 *
33 * RX data is stored in the rcv_buffer (pointer). If the message is complete, it
34 * is removed from rcv_buffer pointer and forwarded to L3. If the RX data is
35 * received while there is an incomplete rcv_buffer, it is appended to it.
36 *
37 * TX data is stored in the send_queue first. When transmitting a frame,
38 * the first message in the send_queue is moved to the send_buffer. There it
39 * resides until all fragments are acknowledged. Fragments to be sent by I
40 * frames are stored in the tx_hist buffer for resend, if required. Also the
41 * current fragment is copied into the tx_queue. There it resides until it is
42 * forwarded to layer 1.
43 *
44 * In case we have SAPI 0, we only have a window size of 1, so the unack-
45 * nowledged message resides always in the send_buffer. In case of a suspend,
46 * it can be written back to the first position of the send_queue.
47 *
48 * The layer 1 normally sends a PH-READY-TO-SEND. But because we use
49 * asynchronous transfer between layer 1 and layer 2 (serial link), we must
50 * send a frame before layer 1 reaches the right timeslot to send it. So we
51 * move the tx_queue to layer 1 when there is not already a pending frame, and
52 * wait until acknowledge after the frame has been sent. If we receive an
53 * acknowledge, we can send the next frame from the buffer, if any.
54 *
55 * The moving of tx_queue to layer 1 may also trigger T200, if desired. Also it
56 * will trigger next I frame, if possible.
57 *
58 * T203 is optional. It will be stated when entering MF EST state. It will also
59 * be started when I or S frame is received in that state . It will be
60 * restarted in the lapd_acknowledge() function, in case outstanding frames
61 * will not trigger T200. It will be stoped, when T200 is started in MF EST
62 * state. It will also be stoped when leaving MF EST state.
63 *
64 */
65
66/* Enable this to test content resolution on network side:
67 * - The first SABM is received, UA is dropped.
68 * - The phone repeats SABM, but it's content is wrong, so it is ignored
69 * - The phone repeats SABM again, content is right, so UA is sent.
70 */
71//#define TEST_CONTENT_RESOLUTION_NETWORK
72
73#include <stdio.h>
74#include <stdint.h>
75#include <string.h>
76#include <errno.h>
77#include <arpa/inet.h>
78
79#include <osmocom/core/logging.h>
80#include <osmocom/core/timer.h>
81#include <osmocom/core/msgb.h>
82#include <osmocom/core/utils.h>
83#include <osmocom/core/talloc.h>
84#include <osmocom/gsm/lapd_core.h>
85
86/* TS 04.06 Table 4 / Section 3.8.1 */
87#define LAPD_U_SABM 0x7
88#define LAPD_U_SABME 0xf
89#define LAPD_U_DM 0x3
90#define LAPD_U_UI 0x0
91#define LAPD_U_DISC 0x8
92#define LAPD_U_UA 0xC
93#define LAPD_U_FRMR 0x11
94
95#define LAPD_S_RR 0x0
96#define LAPD_S_RNR 0x1
97#define LAPD_S_REJ 0x2
98
99#define CR_USER2NET_CMD 0
100#define CR_USER2NET_RESP 1
101#define CR_NET2USER_CMD 1
102#define CR_NET2USER_RESP 0
103
104#define LAPD_HEADROOM 56
105
106#define SBIT(a) (1 << a)
107#define ALL_STATES 0xffffffff
108
Andreas Eversberg742fc792011-09-27 09:40:25 +0200109static void lapd_t200_cb(void *data);
110static void lapd_t203_cb(void *data);
111static int lapd_send_i(struct lapd_msg_ctx *lctx, int line);
112static int lapd_est_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx);
113
rootaf48bed2011-09-26 11:23:06 +0200114/* UTILITY FUNCTIONS */
115
116struct msgb *lapd_msgb_alloc(int length, const char *name)
117{
118 /* adding space for padding, FIXME: add as an option */
119 if (length < 21)
120 length = 21;
121 return msgb_alloc_headroom(length + LAPD_HEADROOM, LAPD_HEADROOM, name);
122}
123
124static inline uint8_t do_mod(uint8_t x, uint8_t m)
125{
126 return x & (m - 1);
127}
128
129static inline uint8_t inc_mod(uint8_t x, uint8_t m)
130{
131 return (x + 1) & (m - 1);
132}
133
134static inline uint8_t add_mod(uint8_t x, uint8_t y, uint8_t m)
135{
136 return (x + y) & (m - 1);
137}
138
139static inline uint8_t sub_mod(uint8_t x, uint8_t y, uint8_t m)
140{
141 return (x - y) & (m - 1); /* handle negative results correctly */
142}
143
144static void lapd_dl_flush_send(struct lapd_datalink *dl)
145{
146 struct msgb *msg;
147
148 /* Flush send-queue */
149 while ((msg = msgb_dequeue(&dl->send_queue)))
150 msgb_free(msg);
151
152 /* Clear send-buffer */
153 if (dl->send_buffer) {
154 msgb_free(dl->send_buffer);
155 dl->send_buffer = NULL;
156 }
157}
158
159static void lapd_dl_flush_hist(struct lapd_datalink *dl)
160{
161 unsigned int i;
162
163 for (i = 0; i < dl->range_hist; i++) {
164 if (dl->tx_hist[i].msg) {
165 msgb_free(dl->tx_hist[i].msg);
166 dl->tx_hist[i].msg = NULL;
167 }
168 }
169}
170
171static void lapd_dl_flush_tx(struct lapd_datalink *dl)
172{
173 struct msgb *msg;
174
175 while ((msg = msgb_dequeue(&dl->tx_queue)))
176 msgb_free(msg);
177 lapd_dl_flush_hist(dl);
178}
179
180/* Figure B.2/Q.921 */
181const char *lapd_state_names[] = {
182 "LAPD_STATE_NULL",
183 "LAPD_STATE_TEI_UNASS",
184 "LAPD_STATE_ASS_TEI_WAIT",
185 "LAPD_STATE_EST_TEI_WAIT",
186 "LAPD_STATE_IDLE",
187 "LAPD_STATE_SABM_SENT",
188 "LAPD_STATE_DISC_SENT",
189 "LAPD_STATE_MF_EST",
190 "LAPD_STATE_TIMER_RECOV",
191
192};
193
Andreas Eversberg742fc792011-09-27 09:40:25 +0200194static void lapd_start_t200(struct lapd_datalink *dl)
195{
196 if (osmo_timer_pending(&dl->t200))
197 return;
198 LOGP(DLLAPD, LOGL_INFO, "start T200\n");
199 osmo_timer_schedule(&dl->t200, dl->t200_sec, dl->t200_usec);
200}
201
202static void lapd_start_t203(struct lapd_datalink *dl)
203{
204 if (osmo_timer_pending(&dl->t203))
205 return;
206 LOGP(DLLAPD, LOGL_INFO, "start T203\n");
207 osmo_timer_schedule(&dl->t203, dl->t203_sec, dl->t203_usec);
208}
209
210static void lapd_stop_t200(struct lapd_datalink *dl)
211{
212 if (!osmo_timer_pending(&dl->t200))
213 return;
214 LOGP(DLLAPD, LOGL_INFO, "stop T200\n");
215 osmo_timer_del(&dl->t200);
216}
217
218static void lapd_stop_t203(struct lapd_datalink *dl)
219{
220 if (!osmo_timer_pending(&dl->t203))
221 return;
222 LOGP(DLLAPD, LOGL_INFO, "stop T203\n");
223 osmo_timer_del(&dl->t203);
224}
225
rootaf48bed2011-09-26 11:23:06 +0200226static void lapd_dl_newstate(struct lapd_datalink *dl, uint32_t state)
227{
228 LOGP(DLLAPD, LOGL_INFO, "new state %s -> %s\n",
229 lapd_state_names[dl->state], lapd_state_names[state]);
230
231 if (state != LAPD_STATE_MF_EST && dl->state == LAPD_STATE_MF_EST) {
232 /* stop T203 on leaving MF EST state, if running */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200233 lapd_stop_t203(dl);
rootaf48bed2011-09-26 11:23:06 +0200234 /* remove content res. (network side) on leaving MF EST state */
235 if (dl->cont_res) {
236 msgb_free(dl->cont_res);
237 dl->cont_res = NULL;
238 }
239 }
240
241 /* start T203 on entering MF EST state, if enabled */
242 if ((dl->t203_sec || dl->t203_usec)
Andreas Eversberg742fc792011-09-27 09:40:25 +0200243 && state == LAPD_STATE_MF_EST && dl->state != LAPD_STATE_MF_EST)
244 lapd_start_t203(dl);
rootaf48bed2011-09-26 11:23:06 +0200245
246 dl->state = state;
247}
248
rootaf48bed2011-09-26 11:23:06 +0200249static void *tall_lapd_ctx = NULL;
250
251/* init datalink instance and allocate history */
252void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range,
253 int maxf)
254{
255 int m;
256
257 memset(dl, 0, sizeof(*dl));
258 INIT_LLIST_HEAD(&dl->send_queue);
259 INIT_LLIST_HEAD(&dl->tx_queue);
260 dl->reestablish = 1;
261 dl->n200_est_rel = 3;
262 dl->n200 = 3;
263 dl->t200_sec = 1;
264 dl->t200_usec = 0;
265 dl->t200.data = dl;
266 dl->t200.cb = &lapd_t200_cb;
267 dl->t203_sec = 10;
268 dl->t203_usec = 0;
269 dl->t203.data = dl;
270 dl->t203.cb = &lapd_t203_cb;
271 dl->maxf = maxf;
272 if (k > v_range - 1)
273 k = v_range - 1;
274 dl->k = k;
275 dl->v_range = v_range;
276
277 /* Calculate modulo for history array:
278 * - The history range must be at least k+1.
279 * - The history range must be 2^x, where x is as low as possible.
280 */
281 k++;
282 for (m = 0x80; m; m >>= 1) {
283 if ((m & k)) {
284 if (k > m)
285 m <<= 1;
286 dl->range_hist = m;
287 break;
288 }
289 }
290
291 LOGP(DLLAPD, LOGL_INFO, "Init DL layer: sequence range = %d, k = %d, "
292 "history range = %d\n", dl->v_range, dl->k, dl->range_hist);
293
294 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
295
296 if (!tall_lapd_ctx)
297 tall_lapd_ctx = talloc_named_const(NULL, 1, "lapd context");
298 dl->tx_hist = (struct lapd_history *) talloc_zero_array(tall_lapd_ctx,
299 struct log_info, dl->range_hist);
300}
301
302/* reset to IDLE state */
303void lapd_dl_reset(struct lapd_datalink *dl)
304{
305 if (dl->state == LAPD_STATE_IDLE)
306 return;
307 LOGP(DLLAPD, LOGL_INFO, "Resetting LAPDm instance\n");
308 /* enter idle state (and remove eventual cont_res) */
309 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
310 /* flush buffer */
311 lapd_dl_flush_tx(dl);
312 lapd_dl_flush_send(dl);
313 /* Discard partly received L3 message */
314 if (dl->rcv_buffer) {
315 msgb_free(dl->rcv_buffer);
316 dl->rcv_buffer = NULL;
317 }
Andreas Eversberg742fc792011-09-27 09:40:25 +0200318 /* stop Timers */
319 lapd_stop_t200(dl);
320 lapd_stop_t203(dl);
rootaf48bed2011-09-26 11:23:06 +0200321}
322
323/* reset and de-allocate history buffer */
324void lapd_dl_exit(struct lapd_datalink *dl)
325{
326 /* free all ressources except history buffer */
327 lapd_dl_reset(dl);
328 /* free history buffer list */
329 talloc_free(dl->tx_hist);
330}
331
332/*! \brief Set the \ref lapdm_mode of a LAPDm entity */
333int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode)
334{
335 switch (mode) {
336 case LAPD_MODE_USER:
337 dl->cr.loc2rem.cmd = CR_USER2NET_CMD;
338 dl->cr.loc2rem.resp = CR_USER2NET_RESP;
339 dl->cr.rem2loc.cmd = CR_NET2USER_CMD;
340 dl->cr.rem2loc.resp = CR_NET2USER_RESP;
341 break;
342 case LAPD_MODE_NETWORK:
343 dl->cr.loc2rem.cmd = CR_NET2USER_CMD;
344 dl->cr.loc2rem.resp = CR_NET2USER_RESP;
345 dl->cr.rem2loc.cmd = CR_USER2NET_CMD;
346 dl->cr.rem2loc.resp = CR_USER2NET_RESP;
347 break;
348 default:
349 return -EINVAL;
350 }
351 dl->mode = mode;
352
353 return 0;
354}
355
356/* send DL message with optional msgb */
357static int send_dl_l3(uint8_t prim, uint8_t op, struct lapd_msg_ctx *lctx,
358 struct msgb *msg)
359{
360 struct lapd_datalink *dl = lctx->dl;
361 struct osmo_dlsap_prim dp;
362
363 osmo_prim_init(&dp.oph, 0, prim, op, msg);
364 return dl->send_dlsap(&dp, lctx);
365}
366
367/* send simple DL message */
368static inline int send_dl_simple(uint8_t prim, uint8_t op,
369 struct lapd_msg_ctx *lctx)
370{
371 struct msgb *msg = lapd_msgb_alloc(0, "DUMMY");
372
373 return send_dl_l3(prim, op, lctx, msg);
374}
375
376/* send MDL-ERROR INDICATION */
377static int mdl_error(uint8_t cause, struct lapd_msg_ctx *lctx)
378{
379 struct lapd_datalink *dl = lctx->dl;
380 struct osmo_dlsap_prim dp;
381
382 LOGP(DLLAPD, LOGL_NOTICE, "sending MDL-ERROR-IND cause %d\n",
383 cause);
384 osmo_prim_init(&dp.oph, 0, PRIM_MDL_ERROR, PRIM_OP_INDICATION, NULL);
385 dp.u.error_ind.cause = cause;
386 return dl->send_dlsap(&dp, lctx);
387}
388
389/* send UA response */
390static int lapd_send_ua(struct lapd_msg_ctx *lctx, uint8_t len, uint8_t *data)
391{
392 struct msgb *msg = lapd_msgb_alloc(len, "LAPD UA");
393 struct lapd_msg_ctx nctx;
394 struct lapd_datalink *dl = lctx->dl;
395
396 memcpy(&nctx, lctx, sizeof(nctx));
397 msg->l3h = msgb_put(msg, len);
398 if (len)
399 memcpy(msg->l3h, data, len);
400 /* keep nctx.ldp */
401 /* keep nctx.sapi */
402 /* keep nctx.tei */
403 nctx.cr = dl->cr.loc2rem.resp;
404 nctx.format = LAPD_FORM_U;
405 nctx.s_u = LAPD_U_UA;
406 /* keep nctx.p_f */
407 nctx.length = len;
408 nctx.more = 0;
409
410 return dl->send_ph_data_req(&nctx, msg);
411}
412
413/* send DM response */
414static int lapd_send_dm(struct lapd_msg_ctx *lctx)
415{
416 struct msgb *msg = lapd_msgb_alloc(0, "LAPD DM");
417 struct lapd_msg_ctx nctx;
418 struct lapd_datalink *dl = lctx->dl;
419
420 memcpy(&nctx, lctx, sizeof(nctx));
421 /* keep nctx.ldp */
422 /* keep nctx.sapi */
423 /* keep nctx.tei */
424 nctx.cr = dl->cr.loc2rem.resp;
425 nctx.format = LAPD_FORM_U;
426 nctx.s_u = LAPD_U_DM;
427 /* keep nctx.p_f */
428 nctx.length = 0;
429 nctx.more = 0;
430
431 return dl->send_ph_data_req(&nctx, msg);
432}
433
434/* send RR response / command */
435static int lapd_send_rr(struct lapd_msg_ctx *lctx, uint8_t f_bit, uint8_t cmd)
436{
437 struct msgb *msg = lapd_msgb_alloc(0, "LAPD RR");
438 struct lapd_msg_ctx nctx;
439 struct lapd_datalink *dl = lctx->dl;
440
441 memcpy(&nctx, lctx, sizeof(nctx));
442 /* keep nctx.ldp */
443 /* keep nctx.sapi */
444 /* keep nctx.tei */
445 nctx.cr = (cmd) ? dl->cr.loc2rem.cmd : dl->cr.loc2rem.resp;
446 nctx.format = LAPD_FORM_S;
447 nctx.s_u = LAPD_S_RR;
448 nctx.p_f = f_bit;
449 nctx.n_recv = dl->v_recv;
450 nctx.length = 0;
451 nctx.more = 0;
452
453 return dl->send_ph_data_req(&nctx, msg);
454}
455
456/* send RNR response / command */
457static int lapd_send_rnr(struct lapd_msg_ctx *lctx, uint8_t f_bit, uint8_t cmd)
458{
459 struct msgb *msg = lapd_msgb_alloc(0, "LAPD RNR");
460 struct lapd_msg_ctx nctx;
461 struct lapd_datalink *dl = lctx->dl;
462
463 memcpy(&nctx, lctx, sizeof(nctx));
464 /* keep nctx.ldp */
465 /* keep nctx.sapi */
466 /* keep nctx.tei */
467 nctx.cr = (cmd) ? dl->cr.loc2rem.cmd : dl->cr.loc2rem.resp;
468 nctx.format = LAPD_FORM_S;
469 nctx.s_u = LAPD_S_RNR;
470 nctx.p_f = f_bit;
471 nctx.n_recv = dl->v_recv;
472 nctx.length = 0;
473 nctx.more = 0;
474
475 return dl->send_ph_data_req(&nctx, msg);
476}
477
478/* send REJ response */
479static int lapd_send_rej(struct lapd_msg_ctx *lctx, uint8_t f_bit)
480{
481 struct msgb *msg = lapd_msgb_alloc(0, "LAPD REJ");
482 struct lapd_msg_ctx nctx;
483 struct lapd_datalink *dl = lctx->dl;
484
485 memcpy(&nctx, lctx, sizeof(nctx));
486 /* keep nctx.ldp */
487 /* keep nctx.sapi */
488 /* keep nctx.tei */
489 nctx.cr = dl->cr.loc2rem.resp;
490 nctx.format = LAPD_FORM_S;
491 nctx.s_u = LAPD_S_REJ;
492 nctx.p_f = f_bit;
493 nctx.n_recv = dl->v_recv;
494 nctx.length = 0;
495 nctx.more = 0;
496
497 return dl->send_ph_data_req(&nctx, msg);
498}
499
500/* resend SABM or DISC message */
501static int lapd_send_resend(struct lapd_datalink *dl)
502{
503 struct msgb *msg;
504 uint8_t h = do_mod(dl->v_send, dl->range_hist);
505 int length = dl->tx_hist[h].msg->len;
506 struct lapd_msg_ctx nctx;
507
508 /* assemble message */
509 memcpy(&nctx, &dl->lctx, sizeof(nctx));
510 /* keep nctx.ldp */
511 /* keep nctx.sapi */
512 /* keep nctx.tei */
513 nctx.cr = dl->cr.loc2rem.cmd;
514 nctx.format = LAPD_FORM_U;
515 if (dl->state == LAPD_STATE_SABM_SENT)
516 nctx.s_u = (dl->use_sabme) ? LAPD_U_SABME : LAPD_U_SABM;
517 else
518 nctx.s_u = LAPD_U_DISC;
519 nctx.p_f = 1;
520 nctx.length = length;
521 nctx.more = 0;
522
523 /* Resend SABM/DISC from tx_hist */
524 msg = lapd_msgb_alloc(length, "LAPD resend");
525 msg->l3h = msgb_put(msg, length);
526 if (length)
527 memcpy(msg->l3h, dl->tx_hist[h].msg->data, length);
528
529 return dl->send_ph_data_req(&nctx, msg);
530}
531
532/* reestablish link */
533static int lapd_reestablish(struct lapd_datalink *dl)
534{
535 struct osmo_dlsap_prim dp;
536 struct msgb *msg;
537
538 msg = lapd_msgb_alloc(0, "DUMMY");
539 osmo_prim_init(&dp.oph, 0, PRIM_DL_EST, PRIM_OP_REQUEST, msg);
540
541 return lapd_est_req(&dp, &dl->lctx);
542}
543
544/* Timer callback on T200 expiry */
545static void lapd_t200_cb(void *data)
546{
547 struct lapd_datalink *dl = data;
548
Andreas Eversberg742fc792011-09-27 09:40:25 +0200549 LOGP(DLLAPD, LOGL_INFO, "Timeout T200 (%p) state=%d\n", dl,
rootaf48bed2011-09-26 11:23:06 +0200550 (int) dl->state);
551
552 switch (dl->state) {
553 case LAPD_STATE_SABM_SENT:
554 /* 5.4.1.3 */
555 if (dl->retrans_ctr + 1 >= dl->n200_est_rel + 1) {
556 /* send RELEASE INDICATION to L3 */
557 send_dl_simple(PRIM_DL_REL, PRIM_OP_INDICATION,
558 &dl->lctx);
559 /* send MDL ERROR INIDCATION to L3 */
560 mdl_error(MDL_CAUSE_T200_EXPIRED, &dl->lctx);
561 /* flush tx and send buffers */
562 lapd_dl_flush_tx(dl);
563 lapd_dl_flush_send(dl);
564 /* go back to idle state */
565 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
566 /* NOTE: we must not change any other states or buffers
567 * and queues, since we may reconnect after handover
568 * failure. the buffered messages is replaced there */
569 break;
570 }
571 /* retransmit SABM command */
572 lapd_send_resend(dl);
573 /* increment re-transmission counter */
574 dl->retrans_ctr++;
575 /* restart T200 (PH-READY-TO-SEND) */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200576 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200577 break;
578 case LAPD_STATE_DISC_SENT:
579 /* 5.4.4.3 */
580 if (dl->retrans_ctr + 1 >= dl->n200_est_rel + 1) {
581 /* send RELEASE INDICATION to L3 */
582 send_dl_simple(PRIM_DL_REL, PRIM_OP_CONFIRM, &dl->lctx);
583 /* send MDL ERROR INIDCATION to L3 */
584 mdl_error(MDL_CAUSE_T200_EXPIRED, &dl->lctx);
585 /* flush tx and send buffers */
586 lapd_dl_flush_tx(dl);
587 lapd_dl_flush_send(dl);
588 /* go back to idle state */
589 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
590 /* NOTE: we must not change any other states or buffers
591 * and queues, since we may reconnect after handover
592 * failure. the buffered messages is replaced there */
593 break;
594 }
595 /* retransmit DISC command */
596 lapd_send_resend(dl);
597 /* increment re-transmission counter */
598 dl->retrans_ctr++;
599 /* restart T200 (PH-READY-TO-SEND) */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200600 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200601 break;
602 case LAPD_STATE_MF_EST:
603 /* 5.5.7 */
604 dl->retrans_ctr = 0;
605 lapd_dl_newstate(dl, LAPD_STATE_TIMER_RECOV);
606 /* fall through */
607 case LAPD_STATE_TIMER_RECOV:
608 dl->retrans_ctr++;
609 if (dl->retrans_ctr < dl->n200) {
610 uint8_t vs = sub_mod(dl->v_send, 1, dl->v_range);
611 uint8_t h = do_mod(vs, dl->range_hist);
612 /* retransmit I frame (V_s-1) with P=1, if any */
613 if (dl->tx_hist[h].msg) {
614 struct msgb *msg;
615 int length = dl->tx_hist[h].msg->len;
616 struct lapd_msg_ctx nctx;
617
618 LOGP(DLLAPD, LOGL_INFO, "retransmit last frame"
619 " V(S)=%d\n", vs);
620 /* Create I frame (segment) from tx_hist */
621 memcpy(&nctx, &dl->lctx, sizeof(nctx));
622 /* keep nctx.ldp */
623 /* keep nctx.sapi */
624 /* keep nctx.tei */
625 nctx.cr = dl->cr.loc2rem.cmd;
626 nctx.format = LAPD_FORM_I;
627 nctx.p_f = 1;
628 nctx.n_send = vs;
629 nctx.n_recv = dl->v_recv;
630 nctx.length = length;
631 nctx.more = dl->tx_hist[h].more;
632 msg = lapd_msgb_alloc(length, "LAPD I resend");
633 msg->l3h = msgb_put(msg, length);
634 memcpy(msg->l3h, dl->tx_hist[h].msg->data,
635 length);
636 dl->send_ph_data_req(&nctx, msg);
637 } else {
638 /* OR send appropriate supervision frame with P=1 */
639 if (!dl->own_busy && !dl->seq_err_cond) {
640 lapd_send_rr(&dl->lctx, 1, 1);
641 /* NOTE: In case of sequence error
642 * condition, the REJ frame has been
643 * transmitted when entering the
644 * condition, so it has not be done
645 * here
646 */
647 } else if (dl->own_busy) {
648 lapd_send_rnr(&dl->lctx, 1, 1);
649 } else {
650 LOGP(DLLAPD, LOGL_INFO, "unhandled, "
651 "pls. fix\n");
652 }
653 }
654 /* restart T200 (PH-READY-TO-SEND) */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200655 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200656 } else {
657 /* send MDL ERROR INIDCATION to L3 */
658 mdl_error(MDL_CAUSE_T200_EXPIRED, &dl->lctx);
659 /* reestablish */
660 if (!dl->reestablish)
661 break;
662 LOGP(DLLAPD, LOGL_NOTICE, "N200 reached, performing "
663 "reestablishment.\n");
664 lapd_reestablish(dl);
665 }
666 break;
667 default:
668 LOGP(DLLAPD, LOGL_INFO, "T200 expired in unexpected "
669 "dl->state %d\n", (int) dl->state);
670 }
671}
672
673/* Timer callback on T203 expiry */
674static void lapd_t203_cb(void *data)
675{
676 struct lapd_datalink *dl = data;
677
Andreas Eversberg742fc792011-09-27 09:40:25 +0200678 LOGP(DLLAPD, LOGL_INFO, "Timeout T203 (%p) state=%d\n", dl,
rootaf48bed2011-09-26 11:23:06 +0200679 (int) dl->state);
680
681 if (dl->state != LAPD_STATE_MF_EST) {
682 LOGP(DLLAPD, LOGL_ERROR, "T203 fired outside MF EST state, "
683 "please fix!\n");
684 return;
685 }
686
687 /* set retransmission counter to 0 */
688 dl->retrans_ctr = 0;
689 /* enter timer recovery state */
690 lapd_dl_newstate(dl, LAPD_STATE_TIMER_RECOV);
691 /* transmit a supervisory command with P bit set to 1 as follows: */
692 if (!dl->own_busy) {
693 LOGP(DLLAPD, LOGL_INFO, "transmit an RR poll command\n");
694 /* Send RR with P=1 */
695 lapd_send_rr(&dl->lctx, 1, 1);
696 } else {
697 LOGP(DLLAPD, LOGL_INFO, "transmit an RNR poll command\n");
698 /* Send RNR with P=1 */
699 lapd_send_rnr(&dl->lctx, 1, 1);
700 }
701 /* start T200 */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200702 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200703}
704
705/* 5.5.3.1: Common function to acknowlege frames up to the given N(R) value */
706static void lapd_acknowledge(struct lapd_msg_ctx *lctx)
707{
708 struct lapd_datalink *dl = lctx->dl;
709 uint8_t nr = lctx->n_recv;
Holger Hans Peter Freytherfb6a2e22012-03-16 10:35:38 +0100710 int s = 0, rej = 0, t200_reset = 0;
rootaf48bed2011-09-26 11:23:06 +0200711 int i, h;
712
713 /* supervisory frame ? */
714 if (lctx->format == LAPD_FORM_S)
715 s = 1;
716 /* REJ frame ? */
717 if (s && lctx->s_u == LAPD_S_REJ)
718 rej = 1;
719
720 /* Flush all transmit buffers of acknowledged frames */
721 for (i = dl->v_ack; i != nr; i = inc_mod(i, dl->v_range)) {
722 h = do_mod(i, dl->range_hist);
723 if (dl->tx_hist[h].msg) {
724 msgb_free(dl->tx_hist[h].msg);
725 dl->tx_hist[h].msg = NULL;
726 LOGP(DLLAPD, LOGL_INFO, "ack frame %d\n", i);
727 }
728 }
729
730 if (dl->state != LAPD_STATE_TIMER_RECOV) {
731 /* When not in the timer recovery condition, the data
732 * link layer entity shall reset the timer T200 on
733 * receipt of a valid I frame with N(R) higher than V(A),
734 * or an REJ with an N(R) equal to V(A). */
735 if ((!rej && nr != dl->v_ack)
736 || (rej && nr == dl->v_ack)) {
rootaf48bed2011-09-26 11:23:06 +0200737 t200_reset = 1;
Andreas Eversberg742fc792011-09-27 09:40:25 +0200738 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200739 /* 5.5.3.1 Note 1 + 2 imply timer recovery cond. */
740 }
741 /* 5.7.4: N(R) sequence error
742 * N(R) is called valid, if and only if
743 * (N(R)-V(A)) mod 8 <= (V(S)-V(A)) mod 8.
744 */
745 if (sub_mod(nr, dl->v_ack, dl->v_range)
746 > sub_mod(dl->v_send, dl->v_ack, dl->v_range)) {
747 LOGP(DLLAPD, LOGL_NOTICE, "N(R) sequence error\n");
748 mdl_error(MDL_CAUSE_SEQ_ERR, lctx);
749 }
750 }
751
752 /* V(A) shall be set to the value of N(R) */
753 dl->v_ack = nr;
754
Andreas Eversberg742fc792011-09-27 09:40:25 +0200755 /* If T200 has been stopped by the receipt of an I, RR or RNR frame,
rootaf48bed2011-09-26 11:23:06 +0200756 * and if there are outstanding I frames, restart T200 */
757 if (t200_reset && !rej) {
758 if (dl->tx_hist[sub_mod(dl->v_send, 1, dl->range_hist)].msg) {
759 LOGP(DLLAPD, LOGL_INFO, "start T200, due to unacked I "
760 "frame(s)\n");
Andreas Eversberg742fc792011-09-27 09:40:25 +0200761 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200762 }
763 }
764
765 /* This also does a restart, when I or S frame is received */
766
767 /* Stop T203, if running */
Andreas Eversberg742fc792011-09-27 09:40:25 +0200768 lapd_stop_t203(dl);
rootaf48bed2011-09-26 11:23:06 +0200769 /* Start T203, if T200 is not running in MF EST state, if enabled */
770 if (!osmo_timer_pending(&dl->t200)
771 && (dl->t203_sec || dl->t203_usec)
772 && (dl->state == LAPD_STATE_MF_EST)) {
Andreas Eversberg742fc792011-09-27 09:40:25 +0200773 lapd_start_t203(dl);
rootaf48bed2011-09-26 11:23:06 +0200774 }
775}
776
777/* L1 -> L2 */
778
779/* Receive a LAPD U (Unnumbered) message from L1 */
780static int lapd_rx_u(struct msgb *msg, struct lapd_msg_ctx *lctx)
781{
782 struct lapd_datalink *dl = lctx->dl;
783 int length = lctx->length;
Sylvain Munaut9a5f3b82011-11-20 09:01:59 +0100784 int rc = 0;
rootaf48bed2011-09-26 11:23:06 +0200785 uint8_t prim, op;
786
787 switch (lctx->s_u) {
788 case LAPD_U_SABM:
789 case LAPD_U_SABME:
790 prim = PRIM_DL_EST;
791 op = PRIM_OP_INDICATION;
792
793 LOGP(DLLAPD, LOGL_INFO, "SABM(E) received in state %s\n",
794 lapd_state_names[dl->state]);
795 /* 5.7.1 */
796 dl->seq_err_cond = 0;
797 /* G.2.2 Wrong value of the C/R bit */
798 if (lctx->cr == dl->cr.rem2loc.resp) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +0100799 LOGP(DLLAPD, LOGL_ERROR, "SABM response error\n");
rootaf48bed2011-09-26 11:23:06 +0200800 msgb_free(msg);
801 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
802 return -EINVAL;
803 }
804
805 /* G.4.5 If SABM is received with L>N201 or with M bit
806 * set, AN MDL-ERROR-INDICATION is sent to MM.
807 */
808 if (lctx->more || length > lctx->n201) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +0100809 LOGP(DLLAPD, LOGL_ERROR, "SABM too large error\n");
rootaf48bed2011-09-26 11:23:06 +0200810 msgb_free(msg);
811 mdl_error(MDL_CAUSE_UFRM_INC_PARAM, lctx);
812 return -EIO;
813 }
814
815 switch (dl->state) {
816 case LAPD_STATE_IDLE:
817 break;
818 case LAPD_STATE_MF_EST:
819 LOGP(DLLAPD, LOGL_INFO, "SABM command, multiple "
820 "frame established state\n");
821 /* If link is lost on the remote side, we start over
822 * and send DL-ESTABLISH indication again. */
Andreas Eversberg6e182082013-02-06 14:13:21 +0100823 /* Additionally, continue in case of content resoltion
824 * (GSM network). This happens, if the mobile has not
825 * yet received UA or another mobile (collision) tries
826 * to establish connection. The mobile must receive
827 * UA again. */
828 if (!dl->cont_res && dl->v_send != dl->v_recv) {
rootaf48bed2011-09-26 11:23:06 +0200829 LOGP(DLLAPD, LOGL_INFO, "Remote reestablish\n");
830 mdl_error(MDL_CAUSE_SABM_MF, lctx);
831 break;
832 }
833 /* Ignore SABM if content differs from first SABM. */
834 if (dl->mode == LAPD_MODE_NETWORK && length
835 && dl->cont_res) {
836#ifdef TEST_CONTENT_RESOLUTION_NETWORK
837 dl->cont_res->data[0] ^= 0x01;
838#endif
Andreas Eversberg6e182082013-02-06 14:13:21 +0100839 if (memcmp(dl->cont_res->data, msg->data,
840 length)) {
rootaf48bed2011-09-26 11:23:06 +0200841 LOGP(DLLAPD, LOGL_INFO, "Another SABM "
842 "with diffrent content - "
843 "ignoring!\n");
844 msgb_free(msg);
845 return 0;
846 }
847 }
848 /* send UA again */
849 lapd_send_ua(lctx, length, msg->l3h);
850 msgb_free(msg);
851 return 0;
852 case LAPD_STATE_DISC_SENT:
853 /* 5.4.6.2 send DM with F=P */
854 lapd_send_dm(lctx);
Andreas Eversberg742fc792011-09-27 09:40:25 +0200855 /* stop Timer T200 */
856 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200857 msgb_free(msg);
858 return send_dl_simple(prim, op, lctx);
859 default:
860 /* collision: Send UA, but still wait for rx UA, then
861 * change to MF_EST state.
862 */
863 /* check for contention resoultion */
864 if (dl->tx_hist[0].msg && dl->tx_hist[0].msg->len) {
865 LOGP(DLLAPD, LOGL_NOTICE, "SABM not allowed "
866 "during contention resolution\n");
867 mdl_error(MDL_CAUSE_SABM_INFO_NOTALL, lctx);
868 }
869 lapd_send_ua(lctx, length, msg->l3h);
870 msgb_free(msg);
871 return 0;
872 }
873 /* save message context for further use */
874 memcpy(&dl->lctx, lctx, sizeof(dl->lctx));
875#ifndef TEST_CONTENT_RESOLUTION_NETWORK
876 /* send UA response */
877 lapd_send_ua(lctx, length, msg->l3h);
878#endif
879 /* set Vs, Vr and Va to 0 */
880 dl->v_send = dl->v_recv = dl->v_ack = 0;
881 /* clear tx_hist */
882 lapd_dl_flush_hist(dl);
883 /* enter multiple-frame-established state */
884 lapd_dl_newstate(dl, LAPD_STATE_MF_EST);
885 /* store content resolution data on network side
886 * Note: cont_res will be removed when changing state again,
887 * so it must be allocated AFTER lapd_dl_newstate(). */
888 if (dl->mode == LAPD_MODE_NETWORK && length) {
889 dl->cont_res = lapd_msgb_alloc(length, "CONT RES");
890 memcpy(msgb_put(dl->cont_res, length), msg->l3h,
891 length);
892 LOGP(DLLAPD, LOGL_NOTICE, "Store content res.\n");
893 }
894 /* send notification to L3 */
895 if (length == 0) {
896 /* 5.4.1.2 Normal establishment procedures */
897 rc = send_dl_simple(prim, op, lctx);
898 msgb_free(msg);
899 } else {
900 /* 5.4.1.4 Contention resolution establishment */
901 rc = send_dl_l3(prim, op, lctx, msg);
902 }
903 break;
904 case LAPD_U_DM:
905 LOGP(DLLAPD, LOGL_INFO, "DM received in state %s\n",
906 lapd_state_names[dl->state]);
907 /* G.2.2 Wrong value of the C/R bit */
908 if (lctx->cr == dl->cr.rem2loc.cmd) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +0100909 LOGP(DLLAPD, LOGL_ERROR, "DM command error\n");
rootaf48bed2011-09-26 11:23:06 +0200910 msgb_free(msg);
911 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
912 return -EINVAL;
913 }
914 if (!lctx->p_f) {
915 /* 5.4.1.2 DM responses with the F bit set to "0"
916 * shall be ignored.
917 */
918 msgb_free(msg);
919 return 0;
920 }
921 switch (dl->state) {
922 case LAPD_STATE_SABM_SENT:
923 break;
924 case LAPD_STATE_MF_EST:
925 if (lctx->p_f) {
926 LOGP(DLLAPD, LOGL_INFO, "unsolicited DM "
927 "response\n");
928 mdl_error(MDL_CAUSE_UNSOL_DM_RESP, lctx);
929 } else {
930 LOGP(DLLAPD, LOGL_INFO, "unsolicited DM "
931 "response, multiple frame established "
932 "state\n");
933 mdl_error(MDL_CAUSE_UNSOL_DM_RESP_MF, lctx);
934 /* reestablish */
935 if (!dl->reestablish) {
936 msgb_free(msg);
937 return 0;
938 }
939 LOGP(DLLAPD, LOGL_NOTICE, "Performing "
940 "reestablishment.\n");
941 lapd_reestablish(dl);
942 }
943 msgb_free(msg);
944 return 0;
945 case LAPD_STATE_TIMER_RECOV:
946 /* FP = 0 (DM is normal in case PF = 1) */
947 if (!lctx->p_f) {
948 LOGP(DLLAPD, LOGL_INFO, "unsolicited DM "
949 "response, multiple frame established "
950 "state\n");
951 mdl_error(MDL_CAUSE_UNSOL_DM_RESP_MF, lctx);
952 msgb_free(msg);
953 /* reestablish */
954 if (!dl->reestablish)
955 return 0;
956 LOGP(DLLAPD, LOGL_NOTICE, "Performing "
957 "reestablishment.\n");
958 return lapd_reestablish(dl);
959 }
960 break;
961 case LAPD_STATE_DISC_SENT:
Andreas Eversberg742fc792011-09-27 09:40:25 +0200962 /* stop Timer T200 */
963 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200964 /* go to idle state */
965 lapd_dl_flush_tx(dl);
966 lapd_dl_flush_send(dl);
967 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
968 rc = send_dl_simple(PRIM_DL_REL, PRIM_OP_CONFIRM, lctx);
969 msgb_free(msg);
970 return 0;
971 case LAPD_STATE_IDLE:
972 /* 5.4.5 all other frame types shall be discarded */
973 default:
974 LOGP(DLLAPD, LOGL_INFO, "unsolicited DM response! "
975 "(discarding)\n");
976 msgb_free(msg);
977 return 0;
978 }
Andreas Eversberg742fc792011-09-27 09:40:25 +0200979 /* stop timer T200 */
980 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +0200981 /* go to idle state */
982 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
983 rc = send_dl_simple(PRIM_DL_REL, PRIM_OP_INDICATION, lctx);
984 msgb_free(msg);
985 break;
986 case LAPD_U_UI:
987 LOGP(DLLAPD, LOGL_INFO, "UI received\n");
988 /* G.2.2 Wrong value of the C/R bit */
989 if (lctx->cr == dl->cr.rem2loc.resp) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +0100990 LOGP(DLLAPD, LOGL_ERROR, "UI indicates response "
rootaf48bed2011-09-26 11:23:06 +0200991 "error\n");
992 msgb_free(msg);
993 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
994 return -EINVAL;
995 }
996
997 /* G.4.5 If UI is received with L>N201 or with M bit
998 * set, AN MDL-ERROR-INDICATION is sent to MM.
999 */
1000 if (length > lctx->n201 || lctx->more) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001001 LOGP(DLLAPD, LOGL_ERROR, "UI too large error "
rootaf48bed2011-09-26 11:23:06 +02001002 "(%d > N201(%d) or M=%d)\n", length,
1003 lctx->n201, lctx->more);
1004 msgb_free(msg);
1005 mdl_error(MDL_CAUSE_UFRM_INC_PARAM, lctx);
1006 return -EIO;
1007 }
1008
1009 /* do some length checks */
1010 if (length == 0) {
1011 /* 5.3.3 UI frames received with the length indicator
1012 * set to "0" shall be ignored
1013 */
1014 LOGP(DLLAPD, LOGL_INFO, "length=0 (discarding)\n");
1015 msgb_free(msg);
1016 return 0;
1017 }
1018 rc = send_dl_l3(PRIM_DL_UNIT_DATA, PRIM_OP_INDICATION, lctx,
1019 msg);
1020 break;
1021 case LAPD_U_DISC:
1022 prim = PRIM_DL_REL;
1023 op = PRIM_OP_INDICATION;
1024
1025 LOGP(DLLAPD, LOGL_INFO, "DISC received in state %s\n",
1026 lapd_state_names[dl->state]);
1027 /* flush tx and send buffers */
1028 lapd_dl_flush_tx(dl);
1029 lapd_dl_flush_send(dl);
1030 /* 5.7.1 */
1031 dl->seq_err_cond = 0;
1032 /* G.2.2 Wrong value of the C/R bit */
1033 if (lctx->cr == dl->cr.rem2loc.resp) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001034 LOGP(DLLAPD, LOGL_ERROR, "DISC response error\n");
rootaf48bed2011-09-26 11:23:06 +02001035 msgb_free(msg);
1036 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
1037 return -EINVAL;
1038 }
1039 if (length > 0 || lctx->more) {
1040 /* G.4.4 If a DISC or DM frame is received with L>0 or
1041 * with the M bit set to "1", an MDL-ERROR-INDICATION
1042 * primitive with cause "U frame with incorrect
1043 * parameters" is sent to the mobile management entity.
1044 */
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001045 LOGP(DLLAPD, LOGL_ERROR,
rootaf48bed2011-09-26 11:23:06 +02001046 "U frame iwth incorrect parameters ");
1047 msgb_free(msg);
1048 mdl_error(MDL_CAUSE_UFRM_INC_PARAM, lctx);
1049 return -EIO;
1050 }
1051 switch (dl->state) {
1052 case LAPD_STATE_IDLE:
1053 LOGP(DLLAPD, LOGL_INFO, "DISC in idle state\n");
1054 /* send DM with F=P */
1055 msgb_free(msg);
1056 return lapd_send_dm(lctx);
1057 case LAPD_STATE_SABM_SENT:
1058 LOGP(DLLAPD, LOGL_INFO, "DISC in SABM state\n");
1059 /* 5.4.6.2 send DM with F=P */
1060 lapd_send_dm(lctx);
Andreas Eversberg742fc792011-09-27 09:40:25 +02001061 /* stop Timer T200 */
1062 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001063 /* go to idle state */
1064 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
1065 msgb_free(msg);
1066 return send_dl_simple(PRIM_DL_REL, PRIM_OP_INDICATION,
1067 lctx);
1068 case LAPD_STATE_MF_EST:
1069 case LAPD_STATE_TIMER_RECOV:
1070 LOGP(DLLAPD, LOGL_INFO, "DISC in est state\n");
1071 break;
1072 case LAPD_STATE_DISC_SENT:
1073 LOGP(DLLAPD, LOGL_INFO, "DISC in disc state\n");
1074 prim = PRIM_DL_REL;
1075 op = PRIM_OP_CONFIRM;
1076 break;
1077 default:
1078 lapd_send_ua(lctx, length, msg->l3h);
1079 msgb_free(msg);
1080 return 0;
1081 }
1082 /* send UA response */
1083 lapd_send_ua(lctx, length, msg->l3h);
Andreas Eversberg742fc792011-09-27 09:40:25 +02001084 /* stop Timer T200 */
1085 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001086 /* enter idle state, keep tx-buffer with UA response */
1087 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
1088 /* send notification to L3 */
1089 rc = send_dl_simple(prim, op, lctx);
1090 msgb_free(msg);
1091 break;
1092 case LAPD_U_UA:
1093 LOGP(DLLAPD, LOGL_INFO, "UA received in state %s\n",
1094 lapd_state_names[dl->state]);
1095 /* G.2.2 Wrong value of the C/R bit */
1096 if (lctx->cr == dl->cr.rem2loc.cmd) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001097 LOGP(DLLAPD, LOGL_ERROR, "UA indicates command "
rootaf48bed2011-09-26 11:23:06 +02001098 "error\n");
1099 msgb_free(msg);
1100 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
1101 return -EINVAL;
1102 }
1103
1104 /* G.4.5 If UA is received with L>N201 or with M bit
1105 * set, AN MDL-ERROR-INDICATION is sent to MM.
1106 */
1107 if (lctx->more || length > lctx->n201) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001108 LOGP(DLLAPD, LOGL_ERROR, "UA too large error\n");
rootaf48bed2011-09-26 11:23:06 +02001109 msgb_free(msg);
1110 mdl_error(MDL_CAUSE_UFRM_INC_PARAM, lctx);
1111 return -EIO;
1112 }
1113
1114 if (!lctx->p_f) {
1115 /* 5.4.1.2 A UA response with the F bit set to "0"
1116 * shall be ignored.
1117 */
1118 LOGP(DLLAPD, LOGL_INFO, "F=0 (discarding)\n");
1119 msgb_free(msg);
1120 return 0;
1121 }
1122 switch (dl->state) {
1123 case LAPD_STATE_SABM_SENT:
1124 break;
1125 case LAPD_STATE_MF_EST:
1126 case LAPD_STATE_TIMER_RECOV:
1127 LOGP(DLLAPD, LOGL_INFO, "unsolicited UA response! "
1128 "(discarding)\n");
1129 mdl_error(MDL_CAUSE_UNSOL_UA_RESP, lctx);
1130 msgb_free(msg);
1131 return 0;
1132 case LAPD_STATE_DISC_SENT:
1133 LOGP(DLLAPD, LOGL_INFO, "UA in disconnect state\n");
Andreas Eversberg742fc792011-09-27 09:40:25 +02001134 /* stop Timer T200 */
1135 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001136 /* go to idle state */
1137 lapd_dl_flush_tx(dl);
1138 lapd_dl_flush_send(dl);
1139 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
1140 rc = send_dl_simple(PRIM_DL_REL, PRIM_OP_CONFIRM, lctx);
1141 msgb_free(msg);
1142 return 0;
1143 case LAPD_STATE_IDLE:
1144 /* 5.4.5 all other frame types shall be discarded */
1145 default:
1146 LOGP(DLLAPD, LOGL_INFO, "unsolicited UA response! "
1147 "(discarding)\n");
1148 msgb_free(msg);
1149 return 0;
1150 }
1151 LOGP(DLLAPD, LOGL_INFO, "UA in SABM state\n");
Andreas Eversberg742fc792011-09-27 09:40:25 +02001152 /* stop Timer T200 */
1153 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001154 /* compare UA with SABME if contention resolution is applied */
1155 if (dl->tx_hist[0].msg->len) {
1156 if (length != (dl->tx_hist[0].msg->len)
1157 || !!memcmp(dl->tx_hist[0].msg->data, msg->l3h,
1158 length)) {
1159 LOGP(DLLAPD, LOGL_INFO, "**** UA response "
1160 "mismatches ****\n");
1161 rc = send_dl_simple(PRIM_DL_REL,
1162 PRIM_OP_INDICATION, lctx);
1163 msgb_free(msg);
1164 /* go to idle state */
1165 lapd_dl_flush_tx(dl);
1166 lapd_dl_flush_send(dl);
1167 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
1168 return 0;
1169 }
1170 }
1171 /* set Vs, Vr and Va to 0 */
1172 dl->v_send = dl->v_recv = dl->v_ack = 0;
1173 /* clear tx_hist */
1174 lapd_dl_flush_hist(dl);
1175 /* enter multiple-frame-established state */
1176 lapd_dl_newstate(dl, LAPD_STATE_MF_EST);
1177 /* send outstanding frames, if any (resume / reconnect) */
1178 lapd_send_i(lctx, __LINE__);
1179 /* send notification to L3 */
1180 rc = send_dl_simple(PRIM_DL_EST, PRIM_OP_CONFIRM, lctx);
1181 msgb_free(msg);
1182 break;
1183 case LAPD_U_FRMR:
1184 LOGP(DLLAPD, LOGL_NOTICE, "Frame reject received\n");
1185 /* send MDL ERROR INIDCATION to L3 */
1186 mdl_error(MDL_CAUSE_FRMR, lctx);
1187 msgb_free(msg);
1188 /* reestablish */
1189 if (!dl->reestablish)
1190 break;
1191 LOGP(DLLAPD, LOGL_NOTICE, "Performing reestablishment.\n");
1192 rc = lapd_reestablish(dl);
1193 break;
1194 default:
1195 /* G.3.1 */
1196 LOGP(DLLAPD, LOGL_NOTICE, "Unnumbered frame not allowed.\n");
1197 msgb_free(msg);
1198 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
1199 return -EINVAL;
1200 }
1201 return rc;
1202}
1203
1204/* Receive a LAPD S (Supervisory) message from L1 */
1205static int lapd_rx_s(struct msgb *msg, struct lapd_msg_ctx *lctx)
1206{
1207 struct lapd_datalink *dl = lctx->dl;
1208 int length = lctx->length;
1209
1210 if (length > 0 || lctx->more) {
1211 /* G.4.3 If a supervisory frame is received with L>0 or
1212 * with the M bit set to "1", an MDL-ERROR-INDICATION
1213 * primitive with cause "S frame with incorrect
1214 * parameters" is sent to the mobile management entity. */
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001215 LOGP(DLLAPD, LOGL_ERROR,
rootaf48bed2011-09-26 11:23:06 +02001216 "S frame with incorrect parameters\n");
1217 msgb_free(msg);
1218 mdl_error(MDL_CAUSE_SFRM_INC_PARAM, lctx);
1219 return -EIO;
1220 }
1221
1222 if (lctx->cr == dl->cr.rem2loc.resp
1223 && lctx->p_f
1224 && dl->state != LAPD_STATE_TIMER_RECOV) {
1225 /* 5.4.2.2: Inidcate error on supervisory reponse F=1 */
1226 LOGP(DLLAPD, LOGL_NOTICE, "S frame response with F=1 error\n");
1227 mdl_error(MDL_CAUSE_UNSOL_SPRV_RESP, lctx);
1228 }
1229
1230 switch (dl->state) {
1231 case LAPD_STATE_IDLE:
1232 /* if P=1, respond DM with F=1 (5.2.2) */
1233 /* 5.4.5 all other frame types shall be discarded */
1234 if (lctx->p_f)
1235 lapd_send_dm(lctx); /* F=P */
1236 /* fall though */
1237 case LAPD_STATE_SABM_SENT:
1238 case LAPD_STATE_DISC_SENT:
1239 LOGP(DLLAPD, LOGL_NOTICE, "S frame ignored in this state\n");
1240 msgb_free(msg);
1241 return 0;
1242 }
1243 switch (lctx->s_u) {
1244 case LAPD_S_RR:
1245 LOGP(DLLAPD, LOGL_INFO, "RR received in state %s\n",
1246 lapd_state_names[dl->state]);
1247 /* 5.5.3.1: Acknowlege all tx frames up the the N(R)-1 */
1248 lapd_acknowledge(lctx);
1249
1250 /* 5.5.3.2 */
1251 if (lctx->cr == dl->cr.rem2loc.cmd
1252 && lctx->p_f) {
1253 if (!dl->own_busy && !dl->seq_err_cond) {
1254 LOGP(DLLAPD, LOGL_INFO, "RR frame command "
1255 "with polling bit set and we are not "
1256 "busy, so we reply with RR frame "
1257 "response\n");
1258 lapd_send_rr(lctx, 1, 0);
1259 /* NOTE: In case of sequence error condition,
1260 * the REJ frame has been transmitted when
1261 * entering the condition, so it has not be
1262 * done here
1263 */
1264 } else if (dl->own_busy) {
1265 LOGP(DLLAPD, LOGL_INFO, "RR frame command "
1266 "with polling bit set and we are busy, "
1267 "so we reply with RR frame response\n");
1268 lapd_send_rnr(lctx, 1, 0);
1269 }
1270 } else if (lctx->cr == dl->cr.rem2loc.resp
1271 && lctx->p_f
1272 && dl->state == LAPD_STATE_TIMER_RECOV) {
1273 LOGP(DLLAPD, LOGL_INFO, "RR response with F==1, "
1274 "and we are in timer recovery state, so "
1275 "we leave that state\n");
1276 /* V(S) to the N(R) in the RR frame */
1277 dl->v_send = lctx->n_recv;
Andreas Eversberg742fc792011-09-27 09:40:25 +02001278 /* stop Timer T200 */
1279 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001280 /* 5.5.7 Clear timer recovery condition */
1281 lapd_dl_newstate(dl, LAPD_STATE_MF_EST);
1282 }
1283 /* Send message, if possible due to acknowledged data */
1284 lapd_send_i(lctx, __LINE__);
1285
1286 break;
1287 case LAPD_S_RNR:
1288 LOGP(DLLAPD, LOGL_INFO, "RNR received in state %s\n",
1289 lapd_state_names[dl->state]);
1290 /* 5.5.3.1: Acknowlege all tx frames up the the N(R)-1 */
1291 lapd_acknowledge(lctx);
1292
1293 /* 5.5.5 */
1294 /* Set peer receiver busy condition */
1295 dl->peer_busy = 1;
1296
1297 if (lctx->p_f) {
1298 if (lctx->cr == dl->cr.rem2loc.cmd) {
1299 if (!dl->own_busy) {
1300 LOGP(DLLAPD, LOGL_INFO, "RNR poll "
1301 "command and we are not busy, "
1302 "so we reply with RR final "
1303 "response\n");
1304 /* Send RR with F=1 */
1305 lapd_send_rr(lctx, 1, 0);
1306 } else {
1307 LOGP(DLLAPD, LOGL_INFO, "RNR poll "
1308 "command and we are busy, so "
1309 "we reply with RNR final "
1310 "response\n");
1311 /* Send RNR with F=1 */
1312 lapd_send_rnr(lctx, 1, 0);
1313 }
1314 } else if (dl->state == LAPD_STATE_TIMER_RECOV) {
1315 LOGP(DLLAPD, LOGL_INFO, "RNR poll response "
1316 "and we in timer recovery state, so "
1317 "we leave that state\n");
1318 /* 5.5.7 Clear timer recovery condition */
1319 lapd_dl_newstate(dl, LAPD_STATE_MF_EST);
1320 /* V(S) to the N(R) in the RNR frame */
1321 dl->v_send = lctx->n_recv;
1322 }
1323 } else
1324 LOGP(DLLAPD, LOGL_INFO, "RNR not polling/final state "
1325 "received\n");
1326
1327 /* Send message, if possible due to acknowledged data */
1328 lapd_send_i(lctx, __LINE__);
1329
1330 break;
1331 case LAPD_S_REJ:
1332 LOGP(DLLAPD, LOGL_INFO, "REJ received in state %s\n",
1333 lapd_state_names[dl->state]);
1334 /* 5.5.3.1: Acknowlege all tx frames up the the N(R)-1 */
1335 lapd_acknowledge(lctx);
1336
1337 /* 5.5.4.1 */
1338 if (dl->state != LAPD_STATE_TIMER_RECOV) {
1339 /* Clear an existing peer receiver busy condition */
1340 dl->peer_busy = 0;
1341 /* V(S) and V(A) to the N(R) in the REJ frame */
1342 dl->v_send = dl->v_ack = lctx->n_recv;
Andreas Eversberg742fc792011-09-27 09:40:25 +02001343 /* stop Timer T200 */
1344 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001345 /* 5.5.3.2 */
1346 if (lctx->cr == dl->cr.rem2loc.cmd && lctx->p_f) {
1347 if (!dl->own_busy && !dl->seq_err_cond) {
1348 LOGP(DLLAPD, LOGL_INFO, "REJ poll "
1349 "command not in timer recovery "
1350 "state and not in own busy "
1351 "condition received, so we "
1352 "respond with RR final "
1353 "response\n");
1354 lapd_send_rr(lctx, 1, 0);
1355 /* NOTE: In case of sequence error
1356 * condition, the REJ frame has been
1357 * transmitted when entering the
1358 * condition, so it has not be done
1359 * here
1360 */
1361 } else if (dl->own_busy) {
1362 LOGP(DLLAPD, LOGL_INFO, "REJ poll "
1363 "command not in timer recovery "
1364 "state and in own busy "
1365 "condition received, so we "
1366 "respond with RNR final "
1367 "response\n");
1368 lapd_send_rnr(lctx, 1, 0);
1369 }
1370 } else
1371 LOGP(DLLAPD, LOGL_INFO, "REJ response or not "
1372 "polling command not in timer recovery "
1373 "state received\n");
1374 /* send MDL ERROR INIDCATION to L3 */
1375 if (lctx->cr == dl->cr.rem2loc.resp && lctx->p_f) {
1376 mdl_error(MDL_CAUSE_UNSOL_SPRV_RESP, lctx);
1377 }
1378
1379 } else if (lctx->cr == dl->cr.rem2loc.resp && lctx->p_f) {
1380 LOGP(DLLAPD, LOGL_INFO, "REJ poll response in timer "
1381 "recovery state received\n");
1382 /* Clear an existing peer receiver busy condition */
1383 dl->peer_busy = 0;
1384 /* V(S) and V(A) to the N(R) in the REJ frame */
1385 dl->v_send = dl->v_ack = lctx->n_recv;
Andreas Eversberg742fc792011-09-27 09:40:25 +02001386 /* stop Timer T200 */
1387 lapd_stop_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001388 /* 5.5.7 Clear timer recovery condition */
1389 lapd_dl_newstate(dl, LAPD_STATE_MF_EST);
1390 } else {
1391 /* Clear an existing peer receiver busy condition */
1392 dl->peer_busy = 0;
1393 /* V(S) and V(A) to the N(R) in the REJ frame */
1394 dl->v_send = dl->v_ack = lctx->n_recv;
1395 /* 5.5.3.2 */
1396 if (lctx->cr == dl->cr.rem2loc.cmd && lctx->p_f) {
1397 if (!dl->own_busy && !dl->seq_err_cond) {
1398 LOGP(DLLAPD, LOGL_INFO, "REJ poll "
1399 "command in timer recovery "
1400 "state and not in own busy "
1401 "condition received, so we "
1402 "respond with RR final "
1403 "response\n");
1404 lapd_send_rr(lctx, 1, 0);
1405 /* NOTE: In case of sequence error
1406 * condition, the REJ frame has been
1407 * transmitted when entering the
1408 * condition, so it has not be done
1409 * here
1410 */
1411 } else if (dl->own_busy) {
1412 LOGP(DLLAPD, LOGL_INFO, "REJ poll "
1413 "command in timer recovery "
1414 "state and in own busy "
1415 "condition received, so we "
1416 "respond with RNR final "
1417 "response\n");
1418 lapd_send_rnr(lctx, 1, 0);
1419 }
1420 } else
1421 LOGP(DLLAPD, LOGL_INFO, "REJ response or not "
1422 "polling command in timer recovery "
1423 "state received\n");
1424 }
1425
1426 /* FIXME: 5.5.4.2 2) */
1427
1428 /* Send message, if possible due to acknowledged data */
1429 lapd_send_i(lctx, __LINE__);
1430
1431 break;
1432 default:
1433 /* G.3.1 */
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001434 LOGP(DLLAPD, LOGL_ERROR, "Supervisory frame not allowed.\n");
rootaf48bed2011-09-26 11:23:06 +02001435 msgb_free(msg);
1436 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
1437 return -EINVAL;
1438 }
1439 msgb_free(msg);
1440 return 0;
1441}
1442
1443/* Receive a LAPD I (Information) message from L1 */
1444static int lapd_rx_i(struct msgb *msg, struct lapd_msg_ctx *lctx)
1445{
1446 struct lapd_datalink *dl = lctx->dl;
1447 //uint8_t nr = lctx->n_recv;
1448 uint8_t ns = lctx->n_send;
1449 int length = lctx->length;
1450 int rc;
1451
1452 LOGP(DLLAPD, LOGL_INFO, "I received in state %s\n",
1453 lapd_state_names[dl->state]);
1454
1455 /* G.2.2 Wrong value of the C/R bit */
1456 if (lctx->cr == dl->cr.rem2loc.resp) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001457 LOGP(DLLAPD, LOGL_ERROR, "I frame response not allowed\n");
rootaf48bed2011-09-26 11:23:06 +02001458 msgb_free(msg);
1459 mdl_error(MDL_CAUSE_FRM_UNIMPL, lctx);
1460 return -EINVAL;
1461 }
1462
1463 if (length == 0 || length > lctx->n201) {
1464 /* G.4.2 If the length indicator of an I frame is set
1465 * to a numerical value L>N201 or L=0, an MDL-ERROR-INDICATION
1466 * primitive with cause "I frame with incorrect length"
1467 * is sent to the mobile management entity. */
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001468 LOGP(DLLAPD, LOGL_ERROR, "I frame length not allowed\n");
rootaf48bed2011-09-26 11:23:06 +02001469 msgb_free(msg);
1470 mdl_error(MDL_CAUSE_IFRM_INC_LEN, lctx);
1471 return -EIO;
1472 }
1473
1474 /* G.4.2 If the numerical value of L is L<N201 and the M
1475 * bit is set to "1", then an MDL-ERROR-INDICATION primitive with
1476 * cause "I frame with incorrect use of M bit" is sent to the
1477 * mobile management entity. */
1478 if (lctx->more && length < lctx->n201) {
Holger Hans Peter Freyther8c012312012-11-26 16:52:23 +01001479 LOGP(DLLAPD, LOGL_ERROR, "I frame with M bit too short\n");
rootaf48bed2011-09-26 11:23:06 +02001480 msgb_free(msg);
1481 mdl_error(MDL_CAUSE_IFRM_INC_MBITS, lctx);
1482 return -EIO;
1483 }
1484
1485 switch (dl->state) {
1486 case LAPD_STATE_IDLE:
1487 /* if P=1, respond DM with F=1 (5.2.2) */
1488 /* 5.4.5 all other frame types shall be discarded */
1489 if (lctx->p_f)
1490 lapd_send_dm(lctx); /* F=P */
1491 /* fall though */
1492 case LAPD_STATE_SABM_SENT:
1493 case LAPD_STATE_DISC_SENT:
1494 LOGP(DLLAPD, LOGL_NOTICE, "I frame ignored in this state\n");
1495 msgb_free(msg);
1496 return 0;
1497 }
1498
1499 /* 5.7.1: N(s) sequence error */
1500 if (ns != dl->v_recv) {
1501 LOGP(DLLAPD, LOGL_NOTICE, "N(S) sequence error: N(S)=%u, "
1502 "V(R)=%u\n", ns, dl->v_recv);
1503 /* discard data */
1504 msgb_free(msg);
Andreas.Eversberg301f01e2012-01-10 13:02:01 +01001505 if (dl->seq_err_cond != 1) {
rootaf48bed2011-09-26 11:23:06 +02001506 /* FIXME: help me understand what exactly todo here
rootaf48bed2011-09-26 11:23:06 +02001507 */
Andreas.Eversberg301f01e2012-01-10 13:02:01 +01001508 dl->seq_err_cond = 1;
rootaf48bed2011-09-26 11:23:06 +02001509 lapd_send_rej(lctx, lctx->p_f);
1510 } else {
Andreas.Eversberg301f01e2012-01-10 13:02:01 +01001511 /* If there are two subsequent sequence errors received,
1512 * ignore it. (Ignore every second subsequent error.)
1513 * This happens if our reply with the REJ is too slow,
1514 * so the remote gets a T200 timeout and sends another
1515 * frame with a sequence error.
1516 * Test showed that replying with two subsequent REJ
1517 * messages could the remote L2 process to abort.
1518 * Replying too slow shouldn't happen, but may happen
1519 * over serial link between BB and LAPD.
1520 */
1521 dl->seq_err_cond = 2;
rootaf48bed2011-09-26 11:23:06 +02001522 }
Andreas.Eversberg301f01e2012-01-10 13:02:01 +01001523 /* Even if N(s) sequence error, acknowledge to N(R)-1 */
1524 /* 5.5.3.1: Acknowlege all transmitted frames up the N(R)-1 */
1525 lapd_acknowledge(lctx); /* V(A) is also set here */
1526
1527 /* Send message, if possible due to acknowledged data */
1528 lapd_send_i(lctx, __LINE__);
1529
1530 return 0;
rootaf48bed2011-09-26 11:23:06 +02001531 }
1532 dl->seq_err_cond = 0;
1533
1534 /* Increment receiver state */
1535 dl->v_recv = inc_mod(dl->v_recv, dl->v_range);
1536 LOGP(DLLAPD, LOGL_INFO, "incrementing V(R) to %u\n", dl->v_recv);
1537
1538 /* 5.5.3.1: Acknowlege all transmitted frames up the the N(R)-1 */
1539 lapd_acknowledge(lctx); /* V(A) is also set here */
1540
1541 /* Only if we are not in own receiver busy condition */
1542 if (!dl->own_busy) {
1543 /* if the frame carries a complete segment */
1544 if (!lctx->more && !dl->rcv_buffer) {
1545 LOGP(DLLAPD, LOGL_INFO, "message in single I frame\n");
1546 /* send a DATA INDICATION to L3 */
1547 msg->len = length;
1548 msg->tail = msg->data + length;
1549 rc = send_dl_l3(PRIM_DL_DATA, PRIM_OP_INDICATION, lctx,
1550 msg);
1551 } else {
1552 /* create rcv_buffer */
1553 if (!dl->rcv_buffer) {
1554 LOGP(DLLAPD, LOGL_INFO, "message in multiple "
1555 "I frames (first message)\n");
1556 dl->rcv_buffer = lapd_msgb_alloc(dl->maxf,
1557 "LAPD RX");
1558 dl->rcv_buffer->l3h = dl->rcv_buffer->data;
1559 }
1560 /* concat. rcv_buffer */
1561 if (msgb_l3len(dl->rcv_buffer) + length > dl->maxf) {
1562 LOGP(DLLAPD, LOGL_NOTICE, "Received frame "
1563 "overflow!\n");
1564 } else {
1565 memcpy(msgb_put(dl->rcv_buffer, length),
1566 msg->l3h, length);
1567 }
1568 /* if the last segment was received */
1569 if (!lctx->more) {
1570 LOGP(DLLAPD, LOGL_INFO, "message in multiple "
1571 "I frames (last message)\n");
1572 rc = send_dl_l3(PRIM_DL_DATA,
1573 PRIM_OP_INDICATION, lctx,
1574 dl->rcv_buffer);
1575 dl->rcv_buffer = NULL;
1576 } else
1577 LOGP(DLLAPD, LOGL_INFO, "message in multiple "
1578 "I frames (next message)\n");
1579 msgb_free(msg);
1580
1581 }
1582 } else
1583 LOGP(DLLAPD, LOGL_INFO, "I frame ignored during own receiver "
1584 "busy condition\n");
1585
1586 /* Check for P bit */
1587 if (lctx->p_f) {
1588 /* 5.5.2.1 */
1589 /* check if we are not in own receiver busy */
1590 if (!dl->own_busy) {
1591 LOGP(DLLAPD, LOGL_INFO, "we are not busy, send RR\n");
1592 /* Send RR with F=1 */
1593 rc = lapd_send_rr(lctx, 1, 0);
1594 } else {
1595 LOGP(DLLAPD, LOGL_INFO, "we are busy, send RNR\n");
1596 /* Send RNR with F=1 */
1597 rc = lapd_send_rnr(lctx, 1, 0);
1598 }
1599 } else {
1600 /* 5.5.2.2 */
1601 /* check if we are not in own receiver busy */
1602 if (!dl->own_busy) {
1603 /* NOTE: V(R) is already set above */
1604 rc = lapd_send_i(lctx, __LINE__);
1605 if (rc) {
1606 LOGP(DLLAPD, LOGL_INFO, "we are not busy and "
1607 "have no pending data, send RR\n");
1608 /* Send RR with F=0 */
1609 return lapd_send_rr(lctx, 0, 0);
1610 }
1611 /* all I or one RR is sent, we are done */
1612 return 0;
1613 } else {
1614 LOGP(DLLAPD, LOGL_INFO, "we are busy, send RNR\n");
1615 /* Send RNR with F=0 */
1616 rc = lapd_send_rnr(lctx, 0, 0);
1617 }
1618 }
1619
1620 /* Send message, if possible due to acknowledged data */
1621 lapd_send_i(lctx, __LINE__);
1622
1623 return rc;
1624}
1625
1626/* Receive a LAPD message from L1 */
1627int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx)
1628{
1629 int rc;
1630
1631 switch (lctx->format) {
1632 case LAPD_FORM_U:
1633 rc = lapd_rx_u(msg, lctx);
1634 break;
1635 case LAPD_FORM_S:
1636 rc = lapd_rx_s(msg, lctx);
1637 break;
1638 case LAPD_FORM_I:
1639 rc = lapd_rx_i(msg, lctx);
1640 break;
1641 default:
1642 LOGP(DLLAPD, LOGL_NOTICE, "unknown LAPD format\n");
1643 msgb_free(msg);
1644 rc = -EINVAL;
1645 }
1646 return rc;
1647}
1648
1649/* L3 -> L2 */
1650
1651/* send unit data */
1652static int lapd_udata_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
1653{
1654 struct lapd_datalink *dl = lctx->dl;
1655 struct msgb *msg = dp->oph.msg;
1656 struct lapd_msg_ctx nctx;
1657
1658 memcpy(&nctx, lctx, sizeof(nctx));
1659 /* keep nctx.ldp */
1660 /* keep nctx.sapi */
1661 /* keep nctx.tei */
1662 nctx.cr = dl->cr.loc2rem.cmd;
1663 nctx.format = LAPD_FORM_U;
1664 nctx.s_u = LAPD_U_UI;
1665 /* keep nctx.p_f */
1666 nctx.length = msg->len;
1667 nctx.more = 0;
1668
1669 return dl->send_ph_data_req(&nctx, msg);
1670}
1671
1672/* request link establishment */
1673static int lapd_est_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
1674{
1675 struct lapd_datalink *dl = lctx->dl;
1676 struct msgb *msg = dp->oph.msg;
1677 struct lapd_msg_ctx nctx;
1678
1679 if (msg->len)
1680 LOGP(DLLAPD, LOGL_INFO, "perform establishment with content "
1681 "(SABM)\n");
1682 else
1683 LOGP(DLLAPD, LOGL_INFO, "perform normal establishm. (SABM)\n");
1684
1685 /* Flush send-queue */
1686 /* Clear send-buffer */
1687 lapd_dl_flush_send(dl);
1688 /* be sure that history is empty */
1689 lapd_dl_flush_hist(dl);
1690
1691 /* save message context for further use */
1692 memcpy(&dl->lctx, lctx, sizeof(dl->lctx));
1693
1694 /* Discard partly received L3 message */
1695 if (dl->rcv_buffer) {
1696 msgb_free(dl->rcv_buffer);
1697 dl->rcv_buffer = NULL;
1698 }
1699
1700 /* assemble message */
1701 memcpy(&nctx, &dl->lctx, sizeof(nctx));
1702 /* keep nctx.ldp */
1703 /* keep nctx.sapi */
1704 /* keep nctx.tei */
1705 nctx.cr = dl->cr.loc2rem.cmd;
1706 nctx.format = LAPD_FORM_U;
1707 nctx.s_u = (dl->use_sabme) ? LAPD_U_SABME : LAPD_U_SABM;
1708 nctx.p_f = 1;
1709 nctx.length = msg->len;
1710 nctx.more = 0;
1711
1712 /* Transmit-buffer carries exactly one segment */
1713 dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST");
1714 msgb_put(dl->tx_hist[0].msg, msg->len);
1715 if (msg->len)
1716 memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len);
1717 dl->tx_hist[0].more = 0;
1718 /* set Vs to 0, because it is used as index when resending SABM */
1719 dl->v_send = 0;
1720
1721 /* Set states */
1722 dl->own_busy = dl->peer_busy = 0;
1723 dl->retrans_ctr = 0;
1724 lapd_dl_newstate(dl, LAPD_STATE_SABM_SENT);
1725
1726 /* Tramsmit and start T200 */
1727 dl->send_ph_data_req(&nctx, msg);
Andreas Eversberg742fc792011-09-27 09:40:25 +02001728 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001729
1730 return 0;
1731}
1732
1733/* send data */
1734static int lapd_data_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
1735{
1736 struct lapd_datalink *dl = lctx->dl;
1737 struct msgb *msg = dp->oph.msg;
1738
Holger Hans Peter Freyther90656db2012-01-13 05:49:29 +08001739 if (msgb_l3len(msg) == 0) {
1740 LOGP(DLLAPD, LOGL_ERROR,
1741 "writing an empty message is not possible.\n");
1742 msgb_free(msg);
1743 return -1;
1744 }
1745
Holger Hans Peter Freyther6ecafef2012-01-13 05:46:26 +08001746 LOGP(DLLAPD, LOGL_INFO,
1747 "writing message to send-queue: l3len: %d\n", msgb_l3len(msg));
rootaf48bed2011-09-26 11:23:06 +02001748
1749 /* Write data into the send queue */
1750 msgb_enqueue(&dl->send_queue, msg);
1751
1752 /* Send message, if possible */
1753 lapd_send_i(&dl->lctx, __LINE__);
1754
1755 return 0;
1756}
1757
1758/* Send next I frame from queued/buffered data */
1759static int lapd_send_i(struct lapd_msg_ctx *lctx, int line)
1760{
1761 struct lapd_datalink *dl = lctx->dl;
1762 uint8_t k = dl->k;
1763 uint8_t h;
1764 struct msgb *msg;
1765 int length, left;
1766 int rc = - 1; /* we sent nothing */
1767 struct lapd_msg_ctx nctx;
1768
1769
1770 LOGP(DLLAPD, LOGL_INFO, "%s() called from line %d\n", __func__, line);
1771
1772 next_frame:
1773
1774 if (dl->peer_busy) {
1775 LOGP(DLLAPD, LOGL_INFO, "peer busy, not sending\n");
1776 return rc;
1777 }
1778
1779 if (dl->state == LAPD_STATE_TIMER_RECOV) {
1780 LOGP(DLLAPD, LOGL_INFO, "timer recovery, not sending\n");
1781 return rc;
1782 }
1783
1784 /* If the send state variable V(S) is equal to V(A) plus k
1785 * (where k is the maximum number of outstanding I frames - see
1786 * subclause 5.8.4), the data link layer entity shall not transmit any
1787 * new I frames, but shall retransmit an I frame as a result
1788 * of the error recovery procedures as described in subclauses 5.5.4 and
1789 * 5.5.7. */
1790 if (dl->v_send == add_mod(dl->v_ack, k, dl->v_range)) {
1791 LOGP(DLLAPD, LOGL_INFO, "k frames outstanding, not sending "
1792 "more (k=%u V(S)=%u V(A)=%u)\n", k, dl->v_send,
1793 dl->v_ack);
1794 return rc;
1795 }
1796
1797 h = do_mod(dl->v_send, dl->range_hist);
1798
1799 /* if we have no tx_hist yet, we create it */
1800 if (!dl->tx_hist[h].msg) {
1801 /* Get next message into send-buffer, if any */
1802 if (!dl->send_buffer) {
1803 next_message:
1804 dl->send_out = 0;
1805 dl->send_buffer = msgb_dequeue(&dl->send_queue);
1806 /* No more data to be sent */
1807 if (!dl->send_buffer)
1808 return rc;
1809 LOGP(DLLAPD, LOGL_INFO, "get message from "
1810 "send-queue\n");
1811 }
1812
1813 /* How much is left in the send-buffer? */
1814 left = msgb_l3len(dl->send_buffer) - dl->send_out;
1815 /* Segment, if data exceeds N201 */
1816 length = left;
1817 if (length > lctx->n201)
1818 length = lctx->n201;
1819 LOGP(DLLAPD, LOGL_INFO, "msg-len %d sent %d left %d N201 %d "
1820 "length %d first byte %02x\n",
1821 msgb_l3len(dl->send_buffer), dl->send_out, left,
1822 lctx->n201, length, dl->send_buffer->l3h[0]);
1823 /* If message in send-buffer is completely sent */
1824 if (left == 0) {
1825 msgb_free(dl->send_buffer);
1826 dl->send_buffer = NULL;
1827 goto next_message;
1828 }
1829
1830 LOGP(DLLAPD, LOGL_INFO, "send I frame %sV(S)=%d\n",
1831 (left > length) ? "segment " : "", dl->v_send);
1832
1833 /* Create I frame (segment) and transmit-buffer content */
1834 msg = lapd_msgb_alloc(length, "LAPD I");
1835 msg->l3h = msgb_put(msg, length);
1836 /* assemble message */
1837 memcpy(&nctx, &dl->lctx, sizeof(nctx));
1838 /* keep nctx.ldp */
1839 /* keep nctx.sapi */
1840 /* keep nctx.tei */
1841 nctx.cr = dl->cr.loc2rem.cmd;
1842 nctx.format = LAPD_FORM_I;
1843 nctx.p_f = 0;
1844 nctx.n_send = dl->v_send;
1845 nctx.n_recv = dl->v_recv;
1846 nctx.length = length;
1847 if (left > length)
1848 nctx.more = 1;
1849 else
1850 nctx.more = 0;
1851 if (length)
1852 memcpy(msg->l3h, dl->send_buffer->l3h + dl->send_out,
1853 length);
1854 /* store in tx_hist */
1855 dl->tx_hist[h].msg = lapd_msgb_alloc(msg->len, "HIST");
1856 msgb_put(dl->tx_hist[h].msg, msg->len);
1857 if (length)
1858 memcpy(dl->tx_hist[h].msg->data, msg->l3h, msg->len);
1859 dl->tx_hist[h].more = nctx.more;
1860 /* Add length to track how much is already in the tx buffer */
1861 dl->send_out += length;
1862 } else {
1863 LOGP(DLLAPD, LOGL_INFO, "resend I frame from tx buffer "
1864 "V(S)=%d\n", dl->v_send);
1865
1866 /* Create I frame (segment) from tx_hist */
1867 length = dl->tx_hist[h].msg->len;
1868 msg = lapd_msgb_alloc(length, "LAPD I resend");
1869 msg->l3h = msgb_put(msg, length);
1870 /* assemble message */
1871 memcpy(&nctx, &dl->lctx, sizeof(nctx));
1872 /* keep nctx.ldp */
1873 /* keep nctx.sapi */
1874 /* keep nctx.tei */
1875 nctx.cr = dl->cr.loc2rem.cmd;
1876 nctx.format = LAPD_FORM_I;
1877 nctx.p_f = 0;
1878 nctx.n_send = dl->v_send;
1879 nctx.n_recv = dl->v_recv;
1880 nctx.length = length;
1881 nctx.more = dl->tx_hist[h].more;
1882 if (length)
1883 memcpy(msg->l3h, dl->tx_hist[h].msg->data, length);
1884 }
1885
1886 /* The value of the send state variable V(S) shall be incremented by 1
1887 * at the end of the transmission of the I frame */
1888 dl->v_send = inc_mod(dl->v_send, dl->v_range);
1889
1890 /* If timer T200 is not running at the time right before transmitting a
1891 * frame, when the PH-READY-TO-SEND primitive is received from the
1892 * physical layer., it shall be set. */
1893 if (!osmo_timer_pending(&dl->t200)) {
Andreas Eversberg742fc792011-09-27 09:40:25 +02001894 /* stop Timer T203, if running */
1895 lapd_stop_t203(dl);
1896 /* start Timer T200 */
1897 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001898 }
1899
1900 dl->send_ph_data_req(&nctx, msg);
1901
1902 rc = 0; /* we sent something */
1903 goto next_frame;
1904}
1905
1906/* request link suspension */
1907static int lapd_susp_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
1908{
1909 struct lapd_datalink *dl = lctx->dl;
1910 struct msgb *msg = dp->oph.msg;
1911
1912 LOGP(DLLAPD, LOGL_INFO, "perform suspension\n");
1913
1914 /* put back the send-buffer to the send-queue (first position) */
1915 if (dl->send_buffer) {
1916 LOGP(DLLAPD, LOGL_INFO, "put frame in sendbuffer back to "
1917 "queue\n");
1918 llist_add(&dl->send_buffer->list, &dl->send_queue);
1919 dl->send_buffer = NULL;
1920 } else
1921 LOGP(DLLAPD, LOGL_INFO, "no frame in sendbuffer\n");
1922
1923 /* Clear transmit buffer, but keep send buffer */
1924 lapd_dl_flush_tx(dl);
Andreas Eversberg742fc792011-09-27 09:40:25 +02001925 /* Stop timers (there is no state change, so we must stop all timers */
1926 lapd_stop_t200(dl);
1927 lapd_stop_t203(dl);
rootaf48bed2011-09-26 11:23:06 +02001928
1929 msgb_free(msg);
1930
1931 return send_dl_simple(PRIM_DL_SUSP, PRIM_OP_CONFIRM, &dl->lctx);
1932}
1933
1934/* requesst resume or reconnect of link */
1935static int lapd_res_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
1936{
1937 struct lapd_datalink *dl = lctx->dl;
1938 struct msgb *msg = dp->oph.msg;
1939 struct lapd_msg_ctx nctx;
1940
1941 LOGP(DLLAPD, LOGL_INFO, "perform re-establishment (SABM) length=%d\n",
1942 msg->len);
1943
1944 /* be sure that history is empty */
1945 lapd_dl_flush_hist(dl);
1946
1947 /* save message context for further use */
1948 memcpy(&dl->lctx, lctx, sizeof(dl->lctx));
1949
1950 /* Replace message in the send-buffer (reconnect) */
1951 if (dl->send_buffer)
1952 msgb_free(dl->send_buffer);
1953 dl->send_out = 0;
Andreas Eversberg5ad4ac82011-11-01 09:40:21 +01001954 if (msg && msg->len)
rootaf48bed2011-09-26 11:23:06 +02001955 /* Write data into the send buffer, to be sent first */
1956 dl->send_buffer = msg;
Andreas Eversberg5ad4ac82011-11-01 09:40:21 +01001957 else
1958 dl->send_buffer = NULL;
rootaf48bed2011-09-26 11:23:06 +02001959
1960 /* Discard partly received L3 message */
1961 if (dl->rcv_buffer) {
1962 msgb_free(dl->rcv_buffer);
1963 dl->rcv_buffer = NULL;
1964 }
1965
1966 /* Create new msgb (old one is now free) */
1967 msg = lapd_msgb_alloc(0, "LAPD SABM");
1968 msg->l3h = msg->data;
1969 /* assemble message */
1970 memcpy(&nctx, &dl->lctx, sizeof(nctx));
1971 /* keep nctx.ldp */
1972 /* keep nctx.sapi */
1973 /* keep nctx.tei */
1974 nctx.cr = dl->cr.loc2rem.cmd;
1975 nctx.format = LAPD_FORM_U;
1976 nctx.s_u = (dl->use_sabme) ? LAPD_U_SABME : LAPD_U_SABM;
1977 nctx.p_f = 1;
1978 nctx.length = 0;
1979 nctx.more = 0;
1980
1981 dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST");
1982 msgb_put(dl->tx_hist[0].msg, msg->len);
1983 if (msg->len)
1984 memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len);
1985 dl->tx_hist[0].more = 0;
1986 /* set Vs to 0, because it is used as index when resending SABM */
1987 dl->v_send = 0;
1988
1989 /* Set states */
1990 dl->own_busy = dl->peer_busy = 0;
1991 dl->retrans_ctr = 0;
1992 lapd_dl_newstate(dl, LAPD_STATE_SABM_SENT);
1993
1994 /* Tramsmit and start T200 */
1995 dl->send_ph_data_req(&nctx, msg);
Andreas Eversberg742fc792011-09-27 09:40:25 +02001996 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02001997
1998 return 0;
1999}
2000
2001/* requesst release of link */
2002static int lapd_rel_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
2003{
2004 struct lapd_datalink *dl = lctx->dl;
2005 struct msgb *msg = dp->oph.msg;
2006 struct lapd_msg_ctx nctx;
2007
2008 /* local release */
2009 if (dp->u.rel_req.mode) {
2010 LOGP(DLLAPD, LOGL_INFO, "perform local release\n");
2011 msgb_free(msg);
Andreas Eversberg742fc792011-09-27 09:40:25 +02002012 /* stop Timer T200 */
2013 lapd_stop_t200(dl);
2014 /* enter idle state, T203 is stopped here, if running */
rootaf48bed2011-09-26 11:23:06 +02002015 lapd_dl_newstate(dl, LAPD_STATE_IDLE);
2016 /* flush buffers */
2017 lapd_dl_flush_tx(dl);
2018 lapd_dl_flush_send(dl);
2019 /* send notification to L3 */
2020 return send_dl_simple(PRIM_DL_REL, PRIM_OP_CONFIRM, &dl->lctx);
2021 }
2022
2023 /* in case we are already disconnecting */
2024 if (dl->state == LAPD_STATE_DISC_SENT)
2025 return -EBUSY;
2026
2027 /* flush tx_hist */
2028 lapd_dl_flush_hist(dl);
2029
2030 LOGP(DLLAPD, LOGL_INFO, "perform normal release (DISC)\n");
2031
2032 /* Push LAPD header on msgb */
2033 /* assemble message */
2034 memcpy(&nctx, &dl->lctx, sizeof(nctx));
2035 /* keep nctx.ldp */
2036 /* keep nctx.sapi */
2037 /* keep nctx.tei */
2038 nctx.cr = dl->cr.loc2rem.cmd;
2039 nctx.format = LAPD_FORM_U;
2040 nctx.s_u = LAPD_U_DISC;
2041 nctx.p_f = 1;
2042 nctx.length = 0;
2043 nctx.more = 0;
2044
2045 dl->tx_hist[0].msg = lapd_msgb_alloc(msg->len, "HIST");
2046 msgb_put(dl->tx_hist[0].msg, msg->len);
2047 if (msg->len)
2048 memcpy(dl->tx_hist[0].msg->data, msg->l3h, msg->len);
2049 dl->tx_hist[0].more = 0;
2050 /* set Vs to 0, because it is used as index when resending DISC */
2051 dl->v_send = 0;
2052
2053 /* Set states */
2054 dl->own_busy = dl->peer_busy = 0;
2055 dl->retrans_ctr = 0;
2056 lapd_dl_newstate(dl, LAPD_STATE_DISC_SENT);
2057
2058 /* Tramsmit and start T200 */
2059 dl->send_ph_data_req(&nctx, msg);
Andreas Eversberg742fc792011-09-27 09:40:25 +02002060 lapd_start_t200(dl);
rootaf48bed2011-09-26 11:23:06 +02002061
2062 return 0;
2063}
2064
2065/* request release of link in idle state */
2066static int lapd_rel_req_idle(struct osmo_dlsap_prim *dp,
2067 struct lapd_msg_ctx *lctx)
2068{
2069 struct lapd_datalink *dl = lctx->dl;
2070 struct msgb *msg = dp->oph.msg;
2071
2072 msgb_free(msg);
2073
2074 /* send notification to L3 */
2075 return send_dl_simple(PRIM_DL_REL, PRIM_OP_CONFIRM, &dl->lctx);
2076}
2077
2078/* statefull handling for DL SAP messages from L3 */
Holger Hans Peter Freyther579fb092012-11-22 10:54:23 +01002079static const struct l2downstate {
rootaf48bed2011-09-26 11:23:06 +02002080 uint32_t states;
2081 int prim, op;
2082 const char *name;
2083 int (*rout) (struct osmo_dlsap_prim *dp,
2084 struct lapd_msg_ctx *lctx);
2085} l2downstatelist[] = {
2086 /* create and send UI command */
2087 {ALL_STATES,
2088 PRIM_DL_UNIT_DATA, PRIM_OP_REQUEST,
2089 "DL-UNIT-DATA-REQUEST", lapd_udata_req},
2090
2091 /* create and send SABM command */
2092 {SBIT(LAPD_STATE_IDLE),
2093 PRIM_DL_EST, PRIM_OP_REQUEST,
2094 "DL-ESTABLISH-REQUEST", lapd_est_req},
2095
2096 /* create and send I command */
2097 {SBIT(LAPD_STATE_MF_EST) |
2098 SBIT(LAPD_STATE_TIMER_RECOV),
2099 PRIM_DL_DATA, PRIM_OP_REQUEST,
2100 "DL-DATA-REQUEST", lapd_data_req},
2101
2102 /* suspend datalink */
2103 {SBIT(LAPD_STATE_MF_EST) |
2104 SBIT(LAPD_STATE_TIMER_RECOV),
2105 PRIM_DL_SUSP, PRIM_OP_REQUEST,
2106 "DL-SUSPEND-REQUEST", lapd_susp_req},
2107
2108 /* create and send SABM command (resume) */
2109 {SBIT(LAPD_STATE_MF_EST) |
2110 SBIT(LAPD_STATE_TIMER_RECOV),
2111 PRIM_DL_RES, PRIM_OP_REQUEST,
2112 "DL-RESUME-REQUEST", lapd_res_req},
2113
2114 /* create and send SABM command (reconnect) */
2115 {SBIT(LAPD_STATE_IDLE) |
2116 SBIT(LAPD_STATE_MF_EST) |
2117 SBIT(LAPD_STATE_TIMER_RECOV),
2118 PRIM_DL_RECON, PRIM_OP_REQUEST,
2119 "DL-RECONNECT-REQUEST", lapd_res_req},
2120
2121 /* create and send DISC command */
2122 {SBIT(LAPD_STATE_SABM_SENT) |
2123 SBIT(LAPD_STATE_MF_EST) |
2124 SBIT(LAPD_STATE_TIMER_RECOV) |
2125 SBIT(LAPD_STATE_DISC_SENT),
2126 PRIM_DL_REL, PRIM_OP_REQUEST,
2127 "DL-RELEASE-REQUEST", lapd_rel_req},
2128
2129 /* release in idle state */
2130 {SBIT(LAPD_STATE_IDLE),
2131 PRIM_DL_REL, PRIM_OP_REQUEST,
2132 "DL-RELEASE-REQUEST", lapd_rel_req_idle},
2133};
2134
2135#define L2DOWNSLLEN \
2136 (sizeof(l2downstatelist) / sizeof(struct l2downstate))
2137
2138int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
2139{
2140 struct lapd_datalink *dl = lctx->dl;
2141 int i, supported = 0;
2142 struct msgb *msg = dp->oph.msg;
2143 int rc;
2144
2145 /* find function for current state and message */
2146 for (i = 0; i < L2DOWNSLLEN; i++) {
2147 if (dp->oph.primitive == l2downstatelist[i].prim
2148 && dp->oph.operation == l2downstatelist[i].op) {
2149 supported = 1;
2150 if ((SBIT(dl->state) & l2downstatelist[i].states))
2151 break;
2152 }
2153 }
2154 if (!supported) {
2155 LOGP(DLLAPD, LOGL_NOTICE, "Message %u/%u unsupported.\n",
2156 dp->oph.primitive, dp->oph.operation);
2157 msgb_free(msg);
2158 return 0;
2159 }
2160 if (i == L2DOWNSLLEN) {
2161 LOGP(DLLAPD, LOGL_NOTICE, "Message %u/%u unhandled at this "
2162 "state %s.\n", dp->oph.primitive, dp->oph.operation,
2163 lapd_state_names[dl->state]);
2164 msgb_free(msg);
2165 return 0;
2166 }
2167
2168 LOGP(DLLAPD, LOGL_INFO, "Message %s received in state %s\n",
2169 l2downstatelist[i].name, lapd_state_names[dl->state]);
2170
2171 rc = l2downstatelist[i].rout(dp, lctx);
2172
2173 return rc;
2174}
2175
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +01002176/*! @} */