2 * This file contains the handling of RX in wlan driver.
5 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 #include <linux/etherdevice.h>
8 #include <linux/hardirq.h>
9 #include <linux/slab.h>
10 #include <linux/types.h>
11 #include <net/cfg80211.h>
35 struct eth803hdr eth803_hdr
;
36 struct rfc1042hdr rfc1042_hdr
;
39 struct rx80211packethdr
{
44 static int process_rxed_802_11_packet(struct lbs_private
*priv
,
48 * lbs_process_rxed_packet - processes received packet and forwards it
49 * to kernel/upper layer
51 * @priv: A pointer to &struct lbs_private
52 * @skb: A pointer to skb which includes the received packet
55 int lbs_process_rxed_packet(struct lbs_private
*priv
, struct sk_buff
*skb
)
58 struct net_device
*dev
= priv
->dev
;
59 struct rxpackethdr
*p_rx_pkt
;
62 struct ethhdr
*p_ethhdr
;
63 static const u8 rfc1042_eth_hdr
[] = {
64 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
67 lbs_deb_enter(LBS_DEB_RX
);
71 skb
->ip_summed
= CHECKSUM_NONE
;
73 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
74 return process_rxed_802_11_packet(priv
, skb
);
76 p_rx_pd
= (struct rxpd
*) skb
->data
;
77 p_rx_pkt
= (struct rxpackethdr
*) ((u8
*)p_rx_pd
+
78 le32_to_cpu(p_rx_pd
->pkt_ptr
));
80 dev
= lbs_mesh_set_dev(priv
, dev
, p_rx_pd
);
82 lbs_deb_hex(LBS_DEB_RX
, "RX Data: Before chop rxpd", skb
->data
,
83 min_t(unsigned int, skb
->len
, 100));
85 if (skb
->len
< (ETH_HLEN
+ 8 + sizeof(struct rxpd
))) {
86 lbs_deb_rx("rx err: frame received with bad length\n");
87 dev
->stats
.rx_length_errors
++;
93 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
94 skb
->len
, (size_t)le32_to_cpu(p_rx_pd
->pkt_ptr
),
95 skb
->len
- (size_t)le32_to_cpu(p_rx_pd
->pkt_ptr
));
97 lbs_deb_hex(LBS_DEB_RX
, "RX Data: Dest", p_rx_pkt
->eth803_hdr
.dest_addr
,
98 sizeof(p_rx_pkt
->eth803_hdr
.dest_addr
));
99 lbs_deb_hex(LBS_DEB_RX
, "RX Data: Src", p_rx_pkt
->eth803_hdr
.src_addr
,
100 sizeof(p_rx_pkt
->eth803_hdr
.src_addr
));
102 if (memcmp(&p_rx_pkt
->rfc1042_hdr
,
103 rfc1042_eth_hdr
, sizeof(rfc1042_eth_hdr
)) == 0) {
105 * Replace the 803 header and rfc1042 header (llc/snap) with an
106 * EthernetII header, keep the src/dst and snap_type (ethertype)
108 * The firmware only passes up SNAP frames converting
109 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
111 * To create the Ethernet II, just move the src, dst address right
112 * before the snap_type.
114 p_ethhdr
= (struct ethhdr
*)
115 ((u8
*) &p_rx_pkt
->eth803_hdr
116 + sizeof(p_rx_pkt
->eth803_hdr
) + sizeof(p_rx_pkt
->rfc1042_hdr
)
117 - sizeof(p_rx_pkt
->eth803_hdr
.dest_addr
)
118 - sizeof(p_rx_pkt
->eth803_hdr
.src_addr
)
119 - sizeof(p_rx_pkt
->rfc1042_hdr
.snap_type
));
121 memcpy(p_ethhdr
->h_source
, p_rx_pkt
->eth803_hdr
.src_addr
,
122 sizeof(p_ethhdr
->h_source
));
123 memcpy(p_ethhdr
->h_dest
, p_rx_pkt
->eth803_hdr
.dest_addr
,
124 sizeof(p_ethhdr
->h_dest
));
126 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
129 hdrchop
= (u8
*)p_ethhdr
- (u8
*)p_rx_pd
;
131 lbs_deb_hex(LBS_DEB_RX
, "RX Data: LLC/SNAP",
132 (u8
*) &p_rx_pkt
->rfc1042_hdr
,
133 sizeof(p_rx_pkt
->rfc1042_hdr
));
135 /* Chop off the rxpd */
136 hdrchop
= (u8
*)&p_rx_pkt
->eth803_hdr
- (u8
*)p_rx_pd
;
139 /* Chop off the leading header bytes so the skb points to the start of
140 * either the reconstructed EthII frame or the 802.2/llc/snap frame
142 skb_pull(skb
, hdrchop
);
144 priv
->cur_rate
= lbs_fw_index_to_data_rate(p_rx_pd
->rx_rate
);
146 lbs_deb_rx("rx data: size of actual packet %d\n", skb
->len
);
147 dev
->stats
.rx_bytes
+= skb
->len
;
148 dev
->stats
.rx_packets
++;
150 skb
->protocol
= eth_type_trans(skb
, dev
);
158 lbs_deb_leave_args(LBS_DEB_RX
, "ret %d", ret
);
161 EXPORT_SYMBOL_GPL(lbs_process_rxed_packet
);
164 * convert_mv_rate_to_radiotap - converts Tx/Rx rates from Marvell WLAN format
165 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
168 * returns: Output Rate (0 if invalid)
170 static u8
convert_mv_rate_to_radiotap(u8 rate
)
177 case 2: /* 5.5 Mbps */
179 case 3: /* 11 Mbps */
181 /* case 4: reserved */
186 case 7: /* 12 Mbps */
188 case 8: /* 18 Mbps */
190 case 9: /* 24 Mbps */
192 case 10: /* 36 Mbps */
194 case 11: /* 48 Mbps */
196 case 12: /* 54 Mbps */
199 pr_alert("Invalid Marvell WLAN rate %i\n", rate
);
204 * process_rxed_802_11_packet - processes a received 802.11 packet and forwards
205 * it to kernel/upper layer
207 * @priv: A pointer to &struct lbs_private
208 * @skb: A pointer to skb which includes the received packet
211 static int process_rxed_802_11_packet(struct lbs_private
*priv
,
215 struct net_device
*dev
= priv
->dev
;
216 struct rx80211packethdr
*p_rx_pkt
;
218 struct rx_radiotap_hdr radiotap_hdr
;
219 struct rx_radiotap_hdr
*pradiotap_hdr
;
221 lbs_deb_enter(LBS_DEB_RX
);
223 p_rx_pkt
= (struct rx80211packethdr
*) skb
->data
;
224 prxpd
= &p_rx_pkt
->rx_pd
;
226 /* lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100)); */
228 if (skb
->len
< (ETH_HLEN
+ 8 + sizeof(struct rxpd
))) {
229 lbs_deb_rx("rx err: frame received with bad length\n");
230 dev
->stats
.rx_length_errors
++;
236 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
237 skb
->len
, sizeof(struct rxpd
), skb
->len
- sizeof(struct rxpd
));
239 /* create the exported radio header */
241 /* radiotap header */
242 memset(&radiotap_hdr
, 0, sizeof(radiotap_hdr
));
243 /* XXX must check radiotap_hdr.hdr.it_pad for pad */
244 radiotap_hdr
.hdr
.it_len
= cpu_to_le16 (sizeof(struct rx_radiotap_hdr
));
245 radiotap_hdr
.hdr
.it_present
= cpu_to_le32 (RX_RADIOTAP_PRESENT
);
246 radiotap_hdr
.rate
= convert_mv_rate_to_radiotap(prxpd
->rx_rate
);
247 /* XXX must check no carryout */
248 radiotap_hdr
.antsignal
= prxpd
->snr
+ prxpd
->nf
;
251 skb_pull(skb
, sizeof(struct rxpd
));
253 /* add space for the new radio header */
254 if ((skb_headroom(skb
) < sizeof(struct rx_radiotap_hdr
)) &&
255 pskb_expand_head(skb
, sizeof(struct rx_radiotap_hdr
), 0, GFP_ATOMIC
)) {
256 netdev_alert(dev
, "%s: couldn't pskb_expand_head\n", __func__
);
262 pradiotap_hdr
= (void *)skb_push(skb
, sizeof(struct rx_radiotap_hdr
));
263 memcpy(pradiotap_hdr
, &radiotap_hdr
, sizeof(struct rx_radiotap_hdr
));
265 priv
->cur_rate
= lbs_fw_index_to_data_rate(prxpd
->rx_rate
);
267 lbs_deb_rx("rx data: size of actual packet %d\n", skb
->len
);
268 dev
->stats
.rx_bytes
+= skb
->len
;
269 dev
->stats
.rx_packets
++;
271 skb
->protocol
= eth_type_trans(skb
, priv
->dev
);
281 lbs_deb_leave_args(LBS_DEB_RX
, "ret %d", ret
);