Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 1 | /* Data Types / Encoding / Decoding for OsmocomBB L1CTL interface */ |
| 2 | /* (C) 2017 by Harald Welte <laforge@gnumonks.org>, derived from l1ctl_proto.h |
| 3 | * (C) 2010 by Harald Welte + Holger Hans Peter Freyther */ |
| 4 | module L1CTL_Types { |
| 5 | |
| 6 | import from General_Types all; |
| 7 | import from GSM_Types all; |
| 8 | import from Osmocom_Types all; |
| 9 | |
| 10 | type enumerated L1ctlMsgType { |
| 11 | L1CTL_NONE, |
| 12 | L1CTL_FBSB_REQ, |
| 13 | L1CTL_FBSB_CONF, |
| 14 | L1CTL_DATA_IND, |
| 15 | L1CTL_RACH_REQ, |
| 16 | L1CTL_DM_EST_REQ, |
| 17 | L1CTL_DATA_REQ, |
| 18 | L1CTL_RESET_IND, |
| 19 | L1CTL_PM_REQ, /* power measurement */ |
| 20 | L1CTL_PM_CONF, /* power measurement */ |
| 21 | L1CTL_ECHO_REQ, |
| 22 | L1CTL_ECHO_CONF, |
| 23 | L1CTL_RACH_CONF, |
| 24 | L1CTL_RESET_REQ, |
| 25 | L1CTL_RESET_CONF, |
| 26 | L1CTL_DATA_CONF, |
| 27 | L1CTL_CCCH_MODE_REQ, |
| 28 | L1CTL_CCCH_MODE_CONF, |
| 29 | L1CTL_DM_REL_REQ, |
| 30 | L1CTL_PARAM_REQ, |
| 31 | L1CTL_DM_FREQ_REQ, |
| 32 | L1CTL_CRYPTO_REQ, |
| 33 | L1CTL_SIM_REQ, |
| 34 | L1CTL_SIM_CONF, |
| 35 | L1CTL_TCH_MODE_REQ, |
| 36 | L1CTL_TCH_MODE_CONF, |
| 37 | L1CTL_NEIGH_PM_REQ, |
| 38 | L1CTL_NEIGH_PM_IND, |
| 39 | L1CTL_TRAFFIC_REQ, |
| 40 | L1CTL_TRAFFIC_CONF, |
| 41 | L1CTL_TRAFFIC_IND |
| 42 | } with { variant "FIELDLENGTH(8)" }; |
| 43 | |
| 44 | type enumerated L1ctlCcchMode { |
| 45 | CCCH_MODE_NONE (0), |
| 46 | CCCH_MODE_NON_COMBINED, |
| 47 | CCCH_MODE_COMBINED |
| 48 | } with { variant "FIELDLENGTH(8)" }; |
| 49 | |
| 50 | type enumerated L1ctlNeighMode { |
| 51 | NEIGH_MODE_NONE (0), |
| 52 | NEIGH_MODE_PM, |
| 53 | NEIGH_MODE_SB |
| 54 | } with { variant "FIELDLENGTH(8)" }; |
| 55 | |
| 56 | type enumerated L1ctlResetType { |
| 57 | L1CTL_RES_T_BOOT (0), |
| 58 | L1CTL_RES_T_FULL, |
| 59 | L1CTL_RES_T_SCHED |
| 60 | } with { variant "FIELDLENGTH(8)" }; |
| 61 | |
| 62 | const integer TRAFFIC_DATA_LEN := 40; |
| 63 | |
| 64 | type record L1ctlHdrFlags { |
| 65 | BIT7 padding, |
| 66 | boolean f_done |
| 67 | } with { variant "" }; |
| 68 | |
| 69 | type record L1ctlHeader { |
| 70 | L1ctlMsgType msg_type, |
| 71 | L1ctlHdrFlags flags, |
| 72 | OCT2 padding |
| 73 | } with { variant "" }; |
| 74 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 75 | template L1ctlHeader t_L1ctlHeader(template L1ctlMsgType msg_type) := { |
| 76 | msg_type := msg_type, |
| 77 | flags := { padding := '0000000'B, f_done := false }, |
| 78 | padding := '0000'O |
| 79 | }; |
| 80 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 81 | type record L1ctlDlInfo { |
Harald Welte | 8e4db2c | 2017-07-16 18:54:55 +0200 | [diff] [blame] | 82 | RslChannelNr chan_nr, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 83 | RslLinkId link_id, |
| 84 | Arfcn arfcn, |
Harald Welte | 5f0d5c8 | 2017-07-16 18:56:01 +0200 | [diff] [blame] | 85 | uint32_t frame_nr, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 86 | GsmRxLev rx_level, |
| 87 | uint8_t snr, |
| 88 | uint8_t num_biterr, |
| 89 | uint8_t fire_crc |
| 90 | } with { variant "" }; |
| 91 | |
| 92 | type record L1ctlFbsbConf { |
| 93 | int16_t initial_freq_err, |
| 94 | uint8_t result, |
| 95 | uint8_t bsic |
| 96 | } with { variant "" }; |
| 97 | |
| 98 | type record L1ctlCcchModeConf { |
| 99 | L1ctlCcchMode ccch_mode, |
| 100 | OCT3 padding |
| 101 | } with { variant "" }; |
| 102 | |
| 103 | /* gsm48_chan_mode */ |
| 104 | type uint8_t L1ctlTchMode; |
| 105 | |
| 106 | type record L1ctlAudioMode { |
| 107 | BIT4 padding, |
| 108 | boolean tx_microphone, |
| 109 | boolean tx_traffic_req, |
| 110 | boolean rx_speaker, |
| 111 | boolean rx_traffic_ind |
| 112 | } with { variant "" }; |
| 113 | |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 114 | template L1ctlAudioMode t_L1CTL_AudioModeNone := { '0000'B, false, false, false, false }; |
| 115 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 116 | type record L1ctlTchModeConf { |
| 117 | L1ctlTchMode tch_mode, |
| 118 | L1ctlAudioMode audio_mode, |
| 119 | OCT2 padding |
| 120 | } with { variant "" }; |
| 121 | |
| 122 | type record L1ctlDataInd { |
| 123 | octetstring payload length(23) |
| 124 | } with { variant "" }; |
| 125 | |
| 126 | type union L1ctlDlPayload { |
| 127 | L1ctlFbsbConf fbsb_conf, |
| 128 | L1ctlCcchModeConf ccch_mode_conf, |
| 129 | L1ctlTchModeConf tch_mode_conf, |
| 130 | L1ctlDataInd data_ind, |
| 131 | L1ctlTrafficReq traffic_ind, |
| 132 | octetstring other |
| 133 | } with { variant "" }; |
| 134 | |
| 135 | type record L1ctlDlMessage { |
| 136 | L1ctlHeader header, |
| 137 | L1ctlDlInfo dl_info optional, |
| 138 | L1ctlDlPayload payload |
| 139 | } with { variant (dl_info) "PRESENCE(header.msg_type = L1CTL_FBSB_CONF, |
| 140 | header.msg_type = L1CTL_RACH_CONF, |
| 141 | header.msg_type = L1CTL_DATA_IND, |
| 142 | header.msg_type = L1CTL_DATA_CONF, |
| 143 | header.msg_type = L1CTL_TRAFFIC_IND)" |
| 144 | variant (payload) "CROSSTAG(fbsb_conf, header.msg_type = L1CTL_FBSB_CONF; |
| 145 | ccch_mode_conf, header.msg_type = L1CTL_CCCH_MODE_CONF; |
| 146 | tch_mode_conf, header.msg_type = L1CTL_TCH_MODE_CONF; |
| 147 | data_ind, header.msg_type = L1CTL_DATA_IND; |
| 148 | traffic_ind, header.msg_type = L1CTL_TRAFFIC_IND; |
| 149 | other, OTHERWISE; |
| 150 | )" }; |
| 151 | |
| 152 | external function enc_L1ctlDlMessage(in L1ctlDlMessage msg) return octetstring |
| 153 | with { extension "prototype(convert) encode(RAW)" }; |
| 154 | external function dec_L1ctlDlMessage(in octetstring stream) return L1ctlDlMessage |
| 155 | with { extension "prototype(convert) decode(RAW)" }; |
| 156 | |
| 157 | |
| 158 | type record L1ctlUlInfo { |
Harald Welte | 8e4db2c | 2017-07-16 18:54:55 +0200 | [diff] [blame] | 159 | RslChannelNr chan_nr, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 160 | RslLinkId link_id, |
| 161 | OCT2 padding |
| 162 | } with { variant "" }; |
| 163 | |
| 164 | type record L1ctlFbsbFlags { |
| 165 | BIT5 padding, |
| 166 | boolean sb, |
| 167 | boolean fb1, |
| 168 | boolean fb0 |
| 169 | } with { variant "" }; |
| 170 | |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 171 | template L1ctlFbsbFlags t_L1CTL_FBSB_F_ALL := { |
| 172 | padding := '00000'B, |
| 173 | sb := true, |
| 174 | fb1 := true, |
| 175 | fb0 := true |
| 176 | }; |
| 177 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 178 | type record L1ctlFbsbReq { |
| 179 | Arfcn arfcn, |
| 180 | uint16_t timeout_tdma_frames, |
| 181 | uint16_t freq_err_thresh1, |
| 182 | uint16_t freq_err_thresh2, |
| 183 | uint8_t num_freqerr_avg, |
| 184 | L1ctlFbsbFlags flags, |
| 185 | uint8_t sync_info_idx, |
| 186 | L1ctlCcchMode ccch_mode, |
| 187 | GsmRxLev rxlev_exp |
| 188 | } with { variant "" }; |
| 189 | |
| 190 | type record L1ctlCcchModeReq { |
| 191 | L1ctlTchMode tch_mode, |
| 192 | L1ctlAudioMode audio_mode, |
| 193 | OCT2 padding |
| 194 | } with { variant "" }; |
| 195 | |
| 196 | type record L1ctlTchModeReq { |
| 197 | L1ctlTchMode tch_mode, |
| 198 | L1ctlAudioMode audio_mode, |
| 199 | OCT2 padding |
| 200 | } with { variant "" }; |
| 201 | |
| 202 | type record L1ctlRachReq { |
| 203 | uint8_t ra, |
| 204 | uint8_t combined, |
| 205 | uint16_t offset |
| 206 | } with { variant "" }; |
| 207 | |
| 208 | type record L1ctlParReq { |
| 209 | int8_t ta, |
| 210 | uint8_t tx_power, |
| 211 | OCT2 padding |
| 212 | } with { variant "" }; |
| 213 | |
| 214 | type record L1ctlH1 { |
| 215 | uint8_t hsn, |
| 216 | uint8_t maio, |
| 217 | uint8_t n, |
| 218 | OCT1 padding, |
| 219 | bitstring ma length(64) |
| 220 | } with { variant "" }; |
| 221 | |
| 222 | type record L1ctlDmEstReq { |
| 223 | GsmTsc tsc, |
| 224 | uint8_t h, |
| 225 | Arfcn arfcn optional, |
| 226 | L1ctlH1 hopping optional, |
| 227 | L1ctlTchMode tch_mode, |
| 228 | L1ctlAudioMode audio_mode |
| 229 | } with { variant (arfcn) "PRESENCE(h = 0)" |
| 230 | variant (hopping) "PRESENCE(h = 1)" }; |
| 231 | |
| 232 | type record L1ctlReset { |
| 233 | L1ctlResetType reset_type, |
| 234 | OCT3 padding |
| 235 | } with { variant "" }; |
| 236 | |
| 237 | |
| 238 | type record L1ctlTrafficReq { |
| 239 | octetstring data length(TRAFFIC_DATA_LEN) |
| 240 | } with { variant "" }; |
| 241 | |
| 242 | type union L1ctlUlPayload { |
| 243 | L1ctlFbsbReq fbsb_req, |
| 244 | L1ctlCcchModeReq ccch_mode_req, |
| 245 | L1ctlTchModeReq tch_mode_req, |
| 246 | L1ctlRachReq rach_req, |
| 247 | L1ctlParReq par_req, |
| 248 | L1ctlDmEstReq dm_est_req, |
| 249 | L1ctlReset reset_req, |
| 250 | //L1ctlNeighPmReq neigh_pm_req, |
| 251 | L1ctlTrafficReq traffic_req, |
| 252 | octetstring other |
| 253 | } with { variant "" }; |
| 254 | |
| 255 | type record L1ctlUlMessage { |
| 256 | L1ctlHeader header, |
| 257 | L1ctlUlInfo ul_info optional, |
| 258 | L1ctlUlPayload payload |
| 259 | } with { variant (ul_info) "PRESENCE(header.msg_type = L1CTL_RACH_REQ, |
| 260 | header.msg_type = L1CTL_PARAM_REQ, |
| 261 | header.msg_type = L1CTL_CRYPTO_REQ, |
| 262 | header.msg_type = L1CTL_DATA_REQ, |
| 263 | header.msg_type = L1CTL_DM_EST_REQ, |
| 264 | header.msg_type = L1CTL_DM_FREQ_REQ, |
| 265 | header.msg_type = L1CTL_DM_REL_REQ, |
| 266 | header.msg_type = L1CTL_TRAFFIC_REQ)" |
| 267 | variant (payload) "CROSSTAG(fbsb_req, header.msg_type = L1CTL_FBSB_REQ; |
| 268 | ccch_mode_req, header.msg_type = L1CTL_CCCH_MODE_REQ; |
| 269 | tch_mode_req, header.msg_type = L1CTL_TCH_MODE_REQ; |
| 270 | rach_req, header.msg_type = L1CTL_RACH_REQ; |
| 271 | par_req, header.msg_type = L1CTL_PARAM_REQ; |
| 272 | dm_est_req, header.msg_type = L1CTL_DM_EST_REQ; |
| 273 | reset_req, header.msg_type = L1CTL_RESET_REQ; |
| 274 | traffic_req, header.msg_type = L1CTL_TRAFFIC_REQ; |
| 275 | other, OTHERWISE; |
| 276 | )" }; |
| 277 | |
| 278 | external function enc_L1ctlUlMessage(in L1ctlUlMessage msg) return octetstring |
| 279 | with { extension "prototype(convert) encode(RAW)" }; |
| 280 | external function dec_L1ctlUlMessage(in octetstring stream) return L1ctlUlMessage |
| 281 | with { extension "prototype(convert) decode(RAW)" }; |
| 282 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 283 | type record L1ctlUlMessageLV { |
| 284 | uint16_t len, |
| 285 | L1ctlUlMessage msg |
| 286 | } with { variant (len) "LENGTHTO(msg)" }; |
| 287 | |
| 288 | external function enc_L1ctlUlMessageLV(in L1ctlUlMessageLV msg) return octetstring |
| 289 | with { extension "prototype(convert) encode(RAW)" }; |
| 290 | external function dec_L1ctlUlMessageLV(in octetstring stream) return L1ctlUlMessageLV |
| 291 | with { extension "prototype(convert) decode(RAW)" }; |
| 292 | |
| 293 | type record L1ctlDlMessageLV { |
| 294 | uint16_t len, |
| 295 | L1ctlDlMessage msg |
| 296 | } with { variant (len) "LENGTHTO(msg)" }; |
| 297 | |
| 298 | external function enc_L1ctlDlMessageLV(in L1ctlDlMessageLV msg) return octetstring |
| 299 | with { extension "prototype(convert) encode(RAW)" }; |
| 300 | external function dec_L1ctlDlMessageLV(in octetstring stream) return L1ctlDlMessageLV |
| 301 | with { extension "prototype(convert) decode(RAW)" }; |
| 302 | |
| 303 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 304 | |
| 305 | |
| 306 | /* for generating RESET_REQ */ |
| 307 | template L1ctlUlMessage t_L1ctlResetReq(template L1ctlResetType rst_type) := { |
| 308 | header := t_L1ctlHeader(L1CTL_RESET_REQ), |
| 309 | ul_info := omit, |
| 310 | payload := { |
| 311 | reset_req := { |
| 312 | reset_type := rst_type, |
| 313 | padding := '000000'O |
| 314 | } |
| 315 | } |
| 316 | }; |
| 317 | |
| 318 | /* for generating FBSB_REQ */ |
| 319 | template L1ctlUlMessage t_L1CTL_FBSB_REQ(template Arfcn arfcn, template L1ctlFbsbFlags flags, uint8_t sync_info_idx, L1ctlCcchMode ccch_mode, GsmRxLev rxlev_exp) := { |
| 320 | header := t_L1ctlHeader(L1CTL_FBSB_REQ), |
| 321 | ul_info := omit, |
| 322 | payload := { |
| 323 | fbsb_req := { |
| 324 | arfcn := arfcn, |
| 325 | timeout_tdma_frames := 10, |
| 326 | freq_err_thresh1 := 10000, |
| 327 | freq_err_thresh2 := 800, |
| 328 | num_freqerr_avg := 3, |
| 329 | flags := flags, |
| 330 | sync_info_idx := sync_info_idx, |
| 331 | ccch_mode := ccch_mode, |
| 332 | rxlev_exp := rxlev_exp |
| 333 | } |
| 334 | } |
| 335 | }; |
| 336 | |
| 337 | /* for matching against incoming FBSB_CONF */ |
| 338 | template L1ctlDlMessage t_L1CTL_FBSB_CONF(template uint8_t result) := { |
| 339 | header := t_L1ctlHeader(L1CTL_FBSB_CONF), |
| 340 | dl_info := ?, |
| 341 | payload := { |
| 342 | fbsb_conf := { |
| 343 | initial_freq_err := ?, |
| 344 | result := result, |
| 345 | bsic := ? |
| 346 | } |
| 347 | } |
| 348 | }; |
| 349 | |
| 350 | template L1ctlUlMessage t_L1CTL_RACH_REQ(uint8_t ra, uint8_t combined, uint16_t offset) := { |
| 351 | header := t_L1ctlHeader(L1CTL_RACH_REQ), |
| 352 | ul_info := { |
| 353 | chan_nr := t_RslChanNr_RACH(0), |
| 354 | link_id := ts_RslLinkID_DCCH(0), |
| 355 | padding := '0000'O |
| 356 | }, |
| 357 | payload := { |
| 358 | rach_req := { |
| 359 | ra := ra, |
| 360 | combined := combined, |
| 361 | offset := offset |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | template L1ctlUlMessage t_L1CTL_DM_EST_REQ(Arfcn arfcn, RslChannelNr chan_nr, GsmTsc tsc) := { |
| 367 | header := t_L1ctlHeader(L1CTL_DM_EST_REQ), |
| 368 | ul_info := { |
| 369 | chan_nr := chan_nr, |
| 370 | link_id := ts_RslLinkID_DCCH(0), |
| 371 | padding := '0000'O |
| 372 | }, |
| 373 | payload := { |
| 374 | dm_est_req := { |
| 375 | tsc := tsc, |
| 376 | h := 0, |
| 377 | arfcn := arfcn, |
| 378 | hopping := omit, |
| 379 | tch_mode := 0, |
| 380 | audio_mode := t_L1CTL_AudioModeNone |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | template L1ctlUlMessage t_L1CTL_DM_REL_REQ(RslChannelNr chan_nr) := { |
Harald Welte | 143edbd | 2017-07-17 20:55:42 +0200 | [diff] [blame] | 386 | header := t_L1ctlHeader(L1CTL_DM_REL_REQ), |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 387 | ul_info := { |
| 388 | chan_nr := chan_nr, |
| 389 | link_id := ts_RslLinkID_DCCH(0), |
| 390 | padding := '0000'O |
| 391 | }, |
| 392 | payload := { |
| 393 | other := ''O |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | template L1ctlUlMessage t_L1CTL_DATA_REQ(template RslChannelNr chan_nr, template RslLinkId link_id, octetstring l2_data) := { |
| 398 | header := t_L1ctlHeader(L1CTL_DATA_REQ), |
| 399 | ul_info := { |
| 400 | chan_nr := chan_nr, |
| 401 | link_id := link_id, |
| 402 | padding := '0000'O |
| 403 | }, |
| 404 | payload := { |
| 405 | other := l2_data |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* for matching against incoming RACH_CONF */ |
| 410 | template L1ctlDlMessage t_L1CTL_RACH_CONF := { |
| 411 | header := t_L1ctlHeader(L1CTL_RACH_CONF), |
| 412 | dl_info := ?, |
| 413 | payload := ? |
| 414 | }; |
| 415 | |
| 416 | /* for matching against incoming RACH_CONF */ |
| 417 | template L1ctlDlMessage t_L1CTL_DATA_IND(template RslChannelNr chan_nr) := { |
| 418 | header := t_L1ctlHeader(L1CTL_DATA_IND), |
| 419 | dl_info := { |
| 420 | chan_nr := chan_nr, |
| 421 | link_id := ?, |
| 422 | arfcn := ?, |
| 423 | frame_nr := ?, |
| 424 | rx_level := ?, |
| 425 | snr := ?, |
| 426 | num_biterr := ?, |
| 427 | fire_crc := ? |
| 428 | }, |
| 429 | payload := { |
| 430 | data_ind := ? |
| 431 | } |
| 432 | }; |
| 433 | |
| 434 | template GsmRrMessage t_RR_IMM_ASS(uint8_t ra, uint8_t fn) := { |
| 435 | header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?), |
| 436 | payload := { |
| 437 | imm_ass := { |
| 438 | ded_or_tbf := ?, |
| 439 | page_mode := ?, |
| 440 | chan_desc := ?, |
| 441 | pkt_chan_desc := omit, |
| 442 | req_ref := f_compute_ReqRef(ra, fn), |
| 443 | timing_advance := ?, |
| 444 | mobile_allocation := ? |
| 445 | } |
| 446 | } |
| 447 | }; |
| 448 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 449 | } with { encode "RAW" }; |