aboutsummaryrefslogtreecommitdiffstats
path: root/library/LLC_Templates.ttcn
blob: ed2ca6f9ee0799c3494327c9779cd055deadcecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* LLC Templates in TTCN-3
 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */


module LLC_Templates {

import from LLC_Types all;
import from Osmocom_Types all;
import from General_Types all;

template Address_field t_LLC_Addr(template BIT4 sapi, template BIT1 cr, template BIT1 pd := '0'B) := {
	sAPI := sapi,
	spare := '00'B,
	cR := cr,
	pD := '0'B
}
template (value) Address_field ts_LLC_Addr(template (value) BIT4 sapi,
					   template (value) BIT1 cr,
					   template (value) BIT1 pd := '0'B) := {
	sAPI := sapi,
	spare := '00'B,
	cR := cr,
	pD := '0'B
}

template (value) Control_field_UI ts_LLC_CtrlUI(uint9_t n_u, boolean encrypted := false,
					boolean protected := false) := {
	format := '110'B,
	spare := '00'B,
	nU := n_u,
	e := bool2bit(encrypted),
	pM := bool2bit(protected)
}

template (value) Control_field_U ts_LLC_CtrlU(template (value) BIT4 m_bits, template (value) BIT1 p_f) := {
	mBits := m_bits,
	pF := p_f,
	format := '111'B
}

template Control_field_UI tr_LLC_CtrlUI(template uint9_t n_u,
					template boolean encrypted := ?,
					template boolean protected := ?) := {
	format := '110'B,
	spare := '00'B,
	nU := n_u,
	e := bool2bit_tmpl(encrypted),
	pM := bool2bit_tmpl(protected)
}

template Control_field_U tr_LLC_CtrlU(template BIT4 m_bits := ?,
					template BIT1 p_f := ?) := {
	mBits := m_bits,
	pF := p_f,
	format := '111'B
}


template PDU_LLC ts_LLC_UI(octetstring payload, BIT4 sapi, BIT1 cr, uint9_t n_u,
			   boolean encrypted := false, boolean protected := false) := {
	pDU_LLC_UI := {
		address_field := ts_LLC_Addr(sapi, cr),
		control_field := ts_LLC_CtrlUI(n_u, encrypted, protected),
		information_field_UI := payload,
		fCS := omit /* causes encoder to generate FCS */
	}
}

template PDU_LLC tr_LLC_UI(template octetstring payload := ?, template BIT4 sapi := ?,
			   template BIT1 cr := ?, template uint9_t n_u := ?,
			   template boolean encrypted := ?, template boolean protected := ?) := {
	pDU_LLC_UI := {
		address_field := t_LLC_Addr(sapi, cr),
		control_field := tr_LLC_CtrlUI(n_u, encrypted, protected),
		information_field_UI := payload,
		fCS := '000000'O /* provided by decoder if FCS OK */
	}
}

template PDU_LLC tr_LLC_XID(template XID_Information xid, template BIT4 sapi := ?,
			    template BIT1 cr := ?, template BIT1 p_f := ?) := {
	pDU_LLC_U := {
		address_field := t_LLC_Addr(sapi, cr),
		control_field := tr_LLC_CtrlU('1011'B, p_f),
		information_field_U := {
			xID := xid
		},
		fCS := '000000'O /* provided by decoder if FCS OK */
	}
}
template PDU_LLC tr_LLC_XID_MO_CMD(template XID_Information xid, template BIT4 sapi) :=
	tr_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B);
template PDU_LLC tr_LLC_XID_MO_RSP(template XID_Information xid, template BIT4 sapi) :=
	tr_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B);
template PDU_LLC tr_LLC_XID_MT_CMD(template XID_Information xid, template BIT4 sapi) :=
	tr_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B);
template PDU_LLC tr_LLC_XID_MT_RSP(template XID_Information xid, template BIT4 sapi) :=
	tr_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B);
template (value) PDU_LLC ts_LLC_XID(template (value) XID_Information xid,
				    template (value) BIT4 sapi,
				    template (value) BIT1 cr,
				    template (value) BIT1 p_f) := {
	pDU_LLC_U := {
		address_field := ts_LLC_Addr(sapi, cr),
		control_field := ts_LLC_CtrlU('1011'B, p_f),
		information_field_U := {
			xID := xid
		},
		fCS := omit /* causes encoder to generate FCS */
	}
}

