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 |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 17 | } with { variant "FIELDORDER(msb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 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, |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 28 | uint2_t lpd, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 29 | LapdmSapi sapi, |
| 30 | boolean c_r, |
| 31 | boolean ea |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 32 | } with { variant "FIELDORDER(msb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 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 { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 43 | BIT1 spare, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 44 | uint3_t n_s, |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 45 | boolean p, |
| 46 | uint3_t n_r |
| 47 | } with { variant "FIELDORDER(lsb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 48 | |
| 49 | type record LapdmCtrlS { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 50 | BIT2 spare, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 51 | LapdmSBits s, |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 52 | boolean p_f, |
| 53 | uint3_t n_r |
| 54 | } with { variant "FIELDORDER(lsb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 55 | |
| 56 | type record LapdmCtrlU { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 57 | BIT2 spare, |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 58 | LapdmU2Bits u2, |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 59 | boolean p_f, |
| 60 | LapdmUBits u |
| 61 | } with { variant "FIELDORDER(lsb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 62 | |
| 63 | /* TS 44.006 Table 3 */ |
| 64 | type union LapdmCtrl { |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 65 | LapdmCtrlS s, |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 66 | LapdmCtrlU u, |
| 67 | LapdmCtrlI i, |
| 68 | uint8_t other |
| 69 | } with { variant "TAG(u, spare = '11'B; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 70 | s, spare = '01'B; |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 71 | i, spare = '0'B; |
| 72 | other, OTHERWISE)" }; |
| 73 | /* )" }; */ |
| 74 | |
| 75 | /* TS 44.006 Table 4 */ |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 76 | |
| 77 | template LapdmCtrl t_LapdmCtrlS := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 78 | s := { spare := '01'B, s := ?, p_f := ?, n_r := ? } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | template LapdmCtrl t_LapdmCtrlU := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 82 | u := { spare := '11'B, u2 := ?, p_f := ?, u := ? } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* TS 44.006 Table 4 */ |
| 86 | template LapdmCtrl t_LapdmCtrlI(template uint3_t nr, template uint3_t ns, template boolean p) := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 87 | i := { spare := '0'B, n_s := ns, p := p, n_r := nr } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | template LapdmCtrl t_LapdmCtrlRR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 91 | s := { s:= '00'B, p_f := pf, n_r := nr } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | template LapdmCtrl t_LapdmCtrlRNR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 95 | s := { s:= '01'B, p_f := pf, n_r := nr } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | template LapdmCtrl t_LapdmCtrlREJ(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 99 | s := { s:= '10'B, p_f := pf, n_r := nr } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | template LapdmCtrl t_LapdmCtrlSABM(template boolean p) modifies t_LapdmCtrlU := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 103 | u := { u2 := '11'B, p_f := p, u := '001'B } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | template LapdmCtrl t_LapdmCtrlDM(template boolean f) modifies t_LapdmCtrlU := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 107 | u := { u2 := '11'B, p_f := f, u := '000'B } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | template LapdmCtrl t_LapdmCtrlUI(template boolean p) modifies t_LapdmCtrlU := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 111 | u := { u2 := '00'B, p_f := p, u := '000'B } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | template LapdmCtrl t_LapdmCtrlDISC(template boolean p) modifies t_LapdmCtrlU := { |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 115 | u := { u2 := '00'B, p_f := p, u := '010'B } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | template LapdmCtrl t_LapdmCtrlUA(template boolean f) modifies t_LapdmCtrlU := { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 119 | u := { u2 := '00'B, p_f := f, u := '011'B } |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
Harald Welte | 1bd7c32 | 2017-07-17 20:59:46 +0200 | [diff] [blame] | 122 | external function dec_LapdmAddressField(in octetstring stream) return LapdmAddressField |
| 123 | with { extension "prototype(convert) decode(RAW)" }; |
| 124 | |
| 125 | external function dec_LapdmCtrl(in octetstring stream) return LapdmCtrl |
| 126 | with { extension "prototype(convert) decode(RAW)" }; |
| 127 | |
| 128 | external function dec_LapdmCtrlU(in octetstring stream) return LapdmCtrlU |
| 129 | with { extension "prototype(convert) decode(RAW)" }; |
| 130 | |
| 131 | external function dec_LapdmLengthIndicator(in octetstring stream) return LapdmLengthIndicator |
| 132 | with { extension "prototype(convert) decode(RAW)" }; |
| 133 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 134 | /* Format A is used on DCCHs for frames where there is no information field */ |
| 135 | type record LapdmFrameA { |
| 136 | LapdmAddressField addr, |
| 137 | LapdmCtrl ctrl, |
| 138 | LapdmLengthIndicator len |
| 139 | } with { variant "" }; |
| 140 | |
| 141 | external function enc_LapdmFrameA(in LapdmFrameA si) return octetstring |
| 142 | with { extension "prototype(convert) encode(RAW)" }; |
| 143 | external function dec_LapdmFrameA(in octetstring stream) return LapdmFrameA |
| 144 | with { extension "prototype(convert) decode(RAW)" }; |
| 145 | |
| 146 | /* Formats B, Bter and B4 are used on DCCHs for frames containing an information field: |
| 147 | /* - format Bter is used on request of higher layers if and only if short L2 header type 1 is |
| 148 | * supported and a UI command is to be transmitted on SAPI 0 */ |
| 149 | /* - format B4 is used for UI frames transmitted by the network on SACCH; */ |
| 150 | /* - format B is applied in all other cases. */ |
| 151 | /* Format Bbis is used only on BCCH, PCH, NCH, and AGCH. |
| 152 | |
| 153 | /* Format B */ |
| 154 | type record LapdmFrameB { |
| 155 | LapdmAddressField addr, |
| 156 | LapdmCtrl ctrl, |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 157 | uint6_t len, |
| 158 | boolean m, |
| 159 | uint1_t el (1), |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 160 | octetstring payload |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 161 | } with { variant (len) "LENGTHTO(payload)" |
| 162 | variant "FIELDORDER(msb)" }; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 163 | |
| 164 | external function enc_LapdmFrameB(in LapdmFrameB si) return octetstring |
| 165 | with { extension "prototype(convert) encode(RAW)" }; |
| 166 | external function dec_LapdmFrameB(in octetstring stream) return LapdmFrameB |
| 167 | with { extension "prototype(convert) decode(RAW)" }; |
| 168 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 169 | /* Format B4 */ |
| 170 | type record LapdmFrameB4 { |
| 171 | LapdmAddressField addr, |
| 172 | LapdmCtrl ctrl, |
| 173 | octetstring payload |
| 174 | } with { variant "" }; |
| 175 | |
| 176 | external function enc_LapdmFrameB4(in LapdmFrameB4 si) return octetstring |
| 177 | with { extension "prototype(convert) encode(RAW)" }; |
| 178 | external function dec_LapdmFrameB4(in octetstring stream) return LapdmFrameB4 |
| 179 | with { extension "prototype(convert) decode(RAW)" }; |
| 180 | |
Harald Welte | c2a5c07 | 2017-07-17 20:58:32 +0200 | [diff] [blame] | 181 | type record LapdmFrameBbis { |
| 182 | octetstring payload |
| 183 | } with { variant "" }; |
| 184 | |
| 185 | external function enc_LapdmFrameBbis(in LapdmFrameBbis si) return octetstring |
| 186 | with { extension "prototype(convert) encode(RAW)" }; |
| 187 | external function dec_LapdmFrameBbis(in octetstring stream) return LapdmFrameBbis |
| 188 | with { extension "prototype(convert) decode(RAW)" }; |
| 189 | |
| 190 | type union LapdmFrame { |
| 191 | LapdmFrameA a, |
| 192 | LapdmFrameB b, |
| 193 | LapdmFrameBbis bbis, |
| 194 | LapdmFrameB4 b4 |
| 195 | } with { variant "" }; |
| 196 | |
| 197 | external function enc_LapdmFrame(in LapdmFrame si) return octetstring |
| 198 | with { extension "prototype(convert) encode(RAW)" }; |
| 199 | /* automatic decoding to the generic LapdmFrame will not work, you have to call one of the |
| 200 | * type-specific decoder routines above */ |
| 201 | |
| 202 | } with { encode "RAW"; /*variant "FIELDORDER(msb)" */} |