ieee80211_rx.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. * Original code based Host AP (software wireless LAN access point) driver
  3. * for Intersil Prism2/2.5/3 - hostap.o module, common routines
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <jkmaline@cc.hut.fi>
  7. * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  8. * Copyright (c) 2004, Intel Corporation
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation. See README and COPYING for
  13. * more details.
  14. */
  15. #include <linux/compiler.h>
  16. #include <linux/config.h>
  17. #include <linux/errno.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/in6.h>
  20. #include <linux/in.h>
  21. #include <linux/ip.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/slab.h>
  28. #include <linux/tcp.h>
  29. #include <linux/types.h>
  30. #include <linux/version.h>
  31. #include <linux/wireless.h>
  32. #include <linux/etherdevice.h>
  33. #include <asm/uaccess.h>
  34. #include <linux/ctype.h>
  35. #include <net/ieee80211.h>
  36. static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
  37. struct sk_buff *skb,
  38. struct ieee80211_rx_stats *rx_stats)
  39. {
  40. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  41. u16 fc = le16_to_cpu(hdr->frame_ctl);
  42. skb->dev = ieee->dev;
  43. skb->mac.raw = skb->data;
  44. skb_pull(skb, ieee80211_get_hdrlen(fc));
  45. skb->pkt_type = PACKET_OTHERHOST;
  46. skb->protocol = __constant_htons(ETH_P_80211_RAW);
  47. memset(skb->cb, 0, sizeof(skb->cb));
  48. netif_rx(skb);
  49. }
  50. /* Called only as a tasklet (software IRQ) */
  51. static struct ieee80211_frag_entry *
  52. ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
  53. unsigned int frag, u8 *src, u8 *dst)
  54. {
  55. struct ieee80211_frag_entry *entry;
  56. int i;
  57. for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
  58. entry = &ieee->frag_cache[i];
  59. if (entry->skb != NULL &&
  60. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  61. IEEE80211_DEBUG_FRAG(
  62. "expiring fragment cache entry "
  63. "seq=%u last_frag=%u\n",
  64. entry->seq, entry->last_frag);
  65. dev_kfree_skb_any(entry->skb);
  66. entry->skb = NULL;
  67. }
  68. if (entry->skb != NULL && entry->seq == seq &&
  69. (entry->last_frag + 1 == frag || frag == -1) &&
  70. memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
  71. memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
  72. return entry;
  73. }
  74. return NULL;
  75. }
  76. /* Called only as a tasklet (software IRQ) */
  77. static struct sk_buff *
  78. ieee80211_frag_cache_get(struct ieee80211_device *ieee,
  79. struct ieee80211_hdr *hdr)
  80. {
  81. struct sk_buff *skb = NULL;
  82. u16 sc;
  83. unsigned int frag, seq;
  84. struct ieee80211_frag_entry *entry;
  85. sc = le16_to_cpu(hdr->seq_ctl);
  86. frag = WLAN_GET_SEQ_FRAG(sc);
  87. seq = WLAN_GET_SEQ_SEQ(sc);
  88. if (frag == 0) {
  89. /* Reserve enough space to fit maximum frame length */
  90. skb = dev_alloc_skb(ieee->dev->mtu +
  91. sizeof(struct ieee80211_hdr) +
  92. 8 /* LLC */ +
  93. 2 /* alignment */ +
  94. 8 /* WEP */ + ETH_ALEN /* WDS */);
  95. if (skb == NULL)
  96. return NULL;
  97. entry = &ieee->frag_cache[ieee->frag_next_idx];
  98. ieee->frag_next_idx++;
  99. if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
  100. ieee->frag_next_idx = 0;
  101. if (entry->skb != NULL)
  102. dev_kfree_skb_any(entry->skb);
  103. entry->first_frag_time = jiffies;
  104. entry->seq = seq;
  105. entry->last_frag = frag;
  106. entry->skb = skb;
  107. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  108. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  109. } else {
  110. /* received a fragment of a frame for which the head fragment
  111. * should have already been received */
  112. entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
  113. hdr->addr1);
  114. if (entry != NULL) {
  115. entry->last_frag = frag;
  116. skb = entry->skb;
  117. }
  118. }
  119. return skb;
  120. }
  121. /* Called only as a tasklet (software IRQ) */
  122. static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
  123. struct ieee80211_hdr *hdr)
  124. {
  125. u16 sc;
  126. unsigned int seq;
  127. struct ieee80211_frag_entry *entry;
  128. sc = le16_to_cpu(hdr->seq_ctl);
  129. seq = WLAN_GET_SEQ_SEQ(sc);
  130. entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
  131. hdr->addr1);
  132. if (entry == NULL) {
  133. IEEE80211_DEBUG_FRAG(
  134. "could not invalidate fragment cache "
  135. "entry (seq=%u)\n", seq);
  136. return -1;
  137. }
  138. entry->skb = NULL;
  139. return 0;
  140. }
  141. #ifdef NOT_YET
  142. /* ieee80211_rx_frame_mgtmt
  143. *
  144. * Responsible for handling management control frames
  145. *
  146. * Called by ieee80211_rx */
  147. static inline int
  148. ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
  149. struct ieee80211_rx_stats *rx_stats, u16 type,
  150. u16 stype)
  151. {
  152. if (ieee->iw_mode == IW_MODE_MASTER) {
  153. printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
  154. ieee->dev->name);
  155. return 0;
  156. /*
  157. hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr *)
  158. skb->data);*/
  159. }
  160. if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
  161. if (stype == WLAN_FC_STYPE_BEACON &&
  162. ieee->iw_mode == IW_MODE_MASTER) {
  163. struct sk_buff *skb2;
  164. /* Process beacon frames also in kernel driver to
  165. * update STA(AP) table statistics */
  166. skb2 = skb_clone(skb, GFP_ATOMIC);
  167. if (skb2)
  168. hostap_rx(skb2->dev, skb2, rx_stats);
  169. }
  170. /* send management frames to the user space daemon for
  171. * processing */
  172. ieee->apdevstats.rx_packets++;
  173. ieee->apdevstats.rx_bytes += skb->len;
  174. prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  175. return 0;
  176. }
  177. if (ieee->iw_mode == IW_MODE_MASTER) {
  178. if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
  179. printk(KERN_DEBUG "%s: unknown management frame "
  180. "(type=0x%02x, stype=0x%02x) dropped\n",
  181. skb->dev->name, type, stype);
  182. return -1;
  183. }
  184. hostap_rx(skb->dev, skb, rx_stats);
  185. return 0;
  186. }
  187. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
  188. "received in non-Host AP mode\n", skb->dev->name);
  189. return -1;
  190. }
  191. #endif
  192. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  193. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  194. static unsigned char rfc1042_header[] =
  195. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  196. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  197. static unsigned char bridge_tunnel_header[] =
  198. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  199. /* No encapsulation header if EtherType < 0x600 (=length) */
  200. /* Called by ieee80211_rx_frame_decrypt */
  201. static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
  202. struct sk_buff *skb)
  203. {
  204. struct net_device *dev = ieee->dev;
  205. u16 fc, ethertype;
  206. struct ieee80211_hdr *hdr;
  207. u8 *pos;
  208. if (skb->len < 24)
  209. return 0;
  210. hdr = (struct ieee80211_hdr *) skb->data;
  211. fc = le16_to_cpu(hdr->frame_ctl);
  212. /* check that the frame is unicast frame to us */
  213. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  214. IEEE80211_FCTL_TODS &&
  215. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
  216. memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
  217. /* ToDS frame with own addr BSSID and DA */
  218. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  219. IEEE80211_FCTL_FROMDS &&
  220. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  221. /* FromDS frame with own addr as DA */
  222. } else
  223. return 0;
  224. if (skb->len < 24 + 8)
  225. return 0;
  226. /* check for port access entity Ethernet type */
  227. pos = skb->data + 24;
  228. ethertype = (pos[6] << 8) | pos[7];
  229. if (ethertype == ETH_P_PAE)
  230. return 1;
  231. return 0;
  232. }
  233. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  234. static inline int
  235. ieee80211_rx_frame_decrypt(struct ieee80211_device* ieee, struct sk_buff *skb,
  236. struct ieee80211_crypt_data *crypt)
  237. {
  238. struct ieee80211_hdr *hdr;
  239. int res, hdrlen;
  240. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  241. return 0;
  242. hdr = (struct ieee80211_hdr *) skb->data;
  243. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  244. #ifdef CONFIG_IEEE80211_CRYPT_TKIP
  245. if (ieee->tkip_countermeasures &&
  246. strcmp(crypt->ops->name, "TKIP") == 0) {
  247. if (net_ratelimit()) {
  248. printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
  249. "received packet from " MAC_FMT "\n",
  250. ieee->dev->name, MAC_ARG(hdr->addr2));
  251. }
  252. return -1;
  253. }
  254. #endif
  255. atomic_inc(&crypt->refcnt);
  256. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  257. atomic_dec(&crypt->refcnt);
  258. if (res < 0) {
  259. IEEE80211_DEBUG_DROP(
  260. "decryption failed (SA=" MAC_FMT
  261. ") res=%d\n", MAC_ARG(hdr->addr2), res);
  262. if (res == -2)
  263. IEEE80211_DEBUG_DROP("Decryption failed ICV "
  264. "mismatch (key %d)\n",
  265. skb->data[hdrlen + 3] >> 6);
  266. ieee->ieee_stats.rx_discards_undecryptable++;
  267. return -1;
  268. }
  269. return res;
  270. }
  271. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  272. static inline int
  273. ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device* ieee, struct sk_buff *skb,
  274. int keyidx, struct ieee80211_crypt_data *crypt)
  275. {
  276. struct ieee80211_hdr *hdr;
  277. int res, hdrlen;
  278. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  279. return 0;
  280. hdr = (struct ieee80211_hdr *) skb->data;
  281. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  282. atomic_inc(&crypt->refcnt);
  283. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  284. atomic_dec(&crypt->refcnt);
  285. if (res < 0) {
  286. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  287. " (SA=" MAC_FMT " keyidx=%d)\n",
  288. ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
  289. return -1;
  290. }
  291. return 0;
  292. }
  293. /* All received frames are sent to this function. @skb contains the frame in
  294. * IEEE 802.11 format, i.e., in the format it was sent over air.
  295. * This function is called only as a tasklet (software IRQ). */
  296. int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
  297. struct ieee80211_rx_stats *rx_stats)
  298. {
  299. struct net_device *dev = ieee->dev;
  300. struct ieee80211_hdr *hdr;
  301. size_t hdrlen;
  302. u16 fc, type, stype, sc;
  303. struct net_device_stats *stats;
  304. unsigned int frag;
  305. u8 *payload;
  306. u16 ethertype;
  307. #ifdef NOT_YET
  308. struct net_device *wds = NULL;
  309. struct sk_buff *skb2 = NULL;
  310. struct net_device *wds = NULL;
  311. int frame_authorized = 0;
  312. int from_assoc_ap = 0;
  313. void *sta = NULL;
  314. #endif
  315. u8 dst[ETH_ALEN];
  316. u8 src[ETH_ALEN];
  317. struct ieee80211_crypt_data *crypt = NULL;
  318. int keyidx = 0;
  319. hdr = (struct ieee80211_hdr *)skb->data;
  320. stats = &ieee->stats;
  321. if (skb->len < 10) {
  322. printk(KERN_INFO "%s: SKB length < 10\n",
  323. dev->name);
  324. goto rx_dropped;
  325. }
  326. fc = le16_to_cpu(hdr->frame_ctl);
  327. type = WLAN_FC_GET_TYPE(fc);
  328. stype = WLAN_FC_GET_STYPE(fc);
  329. sc = le16_to_cpu(hdr->seq_ctl);
  330. frag = WLAN_GET_SEQ_FRAG(sc);
  331. hdrlen = ieee80211_get_hdrlen(fc);
  332. #ifdef NOT_YET
  333. #if WIRELESS_EXT > 15
  334. /* Put this code here so that we avoid duplicating it in all
  335. * Rx paths. - Jean II */
  336. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  337. /* If spy monitoring on */
  338. if (iface->spy_data.spy_number > 0) {
  339. struct iw_quality wstats;
  340. wstats.level = rx_stats->signal;
  341. wstats.noise = rx_stats->noise;
  342. wstats.updated = 6; /* No qual value */
  343. /* Update spy records */
  344. wireless_spy_update(dev, hdr->addr2, &wstats);
  345. }
  346. #endif /* IW_WIRELESS_SPY */
  347. #endif /* WIRELESS_EXT > 15 */
  348. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  349. #endif
  350. #if WIRELESS_EXT > 15
  351. if (ieee->iw_mode == IW_MODE_MONITOR) {
  352. ieee80211_monitor_rx(ieee, skb, rx_stats);
  353. stats->rx_packets++;
  354. stats->rx_bytes += skb->len;
  355. return 1;
  356. }
  357. #endif
  358. if (ieee->host_decrypt) {
  359. int idx = 0;
  360. if (skb->len >= hdrlen + 3)
  361. idx = skb->data[hdrlen + 3] >> 6;
  362. crypt = ieee->crypt[idx];
  363. #ifdef NOT_YET
  364. sta = NULL;
  365. /* Use station specific key to override default keys if the
  366. * receiver address is a unicast address ("individual RA"). If
  367. * bcrx_sta_key parameter is set, station specific key is used
  368. * even with broad/multicast targets (this is against IEEE
  369. * 802.11, but makes it easier to use different keys with
  370. * stations that do not support WEP key mapping). */
  371. if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
  372. (void) hostap_handle_sta_crypto(local, hdr, &crypt,
  373. &sta);
  374. #endif
  375. /* allow NULL decrypt to indicate an station specific override
  376. * for default encryption */
  377. if (crypt && (crypt->ops == NULL ||
  378. crypt->ops->decrypt_mpdu == NULL))
  379. crypt = NULL;
  380. if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
  381. /* This seems to be triggered by some (multicast?)
  382. * frames from other than current BSS, so just drop the
  383. * frames silently instead of filling system log with
  384. * these reports. */
  385. IEEE80211_DEBUG_DROP("Decryption failed (not set)"
  386. " (SA=" MAC_FMT ")\n",
  387. MAC_ARG(hdr->addr2));
  388. ieee->ieee_stats.rx_discards_undecryptable++;
  389. goto rx_dropped;
  390. }
  391. }
  392. #ifdef NOT_YET
  393. if (type != WLAN_FC_TYPE_DATA) {
  394. if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
  395. fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
  396. (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  397. {
  398. printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
  399. "from " MAC_FMT "\n", dev->name,
  400. MAC_ARG(hdr->addr2));
  401. /* TODO: could inform hostapd about this so that it
  402. * could send auth failure report */
  403. goto rx_dropped;
  404. }
  405. if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
  406. goto rx_dropped;
  407. else
  408. goto rx_exit;
  409. }
  410. #endif
  411. /* Data frame - extract src/dst addresses */
  412. if (skb->len < IEEE80211_3ADDR_LEN)
  413. goto rx_dropped;
  414. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  415. case IEEE80211_FCTL_FROMDS:
  416. memcpy(dst, hdr->addr1, ETH_ALEN);
  417. memcpy(src, hdr->addr3, ETH_ALEN);
  418. break;
  419. case IEEE80211_FCTL_TODS:
  420. memcpy(dst, hdr->addr3, ETH_ALEN);
  421. memcpy(src, hdr->addr2, ETH_ALEN);
  422. break;
  423. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  424. if (skb->len < IEEE80211_4ADDR_LEN)
  425. goto rx_dropped;
  426. memcpy(dst, hdr->addr3, ETH_ALEN);
  427. memcpy(src, hdr->addr4, ETH_ALEN);
  428. break;
  429. case 0:
  430. memcpy(dst, hdr->addr1, ETH_ALEN);
  431. memcpy(src, hdr->addr2, ETH_ALEN);
  432. break;
  433. }
  434. #ifdef NOT_YET
  435. if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
  436. goto rx_dropped;
  437. if (wds) {
  438. skb->dev = dev = wds;
  439. stats = hostap_get_stats(dev);
  440. }
  441. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  442. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS &&
  443. ieee->stadev &&
  444. memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
  445. /* Frame from BSSID of the AP for which we are a client */
  446. skb->dev = dev = ieee->stadev;
  447. stats = hostap_get_stats(dev);
  448. from_assoc_ap = 1;
  449. }
  450. #endif
  451. dev->last_rx = jiffies;
  452. #ifdef NOT_YET
  453. if ((ieee->iw_mode == IW_MODE_MASTER ||
  454. ieee->iw_mode == IW_MODE_REPEAT) &&
  455. !from_assoc_ap) {
  456. switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
  457. wds != NULL)) {
  458. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  459. frame_authorized = 0;
  460. break;
  461. case AP_RX_CONTINUE:
  462. frame_authorized = 1;
  463. break;
  464. case AP_RX_DROP:
  465. goto rx_dropped;
  466. case AP_RX_EXIT:
  467. goto rx_exit;
  468. }
  469. }
  470. #endif
  471. /* Nullfunc frames may have PS-bit set, so they must be passed to
  472. * hostap_handle_sta_rx() before being dropped here. */
  473. if (stype != IEEE80211_STYPE_DATA &&
  474. stype != IEEE80211_STYPE_DATA_CFACK &&
  475. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  476. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  477. if (stype != IEEE80211_STYPE_NULLFUNC)
  478. IEEE80211_DEBUG_DROP(
  479. "RX: dropped data frame "
  480. "with no data (type=0x%02x, "
  481. "subtype=0x%02x, len=%d)\n",
  482. type, stype, skb->len);
  483. goto rx_dropped;
  484. }
  485. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  486. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  487. (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  488. goto rx_dropped;
  489. hdr = (struct ieee80211_hdr *) skb->data;
  490. /* skb: hdr + (possibly fragmented) plaintext payload */
  491. // PR: FIXME: hostap has additional conditions in the "if" below:
  492. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  493. if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
  494. int flen;
  495. struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
  496. IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  497. if (!frag_skb) {
  498. IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
  499. "Rx cannot get skb from fragment "
  500. "cache (morefrag=%d seq=%u frag=%u)\n",
  501. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  502. WLAN_GET_SEQ_SEQ(sc), frag);
  503. goto rx_dropped;
  504. }
  505. flen = skb->len;
  506. if (frag != 0)
  507. flen -= hdrlen;
  508. if (frag_skb->tail + flen > frag_skb->end) {
  509. printk(KERN_WARNING "%s: host decrypted and "
  510. "reassembled frame did not fit skb\n",
  511. dev->name);
  512. ieee80211_frag_cache_invalidate(ieee, hdr);
  513. goto rx_dropped;
  514. }
  515. if (frag == 0) {
  516. /* copy first fragment (including full headers) into
  517. * beginning of the fragment cache skb */
  518. memcpy(skb_put(frag_skb, flen), skb->data, flen);
  519. } else {
  520. /* append frame payload to the end of the fragment
  521. * cache skb */
  522. memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
  523. flen);
  524. }
  525. dev_kfree_skb_any(skb);
  526. skb = NULL;
  527. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  528. /* more fragments expected - leave the skb in fragment
  529. * cache for now; it will be delivered to upper layers
  530. * after all fragments have been received */
  531. goto rx_exit;
  532. }
  533. /* this was the last fragment and the frame will be
  534. * delivered, so remove skb from fragment cache */
  535. skb = frag_skb;
  536. hdr = (struct ieee80211_hdr *) skb->data;
  537. ieee80211_frag_cache_invalidate(ieee, hdr);
  538. }
  539. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  540. * encrypted/authenticated */
  541. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  542. ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  543. goto rx_dropped;
  544. hdr = (struct ieee80211_hdr *) skb->data;
  545. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  546. if (/*ieee->ieee802_1x &&*/
  547. ieee80211_is_eapol_frame(ieee, skb)) {
  548. /* pass unencrypted EAPOL frames even if encryption is
  549. * configured */
  550. } else {
  551. IEEE80211_DEBUG_DROP(
  552. "encryption configured, but RX "
  553. "frame not encrypted (SA=" MAC_FMT ")\n",
  554. MAC_ARG(hdr->addr2));
  555. goto rx_dropped;
  556. }
  557. }
  558. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  559. !ieee80211_is_eapol_frame(ieee, skb)) {
  560. IEEE80211_DEBUG_DROP(
  561. "dropped unencrypted RX data "
  562. "frame from " MAC_FMT
  563. " (drop_unencrypted=1)\n",
  564. MAC_ARG(hdr->addr2));
  565. goto rx_dropped;
  566. }
  567. /* skb: hdr + (possible reassembled) full plaintext payload */
  568. payload = skb->data + hdrlen;
  569. ethertype = (payload[6] << 8) | payload[7];
  570. #ifdef NOT_YET
  571. /* If IEEE 802.1X is used, check whether the port is authorized to send
  572. * the received frame. */
  573. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  574. if (ethertype == ETH_P_PAE) {
  575. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  576. dev->name);
  577. if (ieee->hostapd && ieee->apdev) {
  578. /* Send IEEE 802.1X frames to the user
  579. * space daemon for processing */
  580. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  581. PRISM2_RX_MGMT);
  582. ieee->apdevstats.rx_packets++;
  583. ieee->apdevstats.rx_bytes += skb->len;
  584. goto rx_exit;
  585. }
  586. } else if (!frame_authorized) {
  587. printk(KERN_DEBUG "%s: dropped frame from "
  588. "unauthorized port (IEEE 802.1X): "
  589. "ethertype=0x%04x\n",
  590. dev->name, ethertype);
  591. goto rx_dropped;
  592. }
  593. }
  594. #endif
  595. /* convert hdr + possible LLC headers into Ethernet header */
  596. if (skb->len - hdrlen >= 8 &&
  597. ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
  598. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  599. memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
  600. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  601. * replace EtherType */
  602. skb_pull(skb, hdrlen + SNAP_SIZE);
  603. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  604. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  605. } else {
  606. u16 len;
  607. /* Leave Ethernet header part of hdr and full payload */
  608. skb_pull(skb, hdrlen);
  609. len = htons(skb->len);
  610. memcpy(skb_push(skb, 2), &len, 2);
  611. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  612. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  613. }
  614. #ifdef NOT_YET
  615. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  616. IEEE80211_FCTL_TODS) &&
  617. skb->len >= ETH_HLEN + ETH_ALEN) {
  618. /* Non-standard frame: get addr4 from its bogus location after
  619. * the payload */
  620. memcpy(skb->data + ETH_ALEN,
  621. skb->data + skb->len - ETH_ALEN, ETH_ALEN);
  622. skb_trim(skb, skb->len - ETH_ALEN);
  623. }
  624. #endif
  625. stats->rx_packets++;
  626. stats->rx_bytes += skb->len;
  627. #ifdef NOT_YET
  628. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  629. ieee->ap->bridge_packets) {
  630. if (dst[0] & 0x01) {
  631. /* copy multicast frame both to the higher layers and
  632. * to the wireless media */
  633. ieee->ap->bridged_multicast++;
  634. skb2 = skb_clone(skb, GFP_ATOMIC);
  635. if (skb2 == NULL)
  636. printk(KERN_DEBUG "%s: skb_clone failed for "
  637. "multicast frame\n", dev->name);
  638. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  639. /* send frame directly to the associated STA using
  640. * wireless media and not passing to higher layers */
  641. ieee->ap->bridged_unicast++;
  642. skb2 = skb;
  643. skb = NULL;
  644. }
  645. }
  646. if (skb2 != NULL) {
  647. /* send to wireless media */
  648. skb2->protocol = __constant_htons(ETH_P_802_3);
  649. skb2->mac.raw = skb2->nh.raw = skb2->data;
  650. /* skb2->nh.raw = skb2->data + ETH_HLEN; */
  651. skb2->dev = dev;
  652. dev_queue_xmit(skb2);
  653. }
  654. #endif
  655. if (skb) {
  656. skb->protocol = eth_type_trans(skb, dev);
  657. memset(skb->cb, 0, sizeof(skb->cb));
  658. skb->dev = dev;
  659. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  660. netif_rx(skb);
  661. }
  662. rx_exit:
  663. #ifdef NOT_YET
  664. if (sta)
  665. hostap_handle_sta_release(sta);
  666. #endif
  667. return 1;
  668. rx_dropped:
  669. stats->rx_dropped++;
  670. /* Returning 0 indicates to caller that we have not handled the SKB--
  671. * so it is still allocated and can be used again by underlying
  672. * hardware as a DMA target */
  673. return 0;
  674. }
  675. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  676. static inline int ieee80211_is_ofdm_rate(u8 rate)
  677. {
  678. switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
  679. case IEEE80211_OFDM_RATE_6MB:
  680. case IEEE80211_OFDM_RATE_9MB:
  681. case IEEE80211_OFDM_RATE_12MB:
  682. case IEEE80211_OFDM_RATE_18MB:
  683. case IEEE80211_OFDM_RATE_24MB:
  684. case IEEE80211_OFDM_RATE_36MB:
  685. case IEEE80211_OFDM_RATE_48MB:
  686. case IEEE80211_OFDM_RATE_54MB:
  687. return 1;
  688. }
  689. return 0;
  690. }
  691. static inline int ieee80211_network_init(
  692. struct ieee80211_device *ieee,
  693. struct ieee80211_probe_response *beacon,
  694. struct ieee80211_network *network,
  695. struct ieee80211_rx_stats *stats)
  696. {
  697. #ifdef CONFIG_IEEE80211_DEBUG
  698. char rates_str[64];
  699. char *p;
  700. #endif
  701. struct ieee80211_info_element *info_element;
  702. u16 left;
  703. u8 i;
  704. /* Pull out fixed field data */
  705. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  706. network->capability = beacon->capability;
  707. network->last_scanned = jiffies;
  708. network->time_stamp[0] = beacon->time_stamp[0];
  709. network->time_stamp[1] = beacon->time_stamp[1];
  710. network->beacon_interval = beacon->beacon_interval;
  711. /* Where to pull this? beacon->listen_interval;*/
  712. network->listen_interval = 0x0A;
  713. network->rates_len = network->rates_ex_len = 0;
  714. network->last_associate = 0;
  715. network->ssid_len = 0;
  716. network->flags = 0;
  717. network->atim_window = 0;
  718. if (stats->freq == IEEE80211_52GHZ_BAND) {
  719. /* for A band (No DS info) */
  720. network->channel = stats->received_channel;
  721. } else
  722. network->flags |= NETWORK_HAS_CCK;
  723. network->wpa_ie_len = 0;
  724. network->rsn_ie_len = 0;
  725. info_element = &beacon->info_element;
  726. left = stats->len - ((void *)info_element - (void *)beacon);
  727. while (left >= sizeof(struct ieee80211_info_element_hdr)) {
  728. if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
  729. IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%Zd left=%d.\n",
  730. info_element->len + sizeof(struct ieee80211_info_element),
  731. left);
  732. return 1;
  733. }
  734. switch (info_element->id) {
  735. case MFIE_TYPE_SSID:
  736. if (ieee80211_is_empty_essid(info_element->data,
  737. info_element->len)) {
  738. network->flags |= NETWORK_EMPTY_ESSID;
  739. break;
  740. }
  741. network->ssid_len = min(info_element->len,
  742. (u8)IW_ESSID_MAX_SIZE);
  743. memcpy(network->ssid, info_element->data, network->ssid_len);
  744. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  745. memset(network->ssid + network->ssid_len, 0,
  746. IW_ESSID_MAX_SIZE - network->ssid_len);
  747. IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n",
  748. network->ssid, network->ssid_len);
  749. break;
  750. case MFIE_TYPE_RATES:
  751. #ifdef CONFIG_IEEE80211_DEBUG
  752. p = rates_str;
  753. #endif
  754. network->rates_len = min(info_element->len, MAX_RATES_LENGTH);
  755. for (i = 0; i < network->rates_len; i++) {
  756. network->rates[i] = info_element->data[i];
  757. #ifdef CONFIG_IEEE80211_DEBUG
  758. p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
  759. #endif
  760. if (ieee80211_is_ofdm_rate(info_element->data[i])) {
  761. network->flags |= NETWORK_HAS_OFDM;
  762. if (info_element->data[i] &
  763. IEEE80211_BASIC_RATE_MASK)
  764. network->flags &=
  765. ~NETWORK_HAS_CCK;
  766. }
  767. }
  768. IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n",
  769. rates_str, network->rates_len);
  770. break;
  771. case MFIE_TYPE_RATES_EX:
  772. #ifdef CONFIG_IEEE80211_DEBUG
  773. p = rates_str;
  774. #endif
  775. network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH);
  776. for (i = 0; i < network->rates_ex_len; i++) {
  777. network->rates_ex[i] = info_element->data[i];
  778. #ifdef CONFIG_IEEE80211_DEBUG
  779. p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]);
  780. #endif
  781. if (ieee80211_is_ofdm_rate(info_element->data[i])) {
  782. network->flags |= NETWORK_HAS_OFDM;
  783. if (info_element->data[i] &
  784. IEEE80211_BASIC_RATE_MASK)
  785. network->flags &=
  786. ~NETWORK_HAS_CCK;
  787. }
  788. }
  789. IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
  790. rates_str, network->rates_ex_len);
  791. break;
  792. case MFIE_TYPE_DS_SET:
  793. IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n",
  794. info_element->data[0]);
  795. if (stats->freq == IEEE80211_24GHZ_BAND)
  796. network->channel = info_element->data[0];
  797. break;
  798. case MFIE_TYPE_FH_SET:
  799. IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n");
  800. break;
  801. case MFIE_TYPE_CF_SET:
  802. IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n");
  803. break;
  804. case MFIE_TYPE_TIM:
  805. IEEE80211_DEBUG_SCAN("MFIE_TYPE_TIM: ignored\n");
  806. break;
  807. case MFIE_TYPE_IBSS_SET:
  808. IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n");
  809. break;
  810. case MFIE_TYPE_CHALLENGE:
  811. IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n");
  812. break;
  813. case MFIE_TYPE_GENERIC:
  814. IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n",
  815. info_element->len);
  816. if (info_element->len >= 4 &&
  817. info_element->data[0] == 0x00 &&
  818. info_element->data[1] == 0x50 &&
  819. info_element->data[2] == 0xf2 &&
  820. info_element->data[3] == 0x01) {
  821. network->wpa_ie_len = min(info_element->len + 2,
  822. MAX_WPA_IE_LEN);
  823. memcpy(network->wpa_ie, info_element,
  824. network->wpa_ie_len);
  825. }
  826. break;
  827. case MFIE_TYPE_RSN:
  828. IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n",
  829. info_element->len);
  830. network->rsn_ie_len = min(info_element->len + 2,
  831. MAX_WPA_IE_LEN);
  832. memcpy(network->rsn_ie, info_element,
  833. network->rsn_ie_len);
  834. break;
  835. default:
  836. IEEE80211_DEBUG_SCAN("unsupported IE %d\n",
  837. info_element->id);
  838. break;
  839. }
  840. left -= sizeof(struct ieee80211_info_element_hdr) +
  841. info_element->len;
  842. info_element = (struct ieee80211_info_element *)
  843. &info_element->data[info_element->len];
  844. }
  845. network->mode = 0;
  846. if (stats->freq == IEEE80211_52GHZ_BAND)
  847. network->mode = IEEE_A;
  848. else {
  849. if (network->flags & NETWORK_HAS_OFDM)
  850. network->mode |= IEEE_G;
  851. if (network->flags & NETWORK_HAS_CCK)
  852. network->mode |= IEEE_B;
  853. }
  854. if (network->mode == 0) {
  855. IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
  856. "network.\n",
  857. escape_essid(network->ssid,
  858. network->ssid_len),
  859. MAC_ARG(network->bssid));
  860. return 1;
  861. }
  862. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  863. network->flags |= NETWORK_EMPTY_ESSID;
  864. memcpy(&network->stats, stats, sizeof(network->stats));
  865. return 0;
  866. }
  867. static inline int is_same_network(struct ieee80211_network *src,
  868. struct ieee80211_network *dst)
  869. {
  870. /* A network is only a duplicate if the channel, BSSID, and ESSID
  871. * all match. We treat all <hidden> with the same BSSID and channel
  872. * as one network */
  873. return ((src->ssid_len == dst->ssid_len) &&
  874. (src->channel == dst->channel) &&
  875. !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
  876. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  877. }
  878. static inline void update_network(struct ieee80211_network *dst,
  879. struct ieee80211_network *src)
  880. {
  881. memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
  882. dst->capability = src->capability;
  883. memcpy(dst->rates, src->rates, src->rates_len);
  884. dst->rates_len = src->rates_len;
  885. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  886. dst->rates_ex_len = src->rates_ex_len;
  887. dst->mode = src->mode;
  888. dst->flags = src->flags;
  889. dst->time_stamp[0] = src->time_stamp[0];
  890. dst->time_stamp[1] = src->time_stamp[1];
  891. dst->beacon_interval = src->beacon_interval;
  892. dst->listen_interval = src->listen_interval;
  893. dst->atim_window = src->atim_window;
  894. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  895. dst->wpa_ie_len = src->wpa_ie_len;
  896. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  897. dst->rsn_ie_len = src->rsn_ie_len;
  898. dst->last_scanned = jiffies;
  899. /* dst->last_associate is not overwritten */
  900. }
  901. static inline void ieee80211_process_probe_response(
  902. struct ieee80211_device *ieee,
  903. struct ieee80211_probe_response *beacon,
  904. struct ieee80211_rx_stats *stats)
  905. {
  906. struct ieee80211_network network;
  907. struct ieee80211_network *target;
  908. struct ieee80211_network *oldest = NULL;
  909. #ifdef CONFIG_IEEE80211_DEBUG
  910. struct ieee80211_info_element *info_element = &beacon->info_element;
  911. #endif
  912. unsigned long flags;
  913. IEEE80211_DEBUG_SCAN(
  914. "'%s' (" MAC_FMT "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  915. escape_essid(info_element->data, info_element->len),
  916. MAC_ARG(beacon->header.addr3),
  917. (beacon->capability & (1<<0xf)) ? '1' : '0',
  918. (beacon->capability & (1<<0xe)) ? '1' : '0',
  919. (beacon->capability & (1<<0xd)) ? '1' : '0',
  920. (beacon->capability & (1<<0xc)) ? '1' : '0',
  921. (beacon->capability & (1<<0xb)) ? '1' : '0',
  922. (beacon->capability & (1<<0xa)) ? '1' : '0',
  923. (beacon->capability & (1<<0x9)) ? '1' : '0',
  924. (beacon->capability & (1<<0x8)) ? '1' : '0',
  925. (beacon->capability & (1<<0x7)) ? '1' : '0',
  926. (beacon->capability & (1<<0x6)) ? '1' : '0',
  927. (beacon->capability & (1<<0x5)) ? '1' : '0',
  928. (beacon->capability & (1<<0x4)) ? '1' : '0',
  929. (beacon->capability & (1<<0x3)) ? '1' : '0',
  930. (beacon->capability & (1<<0x2)) ? '1' : '0',
  931. (beacon->capability & (1<<0x1)) ? '1' : '0',
  932. (beacon->capability & (1<<0x0)) ? '1' : '0');
  933. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  934. IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
  935. escape_essid(info_element->data,
  936. info_element->len),
  937. MAC_ARG(beacon->header.addr3),
  938. WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
  939. IEEE80211_STYPE_PROBE_RESP ?
  940. "PROBE RESPONSE" : "BEACON");
  941. return;
  942. }
  943. /* The network parsed correctly -- so now we scan our known networks
  944. * to see if we can find it in our list.
  945. *
  946. * NOTE: This search is definitely not optimized. Once its doing
  947. * the "right thing" we'll optimize it for efficiency if
  948. * necessary */
  949. /* Search for this entry in the list and update it if it is
  950. * already there. */
  951. spin_lock_irqsave(&ieee->lock, flags);
  952. list_for_each_entry(target, &ieee->network_list, list) {
  953. if (is_same_network(target, &network))
  954. break;
  955. if ((oldest == NULL) ||
  956. (target->last_scanned < oldest->last_scanned))
  957. oldest = target;
  958. }
  959. /* If we didn't find a match, then get a new network slot to initialize
  960. * with this beacon's information */
  961. if (&target->list == &ieee->network_list) {
  962. if (list_empty(&ieee->network_free_list)) {
  963. /* If there are no more slots, expire the oldest */
  964. list_del(&oldest->list);
  965. target = oldest;
  966. IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
  967. "network list.\n",
  968. escape_essid(target->ssid,
  969. target->ssid_len),
  970. MAC_ARG(target->bssid));
  971. } else {
  972. /* Otherwise just pull from the free list */
  973. target = list_entry(ieee->network_free_list.next,
  974. struct ieee80211_network, list);
  975. list_del(ieee->network_free_list.next);
  976. }
  977. #ifdef CONFIG_IEEE80211_DEBUG
  978. IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
  979. escape_essid(network.ssid,
  980. network.ssid_len),
  981. MAC_ARG(network.bssid),
  982. WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
  983. IEEE80211_STYPE_PROBE_RESP ?
  984. "PROBE RESPONSE" : "BEACON");
  985. #endif
  986. memcpy(target, &network, sizeof(*target));
  987. list_add_tail(&target->list, &ieee->network_list);
  988. } else {
  989. IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
  990. escape_essid(target->ssid,
  991. target->ssid_len),
  992. MAC_ARG(target->bssid),
  993. WLAN_FC_GET_STYPE(beacon->header.frame_ctl) ==
  994. IEEE80211_STYPE_PROBE_RESP ?
  995. "PROBE RESPONSE" : "BEACON");
  996. update_network(target, &network);
  997. }
  998. spin_unlock_irqrestore(&ieee->lock, flags);
  999. }
  1000. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1001. struct ieee80211_hdr *header,
  1002. struct ieee80211_rx_stats *stats)
  1003. {
  1004. switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
  1005. case IEEE80211_STYPE_ASSOC_RESP:
  1006. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1007. WLAN_FC_GET_STYPE(header->frame_ctl));
  1008. break;
  1009. case IEEE80211_STYPE_REASSOC_RESP:
  1010. IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1011. WLAN_FC_GET_STYPE(header->frame_ctl));
  1012. break;
  1013. case IEEE80211_STYPE_PROBE_RESP:
  1014. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1015. WLAN_FC_GET_STYPE(header->frame_ctl));
  1016. IEEE80211_DEBUG_SCAN("Probe response\n");
  1017. ieee80211_process_probe_response(
  1018. ieee, (struct ieee80211_probe_response *)header, stats);
  1019. break;
  1020. case IEEE80211_STYPE_BEACON:
  1021. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1022. WLAN_FC_GET_STYPE(header->frame_ctl));
  1023. IEEE80211_DEBUG_SCAN("Beacon\n");
  1024. ieee80211_process_probe_response(
  1025. ieee, (struct ieee80211_probe_response *)header, stats);
  1026. break;
  1027. default:
  1028. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1029. WLAN_FC_GET_STYPE(header->frame_ctl));
  1030. IEEE80211_WARNING("%s: Unknown management packet: %d\n",
  1031. ieee->dev->name,
  1032. WLAN_FC_GET_STYPE(header->frame_ctl));
  1033. break;
  1034. }
  1035. }
  1036. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1037. EXPORT_SYMBOL(ieee80211_rx);