Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 1 | /* LAPDm definitiona according to 3GPP TS 44.006 */ |
| 2 | /* (C) 2017 bh Harald Welte <laforge@gnumonks.org> */ |
| 3 | module LAPDm_Types { |
| 4 | |
| 5 | import from General_Types all; |
| 6 | import from Osmocom_Types all; |
| 7 | |
| 8 | type uint3_t LapdmSapi; |
| 9 | type BIT2 LapdmSBits; |
| 10 | type BIT3 LapdmUBits; |
| 11 | type BIT2 LapdmU2Bits; |
| 12 | |
| 13 | type record LapdmLengthIndicator { |
| 14 | uint6_t len, |
| 15 | boolean m, |
| 16 | uint1_t el |
| 17 | } with { variant "" }; |
| 18 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame^] | 19 | template LapdmLengthIndicator t_LapdmLengthIndicator(template uint6_t len, boolean m := false) := { |
| 20 | len := len, |
| 21 | m := m, |
| 22 | el := 1 |
| 23 | }; |
| 24 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 25 | /* TS 44.006 Figure 4 */ |
| 26 | type record LapdmAddressField { |
| 27 | BIT1 spare, |
| 28 | uint2_t lpd (0), |
| 29 | LapdmSapi sapi, |
| 30 | boolean c_r, |
| 31 | boolean ea |
| 32 | } with { variant "" }; |
| 33 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame^] | 34 | template LapdmAddressField tr_LapdmAddr(template LapdmSapi sapi, template boolean c_r) := { |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 35 | spare := '0'B, |
| 36 | lpd := 0, |
| 37 | sapi := sapi, |
| 38 | c_r := c_r, |
| 39 | ea := true |
| 40 | }; |
| 41 | |
| 42 | type record LapdmCtrlI { |
| 43 | uint3_t n_r, |
| 44 | boolean p, |
| 45 | uint3_t n_s, |
| 46 | BIT1 spare ('0'B) |
| 47 | } with { variant "" }; |
| 48 | |
| 49 | type record LapdmCtrlS { |
| 50 | uint3_t n_r, |
| 51 | boolean p_f, |
| 52 | LapdmSBits s, |
| 53 | BIT2 spare ('01'B) |
| 54 | } with { variant "" }; |
| 55 | |
| 56 | type record LapdmCtrlU { |
| 57 | LapdmUBits u, |
| 58 | boolean p_f, |
| 59 | LapdmU2Bits u2, |
| 60 | BIT2 spare ('11'B) |
| 61 | } with { variant "" }; |
| 62 | |
| 63 | /* TS 44.006 Table 3 */ |
| 64 | type union LapdmCtrl { |
| 65 | LapdmCtrlI i, |
| 66 | LapdmCtrlS s, |
| 67 | LapdmCtrlU u |
| 68 | } with { variant "TAG(i, spare = '0'B; |
| 69 | s, spare = '01'B; |
| 70 | u, spare = '11'B)" }; |
| 71 | |
| 72 | template LapdmCtrl t_LapdmCtrlS := { |
| 73 | s := { n_r := ?, p_f := ?, s:= ?, spare := '01'B } |
| 74 | }; |
| 75 | |
| 76 | template LapdmCtrl t_LapdmCtrlU := { |
| 77 | u := { u := ?, p_f := ?, u2 := ?, spare := '11'B } |
| 78 | }; |
| 79 | |
| 80 | /* TS 44.006 Table 4 */ |
| 81 | template LapdmCtrl t_LapdmCtrlI(template uint3_t nr, template uint3_t ns, template boolean p) := { |
| 82 | i := { n_r := nr, p := p, n_s := ns, spare := '0'B } |
| 83 | }; |
| 84 | |
| 85 | template LapdmCtrl t_LapdmCtrlRR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
| 86 | s := { n_r := nr, p_f := pf, s := '00'B } |
| 87 | }; |
| 88 | |
| 89 | template LapdmCtrl t_LapdmCtrlRNR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
| 90 | s := { n_r := nr, p_f := pf, s := '01'B } |
| 91 | }; |
| 92 | |
| 93 | template LapdmCtrl t_LapdmCtrlREJ(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
| 94 | s := { n_r := nr, p_f := pf, s := '10'B } |
| 95 | }; |
| 96 | |
| 97 | template LapdmCtrl t_LapdmCtrlSABM(template boolean p) modifies t_LapdmCtrlU := { |
| 98 | u := { u := '001'B, p_f := p, u2 := '11'B } |
| 99 | }; |
| 100 | |
| 101 | template LapdmCtrl t_LapdmCtrlDM(template boolean f) modifies t_LapdmCtrlU := { |
| 102 | u := { u := '000'B, p_f := f, u2 := '11'B } |
| 103 | }; |
| 104 | |
| 105 | template LapdmCtrl t_LapdmCtrlUI(template boolean p) modifies t_LapdmCtrlU := { |
| 106 | u := { u := '000'B, p_f := p, u2 := '00'B } |
| 107 | }; |
| 108 | |
| 109 | template LapdmCtrl t_LapdmCtrlDISC(template boolean p) modifies t_LapdmCtrlU := { |
| 110 | u := { u := '010'B, p_f := p, u2 := '00'B } |
| 111 | }; |
| 112 | |
| 113 | template LapdmCtrl t_LapdmCtrlUA(template boolean f) modifies t_LapdmCtrlU := { |
| 114 | u := { u := '011'B, p_f := f, u2 := '00'B } |
| 115 | }; |
| 116 | |
| 117 | /* Format A is used on DCCHs for frames where there is no information field */ |
| 118 | type record LapdmFrameA { |
| 119 | LapdmAddressField addr, |
| 120 | LapdmCtrl ctrl, |
| 121 | LapdmLengthIndicator len |
| 122 | } with { variant "" }; |
| 123 | |
| 124 | external function enc_LapdmFrameA(in LapdmFrameA si) return octetstring |
| 125 | with { extension "prototype(convert) encode(RAW)" }; |
| 126 | external function dec_LapdmFrameA(in octetstring stream) return LapdmFrameA |
| 127 | with { extension "prototype(convert) decode(RAW)" }; |
| 128 | |
| 129 | /* Formats B, Bter and B4 are used on DCCHs for frames containing an information field: |
| 130 | /* - format Bter is used on request of higher layers if and only if short L2 header type 1 is |
| 131 | * supported and a UI command is to be transmitted on SAPI 0 */ |
| 132 | /* - format B4 is used for UI frames transmitted by the network on SACCH; */ |
| 133 | /* - format B is applied in all other cases. */ |
| 134 | /* Format Bbis is used only on BCCH, PCH, NCH, and AGCH. |
| 135 | |
| 136 | /* Format B */ |
| 137 | type record LapdmFrameB { |
| 138 | LapdmAddressField addr, |
| 139 | LapdmCtrl ctrl, |
| 140 | LapdmLengthIndicator len, |
| 141 | octetstring payload |
| 142 | } with { variant "" }; |
| 143 | |
| 144 | external function enc_LapdmFrameB(in LapdmFrameB si) return octetstring |
| 145 | with { extension "prototype(convert) encode(RAW)" }; |
| 146 | external function dec_LapdmFrameB(in octetstring stream) return LapdmFrameB |
| 147 | with { extension "prototype(convert) decode(RAW)" }; |
| 148 | |
| 149 | |
| 150 | /* Format B4 */ |
| 151 | type record LapdmFrameB4 { |
| 152 | LapdmAddressField addr, |
| 153 | LapdmCtrl ctrl, |
| 154 | octetstring payload |
| 155 | } with { variant "" }; |
| 156 | |
| 157 | external function enc_LapdmFrameB4(in LapdmFrameB4 si) return octetstring |
| 158 | with { extension "prototype(convert) encode(RAW)" }; |
| 159 | external function dec_LapdmFrameB4(in octetstring stream) return LapdmFrameB4 |
| 160 | with { extension "prototype(convert) decode(RAW)" }; |
| 161 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame^] | 162 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |