blob: cb3f3f2c27edfaa2ce9c1955ca04095bd699f483 [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 Weltec2a5c072017-07-17 20:58:32 +0200119 u := { u2 := '01'B, p_f := f, u := '011'B }
Harald Weltef6543322017-07-16 07:35:10 +0200120 };
121
122 /* Format A is used on DCCHs for frames where there is no information field */
123 type record LapdmFrameA {
124 LapdmAddressField addr,
125 LapdmCtrl ctrl,
126 LapdmLengthIndicator len
127 } with { variant "" };
128
129 external function enc_LapdmFrameA(in LapdmFrameA si) return octetstring
130 with { extension "prototype(convert) encode(RAW)" };
131 external function dec_LapdmFrameA(in octetstring stream) return LapdmFrameA
132 with { extension "prototype(convert) decode(RAW)" };
133
134 /* Formats B, Bter and B4 are used on DCCHs for frames containing an information field:
135 /* - format Bter is used on request of higher layers if and only if short L2 header type 1 is
136 * supported and a UI command is to be transmitted on SAPI 0 */
137 /* - format B4 is used for UI frames transmitted by the network on SACCH; */
138 /* - format B is applied in all other cases. */
139 /* Format Bbis is used only on BCCH, PCH, NCH, and AGCH.
140
141 /* Format B */
142 type record LapdmFrameB {
143 LapdmAddressField addr,
144 LapdmCtrl ctrl,
145 LapdmLengthIndicator len,
146 octetstring payload
147 } with { variant "" };
148
149 external function enc_LapdmFrameB(in LapdmFrameB si) return octetstring
150 with { extension "prototype(convert) encode(RAW)" };
151 external function dec_LapdmFrameB(in octetstring stream) return LapdmFrameB
152 with { extension "prototype(convert) decode(RAW)" };
153
154
155 /* Format B4 */
156 type record LapdmFrameB4 {
157 LapdmAddressField addr,
158 LapdmCtrl ctrl,
159 octetstring payload
160 } with { variant "" };
161
162 external function enc_LapdmFrameB4(in LapdmFrameB4 si) return octetstring
163 with { extension "prototype(convert) encode(RAW)" };
164 external function dec_LapdmFrameB4(in octetstring stream) return LapdmFrameB4
165 with { extension "prototype(convert) decode(RAW)" };
166
Harald Weltec2a5c072017-07-17 20:58:32 +0200167 type record LapdmFrameBbis {
168 octetstring payload
169 } with { variant "" };
170
171 external function enc_LapdmFrameBbis(in LapdmFrameBbis si) return octetstring
172 with { extension "prototype(convert) encode(RAW)" };
173 external function dec_LapdmFrameBbis(in octetstring stream) return LapdmFrameBbis
174 with { extension "prototype(convert) decode(RAW)" };
175
176 type union LapdmFrame {
177 LapdmFrameA a,
178 LapdmFrameB b,
179 LapdmFrameBbis bbis,
180 LapdmFrameB4 b4
181 } with { variant "" };
182
183 external function enc_LapdmFrame(in LapdmFrame si) return octetstring
184 with { extension "prototype(convert) encode(RAW)" };
185 /* automatic decoding to the generic LapdmFrame will not work, you have to call one of the
186 * type-specific decoder routines above */
187
188} with { encode "RAW"; /*variant "FIELDORDER(msb)" */}