Pau Espin Pedrol | 0158b05 | 2023-02-17 12:30:57 +0100 | [diff] [blame] | 1 | /*! \file gsm_44_060.h |
| 2 | * General Packet Radio Service (GPRS). |
| 3 | * Radio Link Control / Medium Access Control (RLC/MAC) protocol |
| 4 | * 3GPP TS 44.060 |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | #include <osmocom/core/endian.h> |
| 11 | |
| 12 | /* TS 44.060 10.3a.4.1.1 */ |
| 13 | struct gprs_rlc_ul_header_egprs_1 { |
| 14 | #if OSMO_IS_LITTLE_ENDIAN |
| 15 | uint8_t r:1, |
| 16 | si:1, |
| 17 | cv:4, |
| 18 | tfi_hi:2; |
| 19 | uint8_t tfi_lo:3, |
| 20 | bsn1_hi:5; |
| 21 | uint8_t bsn1_lo:6, |
| 22 | bsn2_hi:2; |
| 23 | uint8_t bsn2_lo:8; |
| 24 | uint8_t cps:5, |
| 25 | rsb:1, |
| 26 | pi:1, |
| 27 | spare_hi:1; |
| 28 | uint8_t spare_lo:6, |
| 29 | dummy:2; |
| 30 | #elif OSMO_IS_BIG_ENDIAN |
| 31 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 32 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 33 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 34 | uint8_t bsn2_hi:2, bsn1_lo:6; |
| 35 | uint8_t bsn2_lo:8; |
| 36 | uint8_t spare_hi:1, pi:1, rsb:1, cps:5; |
| 37 | uint8_t dummy:2, spare_lo:6; |
| 38 | #endif |
| 39 | } __attribute__ ((packed)); |
| 40 | |
| 41 | /* TS 44.060 10.3a.4.2.1 */ |
| 42 | struct gprs_rlc_ul_header_egprs_2 { |
| 43 | #if OSMO_IS_LITTLE_ENDIAN |
| 44 | uint8_t r:1, |
| 45 | si:1, |
| 46 | cv:4, |
| 47 | tfi_hi:2; |
| 48 | uint8_t tfi_lo:3, |
| 49 | bsn1_hi:5; |
| 50 | uint8_t bsn1_lo:6, |
| 51 | cps_hi:2; |
| 52 | uint8_t cps_lo:1, |
| 53 | rsb:1, |
| 54 | pi:1, |
| 55 | spare_hi:5; |
| 56 | uint8_t spare_lo:5, |
| 57 | dummy:3; |
| 58 | #elif OSMO_IS_BIG_ENDIAN |
| 59 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 60 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 61 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 62 | uint8_t cps_hi:2, bsn1_lo:6; |
| 63 | uint8_t spare_hi:5, pi:1, rsb:1, cps_lo:1; |
| 64 | uint8_t dummy:3, spare_lo:5; |
| 65 | #endif |
| 66 | } __attribute__ ((packed)); |
| 67 | |
| 68 | /* TS 44.060 10.3a.4.3.1 */ |
| 69 | struct gprs_rlc_ul_header_egprs_3 { |
| 70 | #if OSMO_IS_LITTLE_ENDIAN |
| 71 | uint8_t r:1, |
| 72 | si:1, |
| 73 | cv:4, |
| 74 | tfi_hi:2; |
| 75 | uint8_t tfi_lo:3, |
| 76 | bsn1_hi:5; |
| 77 | uint8_t bsn1_lo:6, |
| 78 | cps_hi:2; |
| 79 | uint8_t cps_lo:2, |
| 80 | spb:2, |
| 81 | rsb:1, |
| 82 | pi:1, |
| 83 | spare:1, |
| 84 | dummy:1; |
| 85 | #elif OSMO_IS_BIG_ENDIAN |
| 86 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 87 | uint8_t tfi_hi:2, cv:4, si:1, r:1; |
| 88 | uint8_t bsn1_hi:5, tfi_lo:3; |
| 89 | uint8_t cps_hi:2, bsn1_lo:6; |
| 90 | uint8_t dummy:1, spare:1, pi:1, rsb:1, spb:2, cps_lo:2; |
| 91 | #endif |
| 92 | } __attribute__ ((packed)); |
| 93 | |
| 94 | struct gprs_rlc_dl_header_egprs_1 { |
| 95 | #if OSMO_IS_LITTLE_ENDIAN |
| 96 | uint8_t usf:3, |
| 97 | es_p:2, |
| 98 | rrbp:2, |
| 99 | tfi_hi:1; |
| 100 | uint8_t tfi_lo:4, |
| 101 | pr:2, |
| 102 | bsn1_hi:2; |
| 103 | uint8_t bsn1_mid:8; |
| 104 | uint8_t bsn1_lo:1, |
| 105 | bsn2_hi:7; |
| 106 | uint8_t bsn2_lo:3, |
| 107 | cps:5; |
| 108 | #elif OSMO_IS_BIG_ENDIAN |
| 109 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 110 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 111 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 112 | uint8_t bsn1_mid:8; |
| 113 | uint8_t bsn2_hi:7, bsn1_lo:1; |
| 114 | uint8_t cps:5, bsn2_lo:3; |
| 115 | #endif |
| 116 | } __attribute__ ((packed)); |
| 117 | |
| 118 | struct gprs_rlc_dl_header_egprs_2 { |
| 119 | #if OSMO_IS_LITTLE_ENDIAN |
| 120 | uint8_t usf:3, |
| 121 | es_p:2, |
| 122 | rrbp:2, |
| 123 | tfi_hi:1; |
| 124 | uint8_t tfi_lo:4, |
| 125 | pr:2, |
| 126 | bsn1_hi:2; |
| 127 | uint8_t bsn1_mid:8; |
| 128 | uint8_t bsn1_lo:1, |
| 129 | cps:3, |
| 130 | dummy:4; |
| 131 | #elif OSMO_IS_BIG_ENDIAN |
| 132 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 133 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 134 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 135 | uint8_t bsn1_mid:8; |
| 136 | uint8_t dummy:4, cps:3, bsn1_lo:1; |
| 137 | #endif |
| 138 | } __attribute__ ((packed)); |
| 139 | |
| 140 | struct gprs_rlc_dl_header_egprs_3 { |
| 141 | #if OSMO_IS_LITTLE_ENDIAN |
| 142 | uint8_t usf:3, |
| 143 | es_p:2, |
| 144 | rrbp:2, |
| 145 | tfi_hi:1; |
| 146 | uint8_t tfi_lo:4, |
| 147 | pr:2, |
| 148 | bsn1_hi:2; |
| 149 | uint8_t bsn1_mid:8; |
| 150 | uint8_t bsn1_lo:1, |
| 151 | cps:4, |
| 152 | spb:2, |
| 153 | dummy:1; |
| 154 | #elif OSMO_IS_BIG_ENDIAN |
| 155 | /* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */ |
| 156 | uint8_t tfi_hi:1, rrbp:2, es_p:2, usf:3; |
| 157 | uint8_t bsn1_hi:2, pr:2, tfi_lo:4; |
| 158 | uint8_t bsn1_mid:8; |
| 159 | uint8_t dummy:1, spb:2, cps:4, bsn1_lo:1; |
| 160 | #endif |
| 161 | } __attribute__ ((packed)); |
| 162 | |
| 163 | /* TS 44.060 Table 12.24.2 |
| 164 | * Meaning of values documented in TS 23.060 Chapter 6.3.3.1: Network Mode of Operation */ |
| 165 | enum osmo_gprs_nmo { |
| 166 | GPRS_NMO_I = 0, /* CS pagin on GPRS paging or traffic channel */ |
| 167 | GPRS_NMO_II = 1, /* all paging on CCCH */ |
| 168 | GPRS_NMO_III = 2, /* no paging coordination */ |
| 169 | }; |
| 170 | |
| 171 | /* TS 44.060 12.24 */ |
| 172 | struct osmo_gprs_cell_options { |
| 173 | enum osmo_gprs_nmo nmo; |
| 174 | /* T3168: wait for packet uplink assignment message */ |
| 175 | uint32_t t3168; /* in milliseconds */ |
| 176 | /* T3192: wait for release of the TBF after reception of the final block */ |
| 177 | uint32_t t3192; /* in milliseconds */ |
| 178 | uint32_t drx_timer_max;/* in seconds */ |
| 179 | uint32_t bs_cv_max; |
| 180 | uint8_t supports_egprs_11bit_rach; |
| 181 | bool ctrl_ack_type_use_block; /* use PACKET CONTROL ACKNOWLEDGMENT */ |
| 182 | |
| 183 | uint8_t ext_info_present; |
| 184 | struct { |
| 185 | uint8_t egprs_supported; |
| 186 | uint8_t use_egprs_p_ch_req; |
| 187 | uint8_t bep_period; |
| 188 | uint8_t pfc_supported; |
| 189 | uint8_t dtm_supported; |
| 190 | uint8_t bss_paging_coordination; |
| 191 | bool ccn_active; |
| 192 | } ext_info; |
| 193 | }; |
| 194 | |
| 195 | /* TS 44.060 Table 12.9.2 */ |
| 196 | struct osmo_gprs_power_ctrl_pars { |
| 197 | uint8_t alpha; |
| 198 | uint8_t t_avg_w; |
| 199 | uint8_t t_avg_t; |
| 200 | uint8_t pc_meas_chan; |
| 201 | uint8_t n_avg_i; |
| 202 | }; |
| 203 | |
| 204 | |
| 205 | /*! Structure for CPS coding and puncturing scheme (TS 44.060 10.4.8a) */ |
| 206 | struct egprs_cps { |
| 207 | uint8_t bits; |
| 208 | uint8_t mcs; |
| 209 | uint8_t p[2]; |
| 210 | }; |
| 211 | |
| 212 | /*! CPS puncturing table selection (TS 44.060 10.4.8a) */ |
| 213 | enum egprs_cps_punc { |
| 214 | EGPRS_CPS_P1, |
| 215 | EGPRS_CPS_P2, |
| 216 | EGPRS_CPS_P3, |
| 217 | EGPRS_CPS_NONE = -1, |
| 218 | }; |
| 219 | |
| 220 | /*! EGPRS header types (TS 44.060 10.0a.2) */ |
| 221 | enum egprs_hdr_type { |
| 222 | EGPRS_HDR_TYPE1, |
| 223 | EGPRS_HDR_TYPE2, |
| 224 | EGPRS_HDR_TYPE3, |
| 225 | }; |
| 226 | |
| 227 | enum osmo_gprs_cs { |
| 228 | OSMO_GPRS_CS_NONE, |
| 229 | OSMO_GPRS_CS1, |
| 230 | OSMO_GPRS_CS2, |
| 231 | OSMO_GPRS_CS3, |
| 232 | OSMO_GPRS_CS4, |
| 233 | OSMO_GPRS_MCS1, |
| 234 | OSMO_GPRS_MCS2, |
| 235 | OSMO_GPRS_MCS3, |
| 236 | OSMO_GPRS_MCS4, |
| 237 | OSMO_GPRS_MCS5, |
| 238 | OSMO_GPRS_MCS6, |
| 239 | OSMO_GPRS_MCS7, |
| 240 | OSMO_GPRS_MCS8, |
| 241 | OSMO_GPRS_MCS9, |
| 242 | _NUM_OSMO_GPRS_CS |
| 243 | }; |
| 244 | |
| 245 | int egprs_get_cps(struct egprs_cps *cps, uint8_t type, uint8_t bits); |
| 246 | |
| 247 | int osmo_gprs_ul_block_size_bits(enum osmo_gprs_cs cs); |
| 248 | int osmo_gprs_dl_block_size_bits(enum osmo_gprs_cs cs); |
| 249 | int osmo_gprs_ul_block_size_bytes(enum osmo_gprs_cs cs); |
| 250 | int osmo_gprs_dl_block_size_bytes(enum osmo_gprs_cs cs); |
| 251 | enum osmo_gprs_cs osmo_gprs_ul_cs_by_block_bytes(uint8_t block_size); |
| 252 | enum osmo_gprs_cs osmo_gprs_dl_cs_by_block_bytes(uint8_t block_size); |