Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the handling of RX in wlan driver. |
| 3 | */ |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 4 | |
| 5 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 6 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 7 | #include <linux/etherdevice.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 8 | #include <linux/hardirq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include <linux/types.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 12 | #include <net/cfg80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 14 | #include "defs.h" |
Holger Schurig | 9e66e70 | 2009-10-16 17:32:16 +0200 | [diff] [blame] | 15 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 16 | #include "radiotap.h" |
| 17 | #include "decl.h" |
| 18 | #include "dev.h" |
Daniel Drake | 49fee69 | 2011-07-21 20:43:17 +0100 | [diff] [blame] | 19 | #include "mesh.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | |
| 21 | struct eth803hdr { |
| 22 | u8 dest_addr[6]; |
| 23 | u8 src_addr[6]; |
| 24 | u16 h803_len; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 25 | } __packed; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 26 | |
| 27 | struct rfc1042hdr { |
| 28 | u8 llc_dsap; |
| 29 | u8 llc_ssap; |
| 30 | u8 llc_ctrl; |
| 31 | u8 snap_oui[3]; |
| 32 | u16 snap_type; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 33 | } __packed; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 34 | |
| 35 | struct rxpackethdr { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 36 | struct eth803hdr eth803_hdr; |
| 37 | struct rfc1042hdr rfc1042_hdr; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 38 | } __packed; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 39 | |
| 40 | struct rx80211packethdr { |
| 41 | struct rxpd rx_pd; |
| 42 | void *eth80211_hdr; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 43 | } __packed; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 44 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 45 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
| 46 | struct sk_buff *skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 47 | |
| 48 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 49 | * lbs_process_rxed_packet - processes received packet and forwards it |
| 50 | * to kernel/upper layer |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 51 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 52 | * @priv: A pointer to &struct lbs_private |
| 53 | * @skb: A pointer to skb which includes the received packet |
| 54 | * returns: 0 or -1 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 55 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 56 | 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] | 57 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 58 | int ret = 0; |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 59 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 60 | struct rxpackethdr *p_rx_pkt; |
| 61 | struct rxpd *p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 62 | int hdrchop; |
| 63 | struct ethhdr *p_ethhdr; |
Joe Perches | 482e039 | 2010-11-20 18:38:58 -0800 | [diff] [blame] | 64 | static const u8 rfc1042_eth_hdr[] = { |
| 65 | 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 |
| 66 | }; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 67 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 68 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 69 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 70 | BUG_ON(!skb); |
| 71 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 72 | skb->ip_summed = CHECKSUM_NONE; |
| 73 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 74 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | return process_rxed_802_11_packet(priv, skb); |
| 76 | |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 77 | p_rx_pd = (struct rxpd *) skb->data; |
| 78 | p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd + |
| 79 | le32_to_cpu(p_rx_pd->pkt_ptr)); |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 80 | |
| 81 | dev = lbs_mesh_set_dev(priv, dev, p_rx_pd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 82 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 83 | 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] | 84 | min_t(unsigned int, skb->len, 100)); |
| 85 | |
| 86 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 87 | lbs_deb_rx("rx err: frame received with bad length\n"); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 88 | dev->stats.rx_length_errors++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 89 | ret = 0; |
Philip Rakity | f54930f | 2009-04-07 12:41:17 -0700 | [diff] [blame] | 90 | dev_kfree_skb(skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 91 | goto done; |
| 92 | } |
| 93 | |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 94 | 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] | 95 | skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr), |
| 96 | skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 97 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 98 | 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] | 99 | sizeof(p_rx_pkt->eth803_hdr.dest_addr)); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 100 | 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] | 101 | sizeof(p_rx_pkt->eth803_hdr.src_addr)); |
| 102 | |
| 103 | if (memcmp(&p_rx_pkt->rfc1042_hdr, |
| 104 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)) == 0) { |
| 105 | /* |
| 106 | * Replace the 803 header and rfc1042 header (llc/snap) with an |
| 107 | * EthernetII header, keep the src/dst and snap_type (ethertype) |
| 108 | * |
| 109 | * The firmware only passes up SNAP frames converting |
| 110 | * all RX Data from 802.11 to 802.2/LLC/SNAP frames. |
| 111 | * |
| 112 | * To create the Ethernet II, just move the src, dst address right |
| 113 | * before the snap_type. |
| 114 | */ |
| 115 | p_ethhdr = (struct ethhdr *) |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 116 | ((u8 *) &p_rx_pkt->eth803_hdr |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | + sizeof(p_rx_pkt->eth803_hdr) + sizeof(p_rx_pkt->rfc1042_hdr) |
| 118 | - sizeof(p_rx_pkt->eth803_hdr.dest_addr) |
| 119 | - sizeof(p_rx_pkt->eth803_hdr.src_addr) |
| 120 | - sizeof(p_rx_pkt->rfc1042_hdr.snap_type)); |
| 121 | |
| 122 | memcpy(p_ethhdr->h_source, p_rx_pkt->eth803_hdr.src_addr, |
| 123 | sizeof(p_ethhdr->h_source)); |
| 124 | memcpy(p_ethhdr->h_dest, p_rx_pkt->eth803_hdr.dest_addr, |
| 125 | sizeof(p_ethhdr->h_dest)); |
| 126 | |
| 127 | /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header |
| 128 | * that was removed |
| 129 | */ |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 130 | hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 131 | } else { |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 132 | lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP", |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 133 | (u8 *) &p_rx_pkt->rfc1042_hdr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 134 | sizeof(p_rx_pkt->rfc1042_hdr)); |
| 135 | |
| 136 | /* Chop off the rxpd */ |
Bing Zhao | e45d8e5 | 2009-04-06 15:50:56 -0700 | [diff] [blame] | 137 | hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* Chop off the leading header bytes so the skb points to the start of |
| 141 | * either the reconstructed EthII frame or the 802.2/llc/snap frame |
| 142 | */ |
| 143 | skb_pull(skb, hdrchop); |
| 144 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 145 | 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] | 146 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 147 | 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] | 148 | dev->stats.rx_bytes += skb->len; |
| 149 | dev->stats.rx_packets++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 150 | |
David Woodhouse | 6f93a8e | 2007-12-10 00:49:26 -0500 | [diff] [blame] | 151 | skb->protocol = eth_type_trans(skb, dev); |
Holger Schurig | ae3e0fc | 2008-01-16 15:48:44 +0100 | [diff] [blame] | 152 | if (in_interrupt()) |
| 153 | netif_rx(skb); |
| 154 | else |
| 155 | netif_rx_ni(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 156 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 157 | ret = 0; |
| 158 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 159 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 160 | return ret; |
| 161 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 162 | EXPORT_SYMBOL_GPL(lbs_process_rxed_packet); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 163 | |
| 164 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 165 | * convert_mv_rate_to_radiotap - converts Tx/Rx rates from Marvell WLAN format |
| 166 | * (see Table 2 in Section 3.1) to IEEE80211_RADIOTAP_RATE units (500 Kb/s) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 167 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 168 | * @rate: Input rate |
| 169 | * returns: Output Rate (0 if invalid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 170 | */ |
| 171 | static u8 convert_mv_rate_to_radiotap(u8 rate) |
| 172 | { |
| 173 | switch (rate) { |
| 174 | case 0: /* 1 Mbps */ |
| 175 | return 2; |
| 176 | case 1: /* 2 Mbps */ |
| 177 | return 4; |
| 178 | case 2: /* 5.5 Mbps */ |
| 179 | return 11; |
| 180 | case 3: /* 11 Mbps */ |
| 181 | return 22; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 182 | /* case 4: reserved */ |
| 183 | case 5: /* 6 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 184 | return 12; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 185 | case 6: /* 9 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 186 | return 18; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 187 | case 7: /* 12 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 188 | return 24; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 189 | case 8: /* 18 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 190 | return 36; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 191 | case 9: /* 24 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 192 | return 48; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 193 | case 10: /* 36 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 194 | return 72; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 195 | case 11: /* 48 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 196 | return 96; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 197 | case 12: /* 54 Mbps */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 198 | return 108; |
| 199 | } |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 200 | pr_alert("Invalid Marvell WLAN rate %i\n", rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 205 | * process_rxed_802_11_packet - processes a received 802.11 packet and forwards |
| 206 | * it to kernel/upper layer |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 207 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 208 | * @priv: A pointer to &struct lbs_private |
| 209 | * @skb: A pointer to skb which includes the received packet |
| 210 | * returns: 0 or -1 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 211 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 212 | static int process_rxed_802_11_packet(struct lbs_private *priv, |
| 213 | struct sk_buff *skb) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 214 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 215 | int ret = 0; |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 216 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 217 | struct rx80211packethdr *p_rx_pkt; |
| 218 | struct rxpd *prxpd; |
| 219 | struct rx_radiotap_hdr radiotap_hdr; |
| 220 | struct rx_radiotap_hdr *pradiotap_hdr; |
| 221 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 222 | lbs_deb_enter(LBS_DEB_RX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 223 | |
| 224 | p_rx_pkt = (struct rx80211packethdr *) skb->data; |
| 225 | prxpd = &p_rx_pkt->rx_pd; |
| 226 | |
Stewart Malik | 819cf15 | 2010-03-11 20:28:29 +1030 | [diff] [blame] | 227 | /* 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] | 228 | |
| 229 | if (skb->len < (ETH_HLEN + 8 + sizeof(struct rxpd))) { |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 230 | lbs_deb_rx("rx err: frame received with bad length\n"); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 231 | dev->stats.rx_length_errors++; |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 232 | ret = -EINVAL; |
Sergio Luis | b700a98 | 2008-10-26 23:09:27 -0700 | [diff] [blame] | 233 | kfree_skb(skb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 234 | goto done; |
| 235 | } |
| 236 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 237 | 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] | 238 | skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); |
| 239 | |
| 240 | /* create the exported radio header */ |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 241 | |
| 242 | /* radiotap header */ |
Prarit Bhargava | c6a6368 | 2010-05-27 14:41:20 -0400 | [diff] [blame] | 243 | memset(&radiotap_hdr, 0, sizeof(radiotap_hdr)); |
| 244 | /* XXX must check radiotap_hdr.hdr.it_pad for pad */ |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 245 | radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr)); |
| 246 | radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT); |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 247 | radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate); |
| 248 | /* XXX must check no carryout */ |
| 249 | radiotap_hdr.antsignal = prxpd->snr + prxpd->nf; |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 250 | |
| 251 | /* chop the rxpd */ |
| 252 | skb_pull(skb, sizeof(struct rxpd)); |
| 253 | |
| 254 | /* add space for the new radio header */ |
| 255 | if ((skb_headroom(skb) < sizeof(struct rx_radiotap_hdr)) && |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 256 | pskb_expand_head(skb, sizeof(struct rx_radiotap_hdr), 0, GFP_ATOMIC)) { |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 257 | netdev_alert(dev, "%s: couldn't pskb_expand_head\n", __func__); |
David Woodhouse | 7bf02c2 | 2007-12-10 00:17:28 -0500 | [diff] [blame] | 258 | ret = -ENOMEM; |
| 259 | kfree_skb(skb); |
| 260 | goto done; |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 261 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 262 | |
David Woodhouse | 180be75 | 2007-12-10 00:05:37 -0500 | [diff] [blame] | 263 | pradiotap_hdr = (void *)skb_push(skb, sizeof(struct rx_radiotap_hdr)); |
| 264 | memcpy(pradiotap_hdr, &radiotap_hdr, sizeof(struct rx_radiotap_hdr)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 265 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 266 | priv->cur_rate = lbs_fw_index_to_data_rate(prxpd->rx_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 267 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 268 | 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] | 269 | dev->stats.rx_bytes += skb->len; |
| 270 | dev->stats.rx_packets++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 271 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 272 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 273 | |
| 274 | if (in_interrupt()) |
| 275 | netif_rx(skb); |
| 276 | else |
| 277 | netif_rx_ni(skb); |
Florin Malita | 3d4bd24 | 2007-05-18 16:04:33 -0400 | [diff] [blame] | 278 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 280 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 281 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 282 | lbs_deb_leave_args(LBS_DEB_RX, "ret %d", ret); |
| 283 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 284 | } |