2 * This file contains the handling of RX in wlan driver.
4 #include <linux/etherdevice.h>
5 #include <linux/slab.h>
6 #include <linux/types.h>
7 #include <net/cfg80211.h>
30 struct eth803hdr eth803_hdr
;
31 struct rfc1042hdr rfc1042_hdr
;
34 struct rx80211packethdr
{
39 static int process_rxed_802_11_packet(struct lbs_private
*priv
,
43 * @brief This function processes received packet and forwards it
44 * to kernel/upper layer
46 * @param priv A pointer to struct lbs_private
47 * @param skb A pointer to skb which includes the received packet
50 int lbs_process_rxed_packet(struct lbs_private
*priv
, struct sk_buff
*skb
)
53 struct net_device
*dev
= priv
->dev
;
54 struct rxpackethdr
*p_rx_pkt
;
57 struct ethhdr
*p_ethhdr
;
58 static const u8 rfc1042_eth_hdr
[] = {
59 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
62 lbs_deb_enter(LBS_DEB_RX
);
66 skb
->ip_summed
= CHECKSUM_NONE
;
68 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
69 return process_rxed_802_11_packet(priv
, skb
);
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
));
75 dev
= lbs_mesh_set_dev(priv
, dev
, p_rx_pd
);
77 lbs_deb_hex(LBS_DEB_RX
, "RX Data: Before chop rxpd", skb
->data
,
78 min_t(unsigned int, skb
->len
, 100));
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
++;
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
));
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
));
97 if (memcmp(&p_rx_pkt
->rfc1042_hdr
,
98 rfc1042_eth_hdr
, sizeof(rfc1042_eth_hdr
)) == 0) {
100 * Replace the 803 header and rfc1042 header (llc/snap) with an
101 * EthernetII header, keep the src/dst and snap_type (ethertype)
103 * The firmware only passes up SNAP frames converting
104 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
106 * To create the Ethernet II, just move the src, dst address right
107 * before the snap_type.
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
));
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
));
121 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
124 hdrchop
= (u8
*)p_ethhdr
- (u8
*)p_rx_pd
;
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
));
130 /* Chop off the rxpd */
131 hdrchop
= (u8
*)&p_rx_pkt
->eth803_hdr
- (u8
*)p_rx_pd
;
134 /* Chop off the leading header bytes so the skb points to the start of
135 * either the reconstructed EthII frame or the 802.2/llc/snap frame
137 skb_pull(skb
, hdrchop
);
139 priv
->cur_rate
= lbs_fw_index_to_data_rate(p_rx_pd
->rx_rate
);
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
++;
145 skb
->protocol
= eth_type_trans(skb
, dev
);
153 lbs_deb_leave_args(LBS_DEB_RX
, "ret %d", ret
);
156 EXPORT_SYMBOL_GPL(lbs_process_rxed_packet
);
159 * @brief This function converts Tx/Rx rates from the Marvell WLAN format
160 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
162 * @param rate Input rate
163 * @return Output Rate (0 if invalid)
165 static u8
convert_mv_rate_to_radiotap(u8 rate
)
172 case 2: /* 5.5 Mbps */
174 case 3: /* 11 Mbps */
176 /* case 4: reserved */
181 case 7: /* 12 Mbps */
183 case 8: /* 18 Mbps */
185 case 9: /* 24 Mbps */
187 case 10: /* 36 Mbps */
189 case 11: /* 48 Mbps */
191 case 12: /* 54 Mbps */
194 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate
);
199 * @brief This function processes a received 802.11 packet and forwards it
200 * to kernel/upper layer
202 * @param priv A pointer to struct lbs_private
203 * @param skb A pointer to skb which includes the received packet
206 static int process_rxed_802_11_packet(struct lbs_private
*priv
,
210 struct net_device
*dev
= priv
->dev
;
211 struct rx80211packethdr
*p_rx_pkt
;
213 struct rx_radiotap_hdr radiotap_hdr
;
214 struct rx_radiotap_hdr
*pradiotap_hdr
;
216 lbs_deb_enter(LBS_DEB_RX
);
218 p_rx_pkt
= (struct rx80211packethdr
*) skb
->data
;
219 prxpd
= &p_rx_pkt
->rx_pd
;
221 /* lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100)); */
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
++;
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
));
234 /* create the exported radio header */
236 /* radiotap header */
237 memset(&radiotap_hdr
, 0, sizeof(radiotap_hdr
));
238 /* XXX must check radiotap_hdr.hdr.it_pad for pad */
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 /* XXX must check no carryout */
243 radiotap_hdr
.antsignal
= prxpd
->snr
+ prxpd
->nf
;
246 skb_pull(skb
, sizeof(struct rxpd
));
248 /* add space for the new radio header */
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__
);
257 pradiotap_hdr
= (void *)skb_push(skb
, sizeof(struct rx_radiotap_hdr
));
258 memcpy(pradiotap_hdr
, &radiotap_hdr
, sizeof(struct rx_radiotap_hdr
));
260 priv
->cur_rate
= lbs_fw_index_to_data_rate(prxpd
->rx_rate
);
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
++;
266 skb
->protocol
= eth_type_trans(skb
, priv
->dev
);
276 lbs_deb_leave_args(LBS_DEB_RX
, "ret %d", ret
);