blob: ed2ca6f9ee0799c3494327c9779cd055deadcecc [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* LLC Templates in TTCN-3
2 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
3 * All rights reserved.
4 *
5 * Released under the terms of GNU General Public License, Version 2 or
6 * (at your option) any later version.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11
Harald Welte5ac31492018-02-15 20:39:13 +010012module LLC_Templates {
13
14import from LLC_Types all;
15import from Osmocom_Types all;
16import from General_Types all;
17
18template Address_field t_LLC_Addr(template BIT4 sapi, template BIT1 cr, template BIT1 pd := '0'B) := {
19 sAPI := sapi,
20 spare := '00'B,
21 cR := cr,
22 pD := '0'B
23}
Harald Weltef7a5c3c2019-04-23 22:00:00 +020024template (value) Address_field ts_LLC_Addr(template (value) BIT4 sapi,
25 template (value) BIT1 cr,
26 template (value) BIT1 pd := '0'B) := {
27 sAPI := sapi,
28 spare := '00'B,
29 cR := cr,
30 pD := '0'B
31}
Harald Welte5ac31492018-02-15 20:39:13 +010032
33template (value) Control_field_UI ts_LLC_CtrlUI(uint9_t n_u, boolean encrypted := false,
34 boolean protected := false) := {
35 format := '110'B,
36 spare := '00'B,
37 nU := n_u,
38 e := bool2bit(encrypted),
39 pM := bool2bit(protected)
40}
41
Harald Weltef7a5c3c2019-04-23 22:00:00 +020042template (value) Control_field_U ts_LLC_CtrlU(template (value) BIT4 m_bits, template (value) BIT1 p_f) := {
Harald Welte37692d82018-02-18 15:21:34 +010043 mBits := m_bits,
44 pF := p_f,
45 format := '111'B
46}
47
Harald Welte5ac31492018-02-15 20:39:13 +010048template Control_field_UI tr_LLC_CtrlUI(template uint9_t n_u,
49 template boolean encrypted := ?,
50 template boolean protected := ?) := {
51 format := '110'B,
52 spare := '00'B,
53 nU := n_u,
54 e := bool2bit_tmpl(encrypted),
55 pM := bool2bit_tmpl(protected)
56}
57
Harald Welte37692d82018-02-18 15:21:34 +010058template Control_field_U tr_LLC_CtrlU(template BIT4 m_bits := ?,
59 template BIT1 p_f := ?) := {
60 mBits := m_bits,
61 pF := p_f,
62 format := '111'B
63}
64
65
Harald Welte5ac31492018-02-15 20:39:13 +010066template PDU_LLC ts_LLC_UI(octetstring payload, BIT4 sapi, BIT1 cr, uint9_t n_u,
67 boolean encrypted := false, boolean protected := false) := {
68 pDU_LLC_UI := {
Harald Weltef7a5c3c2019-04-23 22:00:00 +020069 address_field := ts_LLC_Addr(sapi, cr),
Harald Welte5ac31492018-02-15 20:39:13 +010070 control_field := ts_LLC_CtrlUI(n_u, encrypted, protected),
71 information_field_UI := payload,
72 fCS := omit /* causes encoder to generate FCS */
73 }
74}
75
76template PDU_LLC tr_LLC_UI(template octetstring payload := ?, template BIT4 sapi := ?,
77 template BIT1 cr := ?, template uint9_t n_u := ?,
78 template boolean encrypted := ?, template boolean protected := ?) := {
79 pDU_LLC_UI := {
80 address_field := t_LLC_Addr(sapi, cr),
81 control_field := tr_LLC_CtrlUI(n_u, encrypted, protected),
82 information_field_UI := payload,
83 fCS := '000000'O /* provided by decoder if FCS OK */
84 }
85}
86
Harald Welte37692d82018-02-18 15:21:34 +010087template PDU_LLC tr_LLC_XID(template XID_Information xid, template BIT4 sapi := ?,
88 template BIT1 cr := ?, template BIT1 p_f := ?) := {
89 pDU_LLC_U := {
90 address_field := t_LLC_Addr(sapi, cr),
91 control_field := tr_LLC_CtrlU('1011'B, p_f),
92 information_field_U := {
93 xID := xid
94 },
95 fCS := '000000'O /* provided by decoder if FCS OK */
96 }
97}
Harald Welted21f6a22019-05-02 09:50:34 +020098template PDU_LLC tr_LLC_XID_MO_CMD(template XID_Information xid, template BIT4 sapi) :=
99 tr_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B);
100template PDU_LLC tr_LLC_XID_MO_RSP(template XID_Information xid, template BIT4 sapi) :=
101 tr_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B);
102template PDU_LLC tr_LLC_XID_MT_CMD(template XID_Information xid, template BIT4 sapi) :=
103 tr_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B);
104template PDU_LLC tr_LLC_XID_MT_RSP(template XID_Information xid, template BIT4 sapi) :=
105 tr_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B);
106template (value) PDU_LLC ts_LLC_XID(template (value) XID_Information xid,
107 template (value) BIT4 sapi,
108 template (value) BIT1 cr,
109 template (value) BIT1 p_f) := {
110 pDU_LLC_U := {
111 address_field := ts_LLC_Addr(sapi, cr),
112 control_field := ts_LLC_CtrlU('1011'B, p_f),
113 information_field_U := {
114 xID := xid
115 },
116 fCS := omit /* causes encoder to generate FCS */
117 }
118}
119
120template (value) PDU_LLC ts_LLC_XID_MO_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) :=
121 ts_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B);
122template (value) PDU_LLC ts_LLC_XID_MO_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) :=
123 ts_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B);
124template (value) PDU_LLC ts_LLC_XID_MT_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) :=
125 ts_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B);
126template (value) PDU_LLC ts_LLC_XID_MT_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) :=
127 ts_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B);
128
Harald Welte37692d82018-02-18 15:21:34 +0100129
Harald Weltef7a5c3c2019-04-23 22:00:00 +0200130template PDU_LLC tr_LLC_U(template BIT4 m_bits, template BIT1 p_f, template Information_field_U u,
131 template BIT4 sapi, template BIT1 cr) := {
132 pDU_LLC_U := {
133 address_field := t_LLC_Addr(sapi, cr),
134 control_field := tr_LLC_CtrlU(m_bits, p_f),
135 information_field_U := u,
136 fCS := '000000'O /* provided by decoder if FCS OK */
137 }
138}
139template (value) PDU_LLC ts_LLC_U(template (value) BIT4 m_bits, template (value) BIT1 p_f,
140 template (value) Information_field_U u,
141 template (value) BIT4 sapi, template (value) BIT1 cr) := {
142 pDU_LLC_U := {
143 address_field := ts_LLC_Addr(sapi, cr),
144 control_field := ts_LLC_CtrlU(m_bits, p_f),
145 information_field_U := u,
146 fCS := omit /* causes encoder to generate FCS */
147 }
148}
149
150template PDU_LLC tr_LLC_SABM(template SABM_Information sabm_xid, template BIT1 p_f,
151 template BIT4 sapi, template BIT1 cr) :=
152 tr_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr);
153template (value) PDU_LLC ts_LLC_SABM(template (value) SABM_Information sabm_xid,
154 template (value) BIT1 p_f,
155 template (value) BIT4 sapi, template (value) BIT1 cr) :=
156 ts_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr);
157
158template PDU_LLC tr_LLC_UA(template UA_Information ua_xid, template BIT1 p_f,
159 template BIT4 sapi, template BIT1 cr) :=
160 tr_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr);
161template (value) PDU_LLC ts_LLC_UA(template (value) UA_Information ua_xid,
162 template (value) BIT1 p_f,
163 template (value) BIT4 sapi, template (value) BIT1 cr) :=
164 ts_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr);
165
166template PDU_LLC tr_LLC_FRMR(template FRMR_Information frmr, template BIT1 p_f,
167 template BIT4 sapi, template BIT1 cr) :=
168 tr_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr);
169template (value) PDU_LLC ts_LLC_FRMR(template (value) FRMR_Information frmr,
170 template (value) BIT1 p_f,
171 template (value) BIT4 sapi, template (value) BIT1 cr) :=
172 ts_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr);
173
174template PDU_LLC tr_LLC_DM(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
175 tr_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr);
176template (value) PDU_LLC ts_LLC_DM(template (value) BIT1 p_f, template (value) BIT4 sapi,
177 template (value) BIT1 cr) :=
178 ts_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr);
Harald Welte37692d82018-02-18 15:21:34 +0100179
Harald Welteceaff262019-04-23 22:18:05 +0200180template PDU_LLC tr_LLC_NULL(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
181 tr_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr);
182template (value) PDU_LLC ts_LLC_NULL(template (value) BIT1 p_f, template (value) BIT4 sapi,
183 template (value) BIT1 cr) :=
184 ts_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr);
185
186template PDU_LLC tr_LLC_DISC(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
187 tr_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr);
188template (value) PDU_LLC ts_LLC_DISC(template (value) BIT1 p_f, template (value) BIT4 sapi,
189 template (value) BIT1 cr) :=
190 ts_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr);
191
192
Harald Welte5ac31492018-02-15 20:39:13 +0100193const BIT4 c_LLC_SAPI_LLGMM := '0001'B;
194const BIT4 c_LLC_SAPI_TOM2 := '0010'B;
195const BIT4 c_LLC_SAPI_LL3 := '0011'B;
196const BIT4 c_LLC_SAPI_LL5 := '0101'B;
197const BIT4 c_LLC_SAPI_LLSMS := '0111'B;
198const BIT4 c_LLC_SAPI_TOM8 := '1000'B;
199const BIT4 c_LLC_SAPI_LL9 := '1001'B;
Harald Welte5ac31492018-02-15 20:39:13 +0100200const BIT4 c_LLC_SAPI_LL11 := '1011'B;
201
202const BIT1 LLC_CR_DL_CMD := '1'B;
203const BIT1 LLC_CR_DL_RSP := '0'B;
204const BIT1 LLC_CR_UL_CMD := '0'B;
205const BIT1 LLC_CR_UL_RSP := '1'B;
206
207/* LLC UI frame with SAPI for L3 payload */
Harald Welted4719012018-02-17 16:45:06 +0100208template PDU_LLC tr_LLC_UI_L3 := ( tr_LLC_UI(?, c_LLC_SAPI_LLGMM) );
Harald Welte5ac31492018-02-15 20:39:13 +0100209
Harald Weltea2526a82018-02-18 19:03:36 +0100210/* LLC UI frame with SAPI for User payload */
211template PDU_LLC tr_LLC_UI_USER := tr_LLC_UI(?, (c_LLC_SAPI_LL3,
212 c_LLC_SAPI_LL5,
213 c_LLC_SAPI_LL9,
214 c_LLC_SAPI_LL11)
215 );
216
Harald Welte5ac31492018-02-15 20:39:13 +0100217
Harald Welted21f6a22019-05-02 09:50:34 +0200218template XID tr_XID(template XID_Data xd := ?) := {
219 xl := ?,
220 typefield := ?,
221 xID_length := ?,
222 xID_Data := xd
223};
224template (value) XID ts_XID(template (value) BIT5 tf, template (value) XID_Data xd) := {
225 xl := '0'B,
226 typefield := tf,
227 xID_length := {
228 short_len := 0
229 },
230 xID_Data := xd
231};
232
233template XID tr_XID_kU(template uint8_t ku) := tr_XID({kU := ku});
234template (value) XID ts_XID_kU(template (value) uint8_t ku) := ts_XID('01010'B, {kU := ku});
235
236template XID tr_XID_kD(template uint8_t kd) := tr_XID({kD := kd});
237template (value) XID ts_XID_kD(template (value) uint8_t kd) := ts_XID('01001'B, {kD := kd});
238
239template XID tr_XID_mD(template uint15_t md) := tr_XID({mD := {spare := '0'B, mDValue := md}});
240template (value) XID ts_XID_mD(template (value) uint15_t md) := ts_XID('00111'B, {mD := { spare := '0'B, mDValue := md}});
241
242template XID tr_XID_mU(template uint15_t mu) := tr_XID({mU := {spare := '0'B, mUValue := mu}});
243template (value) XID ts_XID_mU(template (value) uint15_t mu) := ts_XID('01000'B, {mU := { spare := '0'B, mUValue := mu}});
244
245template XID tr_XID_N201I(template uint11_t n201i) :=
246 tr_XID({n201_I := {spare := '00000'B, n201IValue := n201i}});
247template (value) XID ts_XID_N201I(template (value) uint11_t n201i) :=
248 ts_XID('00110'B, {n201_I := { spare := '00000'B, n201IValue := n201i}});
249
250template XID tr_XID_N201U(template uint11_t n201u) :=
251 tr_XID({n201_U := {spare := '00000'B, n201UValue := n201u}});
252template (value) XID ts_XID_N201U(template (value) uint11_t n201u) :=
253 ts_XID('00101'B, {n201_U := { spare := '00000'B, n201UValue := n201u}});
254
255template XID tr_XID_N200(template uint4_t n200) :=
256 tr_XID({n200 := { retransmissions := n200, spare := '0000'B}});
257template (value) XID ts_XID_N200(template (value) uint4_t n200) :=
258 ts_XID('00100'B, {n200 := { retransmissions := n200, spare := '0000'B}});
259
260template XID tr_XID_T200(template uint12_t t200) :=
261 tr_XID({t200 := { spare := '0000'B, t200Value := t200}});
262template (value) XID ts_XID_T200(template (value) uint12_t t200) :=
263 ts_XID('00011'B, {t200 := { spare := '0000'B, t200Value := t200}});
264
265template XID tr_XID_version(template uint4_t v) :=
266 tr_XID({version := {version_value := v, spare := '0000'B}});
267template (value) XID ts_XID_version(template (value) uint4_t v) :=
268 ts_XID('00000'B, {version := {version_value := v, spare := '0000'B}});
269
270template XID tr_XID_IOV_UI(template OCT4 iov) := tr_XID({iOV_UI := iov});
271template (value) XID ts_XID_IOV_UI(template (value) OCT4 iov) := ts_XID('00001'B, {iOV_UI := iov});
272
273template XID tr_XID_IOV_I(template OCT4 iov) := tr_XID({iOV_I := iov});
274template (value) XID ts_XID_IOV_I(template (value) OCT4 iov) := ts_XID('00010'B, {iOV_I := iov});
275
276template XID tr_XID_L3(template octetstring l3) := tr_XID({l3param := l3});
277template (value) XID ts_XID_L3(template (value) octetstring l3) := ts_XID('01011'B, {l3param := l3});
278
279template XID tr_XID_RESET := tr_XID({reset := ''O});
280template (value) XID ts_XID_RESET := ts_XID('01100'B, {reset := ''O});
281
282
Harald Welte5ac31492018-02-15 20:39:13 +0100283}