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