Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 1 | /* 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 | |
| 30 | int 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 | |
Holger Hans Peter Freyther | fcbc702 | 2013-10-26 17:38:37 +0200 | [diff] [blame] | 71 | uint8_t Decoding::get_ms_class_by_capability(MS_Radio_Access_capability_t *cap) |
| 72 | { |
| 73 | int i; |
| 74 | |
| 75 | for (i = 0; i < cap->Count_MS_RA_capability_value; i++) { |
| 76 | if (!cap->MS_RA_capability_value[i].u.Content.Exist_Multislot_capability) |
| 77 | continue; |
| 78 | if (!cap->MS_RA_capability_value[i].u.Content.Multislot_capability.Exist_GPRS_multislot_class) |
| 79 | continue; |
| 80 | return cap->MS_RA_capability_value[i].u.Content.Multislot_capability.GPRS_multislot_class; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Holger Hans Peter Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 86 | /** |
| 87 | * show_rbb needs to be an array with 65 elements |
Daniel Willmann | 5e94cd4 | 2013-12-11 20:11:16 +0100 | [diff] [blame] | 88 | * The index of the array is the bit position in the rbb |
| 89 | * (show_rbb[63] relates to BSN ssn-1) |
Holger Hans Peter Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 90 | */ |
| 91 | void Decoding::extract_rbb(const uint8_t *rbb, char *show_rbb) |
| 92 | { |
Daniel Willmann | 5e94cd4 | 2013-12-11 20:11:16 +0100 | [diff] [blame] | 93 | for (int i = 0; i < 64; i++) { |
Holger Hans Peter Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 94 | uint8_t bit; |
| 95 | |
Daniel Willmann | 5e94cd4 | 2013-12-11 20:11:16 +0100 | [diff] [blame] | 96 | bit = !!(rbb[i/8] & (1<<(7-i%8))); |
Daniel Willmann | 6f7cb2c | 2013-12-11 14:25:20 +0100 | [diff] [blame] | 97 | show_rbb[i] = bit ? 'R' : 'I'; |
Holger Hans Peter Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | show_rbb[64] = '\0'; |
| 101 | } |