blob: 91f55fabb7d2b77b5a41f667c195254bf510654c [file] [log] [blame]
Harald Weltef6543322017-07-16 07:35:10 +02001/* LAPDm definitiona according to 3GPP TS 44.006 */
Harald Welted879bd92018-03-12 15:01:23 +01002/* (C) 2017-2018 bh Harald Welte <laforge@gnumonks.org> */
Harald Weltef6543322017-07-16 07:35:10 +02003module 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
Harald Weltef6543322017-07-16 07:35:10 +020013 /* TS 44.006 Figure 4 */
14 type record LapdmAddressField {
15 BIT1 spare,
Harald Weltec2a5c072017-07-17 20:58:32 +020016 uint2_t lpd,
Harald Weltef6543322017-07-16 07:35:10 +020017 LapdmSapi sapi,
18 boolean c_r,
19 boolean ea
Harald Weltec2a5c072017-07-17 20:58:32 +020020 } with { variant "FIELDORDER(msb)" };
Harald Weltef6543322017-07-16 07:35:10 +020021
Harald Welte9e4725d2017-07-16 23:18:09 +020022 template LapdmAddressField tr_LapdmAddr(template LapdmSapi sapi, template boolean c_r) := {
Harald Weltef6543322017-07-16 07:35:10 +020023 spare := '0'B,
24 lpd := 0,
25 sapi := sapi,
26 c_r := c_r,
27 ea := true
28 };
29
Harald Welted879bd92018-03-12 15:01:23 +010030 template (value) LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
31 spare := '0'B,
32 lpd := 0,
33 sapi := sapi,
34 c_r := c_r,
35 ea := true
36 };
37
Harald Weltef6543322017-07-16 07:35:10 +020038 type record LapdmCtrlI {
Harald Welteffcad682017-07-30 22:51:04 +020039 BIT1 spare ('0'B),
Harald Weltef6543322017-07-16 07:35:10 +020040 uint3_t n_s,
Harald Weltec2a5c072017-07-17 20:58:32 +020041 boolean p,
42 uint3_t n_r
43 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020044
45 type record LapdmCtrlS {
Harald Welteffcad682017-07-30 22:51:04 +020046 BIT2 spare ('01'B),
Harald Weltef6543322017-07-16 07:35:10 +020047 LapdmSBits s,
Harald Weltec2a5c072017-07-17 20:58:32 +020048 boolean p_f,
49 uint3_t n_r
50 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020051
52 type record LapdmCtrlU {
Harald Welteffcad682017-07-30 22:51:04 +020053 BIT2 spare ('11'B),
Harald Weltef6543322017-07-16 07:35:10 +020054 LapdmU2Bits u2,
Harald Weltec2a5c072017-07-17 20:58:32 +020055 boolean p_f,
56 LapdmUBits u
57 } with { variant "FIELDORDER(lsb)" };
Harald Weltef6543322017-07-16 07:35:10 +020058
59 /* TS 44.006 Table 3 */
60 type union LapdmCtrl {
Harald Weltef6543322017-07-16 07:35:10 +020061 LapdmCtrlS s,
Harald Weltec2a5c072017-07-17 20:58:32 +020062 LapdmCtrlU u,
63 LapdmCtrlI i,
64 uint8_t other
65 } with { variant "TAG(u, spare = '11'B;
Harald Weltef6543322017-07-16 07:35:10 +020066 s, spare = '01'B;
Harald Weltec2a5c072017-07-17 20:58:32 +020067 i, spare = '0'B;
68 other, OTHERWISE)" };
69 /* )" }; */
70
71 /* TS 44.006 Table 4 */
Harald Weltef6543322017-07-16 07:35:10 +020072
Harald Welted879bd92018-03-12 15:01:23 +010073 template LapdmCtrl tr_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020074 s := { spare := '01'B, s := ?, p_f := ?, n_r := ? }
Harald Weltef6543322017-07-16 07:35:10 +020075 };
76
Harald Welted879bd92018-03-12 15:01:23 +010077 template LapdmCtrl tr_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +020078 u := { spare := '11'B, u2 := ?, p_f := ?, u := ? }
Harald Weltef6543322017-07-16 07:35:10 +020079 };
80
81 /* TS 44.006 Table 4 */
Harald Welted879bd92018-03-12 15:01:23 +010082 template LapdmCtrl tr_LapdmCtrlI(template uint3_t nr, template uint3_t ns, template boolean p) := {
Harald Weltec2a5c072017-07-17 20:58:32 +020083 i := { spare := '0'B, n_s := ns, p := p, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020084 };
85
Harald Welted879bd92018-03-12 15:01:23 +010086 template LapdmCtrl tr_LapdmCtrlRR(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020087 s := { s:= '00'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020088 };
89
Harald Welted879bd92018-03-12 15:01:23 +010090 template LapdmCtrl tr_LapdmCtrlRNR(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020091 s := { s:= '01'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020092 };
93
Harald Welted879bd92018-03-12 15:01:23 +010094 template LapdmCtrl tr_LapdmCtrlREJ(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
Harald Weltec2a5c072017-07-17 20:58:32 +020095 s := { s:= '10'B, p_f := pf, n_r := nr }
Harald Weltef6543322017-07-16 07:35:10 +020096 };
97
Harald Welted879bd92018-03-12 15:01:23 +010098 template LapdmCtrl tr_LapdmCtrlSABM(template boolean p) modifies tr_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +020099 u := { u2 := '11'B, p_f := p, u := '001'B }
Harald Weltef6543322017-07-16 07:35:10 +0200100 };
Harald Welted879bd92018-03-12 15:01:23 +0100101 template (value) LapdmCtrl ts_LapdmCtrlSABM(boolean p) := {
102 u := { spare := '11'B, u2 := '11'B, p_f := p, u := '001'B }
103 };
Harald Weltef6543322017-07-16 07:35:10 +0200104
Harald Welted879bd92018-03-12 15:01:23 +0100105 template LapdmCtrl tr_LapdmCtrlDM(template boolean f) modifies tr_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200106 u := { u2 := '11'B, p_f := f, u := '000'B }
Harald Weltef6543322017-07-16 07:35:10 +0200107 };
108
Harald Welted879bd92018-03-12 15:01:23 +0100109 template LapdmCtrl tr_LapdmCtrlUI(template boolean p) modifies tr_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200110 u := { u2 := '00'B, p_f := p, u := '000'B }
Harald Weltef6543322017-07-16 07:35:10 +0200111 };
Harald Welted879bd92018-03-12 15:01:23 +0100112 template (value) LapdmCtrl ts_LapdmCtrlUI(boolean p) := {
113 u := { spare := '11'B, u2 := '00'B, p_f := p, u := '000'B }
114 };
Harald Weltef6543322017-07-16 07:35:10 +0200115
Harald Welted879bd92018-03-12 15:01:23 +0100116 template LapdmCtrl tr_LapdmCtrlDISC(template boolean p) modifies tr_LapdmCtrlU := {
Harald Weltec2a5c072017-07-17 20:58:32 +0200117 u := { u2 := '00'B, p_f := p, u := '010'B }
Harald Weltef6543322017-07-16 07:35:10 +0200118 };
Harald Welted879bd92018-03-12 15:01:23 +0100119 template LapdmCtrl ts_LapdmCtrlDISC(boolean p) := {
120 u := { spare := '11'B, u2 := '00'B, p_f := p, u := '010'B }
121 };
Harald Weltef6543322017-07-16 07:35:10 +0200122
Harald Welted879bd92018-03-12 15:01:23 +0100123 template LapdmCtrl tr_LapdmCtrlUA(template boolean f) modifies tr_LapdmCtrlU := {
Harald Welted4ba7ff2017-07-17 21:00:48 +0200124 u := { u2 := '00'B, p_f := f, u := '011'B }
Harald Weltef6543322017-07-16 07:35:10 +0200125 };
Harald Welted879bd92018-03-12 15:01:23 +0100126 template (value) LapdmCtrl ts_LapdmCtrlUA(boolean f) := {
127 u := { spare := '11'B, u2 := '00'B, p_f := f, u := '011'B }
128 };
129
130
Harald Weltef6543322017-07-16 07:35:10 +0200131
Harald Welte1bd7c322017-07-17 20:59:46 +0200132 external function dec_LapdmAddressField(in octetstring stream) return LapdmAddressField
133 with { extension "prototype(convert) decode(RAW)" };
134
135 external function dec_LapdmCtrl(in octetstring stream) return LapdmCtrl
136 with { extension "prototype(convert) decode(RAW)" };
137
138 external function dec_LapdmCtrlU(in octetstring stream) return LapdmCtrlU
139 with { extension "prototype(convert) decode(RAW)" };
140
Harald Weltef6543322017-07-16 07:35:10 +0200141 /* Formats B, Bter and B4 are used on DCCHs for frames containing an information field:
142 /* - format Bter is used on request of higher layers if and only if short L2 header type 1 is
143 * supported and a UI command is to be transmitted on SAPI 0 */
144 /* - format B4 is used for UI frames transmitted by the network on SACCH; */
145 /* - format B is applied in all other cases. */
146 /* Format Bbis is used only on BCCH, PCH, NCH, and AGCH.
147
148 /* Format B */
Harald Welted879bd92018-03-12 15:01:23 +0100149 type record LapdmFrameAB {
Harald Weltef6543322017-07-16 07:35:10 +0200150 LapdmAddressField addr,
151 LapdmCtrl ctrl,
Harald Welted879bd92018-03-12 15:01:23 +0100152 uint6_t len,
Harald Welted4ba7ff2017-07-17 21:00:48 +0200153 boolean m,
Harald Welted879bd92018-03-12 15:01:23 +0100154 uint1_t el,
155 octetstring payload /* zero-length in Frame A */
Harald Welted4ba7ff2017-07-17 21:00:48 +0200156 } with { variant (len) "LENGTHTO(payload)"
157 variant "FIELDORDER(msb)" };
Harald Weltef6543322017-07-16 07:35:10 +0200158
Harald Welted879bd92018-03-12 15:01:23 +0100159 external function enc_LapdmFrameAB(in LapdmFrameAB si) return octetstring
Harald Weltef6543322017-07-16 07:35:10 +0200160 with { extension "prototype(convert) encode(RAW)" };
Harald Welted879bd92018-03-12 15:01:23 +0100161 external function dec_LapdmFrameAB(in octetstring stream) return LapdmFrameAB
Harald Weltef6543322017-07-16 07:35:10 +0200162 with { extension "prototype(convert) decode(RAW)" };
163
Harald Weltef6543322017-07-16 07:35:10 +0200164 /* Format B4 */
165 type record LapdmFrameB4 {
166 LapdmAddressField addr,
167 LapdmCtrl ctrl,
168 octetstring payload
169 } with { variant "" };
170
171 external function enc_LapdmFrameB4(in LapdmFrameB4 si) return octetstring
172 with { extension "prototype(convert) encode(RAW)" };
173 external function dec_LapdmFrameB4(in octetstring stream) return LapdmFrameB4
174 with { extension "prototype(convert) decode(RAW)" };
175
Harald Weltec2a5c072017-07-17 20:58:32 +0200176 type record LapdmFrameBbis {
177 octetstring payload
178 } with { variant "" };
179
180 external function enc_LapdmFrameBbis(in LapdmFrameBbis si) return octetstring
181 with { extension "prototype(convert) encode(RAW)" };
182 external function dec_LapdmFrameBbis(in octetstring stream) return LapdmFrameBbis
183 with { extension "prototype(convert) decode(RAW)" };
184
185 type union LapdmFrame {
Harald Welted879bd92018-03-12 15:01:23 +0100186 LapdmFrameAB ab,
Harald Weltec2a5c072017-07-17 20:58:32 +0200187 LapdmFrameBbis bbis,
188 LapdmFrameB4 b4
189 } with { variant "" };
190
191 external function enc_LapdmFrame(in LapdmFrame si) return octetstring
192 with { extension "prototype(convert) encode(RAW)" };
193 /* automatic decoding to the generic LapdmFrame will not work, you have to call one of the
194 * type-specific decoder routines above */
195
196} with { encode "RAW"; /*variant "FIELDORDER(msb)" */}