ieee80211_rx.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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-2005, 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 (is_multicast_ether_addr(hdr->addr1) ? ieee->host_mc_decrypt :
  356. 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. stype &= ~IEEE80211_STYPE_QOS_DATA;
  470. if (stype != IEEE80211_STYPE_DATA &&
  471. stype != IEEE80211_STYPE_DATA_CFACK &&
  472. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  473. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  474. if (stype != IEEE80211_STYPE_NULLFUNC)
  475. IEEE80211_DEBUG_DROP("RX: dropped data frame "
  476. "with no data (type=0x%02x, "
  477. "subtype=0x%02x, len=%d)\n",
  478. type, stype, skb->len);
  479. goto rx_dropped;
  480. }
  481. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  482. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  483. (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  484. goto rx_dropped;
  485. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  486. /* skb: hdr + (possibly fragmented) plaintext payload */
  487. // PR: FIXME: hostap has additional conditions in the "if" below:
  488. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  489. if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
  490. int flen;
  491. struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
  492. IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  493. if (!frag_skb) {
  494. IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
  495. "Rx cannot get skb from fragment "
  496. "cache (morefrag=%d seq=%u frag=%u)\n",
  497. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  498. WLAN_GET_SEQ_SEQ(sc), frag);
  499. goto rx_dropped;
  500. }
  501. flen = skb->len;
  502. if (frag != 0)
  503. flen -= hdrlen;
  504. if (frag_skb->tail + flen > frag_skb->end) {
  505. printk(KERN_WARNING "%s: host decrypted and "
  506. "reassembled frame did not fit skb\n",
  507. dev->name);
  508. ieee80211_frag_cache_invalidate(ieee, hdr);
  509. goto rx_dropped;
  510. }
  511. if (frag == 0) {
  512. /* copy first fragment (including full headers) into
  513. * beginning of the fragment cache skb */
  514. memcpy(skb_put(frag_skb, flen), skb->data, flen);
  515. } else {
  516. /* append frame payload to the end of the fragment
  517. * cache skb */
  518. memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
  519. flen);
  520. }
  521. dev_kfree_skb_any(skb);
  522. skb = NULL;
  523. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  524. /* more fragments expected - leave the skb in fragment
  525. * cache for now; it will be delivered to upper layers
  526. * after all fragments have been received */
  527. goto rx_exit;
  528. }
  529. /* this was the last fragment and the frame will be
  530. * delivered, so remove skb from fragment cache */
  531. skb = frag_skb;
  532. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  533. ieee80211_frag_cache_invalidate(ieee, hdr);
  534. }
  535. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  536. * encrypted/authenticated */
  537. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  538. ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  539. goto rx_dropped;
  540. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  541. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  542. if ( /*ieee->ieee802_1x && */
  543. ieee80211_is_eapol_frame(ieee, skb)) {
  544. /* pass unencrypted EAPOL frames even if encryption is
  545. * configured */
  546. } else {
  547. IEEE80211_DEBUG_DROP("encryption configured, but RX "
  548. "frame not encrypted (SA=" MAC_FMT
  549. ")\n", MAC_ARG(hdr->addr2));
  550. goto rx_dropped;
  551. }
  552. }
  553. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  554. !ieee80211_is_eapol_frame(ieee, skb)) {
  555. IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
  556. "frame from " MAC_FMT
  557. " (drop_unencrypted=1)\n",
  558. MAC_ARG(hdr->addr2));
  559. goto rx_dropped;
  560. }
  561. /* skb: hdr + (possible reassembled) full plaintext payload */
  562. payload = skb->data + hdrlen;
  563. ethertype = (payload[6] << 8) | payload[7];
  564. #ifdef NOT_YET
  565. /* If IEEE 802.1X is used, check whether the port is authorized to send
  566. * the received frame. */
  567. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  568. if (ethertype == ETH_P_PAE) {
  569. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  570. dev->name);
  571. if (ieee->hostapd && ieee->apdev) {
  572. /* Send IEEE 802.1X frames to the user
  573. * space daemon for processing */
  574. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  575. PRISM2_RX_MGMT);
  576. ieee->apdevstats.rx_packets++;
  577. ieee->apdevstats.rx_bytes += skb->len;
  578. goto rx_exit;
  579. }
  580. } else if (!frame_authorized) {
  581. printk(KERN_DEBUG "%s: dropped frame from "
  582. "unauthorized port (IEEE 802.1X): "
  583. "ethertype=0x%04x\n", dev->name, ethertype);
  584. goto rx_dropped;
  585. }
  586. }
  587. #endif
  588. /* convert hdr + possible LLC headers into Ethernet header */
  589. if (skb->len - hdrlen >= 8 &&
  590. ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
  591. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  592. memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
  593. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  594. * replace EtherType */
  595. skb_pull(skb, hdrlen + SNAP_SIZE);
  596. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  597. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  598. } else {
  599. u16 len;
  600. /* Leave Ethernet header part of hdr and full payload */
  601. skb_pull(skb, hdrlen);
  602. len = htons(skb->len);
  603. memcpy(skb_push(skb, 2), &len, 2);
  604. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  605. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  606. }
  607. #ifdef NOT_YET
  608. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  609. IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
  610. /* Non-standard frame: get addr4 from its bogus location after
  611. * the payload */
  612. memcpy(skb->data + ETH_ALEN,
  613. skb->data + skb->len - ETH_ALEN, ETH_ALEN);
  614. skb_trim(skb, skb->len - ETH_ALEN);
  615. }
  616. #endif
  617. stats->rx_packets++;
  618. stats->rx_bytes += skb->len;
  619. #ifdef NOT_YET
  620. if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
  621. if (dst[0] & 0x01) {
  622. /* copy multicast frame both to the higher layers and
  623. * to the wireless media */
  624. ieee->ap->bridged_multicast++;
  625. skb2 = skb_clone(skb, GFP_ATOMIC);
  626. if (skb2 == NULL)
  627. printk(KERN_DEBUG "%s: skb_clone failed for "
  628. "multicast frame\n", dev->name);
  629. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  630. /* send frame directly to the associated STA using
  631. * wireless media and not passing to higher layers */
  632. ieee->ap->bridged_unicast++;
  633. skb2 = skb;
  634. skb = NULL;
  635. }
  636. }
  637. if (skb2 != NULL) {
  638. /* send to wireless media */
  639. skb2->protocol = __constant_htons(ETH_P_802_3);
  640. skb2->mac.raw = skb2->nh.raw = skb2->data;
  641. /* skb2->nh.raw = skb2->data + ETH_HLEN; */
  642. skb2->dev = dev;
  643. dev_queue_xmit(skb2);
  644. }
  645. #endif
  646. if (skb) {
  647. skb->protocol = eth_type_trans(skb, dev);
  648. memset(skb->cb, 0, sizeof(skb->cb));
  649. skb->dev = dev;
  650. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  651. netif_rx(skb);
  652. }
  653. rx_exit:
  654. #ifdef NOT_YET
  655. if (sta)
  656. hostap_handle_sta_release(sta);
  657. #endif
  658. return 1;
  659. rx_dropped:
  660. stats->rx_dropped++;
  661. /* Returning 0 indicates to caller that we have not handled the SKB--
  662. * so it is still allocated and can be used again by underlying
  663. * hardware as a DMA target */
  664. return 0;
  665. }
  666. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  667. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  668. /*
  669. * Make ther structure we read from the beacon packet has
  670. * the right values
  671. */
  672. static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
  673. *info_element, int sub_type)
  674. {
  675. if (info_element->qui_subtype != sub_type)
  676. return -1;
  677. if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
  678. return -1;
  679. if (info_element->qui_type != QOS_OUI_TYPE)
  680. return -1;
  681. if (info_element->version != QOS_VERSION_1)
  682. return -1;
  683. return 0;
  684. }
  685. /*
  686. * Parse a QoS parameter element
  687. */
  688. static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
  689. *element_param, struct ieee80211_info_element
  690. *info_element)
  691. {
  692. int ret = 0;
  693. u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
  694. if ((info_element == NULL) || (element_param == NULL))
  695. return -1;
  696. if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
  697. memcpy(element_param->info_element.qui, info_element->data,
  698. info_element->len);
  699. element_param->info_element.elementID = info_element->id;
  700. element_param->info_element.length = info_element->len;
  701. } else
  702. ret = -1;
  703. if (ret == 0)
  704. ret = ieee80211_verify_qos_info(&element_param->info_element,
  705. QOS_OUI_PARAM_SUB_TYPE);
  706. return ret;
  707. }
  708. /*
  709. * Parse a QoS information element
  710. */
  711. static int ieee80211_read_qos_info_element(struct
  712. ieee80211_qos_information_element
  713. *element_info, struct ieee80211_info_element
  714. *info_element)
  715. {
  716. int ret = 0;
  717. u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
  718. if (element_info == NULL)
  719. return -1;
  720. if (info_element == NULL)
  721. return -1;
  722. if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
  723. memcpy(element_info->qui, info_element->data,
  724. info_element->len);
  725. element_info->elementID = info_element->id;
  726. element_info->length = info_element->len;
  727. } else
  728. ret = -1;
  729. if (ret == 0)
  730. ret = ieee80211_verify_qos_info(element_info,
  731. QOS_OUI_INFO_SUB_TYPE);
  732. return ret;
  733. }
  734. /*
  735. * Write QoS parameters from the ac parameters.
  736. */
  737. static int ieee80211_qos_convert_ac_to_parameters(struct
  738. ieee80211_qos_parameter_info
  739. *param_elm, struct
  740. ieee80211_qos_parameters
  741. *qos_param)
  742. {
  743. int rc = 0;
  744. int i;
  745. struct ieee80211_qos_ac_parameter *ac_params;
  746. u32 txop;
  747. u8 cw_min;
  748. u8 cw_max;
  749. for (i = 0; i < QOS_QUEUE_NUM; i++) {
  750. ac_params = &(param_elm->ac_params_record[i]);
  751. qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
  752. qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
  753. cw_min = ac_params->ecw_min_max & 0x0F;
  754. qos_param->cw_min[i] = (u16) ((1 << cw_min) - 1);
  755. cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
  756. qos_param->cw_max[i] = (u16) ((1 << cw_max) - 1);
  757. qos_param->flag[i] =
  758. (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
  759. txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
  760. qos_param->tx_op_limit[i] = (u16) txop;
  761. }
  762. return rc;
  763. }
  764. /*
  765. * we have a generic data element which it may contain QoS information or
  766. * parameters element. check the information element length to decide
  767. * which type to read
  768. */
  769. static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
  770. *info_element,
  771. struct ieee80211_network *network)
  772. {
  773. int rc = 0;
  774. struct ieee80211_qos_parameters *qos_param = NULL;
  775. struct ieee80211_qos_information_element qos_info_element;
  776. rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
  777. if (rc == 0) {
  778. network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
  779. network->flags |= NETWORK_HAS_QOS_INFORMATION;
  780. } else {
  781. struct ieee80211_qos_parameter_info param_element;
  782. rc = ieee80211_read_qos_param_element(&param_element,
  783. info_element);
  784. if (rc == 0) {
  785. qos_param = &(network->qos_data.parameters);
  786. ieee80211_qos_convert_ac_to_parameters(&param_element,
  787. qos_param);
  788. network->flags |= NETWORK_HAS_QOS_PARAMETERS;
  789. network->qos_data.param_count =
  790. param_element.info_element.ac_info & 0x0F;
  791. }
  792. }
  793. if (rc == 0) {
  794. IEEE80211_DEBUG_QOS("QoS is supported\n");
  795. network->qos_data.supported = 1;
  796. }
  797. return rc;
  798. }
  799. static int ieee80211_parse_info_param(struct ieee80211_info_element
  800. *info_element, u16 length,
  801. struct ieee80211_network *network)
  802. {
  803. u8 i;
  804. #ifdef CONFIG_IEEE80211_DEBUG
  805. char rates_str[64];
  806. char *p;
  807. #endif
  808. while (length >= sizeof(*info_element)) {
  809. if (sizeof(*info_element) + info_element->len > length) {
  810. IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
  811. "info_element->len + 2 > left : "
  812. "info_element->len+2=%zd left=%d, id=%d.\n",
  813. info_element->len +
  814. sizeof(*info_element),
  815. length, info_element->id);
  816. return 1;
  817. }
  818. switch (info_element->id) {
  819. case MFIE_TYPE_SSID:
  820. if (ieee80211_is_empty_essid(info_element->data,
  821. info_element->len)) {
  822. network->flags |= NETWORK_EMPTY_ESSID;
  823. break;
  824. }
  825. network->ssid_len = min(info_element->len,
  826. (u8) IW_ESSID_MAX_SIZE);
  827. memcpy(network->ssid, info_element->data,
  828. network->ssid_len);
  829. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  830. memset(network->ssid + network->ssid_len, 0,
  831. IW_ESSID_MAX_SIZE - network->ssid_len);
  832. IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
  833. network->ssid, network->ssid_len);
  834. break;
  835. case MFIE_TYPE_RATES:
  836. #ifdef CONFIG_IEEE80211_DEBUG
  837. p = rates_str;
  838. #endif
  839. network->rates_len = min(info_element->len,
  840. MAX_RATES_LENGTH);
  841. for (i = 0; i < network->rates_len; i++) {
  842. network->rates[i] = info_element->data[i];
  843. #ifdef CONFIG_IEEE80211_DEBUG
  844. p += snprintf(p, sizeof(rates_str) -
  845. (p - rates_str), "%02X ",
  846. network->rates[i]);
  847. #endif
  848. if (ieee80211_is_ofdm_rate
  849. (info_element->data[i])) {
  850. network->flags |= NETWORK_HAS_OFDM;
  851. if (info_element->data[i] &
  852. IEEE80211_BASIC_RATE_MASK)
  853. network->flags &=
  854. ~NETWORK_HAS_CCK;
  855. }
  856. }
  857. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
  858. rates_str, network->rates_len);
  859. break;
  860. case MFIE_TYPE_RATES_EX:
  861. #ifdef CONFIG_IEEE80211_DEBUG
  862. p = rates_str;
  863. #endif
  864. network->rates_ex_len = min(info_element->len,
  865. MAX_RATES_EX_LENGTH);
  866. for (i = 0; i < network->rates_ex_len; i++) {
  867. network->rates_ex[i] = info_element->data[i];
  868. #ifdef CONFIG_IEEE80211_DEBUG
  869. p += snprintf(p, sizeof(rates_str) -
  870. (p - rates_str), "%02X ",
  871. network->rates[i]);
  872. #endif
  873. if (ieee80211_is_ofdm_rate
  874. (info_element->data[i])) {
  875. network->flags |= NETWORK_HAS_OFDM;
  876. if (info_element->data[i] &
  877. IEEE80211_BASIC_RATE_MASK)
  878. network->flags &=
  879. ~NETWORK_HAS_CCK;
  880. }
  881. }
  882. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
  883. rates_str, network->rates_ex_len);
  884. break;
  885. case MFIE_TYPE_DS_SET:
  886. IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
  887. info_element->data[0]);
  888. network->channel = info_element->data[0];
  889. break;
  890. case MFIE_TYPE_FH_SET:
  891. IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
  892. break;
  893. case MFIE_TYPE_CF_SET:
  894. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
  895. break;
  896. case MFIE_TYPE_TIM:
  897. IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: ignored\n");
  898. break;
  899. case MFIE_TYPE_ERP_INFO:
  900. network->erp_value = info_element->data[0];
  901. IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
  902. network->erp_value);
  903. break;
  904. case MFIE_TYPE_IBSS_SET:
  905. network->atim_window = info_element->data[0];
  906. IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
  907. network->atim_window);
  908. break;
  909. case MFIE_TYPE_CHALLENGE:
  910. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
  911. break;
  912. case MFIE_TYPE_GENERIC:
  913. IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
  914. info_element->len);
  915. if (!ieee80211_parse_qos_info_param_IE(info_element,
  916. network))
  917. break;
  918. if (info_element->len >= 4 &&
  919. info_element->data[0] == 0x00 &&
  920. info_element->data[1] == 0x50 &&
  921. info_element->data[2] == 0xf2 &&
  922. info_element->data[3] == 0x01) {
  923. network->wpa_ie_len = min(info_element->len + 2,
  924. MAX_WPA_IE_LEN);
  925. memcpy(network->wpa_ie, info_element,
  926. network->wpa_ie_len);
  927. }
  928. break;
  929. case MFIE_TYPE_RSN:
  930. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
  931. info_element->len);
  932. network->rsn_ie_len = min(info_element->len + 2,
  933. MAX_WPA_IE_LEN);
  934. memcpy(network->rsn_ie, info_element,
  935. network->rsn_ie_len);
  936. break;
  937. case MFIE_TYPE_QOS_PARAMETER:
  938. printk(KERN_ERR
  939. "QoS Error need to parse QOS_PARAMETER IE\n");
  940. break;
  941. default:
  942. IEEE80211_DEBUG_MGMT("unsupported IE %d\n",
  943. info_element->id);
  944. break;
  945. }
  946. length -= sizeof(*info_element) + info_element->len;
  947. info_element =
  948. (struct ieee80211_info_element *)&info_element->
  949. data[info_element->len];
  950. }
  951. return 0;
  952. }
  953. static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
  954. *frame, struct ieee80211_rx_stats *stats)
  955. {
  956. struct ieee80211_network network_resp;
  957. struct ieee80211_network *network = &network_resp;
  958. struct net_device *dev = ieee->dev;
  959. network->flags = 0;
  960. network->qos_data.active = 0;
  961. network->qos_data.supported = 0;
  962. network->qos_data.param_count = 0;
  963. network->qos_data.old_param_count = 0;
  964. //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
  965. network->atim_window = le16_to_cpu(frame->aid);
  966. network->listen_interval = le16_to_cpu(frame->status);
  967. memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
  968. network->capability = le16_to_cpu(frame->capability);
  969. network->last_scanned = jiffies;
  970. network->rates_len = network->rates_ex_len = 0;
  971. network->last_associate = 0;
  972. network->ssid_len = 0;
  973. network->erp_value =
  974. (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
  975. if (stats->freq == IEEE80211_52GHZ_BAND) {
  976. /* for A band (No DS info) */
  977. network->channel = stats->received_channel;
  978. } else
  979. network->flags |= NETWORK_HAS_CCK;
  980. network->wpa_ie_len = 0;
  981. network->rsn_ie_len = 0;
  982. if (ieee80211_parse_info_param
  983. (frame->info_element, stats->len - sizeof(*frame), network))
  984. return 1;
  985. network->mode = 0;
  986. if (stats->freq == IEEE80211_52GHZ_BAND)
  987. network->mode = IEEE_A;
  988. else {
  989. if (network->flags & NETWORK_HAS_OFDM)
  990. network->mode |= IEEE_G;
  991. if (network->flags & NETWORK_HAS_CCK)
  992. network->mode |= IEEE_B;
  993. }
  994. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  995. network->flags |= NETWORK_EMPTY_ESSID;
  996. memcpy(&network->stats, stats, sizeof(network->stats));
  997. if (ieee->handle_assoc_response != NULL)
  998. ieee->handle_assoc_response(dev, frame, network);
  999. return 0;
  1000. }
  1001. /***************************************************/
  1002. static inline int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
  1003. *beacon,
  1004. struct ieee80211_network *network,
  1005. struct ieee80211_rx_stats *stats)
  1006. {
  1007. network->qos_data.active = 0;
  1008. network->qos_data.supported = 0;
  1009. network->qos_data.param_count = 0;
  1010. network->qos_data.old_param_count = 0;
  1011. /* Pull out fixed field data */
  1012. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  1013. network->capability = le16_to_cpu(beacon->capability);
  1014. network->last_scanned = jiffies;
  1015. network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
  1016. network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
  1017. network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
  1018. /* Where to pull this? beacon->listen_interval; */
  1019. network->listen_interval = 0x0A;
  1020. network->rates_len = network->rates_ex_len = 0;
  1021. network->last_associate = 0;
  1022. network->ssid_len = 0;
  1023. network->flags = 0;
  1024. network->atim_window = 0;
  1025. network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
  1026. 0x3 : 0x0;
  1027. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1028. /* for A band (No DS info) */
  1029. network->channel = stats->received_channel;
  1030. } else
  1031. network->flags |= NETWORK_HAS_CCK;
  1032. network->wpa_ie_len = 0;
  1033. network->rsn_ie_len = 0;
  1034. if (ieee80211_parse_info_param
  1035. (beacon->info_element, stats->len - sizeof(*beacon), network))
  1036. return 1;
  1037. network->mode = 0;
  1038. if (stats->freq == IEEE80211_52GHZ_BAND)
  1039. network->mode = IEEE_A;
  1040. else {
  1041. if (network->flags & NETWORK_HAS_OFDM)
  1042. network->mode |= IEEE_G;
  1043. if (network->flags & NETWORK_HAS_CCK)
  1044. network->mode |= IEEE_B;
  1045. }
  1046. if (network->mode == 0) {
  1047. IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
  1048. "network.\n",
  1049. escape_essid(network->ssid,
  1050. network->ssid_len),
  1051. MAC_ARG(network->bssid));
  1052. return 1;
  1053. }
  1054. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  1055. network->flags |= NETWORK_EMPTY_ESSID;
  1056. memcpy(&network->stats, stats, sizeof(network->stats));
  1057. return 0;
  1058. }
  1059. static inline int is_same_network(struct ieee80211_network *src,
  1060. struct ieee80211_network *dst)
  1061. {
  1062. /* A network is only a duplicate if the channel, BSSID, and ESSID
  1063. * all match. We treat all <hidden> with the same BSSID and channel
  1064. * as one network */
  1065. return ((src->ssid_len == dst->ssid_len) &&
  1066. (src->channel == dst->channel) &&
  1067. !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
  1068. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  1069. }
  1070. static inline void update_network(struct ieee80211_network *dst,
  1071. struct ieee80211_network *src)
  1072. {
  1073. int qos_active;
  1074. u8 old_param;
  1075. memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
  1076. dst->capability = src->capability;
  1077. memcpy(dst->rates, src->rates, src->rates_len);
  1078. dst->rates_len = src->rates_len;
  1079. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  1080. dst->rates_ex_len = src->rates_ex_len;
  1081. dst->mode = src->mode;
  1082. dst->flags = src->flags;
  1083. dst->time_stamp[0] = src->time_stamp[0];
  1084. dst->time_stamp[1] = src->time_stamp[1];
  1085. dst->beacon_interval = src->beacon_interval;
  1086. dst->listen_interval = src->listen_interval;
  1087. dst->atim_window = src->atim_window;
  1088. dst->erp_value = src->erp_value;
  1089. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  1090. dst->wpa_ie_len = src->wpa_ie_len;
  1091. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  1092. dst->rsn_ie_len = src->rsn_ie_len;
  1093. dst->last_scanned = jiffies;
  1094. qos_active = src->qos_data.active;
  1095. old_param = dst->qos_data.old_param_count;
  1096. if (dst->flags & NETWORK_HAS_QOS_MASK)
  1097. memcpy(&dst->qos_data, &src->qos_data,
  1098. sizeof(struct ieee80211_qos_data));
  1099. else {
  1100. dst->qos_data.supported = src->qos_data.supported;
  1101. dst->qos_data.param_count = src->qos_data.param_count;
  1102. }
  1103. if (dst->qos_data.supported == 1) {
  1104. if (dst->ssid_len)
  1105. IEEE80211_DEBUG_QOS
  1106. ("QoS the network %s is QoS supported\n",
  1107. dst->ssid);
  1108. else
  1109. IEEE80211_DEBUG_QOS
  1110. ("QoS the network is QoS supported\n");
  1111. }
  1112. dst->qos_data.active = qos_active;
  1113. dst->qos_data.old_param_count = old_param;
  1114. /* dst->last_associate is not overwritten */
  1115. }
  1116. static inline int is_beacon(int fc)
  1117. {
  1118. return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
  1119. }
  1120. static inline void ieee80211_process_probe_response(struct ieee80211_device
  1121. *ieee, struct
  1122. ieee80211_probe_response
  1123. *beacon, struct ieee80211_rx_stats
  1124. *stats)
  1125. {
  1126. struct net_device *dev = ieee->dev;
  1127. struct ieee80211_network network;
  1128. struct ieee80211_network *target;
  1129. struct ieee80211_network *oldest = NULL;
  1130. #ifdef CONFIG_IEEE80211_DEBUG
  1131. struct ieee80211_info_element *info_element = beacon->info_element;
  1132. #endif
  1133. unsigned long flags;
  1134. IEEE80211_DEBUG_SCAN("'%s' (" MAC_FMT
  1135. "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  1136. escape_essid(info_element->data,
  1137. info_element->len),
  1138. MAC_ARG(beacon->header.addr3),
  1139. (beacon->capability & (1 << 0xf)) ? '1' : '0',
  1140. (beacon->capability & (1 << 0xe)) ? '1' : '0',
  1141. (beacon->capability & (1 << 0xd)) ? '1' : '0',
  1142. (beacon->capability & (1 << 0xc)) ? '1' : '0',
  1143. (beacon->capability & (1 << 0xb)) ? '1' : '0',
  1144. (beacon->capability & (1 << 0xa)) ? '1' : '0',
  1145. (beacon->capability & (1 << 0x9)) ? '1' : '0',
  1146. (beacon->capability & (1 << 0x8)) ? '1' : '0',
  1147. (beacon->capability & (1 << 0x7)) ? '1' : '0',
  1148. (beacon->capability & (1 << 0x6)) ? '1' : '0',
  1149. (beacon->capability & (1 << 0x5)) ? '1' : '0',
  1150. (beacon->capability & (1 << 0x4)) ? '1' : '0',
  1151. (beacon->capability & (1 << 0x3)) ? '1' : '0',
  1152. (beacon->capability & (1 << 0x2)) ? '1' : '0',
  1153. (beacon->capability & (1 << 0x1)) ? '1' : '0',
  1154. (beacon->capability & (1 << 0x0)) ? '1' : '0');
  1155. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  1156. IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
  1157. escape_essid(info_element->data,
  1158. info_element->len),
  1159. MAC_ARG(beacon->header.addr3),
  1160. is_beacon(le16_to_cpu
  1161. (beacon->header.
  1162. frame_ctl)) ?
  1163. "BEACON" : "PROBE RESPONSE");
  1164. return;
  1165. }
  1166. /* The network parsed correctly -- so now we scan our known networks
  1167. * to see if we can find it in our list.
  1168. *
  1169. * NOTE: This search is definitely not optimized. Once its doing
  1170. * the "right thing" we'll optimize it for efficiency if
  1171. * necessary */
  1172. /* Search for this entry in the list and update it if it is
  1173. * already there. */
  1174. spin_lock_irqsave(&ieee->lock, flags);
  1175. list_for_each_entry(target, &ieee->network_list, list) {
  1176. if (is_same_network(target, &network))
  1177. break;
  1178. if ((oldest == NULL) ||
  1179. (target->last_scanned < oldest->last_scanned))
  1180. oldest = target;
  1181. }
  1182. /* If we didn't find a match, then get a new network slot to initialize
  1183. * with this beacon's information */
  1184. if (&target->list == &ieee->network_list) {
  1185. if (list_empty(&ieee->network_free_list)) {
  1186. /* If there are no more slots, expire the oldest */
  1187. list_del(&oldest->list);
  1188. target = oldest;
  1189. IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
  1190. "network list.\n",
  1191. escape_essid(target->ssid,
  1192. target->ssid_len),
  1193. MAC_ARG(target->bssid));
  1194. } else {
  1195. /* Otherwise just pull from the free list */
  1196. target = list_entry(ieee->network_free_list.next,
  1197. struct ieee80211_network, list);
  1198. list_del(ieee->network_free_list.next);
  1199. }
  1200. #ifdef CONFIG_IEEE80211_DEBUG
  1201. IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
  1202. escape_essid(network.ssid,
  1203. network.ssid_len),
  1204. MAC_ARG(network.bssid),
  1205. is_beacon(le16_to_cpu
  1206. (beacon->header.
  1207. frame_ctl)) ?
  1208. "BEACON" : "PROBE RESPONSE");
  1209. #endif
  1210. memcpy(target, &network, sizeof(*target));
  1211. list_add_tail(&target->list, &ieee->network_list);
  1212. } else {
  1213. IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
  1214. escape_essid(target->ssid,
  1215. target->ssid_len),
  1216. MAC_ARG(target->bssid),
  1217. is_beacon(le16_to_cpu
  1218. (beacon->header.
  1219. frame_ctl)) ?
  1220. "BEACON" : "PROBE RESPONSE");
  1221. update_network(target, &network);
  1222. }
  1223. spin_unlock_irqrestore(&ieee->lock, flags);
  1224. if (is_beacon(le16_to_cpu(beacon->header.frame_ctl))) {
  1225. if (ieee->handle_beacon != NULL)
  1226. ieee->handle_beacon(dev, beacon, &network);
  1227. } else {
  1228. if (ieee->handle_probe_response != NULL)
  1229. ieee->handle_probe_response(dev, beacon, &network);
  1230. }
  1231. }
  1232. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1233. struct ieee80211_hdr_4addr *header,
  1234. struct ieee80211_rx_stats *stats)
  1235. {
  1236. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1237. case IEEE80211_STYPE_ASSOC_RESP:
  1238. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1239. WLAN_FC_GET_STYPE(le16_to_cpu
  1240. (header->frame_ctl)));
  1241. ieee80211_handle_assoc_resp(ieee,
  1242. (struct ieee80211_assoc_response *)
  1243. header, stats);
  1244. break;
  1245. case IEEE80211_STYPE_REASSOC_RESP:
  1246. IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1247. WLAN_FC_GET_STYPE(le16_to_cpu
  1248. (header->frame_ctl)));
  1249. break;
  1250. case IEEE80211_STYPE_PROBE_REQ:
  1251. IEEE80211_DEBUG_MGMT("recieved auth (%d)\n",
  1252. WLAN_FC_GET_STYPE(le16_to_cpu
  1253. (header->frame_ctl)));
  1254. if (ieee->handle_probe_request != NULL)
  1255. ieee->handle_probe_request(ieee->dev,
  1256. (struct
  1257. ieee80211_probe_request *)
  1258. header, stats);
  1259. break;
  1260. case IEEE80211_STYPE_PROBE_RESP:
  1261. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1262. WLAN_FC_GET_STYPE(le16_to_cpu
  1263. (header->frame_ctl)));
  1264. IEEE80211_DEBUG_SCAN("Probe response\n");
  1265. ieee80211_process_probe_response(ieee,
  1266. (struct
  1267. ieee80211_probe_response *)
  1268. header, stats);
  1269. break;
  1270. case IEEE80211_STYPE_BEACON:
  1271. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1272. WLAN_FC_GET_STYPE(le16_to_cpu
  1273. (header->frame_ctl)));
  1274. IEEE80211_DEBUG_SCAN("Beacon\n");
  1275. ieee80211_process_probe_response(ieee,
  1276. (struct
  1277. ieee80211_probe_response *)
  1278. header, stats);
  1279. break;
  1280. case IEEE80211_STYPE_AUTH:
  1281. IEEE80211_DEBUG_MGMT("recieved auth (%d)\n",
  1282. WLAN_FC_GET_STYPE(le16_to_cpu
  1283. (header->frame_ctl)));
  1284. if (ieee->handle_auth != NULL)
  1285. ieee->handle_auth(ieee->dev,
  1286. (struct ieee80211_auth *)header);
  1287. break;
  1288. case IEEE80211_STYPE_DISASSOC:
  1289. if (ieee->handle_disassoc != NULL)
  1290. ieee->handle_disassoc(ieee->dev,
  1291. (struct ieee80211_disassoc *)
  1292. header);
  1293. break;
  1294. case IEEE80211_STYPE_DEAUTH:
  1295. printk("DEAUTH from AP\n");
  1296. if (ieee->handle_deauth != NULL)
  1297. ieee->handle_deauth(ieee->dev, (struct ieee80211_auth *)
  1298. header);
  1299. break;
  1300. default:
  1301. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1302. WLAN_FC_GET_STYPE(le16_to_cpu
  1303. (header->frame_ctl)));
  1304. IEEE80211_WARNING("%s: Unknown management packet: %d\n",
  1305. ieee->dev->name,
  1306. WLAN_FC_GET_STYPE(le16_to_cpu
  1307. (header->frame_ctl)));
  1308. break;
  1309. }
  1310. }
  1311. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1312. EXPORT_SYMBOL(ieee80211_rx);