Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains the handling of RX in wlan driver. |
| 3 | */ |
| 4 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 5 | #include <linux/slab.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | #include <linux/types.h> |
| 7 | |
Holger Schurig | 9e66e70 | 2009-10-16 17:32:16 +0200 | [diff] [blame] | 8 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 9 | #include "radiotap.h" |
| 10 | #include "decl.h" |
| 11 | #include "dev.h" |
| 12 | #include "wext.h" |
| 13 | |
| 14 | struct eth803hdr { |
| 15 | u8 dest_addr[6]; |
| 16 | u8 src_addr[6]; |
| 17 | u16 h803_len; |
| 18 | } __attribute__ ((packed)); |
| 19 | |
| 20 | struct 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 | |
| 28 | struct rxpackethdr { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 29 | struct eth803hdr eth803_hdr; |
| 30 | struct rfc1042hdr rfc1042_hdr; |
| 31 | } __attribute__ ((packed)); |
| 32 | |
| 33 | struct rx80211packethdr { |
| 34 | struct rxpd rx_pd; |
| 35 | void *eth80211_hdr; |
| 36 | } __attribute__ ((packed)); |
| 37 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 38 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
| 39 | struct sk_buff *skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 40 | |
| 41 | /** |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 42 | * @brief This function computes the avgSNR . |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 43 | * |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 44 | * @param priv A pointer to struct lbs_private structure |
| 45 | * @return avgSNR |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 47 | static u8 lbs_getavgsnr(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 48 | { |
| 49 | u8 i; |
| 50 | u16 temp = 0; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 51 | if (priv->numSNRNF == 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 52 | return 0; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 53 | for (i = 0; i < priv->numSNRNF; i++) |
| 54 | temp += priv->rawSNR[i]; |
| 55 | return (u8) (temp / priv->numSNRNF); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 56 | |
| 57 | } |
| 58 | |
| 59 | /** |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 60 | * @brief This function computes the AvgNF |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 61 | * |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 62 | * @param priv A pointer to struct lbs_private structure |
| 63 | * @return AvgNF |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 64 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 65 | static u8 lbs_getavgnf(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 66 | { |
| 67 | u8 i; |
| 68 | u16 temp = 0; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 69 | if (priv->numSNRNF == 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 70 | return 0; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 71 | for (i = 0; i < priv->numSNRNF; i++) |
| 72 | temp += priv->rawNF[i]; |
| 73 | return (u8) (temp / priv->numSNRNF); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | |
| 75 | } |
| 76 | |
| 77 | /** |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 78 | * @brief This function save the raw SNR/NF to our internel buffer |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 79 | * |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 80 | * @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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 83 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 84 | static void lbs_save_rawSNRNF(struct lbs_private *priv, struct rxpd *p_rx_pd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 85 | { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 86 | 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 96 | * @brief This function computes the RSSI in received packet. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 97 | * |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 98 | * @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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 101 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 102 | static void lbs_compute_rssi(struct lbs_private *priv, struct rxpd *p_rx_pd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 103 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 104 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 105 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 106 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 107 | 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 Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 109 | priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE, |
| 110 | priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 111 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 112 | priv->SNR[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->snr; |
| 113 | priv->NF[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->nf; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 114 | lbs_save_rawSNRNF(priv, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 116 | priv->SNR[TYPE_RXPD][TYPE_AVG] = lbs_getavgsnr(priv) * AVG_SCALE; |
| 117 | priv->NF[TYPE_RXPD][TYPE_AVG] = lbs_getavgnf(priv) * AVG_SCALE; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 118 | lbs_deb_rx("after computing SNR: SNR-avg = %d, NF-avg = %d\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 119 | priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE, |
| 120 | priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 121 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 122 | priv->RSSI[TYPE_RXPD][TYPE_NOAVG] = |
| 123 | CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_NOAVG], |
| 124 | priv->NF[TYPE_RXPD][TYPE_NOAVG]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 125 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 126 | 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 129 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 130 | lbs_deb_leave(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 131 | } |
| 132 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 133 | /** |
| 134 | * @brief This function processes received packet and forwards it |
| 135 | * to kernel/upper layer |
| 136 | * |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 137 | * @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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 140 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 141 | int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 142 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | int ret = 0; |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 144 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 145 | struct rxpackethdr *p_rx_pkt; |
| 146 | struct rxpd *p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | int hdrchop; |
| 148 | struct ethhdr *p_ethhdr; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 149 | const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 150 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 151 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 152 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 153 | BUG_ON(!skb); |
| 154 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 155 | skb->ip_summed = CHECKSUM_NONE; |
| 156 | |
Holger Schurig | c2b310a | 2008-03-26 09:57:14 +0100 | [diff] [blame] | 157 | if (priv->monitormode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 158 | return process_rxed_802_11_packet(priv, skb); |
| 159 | |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 160 | 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 Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 163 | |
| 164 | dev = lbs_mesh_set_dev(priv, dev, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 165 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 166 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 167 | min_t(unsigned int, skb->len, 100)); |
| 168 | |
| 169 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 170 | lbs_deb_rx("rx err: frame received with bad length\n"); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 171 | dev->stats.rx_length_errors++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 172 | ret = 0; |
Philip Rakity | f54930f | 2009-04-07 12:41:17 -0700 | [diff] [blame] | 173 | dev_kfree_skb(skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 174 | goto done; |
| 175 | } |
| 176 | |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 177 | lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n", |
John W. Linville | a2caba6 | 2009-04-14 11:45:57 -0400 | [diff] [blame] | 178 | 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 180 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 181 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 182 | sizeof(p_rx_pkt->eth803_hdr.dest_addr)); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 183 | lbs_deb_hex(LBS_DEB_RX, "RX Data: Src", p_rx_pkt->eth803_hdr.src_addr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 184 | 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 Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 199 | ((u8 *) &p_rx_pkt->eth803_hdr |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 200 | + 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 Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 213 | hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 214 | } else { |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 215 | lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP", |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 216 | (u8 *) &p_rx_pkt->rfc1042_hdr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 217 | sizeof(p_rx_pkt->rfc1042_hdr)); |
| 218 | |
| 219 | /* Chop off the rxpd */ |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 220 | hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 221 | } |
| 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 Cardona | 85319f9 | 2008-05-24 10:59:49 +0100 | [diff] [blame] | 231 | if (priv->enablehwauto) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 232 | priv->cur_rate = lbs_fw_index_to_data_rate(p_rx_pd->rx_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 233 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 234 | lbs_compute_rssi(priv, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 235 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 236 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 237 | dev->stats.rx_bytes += skb->len; |
| 238 | dev->stats.rx_packets++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 239 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 240 | skb->protocol = eth_type_trans(skb, dev); |
Holger Schurig | ae3e0fc | 2008-01-16 15:48:44 +0100 | [diff] [blame] | 241 | if (in_interrupt()) |
| 242 | netif_rx(skb); |
| 243 | else |
| 244 | netif_rx_ni(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 245 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 246 | ret = 0; |
| 247 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 248 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 249 | return ret; |
| 250 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 251 | EXPORT_SYMBOL_GPL(lbs_process_rxed_packet); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 252 | |
| 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 Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 257 | * @param rate Input rate |
| 258 | * @return Output Rate (0 if invalid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 259 | */ |
| 260 | static 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 Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 271 | /* case 4: reserved */ |
| 272 | case 5: /* 6 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 273 | return 12; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 274 | case 6: /* 9 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 275 | return 18; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 276 | case 7: /* 12 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 277 | return 24; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 278 | case 8: /* 18 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | return 36; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 280 | case 9: /* 24 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 281 | return 48; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 282 | case 10: /* 36 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 283 | return 72; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 284 | case 11: /* 48 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 285 | return 96; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 286 | case 12: /* 54 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | return 108; |
| 288 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 289 | lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 290 | 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 Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 297 | * @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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 300 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 301 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
| 302 | struct sk_buff *skb) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 303 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 304 | int ret = 0; |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 305 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 306 | 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 Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 311 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 | |
| 313 | p_rx_pkt = (struct rx80211packethdr *) skb->data; |
| 314 | prxpd = &p_rx_pkt->rx_pd; |
| 315 | |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 316 | /* lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, min(skb->len, 100)); */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 317 | |
| 318 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 319 | lbs_deb_rx("rx err: frame received with bad length\n"); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 320 | dev->stats.rx_length_errors++; |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 321 | ret = -EINVAL; |
Sergio Luis | b700a98 | 2008-10-26 23:09:27 -0700 | [diff] [blame] | 322 | kfree_skb(skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 323 | goto done; |
| 324 | } |
| 325 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 326 | lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 327 | skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); |
| 328 | |
| 329 | /* create the exported radio header */ |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 330 | |
| 331 | /* radiotap header */ |
| 332 | radiotap_hdr.hdr.it_version = 0; |
| 333 | /* XXX must check this value for pad */ |
| 334 | radiotap_hdr.hdr.it_pad = 0; |
| 335 | radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr)); |
| 336 | radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT); |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 337 | radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate); |
| 338 | /* XXX must check no carryout */ |
| 339 | radiotap_hdr.antsignal = prxpd->snr + prxpd->nf; |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 340 | |
| 341 | /* chop the rxpd */ |
| 342 | skb_pull(skb, sizeof(struct rxpd)); |
| 343 | |
| 344 | /* add space for the new radio header */ |
| 345 | if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) && |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 346 | pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) { |
| 347 | lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__); |
| 348 | ret = -ENOMEM; |
| 349 | kfree_skb(skb); |
| 350 | goto done; |
Luis Carlos Cobo | 965f8bb | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 351 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 352 | |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 353 | pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr)); |
| 354 | memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 355 | |
| 356 | /* Take the data rate from the rxpd structure |
| 357 | * only if the rate is auto |
| 358 | */ |
Javier Cardona | 85319f9 | 2008-05-24 10:59:49 +0100 | [diff] [blame] | 359 | if (priv->enablehwauto) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 360 | priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 361 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 362 | lbs_compute_rssi(priv, prxpd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 363 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 364 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 365 | dev->stats.rx_bytes += skb->len; |
| 366 | dev->stats.rx_packets++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 367 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 368 | skb->protocol = eth_type_trans(skb, priv->rtap_net_dev); |
| 369 | netif_rx(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 370 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 371 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 372 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 373 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 374 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
| 375 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 376 | } |