ieee80211_rx.c 36 KB

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