ieee80211_rx.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. 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 *hdr;
  266. int res, hdrlen;
  267. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  268. return 0;
  269. hdr = (struct ieee80211_hdr *)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 *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 *)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 *)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 *)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 *)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 void ieee80211_process_probe_response(struct ieee80211_device
  903. *ieee, struct
  904. ieee80211_probe_response
  905. *beacon, struct ieee80211_rx_stats
  906. *stats)
  907. {
  908. struct ieee80211_network network;
  909. struct ieee80211_network *target;
  910. struct ieee80211_network *oldest = NULL;
  911. #ifdef CONFIG_IEEE80211_DEBUG
  912. struct ieee80211_info_element *info_element = beacon->info_element;
  913. #endif
  914. unsigned long flags;
  915. IEEE80211_DEBUG_SCAN("'%s' (" MAC_FMT
  916. "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  917. escape_essid(info_element->data,
  918. info_element->len),
  919. MAC_ARG(beacon->header.addr3),
  920. (beacon->capability & (1 << 0xf)) ? '1' : '0',
  921. (beacon->capability & (1 << 0xe)) ? '1' : '0',
  922. (beacon->capability & (1 << 0xd)) ? '1' : '0',
  923. (beacon->capability & (1 << 0xc)) ? '1' : '0',
  924. (beacon->capability & (1 << 0xb)) ? '1' : '0',
  925. (beacon->capability & (1 << 0xa)) ? '1' : '0',
  926. (beacon->capability & (1 << 0x9)) ? '1' : '0',
  927. (beacon->capability & (1 << 0x8)) ? '1' : '0',
  928. (beacon->capability & (1 << 0x7)) ? '1' : '0',
  929. (beacon->capability & (1 << 0x6)) ? '1' : '0',
  930. (beacon->capability & (1 << 0x5)) ? '1' : '0',
  931. (beacon->capability & (1 << 0x4)) ? '1' : '0',
  932. (beacon->capability & (1 << 0x3)) ? '1' : '0',
  933. (beacon->capability & (1 << 0x2)) ? '1' : '0',
  934. (beacon->capability & (1 << 0x1)) ? '1' : '0',
  935. (beacon->capability & (1 << 0x0)) ? '1' : '0');
  936. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  937. IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
  938. escape_essid(info_element->data,
  939. info_element->len),
  940. MAC_ARG(beacon->header.addr3),
  941. WLAN_FC_GET_STYPE(le16_to_cpu
  942. (beacon->header.
  943. frame_ctl)) ==
  944. IEEE80211_STYPE_PROBE_RESP ?
  945. "PROBE RESPONSE" : "BEACON");
  946. return;
  947. }
  948. /* The network parsed correctly -- so now we scan our known networks
  949. * to see if we can find it in our list.
  950. *
  951. * NOTE: This search is definitely not optimized. Once its doing
  952. * the "right thing" we'll optimize it for efficiency if
  953. * necessary */
  954. /* Search for this entry in the list and update it if it is
  955. * already there. */
  956. spin_lock_irqsave(&ieee->lock, flags);
  957. list_for_each_entry(target, &ieee->network_list, list) {
  958. if (is_same_network(target, &network))
  959. break;
  960. if ((oldest == NULL) ||
  961. (target->last_scanned < oldest->last_scanned))
  962. oldest = target;
  963. }
  964. /* If we didn't find a match, then get a new network slot to initialize
  965. * with this beacon's information */
  966. if (&target->list == &ieee->network_list) {
  967. if (list_empty(&ieee->network_free_list)) {
  968. /* If there are no more slots, expire the oldest */
  969. list_del(&oldest->list);
  970. target = oldest;
  971. IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
  972. "network list.\n",
  973. escape_essid(target->ssid,
  974. target->ssid_len),
  975. MAC_ARG(target->bssid));
  976. } else {
  977. /* Otherwise just pull from the free list */
  978. target = list_entry(ieee->network_free_list.next,
  979. struct ieee80211_network, list);
  980. list_del(ieee->network_free_list.next);
  981. }
  982. #ifdef CONFIG_IEEE80211_DEBUG
  983. IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
  984. escape_essid(network.ssid,
  985. network.ssid_len),
  986. MAC_ARG(network.bssid),
  987. WLAN_FC_GET_STYPE(le16_to_cpu
  988. (beacon->header.
  989. frame_ctl)) ==
  990. IEEE80211_STYPE_PROBE_RESP ?
  991. "PROBE RESPONSE" : "BEACON");
  992. #endif
  993. memcpy(target, &network, sizeof(*target));
  994. list_add_tail(&target->list, &ieee->network_list);
  995. } else {
  996. IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
  997. escape_essid(target->ssid,
  998. target->ssid_len),
  999. MAC_ARG(target->bssid),
  1000. WLAN_FC_GET_STYPE(le16_to_cpu
  1001. (beacon->header.
  1002. frame_ctl)) ==
  1003. IEEE80211_STYPE_PROBE_RESP ?
  1004. "PROBE RESPONSE" : "BEACON");
  1005. update_network(target, &network);
  1006. }
  1007. spin_unlock_irqrestore(&ieee->lock, flags);
  1008. }
  1009. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1010. struct ieee80211_hdr *header,
  1011. struct ieee80211_rx_stats *stats)
  1012. {
  1013. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1014. case IEEE80211_STYPE_ASSOC_RESP:
  1015. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1016. WLAN_FC_GET_STYPE(le16_to_cpu
  1017. (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(le16_to_cpu
  1022. (header->frame_ctl)));
  1023. break;
  1024. case IEEE80211_STYPE_PROBE_RESP:
  1025. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1026. WLAN_FC_GET_STYPE(le16_to_cpu
  1027. (header->frame_ctl)));
  1028. IEEE80211_DEBUG_SCAN("Probe response\n");
  1029. ieee80211_process_probe_response(ieee,
  1030. (struct
  1031. ieee80211_probe_response *)
  1032. header, stats);
  1033. break;
  1034. case IEEE80211_STYPE_BEACON:
  1035. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1036. WLAN_FC_GET_STYPE(le16_to_cpu
  1037. (header->frame_ctl)));
  1038. IEEE80211_DEBUG_SCAN("Beacon\n");
  1039. ieee80211_process_probe_response(ieee,
  1040. (struct
  1041. ieee80211_probe_response *)
  1042. header, stats);
  1043. break;
  1044. default:
  1045. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1046. WLAN_FC_GET_STYPE(le16_to_cpu
  1047. (header->frame_ctl)));
  1048. IEEE80211_WARNING("%s: Unknown management packet: %d\n",
  1049. ieee->dev->name,
  1050. WLAN_FC_GET_STYPE(le16_to_cpu
  1051. (header->frame_ctl)));
  1052. break;
  1053. }
  1054. }
  1055. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1056. EXPORT_SYMBOL(ieee80211_rx);