blob: 784dae7147055b64b91821b5366887e4c72c6bb0 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include <linux/types.h>
7
Holger Schurig9e66e702009-10-16 17:32:16 +02008#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include "radiotap.h"
10#include "decl.h"
11#include "dev.h"
12#include "wext.h"
13
14struct eth803hdr {
15 u8 dest_addr[6];
16 u8 src_addr[6];
17 u16 h803_len;
18} __attribute__ ((packed));
19
20struct rfc1042hdr {
21 u8 llc_dsap;
22 u8 llc_ssap;
23 u8 llc_ctrl;
24 u8 snap_oui[3];
25 u16 snap_type;
26} __attribute__ ((packed));
27
28struct rxpackethdr {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029 struct eth803hdr eth803_hdr;
30 struct rfc1042hdr rfc1042_hdr;
31} __attribute__ ((packed));
32
33struct rx80211packethdr {
34 struct rxpd rx_pd;
35 void *eth80211_hdr;
36} __attribute__ ((packed));
37
Holger Schurig69f90322007-11-23 15:43:44 +010038static int process_rxed_802_11_packet(struct lbs_private *priv,
39 struct sk_buff *skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020040
41/**
42 * @brief This function computes the avgSNR .
43 *
Holger Schurig69f90322007-11-23 15:43:44 +010044 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045 * @return avgSNR
46 */
Holger Schurig69f90322007-11-23 15:43:44 +010047static u8 lbs_getavgsnr(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048{
49 u8 i;
50 u16 temp = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000051 if (priv->numSNRNF == 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052 return 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000053 for (i = 0; i < priv->numSNRNF; i++)
54 temp += priv->rawSNR[i];
55 return (u8) (temp / priv->numSNRNF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020056
57}
58
59/**
60 * @brief This function computes the AvgNF
61 *
Holger Schurig69f90322007-11-23 15:43:44 +010062 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 * @return AvgNF
64 */
Holger Schurig69f90322007-11-23 15:43:44 +010065static u8 lbs_getavgnf(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066{
67 u8 i;
68 u16 temp = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000069 if (priv->numSNRNF == 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070 return 0;
David Woodhouseaa21c002007-12-08 20:04:36 +000071 for (i = 0; i < priv->numSNRNF; i++)
72 temp += priv->rawNF[i];
73 return (u8) (temp / priv->numSNRNF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074
75}
76
77/**
78 * @brief This function save the raw SNR/NF to our internel buffer
79 *
Holger Schurig69f90322007-11-23 15:43:44 +010080 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020081 * @param prxpd A pointer to rxpd structure of received packet
82 * @return n/a
83 */
Holger Schurig69f90322007-11-23 15:43:44 +010084static void lbs_save_rawSNRNF(struct lbs_private *priv, struct rxpd *p_rx_pd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085{
David Woodhouseaa21c002007-12-08 20:04:36 +000086 if (priv->numSNRNF < DEFAULT_DATA_AVG_FACTOR)
87 priv->numSNRNF++;
88 priv->rawSNR[priv->nextSNRNF] = p_rx_pd->snr;
89 priv->rawNF[priv->nextSNRNF] = p_rx_pd->nf;
90 priv->nextSNRNF++;
91 if (priv->nextSNRNF >= DEFAULT_DATA_AVG_FACTOR)
92 priv->nextSNRNF = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 return;
94}
95
96/**
97 * @brief This function computes the RSSI in received packet.
98 *
Holger Schurig69f90322007-11-23 15:43:44 +010099 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100 * @param prxpd A pointer to rxpd structure of received packet
101 * @return n/a
102 */
Holger Schurig69f90322007-11-23 15:43:44 +0100103static void lbs_compute_rssi(struct lbs_private *priv, struct rxpd *p_rx_pd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105
Holger Schurig9012b282007-05-25 11:27:16 -0400106 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107
Holger Schurig9012b282007-05-25 11:27:16 -0400108 lbs_deb_rx("rxpd: SNR %d, NF %d\n", p_rx_pd->snr, p_rx_pd->nf);
109 lbs_deb_rx("before computing SNR: SNR-avg = %d, NF-avg = %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000110 priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
111 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200112
David Woodhouseaa21c002007-12-08 20:04:36 +0000113 priv->SNR[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->snr;
114 priv->NF[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->nf;
Holger Schurig10078322007-11-15 18:05:47 -0500115 lbs_save_rawSNRNF(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116
David Woodhouseaa21c002007-12-08 20:04:36 +0000117 priv->SNR[TYPE_RXPD][TYPE_AVG] = lbs_getavgsnr(priv) * AVG_SCALE;
118 priv->NF[TYPE_RXPD][TYPE_AVG] = lbs_getavgnf(priv) * AVG_SCALE;
Holger Schurig9012b282007-05-25 11:27:16 -0400119 lbs_deb_rx("after computing SNR: SNR-avg = %d, NF-avg = %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000120 priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
121 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
David Woodhouseaa21c002007-12-08 20:04:36 +0000123 priv->RSSI[TYPE_RXPD][TYPE_NOAVG] =
124 CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_NOAVG],
125 priv->NF[TYPE_RXPD][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126
David Woodhouseaa21c002007-12-08 20:04:36 +0000127 priv->RSSI[TYPE_RXPD][TYPE_AVG] =
128 CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
129 priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
Holger Schurig9012b282007-05-25 11:27:16 -0400131 lbs_deb_leave(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132}
133
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134/**
135 * @brief This function processes received packet and forwards it
136 * to kernel/upper layer
137 *
Holger Schurig69f90322007-11-23 15:43:44 +0100138 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 * @param skb A pointer to skb which includes the received packet
140 * @return 0 or -1
141 */
Holger Schurig69f90322007-11-23 15:43:44 +0100142int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 int ret = 0;
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500145 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146 struct rxpackethdr *p_rx_pkt;
147 struct rxpd *p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148 int hdrchop;
149 struct ethhdr *p_ethhdr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
151
Holger Schurig9012b282007-05-25 11:27:16 -0400152 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153
Holger Schurig7919b892008-04-01 14:50:43 +0200154 BUG_ON(!skb);
155
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500156 skb->ip_summed = CHECKSUM_NONE;
157
Holger Schurigc2b310a2008-03-26 09:57:14 +0100158 if (priv->monitormode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 return process_rxed_802_11_packet(priv, skb);
160
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700161 p_rx_pd = (struct rxpd *) skb->data;
162 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd +
163 le32_to_cpu(p_rx_pd->pkt_ptr));
Holger Schurige0e42da2009-11-25 13:10:15 +0100164
165 dev = lbs_mesh_set_dev(priv, dev, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166
Holger Schurigece56192007-08-02 11:53:06 -0400167 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168 min_t(unsigned int, skb->len, 100));
169
170 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400171 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000172 dev->stats.rx_length_errors++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173 ret = 0;
Philip Rakityf54930f2009-04-07 12:41:17 -0700174 dev_kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 goto done;
176 }
177
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700178 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
John W. Linvillea2caba62009-04-14 11:45:57 -0400179 skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr),
180 skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181
Holger Schurigece56192007-08-02 11:53:06 -0400182 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
Holger Schurigece56192007-08-02 11:53:06 -0400184 lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 sizeof(p_rx_pkt->eth803_hdr.src_addr));
186
187 if (memcmp(&p_rx_pkt->rfc1042_hdr,
188 rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
189 /*
190 * Replace the 803 header and rfc1042 header (llc/snap) with an
191 * EthernetII header, keep the src/dst and snap_type (ethertype)
192 *
193 * The firmware only passes up SNAP frames converting
194 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
195 *
196 * To create the Ethernet II, just move the src, dst address right
197 * before the snap_type.
198 */
199 p_ethhdr = (struct ethhdr *)
200 ((u8 *) & p_rx_pkt->eth803_hdr
201 + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr)
202 - sizeof(p_rx_pkt->eth803_hdr.dest_addr)
203 - sizeof(p_rx_pkt->eth803_hdr.src_addr)
204 - sizeof(p_rx_pkt->rfc1042_hdr.snap_type));
205
206 memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr,
207 sizeof(p_ethhdr->h_source));
208 memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr,
209 sizeof(p_ethhdr->h_dest));
210
211 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
212 * that was removed
213 */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700214 hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215 } else {
Holger Schurigece56192007-08-02 11:53:06 -0400216 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 (u8 *) & p_rx_pkt->rfc1042_hdr,
218 sizeof(p_rx_pkt->rfc1042_hdr));
219
220 /* Chop off the rxpd */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700221 hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222 }
223
224 /* Chop off the leading header bytes so the skb points to the start of
225 * either the reconstructed EthII frame or the 802.2/llc/snap frame
226 */
227 skb_pull(skb, hdrchop);
228
229 /* Take the data rate from the rxpd structure
230 * only if the rate is auto
231 */
Javier Cardona85319f92008-05-24 10:59:49 +0100232 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000233 priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
Holger Schurig10078322007-11-15 18:05:47 -0500235 lbs_compute_rssi(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236
Holger Schurig9012b282007-05-25 11:27:16 -0400237 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000238 dev->stats.rx_bytes += skb->len;
239 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500241 skb->protocol = eth_type_trans(skb, dev);
Holger Schurigae3e0fc2008-01-16 15:48:44 +0100242 if (in_interrupt())
243 netif_rx(skb);
244 else
245 netif_rx_ni(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400246
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 ret = 0;
248done:
Holger Schurig9012b282007-05-25 11:27:16 -0400249 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250 return ret;
251}
Holger Schurig10078322007-11-15 18:05:47 -0500252EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253
254/**
255 * @brief This function converts Tx/Rx rates from the Marvell WLAN format
256 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
257 *
258 * @param rate Input rate
259 * @return Output Rate (0 if invalid)
260 */
261static u8 convert_mv_rate_to_radiotap(u8 rate)
262{
263 switch (rate) {
264 case 0: /* 1 Mbps */
265 return 2;
266 case 1: /* 2 Mbps */
267 return 4;
268 case 2: /* 5.5 Mbps */
269 return 11;
270 case 3: /* 11 Mbps */
271 return 22;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400272 /* case 4: reserved */
273 case 5: /* 6 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200274 return 12;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400275 case 6: /* 9 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276 return 18;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400277 case 7: /* 12 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278 return 24;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400279 case 8: /* 18 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280 return 36;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400281 case 9: /* 24 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 return 48;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400283 case 10: /* 36 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200284 return 72;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400285 case 11: /* 48 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 return 96;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400287 case 12: /* 54 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288 return 108;
289 }
Holger Schurig9012b282007-05-25 11:27:16 -0400290 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291 return 0;
292}
293
294/**
295 * @brief This function processes a received 802.11 packet and forwards it
296 * to kernel/upper layer
297 *
Holger Schurig69f90322007-11-23 15:43:44 +0100298 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299 * @param skb A pointer to skb which includes the received packet
300 * @return 0 or -1
301 */
Holger Schurig69f90322007-11-23 15:43:44 +0100302static int process_rxed_802_11_packet(struct lbs_private *priv,
303 struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 int ret = 0;
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000306 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 struct rx80211packethdr *p_rx_pkt;
308 struct rxpd *prxpd;
309 struct rx_radiotap_hdr radiotap_hdr;
310 struct rx_radiotap_hdr *pradiotap_hdr;
311
Holger Schurig9012b282007-05-25 11:27:16 -0400312 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313
314 p_rx_pkt = (struct rx80211packethdr *) skb->data;
315 prxpd = &p_rx_pkt->rx_pd;
316
Holger Schurigece56192007-08-02 11:53:06 -0400317 // lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318
319 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
David Woodhouse7bf02c22007-12-10 00:17:28 -0500320 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000321 dev->stats.rx_length_errors++;
David Woodhouse7bf02c22007-12-10 00:17:28 -0500322 ret = -EINVAL;
Sergio Luisb700a982008-10-26 23:09:27 -0700323 kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324 goto done;
325 }
326
Holger Schurig9012b282007-05-25 11:27:16 -0400327 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
329
330 /* create the exported radio header */
David Woodhouse180be752007-12-10 00:05:37 -0500331
332 /* radiotap header */
333 radiotap_hdr.hdr.it_version = 0;
334 /* XXX must check this value for pad */
335 radiotap_hdr.hdr.it_pad = 0;
336 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
337 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
David Woodhouse180be752007-12-10 00:05:37 -0500338 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
339 /* XXX must check no carryout */
340 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
David Woodhouse180be752007-12-10 00:05:37 -0500341
342 /* chop the rxpd */
343 skb_pull(skb, sizeof(struct rxpd));
344
345 /* add space for the new radio header */
346 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
David Woodhouse7bf02c22007-12-10 00:17:28 -0500347 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
348 lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__);
349 ret = -ENOMEM;
350 kfree_skb(skb);
351 goto done;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400352 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353
David Woodhouse180be752007-12-10 00:05:37 -0500354 pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr));
355 memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356
357 /* Take the data rate from the rxpd structure
358 * only if the rate is auto
359 */
Javier Cardona85319f92008-05-24 10:59:49 +0100360 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000361 priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
Holger Schurig10078322007-11-15 18:05:47 -0500363 lbs_compute_rssi(priv, prxpd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Holger Schurig9012b282007-05-25 11:27:16 -0400365 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000366 dev->stats.rx_bytes += skb->len;
367 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500369 skb->protocol = eth_type_trans(skb, priv->rtap_net_dev);
370 netif_rx(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400371
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373
Holger Schurig9012b282007-05-25 11:27:16 -0400374done:
Holger Schurig9012b282007-05-25 11:27:16 -0400375 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
376 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377}