blob: 9f18a19cc49d4f4b39c2e1ea7bf6261e2c16642b [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of RX in wlan driver.
3 */
4#include <linux/etherdevice.h>
5#include <linux/types.h>
6
Holger Schurig9e66e702009-10-16 17:32:16 +02007#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#include "radiotap.h"
9#include "decl.h"
10#include "dev.h"
11#include "wext.h"
12
13struct eth803hdr {
14 u8 dest_addr[6];
15 u8 src_addr[6];
16 u16 h803_len;
17} __attribute__ ((packed));
18
19struct rfc1042hdr {
20 u8 llc_dsap;
21 u8 llc_ssap;
22 u8 llc_ctrl;
23 u8 snap_oui[3];
24 u16 snap_type;
25} __attribute__ ((packed));
26
27struct rxpackethdr {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020028 struct eth803hdr eth803_hdr;
29 struct rfc1042hdr rfc1042_hdr;
30} __attribute__ ((packed));
31
32struct rx80211packethdr {
33 struct rxpd rx_pd;
34 void *eth80211_hdr;
35} __attribute__ ((packed));
36
Holger Schurig69f90322007-11-23 15:43:44 +010037static int process_rxed_802_11_packet(struct lbs_private *priv,
38 struct sk_buff *skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039
40/**
41 * @brief This function computes the avgSNR .
42 *
Holger Schurig69f90322007-11-23 15:43:44 +010043 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020044 * @return avgSNR
45 */
Holger Schurig69f90322007-11-23 15:43:44 +010046static u8 lbs_getavgsnr(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020047{
48 u8 i;
49 u16 temp = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000050 if (priv->numSNRNF == 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 return 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000052 for (i = 0; i < priv->numSNRNF; i++)
53 temp += priv->rawSNR[i];
54 return (u8) (temp / priv->numSNRNF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055
56}
57
58/**
59 * @brief This function computes the AvgNF
60 *
Holger Schurig69f90322007-11-23 15:43:44 +010061 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 * @return AvgNF
63 */
Holger Schurig69f90322007-11-23 15:43:44 +010064static u8 lbs_getavgnf(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065{
66 u8 i;
67 u16 temp = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000068 if (priv->numSNRNF == 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 return 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000070 for (i = 0; i < priv->numSNRNF; i++)
71 temp += priv->rawNF[i];
72 return (u8) (temp / priv->numSNRNF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073
74}
75
76/**
77 * @brief This function save the raw SNR/NF to our internel buffer
78 *
Holger Schurig69f90322007-11-23 15:43:44 +010079 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020080 * @param prxpd A pointer to rxpd structure of received packet
81 * @return n/a
82 */
Holger Schurig69f90322007-11-23 15:43:44 +010083static void lbs_save_rawSNRNF(struct lbs_private *priv, struct rxpd *p_rx_pd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084{
David Woodhouseaa21c002007-12-08 20:04:36 +000085 if (priv->numSNRNF < DEFAULT_DATA_AVG_FACTOR)
86 priv->numSNRNF++;
87 priv->rawSNR[priv->nextSNRNF] = p_rx_pd->snr;
88 priv->rawNF[priv->nextSNRNF] = p_rx_pd->nf;
89 priv->nextSNRNF++;
90 if (priv->nextSNRNF >= DEFAULT_DATA_AVG_FACTOR)
91 priv->nextSNRNF = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092 return;
93}
94
95/**
96 * @brief This function computes the RSSI in received packet.
97 *
Holger Schurig69f90322007-11-23 15:43:44 +010098 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099 * @param prxpd A pointer to rxpd structure of received packet
100 * @return n/a
101 */
Holger Schurig69f90322007-11-23 15:43:44 +0100102static void lbs_compute_rssi(struct lbs_private *priv, struct rxpd *p_rx_pd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104
Holger Schurig9012b282007-05-25 11:27:16 -0400105 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106
Holger Schurig9012b282007-05-25 11:27:16 -0400107 lbs_deb_rx("rxpd: SNR %d, NF %d\n", p_rx_pd->snr, p_rx_pd->nf);
108 lbs_deb_rx("before computing SNR: SNR-avg = %d, NF-avg = %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000109 priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
110 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111
David Woodhouseaa21c002007-12-08 20:04:36 +0000112 priv->SNR[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->snr;
113 priv->NF[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->nf;
Holger Schurig10078322007-11-15 18:05:47 -0500114 lbs_save_rawSNRNF(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
David Woodhouseaa21c002007-12-08 20:04:36 +0000116 priv->SNR[TYPE_RXPD][TYPE_AVG] = lbs_getavgsnr(priv) * AVG_SCALE;
117 priv->NF[TYPE_RXPD][TYPE_AVG] = lbs_getavgnf(priv) * AVG_SCALE;
Holger Schurig9012b282007-05-25 11:27:16 -0400118 lbs_deb_rx("after computing SNR: SNR-avg = %d, NF-avg = %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000119 priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
120 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121
David Woodhouseaa21c002007-12-08 20:04:36 +0000122 priv->RSSI[TYPE_RXPD][TYPE_NOAVG] =
123 CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_NOAVG],
124 priv->NF[TYPE_RXPD][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125
David Woodhouseaa21c002007-12-08 20:04:36 +0000126 priv->RSSI[TYPE_RXPD][TYPE_AVG] =
127 CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
128 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129
Holger Schurig9012b282007-05-25 11:27:16 -0400130 lbs_deb_leave(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131}
132
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133/**
134 * @brief This function processes received packet and forwards it
135 * to kernel/upper layer
136 *
Holger Schurig69f90322007-11-23 15:43:44 +0100137 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 * @param skb A pointer to skb which includes the received packet
139 * @return 0 or -1
140 */
Holger Schurig69f90322007-11-23 15:43:44 +0100141int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 int ret = 0;
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500144 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145 struct rxpackethdr *p_rx_pkt;
146 struct rxpd *p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147 int hdrchop;
148 struct ethhdr *p_ethhdr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
150
Holger Schurig9012b282007-05-25 11:27:16 -0400151 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
Holger Schurig7919b892008-04-01 14:50:43 +0200153 BUG_ON(!skb);
154
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500155 skb->ip_summed = CHECKSUM_NONE;
156
Holger Schurigc2b310a2008-03-26 09:57:14 +0100157 if (priv->monitormode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 return process_rxed_802_11_packet(priv, skb);
159
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700160 p_rx_pd = (struct rxpd *) skb->data;
161 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd +
162 le32_to_cpu(p_rx_pd->pkt_ptr));
Bing Zhao684d6b32009-03-25 09:51:16 -0700163 if (priv->mesh_dev) {
164 if (priv->mesh_fw_ver == MESH_FW_OLD) {
165 if (p_rx_pd->rx_control & RxPD_MESH_FRAME)
166 dev = priv->mesh_dev;
167 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
168 if (p_rx_pd->u.bss.bss_num == MESH_IFACE_ID)
169 dev = priv->mesh_dev;
170 }
171 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172
Holger Schurigece56192007-08-02 11:53:06 -0400173 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174 min_t(unsigned int, skb->len, 100));
175
176 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400177 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000178 dev->stats.rx_length_errors++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 ret = 0;
Philip Rakityf54930f2009-04-07 12:41:17 -0700180 dev_kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181 goto done;
182 }
183
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700184 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
John W. Linvillea2caba62009-04-14 11:45:57 -0400185 skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr),
186 skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187
Holger Schurigece56192007-08-02 11:53:06 -0400188 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
Holger Schurigece56192007-08-02 11:53:06 -0400190 lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191 sizeof(p_rx_pkt->eth803_hdr.src_addr));
192
193 if (memcmp(&p_rx_pkt->rfc1042_hdr,
194 rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
195 /*
196 * Replace the 803 header and rfc1042 header (llc/snap) with an
197 * EthernetII header, keep the src/dst and snap_type (ethertype)
198 *
199 * The firmware only passes up SNAP frames converting
200 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
201 *
202 * To create the Ethernet II, just move the src, dst address right
203 * before the snap_type.
204 */
205 p_ethhdr = (struct ethhdr *)
206 ((u8 *) & p_rx_pkt->eth803_hdr
207 + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr)
208 - sizeof(p_rx_pkt->eth803_hdr.dest_addr)
209 - sizeof(p_rx_pkt->eth803_hdr.src_addr)
210 - sizeof(p_rx_pkt->rfc1042_hdr.snap_type));
211
212 memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr,
213 sizeof(p_ethhdr->h_source));
214 memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr,
215 sizeof(p_ethhdr->h_dest));
216
217 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
218 * that was removed
219 */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700220 hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 } else {
Holger Schurigece56192007-08-02 11:53:06 -0400222 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223 (u8 *) & p_rx_pkt->rfc1042_hdr,
224 sizeof(p_rx_pkt->rfc1042_hdr));
225
226 /* Chop off the rxpd */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700227 hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 }
229
230 /* Chop off the leading header bytes so the skb points to the start of
231 * either the reconstructed EthII frame or the 802.2/llc/snap frame
232 */
233 skb_pull(skb, hdrchop);
234
235 /* Take the data rate from the rxpd structure
236 * only if the rate is auto
237 */
Javier Cardona85319f92008-05-24 10:59:49 +0100238 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000239 priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
Holger Schurig10078322007-11-15 18:05:47 -0500241 lbs_compute_rssi(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242
Holger Schurig9012b282007-05-25 11:27:16 -0400243 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000244 dev->stats.rx_bytes += skb->len;
245 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500247 skb->protocol = eth_type_trans(skb, dev);
Holger Schurigae3e0fc2008-01-16 15:48:44 +0100248 if (in_interrupt())
249 netif_rx(skb);
250 else
251 netif_rx_ni(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400252
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253 ret = 0;
254done:
Holger Schurig9012b282007-05-25 11:27:16 -0400255 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256 return ret;
257}
Holger Schurig10078322007-11-15 18:05:47 -0500258EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259
260/**
261 * @brief This function converts Tx/Rx rates from the Marvell WLAN format
262 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
263 *
264 * @param rate Input rate
265 * @return Output Rate (0 if invalid)
266 */
267static u8 convert_mv_rate_to_radiotap(u8 rate)
268{
269 switch (rate) {
270 case 0: /* 1 Mbps */
271 return 2;
272 case 1: /* 2 Mbps */
273 return 4;
274 case 2: /* 5.5 Mbps */
275 return 11;
276 case 3: /* 11 Mbps */
277 return 22;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400278 /* case 4: reserved */
279 case 5: /* 6 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280 return 12;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400281 case 6: /* 9 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 return 18;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400283 case 7: /* 12 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200284 return 24;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400285 case 8: /* 18 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 return 36;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400287 case 9: /* 24 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288 return 48;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400289 case 10: /* 36 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290 return 72;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400291 case 11: /* 48 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200292 return 96;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400293 case 12: /* 54 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294 return 108;
295 }
Holger Schurig9012b282007-05-25 11:27:16 -0400296 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297 return 0;
298}
299
300/**
301 * @brief This function processes a received 802.11 packet and forwards it
302 * to kernel/upper layer
303 *
Holger Schurig69f90322007-11-23 15:43:44 +0100304 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 * @param skb A pointer to skb which includes the received packet
306 * @return 0 or -1
307 */
Holger Schurig69f90322007-11-23 15:43:44 +0100308static int process_rxed_802_11_packet(struct lbs_private *priv,
309 struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311 int ret = 0;
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000312 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313 struct rx80211packethdr *p_rx_pkt;
314 struct rxpd *prxpd;
315 struct rx_radiotap_hdr radiotap_hdr;
316 struct rx_radiotap_hdr *pradiotap_hdr;
317
Holger Schurig9012b282007-05-25 11:27:16 -0400318 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319
320 p_rx_pkt = (struct rx80211packethdr *) skb->data;
321 prxpd = &p_rx_pkt->rx_pd;
322
Holger Schurigece56192007-08-02 11:53:06 -0400323 // lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324
325 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
David Woodhouse7bf02c22007-12-10 00:17:28 -0500326 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000327 dev->stats.rx_length_errors++;
David Woodhouse7bf02c22007-12-10 00:17:28 -0500328 ret = -EINVAL;
Sergio Luisb700a982008-10-26 23:09:27 -0700329 kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330 goto done;
331 }
332
Holger Schurig9012b282007-05-25 11:27:16 -0400333 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
335
336 /* create the exported radio header */
David Woodhouse180be752007-12-10 00:05:37 -0500337
338 /* radiotap header */
339 radiotap_hdr.hdr.it_version = 0;
340 /* XXX must check this value for pad */
341 radiotap_hdr.hdr.it_pad = 0;
342 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
343 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
David Woodhouse180be752007-12-10 00:05:37 -0500344 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
345 /* XXX must check no carryout */
346 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
David Woodhouse180be752007-12-10 00:05:37 -0500347
348 /* chop the rxpd */
349 skb_pull(skb, sizeof(struct rxpd));
350
351 /* add space for the new radio header */
352 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
David Woodhouse7bf02c22007-12-10 00:17:28 -0500353 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
354 lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__);
355 ret = -ENOMEM;
356 kfree_skb(skb);
357 goto done;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400358 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359
David Woodhouse180be752007-12-10 00:05:37 -0500360 pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr));
361 memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
363 /* Take the data rate from the rxpd structure
364 * only if the rate is auto
365 */
Javier Cardona85319f92008-05-24 10:59:49 +0100366 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000367 priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368
Holger Schurig10078322007-11-15 18:05:47 -0500369 lbs_compute_rssi(priv, prxpd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370
Holger Schurig9012b282007-05-25 11:27:16 -0400371 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000372 dev->stats.rx_bytes += skb->len;
373 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500375 skb->protocol = eth_type_trans(skb, priv->rtap_net_dev);
376 netif_rx(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400377
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379
Holger Schurig9012b282007-05-25 11:27:16 -0400380done:
Holger Schurig9012b282007-05-25 11:27:16 -0400381 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
382 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383}