1
2
3
4
5#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6
7#include <linux/etherdevice.h>
8#include <linux/hardirq.h>
9#include <linux/slab.h>
10#include <linux/types.h>
11#include <linux/export.h>
12#include <net/cfg80211.h>
13
14#include "defs.h"
15#include "host.h"
16#include "radiotap.h"
17#include "decl.h"
18#include "dev.h"
19#include "mesh.h"
20
21struct eth803hdr {
22 u8 dest_addr[6];
23 u8 src_addr[6];
24 u16 h803_len;
25} __packed;
26
27struct rfc1042hdr {
28 u8 llc_dsap;
29 u8 llc_ssap;
30 u8 llc_ctrl;
31 u8 snap_oui[3];
32 u16 snap_type;
33} __packed;
34
35struct rxpackethdr {
36 struct eth803hdr eth803_hdr;
37 struct rfc1042hdr rfc1042_hdr;
38} __packed;
39
40struct rx80211packethdr {
41 struct rxpd rx_pd;
42 void *eth80211_hdr;
43} __packed;
44
45static int process_rxed_802_11_packet(struct lbs_private *priv,
46 struct sk_buff *skb);
47
48
49
50
51
52
53
54
55
56int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
57{
58 int ret = 0;
59 struct net_device *dev = priv->dev;
60 struct rxpackethdr *p_rx_pkt;
61 struct rxpd *p_rx_pd;
62 int hdrchop;
63 struct ethhdr *p_ethhdr;
64 static const u8 rfc1042_eth_hdr[] = {
65 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
66 };
67
68 lbs_deb_enter(LBS_DEB_RX);
69
70 BUG_ON(!skb);
71
72 skb->ip_summed = CHECKSUM_NONE;
73
74 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
75 return process_rxed_802_11_packet(priv, skb);
76
77 p_rx_pd = (struct rxpd *) skb->data;
78 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd +
79 le32_to_cpu(p_rx_pd->pkt_ptr));
80
81 dev = lbs_mesh_set_dev(priv, dev, p_rx_pd);
82
83 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
84 min_t(unsigned int, skb->len, 100));
85
86 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
87 lbs_deb_rx("rx err: frame received with bad length\n");
88 dev->stats.rx_length_errors++;
89 ret = 0;
90 dev_kfree_skb(skb);
91 goto done;
92 }
93
94 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
95 skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr),
96 skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr));
97
98 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
99 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
100 lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr,
101 sizeof(p_rx_pkt->eth803_hdr.src_addr));
102
103 if (memcmp(&p_rx_pkt->rfc1042_hdr,
104 rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
105
106
107
108
109
110
111
112
113
114
115 p_ethhdr = (struct ethhdr *)
116 ((u8 *) &p_rx_pkt->eth803_hdr
117 + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr)
118 - sizeof(p_rx_pkt->eth803_hdr.dest_addr)
119 - sizeof(p_rx_pkt->eth803_hdr.src_addr)
120 - sizeof(p_rx_pkt->rfc1042_hdr.snap_type));
121
122 memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr,
123 sizeof(p_ethhdr->h_source));
124 memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr,
125 sizeof(p_ethhdr->h_dest));
126
127
128
129
130 hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd;
131 } else {
132 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
133 (u8 *) &p_rx_pkt->rfc1042_hdr,
134 sizeof(p_rx_pkt->rfc1042_hdr));
135
136
137 hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd;
138 }
139
140
141
142
143 skb_pull(skb, hdrchop);
144
145 priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate);
146
147 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
148 dev->stats.rx_bytes += skb->len;
149 dev->stats.rx_packets++;
150
151 skb->protocol = eth_type_trans(skb, dev);
152 if (in_interrupt())
153 netif_rx(skb);
154 else
155 netif_rx_ni(skb);
156
157 ret = 0;
158done:
159 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
160 return ret;
161}
162EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
163
164
165
166
167
168
169
170
171static u8 convert_mv_rate_to_radiotap(u8 rate)
172{
173 switch (rate) {
174 case 0:
175 return 2;
176 case 1:
177 return 4;
178 case 2:
179 return 11;
180 case 3:
181 return 22;
182
183 case 5:
184 return 12;
185 case 6:
186 return 18;
187 case 7:
188 return 24;
189 case 8:
190 return 36;
191 case 9:
192 return 48;
193 case 10:
194 return 72;
195 case 11:
196 return 96;
197 case 12:
198 return 108;
199 }
200 pr_alert("Invalid Marvell WLAN rate %i\n", rate);
201 return 0;
202}
203
204
205
206
207
208
209
210
211
212static int process_rxed_802_11_packet(struct lbs_private *priv,
213 struct sk_buff *skb)
214{
215 int ret = 0;
216 struct net_device *dev = priv->dev;
217 struct rx80211packethdr *p_rx_pkt;
218 struct rxpd *prxpd;
219 struct rx_radiotap_hdr radiotap_hdr;
220 struct rx_radiotap_hdr *pradiotap_hdr;
221
222 lbs_deb_enter(LBS_DEB_RX);
223
224 p_rx_pkt = (struct rx80211packethdr *) skb->data;
225 prxpd = &p_rx_pkt->rx_pd;
226
227
228
229 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
230 lbs_deb_rx("rx err: frame received with bad length\n");
231 dev->stats.rx_length_errors++;
232 ret = -EINVAL;
233 kfree_skb(skb);
234 goto done;
235 }
236
237 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
238 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
239
240
241
242
243 memset(&radiotap_hdr, 0, sizeof(radiotap_hdr));
244
245 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
246 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
247 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
248
249 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
250
251
252 skb_pull(skb, sizeof(struct rxpd));
253
254
255 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
256 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
257 netdev_alert(dev, "%s: couldn't pskb_expand_head\n", __func__);
258 ret = -ENOMEM;
259 kfree_skb(skb);
260 goto done;
261 }
262
263 pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr));
264 memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr));
265
266 priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate);
267
268 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
269 dev->stats.rx_bytes += skb->len;
270 dev->stats.rx_packets++;
271
272 skb->protocol = eth_type_trans(skb, priv->dev);
273
274 if (in_interrupt())
275 netif_rx(skb);
276 else
277 netif_rx_ni(skb);
278
279 ret = 0;
280
281done:
282 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
283 return ret;
284}
285