blob: 8ca8f39d1c613d0dd21e72951ecdf47f007fafd4 [file] [log] [blame]
Harald Weltee38fd7b2017-07-23 21:03:02 +02001module LLC_Types {
2 import from General_Types all;
3 import from Osmocom_Types all;
4
5 /* TS 44.064 Chapter 6.2 */
6 type record LlcAddressField {
Harald Welte244cd8a2017-08-26 09:25:20 +02007 BIT1 pd ('0'B),
Harald Weltee38fd7b2017-07-23 21:03:02 +02008 boolean c_r,
9 BIT2 reserved,
10 LlcSapi sapi
11 } with {
Harald Weltee38fd7b2017-07-23 21:03:02 +020012 variant (c_r) "FIELDLENGTH(1)"
13 };
14
Harald Welte244cd8a2017-08-26 09:25:20 +020015 template LlcAddressField t_LLC_Addr(template boolean c_r, template LlcSapi sapi) := {
16 pd := '0'B,
17 c_r := c_r,
18 reserved := '00'B,
19 sapi := sapi
20 };
21
22 const boolean LLC_CR_DL_CMD := true;
23 const boolean LLC_CR_DL_RSP := false;
24 const boolean LLC_CR_UL_CMD := false;
25 const boolean LLC_CR_UL_RSP := true;
26
27 template LlcAddressField t_LLC_Addr_DlCmd(template LlcSapi sapi) := t_LLC_Addr(true, sapi);
28 template LlcAddressField t_LLC_Addr_DlRsp(template LlcSapi sapi) := t_LLC_Addr(false, sapi);
29 template LlcAddressField t_LLC_Addr_UlCmd(template LlcSapi sapi) := t_LLC_Addr(false, sapi);
30 template LlcAddressField t_LLC_Addr_UlRsp(template LlcSapi sapi) := t_LLC_Addr(true, sapi);
31
Harald Weltee38fd7b2017-07-23 21:03:02 +020032 type enumerated LlcSapi {
33 LLC_SAPI_RESERVED_0 ('0000'B),
34 LLC_SAPI_GMM ('0001'B),
35 LLC_SAPI_TOM2 ('0010'B),
36 LLC_SAPI_LL3 ('0011'B),
37 LLC_SAPI_RESERVED_4 ('0100'B),
38 LLC_SAPI_LL5 ('0101'B),
39 LLC_SAPI_RESERVED_6 ('0110'B),
40 LLC_SAPI_SMS ('0111'B),
41 LLC_SAPI_TOM8 ('1000'B),
42 LLC_SAPI_LL9 ('1001'B),
43 LLC_SAPI_RESERVED_10 ('1010'B),
44 LLC_SAPI_LL11 ('1011'B),
45 LLC_SAPI_RESERVED_12 ('1100'B),
46 LLC_SAPI_RESERVED_13 ('1101'B),
47 LLC_SAPI_RESERVED_14 ('1110'B),
48 LLC_SAPI_RESERVED_15 ('1111'B)
49 } with { variant "FIELDLENGTH(4)" };
50
51 /* TS 44.064 Chapter 6.3 */
52 type record LlcCtrlFieldI {
53 BIT1 presence ('0'B),
54 boolean a,
55 BIT1 spare,
56 uint9_t n_s,
57 BIT1 spare2,
58 uint9_t n_r,
59 LlcCtrlS s
60 } with { variant
61 (a) "FIELDLENGTH(1)"
62 };
63
64 /* TS 44.064 Chapter 6.3 */
65 type record LlcCtrlFieldS {
66 BIT2 presence ('10'B),
67 boolean a,
68 BIT2 spare,
69 uint9_t n_r,
70 LlcCtrlS s
71 } with {
72 variant (a) "FIELDLENGTH(1)"
73 };
74
75 /* TS 44.064 Chapter 6.3 */
76 type record LlcCtrlFieldUI {
77 BIT3 presence ('110'B),
78 BIT2 spare,
79 uint9_t n_u,
80 boolean e,
81 boolean pm
82 } with {
83 variant (e) "FIELDLENGTH(1)"
84 variant (pm) "FIELDLENGTH(1)"
85 };
86
Harald Welte244cd8a2017-08-26 09:25:20 +020087 template LlcCtrlFieldUI t_LlcCtrlUI(template uint8_t n_u) := {
88 presence := '110'B,
89 spare := '00'B,
90 n_u := n_u,
91 e := false,
92 pm := true
93 };
94
Harald Weltee38fd7b2017-07-23 21:03:02 +020095 /* TS 44.064 Chapter 6.3 */
96 type record LlcCtrlFieldU {
97 BIT3 presence ('111'B),
98 boolean p_f,
99 LlcCtrlM m
100 } with {
101 variant (p_f) "FIELDLENGTH(1)"
102 };
103
104
105 /* TS 44.064 Chapter 6.4 */
106 type enumerated LlcCtrlS {
107 LLC_S_RR ('00'B),
108 LLC_S_ACK ('01'B),
109 LLC_S_RNR ('10'B),
110 LLC_S_SACK ('11'B)
111 } with { variant "FIELDLENGTH(2)" };
112
113 /* TS 44.064 Chapter 6.4 */
114 type enumerated LlcCtrlM {
115 LLC_M_DM ('0001'B),
116 LLC_M_DISC ('0100'B),
117 LLC_M_UA ('0110'B),
118 LLC_M_SABM ('0111'B),
119 LLC_M_FRMR ('1000'B),
120 LLC_M_XID ('1011'B),
121 LLC_M_NULL ('0000'B)
122 } with { variant "FIELDLENGTH(4)" };
123
124 type union LlcCtrlUnion {
125 LlcCtrlFieldI i,
126 LlcCtrlFieldS s,
127 LlcCtrlFieldUI ui,
128 LlcCtrlFieldU u
129 } with { variant "TAG(i, presence = '0'B;
130 s, presence = '10'B;
131 ui, presence = '110'B;
132 u, presence = '111'B)"
133 variant "FIELDORDER(msb)"
134 };
135
136 external function enc_LlcCtrlUnion(in LlcCtrlUnion pdu) return octetstring
137 with { extension "prototype(convert) encode(RAW)" };
138 external function dec_LlcCtrlUnion(in octetstring stream) return LlcCtrlUnion
139 with { extension "prototype(convert) decode(RAW)" };
140
141
142 type uint24_t LlcFcs;
143
144 type record LlcPdu {
145 LlcAddressField addr,
146 LlcCtrlUnion ctrl,
Harald Welte244cd8a2017-08-26 09:25:20 +0200147 octetstring payload//,
148 //LlcFcs fcs
Harald Weltee38fd7b2017-07-23 21:03:02 +0200149 } with { variant "" };
150
151 external function enc_LlcPdu(in LlcPdu pdu) return octetstring
152 with { extension "prototype(convert) encode(RAW)" };
153 external function dec_LlcPdu(in octetstring stream) return LlcPdu
154 with { extension "prototype(convert) decode(RAW)" };
155
Harald Welte244cd8a2017-08-26 09:25:20 +0200156
157 template LlcPdu t_LLC_UI(template boolean c_r, template uint8_t n_u, template octetstring payload,
158 template LlcSapi sapi := LLC_SAPI_GMM) := {
159 addr := t_LLC_Addr(c_r, sapi),
160 ctrl := {
161 ui := t_LlcCtrlUI(n_u)
162 },
163 payload := payload
164 };
Harald Weltee38fd7b2017-07-23 21:03:02 +0200165} with { encode "RAW"; variant "FIELDORDER(msb)" }