Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * llc_station.c - station component of LLC | |
3 | * | |
4 | * Copyright (c) 1997 by Procom Technology, Inc. | |
5 | * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> | |
6 | * | |
7 | * This program can be redistributed or modified under the terms of the | |
8 | * GNU General Public License as published by the Free Software Foundation. | |
9 | * This program is distributed without any warranty or implied warranty | |
10 | * of merchantability or fitness for a particular purpose. | |
11 | * | |
12 | * See the GNU General Public License for more details. | |
13 | */ | |
1da177e4 LT |
14 | #include <linux/init.h> |
15 | #include <linux/module.h> | |
5a0e3ad6 | 16 | #include <linux/slab.h> |
1da177e4 LT |
17 | #include <net/llc.h> |
18 | #include <net/llc_sap.h> | |
19 | #include <net/llc_conn.h> | |
20 | #include <net/llc_c_ac.h> | |
21 | #include <net/llc_s_ac.h> | |
22 | #include <net/llc_c_ev.h> | |
23 | #include <net/llc_c_st.h> | |
24 | #include <net/llc_s_ev.h> | |
25 | #include <net/llc_s_st.h> | |
26 | #include <net/llc_pdu.h> | |
27 | ||
1da177e4 LT |
28 | static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb) |
29 | { | |
1da177e4 LT |
30 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); |
31 | ||
025e3633 | 32 | return LLC_PDU_IS_CMD(pdu) && /* command PDU */ |
1da177e4 LT |
33 | LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ |
34 | LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID && | |
af1c0e4e | 35 | !pdu->dsap; /* NULL DSAP value */ |
1da177e4 LT |
36 | } |
37 | ||
1da177e4 LT |
38 | static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb) |
39 | { | |
1da177e4 LT |
40 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); |
41 | ||
025e3633 | 42 | return LLC_PDU_IS_CMD(pdu) && /* command PDU */ |
1da177e4 LT |
43 | LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ |
44 | LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST && | |
af1c0e4e | 45 | !pdu->dsap; /* NULL DSAP */ |
1da177e4 LT |
46 | } |
47 | ||
1da177e4 LT |
48 | static int llc_station_ac_send_xid_r(struct sk_buff *skb) |
49 | { | |
50 | u8 mac_da[ETH_ALEN], dsap; | |
51 | int rc = 1; | |
f83f1768 JP |
52 | struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, |
53 | sizeof(struct llc_xid_info)); | |
1da177e4 LT |
54 | |
55 | if (!nskb) | |
56 | goto out; | |
1da177e4 LT |
57 | llc_pdu_decode_sa(skb, mac_da); |
58 | llc_pdu_decode_ssap(skb, &dsap); | |
59 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); | |
60 | llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127); | |
a5a04819 | 61 | rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); |
249ff1c6 | 62 | if (unlikely(rc)) |
1da177e4 | 63 | goto free; |
5ecf9eea | 64 | dev_queue_xmit(nskb); |
1da177e4 LT |
65 | out: |
66 | return rc; | |
67 | free: | |
91d27a86 | 68 | kfree_skb(nskb); |
1da177e4 LT |
69 | goto out; |
70 | } | |
71 | ||
72 | static int llc_station_ac_send_test_r(struct sk_buff *skb) | |
73 | { | |
74 | u8 mac_da[ETH_ALEN], dsap; | |
75 | int rc = 1; | |
f83f1768 JP |
76 | u32 data_size; |
77 | struct sk_buff *nskb; | |
78 | ||
79 | /* The test request command is type U (llc_len = 3) */ | |
80 | data_size = ntohs(eth_hdr(skb)->h_proto) - 3; | |
81 | nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size); | |
1da177e4 LT |
82 | |
83 | if (!nskb) | |
84 | goto out; | |
1da177e4 LT |
85 | llc_pdu_decode_sa(skb, mac_da); |
86 | llc_pdu_decode_ssap(skb, &dsap); | |
87 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); | |
d57b1869 | 88 | llc_pdu_init_as_test_rsp(nskb, skb); |
a5a04819 | 89 | rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); |
249ff1c6 | 90 | if (unlikely(rc)) |
1da177e4 | 91 | goto free; |
5ecf9eea | 92 | dev_queue_xmit(nskb); |
1da177e4 LT |
93 | out: |
94 | return rc; | |
95 | free: | |
91d27a86 | 96 | kfree_skb(nskb); |
1da177e4 LT |
97 | goto out; |
98 | } | |
99 | ||
2c53040f | 100 | /** |
1da177e4 LT |
101 | * llc_station_rcv - send received pdu to the station state machine |
102 | * @skb: received frame. | |
103 | * | |
104 | * Sends data unit to station state machine. | |
105 | */ | |
106 | static void llc_station_rcv(struct sk_buff *skb) | |
107 | { | |
12ebc8b9 BH |
108 | if (llc_stat_ev_rx_null_dsap_xid_c(skb)) |
109 | llc_station_ac_send_xid_r(skb); | |
110 | else if (llc_stat_ev_rx_null_dsap_test_c(skb)) | |
111 | llc_station_ac_send_test_r(skb); | |
04d191c2 | 112 | kfree_skb(skb); |
1da177e4 LT |
113 | } |
114 | ||
6024935f | 115 | void __init llc_station_init(void) |
1da177e4 | 116 | { |
aadf31de | 117 | llc_set_station_handler(llc_station_rcv); |
1da177e4 LT |
118 | } |
119 | ||
f4f8720f | 120 | void llc_station_exit(void) |
1da177e4 LT |
121 | { |
122 | llc_set_station_handler(NULL); | |
123 | } |