Commit | Line | Data |
---|---|---|
8973a6e7 RD |
1 | /* |
2 | * This file contains the handling of RX in wlan driver. | |
3 | */ | |
0e4e06ae JP |
4 | |
5 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
6 | ||
876c9d3a | 7 | #include <linux/etherdevice.h> |
a6b7a407 | 8 | #include <linux/hardirq.h> |
5a0e3ad6 | 9 | #include <linux/slab.h> |
876c9d3a | 10 | #include <linux/types.h> |
ee40fa06 | 11 | #include <linux/export.h> |
e86dc1ca | 12 | #include <net/cfg80211.h> |
876c9d3a | 13 | |
e86dc1ca | 14 | #include "defs.h" |
9e66e701 | 15 | #include "host.h" |
876c9d3a MT |
16 | #include "radiotap.h" |
17 | #include "decl.h" | |
18 | #include "dev.h" | |
49fee692 | 19 | #include "mesh.h" |
876c9d3a MT |
20 | |
21 | struct eth803hdr { | |
22 | u8 dest_addr[6]; | |
23 | u8 src_addr[6]; | |
24 | u16 h803_len; | |
ba2d3587 | 25 | } __packed; |
876c9d3a MT |
26 | |
27 | struct rfc1042hdr { | |
28 | u8 llc_dsap; | |
29 | u8 llc_ssap; | |
30 | u8 llc_ctrl; | |
31 | u8 snap_oui[3]; | |
32 | u16 snap_type; | |
ba2d3587 | 33 | } __packed; |
876c9d3a MT |
34 | |
35 | struct rxpackethdr { | |
876c9d3a MT |
36 | struct eth803hdr eth803_hdr; |
37 | struct rfc1042hdr rfc1042_hdr; | |
ba2d3587 | 38 | } __packed; |
876c9d3a MT |
39 | |
40 | struct rx80211packethdr { | |
41 | struct rxpd rx_pd; | |
42 | void *eth80211_hdr; | |
ba2d3587 | 43 | } __packed; |
876c9d3a | 44 | |
69f9032d HS |
45 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
46 | struct sk_buff *skb); | |
876c9d3a | 47 | |
876c9d3a | 48 | /** |
8973a6e7 RD |
49 | * lbs_process_rxed_packet - processes received packet and forwards it |
50 | * to kernel/upper layer | |
876c9d3a | 51 | * |
8973a6e7 RD |
52 | * @priv: A pointer to &struct lbs_private |
53 | * @skb: A pointer to skb which includes the received packet | |
54 | * returns: 0 or -1 | |
876c9d3a | 55 | */ |
69f9032d | 56 | int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb) |
876c9d3a | 57 | { |
876c9d3a | 58 | int ret = 0; |
6f93a8e7 | 59 | struct net_device *dev = priv->dev; |
876c9d3a MT |
60 | struct rxpackethdr *p_rx_pkt; |
61 | struct rxpd *p_rx_pd; | |
876c9d3a MT |
62 | int hdrchop; |
63 | struct ethhdr *p_ethhdr; | |
482e039f JP |
64 | static const u8 rfc1042_eth_hdr[] = { |
65 | 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 | |
66 | }; | |
876c9d3a | 67 | |
9012b28a | 68 | lbs_deb_enter(LBS_DEB_RX); |
876c9d3a | 69 | |
7919b89c HS |
70 | BUG_ON(!skb); |
71 | ||
6f93a8e7 DW |
72 | skb->ip_summed = CHECKSUM_NONE; |
73 | ||
e86dc1ca | 74 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) |
876c9d3a MT |
75 | return process_rxed_802_11_packet(priv, skb); |
76 | ||
e45d8e53 BZ |
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)); | |
e0e42da3 HS |
80 | |
81 | dev = lbs_mesh_set_dev(priv, dev, p_rx_pd); | |
876c9d3a | 82 | |
ece56191 | 83 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, |
876c9d3a MT |
84 | min_t(unsigned int, skb->len, 100)); |
85 | ||
86 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { | |
9012b28a | 87 | lbs_deb_rx("rx err: frame received with bad length\n"); |
bbfc6b78 | 88 | dev->stats.rx_length_errors++; |
876c9d3a | 89 | ret = 0; |
f54930f3 | 90 | dev_kfree_skb(skb); |
876c9d3a MT |
91 | goto done; |
92 | } | |
93 | ||
e45d8e53 | 94 | lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n", |
a2caba6b JL |
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)); | |
876c9d3a | 97 | |
ece56191 | 98 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr, |
876c9d3a | 99 | sizeof(p_rx_pkt->eth803_hdr.dest_addr)); |
ece56191 | 100 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr, |
876c9d3a MT |
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 | * Replace the 803 header and rfc1042 header (llc/snap) with an | |
107 | * EthernetII header, keep the src/dst and snap_type (ethertype) | |
108 | * | |
109 | * The firmware only passes up SNAP frames converting | |
110 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. | |
111 | * | |
112 | * To create the Ethernet II, just move the src, dst address right | |
113 | * before the snap_type. | |
114 | */ | |
115 | p_ethhdr = (struct ethhdr *) | |
819cf15e | 116 | ((u8 *) &p_rx_pkt->eth803_hdr |
876c9d3a MT |
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 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header | |
128 | * that was removed | |
129 | */ | |
e45d8e53 | 130 | hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd; |
876c9d3a | 131 | } else { |
ece56191 | 132 | lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP", |
819cf15e | 133 | (u8 *) &p_rx_pkt->rfc1042_hdr, |
876c9d3a MT |
134 | sizeof(p_rx_pkt->rfc1042_hdr)); |
135 | ||
136 | /* Chop off the rxpd */ | |
e45d8e53 | 137 | hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd; |
876c9d3a MT |
138 | } |
139 | ||
140 | /* Chop off the leading header bytes so the skb points to the start of | |
141 | * either the reconstructed EthII frame or the 802.2/llc/snap frame | |
142 | */ | |
143 | skb_pull(skb, hdrchop); | |
144 | ||
e86dc1ca | 145 | priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate); |
876c9d3a | 146 | |
9012b28a | 147 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
bbfc6b78 SH |
148 | dev->stats.rx_bytes += skb->len; |
149 | dev->stats.rx_packets++; | |
876c9d3a | 150 | |
6f93a8e7 | 151 | skb->protocol = eth_type_trans(skb, dev); |
ae3e0fcf HS |
152 | if (in_interrupt()) |
153 | netif_rx(skb); | |
154 | else | |
155 | netif_rx_ni(skb); | |
3d4bd24b | 156 | |
876c9d3a MT |
157 | ret = 0; |
158 | done: | |
9012b28a | 159 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
876c9d3a MT |
160 | return ret; |
161 | } | |
10078321 | 162 | EXPORT_SYMBOL_GPL(lbs_process_rxed_packet); |
876c9d3a MT |
163 | |
164 | /** | |
8973a6e7 RD |
165 | * convert_mv_rate_to_radiotap - converts Tx/Rx rates from Marvell WLAN format |
166 | * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s) | |
876c9d3a | 167 | * |
8973a6e7 RD |
168 | * @rate: Input rate |
169 | * returns: Output Rate (0 if invalid) | |
876c9d3a MT |
170 | */ |
171 | static u8 convert_mv_rate_to_radiotap(u8 rate) | |
172 | { | |
173 | switch (rate) { | |
174 | case 0: /* 1 Mbps */ | |
175 | return 2; | |
176 | case 1: /* 2 Mbps */ | |
177 | return 4; | |
178 | case 2: /* 5.5 Mbps */ | |
179 | return 11; | |
180 | case 3: /* 11 Mbps */ | |
181 | return 22; | |
965f8bbc LCC |
182 | /* case 4: reserved */ |
183 | case 5: /* 6 Mbps */ | |
876c9d3a | 184 | return 12; |
965f8bbc | 185 | case 6: /* 9 Mbps */ |
876c9d3a | 186 | return 18; |
965f8bbc | 187 | case 7: /* 12 Mbps */ |
876c9d3a | 188 | return 24; |
965f8bbc | 189 | case 8: /* 18 Mbps */ |
876c9d3a | 190 | return 36; |
965f8bbc | 191 | case 9: /* 24 Mbps */ |
876c9d3a | 192 | return 48; |
965f8bbc | 193 | case 10: /* 36 Mbps */ |
876c9d3a | 194 | return 72; |
965f8bbc | 195 | case 11: /* 48 Mbps */ |
876c9d3a | 196 | return 96; |
965f8bbc | 197 | case 12: /* 54 Mbps */ |
876c9d3a MT |
198 | return 108; |
199 | } | |
0e4e06ae | 200 | pr_alert("Invalid Marvell WLAN rate %i\n", rate); |
876c9d3a MT |
201 | return 0; |
202 | } | |
203 | ||
204 | /** | |
8973a6e7 RD |
205 | * process_rxed_802_11_packet - processes a received 802.11 packet and forwards |
206 | * it to kernel/upper layer | |
876c9d3a | 207 | * |
8973a6e7 RD |
208 | * @priv: A pointer to &struct lbs_private |
209 | * @skb: A pointer to skb which includes the received packet | |
210 | * returns: 0 or -1 | |
876c9d3a | 211 | */ |
69f9032d HS |
212 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
213 | struct sk_buff *skb) | |
876c9d3a | 214 | { |
876c9d3a | 215 | int ret = 0; |
bbfc6b78 | 216 | struct net_device *dev = priv->dev; |
876c9d3a MT |
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 | ||
9012b28a | 222 | lbs_deb_enter(LBS_DEB_RX); |
876c9d3a MT |
223 | |
224 | p_rx_pkt = (struct rx80211packethdr *) skb->data; | |
225 | prxpd = &p_rx_pkt->rx_pd; | |
226 | ||
819cf15e | 227 | /* lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100)); */ |
876c9d3a MT |
228 | |
229 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { | |
7bf02c29 | 230 | lbs_deb_rx("rx err: frame received with bad length\n"); |
bbfc6b78 | 231 | dev->stats.rx_length_errors++; |
7bf02c29 | 232 | ret = -EINVAL; |
b700a98c | 233 | kfree_skb(skb); |
876c9d3a MT |
234 | goto done; |
235 | } | |
236 | ||
9012b28a | 237 | lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n", |
876c9d3a MT |
238 | skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); |
239 | ||
240 | /* create the exported radio header */ | |
876c9d3a | 241 | |
180be755 | 242 | /* radiotap header */ |
c6a6368b PB |
243 | memset(&radiotap_hdr, 0, sizeof(radiotap_hdr)); |
244 | /* XXX must check radiotap_hdr.hdr.it_pad for pad */ | |
180be755 DW |
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); | |
180be755 DW |
247 | radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate); |
248 | /* XXX must check no carryout */ | |
249 | radiotap_hdr.antsignal = prxpd->snr + prxpd->nf; | |
180be755 DW |
250 | |
251 | /* chop the rxpd */ | |
252 | skb_pull(skb, sizeof(struct rxpd)); | |
253 | ||
254 | /* add space for the new radio header */ | |
255 | if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) && | |
7bf02c29 | 256 | pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) { |
f3a57fd1 | 257 | netdev_alert(dev, "%s: couldn't pskb_expand_head\n", __func__); |
7bf02c29 DW |
258 | ret = -ENOMEM; |
259 | kfree_skb(skb); | |
260 | goto done; | |
876c9d3a MT |
261 | } |
262 | ||
180be755 DW |
263 | pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr)); |
264 | memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr)); | |
265 | ||
e86dc1ca | 266 | priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate); |
876c9d3a | 267 | |
9012b28a | 268 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
bbfc6b78 SH |
269 | dev->stats.rx_bytes += skb->len; |
270 | dev->stats.rx_packets++; | |
876c9d3a | 271 | |
e86dc1ca KD |
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); | |
3d4bd24b | 278 | |
876c9d3a | 279 | ret = 0; |
876c9d3a | 280 | |
9012b28a | 281 | done: |
9012b28a HS |
282 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
283 | return ret; | |
876c9d3a | 284 | } |