blob: 596b66ebd284a79a41c1aadb978fff79b28cdcbc [file] [log] [blame]
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +02001/* decoding
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20#include <decoding.h>
21#include <rlc.h>
22#include <gprs_debug.h>
23
24#include <arpa/inet.h>
25
26#include <errno.h>
27#include <string.h>
28
29
30int Decoding::tlli_from_ul_data(const uint8_t *data, uint8_t len,
31 uint32_t *tlli)
32{
33 struct rlc_ul_header *rh = (struct rlc_ul_header *)data;
34 struct rlc_li_field *li;
35 uint8_t e;
36 uint32_t _tlli;
37
38 if (!rh->ti)
39 return -EINVAL;
40
41 data += 3;
42 len -= 3;
43 e = rh->e;
44 /* if E is not set (LI follows) */
45 while (!e) {
46 if (!len) {
47 LOGP(DRLCMACUL, LOGL_NOTICE, "UL DATA LI extended, "
48 "but no more data\n");
49 return -EINVAL;
50 }
51 /* get new E */
52 li = (struct rlc_li_field *)data;
53 if (li->e == 0) /* if LI==0, E is interpreted as '1' */
54 e = 1;
55 else
56 e = li->e;
57 data++;
58 len--;
59 }
60 if (len < 4) {
61 LOGP(DRLCMACUL, LOGL_NOTICE, "UL DATA TLLI out of frame "
62 "border\n");
63 return -EINVAL;
64 }
65 memcpy(&_tlli, data, 4);
66 *tlli = ntohl(_tlli);
67
68 return 0;
69}
70