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> |
| 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 | |
| 13 | struct eth803hdr { |
| 14 | u8 dest_addr[6]; |
| 15 | u8 src_addr[6]; |
| 16 | u16 h803_len; |
| 17 | } __attribute__ ((packed)); |
| 18 | |
| 19 | struct 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 | |
| 27 | struct rxpackethdr { |
| 28 | struct rxpd rx_pd; |
| 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 | /** |
| 42 | * @brief This function computes the avgSNR . |
| 43 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 44 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 45 | * @return avgSNR |
| 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 | /** |
| 60 | * @brief This function computes the AvgNF |
| 61 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 62 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 63 | * @return AvgNF |
| 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 | /** |
| 78 | * @brief This function save the raw SNR/NF to our internel buffer |
| 79 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 80 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 81 | * @param prxpd A pointer to rxpd structure of received packet |
| 82 | * @return n/a |
| 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 | return; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @brief This function computes the RSSI in received packet. |
| 98 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 99 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 100 | * @param prxpd A pointer to rxpd structure of received packet |
| 101 | * @return n/a |
| 102 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 103 | 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] | 104 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 105 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 106 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 107 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 108 | 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 Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 110 | priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE, |
| 111 | priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 112 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 113 | priv->SNR[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->snr; |
| 114 | priv->NF[TYPE_RXPD][TYPE_NOAVG] = p_rx_pd->nf; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 115 | lbs_save_rawSNRNF(priv, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 116 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 117 | priv->SNR[TYPE_RXPD][TYPE_AVG] = lbs_getavgsnr(priv) * AVG_SCALE; |
| 118 | priv->NF[TYPE_RXPD][TYPE_AVG] = lbs_getavgnf(priv) * AVG_SCALE; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 119 | 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] | 120 | priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE, |
| 121 | priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 122 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 123 | priv->RSSI[TYPE_RXPD][TYPE_NOAVG] = |
| 124 | CAL_RSSI(priv->SNR[TYPE_RXPD][TYPE_NOAVG], |
| 125 | priv->NF[TYPE_RXPD][TYPE_NOAVG]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 126 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 127 | 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 130 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 131 | lbs_deb_leave(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 132 | } |
| 133 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 134 | /** |
| 135 | * @brief This function processes received packet and forwards it |
| 136 | * to kernel/upper layer |
| 137 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 138 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 139 | * @param skb A pointer to skb which includes the received packet |
| 140 | * @return 0 or -1 |
| 141 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 142 | 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] | 143 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 144 | int ret = 0; |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 145 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 146 | struct rxpackethdr *p_rx_pkt; |
| 147 | struct rxpd *p_rx_pd; |
| 148 | |
| 149 | int hdrchop; |
| 150 | struct ethhdr *p_ethhdr; |
| 151 | |
| 152 | const u8 rfc1042_eth_hdr[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 153 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 154 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 155 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 156 | skb->ip_summed = CHECKSUM_NONE; |
| 157 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 158 | if (priv->monitormode != LBS_MONITOR_OFF) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 159 | return process_rxed_802_11_packet(priv, skb); |
| 160 | |
| 161 | p_rx_pkt = (struct rxpackethdr *) skb->data; |
| 162 | p_rx_pd = &p_rx_pkt->rx_pd; |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 163 | if (priv->mesh_dev && (p_rx_pd->rx_control & RxPD_MESH_FRAME)) |
| 164 | dev = priv->mesh_dev; |
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"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 171 | priv->stats.rx_length_errors++; |
| 172 | ret = 0; |
| 173 | goto done; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * Check rxpd status and update 802.3 stat, |
| 178 | */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 179 | if (!(p_rx_pd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 180 | lbs_deb_rx("rx err: frame received with bad status\n"); |
| 181 | lbs_pr_alert("rxpd not ok\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 182 | priv->stats.rx_errors++; |
| 183 | ret = 0; |
| 184 | goto done; |
| 185 | } |
| 186 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 187 | 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] | 188 | skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); |
| 189 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 190 | 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] | 191 | sizeof(p_rx_pkt->eth803_hdr.dest_addr)); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 192 | 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] | 193 | sizeof(p_rx_pkt->eth803_hdr.src_addr)); |
| 194 | |
| 195 | if (memcmp(&p_rx_pkt->rfc1042_hdr, |
| 196 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) { |
| 197 | /* |
| 198 | * Replace the 803 header and rfc1042 header (llc/snap) with an |
| 199 | * EthernetII header, keep the src/dst and snap_type (ethertype) |
| 200 | * |
| 201 | * The firmware only passes up SNAP frames converting |
| 202 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. |
| 203 | * |
| 204 | * To create the Ethernet II, just move the src, dst address right |
| 205 | * before the snap_type. |
| 206 | */ |
| 207 | p_ethhdr = (struct ethhdr *) |
| 208 | ((u8 *) & p_rx_pkt->eth803_hdr |
| 209 | + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr) |
| 210 | - sizeof(p_rx_pkt->eth803_hdr.dest_addr) |
| 211 | - sizeof(p_rx_pkt->eth803_hdr.src_addr) |
| 212 | - sizeof(p_rx_pkt->rfc1042_hdr.snap_type)); |
| 213 | |
| 214 | memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr, |
| 215 | sizeof(p_ethhdr->h_source)); |
| 216 | memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr, |
| 217 | sizeof(p_ethhdr->h_dest)); |
| 218 | |
| 219 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header |
| 220 | * that was removed |
| 221 | */ |
| 222 | hdrchop = (u8 *) p_ethhdr - (u8 *) p_rx_pkt; |
| 223 | } else { |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 224 | lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 225 | (u8 *) & p_rx_pkt->rfc1042_hdr, |
| 226 | sizeof(p_rx_pkt->rfc1042_hdr)); |
| 227 | |
| 228 | /* Chop off the rxpd */ |
| 229 | hdrchop = (u8 *) & p_rx_pkt->eth803_hdr - (u8 *) p_rx_pkt; |
| 230 | } |
| 231 | |
| 232 | /* Chop off the leading header bytes so the skb points to the start of |
| 233 | * either the reconstructed EthII frame or the 802.2/llc/snap frame |
| 234 | */ |
| 235 | skb_pull(skb, hdrchop); |
| 236 | |
| 237 | /* Take the data rate from the rxpd structure |
| 238 | * only if the rate is auto |
| 239 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 240 | if (priv->auto_rate) |
| 241 | 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] | 242 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 243 | lbs_compute_rssi(priv, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 244 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 245 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 246 | priv->stats.rx_bytes += skb->len; |
| 247 | priv->stats.rx_packets++; |
| 248 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 249 | skb->protocol = eth_type_trans(skb, dev); |
Holger Schurig | ae3e0fc | 2008-01-16 15:48:44 +0100 | [diff] [blame^] | 250 | if (in_interrupt()) |
| 251 | netif_rx(skb); |
| 252 | else |
| 253 | netif_rx_ni(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 254 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 255 | ret = 0; |
| 256 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 257 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 258 | return ret; |
| 259 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 260 | EXPORT_SYMBOL_GPL(lbs_process_rxed_packet); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 261 | |
| 262 | /** |
| 263 | * @brief This function converts Tx/Rx rates from the Marvell WLAN format |
| 264 | * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s) |
| 265 | * |
| 266 | * @param rate Input rate |
| 267 | * @return Output Rate (0 if invalid) |
| 268 | */ |
| 269 | static u8 convert_mv_rate_to_radiotap(u8 rate) |
| 270 | { |
| 271 | switch (rate) { |
| 272 | case 0: /* 1 Mbps */ |
| 273 | return 2; |
| 274 | case 1: /* 2 Mbps */ |
| 275 | return 4; |
| 276 | case 2: /* 5.5 Mbps */ |
| 277 | return 11; |
| 278 | case 3: /* 11 Mbps */ |
| 279 | return 22; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 280 | /* case 4: reserved */ |
| 281 | case 5: /* 6 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 282 | return 12; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 283 | case 6: /* 9 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 284 | return 18; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 285 | case 7: /* 12 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 286 | return 24; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 287 | case 8: /* 18 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 288 | return 36; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 289 | case 9: /* 24 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 290 | return 48; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 291 | case 10: /* 36 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 292 | return 72; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 293 | case 11: /* 48 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 294 | return 96; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 295 | case 12: /* 54 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 296 | return 108; |
| 297 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 298 | lbs_pr_alert("Invalid Marvell WLAN rate %i\n", rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * @brief This function processes a received 802.11 packet and forwards it |
| 304 | * to kernel/upper layer |
| 305 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 306 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | * @param skb A pointer to skb which includes the received packet |
| 308 | * @return 0 or -1 |
| 309 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 310 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
| 311 | struct sk_buff *skb) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 313 | int ret = 0; |
| 314 | |
| 315 | struct rx80211packethdr *p_rx_pkt; |
| 316 | struct rxpd *prxpd; |
| 317 | struct rx_radiotap_hdr radiotap_hdr; |
| 318 | struct rx_radiotap_hdr *pradiotap_hdr; |
| 319 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 320 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 321 | |
| 322 | p_rx_pkt = (struct rx80211packethdr *) skb->data; |
| 323 | prxpd = &p_rx_pkt->rx_pd; |
| 324 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 325 | // 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] | 326 | |
| 327 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 328 | lbs_deb_rx("rx err: frame received with bad length\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 329 | priv->stats.rx_length_errors++; |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 330 | ret = -EINVAL; |
| 331 | kfree(skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 332 | goto done; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Check rxpd status and update 802.3 stat, |
| 337 | */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 338 | if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 339 | //lbs_deb_rx("rx err: frame received with bad status\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 340 | priv->stats.rx_errors++; |
| 341 | } |
| 342 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 343 | 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] | 344 | skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); |
| 345 | |
| 346 | /* create the exported radio header */ |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 347 | |
| 348 | /* radiotap header */ |
| 349 | radiotap_hdr.hdr.it_version = 0; |
| 350 | /* XXX must check this value for pad */ |
| 351 | radiotap_hdr.hdr.it_pad = 0; |
| 352 | radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr)); |
| 353 | radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT); |
| 354 | /* unknown values */ |
| 355 | radiotap_hdr.flags = 0; |
| 356 | radiotap_hdr.chan_freq = 0; |
| 357 | radiotap_hdr.chan_flags = 0; |
| 358 | radiotap_hdr.antenna = 0; |
| 359 | /* known values */ |
| 360 | radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate); |
| 361 | /* XXX must check no carryout */ |
| 362 | radiotap_hdr.antsignal = prxpd->snr + prxpd->nf; |
| 363 | radiotap_hdr.rx_flags = 0; |
| 364 | if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) |
| 365 | radiotap_hdr.rx_flags |= IEEE80211_RADIOTAP_F_RX_BADFCS; |
| 366 | //memset(radiotap_hdr.pad, 0x11, IEEE80211_RADIOTAP_HDRLEN - 18); |
| 367 | |
| 368 | /* chop the rxpd */ |
| 369 | skb_pull(skb, sizeof(struct rxpd)); |
| 370 | |
| 371 | /* add space for the new radio header */ |
| 372 | if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) && |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 373 | pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) { |
| 374 | lbs_pr_alert("%s: couldn't pskb_expand_head\n", __func__); |
| 375 | ret = -ENOMEM; |
| 376 | kfree_skb(skb); |
| 377 | goto done; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 378 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 379 | |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 380 | pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr)); |
| 381 | memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 382 | |
| 383 | /* Take the data rate from the rxpd structure |
| 384 | * only if the rate is auto |
| 385 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 386 | if (priv->auto_rate) |
| 387 | priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 388 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 389 | lbs_compute_rssi(priv, prxpd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 390 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 391 | lbs_deb_rx("rx data: size of actual packet %d\n", skb->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 392 | priv->stats.rx_bytes += skb->len; |
| 393 | priv->stats.rx_packets++; |
| 394 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 395 | skb->protocol = eth_type_trans(skb, priv->rtap_net_dev); |
| 396 | netif_rx(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 397 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 398 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 399 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 400 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 401 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
| 402 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 403 | } |