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