template (value) PDU_LLC ts_LLC_XID_MO_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) :=
	ts_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B);
template (value) PDU_LLC ts_LLC_XID_MO_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) :=
	ts_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B);
template (value) PDU_LLC ts_LLC_XID_MT_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) :=
	ts_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B);
template (value) PDU_LLC ts_LLC_XID_MT_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) :=
	ts_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B);


template PDU_LLC tr_LLC_U(template BIT4 m_bits, template BIT1 p_f, template Information_field_U u,
			  template BIT4 sapi, template BIT1 cr) := {
	pDU_LLC_U := {
		address_field := t_LLC_Addr(sapi, cr),
		control_field := tr_LLC_CtrlU(m_bits, p_f),
		information_field_U := u,
		fCS := '000000'O /* provided by decoder if FCS OK */
	}
}
template (value) PDU_LLC ts_LLC_U(template (value) BIT4 m_bits, template (value) BIT1 p_f,
				  template (value) Information_field_U u,
				  template (value) BIT4 sapi, template (value) BIT1 cr) := {
	pDU_LLC_U := {
		address_field := ts_LLC_Addr(sapi, cr),
		control_field := ts_LLC_CtrlU(m_bits, p_f),
		information_field_U := u,
		fCS := omit /* causes encoder to generate FCS */
	}
}

template PDU_LLC tr_LLC_SABM(template SABM_Information sabm_xid, template BIT1 p_f,
			     template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr);
template (value) PDU_LLC ts_LLC_SABM(template (value) SABM_Information sabm_xid,
				     template (value) BIT1 p_f,
				     template (value) BIT4 sapi, template (value) BIT1 cr) :=
	ts_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr);

template PDU_LLC tr_LLC_UA(template UA_Information ua_xid, template BIT1 p_f,
			   template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr);
template (value) PDU_LLC ts_LLC_UA(template (value) UA_Information ua_xid,
				   template (value) BIT1 p_f,
				   template (value) BIT4 sapi, template (value) BIT1 cr) :=
	ts_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr);

template PDU_LLC tr_LLC_FRMR(template FRMR_Information frmr, template BIT1 p_f,
			     template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr);
template (value) PDU_LLC ts_LLC_FRMR(template (value) FRMR_Information frmr,
				     template (value) BIT1 p_f,
				     template (value) BIT4 sapi, template (value) BIT1 cr) :=
	ts_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr);

template PDU_LLC tr_LLC_DM(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr);
template (value) PDU_LLC ts_LLC_DM(template (value) BIT1 p_f, template (value) BIT4 sapi,
				   template (value) BIT1 cr) :=
	ts_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr);

template PDU_LLC tr_LLC_NULL(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr);
template (value) PDU_LLC ts_LLC_NULL(template (value) BIT1 p_f, template (value) BIT4 sapi,
				     template (value) BIT1 cr) :=
	ts_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr);

template PDU_LLC tr_LLC_DISC(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) :=
	tr_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr);
template (value) PDU_LLC ts_LLC_DISC(template (value) BIT1 p_f, template (value) BIT4 sapi,
				     template (value) BIT1 cr) :=
	ts_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr);


const BIT4 c_LLC_SAPI_LLGMM := '0001'B;
const BIT4 c_LLC_SAPI_TOM2 := '0010'B;
const BIT4 c_LLC_SAPI_LL3 := '0011'B;
const BIT4 c_LLC_SAPI_LL5 := '0101'B;
const BIT4 c_LLC_SAPI_LLSMS := '0111'B;
const BIT4 c_LLC_SAPI_TOM8 := '1000'B;
const BIT4 c_LLC_SAPI_LL9 := '1001'B;
const BIT4 c_LLC_SAPI_LL11 := '1011'B;

const BIT1 LLC_CR_DL_CMD := '1'B;
const BIT1 LLC_CR_DL_RSP := '0'B;
const BIT1 LLC_CR_UL_CMD := '0'B;
const BIT1 LLC_CR_UL_RSP := '1'B;

