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