blob: 988e015b21eea8f2bdc47249039388b87ed3cb90 [file] [log] [blame]
Harald Weltef6543322017-07-16 07:35:10 +02001/* LAPDm definitiona according to 3GPP TS 44.006 */
2/* (C) 2017 bh Harald Welte <laforge@gnumonks.org> */
3module 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 Weltec2a5c072017-07-17 20:58:32 +020017 } with { variant "FIELDORDER(msb)" };
Harald Weltef6543322017-07-16 07:35:10 +020018
Harald Welte9e4725d2017-07-16 23:18:09 +020019 template LapdmLengthIndicator t_LapdmLengthIndicator(template uint6_t len, boolean m := false) := {
20 len := len,
21 m := m,
22 el := 1
23 };
24
Harald Weltef6543322017-07-16 07:35:10 +020025 /* TS 44.006 Figure 4 */
26 type record LapdmAddressField {
27 BIT1 spare,
Harald Weltec2a5c072017-07-17 20:58:32 +020028 uint2_t lpd,
Harald Weltef6543322017-07-16 07:35:10 +020029 LapdmSapi sapi,
30 boolean c_r,
31 boolean ea
Harald Weltec2a5c072017-07-17 20:58:32 +020032 } with { variant "FIELDORDER(msb)" };
Harald Weltef6543322017-07-16 07:35:10 +020033
Harald Welte9e4725d2017-07-16 23:18:09 +020034 template LapdmAddressField tr_LapdmAddr(template LapdmSapi sapi, template boolean c_r) := {
Harald Weltef6543322017-07-16 07:35:10 +020035 spare := '0'B,
36 lpd := 0,
37 sapi := sapi,
38 c_r := c_r,
39 ea := true
40 };
41
42 type record LapdmCtrlI {
Harald Weltec2a5c072017-07-17 20:58:32 +020043 BIT1 spare,
Harald Weltef6543322017-07-16 07:35:10 +020044 uint3_t n_s,
Harald Weltec2a5c072017-07-17 20:58:32 +020045 boolean p,
46 uint3_t n_r
47 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020048
49 type record LapdmCtrlS {
Harald Weltec2a5c072017-07-17 20:58:32 +020050 BIT2 spare,
Harald Weltef6543322017-07-16 07:35:10 +020051 LapdmSBits s,
Harald Weltec2a5c072017-07-17 20:58:32 +020052 boolean p_f,
53 uint3_t n_r
54 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020055
56 type record LapdmCtrlU {
Harald Weltec2a5c072017-07-17 20:58:32 +020057 BIT2 spare,
Harald Weltef6543322017-07-16 07:35:10 +020058 LapdmU2Bits u2,
Harald Weltec2a5c072017-07-17 20:58:32 +020059 boolean p_f,
60 LapdmUBits u
61 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020062
63 /* TS 44.006 Table 3 */
64 type union LapdmCtrl {
Harald Weltef6543322017-07-16 07:35:10 +020065 LapdmCtrlS s,
Harald Weltec2a5c072017-07-17 20:58:32 +020066 LapdmCtrlU u,
67 LapdmCtrlI i,
68 uint8_t other
69 } with { variant "TAG(u, spare = '11'B;
Harald Weltef6543322017-07-16 07:35:10 +020070 s, spare = '01'B;
Harald Weltec2a5c072017-07-17 20:58:32 +020071 i, spare = '0'B;
72 other, OTHERWISE)" };
73 /* )" }; */
74
75 /* TS 44.006 Table 4 */
Harald Weltef6543322017-07-16 07:35:10 +020076
77 template LapdmCtrl t_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020078 s := { spare := '01'B, s := ?, p_f := ?, n_r := ? }
Harald Weltef6543322017-07-16 07:35:10 +020079 };
80
81 template LapdmCtrl t_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +020082 u := { spare := '11'B, u2 := ?, p_f := ?, u := ? }
Harald Weltef6543322017-07-16 07:35:10 +020083 };
84
85 /* TS 44.006 Table 4 */
86 template LapdmCtrl t_LapdmCtrlI(template uint3_t nr, template uint3_t ns, template boolean p) := {
Harald Weltec2a5c072017-07-17 20:58:32 +020087 i := { spare := '0'B, n_s := ns, p := p, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020088 };
89
90 template LapdmCtrl t_LapdmCtrlRR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020091 s := { s:= '00'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020092 };
93
94 template LapdmCtrl t_LapdmCtrlRNR(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020095 s := { s:= '01'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020096 };
97
98 template LapdmCtrl t_LapdmCtrlREJ(template uint3_t nr, template boolean pf) modifies t_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020099 s := { s:= '10'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +0200100 };
101
102 template LapdmCtrl t_LapdmCtrlSABM(template boolean p) modifies t_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200103 u := { u2 := '11'B, p_f := p, u := '001'B }
Harald Weltef6543322017-07-16 07:35:10 +0200104 };
105
106 template LapdmCtrl t_LapdmCtrlDM(template boolean f) modifies t_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200107 u := { u2 := '11'B, p_f := f, u := '000'B }
Harald Weltef6543322017-07-16 07:35:10 +0200108 };
109
110 template LapdmCtrl t_LapdmCtrlUI(template boolean p) modifies t_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200111 u := { u2 := '00'B, p_f := p, u := '000'B }
Harald Weltef6543322017-07-16 07:35:10 +0200112 };
113
114 template LapdmCtrl t_LapdmCtrlDISC(template boolean p) modifies t_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200115 u := { u2 := '00'B, p_f := p, u := '010'B }
Harald Weltef6543322017-07-16 07:35:10 +0200116 };
117
118 template LapdmCtrl t_LapdmCtrlUA(template boolean f) modifies t_LapdmCtrlU := {
Harald Welted4ba7ff2017-07-17 21:00:48 +0200119 u := { u2 := '00'B, p_f := f, u := '011'B }
Harald Weltef6543322017-07-16 07:35:10 +0200120 };
121
Harald Welte1bd7c322017-07-17 20:59:46 +0200122 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 Weltef6543322017-07-16 07:35:10 +0200134 /* 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 Welted4ba7ff2017-07-17 21:00:48 +0200157 uint6_t len,
158 boolean m,
159 uint1_t el (1),
Harald Weltef6543322017-07-16 07:35:10 +0200160 octetstring payload
Harald Welted4ba7ff2017-07-17 21:00:48 +0200161 } with { variant (len) "LENGTHTO(payload)"
162 variant "FIELDORDER(msb)" };
Harald Weltef6543322017-07-16 07:35:10 +0200163
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 Weltef6543322017-07-16 07:35:10 +0200169 /* 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 Weltec2a5c072017-07-17 20:58:32 +0200181 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)" */}