blob: 141069fa67f22b1e312ac945bceaebe05f3fdad7 [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
7#include "hostcmd.h"
8#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 {
28 struct rxpd rx_pd;
29 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
Holger Schurig69f90322007-11-23 15:43:44 +0100134void lbs_upload_rx_packet(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135{
Holger Schurig9012b282007-05-25 11:27:16 -0400136 lbs_deb_rx("skb->data %p\n", skb->data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137
David Woodhouseaa21c002007-12-08 20:04:36 +0000138 if (priv->monitormode != LBS_MONITOR_OFF) {
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400139 skb->protocol = eth_type_trans(skb, priv->rtap_net_dev);
140 } else {
141 if (priv->mesh_dev && IS_MESH_FRAME(skb))
142 skb->protocol = eth_type_trans(skb, priv->mesh_dev);
143 else
144 skb->protocol = eth_type_trans(skb, priv->dev);
145 }
David Woodhouse90885662007-12-06 10:36:08 +0000146 skb->ip_summed = CHECKSUM_NONE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147 netif_rx(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148}
149
150/**
151 * @brief This function processes received packet and forwards it
152 * to kernel/upper layer
153 *
Holger Schurig69f90322007-11-23 15:43:44 +0100154 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 * @param skb A pointer to skb which includes the received packet
156 * @return 0 or -1
157 */
Holger Schurig69f90322007-11-23 15:43:44 +0100158int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 int ret = 0;
161
162 struct rxpackethdr *p_rx_pkt;
163 struct rxpd *p_rx_pd;
164
165 int hdrchop;
166 struct ethhdr *p_ethhdr;
167
168 const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
169
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171
David Woodhouseaa21c002007-12-08 20:04:36 +0000172 if (priv->monitormode != LBS_MONITOR_OFF)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173 return process_rxed_802_11_packet(priv, skb);
174
175 p_rx_pkt = (struct rxpackethdr *) skb->data;
176 p_rx_pd = &p_rx_pkt->rx_pd;
177 if (p_rx_pd->rx_control & RxPD_MESH_FRAME)
178 SET_MESH_FRAME(skb);
179 else
180 UNSET_MESH_FRAME(skb);
181
Holger Schurigece56192007-08-02 11:53:06 -0400182 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 min_t(unsigned int, skb->len, 100));
184
185 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400186 lbs_deb_rx("rx err: frame received with bad length\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187 priv->stats.rx_length_errors++;
188 ret = 0;
189 goto done;
190 }
191
192 /*
193 * Check rxpd status and update 802.3 stat,
194 */
David Woodhouse981f1872007-05-25 23:36:54 -0400195 if (!(p_rx_pd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400196 lbs_deb_rx("rx err: frame received with bad status\n");
197 lbs_pr_alert("rxpd not ok\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198 priv->stats.rx_errors++;
199 ret = 0;
200 goto done;
201 }
202
Holger Schurig9012b282007-05-25 11:27:16 -0400203 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
205
Holger Schurigece56192007-08-02 11:53:06 -0400206 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
Holger Schurigece56192007-08-02 11:53:06 -0400208 lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 sizeof(p_rx_pkt->eth803_hdr.src_addr));
210
211 if (memcmp(&p_rx_pkt->rfc1042_hdr,
212 rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) {
213 /*
214 * Replace the 803 header and rfc1042 header (llc/snap) with an
215 * EthernetII header, keep the src/dst and snap_type (ethertype)
216 *
217 * The firmware only passes up SNAP frames converting
218 * all RX Data from 802.11 to 802.2/LLC/SNAP frames.
219 *
220 * To create the Ethernet II, just move the src, dst address right
221 * before the snap_type.
222 */
223 p_ethhdr = (struct ethhdr *)
224 ((u8 *) & p_rx_pkt->eth803_hdr
225 + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr)
226 - sizeof(p_rx_pkt->eth803_hdr.dest_addr)
227 - sizeof(p_rx_pkt->eth803_hdr.src_addr)
228 - sizeof(p_rx_pkt->rfc1042_hdr.snap_type));
229
230 memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr,
231 sizeof(p_ethhdr->h_source));
232 memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr,
233 sizeof(p_ethhdr->h_dest));
234
235 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
236 * that was removed
237 */
238 hdrchop = (u8 *) p_ethhdr - (u8 *) p_rx_pkt;
239 } else {
Holger Schurigece56192007-08-02 11:53:06 -0400240 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241 (u8 *) & p_rx_pkt->rfc1042_hdr,
242 sizeof(p_rx_pkt->rfc1042_hdr));
243
244 /* Chop off the rxpd */
245 hdrchop = (u8 *) & p_rx_pkt->eth803_hdr - (u8 *) p_rx_pkt;
246 }
247
248 /* Chop off the leading header bytes so the skb points to the start of
249 * either the reconstructed EthII frame or the 802.2/llc/snap frame
250 */
251 skb_pull(skb, hdrchop);
252
253 /* Take the data rate from the rxpd structure
254 * only if the rate is auto
255 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000256 if (priv->auto_rate)
257 priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258
Holger Schurig10078322007-11-15 18:05:47 -0500259 lbs_compute_rssi(priv, p_rx_pd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200260
Holger Schurig9012b282007-05-25 11:27:16 -0400261 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200262 priv->stats.rx_bytes += skb->len;
263 priv->stats.rx_packets++;
264
Holger Schurig10078322007-11-15 18:05:47 -0500265 lbs_upload_rx_packet(priv, skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400266
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267 ret = 0;
268done:
Holger Schurig9012b282007-05-25 11:27:16 -0400269 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 return ret;
271}
Holger Schurig10078322007-11-15 18:05:47 -0500272EXPORT_SYMBOL_GPL(lbs_process_rxed_packet);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273
274/**
275 * @brief This function converts Tx/Rx rates from the Marvell WLAN format
276 * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s)
277 *
278 * @param rate Input rate
279 * @return Output Rate (0 if invalid)
280 */
281static u8 convert_mv_rate_to_radiotap(u8 rate)
282{
283 switch (rate) {
284 case 0: /* 1 Mbps */
285 return 2;
286 case 1: /* 2 Mbps */
287 return 4;
288 case 2: /* 5.5 Mbps */
289 return 11;
290 case 3: /* 11 Mbps */
291 return 22;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400292 /* case 4: reserved */
293 case 5: /* 6 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294 return 12;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400295 case 6: /* 9 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296 return 18;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400297 case 7: /* 12 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 return 24;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400299 case 8: /* 18 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 return 36;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400301 case 9: /* 24 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302 return 48;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400303 case 10: /* 36 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304 return 72;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400305 case 11: /* 48 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306 return 96;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400307 case 12: /* 54 Mbps */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308 return 108;
309 }
Holger Schurig9012b282007-05-25 11:27:16 -0400310 lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311 return 0;
312}
313
314/**
315 * @brief This function processes a received 802.11 packet and forwards it
316 * to kernel/upper layer
317 *
Holger Schurig69f90322007-11-23 15:43:44 +0100318 * @param priv A pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319 * @param skb A pointer to skb which includes the received packet
320 * @return 0 or -1
321 */
Holger Schurig69f90322007-11-23 15:43:44 +0100322static int process_rxed_802_11_packet(struct lbs_private *priv,
323 struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325 int ret = 0;
326
327 struct rx80211packethdr *p_rx_pkt;
328 struct rxpd *prxpd;
329 struct rx_radiotap_hdr radiotap_hdr;
330 struct rx_radiotap_hdr *pradiotap_hdr;
331
Holger Schurig9012b282007-05-25 11:27:16 -0400332 lbs_deb_enter(LBS_DEB_RX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
334 p_rx_pkt = (struct rx80211packethdr *) skb->data;
335 prxpd = &p_rx_pkt->rx_pd;
336
Holger Schurigece56192007-08-02 11:53:06 -0400337 // lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338
339 if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) {
David Woodhouse7bf02c22007-12-10 00:17:28 -0500340 lbs_deb_rx("rx err: frame received with bad length\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341 priv->stats.rx_length_errors++;
David Woodhouse7bf02c22007-12-10 00:17:28 -0500342 ret = -EINVAL;
343 kfree(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 goto done;
345 }
346
347 /*
348 * Check rxpd status and update 802.3 stat,
349 */
David Woodhouse981f1872007-05-25 23:36:54 -0400350 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400351 //lbs_deb_rx("rx err: frame received with bad status\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 priv->stats.rx_errors++;
353 }
354
Holger Schurig9012b282007-05-25 11:27:16 -0400355 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
357
358 /* create the exported radio header */
David Woodhouse180be752007-12-10 00:05:37 -0500359
360 /* radiotap header */
361 radiotap_hdr.hdr.it_version = 0;
362 /* XXX must check this value for pad */
363 radiotap_hdr.hdr.it_pad = 0;
364 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
365 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
366 /* unknown values */
367 radiotap_hdr.flags = 0;
368 radiotap_hdr.chan_freq = 0;
369 radiotap_hdr.chan_flags = 0;
370 radiotap_hdr.antenna = 0;
371 /* known values */
372 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
373 /* XXX must check no carryout */
374 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
375 radiotap_hdr.rx_flags = 0;
376 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
377 radiotap_hdr.rx_flags |= IEEE80211_RADIOTAP_F_RX_BADFCS;
378 //memset(radiotap_hdr.pad, 0x11, IEEE80211_RADIOTAP_HDRLEN - 18);
379
380 /* chop the rxpd */
381 skb_pull(skb, sizeof(struct rxpd));
382
383 /* add space for the new radio header */
384 if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) &&
David Woodhouse7bf02c22007-12-10 00:17:28 -0500385 pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) {
386 lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__);
387 ret = -ENOMEM;
388 kfree_skb(skb);
389 goto done;
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400390 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
David Woodhouse180be752007-12-10 00:05:37 -0500392 pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr));
393 memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
395 /* Take the data rate from the rxpd structure
396 * only if the rate is auto
397 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000398 if (priv->auto_rate)
399 priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Holger Schurig10078322007-11-15 18:05:47 -0500401 lbs_compute_rssi(priv, prxpd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402
Holger Schurig9012b282007-05-25 11:27:16 -0400403 lbs_deb_rx("rx data: size of actual packet %d\n", skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 priv->stats.rx_bytes += skb->len;
405 priv->stats.rx_packets++;
406
Holger Schurig10078322007-11-15 18:05:47 -0500407 lbs_upload_rx_packet(priv, skb);
Florin Malita3d4bd242007-05-18 16:04:33 -0400408
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200409 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410
Holger Schurig9012b282007-05-25 11:27:16 -0400411done:
Holger Schurig9012b282007-05-25 11:27:16 -0400412 lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret);
413 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414}