blob: 1c63f8ce73494ecc328f71262e08688fcdbe71f5 [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;
Eric Dumazetba2d3582010-06-02 18:10:09 +000018} __packed;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019
20struct rfc1042hdr {
21 u8 llc_dsap;
22 u8 llc_ssap;
23 u8 llc_ctrl;
24 u8 snap_oui[3];
25 u16 snap_type;
Eric Dumazetba2d3582010-06-02 18:10:09 +000026} __packed;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027
28struct rxpackethdr {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029 struct eth803hdr eth803_hdr;
30 struct rfc1042hdr rfc1042_hdr;
Eric Dumazetba2d3582010-06-02 18:10:09 +000031} __packed;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020032
33struct rx80211packethdr {
34 struct rxpd rx_pd;
35 void *eth80211_hdr;
Eric Dumazetba2d3582010-06-02 18:10:09 +000036} __packed;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020037
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/**
Stewart Malik819cf152010-03-11 20:28:29 +103042 * @brief This function computes the avgSNR .
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020043 *
Stewart Malik819cf152010-03-11 20:28:29 +103044 * @param priv A pointer to struct lbs_private structure
45 * @return avgSNR
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 */
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/**
Stewart Malik819cf152010-03-11 20:28:29 +103060 * @brief This function computes the AvgNF
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061 *
Stewart Malik819cf152010-03-11 20:28:29 +103062 * @param priv A pointer to struct lbs_private structure
63 * @return AvgNF
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 */
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/**
Stewart Malik819cf152010-03-11 20:28:29 +103078 * @brief This function save the raw SNR/NF to our internel buffer
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020079 *
Stewart Malik819cf152010-03-11 20:28:29 +103080 * @param priv A pointer to struct lbs_private structure
81 * @param prxpd A pointer to rxpd structure of received packet
82 * @return n/a
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083 */
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}
94
95/**
Stewart Malik819cf152010-03-11 20:28:29 +103096 * @brief This function computes the RSSI in received packet.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020097 *
Stewart Malik819cf152010-03-11 20:28:29 +103098 * @param priv A pointer to struct lbs_private structure
99 * @param prxpd A pointer to rxpd structure of received packet
100 * @return n/a
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200101 */
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 *
Stewart Malik819cf152010-03-11 20:28:29 +1030137 * @param priv A pointer to struct lbs_private
138 * @param skb A pointer to skb which includes the received packet
139 * @return 0 or -1
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 */
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));
Holger Schurige0e42da2009-11-25 13:10:15 +0100163
164 dev = lbs_mesh_set_dev(priv, dev, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
Holger Schurigece56192007-08-02 11:53:06 -0400166 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167 min_t(unsigned int, skb->len, 100));
168
169 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000171 dev->stats.rx_length_errors++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172 ret = 0;
Philip Rakityf54930f2009-04-07 12:41:17 -0700173 dev_kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174 goto done;
175 }
176
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700177 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
John W. Linvillea2caba62009-04-14 11:45:57 -0400178 skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr),
179 skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180
Holger Schurigece56192007-08-02 11:53:06 -0400181 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
Holger Schurigece56192007-08-02 11:53:06 -0400183 lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184 sizeof(p_rx_pkt->eth803_hdr.src_addr));
185
186 if (memcmp(&p_rx_pkt->rfc1042_hdr,
187 rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
188 /*
189 * Replace the 803 header and rfc1042 header (llc/snap) with an
190 * EthernetII header, keep the src/dst and snap_type (ethertype)
191 *
192 * The firmware only passes up SNAP frames converting
193 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
194 *
195 * To create the Ethernet II, just move the src, dst address right
196 * before the snap_type.
197 */
198 p_ethhdr = (struct ethhdr *)
Stewart Malik819cf152010-03-11 20:28:29 +1030199 ((u8 *) &p_rx_pkt->eth803_hdr
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr)
201 - sizeof(p_rx_pkt->eth803_hdr.dest_addr)
202 - sizeof(p_rx_pkt->eth803_hdr.src_addr)
203 - sizeof(p_rx_pkt->rfc1042_hdr.snap_type));
204
205 memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr,
206 sizeof(p_ethhdr->h_source));
207 memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr,
208 sizeof(p_ethhdr->h_dest));
209
210 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
211 * that was removed
212 */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700213 hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 } else {
Holger Schurigece56192007-08-02 11:53:06 -0400215 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
Stewart Malik819cf152010-03-11 20:28:29 +1030216 (u8 *) &p_rx_pkt->rfc1042_hdr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 sizeof(p_rx_pkt->rfc1042_hdr));
218
219 /* Chop off the rxpd */
Bing Zhaoe45d8e52009-04-06 15:50:56 -0700220 hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 }
222
223 /* Chop off the leading header bytes so the skb points to the start of
224 * either the reconstructed EthII frame or the 802.2/llc/snap frame
225 */
226 skb_pull(skb, hdrchop);
227
228 /* Take the data rate from the rxpd structure
229 * only if the rate is auto
230 */
Javier Cardona85319f92008-05-24 10:59:49 +0100231 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000232 priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233
Holger Schurig10078322007-11-15 18:05:47 -0500234 lbs_compute_rssi(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235
Holger Schurig9012b282007-05-25 11:27:16 -0400236 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000237 dev->stats.rx_bytes += skb->len;
238 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500240 skb->protocol = eth_type_trans(skb, dev);
Holger Schurigae3e0fc2008-01-16 15:48:44 +0100241 if (in_interrupt())
242 netif_rx(skb);
243 else
244 netif_rx_ni(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400245
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 ret = 0;
247done:
Holger Schurig9012b282007-05-25 11:27:16 -0400248 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 return ret;
250}
Holger Schurig10078322007-11-15 18:05:47 -0500251EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252
253/**
254 * @brief This function converts Tx/Rx rates from the Marvell WLAN format
255 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
256 *
Stewart Malik819cf152010-03-11 20:28:29 +1030257 * @param rate Input rate
258 * @return Output Rate (0 if invalid)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259 */
260static u8 convert_mv_rate_to_radiotap(u8 rate)
261{
262 switch (rate) {
263 case 0: /* 1 Mbps */
264 return 2;
265 case 1: /* 2 Mbps */
266 return 4;
267 case 2: /* 5.5 Mbps */
268 return 11;
269 case 3: /* 11 Mbps */
270 return 22;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400271 /* case 4: reserved */
272 case 5: /* 6 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273 return 12;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400274 case 6: /* 9 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275 return 18;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400276 case 7: /* 12 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277 return 24;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400278 case 8: /* 18 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279 return 36;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400280 case 9: /* 24 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281 return 48;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400282 case 10: /* 36 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283 return 72;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400284 case 11: /* 48 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 return 96;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400286 case 12: /* 54 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287 return 108;
288 }
Holger Schurig9012b282007-05-25 11:27:16 -0400289 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290 return 0;
291}
292
293/**
294 * @brief This function processes a received 802.11 packet and forwards it
295 * to kernel/upper layer
296 *
Stewart Malik819cf152010-03-11 20:28:29 +1030297 * @param priv A pointer to struct lbs_private
298 * @param skb A pointer to skb which includes the received packet
299 * @return 0 or -1
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 */
Holger Schurig69f90322007-11-23 15:43:44 +0100301static int process_rxed_802_11_packet(struct lbs_private *priv,
302 struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304 int ret = 0;
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000305 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306 struct rx80211packethdr *p_rx_pkt;
307 struct rxpd *prxpd;
308 struct rx_radiotap_hdr radiotap_hdr;
309 struct rx_radiotap_hdr *pradiotap_hdr;
310
Holger Schurig9012b282007-05-25 11:27:16 -0400311 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312
313 p_rx_pkt = (struct rx80211packethdr *) skb->data;
314 prxpd = &p_rx_pkt->rx_pd;
315
Stewart Malik819cf152010-03-11 20:28:29 +1030316 /* lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100)); */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317
318 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
David Woodhouse7bf02c22007-12-10 00:17:28 -0500319 lbs_deb_rx("rx err: frame received with bad length\n");
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000320 dev->stats.rx_length_errors++;
David Woodhouse7bf02c22007-12-10 00:17:28 -0500321 ret = -EINVAL;
Sergio Luisb700a982008-10-26 23:09:27 -0700322 kfree_skb(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323 goto done;
324 }
325
Holger Schurig9012b282007-05-25 11:27:16 -0400326 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
328
329 /* create the exported radio header */
David Woodhouse180be752007-12-10 00:05:37 -0500330
331 /* radiotap header */
Prarit Bhargavac6a63682010-05-27 14:41:20 -0400332 memset(&radiotap_hdr, 0, sizeof(radiotap_hdr));
333 /* XXX must check radiotap_hdr.hdr.it_pad for pad */
David Woodhouse180be752007-12-10 00:05:37 -0500334 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
335 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
David Woodhouse180be752007-12-10 00:05:37 -0500336 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
337 /* XXX must check no carryout */
338 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
David Woodhouse180be752007-12-10 00:05:37 -0500339
340 /* chop the rxpd */
341 skb_pull(skb, sizeof(struct rxpd));
342
343 /* add space for the new radio header */
344 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
David Woodhouse7bf02c22007-12-10 00:17:28 -0500345 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
346 lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__);
347 ret = -ENOMEM;
348 kfree_skb(skb);
349 goto done;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400350 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200351
David Woodhouse180be752007-12-10 00:05:37 -0500352 pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr));
353 memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
355 /* Take the data rate from the rxpd structure
356 * only if the rate is auto
357 */
Javier Cardona85319f92008-05-24 10:59:49 +0100358 if (priv->enablehwauto)
David Woodhouseaa21c002007-12-08 20:04:36 +0000359 priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
Holger Schurig10078322007-11-15 18:05:47 -0500361 lbs_compute_rssi(priv, prxpd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
Holger Schurig9012b282007-05-25 11:27:16 -0400363 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000364 dev->stats.rx_bytes += skb->len;
365 dev->stats.rx_packets++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500367 skb->protocol = eth_type_trans(skb, priv->rtap_net_dev);
368 netif_rx(skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400369
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
Holger Schurig9012b282007-05-25 11:27:16 -0400372done:
Holger Schurig9012b282007-05-25 11:27:16 -0400373 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
374 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375}