Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 1 | /* mslot_class.c |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
| 4 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
| 5 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 6 | * Copyright (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (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 |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <mslot_class.h> |
| 24 | |
| 25 | #include <osmocom/core/utils.h> |
| 26 | #include <osmocom/core/logging.h> |
| 27 | |
| 28 | #include <errno.h> |
| 29 | |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 30 | /* 3GPP TS 45.002 Annex B Table B.1 */ |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 31 | |
| 32 | struct gprs_ms_multislot_class { |
| 33 | uint8_t rx, tx, sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */ |
| 34 | uint8_t ta, tb, ra, rb; /* Minimum Number of Slots */ |
| 35 | uint8_t type; /* Type of Mobile */ |
| 36 | }; |
| 37 | |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 38 | static const struct gprs_ms_multislot_class gprs_ms_multislot_class[] = { |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 39 | /* M-S Class | Max # of slots | Min # of slots | Type */ |
| 40 | /* | Rx Tx Sum | Tta Ttb Tra Trb | */ |
| 41 | /* N/A */ { MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA }, |
| 42 | /* 1 */ { 1, 1, 2, 3, 2, 4, 2, 1 }, |
| 43 | /* 2 */ { 2, 1, 3, 3, 2, 3, 1, 1 }, |
| 44 | /* 3 */ { 2, 2, 3, 3, 2, 3, 1, 1 }, |
| 45 | /* 4 */ { 3, 1, 4, 3, 1, 3, 1, 1 }, |
| 46 | /* 5 */ { 2, 2, 4, 3, 1, 3, 1, 1 }, |
| 47 | /* 6 */ { 3, 2, 4, 3, 1, 3, 1, 1 }, |
| 48 | /* 7 */ { 3, 3, 4, 3, 1, 3, 1, 1 }, |
| 49 | /* 8 */ { 4, 1, 5, 3, 1, 2, 1, 1 }, |
| 50 | /* 9 */ { 3, 2, 5, 3, 1, 2, 1, 1 }, |
| 51 | /* 10 */ { 4, 2, 5, 3, 1, 2, 1, 1 }, |
| 52 | /* 11 */ { 4, 3, 5, 3, 1, 2, 1, 1 }, |
| 53 | /* 12 */ { 4, 4, 5, 2, 1, 2, 1, 1 }, |
| 54 | /* 13 */ { 3, 3, MS_NA, MS_NA, MS_A, 3, MS_A, 2 }, |
| 55 | /* 14 */ { 4, 4, MS_NA, MS_NA, MS_A, 3, MS_A, 2 }, |
| 56 | /* 15 */ { 5, 5, MS_NA, MS_NA, MS_A, 3, MS_A, 2 }, |
| 57 | /* 16 */ { 6, 6, MS_NA, MS_NA, MS_A, 2, MS_A, 2 }, |
| 58 | /* 17 */ { 7, 7, MS_NA, MS_NA, MS_A, 1, 0, 2 }, |
| 59 | /* 18 */ { 8, 8, MS_NA, MS_NA, 0, 0, 0, 2 }, |
| 60 | /* 19 */ { 6, 2, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 61 | /* 20 */ { 6, 3, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 62 | /* 21 */ { 6, 4, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 63 | /* 22 */ { 6, 4, MS_NA, 2, MS_B, 2, MS_C, 1 }, |
| 64 | /* 23 */ { 6, 6, MS_NA, 2, MS_B, 2, MS_C, 1 }, |
| 65 | /* 24 */ { 8, 2, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 66 | /* 25 */ { 8, 3, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 67 | /* 26 */ { 8, 4, MS_NA, 3, MS_B, 2, MS_C, 1 }, |
| 68 | /* 27 */ { 8, 4, MS_NA, 2, MS_B, 2, MS_C, 1 }, |
| 69 | /* 28 */ { 8, 6, MS_NA, 2, MS_B, 2, MS_C, 1 }, |
| 70 | /* 29 */ { 8, 8, MS_NA, 2, MS_B, 2, MS_C, 1 }, |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 71 | /* 30 */ { 5, 1, 6, 2, 1, 1, 1, 1 }, |
| 72 | /* 31 */ { 5, 2, 6, 2, 1, 1, 1, 1 }, |
| 73 | /* 32 */ { 5, 3, 6, 2, 1, 1, 1, 1 }, |
| 74 | /* 33 */ { 5, 4, 6, 2, 1, 1, 1, 1 }, |
| 75 | /* 34 */ { 5, 5, 6, 2, 1, 1, 1, 1 }, |
| 76 | /* 35 */ { 5, 1, 6, 2, 1, MS_TO, 1, 1 }, |
| 77 | /* 36 */ { 5, 2, 6, 2, 1, MS_TO, 1, 1 }, |
| 78 | /* 37 */ { 5, 3, 6, 2, 1, MS_TO, 1, 1 }, |
| 79 | /* 38 */ { 5, 4, 6, 2, 1, MS_TO, 1, 1 }, |
| 80 | /* 39 */ { 5, 5, 6, 2, 1, MS_TO, 1, 1 }, |
| 81 | /* 40 */ { 6, 1, 7, 1, 1, 1, MS_TO, 1 }, |
| 82 | /* 41 */ { 6, 2, 7, 1, 1, 1, MS_TO, 1 }, |
| 83 | /* 42 */ { 6, 3, 7, 1, 1, 1, MS_TO, 1 }, |
| 84 | /* 43 */ { 6, 4, 7, 1, 1, 1, MS_TO, 1 }, |
| 85 | /* 44 */ { 6, 5, 7, 1, 1, 1, MS_TO, 1 }, |
| 86 | /* 45 */ { 6, 6, 7, 1, 1, 1, MS_TO, 1 }, |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static inline const struct gprs_ms_multislot_class *get_mslot_table(uint8_t ms_cl) |
| 90 | { |
| 91 | uint8_t index = ms_cl ? ms_cl : DEFAULT_MSLOT_CLASS; |
| 92 | |
| 93 | if (ms_cl >= ARRAY_SIZE(gprs_ms_multislot_class)) |
| 94 | index = 0; |
| 95 | |
| 96 | return &gprs_ms_multislot_class[index]; |
| 97 | } |
| 98 | |
Max | 327e121 | 2017-11-21 13:01:19 +0100 | [diff] [blame] | 99 | uint8_t mslot_class_max() |
| 100 | { |
| 101 | return ARRAY_SIZE(gprs_ms_multislot_class); |
| 102 | } |
| 103 | |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 104 | uint8_t mslot_class_get_ta(uint8_t ms_cl) |
| 105 | { |
| 106 | return get_mslot_table(ms_cl)->ta; |
| 107 | } |
| 108 | |
| 109 | /* TODO: Set it to 1 if FH is implemented and enabled |
| 110 | * MS_A and MS_B are 0 iff FH is disabled and there is no Tx/Rx change. |
| 111 | * This is never the case with the current implementation, so 1 will always be used. */ |
| 112 | uint8_t mslot_class_get_tb(uint8_t ms_cl) |
| 113 | { |
| 114 | const struct gprs_ms_multislot_class *t = get_mslot_table(ms_cl); |
| 115 | |
| 116 | switch (t->tb) { |
| 117 | case MS_A: |
| 118 | return 0; |
| 119 | case MS_B: |
| 120 | return 1; |
| 121 | default: |
| 122 | return t->tb; |
| 123 | } |
| 124 | } |
| 125 | |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 126 | uint8_t mslot_class_get_ra(uint8_t ms_cl, uint8_t ta) |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 127 | { |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 128 | const struct gprs_ms_multislot_class *t = get_mslot_table(ms_cl); |
| 129 | |
| 130 | switch (t->ra) { |
| 131 | case MS_TO: |
| 132 | return ta + 1; |
| 133 | default: |
| 134 | return t->ra; |
| 135 | } |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 138 | uint8_t mslot_class_get_rb(uint8_t ms_cl, uint8_t ta) |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 139 | { |
| 140 | const struct gprs_ms_multislot_class *t = get_mslot_table(ms_cl); |
| 141 | |
| 142 | switch (t->rb) { |
| 143 | case MS_A: |
| 144 | return 0; |
| 145 | case MS_C: |
| 146 | return 1; |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 147 | case MS_TO: |
| 148 | return ta; |
Max | 842d781 | 2017-11-01 18:11:24 +0100 | [diff] [blame] | 149 | default: |
| 150 | return t->rb; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | uint8_t mslot_class_get_tx(uint8_t ms_cl) |
| 155 | { |
| 156 | return get_mslot_table(ms_cl)->tx; |
| 157 | } |
| 158 | |
| 159 | uint8_t mslot_class_get_rx(uint8_t ms_cl) |
| 160 | { |
| 161 | return get_mslot_table(ms_cl)->rx; |
| 162 | } |
| 163 | |
| 164 | uint8_t mslot_class_get_sum(uint8_t ms_cl) |
| 165 | { |
| 166 | return get_mslot_table(ms_cl)->sum; |
| 167 | } |
| 168 | |
| 169 | uint8_t mslot_class_get_type(uint8_t ms_cl) |
| 170 | { |
| 171 | return get_mslot_table(ms_cl)->type; |
| 172 | } |