/* LLC UI frame with SAPI for L3 payload */
template PDU_LLC tr_LLC_UI_L3 := ( tr_LLC_UI(?, c_LLC_SAPI_LLGMM) );

/* LLC UI frame with SAPI for User payload */
template PDU_LLC tr_LLC_UI_USER := tr_LLC_UI(?, (c_LLC_SAPI_LL3,
						 c_LLC_SAPI_LL5,
						 c_LLC_SAPI_LL9,
						 c_LLC_SAPI_LL11)
						);


template XID tr_XID(template XID_Data xd := ?) := {
	xl := ?,
	typefield := ?,
	xID_length := ?,
	xID_Data := xd
};
template (value) XID ts_XID(template (value) BIT5 tf, template (value) XID_Data xd) := {
	xl := '0'B,
	typefield := tf,
	xID_length := {
		short_len := 0
	},
	xID_Data := xd
};

template XID tr_XID_kU(template uint8_t ku) := tr_XID({kU := ku});
template (value) XID ts_XID_kU(template (value) uint8_t ku) := ts_XID('01010'B, {kU := ku});

template XID tr_XID_kD(template uint8_t kd) := tr_XID({kD := kd});
template (value) XID ts_XID_kD(template (value) uint8_t kd) := ts_XID('01001'B, {kD := kd});

template XID tr_XID_mD(template uint15_t md) := tr_XID({mD := {spare := '0'B, mDValue := md}});
template (value) XID ts_XID_mD(template (value) uint15_t md) := ts_XID('00111'B, {mD := { spare := '0'B, mDValue := md}});

template XID tr_XID_mU(template uint15_t mu) := tr_XID({mU := {spare := '0'B, mUValue := mu}});
template (value) XID ts_XID_mU(template (value) uint15_t mu) := ts_XID('01000'B, {mU := { spare := '0'B, mUValue := mu}});

template XID tr_XID_N201I(template uint11_t n201i) :=
	tr_XID({n201_I := {spare := '00000'B, n201IValue := n201i}});
template (value) XID ts_XID_N201I(template (value) uint11_t n201i) :=
	ts_XID('00110'B, {n201_I := { spare := '00000'B, n201IValue := n201i}});

template XID tr_XID_N201U(template uint11_t n201u) :=
	tr_XID({n201_U := {spare := '00000'B, n201UValue := n201u}});
template (value) XID ts_XID_N201U(template (value) uint11_t n201u) :=
	ts_XID('00101'B, {n201_U := { spare := '00000'B, n201UValue := n201u}});

template XID tr_XID_N200(template uint4_t n200) :=
	tr_XID({n200 := { retransmissions := n200, spare := '0000'B}});
template (value) XID ts_XID_N200(template (value) uint4_t n200) :=
	ts_XID('00100'B, {n200 := { retransmissions := n200, spare := '0000'B}});

template XID tr_XID_T200(template uint12_t t200) :=
	tr_XID({t200 := { spare := '0000'B, t200Value := t200}});
template (value) XID ts_XID_T200(template (value) uint12_t t200) :=
	ts_XID('00011'B, {t200 := { spare := '0000'B, t200Value := t200}});

template XID tr_XID_version(template uint4_t v) :=
	tr_XID({version := {version_value := v, spare := '0000'B}});
template (value) XID ts_XID_version(template (value) uint4_t v) :=
	ts_XID('00000'B, {version := {version_value := v, spare := '0000'B}});

template XID tr_XID_IOV_UI(template OCT4 iov) := tr_XID({iOV_UI := iov});
template (value) XID ts_XID_IOV_UI(template (value) OCT4 iov) := ts_XID('00001'B, {iOV_UI := iov});

template XID tr_XID_IOV_I(template OCT4 iov) := tr_XID({iOV_I := iov});
template (value) XID ts_XID_IOV_I(template (value) OCT4 iov) := ts_XID('00010'B, {iOV_I := iov});

template XID tr_XID_L3(template octetstring l3) := tr_XID({l3param := l3});
template (value) XID ts_XID_L3(template (value) octetstring l3) := ts_XID('01011'B, {l3param := l3});

template XID tr_XID_RESET := tr_XID({reset := ''O});
template (value) XID ts_XID_RESET := ts_XID('01100'B, {reset := ''O});


}