Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/net/wireless/hostap/hostap_80211_rx.c (Version 2.6.25.8) and /linux/drivers/net/wireless/hostap/hostap_80211_rx.c (Version 2.6.25)


  1 #include <linux/etherdevice.h>                      1 #include <linux/etherdevice.h>
  2 #include <net/ieee80211_crypt.h>                    2 #include <net/ieee80211_crypt.h>
  3                                                     3 
  4 #include "hostap_80211.h"                           4 #include "hostap_80211.h"
  5 #include "hostap.h"                                 5 #include "hostap.h"
  6 #include "hostap_ap.h"                              6 #include "hostap_ap.h"
  7                                                     7 
  8 /* See IEEE 802.1H for LLC/SNAP encapsulation/      8 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  9 /* Ethernet-II snap header (RFC1042 for most E      9 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
 10 static unsigned char rfc1042_header[] =            10 static unsigned char rfc1042_header[] =
 11 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };            11 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
 12 /* Bridge-Tunnel header (for EtherTypes ETH_P_     12 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
 13 static unsigned char bridge_tunnel_header[] =      13 static unsigned char bridge_tunnel_header[] =
 14 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };            14 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
 15 /* No encapsulation header if EtherType < 0x60     15 /* No encapsulation header if EtherType < 0x600 (=length) */
 16                                                    16 
 17 void hostap_dump_rx_80211(const char *name, st     17 void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
 18                           struct hostap_80211_     18                           struct hostap_80211_rx_status *rx_stats)
 19 {                                                  19 {
 20         struct ieee80211_hdr_4addr *hdr;           20         struct ieee80211_hdr_4addr *hdr;
 21         u16 fc;                                    21         u16 fc;
 22         DECLARE_MAC_BUF(mac);                      22         DECLARE_MAC_BUF(mac);
 23                                                    23 
 24         hdr = (struct ieee80211_hdr_4addr *) s     24         hdr = (struct ieee80211_hdr_4addr *) skb->data;
 25                                                    25 
 26         printk(KERN_DEBUG "%s: RX signal=%d no     26         printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
 27                "jiffies=%ld\n",                    27                "jiffies=%ld\n",
 28                name, rx_stats->signal, rx_stat     28                name, rx_stats->signal, rx_stats->noise, rx_stats->rate,
 29                skb->len, jiffies);                 29                skb->len, jiffies);
 30                                                    30 
 31         if (skb->len < 2)                          31         if (skb->len < 2)
 32                 return;                            32                 return;
 33                                                    33 
 34         fc = le16_to_cpu(hdr->frame_ctl);          34         fc = le16_to_cpu(hdr->frame_ctl);
 35         printk(KERN_DEBUG "   FC=0x%04x (type=     35         printk(KERN_DEBUG "   FC=0x%04x (type=%d:%d)%s%s",
 36                fc, WLAN_FC_GET_TYPE(fc) >> 2,      36                fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
 37                fc & IEEE80211_FCTL_TODS ? " [T     37                fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
 38                fc & IEEE80211_FCTL_FROMDS ? "      38                fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
 39                                                    39 
 40         if (skb->len < IEEE80211_DATA_HDR3_LEN     40         if (skb->len < IEEE80211_DATA_HDR3_LEN) {
 41                 printk("\n");                      41                 printk("\n");
 42                 return;                            42                 return;
 43         }                                          43         }
 44                                                    44 
 45         printk(" dur=0x%04x seq=0x%04x\n", le1     45         printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
 46                le16_to_cpu(hdr->seq_ctl));         46                le16_to_cpu(hdr->seq_ctl));
 47                                                    47 
 48         printk(KERN_DEBUG "   A1=%s", print_ma     48         printk(KERN_DEBUG "   A1=%s", print_mac(mac, hdr->addr1));
 49         printk(" A2=%s", print_mac(mac, hdr->a     49         printk(" A2=%s", print_mac(mac, hdr->addr2));
 50         printk(" A3=%s", print_mac(mac, hdr->a     50         printk(" A3=%s", print_mac(mac, hdr->addr3));
 51         if (skb->len >= 30)                        51         if (skb->len >= 30)
 52                 printk(" A4=%s", print_mac(mac     52                 printk(" A4=%s", print_mac(mac, hdr->addr4));
 53         printk("\n");                              53         printk("\n");
 54 }                                                  54 }
 55                                                    55 
 56                                                    56 
 57 /* Send RX frame to netif with 802.11 (and pos     57 /* Send RX frame to netif with 802.11 (and possible prism) header.
 58  * Called from hardware or software IRQ contex     58  * Called from hardware or software IRQ context. */
 59 int prism2_rx_80211(struct net_device *dev, st     59 int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
 60                     struct hostap_80211_rx_sta     60                     struct hostap_80211_rx_status *rx_stats, int type)
 61 {                                                  61 {
 62         struct hostap_interface *iface;            62         struct hostap_interface *iface;
 63         local_info_t *local;                       63         local_info_t *local;
 64         int hdrlen, phdrlen, head_need, tail_n     64         int hdrlen, phdrlen, head_need, tail_need;
 65         u16 fc;                                    65         u16 fc;
 66         int prism_header, ret;                     66         int prism_header, ret;
 67         struct ieee80211_hdr_4addr *hdr;           67         struct ieee80211_hdr_4addr *hdr;
 68                                                    68 
 69         iface = netdev_priv(dev);                  69         iface = netdev_priv(dev);
 70         local = iface->local;                      70         local = iface->local;
 71         dev->last_rx = jiffies;                    71         dev->last_rx = jiffies;
 72                                                    72 
 73         if (dev->type == ARPHRD_IEEE80211_PRIS     73         if (dev->type == ARPHRD_IEEE80211_PRISM) {
 74                 if (local->monitor_type == PRI     74                 if (local->monitor_type == PRISM2_MONITOR_PRISM) {
 75                         prism_header = 1;          75                         prism_header = 1;
 76                         phdrlen = sizeof(struc     76                         phdrlen = sizeof(struct linux_wlan_ng_prism_hdr);
 77                 } else { /* local->monitor_typ     77                 } else { /* local->monitor_type == PRISM2_MONITOR_CAPHDR */
 78                         prism_header = 2;          78                         prism_header = 2;
 79                         phdrlen = sizeof(struc     79                         phdrlen = sizeof(struct linux_wlan_ng_cap_hdr);
 80                 }                                  80                 }
 81         } else {                                   81         } else {
 82                 prism_header = 0;                  82                 prism_header = 0;
 83                 phdrlen = 0;                       83                 phdrlen = 0;
 84         }                                          84         }
 85                                                    85 
 86         hdr = (struct ieee80211_hdr_4addr *) s     86         hdr = (struct ieee80211_hdr_4addr *) skb->data;
 87         fc = le16_to_cpu(hdr->frame_ctl);          87         fc = le16_to_cpu(hdr->frame_ctl);
 88                                                    88 
 89         if (type == PRISM2_RX_MGMT && (fc & IE     89         if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
 90                 printk(KERN_DEBUG "%s: dropped     90                 printk(KERN_DEBUG "%s: dropped management frame with header "
 91                        "version %d\n", dev->na     91                        "version %d\n", dev->name, fc & IEEE80211_FCTL_VERS);
 92                 dev_kfree_skb_any(skb);            92                 dev_kfree_skb_any(skb);
 93                 return 0;                          93                 return 0;
 94         }                                          94         }
 95                                                    95 
 96         hdrlen = hostap_80211_get_hdrlen(fc);      96         hdrlen = hostap_80211_get_hdrlen(fc);
 97                                                    97 
 98         /* check if there is enough room for e     98         /* check if there is enough room for extra data; if not, expand skb
 99          * buffer to be large enough for the c     99          * buffer to be large enough for the changes */
100         head_need = phdrlen;                      100         head_need = phdrlen;
101         tail_need = 0;                            101         tail_need = 0;
102 #ifdef PRISM2_ADD_BOGUS_CRC                       102 #ifdef PRISM2_ADD_BOGUS_CRC
103         tail_need += 4;                           103         tail_need += 4;
104 #endif /* PRISM2_ADD_BOGUS_CRC */                 104 #endif /* PRISM2_ADD_BOGUS_CRC */
105                                                   105 
106         head_need -= skb_headroom(skb);           106         head_need -= skb_headroom(skb);
107         tail_need -= skb_tailroom(skb);           107         tail_need -= skb_tailroom(skb);
108                                                   108 
109         if (head_need > 0 || tail_need > 0) {     109         if (head_need > 0 || tail_need > 0) {
110                 if (pskb_expand_head(skb, head    110                 if (pskb_expand_head(skb, head_need > 0 ? head_need : 0,
111                                      tail_need    111                                      tail_need > 0 ? tail_need : 0,
112                                      GFP_ATOMI    112                                      GFP_ATOMIC)) {
113                         printk(KERN_DEBUG "%s:    113                         printk(KERN_DEBUG "%s: prism2_rx_80211 failed to "
114                                "reallocate skb    114                                "reallocate skb buffer\n", dev->name);
115                         dev_kfree_skb_any(skb)    115                         dev_kfree_skb_any(skb);
116                         return 0;                 116                         return 0;
117                 }                                 117                 }
118         }                                         118         }
119                                                   119 
120         /* We now have an skb with enough head    120         /* We now have an skb with enough head and tail room, so just insert
121          * the extra data */                      121          * the extra data */
122                                                   122 
123 #ifdef PRISM2_ADD_BOGUS_CRC                       123 #ifdef PRISM2_ADD_BOGUS_CRC
124         memset(skb_put(skb, 4), 0xff, 4); /* P    124         memset(skb_put(skb, 4), 0xff, 4); /* Prism2 strips CRC */
125 #endif /* PRISM2_ADD_BOGUS_CRC */                 125 #endif /* PRISM2_ADD_BOGUS_CRC */
126                                                   126 
127         if (prism_header == 1) {                  127         if (prism_header == 1) {
128                 struct linux_wlan_ng_prism_hdr    128                 struct linux_wlan_ng_prism_hdr *hdr;
129                 hdr = (struct linux_wlan_ng_pr    129                 hdr = (struct linux_wlan_ng_prism_hdr *)
130                         skb_push(skb, phdrlen)    130                         skb_push(skb, phdrlen);
131                 memset(hdr, 0, phdrlen);          131                 memset(hdr, 0, phdrlen);
132                 hdr->msgcode = LWNG_CAP_DID_BA    132                 hdr->msgcode = LWNG_CAP_DID_BASE;
133                 hdr->msglen = sizeof(*hdr);       133                 hdr->msglen = sizeof(*hdr);
134                 memcpy(hdr->devname, dev->name    134                 memcpy(hdr->devname, dev->name, sizeof(hdr->devname));
135 #define LWNG_SETVAL(f,i,s,l,d) \                  135 #define LWNG_SETVAL(f,i,s,l,d) \
136 hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \     136 hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \
137 hdr->f.status = s; hdr->f.len = l; hdr->f.data    137 hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
138                 LWNG_SETVAL(hosttime, 1, 0, 4,    138                 LWNG_SETVAL(hosttime, 1, 0, 4, jiffies);
139                 LWNG_SETVAL(mactime, 2, 0, 4,     139                 LWNG_SETVAL(mactime, 2, 0, 4, rx_stats->mac_time);
140                 LWNG_SETVAL(channel, 3, 1 /* n    140                 LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0);
141                 LWNG_SETVAL(rssi, 4, 1 /* no v    141                 LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0);
142                 LWNG_SETVAL(sq, 5, 1 /* no val    142                 LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0);
143                 LWNG_SETVAL(signal, 6, 0, 4, r    143                 LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal);
144                 LWNG_SETVAL(noise, 7, 0, 4, rx    144                 LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise);
145                 LWNG_SETVAL(rate, 8, 0, 4, rx_    145                 LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5);
146                 LWNG_SETVAL(istx, 9, 0, 4, 0);    146                 LWNG_SETVAL(istx, 9, 0, 4, 0);
147                 LWNG_SETVAL(frmlen, 10, 0, 4,     147                 LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen);
148 #undef LWNG_SETVAL                                148 #undef LWNG_SETVAL
149         } else if (prism_header == 2) {           149         } else if (prism_header == 2) {
150                 struct linux_wlan_ng_cap_hdr *    150                 struct linux_wlan_ng_cap_hdr *hdr;
151                 hdr = (struct linux_wlan_ng_ca    151                 hdr = (struct linux_wlan_ng_cap_hdr *)
152                         skb_push(skb, phdrlen)    152                         skb_push(skb, phdrlen);
153                 memset(hdr, 0, phdrlen);          153                 memset(hdr, 0, phdrlen);
154                 hdr->version    = htonl(LWNG_C    154                 hdr->version    = htonl(LWNG_CAPHDR_VERSION);
155                 hdr->length     = htonl(phdrle    155                 hdr->length     = htonl(phdrlen);
156                 hdr->mactime    = __cpu_to_be6    156                 hdr->mactime    = __cpu_to_be64(rx_stats->mac_time);
157                 hdr->hosttime   = __cpu_to_be6    157                 hdr->hosttime   = __cpu_to_be64(jiffies);
158                 hdr->phytype    = htonl(4); /*    158                 hdr->phytype    = htonl(4); /* dss_dot11_b */
159                 hdr->channel    = htonl(local-    159                 hdr->channel    = htonl(local->channel);
160                 hdr->datarate   = htonl(rx_sta    160                 hdr->datarate   = htonl(rx_stats->rate);
161                 hdr->antenna    = htonl(0); /*    161                 hdr->antenna    = htonl(0); /* unknown */
162                 hdr->priority   = htonl(0); /*    162                 hdr->priority   = htonl(0); /* unknown */
163                 hdr->ssi_type   = htonl(3); /*    163                 hdr->ssi_type   = htonl(3); /* raw */
164                 hdr->ssi_signal = htonl(rx_sta    164                 hdr->ssi_signal = htonl(rx_stats->signal);
165                 hdr->ssi_noise  = htonl(rx_sta    165                 hdr->ssi_noise  = htonl(rx_stats->noise);
166                 hdr->preamble   = htonl(0); /*    166                 hdr->preamble   = htonl(0); /* unknown */
167                 hdr->encoding   = htonl(1); /*    167                 hdr->encoding   = htonl(1); /* cck */
168         }                                         168         }
169                                                   169 
170         ret = skb->len - phdrlen;                 170         ret = skb->len - phdrlen;
171         skb->dev = dev;                           171         skb->dev = dev;
172         skb_reset_mac_header(skb);                172         skb_reset_mac_header(skb);
173         skb_pull(skb, hdrlen);                    173         skb_pull(skb, hdrlen);
174         if (prism_header)                         174         if (prism_header)
175                 skb_pull(skb, phdrlen);           175                 skb_pull(skb, phdrlen);
176         skb->pkt_type = PACKET_OTHERHOST;         176         skb->pkt_type = PACKET_OTHERHOST;
177         skb->protocol = __constant_htons(ETH_P    177         skb->protocol = __constant_htons(ETH_P_802_2);
178         memset(skb->cb, 0, sizeof(skb->cb));      178         memset(skb->cb, 0, sizeof(skb->cb));
179         netif_rx(skb);                            179         netif_rx(skb);
180                                                   180 
181         return ret;                               181         return ret;
182 }                                                 182 }
183                                                   183 
184                                                   184 
185 /* Called only as a tasklet (software IRQ) */     185 /* Called only as a tasklet (software IRQ) */
186 static void monitor_rx(struct net_device *dev,    186 static void monitor_rx(struct net_device *dev, struct sk_buff *skb,
187                        struct hostap_80211_rx_    187                        struct hostap_80211_rx_status *rx_stats)
188 {                                                 188 {
189         struct net_device_stats *stats;           189         struct net_device_stats *stats;
190         int len;                                  190         int len;
191                                                   191 
192         len = prism2_rx_80211(dev, skb, rx_sta    192         len = prism2_rx_80211(dev, skb, rx_stats, PRISM2_RX_MONITOR);
193         stats = hostap_get_stats(dev);            193         stats = hostap_get_stats(dev);
194         stats->rx_packets++;                      194         stats->rx_packets++;
195         stats->rx_bytes += len;                   195         stats->rx_bytes += len;
196 }                                                 196 }
197                                                   197 
198                                                   198 
199 /* Called only as a tasklet (software IRQ) */     199 /* Called only as a tasklet (software IRQ) */
200 static struct prism2_frag_entry *                 200 static struct prism2_frag_entry *
201 prism2_frag_cache_find(local_info_t *local, un    201 prism2_frag_cache_find(local_info_t *local, unsigned int seq,
202                        unsigned int frag, u8 *    202                        unsigned int frag, u8 *src, u8 *dst)
203 {                                                 203 {
204         struct prism2_frag_entry *entry;          204         struct prism2_frag_entry *entry;
205         int i;                                    205         int i;
206                                                   206 
207         for (i = 0; i < PRISM2_FRAG_CACHE_LEN;    207         for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
208                 entry = &local->frag_cache[i];    208                 entry = &local->frag_cache[i];
209                 if (entry->skb != NULL &&         209                 if (entry->skb != NULL &&
210                     time_after(jiffies, entry-    210                     time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
211                         printk(KERN_DEBUG "%s:    211                         printk(KERN_DEBUG "%s: expiring fragment cache entry "
212                                "seq=%u last_fr    212                                "seq=%u last_frag=%u\n",
213                                local->dev->nam    213                                local->dev->name, entry->seq, entry->last_frag);
214                         dev_kfree_skb(entry->s    214                         dev_kfree_skb(entry->skb);
215                         entry->skb = NULL;        215                         entry->skb = NULL;
216                 }                                 216                 }
217                                                   217 
218                 if (entry->skb != NULL && entr    218                 if (entry->skb != NULL && entry->seq == seq &&
219                     (entry->last_frag + 1 == f    219                     (entry->last_frag + 1 == frag || frag == -1) &&
220                     memcmp(entry->src_addr, sr    220                     memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
221                     memcmp(entry->dst_addr, ds    221                     memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
222                         return entry;             222                         return entry;
223         }                                         223         }
224                                                   224 
225         return NULL;                              225         return NULL;
226 }                                                 226 }
227                                                   227 
228                                                   228 
229 /* Called only as a tasklet (software IRQ) */     229 /* Called only as a tasklet (software IRQ) */
230 static struct sk_buff *                           230 static struct sk_buff *
231 prism2_frag_cache_get(local_info_t *local, str    231 prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
232 {                                                 232 {
233         struct sk_buff *skb = NULL;               233         struct sk_buff *skb = NULL;
234         u16 sc;                                   234         u16 sc;
235         unsigned int frag, seq;                   235         unsigned int frag, seq;
236         struct prism2_frag_entry *entry;          236         struct prism2_frag_entry *entry;
237                                                   237 
238         sc = le16_to_cpu(hdr->seq_ctl);           238         sc = le16_to_cpu(hdr->seq_ctl);
239         frag = WLAN_GET_SEQ_FRAG(sc);             239         frag = WLAN_GET_SEQ_FRAG(sc);
240         seq = WLAN_GET_SEQ_SEQ(sc) >> 4;          240         seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
241                                                   241 
242         if (frag == 0) {                          242         if (frag == 0) {
243                 /* Reserve enough space to fit    243                 /* Reserve enough space to fit maximum frame length */
244                 skb = dev_alloc_skb(local->dev    244                 skb = dev_alloc_skb(local->dev->mtu +
245                                     sizeof(str    245                                     sizeof(struct ieee80211_hdr_4addr) +
246                                     8 /* LLC *    246                                     8 /* LLC */ +
247                                     2 /* align    247                                     2 /* alignment */ +
248                                     8 /* WEP *    248                                     8 /* WEP */ + ETH_ALEN /* WDS */);
249                 if (skb == NULL)                  249                 if (skb == NULL)
250                         return NULL;              250                         return NULL;
251                                                   251 
252                 entry = &local->frag_cache[loc    252                 entry = &local->frag_cache[local->frag_next_idx];
253                 local->frag_next_idx++;           253                 local->frag_next_idx++;
254                 if (local->frag_next_idx >= PR    254                 if (local->frag_next_idx >= PRISM2_FRAG_CACHE_LEN)
255                         local->frag_next_idx =    255                         local->frag_next_idx = 0;
256                                                   256 
257                 if (entry->skb != NULL)           257                 if (entry->skb != NULL)
258                         dev_kfree_skb(entry->s    258                         dev_kfree_skb(entry->skb);
259                                                   259 
260                 entry->first_frag_time = jiffi    260                 entry->first_frag_time = jiffies;
261                 entry->seq = seq;                 261                 entry->seq = seq;
262                 entry->last_frag = frag;          262                 entry->last_frag = frag;
263                 entry->skb = skb;                 263                 entry->skb = skb;
264                 memcpy(entry->src_addr, hdr->a    264                 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
265                 memcpy(entry->dst_addr, hdr->a    265                 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
266         } else {                                  266         } else {
267                 /* received a fragment of a fr    267                 /* received a fragment of a frame for which the head fragment
268                  * should have already been re    268                  * should have already been received */
269                 entry = prism2_frag_cache_find    269                 entry = prism2_frag_cache_find(local, seq, frag, hdr->addr2,
270                                                   270                                                hdr->addr1);
271                 if (entry != NULL) {              271                 if (entry != NULL) {
272                         entry->last_frag = fra    272                         entry->last_frag = frag;
273                         skb = entry->skb;         273                         skb = entry->skb;
274                 }                                 274                 }
275         }                                         275         }
276                                                   276 
277         return skb;                               277         return skb;
278 }                                                 278 }
279                                                   279 
280                                                   280 
281 /* Called only as a tasklet (software IRQ) */     281 /* Called only as a tasklet (software IRQ) */
282 static int prism2_frag_cache_invalidate(local_    282 static int prism2_frag_cache_invalidate(local_info_t *local,
283                                         struct    283                                         struct ieee80211_hdr_4addr *hdr)
284 {                                                 284 {
285         u16 sc;                                   285         u16 sc;
286         unsigned int seq;                         286         unsigned int seq;
287         struct prism2_frag_entry *entry;          287         struct prism2_frag_entry *entry;
288                                                   288 
289         sc = le16_to_cpu(hdr->seq_ctl);           289         sc = le16_to_cpu(hdr->seq_ctl);
290         seq = WLAN_GET_SEQ_SEQ(sc) >> 4;          290         seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
291                                                   291 
292         entry = prism2_frag_cache_find(local,     292         entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1);
293                                                   293 
294         if (entry == NULL) {                      294         if (entry == NULL) {
295                 printk(KERN_DEBUG "%s: could n    295                 printk(KERN_DEBUG "%s: could not invalidate fragment cache "
296                        "entry (seq=%u)\n",        296                        "entry (seq=%u)\n",
297                        local->dev->name, seq);    297                        local->dev->name, seq);
298                 return -1;                        298                 return -1;
299         }                                         299         }
300                                                   300 
301         entry->skb = NULL;                        301         entry->skb = NULL;
302         return 0;                                 302         return 0;
303 }                                                 303 }
304                                                   304 
305                                                   305 
306 static struct hostap_bss_info *__hostap_get_bs    306 static struct hostap_bss_info *__hostap_get_bss(local_info_t *local, u8 *bssid,
307                                                   307                                                 u8 *ssid, size_t ssid_len)
308 {                                                 308 {
309         struct list_head *ptr;                    309         struct list_head *ptr;
310         struct hostap_bss_info *bss;              310         struct hostap_bss_info *bss;
311                                                   311 
312         list_for_each(ptr, &local->bss_list) {    312         list_for_each(ptr, &local->bss_list) {
313                 bss = list_entry(ptr, struct h    313                 bss = list_entry(ptr, struct hostap_bss_info, list);
314                 if (memcmp(bss->bssid, bssid,     314                 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
315                     (ssid == NULL ||              315                     (ssid == NULL ||
316                      (ssid_len == bss->ssid_le    316                      (ssid_len == bss->ssid_len &&
317                       memcmp(ssid, bss->ssid,     317                       memcmp(ssid, bss->ssid, ssid_len) == 0))) {
318                         list_move(&bss->list,     318                         list_move(&bss->list, &local->bss_list);
319                         return bss;               319                         return bss;
320                 }                                 320                 }
321         }                                         321         }
322                                                   322 
323         return NULL;                              323         return NULL;
324 }                                                 324 }
325                                                   325 
326                                                   326 
327 static struct hostap_bss_info *__hostap_add_bs    327 static struct hostap_bss_info *__hostap_add_bss(local_info_t *local, u8 *bssid,
328                                                   328                                                 u8 *ssid, size_t ssid_len)
329 {                                                 329 {
330         struct hostap_bss_info *bss;              330         struct hostap_bss_info *bss;
331                                                   331 
332         if (local->num_bss_info >= HOSTAP_MAX_    332         if (local->num_bss_info >= HOSTAP_MAX_BSS_COUNT) {
333                 bss = list_entry(local->bss_li    333                 bss = list_entry(local->bss_list.prev,
334                                  struct hostap    334                                  struct hostap_bss_info, list);
335                 list_del(&bss->list);             335                 list_del(&bss->list);
336                 local->num_bss_info--;            336                 local->num_bss_info--;
337         } else {                                  337         } else {
338                 bss = (struct hostap_bss_info     338                 bss = (struct hostap_bss_info *)
339                         kmalloc(sizeof(*bss),     339                         kmalloc(sizeof(*bss), GFP_ATOMIC);
340                 if (bss == NULL)                  340                 if (bss == NULL)
341                         return NULL;              341                         return NULL;
342         }                                         342         }
343                                                   343 
344         memset(bss, 0, sizeof(*bss));             344         memset(bss, 0, sizeof(*bss));
345         memcpy(bss->bssid, bssid, ETH_ALEN);      345         memcpy(bss->bssid, bssid, ETH_ALEN);
346         memcpy(bss->ssid, ssid, ssid_len);        346         memcpy(bss->ssid, ssid, ssid_len);
347         bss->ssid_len = ssid_len;                 347         bss->ssid_len = ssid_len;
348         local->num_bss_info++;                    348         local->num_bss_info++;
349         list_add(&bss->list, &local->bss_list)    349         list_add(&bss->list, &local->bss_list);
350         return bss;                               350         return bss;
351 }                                                 351 }
352                                                   352 
353                                                   353 
354 static void __hostap_expire_bss(local_info_t *    354 static void __hostap_expire_bss(local_info_t *local)
355 {                                                 355 {
356         struct hostap_bss_info *bss;              356         struct hostap_bss_info *bss;
357                                                   357 
358         while (local->num_bss_info > 0) {         358         while (local->num_bss_info > 0) {
359                 bss = list_entry(local->bss_li    359                 bss = list_entry(local->bss_list.prev,
360                                  struct hostap    360                                  struct hostap_bss_info, list);
361                 if (!time_after(jiffies, bss->    361                 if (!time_after(jiffies, bss->last_update + 60 * HZ))
362                         break;                    362                         break;
363                                                   363 
364                 list_del(&bss->list);             364                 list_del(&bss->list);
365                 local->num_bss_info--;            365                 local->num_bss_info--;
366                 kfree(bss);                       366                 kfree(bss);
367         }                                         367         }
368 }                                                 368 }
369                                                   369 
370                                                   370 
371 /* Both IEEE 802.11 Beacon and Probe Response     371 /* Both IEEE 802.11 Beacon and Probe Response frames have similar structure, so
372  * the same routine can be used to parse both     372  * the same routine can be used to parse both of them. */
373 static void hostap_rx_sta_beacon(local_info_t     373 static void hostap_rx_sta_beacon(local_info_t *local, struct sk_buff *skb,
374                                  int stype)       374                                  int stype)
375 {                                                 375 {
376         struct hostap_ieee80211_mgmt *mgmt;       376         struct hostap_ieee80211_mgmt *mgmt;
377         int left, chan = 0;                       377         int left, chan = 0;
378         u8 *pos;                                  378         u8 *pos;
379         u8 *ssid = NULL, *wpa = NULL, *rsn = N    379         u8 *ssid = NULL, *wpa = NULL, *rsn = NULL;
380         size_t ssid_len = 0, wpa_len = 0, rsn_    380         size_t ssid_len = 0, wpa_len = 0, rsn_len = 0;
381         struct hostap_bss_info *bss;              381         struct hostap_bss_info *bss;
382                                                   382 
383         if (skb->len < IEEE80211_MGMT_HDR_LEN     383         if (skb->len < IEEE80211_MGMT_HDR_LEN + sizeof(mgmt->u.beacon))
384                 return;                           384                 return;
385                                                   385 
386         mgmt = (struct hostap_ieee80211_mgmt *    386         mgmt = (struct hostap_ieee80211_mgmt *) skb->data;
387         pos = mgmt->u.beacon.variable;            387         pos = mgmt->u.beacon.variable;
388         left = skb->len - (pos - skb->data);      388         left = skb->len - (pos - skb->data);
389                                                   389 
390         while (left >= 2) {                       390         while (left >= 2) {
391                 if (2 + pos[1] > left)            391                 if (2 + pos[1] > left)
392                         return; /* parse faile    392                         return; /* parse failed */
393                 switch (*pos) {                   393                 switch (*pos) {
394                 case WLAN_EID_SSID:               394                 case WLAN_EID_SSID:
395                         ssid = pos + 2;           395                         ssid = pos + 2;
396                         ssid_len = pos[1];        396                         ssid_len = pos[1];
397                         break;                    397                         break;
398                 case WLAN_EID_GENERIC:            398                 case WLAN_EID_GENERIC:
399                         if (pos[1] >= 4 &&        399                         if (pos[1] >= 4 &&
400                             pos[2] == 0x00 &&     400                             pos[2] == 0x00 && pos[3] == 0x50 &&
401                             pos[4] == 0xf2 &&     401                             pos[4] == 0xf2 && pos[5] == 1) {
402                                 wpa = pos;        402                                 wpa = pos;
403                                 wpa_len = pos[    403                                 wpa_len = pos[1] + 2;
404                         }                         404                         }
405                         break;                    405                         break;
406                 case WLAN_EID_RSN:                406                 case WLAN_EID_RSN:
407                         rsn = pos;                407                         rsn = pos;
408                         rsn_len = pos[1] + 2;     408                         rsn_len = pos[1] + 2;
409                         break;                    409                         break;
410                 case WLAN_EID_DS_PARAMS:          410                 case WLAN_EID_DS_PARAMS:
411                         if (pos[1] >= 1)          411                         if (pos[1] >= 1)
412                                 chan = pos[2];    412                                 chan = pos[2];
413                         break;                    413                         break;
414                 }                                 414                 }
415                 left -= 2 + pos[1];               415                 left -= 2 + pos[1];
416                 pos += 2 + pos[1];                416                 pos += 2 + pos[1];
417         }                                         417         }
418                                                   418 
419         if (wpa_len > MAX_WPA_IE_LEN)             419         if (wpa_len > MAX_WPA_IE_LEN)
420                 wpa_len = MAX_WPA_IE_LEN;         420                 wpa_len = MAX_WPA_IE_LEN;
421         if (rsn_len > MAX_WPA_IE_LEN)             421         if (rsn_len > MAX_WPA_IE_LEN)
422                 rsn_len = MAX_WPA_IE_LEN;         422                 rsn_len = MAX_WPA_IE_LEN;
423         if (ssid_len > sizeof(bss->ssid))         423         if (ssid_len > sizeof(bss->ssid))
424                 ssid_len = sizeof(bss->ssid);     424                 ssid_len = sizeof(bss->ssid);
425                                                   425 
426         spin_lock(&local->lock);                  426         spin_lock(&local->lock);
427         bss = __hostap_get_bss(local, mgmt->bs    427         bss = __hostap_get_bss(local, mgmt->bssid, ssid, ssid_len);
428         if (bss == NULL)                          428         if (bss == NULL)
429                 bss = __hostap_add_bss(local,     429                 bss = __hostap_add_bss(local, mgmt->bssid, ssid, ssid_len);
430         if (bss) {                                430         if (bss) {
431                 bss->last_update = jiffies;       431                 bss->last_update = jiffies;
432                 bss->count++;                     432                 bss->count++;
433                 bss->capab_info = le16_to_cpu(    433                 bss->capab_info = le16_to_cpu(mgmt->u.beacon.capab_info);
434                 if (wpa) {                        434                 if (wpa) {
435                         memcpy(bss->wpa_ie, wp    435                         memcpy(bss->wpa_ie, wpa, wpa_len);
436                         bss->wpa_ie_len = wpa_    436                         bss->wpa_ie_len = wpa_len;
437                 } else                            437                 } else
438                         bss->wpa_ie_len = 0;      438                         bss->wpa_ie_len = 0;
439                 if (rsn) {                        439                 if (rsn) {
440                         memcpy(bss->rsn_ie, rs    440                         memcpy(bss->rsn_ie, rsn, rsn_len);
441                         bss->rsn_ie_len = rsn_    441                         bss->rsn_ie_len = rsn_len;
442                 } else                            442                 } else
443                         bss->rsn_ie_len = 0;      443                         bss->rsn_ie_len = 0;
444                 bss->chan = chan;                 444                 bss->chan = chan;
445         }                                         445         }
446         __hostap_expire_bss(local);               446         __hostap_expire_bss(local);
447         spin_unlock(&local->lock);                447         spin_unlock(&local->lock);
448 }                                                 448 }
449                                                   449 
450                                                   450 
451 static int                                        451 static int
452 hostap_rx_frame_mgmt(local_info_t *local, stru    452 hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
453                      struct hostap_80211_rx_st    453                      struct hostap_80211_rx_status *rx_stats, u16 type,
454                      u16 stype)                   454                      u16 stype)
455 {                                                 455 {
456         if (local->iw_mode == IW_MODE_MASTER)     456         if (local->iw_mode == IW_MODE_MASTER) {
457                 hostap_update_sta_ps(local, (s    457                 hostap_update_sta_ps(local, (struct ieee80211_hdr_4addr *)
458                                      skb->data    458                                      skb->data);
459         }                                         459         }
460                                                   460 
461         if (local->hostapd && type == IEEE8021    461         if (local->hostapd && type == IEEE80211_FTYPE_MGMT) {
462                 if (stype == IEEE80211_STYPE_B    462                 if (stype == IEEE80211_STYPE_BEACON &&
463                     local->iw_mode == IW_MODE_    463                     local->iw_mode == IW_MODE_MASTER) {
464                         struct sk_buff *skb2;     464                         struct sk_buff *skb2;
465                         /* Process beacon fram    465                         /* Process beacon frames also in kernel driver to
466                          * update STA(AP) tabl    466                          * update STA(AP) table statistics */
467                         skb2 = skb_clone(skb,     467                         skb2 = skb_clone(skb, GFP_ATOMIC);
468                         if (skb2)                 468                         if (skb2)
469                                 hostap_rx(skb2    469                                 hostap_rx(skb2->dev, skb2, rx_stats);
470                 }                                 470                 }
471                                                   471 
472                 /* send management frames to t    472                 /* send management frames to the user space daemon for
473                  * processing */                  473                  * processing */
474                 local->apdevstats.rx_packets++    474                 local->apdevstats.rx_packets++;
475                 local->apdevstats.rx_bytes +=     475                 local->apdevstats.rx_bytes += skb->len;
476                 if (local->apdev == NULL)         476                 if (local->apdev == NULL)
477                         return -1;                477                         return -1;
478                 prism2_rx_80211(local->apdev,     478                 prism2_rx_80211(local->apdev, skb, rx_stats, PRISM2_RX_MGMT);
479                 return 0;                         479                 return 0;
480         }                                         480         }
481                                                   481 
482         if (local->iw_mode == IW_MODE_MASTER)     482         if (local->iw_mode == IW_MODE_MASTER) {
483                 if (type != IEEE80211_FTYPE_MG    483                 if (type != IEEE80211_FTYPE_MGMT &&
484                     type != IEEE80211_FTYPE_CT    484                     type != IEEE80211_FTYPE_CTL) {
485                         printk(KERN_DEBUG "%s:    485                         printk(KERN_DEBUG "%s: unknown management frame "
486                                "(type=0x%02x,     486                                "(type=0x%02x, stype=0x%02x) dropped\n",
487                                skb->dev->name,    487                                skb->dev->name, type >> 2, stype >> 4);
488                         return -1;                488                         return -1;
489                 }                                 489                 }
490                                                   490 
491                 hostap_rx(skb->dev, skb, rx_st    491                 hostap_rx(skb->dev, skb, rx_stats);
492                 return 0;                         492                 return 0;
493         } else if (type == IEEE80211_FTYPE_MGM    493         } else if (type == IEEE80211_FTYPE_MGMT &&
494                    (stype == IEEE80211_STYPE_B    494                    (stype == IEEE80211_STYPE_BEACON ||
495                     stype == IEEE80211_STYPE_P    495                     stype == IEEE80211_STYPE_PROBE_RESP)) {
496                 hostap_rx_sta_beacon(local, sk    496                 hostap_rx_sta_beacon(local, skb, stype);
497                 return -1;                        497                 return -1;
498         } else if (type == IEEE80211_FTYPE_MGM    498         } else if (type == IEEE80211_FTYPE_MGMT &&
499                    (stype == IEEE80211_STYPE_A    499                    (stype == IEEE80211_STYPE_ASSOC_RESP ||
500                     stype == IEEE80211_STYPE_R    500                     stype == IEEE80211_STYPE_REASSOC_RESP)) {
501                 /* Ignore (Re)AssocResp silent    501                 /* Ignore (Re)AssocResp silently since these are not currently
502                  * needed but are still receiv    502                  * needed but are still received when WPA/RSN mode is enabled.
503                  */                               503                  */
504                 return -1;                        504                 return -1;
505         } else {                                  505         } else {
506                 printk(KERN_DEBUG "%s: hostap_    506                 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: dropped unhandled"
507                        " management frame in n    507                        " management frame in non-Host AP mode (type=%d:%d)\n",
508                        skb->dev->name, type >>    508                        skb->dev->name, type >> 2, stype >> 4);
509                 return -1;                        509                 return -1;
510         }                                         510         }
511 }                                                 511 }
512                                                   512 
513                                                   513 
514 /* Called only as a tasklet (software IRQ) */     514 /* Called only as a tasklet (software IRQ) */
515 static struct net_device *prism2_rx_get_wds(lo    515 static struct net_device *prism2_rx_get_wds(local_info_t *local,
516                                                   516                                                    u8 *addr)
517 {                                                 517 {
518         struct hostap_interface *iface = NULL;    518         struct hostap_interface *iface = NULL;
519         struct list_head *ptr;                    519         struct list_head *ptr;
520                                                   520 
521         read_lock_bh(&local->iface_lock);         521         read_lock_bh(&local->iface_lock);
522         list_for_each(ptr, &local->hostap_inte    522         list_for_each(ptr, &local->hostap_interfaces) {
523                 iface = list_entry(ptr, struct    523                 iface = list_entry(ptr, struct hostap_interface, list);
524                 if (iface->type == HOSTAP_INTE    524                 if (iface->type == HOSTAP_INTERFACE_WDS &&
525                     memcmp(iface->u.wds.remote    525                     memcmp(iface->u.wds.remote_addr, addr, ETH_ALEN) == 0)
526                         break;                    526                         break;
527                 iface = NULL;                     527                 iface = NULL;
528         }                                         528         }
529         read_unlock_bh(&local->iface_lock);       529         read_unlock_bh(&local->iface_lock);
530                                                   530 
531         return iface ? iface->dev : NULL;         531         return iface ? iface->dev : NULL;
532 }                                                 532 }
533                                                   533 
534                                                   534 
535 static int                                        535 static int
536 hostap_rx_frame_wds(local_info_t *local, struc    536 hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
537                     u16 fc, struct net_device     537                     u16 fc, struct net_device **wds)
538 {                                                 538 {
539         DECLARE_MAC_BUF(mac);                     539         DECLARE_MAC_BUF(mac);
540         /* FIX: is this really supposed to acc    540         /* FIX: is this really supposed to accept WDS frames only in Master
541          * mode? What about Repeater or Manage    541          * mode? What about Repeater or Managed with WDS frames? */
542         if ((fc & (IEEE80211_FCTL_TODS | IEEE8    542         if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) !=
543             (IEEE80211_FCTL_TODS | IEEE80211_F    543             (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS) &&
544             (local->iw_mode != IW_MODE_MASTER     544             (local->iw_mode != IW_MODE_MASTER || !(fc & IEEE80211_FCTL_TODS)))
545                 return 0; /* not a WDS frame *    545                 return 0; /* not a WDS frame */
546                                                   546 
547         /* Possible WDS frame: either IEEE 802    547         /* Possible WDS frame: either IEEE 802.11 compliant (if FromDS)
548          * or own non-standard frame with 4th     548          * or own non-standard frame with 4th address after payload */
549         if (memcmp(hdr->addr1, local->dev->dev    549         if (memcmp(hdr->addr1, local->dev->dev_addr, ETH_ALEN) != 0 &&
550             (hdr->addr1[0] != 0xff || hdr->add    550             (hdr->addr1[0] != 0xff || hdr->addr1[1] != 0xff ||
551              hdr->addr1[2] != 0xff || hdr->add    551              hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff ||
552              hdr->addr1[4] != 0xff || hdr->add    552              hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
553                 /* RA (or BSSID) is not ours -    553                 /* RA (or BSSID) is not ours - drop */
554                 PDEBUG(DEBUG_EXTRA, "%s: recei    554                 PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with "
555                        "not own or broadcast %    555                        "not own or broadcast %s=%s\n",
556                        local->dev->name,          556                        local->dev->name,
557                        fc & IEEE80211_FCTL_FRO    557                        fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID",
558                        print_mac(mac, hdr->add    558                        print_mac(mac, hdr->addr1));
559                 return -1;                        559                 return -1;
560         }                                         560         }
561                                                   561 
562         /* check if the frame came from a regi    562         /* check if the frame came from a registered WDS connection */
563         *wds = prism2_rx_get_wds(local, hdr->a    563         *wds = prism2_rx_get_wds(local, hdr->addr2);
564         if (*wds == NULL && fc & IEEE80211_FCT    564         if (*wds == NULL && fc & IEEE80211_FCTL_FROMDS &&
565             (local->iw_mode != IW_MODE_INFRA |    565             (local->iw_mode != IW_MODE_INFRA ||
566              !(local->wds_type & HOSTAP_WDS_AP    566              !(local->wds_type & HOSTAP_WDS_AP_CLIENT) ||
567              memcmp(hdr->addr2, local->bssid,     567              memcmp(hdr->addr2, local->bssid, ETH_ALEN) != 0)) {
568                 /* require that WDS link has b    568                 /* require that WDS link has been registered with TA or the
569                  * frame is from current AP wh    569                  * frame is from current AP when using 'AP client mode' */
570                 PDEBUG(DEBUG_EXTRA, "%s: recei    570                 PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame "
571                        "from unknown TA=%s\n",    571                        "from unknown TA=%s\n",
572                        local->dev->name, print    572                        local->dev->name, print_mac(mac, hdr->addr2));
573                 if (local->ap && local->ap->au    573                 if (local->ap && local->ap->autom_ap_wds)
574                         hostap_wds_link_oper(l    574                         hostap_wds_link_oper(local, hdr->addr2, WDS_ADD);
575                 return -1;                        575                 return -1;
576         }                                         576         }
577                                                   577 
578         if (*wds && !(fc & IEEE80211_FCTL_FROM    578         if (*wds && !(fc & IEEE80211_FCTL_FROMDS) && local->ap &&
579             hostap_is_sta_assoc(local->ap, hdr    579             hostap_is_sta_assoc(local->ap, hdr->addr2)) {
580                 /* STA is actually associated     580                 /* STA is actually associated with us even though it has a
581                  * registered WDS link. Assume    581                  * registered WDS link. Assume it is in 'AP client' mode.
582                  * Since this is a 3-addr fram    582                  * Since this is a 3-addr frame, assume it is not (bogus) WDS
583                  * frame and process it like a    583                  * frame and process it like any normal ToDS frame from
584                  * associated STA. */             584                  * associated STA. */
585                 *wds = NULL;                      585                 *wds = NULL;
586         }                                         586         }
587                                                   587 
588         return 0;                                 588         return 0;
589 }                                                 589 }
590                                                   590 
591                                                   591 
592 static int hostap_is_eapol_frame(local_info_t     592 static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
593 {                                                 593 {
594         struct net_device *dev = local->dev;      594         struct net_device *dev = local->dev;
595         u16 fc, ethertype;                        595         u16 fc, ethertype;
596         struct ieee80211_hdr_4addr *hdr;          596         struct ieee80211_hdr_4addr *hdr;
597         u8 *pos;                                  597         u8 *pos;
598                                                   598 
599         if (skb->len < 24)                        599         if (skb->len < 24)
600                 return 0;                         600                 return 0;
601                                                   601 
602         hdr = (struct ieee80211_hdr_4addr *) s    602         hdr = (struct ieee80211_hdr_4addr *) skb->data;
603         fc = le16_to_cpu(hdr->frame_ctl);         603         fc = le16_to_cpu(hdr->frame_ctl);
604                                                   604 
605         /* check that the frame is unicast fra    605         /* check that the frame is unicast frame to us */
606         if ((fc & (IEEE80211_FCTL_TODS | IEEE8    606         if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
607             IEEE80211_FCTL_TODS &&                607             IEEE80211_FCTL_TODS &&
608             memcmp(hdr->addr1, dev->dev_addr,     608             memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
609             memcmp(hdr->addr3, dev->dev_addr,     609             memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
610                 /* ToDS frame with own addr BS    610                 /* ToDS frame with own addr BSSID and DA */
611         } else if ((fc & (IEEE80211_FCTL_TODS     611         } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
612                    IEEE80211_FCTL_FROMDS &&       612                    IEEE80211_FCTL_FROMDS &&
613                    memcmp(hdr->addr1, dev->dev    613                    memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
614                 /* FromDS frame with own addr     614                 /* FromDS frame with own addr as DA */
615         } else                                    615         } else
616                 return 0;                         616                 return 0;
617                                                   617 
618         if (skb->len < 24 + 8)                    618         if (skb->len < 24 + 8)
619                 return 0;                         619                 return 0;
620                                                   620 
621         /* check for port access entity Ethern    621         /* check for port access entity Ethernet type */
622         pos = skb->data + 24;                     622         pos = skb->data + 24;
623         ethertype = (pos[6] << 8) | pos[7];       623         ethertype = (pos[6] << 8) | pos[7];
624         if (ethertype == ETH_P_PAE)               624         if (ethertype == ETH_P_PAE)
625                 return 1;                         625                 return 1;
626                                                   626 
627         return 0;                                 627         return 0;
628 }                                                 628 }
629                                                   629 
630                                                   630 
631 /* Called only as a tasklet (software IRQ) */     631 /* Called only as a tasklet (software IRQ) */
632 static int                                        632 static int
633 hostap_rx_frame_decrypt(local_info_t *local, s    633 hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
634                         struct ieee80211_crypt    634                         struct ieee80211_crypt_data *crypt)
635 {                                                 635 {
636         struct ieee80211_hdr_4addr *hdr;          636         struct ieee80211_hdr_4addr *hdr;
637         int res, hdrlen;                          637         int res, hdrlen;
638                                                   638 
639         if (crypt == NULL || crypt->ops->decry    639         if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
640                 return 0;                         640                 return 0;
641                                                   641 
642         hdr = (struct ieee80211_hdr_4addr *) s    642         hdr = (struct ieee80211_hdr_4addr *) skb->data;
643         hdrlen = hostap_80211_get_hdrlen(le16_    643         hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
644                                                   644 
645         if (local->tkip_countermeasures &&        645         if (local->tkip_countermeasures &&
646             strcmp(crypt->ops->name, "TKIP") =    646             strcmp(crypt->ops->name, "TKIP") == 0) {
647                 if (net_ratelimit()) {            647                 if (net_ratelimit()) {
648                         printk(KERN_DEBUG "%s:    648                         printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
649                                "received packe    649                                "received packet from " MAC_FMT "\n",
650                                local->dev->nam    650                                local->dev->name,
651                                hdr->addr2[0],     651                                hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
652                                hdr->addr2[3],     652                                hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
653                 }                                 653                 }
654                 return -1;                        654                 return -1;
655         }                                         655         }
656                                                   656 
657         atomic_inc(&crypt->refcnt);               657         atomic_inc(&crypt->refcnt);
658         res = crypt->ops->decrypt_mpdu(skb, hd    658         res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
659         atomic_dec(&crypt->refcnt);               659         atomic_dec(&crypt->refcnt);
660         if (res < 0) {                            660         if (res < 0) {
661                 printk(KERN_DEBUG "%s: decrypt    661                 printk(KERN_DEBUG "%s: decryption failed (SA=" MAC_FMT
662                        ") res=%d\n",              662                        ") res=%d\n",
663                        local->dev->name,          663                        local->dev->name,
664                        hdr->addr2[0], hdr->add    664                        hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
665                        hdr->addr2[3], hdr->add    665                        hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
666                        res);                      666                        res);
667                 local->comm_tallies.rx_discard    667                 local->comm_tallies.rx_discards_wep_undecryptable++;
668                 return -1;                        668                 return -1;
669         }                                         669         }
670                                                   670 
671         return res;                               671         return res;
672 }                                                 672 }
673                                                   673 
674                                                   674 
675 /* Called only as a tasklet (software IRQ) */     675 /* Called only as a tasklet (software IRQ) */
676 static int                                        676 static int
677 hostap_rx_frame_decrypt_msdu(local_info_t *loc    677 hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
678                              int keyidx, struc    678                              int keyidx, struct ieee80211_crypt_data *crypt)
679 {                                                 679 {
680         struct ieee80211_hdr_4addr *hdr;          680         struct ieee80211_hdr_4addr *hdr;
681         int res, hdrlen;                          681         int res, hdrlen;
682         DECLARE_MAC_BUF(mac);                     682         DECLARE_MAC_BUF(mac);
683                                                   683 
684         if (crypt == NULL || crypt->ops->decry    684         if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
685                 return 0;                         685                 return 0;
686                                                   686 
687         hdr = (struct ieee80211_hdr_4addr *) s    687         hdr = (struct ieee80211_hdr_4addr *) skb->data;
688         hdrlen = hostap_80211_get_hdrlen(le16_    688         hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
689                                                   689 
690         atomic_inc(&crypt->refcnt);               690         atomic_inc(&crypt->refcnt);
691         res = crypt->ops->decrypt_msdu(skb, ke    691         res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
692         atomic_dec(&crypt->refcnt);               692         atomic_dec(&crypt->refcnt);
693         if (res < 0) {                            693         if (res < 0) {
694                 printk(KERN_DEBUG "%s: MSDU de    694                 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
695                        " (SA=%s keyidx=%d)\n",    695                        " (SA=%s keyidx=%d)\n",
696                        local->dev->name, print    696                        local->dev->name, print_mac(mac, hdr->addr2), keyidx);
697                 return -1;                        697                 return -1;
698         }                                         698         }
699                                                   699 
700         return 0;                                 700         return 0;
701 }                                                 701 }
702                                                   702 
703                                                   703 
704 /* All received frames are sent to this functi    704 /* All received frames are sent to this function. @skb contains the frame in
705  * IEEE 802.11 format, i.e., in the format it     705  * IEEE 802.11 format, i.e., in the format it was sent over air.
706  * This function is called only as a tasklet (    706  * This function is called only as a tasklet (software IRQ). */
707 void hostap_80211_rx(struct net_device *dev, s    707 void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
708                      struct hostap_80211_rx_st    708                      struct hostap_80211_rx_status *rx_stats)
709 {                                                 709 {
710         struct hostap_interface *iface;           710         struct hostap_interface *iface;
711         local_info_t *local;                      711         local_info_t *local;
712         struct ieee80211_hdr_4addr *hdr;          712         struct ieee80211_hdr_4addr *hdr;
713         size_t hdrlen;                            713         size_t hdrlen;
714         u16 fc, type, stype, sc;                  714         u16 fc, type, stype, sc;
715         struct net_device *wds = NULL;            715         struct net_device *wds = NULL;
716         struct net_device_stats *stats;           716         struct net_device_stats *stats;
717         unsigned int frag;                        717         unsigned int frag;
718         u8 *payload;                              718         u8 *payload;
719         struct sk_buff *skb2 = NULL;              719         struct sk_buff *skb2 = NULL;
720         u16 ethertype;                            720         u16 ethertype;
721         int frame_authorized = 0;                 721         int frame_authorized = 0;
722         int from_assoc_ap = 0;                    722         int from_assoc_ap = 0;
723         u8 dst[ETH_ALEN];                         723         u8 dst[ETH_ALEN];
724         u8 src[ETH_ALEN];                         724         u8 src[ETH_ALEN];
725         struct ieee80211_crypt_data *crypt = N    725         struct ieee80211_crypt_data *crypt = NULL;
726         void *sta = NULL;                         726         void *sta = NULL;
727         int keyidx = 0;                           727         int keyidx = 0;
728                                                   728 
729         iface = netdev_priv(dev);                 729         iface = netdev_priv(dev);
730         local = iface->local;                     730         local = iface->local;
731         iface->stats.rx_packets++;                731         iface->stats.rx_packets++;
732         iface->stats.rx_bytes += skb->len;        732         iface->stats.rx_bytes += skb->len;
733                                                   733 
734         /* dev is the master radio device; cha    734         /* dev is the master radio device; change this to be the default
735          * virtual interface (this may be chan    735          * virtual interface (this may be changed to WDS device below) */
736         dev = local->ddev;                        736         dev = local->ddev;
737         iface = netdev_priv(dev);                 737         iface = netdev_priv(dev);
738                                                   738 
739         hdr = (struct ieee80211_hdr_4addr *) s    739         hdr = (struct ieee80211_hdr_4addr *) skb->data;
740         stats = hostap_get_stats(dev);            740         stats = hostap_get_stats(dev);
741                                                   741 
742         if (skb->len < 10)                        742         if (skb->len < 10)
743                 goto rx_dropped;                  743                 goto rx_dropped;
744                                                   744 
745         fc = le16_to_cpu(hdr->frame_ctl);         745         fc = le16_to_cpu(hdr->frame_ctl);
746         type = WLAN_FC_GET_TYPE(fc);              746         type = WLAN_FC_GET_TYPE(fc);
747         stype = WLAN_FC_GET_STYPE(fc);            747         stype = WLAN_FC_GET_STYPE(fc);
748         sc = le16_to_cpu(hdr->seq_ctl);           748         sc = le16_to_cpu(hdr->seq_ctl);
749         frag = WLAN_GET_SEQ_FRAG(sc);             749         frag = WLAN_GET_SEQ_FRAG(sc);
750         hdrlen = hostap_80211_get_hdrlen(fc);     750         hdrlen = hostap_80211_get_hdrlen(fc);
751                                                   751 
752         /* Put this code here so that we avoid    752         /* Put this code here so that we avoid duplicating it in all
753          * Rx paths. - Jean II */                 753          * Rx paths. - Jean II */
754 #ifdef IW_WIRELESS_SPY          /* defined in     754 #ifdef IW_WIRELESS_SPY          /* defined in iw_handler.h */
755         /* If spy monitoring on */                755         /* If spy monitoring on */
756         if (iface->spy_data.spy_number > 0) {     756         if (iface->spy_data.spy_number > 0) {
757                 struct iw_quality wstats;         757                 struct iw_quality wstats;
758                 wstats.level = rx_stats->signa    758                 wstats.level = rx_stats->signal;
759                 wstats.noise = rx_stats->noise    759                 wstats.noise = rx_stats->noise;
760                 wstats.updated = IW_QUAL_LEVEL    760                 wstats.updated = IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED
761                         | IW_QUAL_QUAL_INVALID    761                         | IW_QUAL_QUAL_INVALID | IW_QUAL_DBM;
762                 /* Update spy records */          762                 /* Update spy records */
763                 wireless_spy_update(dev, hdr->    763                 wireless_spy_update(dev, hdr->addr2, &wstats);
764         }                                         764         }
765 #endif /* IW_WIRELESS_SPY */                      765 #endif /* IW_WIRELESS_SPY */
766         hostap_update_rx_stats(local->ap, hdr,    766         hostap_update_rx_stats(local->ap, hdr, rx_stats);
767                                                   767 
768         if (local->iw_mode == IW_MODE_MONITOR)    768         if (local->iw_mode == IW_MODE_MONITOR) {
769                 monitor_rx(dev, skb, rx_stats)    769                 monitor_rx(dev, skb, rx_stats);
770                 return;                           770                 return;
771         }                                         771         }
772                                                   772 
773         if (local->host_decrypt) {                773         if (local->host_decrypt) {
774                 int idx = 0;                      774                 int idx = 0;
775                 if (skb->len >= hdrlen + 3)       775                 if (skb->len >= hdrlen + 3)
776                         idx = skb->data[hdrlen    776                         idx = skb->data[hdrlen + 3] >> 6;
777                 crypt = local->crypt[idx];        777                 crypt = local->crypt[idx];
778                 sta = NULL;                       778                 sta = NULL;
779                                                   779 
780                 /* Use station specific key to    780                 /* Use station specific key to override default keys if the
781                  * receiver address is a unica    781                  * receiver address is a unicast address ("individual RA"). If
782                  * bcrx_sta_key parameter is s    782                  * bcrx_sta_key parameter is set, station specific key is used
783                  * even with broad/multicast t    783                  * even with broad/multicast targets (this is against IEEE
784                  * 802.11, but makes it easier    784                  * 802.11, but makes it easier to use different keys with
785                  * stations that do not suppor    785                  * stations that do not support WEP key mapping). */
786                                                   786 
787                 if (!(hdr->addr1[0] & 0x01) ||    787                 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
788                         (void) hostap_handle_s    788                         (void) hostap_handle_sta_crypto(local, hdr, &crypt,
789                                                   789                                                         &sta);
790                                                   790 
791                 /* allow NULL decrypt to indic    791                 /* allow NULL decrypt to indicate an station specific override
792                  * for default encryption */      792                  * for default encryption */
793                 if (crypt && (crypt->ops == NU    793                 if (crypt && (crypt->ops == NULL ||
794                               crypt->ops->decr    794                               crypt->ops->decrypt_mpdu == NULL))
795                         crypt = NULL;             795                         crypt = NULL;
796                                                   796 
797                 if (!crypt && (fc & IEEE80211_    797                 if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
798 #if 0                                             798 #if 0
799                         /* This seems to be tr    799                         /* This seems to be triggered by some (multicast?)
800                          * frames from other t    800                          * frames from other than current BSS, so just drop the
801                          * frames silently ins    801                          * frames silently instead of filling system log with
802                          * these reports. */      802                          * these reports. */
803                         printk(KERN_DEBUG "%s:    803                         printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
804                                " (SA=" MAC_FMT    804                                " (SA=" MAC_FMT ")\n",
805                                local->dev->nam    805                                local->dev->name,
806                                hdr->addr2[0],     806                                hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
807                                hdr->addr2[3],     807                                hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
808 #endif                                            808 #endif
809                         local->comm_tallies.rx    809                         local->comm_tallies.rx_discards_wep_undecryptable++;
810                         goto rx_dropped;          810                         goto rx_dropped;
811                 }                                 811                 }
812         }                                         812         }
813                                                   813 
814         if (type != IEEE80211_FTYPE_DATA) {       814         if (type != IEEE80211_FTYPE_DATA) {
815                 if (type == IEEE80211_FTYPE_MG    815                 if (type == IEEE80211_FTYPE_MGMT &&
816                     stype == IEEE80211_STYPE_A    816                     stype == IEEE80211_STYPE_AUTH &&
817                     fc & IEEE80211_FCTL_PROTEC    817                     fc & IEEE80211_FCTL_PROTECTED && local->host_decrypt &&
818                     (keyidx = hostap_rx_frame_    818                     (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
819                 {                                 819                 {
820                         printk(KERN_DEBUG "%s:    820                         printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
821                                "from " MAC_FMT    821                                "from " MAC_FMT "\n", dev->name,
822                                hdr->addr2[0],     822                                hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
823                                hdr->addr2[3],     823                                hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
824                         /* TODO: could inform     824                         /* TODO: could inform hostapd about this so that it
825                          * could send auth fai    825                          * could send auth failure report */
826                         goto rx_dropped;          826                         goto rx_dropped;
827                 }                                 827                 }
828                                                   828 
829                 if (hostap_rx_frame_mgmt(local    829                 if (hostap_rx_frame_mgmt(local, skb, rx_stats, type, stype))
830                         goto rx_dropped;          830                         goto rx_dropped;
831                 else                              831                 else
832                         goto rx_exit;             832                         goto rx_exit;
833         }                                         833         }
834                                                   834 
835         /* Data frame - extract src/dst addres    835         /* Data frame - extract src/dst addresses */
836         if (skb->len < IEEE80211_DATA_HDR3_LEN    836         if (skb->len < IEEE80211_DATA_HDR3_LEN)
837                 goto rx_dropped;                  837                 goto rx_dropped;
838                                                   838 
839         switch (fc & (IEEE80211_FCTL_FROMDS |     839         switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
840         case IEEE80211_FCTL_FROMDS:               840         case IEEE80211_FCTL_FROMDS:
841                 memcpy(dst, hdr->addr1, ETH_AL    841                 memcpy(dst, hdr->addr1, ETH_ALEN);
842                 memcpy(src, hdr->addr3, ETH_AL    842                 memcpy(src, hdr->addr3, ETH_ALEN);
843                 break;                            843                 break;
844         case IEEE80211_FCTL_TODS:                 844         case IEEE80211_FCTL_TODS:
845                 memcpy(dst, hdr->addr3, ETH_AL    845                 memcpy(dst, hdr->addr3, ETH_ALEN);
846                 memcpy(src, hdr->addr2, ETH_AL    846                 memcpy(src, hdr->addr2, ETH_ALEN);
847                 break;                            847                 break;
848         case IEEE80211_FCTL_FROMDS | IEEE80211    848         case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
849                 if (skb->len < IEEE80211_DATA_    849                 if (skb->len < IEEE80211_DATA_HDR4_LEN)
850                         goto rx_dropped;          850                         goto rx_dropped;
851                 memcpy(dst, hdr->addr3, ETH_AL    851                 memcpy(dst, hdr->addr3, ETH_ALEN);
852                 memcpy(src, hdr->addr4, ETH_AL    852                 memcpy(src, hdr->addr4, ETH_ALEN);
853                 break;                            853                 break;
854         case 0:                                   854         case 0:
855                 memcpy(dst, hdr->addr1, ETH_AL    855                 memcpy(dst, hdr->addr1, ETH_ALEN);
856                 memcpy(src, hdr->addr2, ETH_AL    856                 memcpy(src, hdr->addr2, ETH_ALEN);
857                 break;                            857                 break;
858         }                                         858         }
859                                                   859 
860         if (hostap_rx_frame_wds(local, hdr, fc    860         if (hostap_rx_frame_wds(local, hdr, fc, &wds))
861                 goto rx_dropped;                  861                 goto rx_dropped;
862         if (wds) {                                862         if (wds) {
863                 skb->dev = dev = wds;             863                 skb->dev = dev = wds;
864                 stats = hostap_get_stats(dev);    864                 stats = hostap_get_stats(dev);
865         }                                         865         }
866                                                   866 
867         if (local->iw_mode == IW_MODE_MASTER &    867         if (local->iw_mode == IW_MODE_MASTER && !wds &&
868             (fc & (IEEE80211_FCTL_TODS | IEEE8    868             (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
869             IEEE80211_FCTL_FROMDS &&              869             IEEE80211_FCTL_FROMDS &&
870             local->stadev &&                      870             local->stadev &&
871             memcmp(hdr->addr2, local->assoc_ap    871             memcmp(hdr->addr2, local->assoc_ap_addr, ETH_ALEN) == 0) {
872                 /* Frame from BSSID of the AP     872                 /* Frame from BSSID of the AP for which we are a client */
873                 skb->dev = dev = local->stadev    873                 skb->dev = dev = local->stadev;
874                 stats = hostap_get_stats(dev);    874                 stats = hostap_get_stats(dev);
875                 from_assoc_ap = 1;                875                 from_assoc_ap = 1;
876         }                                         876         }
877                                                   877 
878         dev->last_rx = jiffies;                   878         dev->last_rx = jiffies;
879                                                   879 
880         if ((local->iw_mode == IW_MODE_MASTER     880         if ((local->iw_mode == IW_MODE_MASTER ||
881              local->iw_mode == IW_MODE_REPEAT)    881              local->iw_mode == IW_MODE_REPEAT) &&
882             !from_assoc_ap) {                     882             !from_assoc_ap) {
883                 switch (hostap_handle_sta_rx(l    883                 switch (hostap_handle_sta_rx(local, dev, skb, rx_stats,
884                                              w    884                                              wds != NULL)) {
885                 case AP_RX_CONTINUE_NOT_AUTHOR    885                 case AP_RX_CONTINUE_NOT_AUTHORIZED:
886                         frame_authorized = 0;     886                         frame_authorized = 0;
887                         break;                    887                         break;
888                 case AP_RX_CONTINUE:              888                 case AP_RX_CONTINUE:
889                         frame_authorized = 1;     889                         frame_authorized = 1;
890                         break;                    890                         break;
891                 case AP_RX_DROP:                  891                 case AP_RX_DROP:
892                         goto rx_dropped;          892                         goto rx_dropped;
893                 case AP_RX_EXIT:                  893                 case AP_RX_EXIT:
894                         goto rx_exit;             894                         goto rx_exit;
895                 }                                 895                 }
896         }                                         896         }
897                                                   897 
898         /* Nullfunc frames may have PS-bit set    898         /* Nullfunc frames may have PS-bit set, so they must be passed to
899          * hostap_handle_sta_rx() before being    899          * hostap_handle_sta_rx() before being dropped here. */
900         if (stype != IEEE80211_STYPE_DATA &&      900         if (stype != IEEE80211_STYPE_DATA &&
901             stype != IEEE80211_STYPE_DATA_CFAC    901             stype != IEEE80211_STYPE_DATA_CFACK &&
902             stype != IEEE80211_STYPE_DATA_CFPO    902             stype != IEEE80211_STYPE_DATA_CFPOLL &&
903             stype != IEEE80211_STYPE_DATA_CFAC    903             stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
904                 if (stype != IEEE80211_STYPE_N    904                 if (stype != IEEE80211_STYPE_NULLFUNC)
905                         printk(KERN_DEBUG "%s:    905                         printk(KERN_DEBUG "%s: RX: dropped data frame "
906                                "with no data (    906                                "with no data (type=0x%02x, subtype=0x%02x)\n",
907                                dev->name, type    907                                dev->name, type >> 2, stype >> 4);
908                 goto rx_dropped;                  908                 goto rx_dropped;
909         }                                         909         }
910                                                   910 
911         /* skb: hdr + (possibly fragmented, po    911         /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
912                                                   912 
913         if (local->host_decrypt && (fc & IEEE8    913         if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
914             (keyidx = hostap_rx_frame_decrypt(    914             (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
915                 goto rx_dropped;                  915                 goto rx_dropped;
916         hdr = (struct ieee80211_hdr_4addr *) s    916         hdr = (struct ieee80211_hdr_4addr *) skb->data;
917                                                   917 
918         /* skb: hdr + (possibly fragmented) pl    918         /* skb: hdr + (possibly fragmented) plaintext payload */
919                                                   919 
920         if (local->host_decrypt && (fc & IEEE8    920         if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
921             (frag != 0 || (fc & IEEE80211_FCTL    921             (frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
922                 int flen;                         922                 int flen;
923                 struct sk_buff *frag_skb =        923                 struct sk_buff *frag_skb =
924                         prism2_frag_cache_get(    924                         prism2_frag_cache_get(local, hdr);
925                 if (!frag_skb) {                  925                 if (!frag_skb) {
926                         printk(KERN_DEBUG "%s:    926                         printk(KERN_DEBUG "%s: Rx cannot get skb from "
927                                "fragment cache    927                                "fragment cache (morefrag=%d seq=%u frag=%u)\n",
928                                dev->name, (fc     928                                dev->name, (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
929                                WLAN_GET_SEQ_SE    929                                WLAN_GET_SEQ_SEQ(sc) >> 4, frag);
930                         goto rx_dropped;          930                         goto rx_dropped;
931                 }                                 931                 }
932                                                   932 
933                 flen = skb->len;                  933                 flen = skb->len;
934                 if (frag != 0)                    934                 if (frag != 0)
935                         flen -= hdrlen;           935                         flen -= hdrlen;
936                                                   936 
937                 if (frag_skb->tail + flen > fr    937                 if (frag_skb->tail + flen > frag_skb->end) {
938                         printk(KERN_WARNING "%    938                         printk(KERN_WARNING "%s: host decrypted and "
939                                "reassembled fr    939                                "reassembled frame did not fit skb\n",
940                                dev->name);        940                                dev->name);
941                         prism2_frag_cache_inva    941                         prism2_frag_cache_invalidate(local, hdr);
942                         goto rx_dropped;          942                         goto rx_dropped;
943                 }                                 943                 }
944                                                   944 
945                 if (frag == 0) {                  945                 if (frag == 0) {
946                         /* copy first fragment    946                         /* copy first fragment (including full headers) into
947                          * beginning of the fr    947                          * beginning of the fragment cache skb */
948                         skb_copy_from_linear_d    948                         skb_copy_from_linear_data(skb, skb_put(frag_skb, flen),
949                                                   949                                                   flen);
950                 } else {                          950                 } else {
951                         /* append frame payloa    951                         /* append frame payload to the end of the fragment
952                          * cache skb */           952                          * cache skb */
953                         skb_copy_from_linear_d    953                         skb_copy_from_linear_data_offset(skb, hdrlen,
954                                                   954                                                          skb_put(frag_skb,
955                                                   955                                                                  flen), flen);
956                 }                                 956                 }
957                 dev_kfree_skb(skb);               957                 dev_kfree_skb(skb);
958                 skb = NULL;                       958                 skb = NULL;
959                                                   959 
960                 if (fc & IEEE80211_FCTL_MOREFR    960                 if (fc & IEEE80211_FCTL_MOREFRAGS) {
961                         /* more fragments expe    961                         /* more fragments expected - leave the skb in fragment
962                          * cache for now; it w    962                          * cache for now; it will be delivered to upper layers
963                          * after all fragments    963                          * after all fragments have been received */
964                         goto rx_exit;             964                         goto rx_exit;
965                 }                                 965                 }
966                                                   966 
967                 /* this was the last fragment     967                 /* this was the last fragment and the frame will be
968                  * delivered, so remove skb fr    968                  * delivered, so remove skb from fragment cache */
969                 skb = frag_skb;                   969                 skb = frag_skb;
970                 hdr = (struct ieee80211_hdr_4a    970                 hdr = (struct ieee80211_hdr_4addr *) skb->data;
971                 prism2_frag_cache_invalidate(l    971                 prism2_frag_cache_invalidate(local, hdr);
972         }                                         972         }
973                                                   973 
974         /* skb: hdr + (possible reassembled) f    974         /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
975          * encrypted/authenticated */             975          * encrypted/authenticated */
976                                                   976 
977         if (local->host_decrypt && (fc & IEEE8    977         if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
978             hostap_rx_frame_decrypt_msdu(local    978             hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
979                 goto rx_dropped;                  979                 goto rx_dropped;
980                                                   980 
981         hdr = (struct ieee80211_hdr_4addr *) s    981         hdr = (struct ieee80211_hdr_4addr *) skb->data;
982         if (crypt && !(fc & IEEE80211_FCTL_PRO    982         if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) {
983                 if (local->ieee_802_1x &&         983                 if (local->ieee_802_1x &&
984                     hostap_is_eapol_frame(loca    984                     hostap_is_eapol_frame(local, skb)) {
985                         /* pass unencrypted EA    985                         /* pass unencrypted EAPOL frames even if encryption is
986                          * configured */          986                          * configured */
987                         PDEBUG(DEBUG_EXTRA2, "    987                         PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X - passing "
988                                "unencrypted EA    988                                "unencrypted EAPOL frame\n", local->dev->name);
989                 } else {                          989                 } else {
990                         printk(KERN_DEBUG "%s:    990                         printk(KERN_DEBUG "%s: encryption configured, but RX "
991                                "frame not encr    991                                "frame not encrypted (SA=" MAC_FMT ")\n",
992                                local->dev->nam    992                                local->dev->name,
993                                hdr->addr2[0],     993                                hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
994                                hdr->addr2[3],     994                                hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
995                         goto rx_dropped;          995                         goto rx_dropped;
996                 }                                 996                 }
997         }                                         997         }
998                                                   998 
999         if (local->drop_unencrypted && !(fc &     999         if (local->drop_unencrypted && !(fc & IEEE80211_FCTL_PROTECTED) &&
1000             !hostap_is_eapol_frame(local, skb    1000             !hostap_is_eapol_frame(local, skb)) {
1001                 if (net_ratelimit()) {           1001                 if (net_ratelimit()) {
1002                         printk(KERN_DEBUG "%s    1002                         printk(KERN_DEBUG "%s: dropped unencrypted RX data "
1003                                "frame from "     1003                                "frame from " MAC_FMT " (drop_unencrypted=1)\n",
1004                                dev->name,        1004                                dev->name,
1005                                hdr->addr2[0],    1005                                hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
1006                                hdr->addr2[3],    1006                                hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
1007                 }                                1007                 }
1008                 goto rx_dropped;                 1008                 goto rx_dropped;
1009         }                                        1009         }
1010                                                  1010 
1011         /* skb: hdr + (possible reassembled)     1011         /* skb: hdr + (possible reassembled) full plaintext payload */
1012                                                  1012 
1013         payload = skb->data + hdrlen;            1013         payload = skb->data + hdrlen;
1014         ethertype = (payload[6] << 8) | paylo    1014         ethertype = (payload[6] << 8) | payload[7];
1015                                                  1015 
1016         /* If IEEE 802.1X is used, check whet    1016         /* If IEEE 802.1X is used, check whether the port is authorized to send
1017          * the received frame. */                1017          * the received frame. */
1018         if (local->ieee_802_1x && local->iw_m    1018         if (local->ieee_802_1x && local->iw_mode == IW_MODE_MASTER) {
1019                 if (ethertype == ETH_P_PAE) {    1019                 if (ethertype == ETH_P_PAE) {
1020                         PDEBUG(DEBUG_EXTRA2,     1020                         PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X frame\n",
1021                                dev->name);       1021                                dev->name);
1022                         if (local->hostapd &&    1022                         if (local->hostapd && local->apdev) {
1023                                 /* Send IEEE     1023                                 /* Send IEEE 802.1X frames to the user
1024                                  * space daem    1024                                  * space daemon for processing */
1025                                 prism2_rx_802    1025                                 prism2_rx_80211(local->apdev, skb, rx_stats,
1026                                                  1026                                                 PRISM2_RX_MGMT);
1027                                 local->apdevs    1027                                 local->apdevstats.rx_packets++;
1028                                 local->apdevs    1028                                 local->apdevstats.rx_bytes += skb->len;
1029                                 goto rx_exit;    1029                                 goto rx_exit;
1030                         }                        1030                         }
1031                 } else if (!frame_authorized)    1031                 } else if (!frame_authorized) {
1032                         printk(KERN_DEBUG "%s    1032                         printk(KERN_DEBUG "%s: dropped frame from "
1033                                "unauthorized     1033                                "unauthorized port (IEEE 802.1X): "
1034                                "ethertype=0x%    1034                                "ethertype=0x%04x\n",
1035                                dev->name, eth    1035                                dev->name, ethertype);
1036                         goto rx_dropped;         1036                         goto rx_dropped;
1037                 }                                1037                 }
1038         }                                        1038         }
1039                                                  1039 
1040         /* convert hdr + possible LLC headers    1040         /* convert hdr + possible LLC headers into Ethernet header */
1041         if (skb->len - hdrlen >= 8 &&            1041         if (skb->len - hdrlen >= 8 &&
1042             ((memcmp(payload, rfc1042_header,    1042             ((memcmp(payload, rfc1042_header, 6) == 0 &&
1043               ethertype != ETH_P_AARP && ethe    1043               ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1044              memcmp(payload, bridge_tunnel_he    1044              memcmp(payload, bridge_tunnel_header, 6) == 0)) {
1045                 /* remove RFC1042 or Bridge-T    1045                 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1046                  * replace EtherType */          1046                  * replace EtherType */
1047                 skb_pull(skb, hdrlen + 6);       1047                 skb_pull(skb, hdrlen + 6);
1048                 memcpy(skb_push(skb, ETH_ALEN    1048                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1049                 memcpy(skb_push(skb, ETH_ALEN    1049                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1050         } else {                                 1050         } else {
1051                 __be16 len;                      1051                 __be16 len;
1052                 /* Leave Ethernet header part    1052                 /* Leave Ethernet header part of hdr and full payload */
1053                 skb_pull(skb, hdrlen);           1053                 skb_pull(skb, hdrlen);
1054                 len = htons(skb->len);           1054                 len = htons(skb->len);
1055                 memcpy(skb_push(skb, 2), &len    1055                 memcpy(skb_push(skb, 2), &len, 2);
1056                 memcpy(skb_push(skb, ETH_ALEN    1056                 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1057                 memcpy(skb_push(skb, ETH_ALEN    1057                 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1058         }                                        1058         }
1059                                                  1059 
1060         if (wds && ((fc & (IEEE80211_FCTL_TOD    1060         if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
1061                     IEEE80211_FCTL_TODS) &&      1061                     IEEE80211_FCTL_TODS) &&
1062             skb->len >= ETH_HLEN + ETH_ALEN)     1062             skb->len >= ETH_HLEN + ETH_ALEN) {
1063                 /* Non-standard frame: get ad    1063                 /* Non-standard frame: get addr4 from its bogus location after
1064                  * the payload */                1064                  * the payload */
1065                 skb_copy_from_linear_data_off    1065                 skb_copy_from_linear_data_offset(skb, skb->len - ETH_ALEN,
1066                                                  1066                                                  skb->data + ETH_ALEN,
1067                                                  1067                                                  ETH_ALEN);
1068                 skb_trim(skb, skb->len - ETH_    1068                 skb_trim(skb, skb->len - ETH_ALEN);
1069         }                                        1069         }
1070                                                  1070 
1071         stats->rx_packets++;                     1071         stats->rx_packets++;
1072         stats->rx_bytes += skb->len;             1072         stats->rx_bytes += skb->len;
1073                                                  1073 
1074         if (local->iw_mode == IW_MODE_MASTER     1074         if (local->iw_mode == IW_MODE_MASTER && !wds &&
1075             local->ap->bridge_packets) {         1075             local->ap->bridge_packets) {
1076                 if (dst[0] & 0x01) {             1076                 if (dst[0] & 0x01) {
1077                         /* copy multicast fra    1077                         /* copy multicast frame both to the higher layers and
1078                          * to the wireless me    1078                          * to the wireless media */
1079                         local->ap->bridged_mu    1079                         local->ap->bridged_multicast++;
1080                         skb2 = skb_clone(skb,    1080                         skb2 = skb_clone(skb, GFP_ATOMIC);
1081                         if (skb2 == NULL)        1081                         if (skb2 == NULL)
1082                                 printk(KERN_D    1082                                 printk(KERN_DEBUG "%s: skb_clone failed for "
1083                                        "multi    1083                                        "multicast frame\n", dev->name);
1084                 } else if (hostap_is_sta_auth    1084                 } else if (hostap_is_sta_authorized(local->ap, dst)) {
1085                         /* send frame directl    1085                         /* send frame directly to the associated STA using
1086                          * wireless media and    1086                          * wireless media and not passing to higher layers */
1087                         local->ap->bridged_un    1087                         local->ap->bridged_unicast++;
1088                         skb2 = skb;              1088                         skb2 = skb;
1089                         skb = NULL;              1089                         skb = NULL;
1090                 }                                1090                 }
1091         }                                        1091         }
1092                                                  1092 
1093         if (skb2 != NULL) {                      1093         if (skb2 != NULL) {
1094                 /* send to wireless media */     1094                 /* send to wireless media */
1095                 skb2->dev = dev;                 1095                 skb2->dev = dev;
1096                 skb2->protocol = __constant_h    1096                 skb2->protocol = __constant_htons(ETH_P_802_3);
1097                 skb_reset_mac_header(skb2);      1097                 skb_reset_mac_header(skb2);
1098                 skb_reset_network_header(skb2    1098                 skb_reset_network_header(skb2);
1099                 /* skb2->network_header += ET    1099                 /* skb2->network_header += ETH_HLEN; */
1100                 dev_queue_xmit(skb2);            1100                 dev_queue_xmit(skb2);
1101         }                                        1101         }
1102                                                  1102 
1103         if (skb) {                               1103         if (skb) {
1104                 skb->protocol = eth_type_tran    1104                 skb->protocol = eth_type_trans(skb, dev);
1105                 memset(skb->cb, 0, sizeof(skb    1105                 memset(skb->cb, 0, sizeof(skb->cb));
1106                 netif_rx(skb);                   1106                 netif_rx(skb);
1107         }                                        1107         }
1108                                                  1108 
1109  rx_exit:                                        1109  rx_exit:
1110         if (sta)                                 1110         if (sta)
1111                 hostap_handle_sta_release(sta    1111                 hostap_handle_sta_release(sta);
1112         return;                                  1112         return;
1113                                                  1113 
1114  rx_dropped:                                     1114  rx_dropped:
1115         dev_kfree_skb(skb);                      1115         dev_kfree_skb(skb);
1116                                                  1116 
1117         stats->rx_dropped++;                     1117         stats->rx_dropped++;
1118         goto rx_exit;                            1118         goto rx_exit;
1119 }                                                1119 }
1120                                                  1120 
1121                                                  1121 
1122 EXPORT_SYMBOL(hostap_80211_rx);                  1122 EXPORT_SYMBOL(hostap_80211_rx);
1123                                                  1123 
  This page was automatically generated by the LXR engine.