1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/netdevice.h>
16#include <net/llc_pdu.h>
17
18static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type);
19static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu);
20
21void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 pdu_type)
22{
23 llc_pdu_un_hdr(skb)->ssap |= pdu_type;
24}
25
26
27
28
29
30
31
32
33
34
35void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value)
36{
37 u8 pdu_type;
38 struct llc_pdu_sn *pdu;
39
40 llc_pdu_decode_pdu_type(skb, &pdu_type);
41 pdu = llc_pdu_sn_hdr(skb);
42
43 switch (pdu_type) {
44 case LLC_PDU_TYPE_I:
45 case LLC_PDU_TYPE_S:
46 pdu->ctrl_2 = (pdu->ctrl_2 & 0xFE) | bit_value;
47 break;
48 case LLC_PDU_TYPE_U:
49 pdu->ctrl_1 |= (pdu->ctrl_1 & 0xEF) | (bit_value << 4);
50 break;
51 }
52}
53
54
55
56
57
58
59
60
61
62
63void llc_pdu_decode_pf_bit(struct sk_buff *skb, u8 *pf_bit)
64{
65 u8 pdu_type;
66 struct llc_pdu_sn *pdu;
67
68 llc_pdu_decode_pdu_type(skb, &pdu_type);
69 pdu = llc_pdu_sn_hdr(skb);
70
71 switch (pdu_type) {
72 case LLC_PDU_TYPE_I:
73 case LLC_PDU_TYPE_S:
74 *pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK;
75 break;
76 case LLC_PDU_TYPE_U:
77 *pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4;
78 break;
79 }
80}
81
82
83
84
85
86
87
88
89void llc_pdu_init_as_disc_cmd(struct sk_buff *skb, u8 p_bit)
90{
91 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
92
93 pdu->ctrl_1 = LLC_PDU_TYPE_U;
94 pdu->ctrl_1 |= LLC_2_PDU_CMD_DISC;
95 pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
96}
97
98
99
100
101
102
103
104
105
106
107void llc_pdu_init_as_i_cmd(struct sk_buff *skb, u8 p_bit, u8 ns, u8 nr)
108{
109 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
110
111 pdu->ctrl_1 = LLC_PDU_TYPE_I;
112 pdu->ctrl_2 = 0;
113 pdu->ctrl_2 |= (p_bit & LLC_I_PF_BIT_MASK);
114 pdu->ctrl_1 |= (ns << 1) & 0xFE;
115 pdu->ctrl_2 |= (nr << 1) & 0xFE;
116}
117
118
119
120
121
122
123
124
125
126void llc_pdu_init_as_rej_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
127{
128 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
129
130 pdu->ctrl_1 = LLC_PDU_TYPE_S;
131 pdu->ctrl_1 |= LLC_2_PDU_CMD_REJ;
132 pdu->ctrl_2 = 0;
133 pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK;
134 pdu->ctrl_1 &= 0x0F;
135 pdu->ctrl_2 |= (nr << 1) & 0xFE;
136}
137
138
139
140
141
142
143
144
145
146void llc_pdu_init_as_rnr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
147{
148 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
149
150 pdu->ctrl_1 = LLC_PDU_TYPE_S;
151 pdu->ctrl_1 |= LLC_2_PDU_CMD_RNR;
152 pdu->ctrl_2 = 0;
153 pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK;
154 pdu->ctrl_1 &= 0x0F;
155 pdu->ctrl_2 |= (nr << 1) & 0xFE;
156}
157
158
159
160
161
162
163
164
165
166void llc_pdu_init_as_rr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
167{
168 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
169
170 pdu->ctrl_1 = LLC_PDU_TYPE_S;
171 pdu->ctrl_1 |= LLC_2_PDU_CMD_RR;
172 pdu->ctrl_2 = p_bit & LLC_S_PF_BIT_MASK;
173 pdu->ctrl_1 &= 0x0F;
174 pdu->ctrl_2 |= (nr << 1) & 0xFE;
175}
176
177
178
179
180
181
182
183
184void llc_pdu_init_as_sabme_cmd(struct sk_buff *skb, u8 p_bit)
185{
186 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
187
188 pdu->ctrl_1 = LLC_PDU_TYPE_U;
189 pdu->ctrl_1 |= LLC_2_PDU_CMD_SABME;
190 pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
191}
192
193
194
195
196
197
198
199
200void llc_pdu_init_as_dm_rsp(struct sk_buff *skb, u8 f_bit)
201{
202 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
203
204 pdu->ctrl_1 = LLC_PDU_TYPE_U;
205 pdu->ctrl_1 |= LLC_2_PDU_RSP_DM;
206 pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
207}
208
209
210
211
212
213
214
215
216
217
218
219
220void llc_pdu_init_as_frmr_rsp(struct sk_buff *skb, struct llc_pdu_sn *prev_pdu,
221 u8 f_bit, u8 vs, u8 vr, u8 vzyxw)
222{
223 struct llc_frmr_info *frmr_info;
224 u8 prev_pf = 0;
225 u8 *ctrl;
226 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
227
228 pdu->ctrl_1 = LLC_PDU_TYPE_U;
229 pdu->ctrl_1 |= LLC_2_PDU_RSP_FRMR;
230 pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
231
232 frmr_info = (struct llc_frmr_info *)&pdu->ctrl_2;
233 ctrl = (u8 *)&prev_pdu->ctrl_1;
234 FRMR_INFO_SET_REJ_CNTRL(frmr_info,ctrl);
235 FRMR_INFO_SET_Vs(frmr_info, vs);
236 FRMR_INFO_SET_Vr(frmr_info, vr);
237 prev_pf = llc_pdu_get_pf_bit(prev_pdu);
238 FRMR_INFO_SET_C_R_BIT(frmr_info, prev_pf);
239 FRMR_INFO_SET_INVALID_PDU_CTRL_IND(frmr_info, vzyxw);
240 FRMR_INFO_SET_INVALID_PDU_INFO_IND(frmr_info, vzyxw);
241 FRMR_INFO_SET_PDU_INFO_2LONG_IND(frmr_info, vzyxw);
242 FRMR_INFO_SET_PDU_INVALID_Nr_IND(frmr_info, vzyxw);
243 FRMR_INFO_SET_PDU_INVALID_Ns_IND(frmr_info, vzyxw);
244 skb_put(skb, sizeof(struct llc_frmr_info));
245}
246
247
248
249
250
251
252
253
254
255void llc_pdu_init_as_rr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
256{
257 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
258
259 pdu->ctrl_1 = LLC_PDU_TYPE_S;
260 pdu->ctrl_1 |= LLC_2_PDU_RSP_RR;
261 pdu->ctrl_2 = 0;
262 pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
263 pdu->ctrl_1 &= 0x0F;
264 pdu->ctrl_2 |= (nr << 1) & 0xFE;
265}
266
267
268
269
270
271
272
273
274
275void llc_pdu_init_as_rej_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
276{
277 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
278
279 pdu->ctrl_1 = LLC_PDU_TYPE_S;
280 pdu->ctrl_1 |= LLC_2_PDU_RSP_REJ;
281 pdu->ctrl_2 = 0;
282 pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
283 pdu->ctrl_1 &= 0x0F;
284 pdu->ctrl_2 |= (nr << 1) & 0xFE;
285}
286
287
288
289
290
291
292
293
294
295void llc_pdu_init_as_rnr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
296{
297 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
298
299 pdu->ctrl_1 = LLC_PDU_TYPE_S;
300 pdu->ctrl_1 |= LLC_2_PDU_RSP_RNR;
301 pdu->ctrl_2 = 0;
302 pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
303 pdu->ctrl_1 &= 0x0F;
304 pdu->ctrl_2 |= (nr << 1) & 0xFE;
305}
306
307
308
309
310
311
312
313
314void llc_pdu_init_as_ua_rsp(struct sk_buff *skb, u8 f_bit)
315{
316 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
317
318 pdu->ctrl_1 = LLC_PDU_TYPE_U;
319 pdu->ctrl_1 |= LLC_2_PDU_RSP_UA;
320 pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
321}
322
323
324
325
326
327
328
329
330static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type)
331{
332 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
333
334 if (pdu->ctrl_1 & 1) {
335 if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U)
336 *type = LLC_PDU_TYPE_U;
337 else
338 *type = LLC_PDU_TYPE_S;
339 } else
340 *type = LLC_PDU_TYPE_I;
341}
342
343
344
345
346
347
348
349
350static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu)
351{
352 u8 pdu_type;
353 u8 pf_bit = 0;
354
355 if (pdu->ctrl_1 & 1) {
356 if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U)
357 pdu_type = LLC_PDU_TYPE_U;
358 else
359 pdu_type = LLC_PDU_TYPE_S;
360 } else
361 pdu_type = LLC_PDU_TYPE_I;
362 switch (pdu_type) {
363 case LLC_PDU_TYPE_I:
364 case LLC_PDU_TYPE_S:
365 pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK;
366 break;
367 case LLC_PDU_TYPE_U:
368 pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4;
369 break;
370 }
371 return pf_bit;
372}
373