ieee80211_rx.c 35 KB

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