summaryrefslogtreecommitdiffstats
path: root/library/LAPDm_Types.ttcn
blob: 32e1ba6ece1a2fb6e6ec5a9d3208e72cf29595b2 (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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/* LAPDm definitiona according to 3GPP TS 44.006 */
/* (C) 2017-2018 bh Harald Welte <laforge@gnumonks.org> */
module LAPDm_Types {

	import from General_Types all;
	import from Osmocom_Types all;

	type uint3_t LapdmSapi;
	type BIT2 LapdmSBits;
	type BIT3 LapdmUBits;
	type BIT2 LapdmU2Bits;

	/* 44.006 6.3.2 */
	const boolean cr_MO_CMD := false;
	const boolean cr_MO_RSP := true;
	const boolean cr_MT_CMD := true;
	const boolean cr_MT_RSP := false;

	/* TS 44.006 Figure 4 */
	type record LapdmAddressField {
		BIT1		spare,
		uint2_t		lpd,
		LapdmSapi	sapi,
		boolean		c_r,
		boolean		ea
	} with { variant "FIELDORDER(msb)" };

	template LapdmAddressField tr_LapdmAddr(template LapdmSapi sapi, template boolean c_r) := {
		spare := '0'B,
		lpd := 0,
		sapi := sapi,
		c_r := c_r,
		ea := true
	};

	template (value) LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
		spare := '0'B,
		lpd := 0,
		sapi := sapi,
		c_r := c_r,
		ea := true
	};

	type record LapdmCtrlI {
		uint3_t n_r,
		boolean	p,
		uint3_t	n_s,
		BIT1	spare ('0'B)
	} with { variant "FIELDORDER(msb)" };

	type record LapdmCtrlS {
		uint3_t		n_r,
		boolean		p_f,
		LapdmSBits	s,
		BIT2		spare ('01'B)
	} with { variant "FIELDORDER(msb)" };

	type record LapdmCtrlU {
		LapdmUBits	u,
		boolean		p_f,
		LapdmU2Bits	u2,
		BIT2		spare ('11'B)
	} with { variant "FIELDORDER(msb)" };

	/* TS 44.006 Table 3 */
	type union LapdmCtrl {
		LapdmCtrlS	s,
		LapdmCtrlU	u,
		LapdmCtrlI	i,
		uint8_t		other
	} with { variant "TAG(u, spare = '11'B;
			      s, spare = '01'B;
			      i, spare = '0'B;
			      other, OTHERWISE)" };
			/*      )" }; */

	/* TS 44.006 Table 4 */

	template LapdmCtrl tr_LapdmCtrlS := {
		s := { n_r := ?, p_f := ?, s := ?, spare := '01'B }
	};

	template LapdmCtrl tr_LapdmCtrlU := {
		u := { u := ?, p_f := ?, u2 := ?, spare := '11'B }
	};

	/* TS 44.006 Table 4 */
	template LapdmCtrl tr_LapdmCtrlI(template uint3_t nr, template uint3_t ns, template boolean p) := {
		i := { n_r := nr, p := p, n_s := ns, spare := '0'B }
	};
	template (value) LapdmCtrl ts_LapdmCtrlI(uint3_t nr, uint3_t ns, boolean p) := {
		i := { n_r := nr, p := p, n_s := ns, spare := '0'B }
	};


	template LapdmCtrl tr_LapdmCtrlRR(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
		s := { n_r := nr, p_f := pf, s := '00'B }
	};
	template (value) LapdmCtrl ts_LapdmCtrlRR(uint3_t nr, boolean pf) := {
		s := { n_r := nr, p_f := pf, s := '00'B }
	};

	template LapdmCtrl tr_LapdmCtrlRNR(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
		s := { n_r := nr, p_f := pf, s := '01'B }
	};

	template LapdmCtrl tr_LapdmCtrlREJ(template uint3_t nr, template boolean pf) modifies tr_LapdmCtrlS := {
		s := { n_r := nr, p_f := pf, s := '10'B }
	};

	template LapdmCtrl tr_LapdmCtrlSABM(template boolean p) := {
		u := { u := '001'B, p_f := p, u2 := '11'B, spare := '11'B }
	};
	template (value) LapdmCtrl ts_LapdmCtrlSABM(boolean p) := {
		u := { u := '001'B, p_f := p, u2 := '11'B, spare := '11'B }
	};

	template LapdmCtrl tr_LapdmCtrlDM(template boolean f) := {
		u := { u := '000'B, p_f := f, u2 := '11'B, spare := '11'B }
	};

	template LapdmCtrl tr_LapdmCtrlUI(template boolean p := false) := {
		u := { u := '000'B, p_f := p, u2 := '00'B, spare := '11'B }
	};
	template (value) LapdmCtrl ts_LapdmCtrlUI(boolean p := false) := {
		u := { u := '000'B, p_f := p, u2 := '00'B, spare := '11'B }
	};

	template LapdmCtrl tr_LapdmCtrlDISC(template boolean p) := {
		u := { u := '010'B, p_f := p, u2 := '00'B, spare := '11'B }
	};
	template LapdmCtrl ts_LapdmCtrlDISC(boolean p) := {
		u := { u := '010'B, p_f := p, u2 := '00'B, spare := '11'B }
	};

	template LapdmCtrl tr_LapdmCtrlUA(template boolean f) modifies tr_LapdmCtrlU := {
		u := { u := '011'B, p_f := f, u2 := '00'B, spare := '11'B }
	};
	template (value) LapdmCtrl ts_LapdmCtrlUA(boolean f) := {
		u := { u := '011'B, p_f := f, u2 := '00'B, spare := '11'B }
	};



	external function dec_LapdmAddressField(in octetstring stream) return LapdmAddressField
		with { extension "prototype(convert) decode(RAW)" };

	external function dec_LapdmCtrl(in octetstring stream) return LapdmCtrl
		with { extension "prototype(convert) decode(RAW)" };

	external function dec_LapdmCtrlU(in octetstring stream) return LapdmCtrlU
		with { extension "prototype(convert) decode(RAW)" };

	/* Formats B, Bter and B4 are used on DCCHs for frames containing an information field: 
	/* - format Bter is used on request of higher layers if and only if short L2 header type 1 is
	 *   supported and a UI command is to be transmitted on SAPI 0 */
	/* - format B4 is used for UI frames transmitted by the network on SACCH; */
	/* - format B is applied in all other cases. */
	/* Format Bbis is used only on BCCH, PCH, NCH, and AGCH.

	/* Format B */
	type record LapdmFrameAB {
		LapdmAddressField	addr,
		LapdmCtrl		ctrl,
		uint6_t 		len,
		boolean			m,
		uint1_t			el,
		octetstring		payload	/* zero-length in Frame A */
	} with { variant (len) "LENGTHTO(payload)"
		 variant "FIELDORDER(msb)" };

	external function enc_LapdmFrameAB(in LapdmFrameAB si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_LapdmFrameAB(in octetstring stream) return LapdmFrameAB
		with { extension "prototype(convert) decode(RAW)" };

	/* Format B4 */
	type record LapdmFrameB4 {
		LapdmAddressField	addr,
		LapdmCtrl		ctrl,
		octetstring		payload
	} with { variant "" };

	external function enc_LapdmFrameB4(in LapdmFrameB4 si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_LapdmFrameB4(in octetstring stream) return LapdmFrameB4
		with { extension "prototype(convert) decode(RAW)" };

	type record LapdmFrameBbis {
		octetstring		payload
	} with { variant "" };

	external function enc_LapdmFrameBbis(in LapdmFrameBbis si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_LapdmFrameBbis(in octetstring stream) return LapdmFrameBbis
		with { extension "prototype(convert) decode(RAW)" };

	type union LapdmFrame {
		LapdmFrameAB	ab,
		LapdmFrameBbis	bbis,
		LapdmFrameB4	b4
	} with { variant "" };

	external function enc_LapdmFrame(in LapdmFrame si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	/* automatic decoding to the generic LapdmFrame will not work, you have to call one of the
	 * type-specific decoder routines above */

	/* SABM frame with L3 payload */
	template (value) LapdmFrame ts_LAPDm_SABM(LapdmSapi sapi, boolean c_r, boolean p,
						  octetstring l3) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlSABM(p),
			len := 0, /* overwritten in encoder */
			m := false,
			el := 1,
			payload := l3
		}
	}
	template LapdmFrame tr_LAPDm_SABM(template LapdmSapi sapi, template boolean c_r,
					  template boolean p, template octetstring l3) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlSABM(p),
			len := ?,
			m := false,
			el := 1,
			payload := l3
		}
	}

	template (value) LapdmFrame ts_LAPDm_UA(LapdmSapi sapi, boolean c_r, boolean f,
						octetstring l3) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlUA(f),
			len := 0, /* overwritten in encoder */
			m := false,
			el := 1,
			payload := l3
		}
	}
	template LapdmFrame tr_LAPDm_UA(template LapdmSapi sapi, template boolean c_r,
					template boolean f, template octetstring l3) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlUA(f),
			len := ?,
			m := false,
			el := 1,
			payload := l3
		}
	}

	template LapdmFrame ts_LAPDm_DISC(LapdmSapi sapi, boolean c_r, boolean p) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlDISC(p),
			len := 0,
			m := false,
			el := 1,
			payload := ''O
		}
	}
	template LapdmFrame tr_LAPDm_DISC(template LapdmSapi sapi, template boolean c_r,
					  template boolean p) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlDISC(p),
			len := ?,
			m := false,
			el := 1,
			payload := ''O
		}
	}

	template LapdmFrame ts_LAPDm_UI(LapdmSapi sapi, boolean c_r, octetstring l3) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlUI,
			len := 0,
			m := false,
			el := 1,
			payload := l3
		}
	}
	template LapdmFrame tr_LAPDm_UI(template LapdmSapi sapi, template boolean c_r,
					template octetstring l3) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlUI,
			len := ?,
			m := false,
			el := 1,
			payload := l3
		}
	}

	template LapdmFrame ts_LAPDm_B4_UI(LapdmSapi sapi, boolean c_r, octetstring l3) := {
		b4 := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlUI,
			payload := l3
		}
	}
	template LapdmFrame tr_LAPDm_B4_UI(template LapdmSapi sapi, template boolean c_r,
					   template octetstring l3) := {
		b4 := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlUI,
			payload := l3
		}
	}

	template LapdmFrame tr_LAPDm_I(template LapdmSapi sapi, template boolean c_r,
					template boolean p, template uint3_t nr,
					template uint3_t ns, template octetstring l3) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlI(nr, ns, p),
			len := ?,
			m := false,
			el := 1,
			payload := l3
		}
	}
	template (value) LapdmFrame ts_LAPDm_I(LapdmSapi sapi, boolean c_r, boolean p, uint3_t nr,
						uint3_t ns, octetstring l3) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlI(nr, ns, p),
			len := 0,
			m := false,
			el := 1,
			payload := l3
		}
	}

	template LapdmFrame tr_LAPDm_RR(template LapdmSapi sapi, template boolean c_r,
					template boolean p, template uint3_t nr) := {
		ab := {
			addr := tr_LapdmAddr(sapi, c_r),
			ctrl := tr_LapdmCtrlRR(nr, p),
			len := 0,
			m := false,
			el := 1,
			payload := ''O
		}
	}
	template (value) LapdmFrame ts_LAPDm_RR(LapdmSapi sapi, boolean c_r,
						boolean p, uint3_t nr) := {
		ab := {
			addr := ts_LapdmAddr(sapi, c_r),
			ctrl := ts_LapdmCtrlRR(nr, p),
			len := 0,
			m := false,
			el := 1,
			payload := ''O
		}
	}



} with { encode "RAW"; /*variant "FIELDORDER(msb)" */}