blob: 66e7b9da464f75797bd3a1d699db3c9ffe813d39 [file] [log] [blame]
Harald Weltef6543322017-07-16 07:35:10 +02001/* 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 */
4module 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,
Harald Welte00d4dac2017-07-30 00:50:32 +020041 L1CTL_TRAFFIC_IND,
42 L1CTL_TBF_CFG_REQ,
43 L1CTL_TBF_CFG_CONF
Harald Weltef6543322017-07-16 07:35:10 +020044 } with { variant "FIELDLENGTH(8)" };
45
46 type enumerated L1ctlCcchMode {
47 CCCH_MODE_NONE (0),
48 CCCH_MODE_NON_COMBINED,
49 CCCH_MODE_COMBINED
50 } with { variant "FIELDLENGTH(8)" };
51
52 type enumerated L1ctlNeighMode {
53 NEIGH_MODE_NONE (0),
54 NEIGH_MODE_PM,
55 NEIGH_MODE_SB
56 } with { variant "FIELDLENGTH(8)" };
57
58 type enumerated L1ctlResetType {
59 L1CTL_RES_T_BOOT (0),
60 L1CTL_RES_T_FULL,
61 L1CTL_RES_T_SCHED
62 } with { variant "FIELDLENGTH(8)" };
63
64 const integer TRAFFIC_DATA_LEN := 40;
65
66 type record L1ctlHdrFlags {
67 BIT7 padding,
68 boolean f_done
69 } with { variant "" };
70
71 type record L1ctlHeader {
72 L1ctlMsgType msg_type,
73 L1ctlHdrFlags flags,
74 OCT2 padding
75 } with { variant "" };
76
Harald Welte52c713c2017-07-16 15:44:44 +020077 template L1ctlHeader t_L1ctlHeader(template L1ctlMsgType msg_type) := {
78 msg_type := msg_type,
79 flags := { padding := '0000000'B, f_done := false },
80 padding := '0000'O
81 };
82
Harald Weltef6543322017-07-16 07:35:10 +020083 type record L1ctlDlInfo {
Harald Welte8e4db2c2017-07-16 18:54:55 +020084 RslChannelNr chan_nr,
Harald Weltef6543322017-07-16 07:35:10 +020085 RslLinkId link_id,
86 Arfcn arfcn,
Harald Welte5f0d5c82017-07-16 18:56:01 +020087 uint32_t frame_nr,
Harald Weltef6543322017-07-16 07:35:10 +020088 GsmRxLev rx_level,
89 uint8_t snr,
90 uint8_t num_biterr,
91 uint8_t fire_crc
92 } with { variant "" };
93
94 type record L1ctlFbsbConf {
95 int16_t initial_freq_err,
96 uint8_t result,
97 uint8_t bsic
98 } with { variant "" };
99
100 type record L1ctlCcchModeConf {
101 L1ctlCcchMode ccch_mode,
102 OCT3 padding
103 } with { variant "" };
104
105 /* gsm48_chan_mode */
106 type uint8_t L1ctlTchMode;
107
108 type record L1ctlAudioMode {
109 BIT4 padding,
110 boolean tx_microphone,
111 boolean tx_traffic_req,
112 boolean rx_speaker,
113 boolean rx_traffic_ind
114 } with { variant "" };
115
Harald Welte66110f02017-07-16 21:05:18 +0200116 template L1ctlAudioMode t_L1CTL_AudioModeNone := { '0000'B, false, false, false, false };
117
Harald Weltef6543322017-07-16 07:35:10 +0200118 type record L1ctlTchModeConf {
119 L1ctlTchMode tch_mode,
120 L1ctlAudioMode audio_mode,
121 OCT2 padding
122 } with { variant "" };
123
124 type record L1ctlDataInd {
125 octetstring payload length(23)
126 } with { variant "" };
127
128 type union L1ctlDlPayload {
129 L1ctlFbsbConf fbsb_conf,
130 L1ctlCcchModeConf ccch_mode_conf,
131 L1ctlTchModeConf tch_mode_conf,
132 L1ctlDataInd data_ind,
133 L1ctlTrafficReq traffic_ind,
Harald Welte00d4dac2017-07-30 00:50:32 +0200134 L1ctlTbfCfgReq tbf_cfg_conf,
Harald Weltef6543322017-07-16 07:35:10 +0200135 octetstring other
136 } with { variant "" };
137
138 type record L1ctlDlMessage {
139 L1ctlHeader header,
140 L1ctlDlInfo dl_info optional,
141 L1ctlDlPayload payload
142 } with { variant (dl_info) "PRESENCE(header.msg_type = L1CTL_FBSB_CONF,
143 header.msg_type = L1CTL_RACH_CONF,
144 header.msg_type = L1CTL_DATA_IND,
145 header.msg_type = L1CTL_DATA_CONF,
146 header.msg_type = L1CTL_TRAFFIC_IND)"
147 variant (payload) "CROSSTAG(fbsb_conf, header.msg_type = L1CTL_FBSB_CONF;
148 ccch_mode_conf, header.msg_type = L1CTL_CCCH_MODE_CONF;
149 tch_mode_conf, header.msg_type = L1CTL_TCH_MODE_CONF;
150 data_ind, header.msg_type = L1CTL_DATA_IND;
151 traffic_ind, header.msg_type = L1CTL_TRAFFIC_IND;
Harald Welte00d4dac2017-07-30 00:50:32 +0200152 tbf_cfg_conf, header.msg_type = L1CTL_TBF_CFG_CONF;
Harald Weltef6543322017-07-16 07:35:10 +0200153 other, OTHERWISE;
154 )" };
155
156 external function enc_L1ctlDlMessage(in L1ctlDlMessage msg) return octetstring
157 with { extension "prototype(convert) encode(RAW)" };
158 external function dec_L1ctlDlMessage(in octetstring stream) return L1ctlDlMessage
159 with { extension "prototype(convert) decode(RAW)" };
160
161
162 type record L1ctlUlInfo {
Harald Welte8e4db2c2017-07-16 18:54:55 +0200163 RslChannelNr chan_nr,
Harald Weltef6543322017-07-16 07:35:10 +0200164 RslLinkId link_id,
165 OCT2 padding
166 } with { variant "" };
167
168 type record L1ctlFbsbFlags {
169 BIT5 padding,
170 boolean sb,
171 boolean fb1,
172 boolean fb0
173 } with { variant "" };
174
Harald Welte66110f02017-07-16 21:05:18 +0200175 template L1ctlFbsbFlags t_L1CTL_FBSB_F_ALL := {
176 padding := '00000'B,
177 sb := true,
178 fb1 := true,
179 fb0 := true
180 };
181
Harald Weltef6543322017-07-16 07:35:10 +0200182 type record L1ctlFbsbReq {
183 Arfcn arfcn,
184 uint16_t timeout_tdma_frames,
185 uint16_t freq_err_thresh1,
186 uint16_t freq_err_thresh2,
187 uint8_t num_freqerr_avg,
188 L1ctlFbsbFlags flags,
189 uint8_t sync_info_idx,
190 L1ctlCcchMode ccch_mode,
191 GsmRxLev rxlev_exp
192 } with { variant "" };
193
194 type record L1ctlCcchModeReq {
195 L1ctlTchMode tch_mode,
196 L1ctlAudioMode audio_mode,
197 OCT2 padding
198 } with { variant "" };
199
200 type record L1ctlTchModeReq {
201 L1ctlTchMode tch_mode,
202 L1ctlAudioMode audio_mode,
203 OCT2 padding
204 } with { variant "" };
205
206 type record L1ctlRachReq {
207 uint8_t ra,
208 uint8_t combined,
209 uint16_t offset
210 } with { variant "" };
211
212 type record L1ctlParReq {
213 int8_t ta,
214 uint8_t tx_power,
215 OCT2 padding
216 } with { variant "" };
217
218 type record L1ctlH1 {
219 uint8_t hsn,
220 uint8_t maio,
221 uint8_t n,
222 OCT1 padding,
223 bitstring ma length(64)
224 } with { variant "" };
225
226 type record L1ctlDmEstReq {
227 GsmTsc tsc,
228 uint8_t h,
229 Arfcn arfcn optional,
230 L1ctlH1 hopping optional,
231 L1ctlTchMode tch_mode,
232 L1ctlAudioMode audio_mode
233 } with { variant (arfcn) "PRESENCE(h = 0)"
234 variant (hopping) "PRESENCE(h = 1)" };
235
236 type record L1ctlReset {
237 L1ctlResetType reset_type,
238 OCT3 padding
239 } with { variant "" };
240
241
242 type record L1ctlTrafficReq {
243 octetstring data length(TRAFFIC_DATA_LEN)
244 } with { variant "" };
245
Harald Welte00d4dac2017-07-30 00:50:32 +0200246 type record length(8) of uint8_t TfiUsfArr;
247
248 type record L1ctlTbfCfgReq {
249 uint8_t tbf_nr,
250 boolean is_uplink,
251 OCT2 padding,
252 TfiUsfArr tfi_usf
253 } with { variant (is_uplink) "FIELDLENGTH(8)" };
254
Harald Weltef6543322017-07-16 07:35:10 +0200255 type union L1ctlUlPayload {
256 L1ctlFbsbReq fbsb_req,
257 L1ctlCcchModeReq ccch_mode_req,
258 L1ctlTchModeReq tch_mode_req,
259 L1ctlRachReq rach_req,
260 L1ctlParReq par_req,
261 L1ctlDmEstReq dm_est_req,
262 L1ctlReset reset_req,
263 //L1ctlNeighPmReq neigh_pm_req,
264 L1ctlTrafficReq traffic_req,
Harald Welte00d4dac2017-07-30 00:50:32 +0200265 L1ctlTbfCfgReq tbf_cfg_req,
Harald Weltef6543322017-07-16 07:35:10 +0200266 octetstring other
267 } with { variant "" };
268
269 type record L1ctlUlMessage {
270 L1ctlHeader header,
271 L1ctlUlInfo ul_info optional,
272 L1ctlUlPayload payload
273 } with { variant (ul_info) "PRESENCE(header.msg_type = L1CTL_RACH_REQ,
274 header.msg_type = L1CTL_PARAM_REQ,
275 header.msg_type = L1CTL_CRYPTO_REQ,
276 header.msg_type = L1CTL_DATA_REQ,
277 header.msg_type = L1CTL_DM_EST_REQ,
278 header.msg_type = L1CTL_DM_FREQ_REQ,
279 header.msg_type = L1CTL_DM_REL_REQ,
280 header.msg_type = L1CTL_TRAFFIC_REQ)"
281 variant (payload) "CROSSTAG(fbsb_req, header.msg_type = L1CTL_FBSB_REQ;
282 ccch_mode_req, header.msg_type = L1CTL_CCCH_MODE_REQ;
283 tch_mode_req, header.msg_type = L1CTL_TCH_MODE_REQ;
284 rach_req, header.msg_type = L1CTL_RACH_REQ;
285 par_req, header.msg_type = L1CTL_PARAM_REQ;
286 dm_est_req, header.msg_type = L1CTL_DM_EST_REQ;
287 reset_req, header.msg_type = L1CTL_RESET_REQ;
288 traffic_req, header.msg_type = L1CTL_TRAFFIC_REQ;
Harald Welte00d4dac2017-07-30 00:50:32 +0200289 tbf_cfg_req, header.msg_type = L1CTL_TBF_CFG_REQ;
Harald Weltef6543322017-07-16 07:35:10 +0200290 other, OTHERWISE;
291 )" };
292
293 external function enc_L1ctlUlMessage(in L1ctlUlMessage msg) return octetstring
294 with { extension "prototype(convert) encode(RAW)" };
295 external function dec_L1ctlUlMessage(in octetstring stream) return L1ctlUlMessage
296 with { extension "prototype(convert) decode(RAW)" };
297
Harald Welte52c713c2017-07-16 15:44:44 +0200298 type record L1ctlUlMessageLV {
299 uint16_t len,
300 L1ctlUlMessage msg
301 } with { variant (len) "LENGTHTO(msg)" };
302
303 external function enc_L1ctlUlMessageLV(in L1ctlUlMessageLV msg) return octetstring
304 with { extension "prototype(convert) encode(RAW)" };
305 external function dec_L1ctlUlMessageLV(in octetstring stream) return L1ctlUlMessageLV
306 with { extension "prototype(convert) decode(RAW)" };
307
308 type record L1ctlDlMessageLV {
309 uint16_t len,
310 L1ctlDlMessage msg
311 } with { variant (len) "LENGTHTO(msg)" };
312
313 external function enc_L1ctlDlMessageLV(in L1ctlDlMessageLV msg) return octetstring
314 with { extension "prototype(convert) encode(RAW)" };
315 external function dec_L1ctlDlMessageLV(in octetstring stream) return L1ctlDlMessageLV
316 with { extension "prototype(convert) decode(RAW)" };
317
318
Harald Welte9e4725d2017-07-16 23:18:09 +0200319
320
321 /* for generating RESET_REQ */
322 template L1ctlUlMessage t_L1ctlResetReq(template L1ctlResetType rst_type) := {
323 header := t_L1ctlHeader(L1CTL_RESET_REQ),
324 ul_info := omit,
325 payload := {
326 reset_req := {
327 reset_type := rst_type,
328 padding := '000000'O
329 }
330 }
331 };
332
333 /* for generating FBSB_REQ */
334 template L1ctlUlMessage t_L1CTL_FBSB_REQ(template Arfcn arfcn, template L1ctlFbsbFlags flags, uint8_t sync_info_idx, L1ctlCcchMode ccch_mode, GsmRxLev rxlev_exp) := {
335 header := t_L1ctlHeader(L1CTL_FBSB_REQ),
336 ul_info := omit,
337 payload := {
338 fbsb_req := {
339 arfcn := arfcn,
340 timeout_tdma_frames := 10,
341 freq_err_thresh1 := 10000,
342 freq_err_thresh2 := 800,
343 num_freqerr_avg := 3,
344 flags := flags,
345 sync_info_idx := sync_info_idx,
346 ccch_mode := ccch_mode,
347 rxlev_exp := rxlev_exp
348 }
349 }
350 };
351
352 /* for matching against incoming FBSB_CONF */
353 template L1ctlDlMessage t_L1CTL_FBSB_CONF(template uint8_t result) := {
354 header := t_L1ctlHeader(L1CTL_FBSB_CONF),
355 dl_info := ?,
356 payload := {
357 fbsb_conf := {
358 initial_freq_err := ?,
359 result := result,
360 bsic := ?
361 }
362 }
363 };
364
365 template L1ctlUlMessage t_L1CTL_RACH_REQ(uint8_t ra, uint8_t combined, uint16_t offset) := {
366 header := t_L1ctlHeader(L1CTL_RACH_REQ),
367 ul_info := {
368 chan_nr := t_RslChanNr_RACH(0),
369 link_id := ts_RslLinkID_DCCH(0),
370 padding := '0000'O
371 },
372 payload := {
373 rach_req := {
374 ra := ra,
375 combined := combined,
376 offset := offset
377 }
378 }
379 }
380
381 template L1ctlUlMessage t_L1CTL_DM_EST_REQ(Arfcn arfcn, RslChannelNr chan_nr, GsmTsc tsc) := {
382 header := t_L1ctlHeader(L1CTL_DM_EST_REQ),
383 ul_info := {
384 chan_nr := chan_nr,
385 link_id := ts_RslLinkID_DCCH(0),
386 padding := '0000'O
387 },
388 payload := {
389 dm_est_req := {
390 tsc := tsc,
391 h := 0,
392 arfcn := arfcn,
393 hopping := omit,
394 tch_mode := 0,
395 audio_mode := t_L1CTL_AudioModeNone
396 }
397 }
398 }
399
400 template L1ctlUlMessage t_L1CTL_DM_REL_REQ(RslChannelNr chan_nr) := {
Harald Welte143edbd2017-07-17 20:55:42 +0200401 header := t_L1ctlHeader(L1CTL_DM_REL_REQ),
Harald Welte9e4725d2017-07-16 23:18:09 +0200402 ul_info := {
403 chan_nr := chan_nr,
404 link_id := ts_RslLinkID_DCCH(0),
405 padding := '0000'O
406 },
407 payload := {
408 other := ''O
409 }
410 }
411
412 template L1ctlUlMessage t_L1CTL_DATA_REQ(template RslChannelNr chan_nr, template RslLinkId link_id, octetstring l2_data) := {
413 header := t_L1ctlHeader(L1CTL_DATA_REQ),
414 ul_info := {
415 chan_nr := chan_nr,
416 link_id := link_id,
417 padding := '0000'O
418 },
419 payload := {
420 other := l2_data
421 }
422 }
423
Harald Welte00d4dac2017-07-30 00:50:32 +0200424 template L1ctlUlMessage t_L1CTL_TBF_CFG_REQ(boolean is_uplink, TfiUsfArr tfi_usf) := {
425 header := t_L1ctlHeader(L1CTL_TBF_CFG_REQ),
426 ul_info := omit,
427 payload := {
428 tbf_cfg_req := {
429 tbf_nr := 0,
430 is_uplink := is_uplink,
431 padding := '0000'O,
432 tfi_usf := tfi_usf
433 }
434 }
435 };
436
437 template L1ctlDlMessage t_L1CTL_TBF_CFG_CONF(template boolean is_uplink) := {
438 header := t_L1ctlHeader(L1CTL_TBF_CFG_CONF),
439 dl_info := omit,
440 payload := {
441 tbf_cfg_conf := {
442 tbf_nr := 0,
443 is_uplink := is_uplink,
444 padding := ?,
445 tfi_usf := ?
446 }
447 }
448 };
449
Harald Welte9e4725d2017-07-16 23:18:09 +0200450 /* for matching against incoming RACH_CONF */
451 template L1ctlDlMessage t_L1CTL_RACH_CONF := {
452 header := t_L1ctlHeader(L1CTL_RACH_CONF),
453 dl_info := ?,
454 payload := ?
455 };
456
457 /* for matching against incoming RACH_CONF */
458 template L1ctlDlMessage t_L1CTL_DATA_IND(template RslChannelNr chan_nr) := {
459 header := t_L1ctlHeader(L1CTL_DATA_IND),
460 dl_info := {
461 chan_nr := chan_nr,
462 link_id := ?,
463 arfcn := ?,
464 frame_nr := ?,
465 rx_level := ?,
466 snr := ?,
467 num_biterr := ?,
468 fire_crc := ?
469 },
470 payload := {
471 data_ind := ?
472 }
473 };
474
475 template GsmRrMessage t_RR_IMM_ASS(uint8_t ra, uint8_t fn) := {
476 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
477 payload := {
478 imm_ass := {
479 ded_or_tbf := ?,
480 page_mode := ?,
Harald Welted335cbc2017-07-30 00:51:23 +0200481 chan_desc := *,
482 pkt_chan_desc := *,
Harald Welte9e4725d2017-07-16 23:18:09 +0200483 req_ref := f_compute_ReqRef(ra, fn),
484 timing_advance := ?,
485 mobile_allocation := ?
486 }
487 }
488 };
489
Harald Weltef6543322017-07-16 07:35:10 +0200490} with { encode "RAW" };