Max | 51754b6 | 2019-03-13 17:14:13 +0100 | [diff] [blame] | 1 | /* coding_scheme.c |
| 2 | * |
| 3 | * Copyright (C) 2019 by sysmocom s.f.m.c. GmbH |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <stdbool.h> |
| 22 | |
| 23 | #include <osmocom/core/utils.h> |
| 24 | |
| 25 | #include "coding_scheme.h" |
| 26 | |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame^] | 27 | const struct value_string mcs_names[] = { |
| 28 | { UNKNOWN, "UNKNOWN" }, |
| 29 | { CS1, "CS-1" }, |
| 30 | { CS2, "CS-2" }, |
| 31 | { CS3, "CS-3" }, |
| 32 | { CS4, "CS-4" }, |
| 33 | { MCS1, "MCS-1" }, |
| 34 | { MCS2, "MCS-2" }, |
| 35 | { MCS3, "MCS-3" }, |
| 36 | { MCS4, "MCS-4" }, |
| 37 | { MCS5, "MCS-5" }, |
| 38 | { MCS6, "MCS-6" }, |
| 39 | { MCS7, "MCS-7" }, |
| 40 | { MCS8, "MCS-8" }, |
| 41 | { MCS9, "MCS-9" }, |
| 42 | { 0, NULL } |
| 43 | }; |
| 44 | |
| 45 | const char *mcs_name(enum CodingScheme val) { |
| 46 | return get_value_string(mcs_names, val); |
| 47 | } |
| 48 | |
Max | 51754b6 | 2019-03-13 17:14:13 +0100 | [diff] [blame] | 49 | static struct { |
| 50 | struct { |
| 51 | uint8_t data_header_bits; |
| 52 | } uplink, downlink; |
| 53 | uint8_t data_block_header_bits; |
| 54 | uint8_t num_blocks; |
| 55 | const char *name; |
| 56 | } hdr_type_info[NUM_HEADER_TYPES] = { |
| 57 | { { 0 }, { 0 }, 0, 0, "INVALID" }, |
| 58 | { { 1 * 8 + 0 }, { 1 * 8 + 0 }, 0, 0, "CONTROL" }, |
| 59 | { { 3 * 8 + 0 }, { 3 * 8 + 0 }, 0, 1, "GPRS_DATA" }, |
| 60 | { { 5 * 8 + 6 }, { 5 * 8 + 0 }, 2, 2, "EGPRS_DATA_TYPE1" }, |
| 61 | { { 4 * 8 + 5 }, { 3 * 8 + 4 }, 2, 1, "EGPRS_DATA_TYPE2" }, |
| 62 | { { 3 * 8 + 7 }, { 3 * 8 + 7 }, 2, 1, "EGPRS_DATA_TYPE3" }, |
| 63 | }; |
| 64 | |
| 65 | uint8_t num_data_blocks(enum HeaderType ht) |
| 66 | { |
| 67 | OSMO_ASSERT(ht < NUM_HEADER_TYPES); |
| 68 | return hdr_type_info[ht].num_blocks; |
| 69 | } |
| 70 | |
| 71 | uint8_t num_data_header_bits_UL(enum HeaderType ht) |
| 72 | { |
| 73 | OSMO_ASSERT(ht < NUM_HEADER_TYPES); |
| 74 | return hdr_type_info[ht].uplink.data_header_bits; |
| 75 | } |
| 76 | |
| 77 | uint8_t num_data_header_bits_DL(enum HeaderType ht) |
| 78 | { |
| 79 | OSMO_ASSERT(ht < NUM_HEADER_TYPES); |
| 80 | return hdr_type_info[ht].downlink.data_header_bits; |
| 81 | } |
| 82 | |
| 83 | uint8_t num_data_block_header_bits(enum HeaderType ht) |
| 84 | { |
| 85 | OSMO_ASSERT(ht < NUM_HEADER_TYPES); |
| 86 | return hdr_type_info[ht].data_block_header_bits; |
| 87 | } |