ieee80211_rx.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  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. * <j@w1.fi>
  7. * Copyright (c) 2002-2003, Jouni Malinen <j@w1.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/errno.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/in6.h>
  19. #include <linux/in.h>
  20. #include <linux/ip.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/slab.h>
  27. #include <linux/tcp.h>
  28. #include <linux/types.h>
  29. #include <linux/wireless.h>
  30. #include <linux/etherdevice.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/ctype.h>
  33. #include <net/lib80211.h>
  34. #include <net/ieee80211.h>
  35. static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
  36. struct sk_buff *skb,
  37. struct ieee80211_rx_stats *rx_stats)
  38. {
  39. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  40. u16 fc = le16_to_cpu(hdr->frame_ctl);
  41. skb->dev = ieee->dev;
  42. skb_reset_mac_header(skb);
  43. skb_pull(skb, ieee80211_get_hdrlen(fc));
  44. skb->pkt_type = PACKET_OTHERHOST;
  45. skb->protocol = htons(ETH_P_80211_RAW);
  46. memset(skb->cb, 0, sizeof(skb->cb));
  47. netif_rx(skb);
  48. }
  49. /* Called only as a tasklet (software IRQ) */
  50. static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
  51. ieee80211_device
  52. *ieee,
  53. unsigned int seq,
  54. unsigned int frag,
  55. u8 * src,
  56. u8 * dst)
  57. {
  58. struct ieee80211_frag_entry *entry;
  59. int i;
  60. for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
  61. entry = &ieee->frag_cache[i];
  62. if (entry->skb != NULL &&
  63. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  64. IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
  65. "seq=%u last_frag=%u\n",
  66. entry->seq, entry->last_frag);
  67. dev_kfree_skb_any(entry->skb);
  68. entry->skb = NULL;
  69. }
  70. if (entry->skb != NULL && entry->seq == seq &&
  71. (entry->last_frag + 1 == frag || frag == -1) &&
  72. !compare_ether_addr(entry->src_addr, src) &&
  73. !compare_ether_addr(entry->dst_addr, dst))
  74. return entry;
  75. }
  76. return NULL;
  77. }
  78. /* Called only as a tasklet (software IRQ) */
  79. static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
  80. struct ieee80211_hdr_4addr *hdr)
  81. {
  82. struct sk_buff *skb = NULL;
  83. u16 sc;
  84. unsigned int frag, seq;
  85. struct ieee80211_frag_entry *entry;
  86. sc = le16_to_cpu(hdr->seq_ctl);
  87. frag = WLAN_GET_SEQ_FRAG(sc);
  88. seq = WLAN_GET_SEQ_SEQ(sc);
  89. if (frag == 0) {
  90. /* Reserve enough space to fit maximum frame length */
  91. skb = dev_alloc_skb(ieee->dev->mtu +
  92. sizeof(struct ieee80211_hdr_4addr) +
  93. 8 /* LLC */ +
  94. 2 /* alignment */ +
  95. 8 /* WEP */ + ETH_ALEN /* WDS */ );
  96. if (skb == NULL)
  97. return NULL;
  98. entry = &ieee->frag_cache[ieee->frag_next_idx];
  99. ieee->frag_next_idx++;
  100. if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
  101. ieee->frag_next_idx = 0;
  102. if (entry->skb != NULL)
  103. dev_kfree_skb_any(entry->skb);
  104. entry->first_frag_time = jiffies;
  105. entry->seq = seq;
  106. entry->last_frag = frag;
  107. entry->skb = skb;
  108. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  109. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  110. } else {
  111. /* received a fragment of a frame for which the head fragment
  112. * should have already been received */
  113. entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
  114. hdr->addr1);
  115. if (entry != NULL) {
  116. entry->last_frag = frag;
  117. skb = entry->skb;
  118. }
  119. }
  120. return skb;
  121. }
  122. /* Called only as a tasklet (software IRQ) */
  123. static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
  124. struct ieee80211_hdr_4addr *hdr)
  125. {
  126. u16 sc;
  127. unsigned int seq;
  128. struct ieee80211_frag_entry *entry;
  129. sc = le16_to_cpu(hdr->seq_ctl);
  130. seq = WLAN_GET_SEQ_SEQ(sc);
  131. entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
  132. hdr->addr1);
  133. if (entry == NULL) {
  134. IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
  135. "entry (seq=%u)\n", seq);
  136. return -1;
  137. }
  138. entry->skb = NULL;
  139. return 0;
  140. }
  141. #ifdef NOT_YET
  142. /* ieee80211_rx_frame_mgtmt
  143. *
  144. * Responsible for handling management control frames
  145. *
  146. * Called by ieee80211_rx */
  147. static int
  148. ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
  149. struct ieee80211_rx_stats *rx_stats, u16 type,
  150. u16 stype)
  151. {
  152. if (ieee->iw_mode == IW_MODE_MASTER) {
  153. printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
  154. ieee->dev->name);
  155. return 0;
  156. /*
  157. hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
  158. skb->data);*/
  159. }
  160. if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
  161. if (stype == WLAN_FC_STYPE_BEACON &&
  162. ieee->iw_mode == IW_MODE_MASTER) {
  163. struct sk_buff *skb2;
  164. /* Process beacon frames also in kernel driver to
  165. * update STA(AP) table statistics */
  166. skb2 = skb_clone(skb, GFP_ATOMIC);
  167. if (skb2)
  168. hostap_rx(skb2->dev, skb2, rx_stats);
  169. }
  170. /* send management frames to the user space daemon for
  171. * processing */
  172. ieee->apdevstats.rx_packets++;
  173. ieee->apdevstats.rx_bytes += skb->len;
  174. prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  175. return 0;
  176. }
  177. if (ieee->iw_mode == IW_MODE_MASTER) {
  178. if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
  179. printk(KERN_DEBUG "%s: unknown management frame "
  180. "(type=0x%02x, stype=0x%02x) dropped\n",
  181. skb->dev->name, type, stype);
  182. return -1;
  183. }
  184. hostap_rx(skb->dev, skb, rx_stats);
  185. return 0;
  186. }
  187. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
  188. "received in non-Host AP mode\n", skb->dev->name);
  189. return -1;
  190. }
  191. #endif
  192. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  193. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  194. static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  195. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  196. static unsigned char bridge_tunnel_header[] =
  197. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  198. /* No encapsulation header if EtherType < 0x600 (=length) */
  199. /* Called by ieee80211_rx_frame_decrypt */
  200. static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
  201. struct sk_buff *skb)
  202. {
  203. struct net_device *dev = ieee->dev;
  204. u16 fc, ethertype;
  205. struct ieee80211_hdr_3addr *hdr;
  206. u8 *pos;
  207. if (skb->len < 24)
  208. return 0;
  209. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  210. fc = le16_to_cpu(hdr->frame_ctl);
  211. /* check that the frame is unicast frame to us */
  212. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  213. IEEE80211_FCTL_TODS &&
  214. !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
  215. !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
  216. /* ToDS frame with own addr BSSID and DA */
  217. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  218. IEEE80211_FCTL_FROMDS &&
  219. !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
  220. /* FromDS frame with own addr as DA */
  221. } else
  222. return 0;
  223. if (skb->len < 24 + 8)
  224. return 0;
  225. /* check for port access entity Ethernet type */
  226. pos = skb->data + 24;
  227. ethertype = (pos[6] << 8) | pos[7];
  228. if (ethertype == ETH_P_PAE)
  229. return 1;
  230. return 0;
  231. }
  232. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  233. static int
  234. ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
  235. struct ieee80211_crypt_data *crypt)
  236. {
  237. struct ieee80211_hdr_3addr *hdr;
  238. int res, hdrlen;
  239. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  240. return 0;
  241. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  242. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  243. atomic_inc(&crypt->refcnt);
  244. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  245. atomic_dec(&crypt->refcnt);
  246. if (res < 0) {
  247. IEEE80211_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
  248. hdr->addr2, res);
  249. if (res == -2)
  250. IEEE80211_DEBUG_DROP("Decryption failed ICV "
  251. "mismatch (key %d)\n",
  252. skb->data[hdrlen + 3] >> 6);
  253. ieee->ieee_stats.rx_discards_undecryptable++;
  254. return -1;
  255. }
  256. return res;
  257. }
  258. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  259. static int
  260. ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
  261. struct sk_buff *skb, int keyidx,
  262. struct ieee80211_crypt_data *crypt)
  263. {
  264. struct ieee80211_hdr_3addr *hdr;
  265. int res, hdrlen;
  266. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  267. return 0;
  268. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  269. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  270. atomic_inc(&crypt->refcnt);
  271. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  272. atomic_dec(&crypt->refcnt);
  273. if (res < 0) {
  274. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  275. " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
  276. keyidx);
  277. return -1;
  278. }
  279. return 0;
  280. }
  281. /* All received frames are sent to this function. @skb contains the frame in
  282. * IEEE 802.11 format, i.e., in the format it was sent over air.
  283. * This function is called only as a tasklet (software IRQ). */
  284. int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
  285. struct ieee80211_rx_stats *rx_stats)
  286. {
  287. struct net_device *dev = ieee->dev;
  288. struct ieee80211_hdr_4addr *hdr;
  289. size_t hdrlen;
  290. u16 fc, type, stype, sc;
  291. struct net_device_stats *stats;
  292. unsigned int frag;
  293. u8 *payload;
  294. u16 ethertype;
  295. #ifdef NOT_YET
  296. struct net_device *wds = NULL;
  297. struct sk_buff *skb2 = NULL;
  298. struct net_device *wds = NULL;
  299. int frame_authorized = 0;
  300. int from_assoc_ap = 0;
  301. void *sta = NULL;
  302. #endif
  303. u8 dst[ETH_ALEN];
  304. u8 src[ETH_ALEN];
  305. struct ieee80211_crypt_data *crypt = NULL;
  306. int keyidx = 0;
  307. int can_be_decrypted = 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. if (skb->len < hdrlen) {
  321. printk(KERN_INFO "%s: invalid SKB length %d\n",
  322. dev->name, skb->len);
  323. goto rx_dropped;
  324. }
  325. /* Put this code here so that we avoid duplicating it in all
  326. * Rx paths. - Jean II */
  327. #ifdef CONFIG_WIRELESS_EXT
  328. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  329. /* If spy monitoring on */
  330. if (ieee->spy_data.spy_number > 0) {
  331. struct iw_quality wstats;
  332. wstats.updated = 0;
  333. if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
  334. wstats.level = rx_stats->signal;
  335. wstats.updated |= IW_QUAL_LEVEL_UPDATED;
  336. } else
  337. wstats.updated |= IW_QUAL_LEVEL_INVALID;
  338. if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
  339. wstats.noise = rx_stats->noise;
  340. wstats.updated |= IW_QUAL_NOISE_UPDATED;
  341. } else
  342. wstats.updated |= IW_QUAL_NOISE_INVALID;
  343. if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
  344. wstats.qual = rx_stats->signal;
  345. wstats.updated |= IW_QUAL_QUAL_UPDATED;
  346. } else
  347. wstats.updated |= IW_QUAL_QUAL_INVALID;
  348. /* Update spy records */
  349. wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
  350. }
  351. #endif /* IW_WIRELESS_SPY */
  352. #endif /* CONFIG_WIRELESS_EXT */
  353. #ifdef NOT_YET
  354. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  355. #endif
  356. if (ieee->iw_mode == IW_MODE_MONITOR) {
  357. stats->rx_packets++;
  358. stats->rx_bytes += skb->len;
  359. ieee80211_monitor_rx(ieee, skb, rx_stats);
  360. return 1;
  361. }
  362. can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
  363. is_broadcast_ether_addr(hdr->addr2)) ?
  364. ieee->host_mc_decrypt : ieee->host_decrypt;
  365. if (can_be_decrypted) {
  366. if (skb->len >= hdrlen + 3) {
  367. /* Top two-bits of byte 3 are the key index */
  368. keyidx = skb->data[hdrlen + 3] >> 6;
  369. }
  370. /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
  371. * is only allowed 2-bits of storage, no value of keyidx can
  372. * be provided via above code that would result in keyidx
  373. * being out of range */
  374. crypt = ieee->crypt[keyidx];
  375. #ifdef NOT_YET
  376. sta = NULL;
  377. /* Use station specific key to override default keys if the
  378. * receiver address is a unicast address ("individual RA"). If
  379. * bcrx_sta_key parameter is set, station specific key is used
  380. * even with broad/multicast targets (this is against IEEE
  381. * 802.11, but makes it easier to use different keys with
  382. * stations that do not support WEP key mapping). */
  383. if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
  384. (void)hostap_handle_sta_crypto(local, hdr, &crypt,
  385. &sta);
  386. #endif
  387. /* allow NULL decrypt to indicate an station specific override
  388. * for default encryption */
  389. if (crypt && (crypt->ops == NULL ||
  390. crypt->ops->decrypt_mpdu == NULL))
  391. crypt = NULL;
  392. if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
  393. /* This seems to be triggered by some (multicast?)
  394. * frames from other than current BSS, so just drop the
  395. * frames silently instead of filling system log with
  396. * these reports. */
  397. IEEE80211_DEBUG_DROP("Decryption failed (not set)"
  398. " (SA=%pM)\n", hdr->addr2);
  399. ieee->ieee_stats.rx_discards_undecryptable++;
  400. goto rx_dropped;
  401. }
  402. }
  403. #ifdef NOT_YET
  404. if (type != WLAN_FC_TYPE_DATA) {
  405. if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
  406. fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
  407. (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
  408. printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
  409. "from %pM\n", dev->name, hdr->addr2);
  410. /* TODO: could inform hostapd about this so that it
  411. * could send auth failure report */
  412. goto rx_dropped;
  413. }
  414. if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
  415. goto rx_dropped;
  416. else
  417. goto rx_exit;
  418. }
  419. #endif
  420. /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
  421. if (sc == ieee->prev_seq_ctl)
  422. goto rx_dropped;
  423. else
  424. ieee->prev_seq_ctl = sc;
  425. /* Data frame - extract src/dst addresses */
  426. if (skb->len < IEEE80211_3ADDR_LEN)
  427. goto rx_dropped;
  428. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  429. case IEEE80211_FCTL_FROMDS:
  430. memcpy(dst, hdr->addr1, ETH_ALEN);
  431. memcpy(src, hdr->addr3, ETH_ALEN);
  432. break;
  433. case IEEE80211_FCTL_TODS:
  434. memcpy(dst, hdr->addr3, ETH_ALEN);
  435. memcpy(src, hdr->addr2, ETH_ALEN);
  436. break;
  437. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  438. if (skb->len < IEEE80211_4ADDR_LEN)
  439. goto rx_dropped;
  440. memcpy(dst, hdr->addr3, ETH_ALEN);
  441. memcpy(src, hdr->addr4, ETH_ALEN);
  442. break;
  443. case 0:
  444. memcpy(dst, hdr->addr1, ETH_ALEN);
  445. memcpy(src, hdr->addr2, ETH_ALEN);
  446. break;
  447. }
  448. #ifdef NOT_YET
  449. if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
  450. goto rx_dropped;
  451. if (wds) {
  452. skb->dev = dev = wds;
  453. stats = hostap_get_stats(dev);
  454. }
  455. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  456. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  457. IEEE80211_FCTL_FROMDS && ieee->stadev
  458. && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
  459. /* Frame from BSSID of the AP for which we are a client */
  460. skb->dev = dev = ieee->stadev;
  461. stats = hostap_get_stats(dev);
  462. from_assoc_ap = 1;
  463. }
  464. #endif
  465. dev->last_rx = jiffies;
  466. #ifdef NOT_YET
  467. if ((ieee->iw_mode == IW_MODE_MASTER ||
  468. ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
  469. switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
  470. wds != NULL)) {
  471. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  472. frame_authorized = 0;
  473. break;
  474. case AP_RX_CONTINUE:
  475. frame_authorized = 1;
  476. break;
  477. case AP_RX_DROP:
  478. goto rx_dropped;
  479. case AP_RX_EXIT:
  480. goto rx_exit;
  481. }
  482. }
  483. #endif
  484. /* Nullfunc frames may have PS-bit set, so they must be passed to
  485. * hostap_handle_sta_rx() before being dropped here. */
  486. stype &= ~IEEE80211_STYPE_QOS_DATA;
  487. if (stype != IEEE80211_STYPE_DATA &&
  488. stype != IEEE80211_STYPE_DATA_CFACK &&
  489. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  490. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  491. if (stype != IEEE80211_STYPE_NULLFUNC)
  492. IEEE80211_DEBUG_DROP("RX: dropped data frame "
  493. "with no data (type=0x%02x, "
  494. "subtype=0x%02x, len=%d)\n",
  495. type, stype, skb->len);
  496. goto rx_dropped;
  497. }
  498. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  499. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  500. (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  501. goto rx_dropped;
  502. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  503. /* skb: hdr + (possibly fragmented) plaintext payload */
  504. // PR: FIXME: hostap has additional conditions in the "if" below:
  505. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  506. if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
  507. int flen;
  508. struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
  509. IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  510. if (!frag_skb) {
  511. IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
  512. "Rx cannot get skb from fragment "
  513. "cache (morefrag=%d seq=%u frag=%u)\n",
  514. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  515. WLAN_GET_SEQ_SEQ(sc), frag);
  516. goto rx_dropped;
  517. }
  518. flen = skb->len;
  519. if (frag != 0)
  520. flen -= hdrlen;
  521. if (frag_skb->tail + flen > frag_skb->end) {
  522. printk(KERN_WARNING "%s: host decrypted and "
  523. "reassembled frame did not fit skb\n",
  524. dev->name);
  525. ieee80211_frag_cache_invalidate(ieee, hdr);
  526. goto rx_dropped;
  527. }
  528. if (frag == 0) {
  529. /* copy first fragment (including full headers) into
  530. * beginning of the fragment cache skb */
  531. skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
  532. } else {
  533. /* append frame payload to the end of the fragment
  534. * cache skb */
  535. skb_copy_from_linear_data_offset(skb, hdrlen,
  536. skb_put(frag_skb, flen), flen);
  537. }
  538. dev_kfree_skb_any(skb);
  539. skb = NULL;
  540. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  541. /* more fragments expected - leave the skb in fragment
  542. * cache for now; it will be delivered to upper layers
  543. * after all fragments have been received */
  544. goto rx_exit;
  545. }
  546. /* this was the last fragment and the frame will be
  547. * delivered, so remove skb from fragment cache */
  548. skb = frag_skb;
  549. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  550. ieee80211_frag_cache_invalidate(ieee, hdr);
  551. }
  552. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  553. * encrypted/authenticated */
  554. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  555. ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  556. goto rx_dropped;
  557. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  558. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  559. if ( /*ieee->ieee802_1x && */
  560. ieee80211_is_eapol_frame(ieee, skb)) {
  561. /* pass unencrypted EAPOL frames even if encryption is
  562. * configured */
  563. } else {
  564. IEEE80211_DEBUG_DROP("encryption configured, but RX "
  565. "frame not encrypted (SA=%pM)\n",
  566. hdr->addr2);
  567. goto rx_dropped;
  568. }
  569. }
  570. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  571. !ieee80211_is_eapol_frame(ieee, skb)) {
  572. IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
  573. "frame from %pM (drop_unencrypted=1)\n",
  574. hdr->addr2);
  575. goto rx_dropped;
  576. }
  577. /* If the frame was decrypted in hardware, we may need to strip off
  578. * any security data (IV, ICV, etc) that was left behind */
  579. if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
  580. ieee->host_strip_iv_icv) {
  581. int trimlen = 0;
  582. /* Top two-bits of byte 3 are the key index */
  583. if (skb->len >= hdrlen + 3)
  584. keyidx = skb->data[hdrlen + 3] >> 6;
  585. /* To strip off any security data which appears before the
  586. * payload, we simply increase hdrlen (as the header gets
  587. * chopped off immediately below). For the security data which
  588. * appears after the payload, we use skb_trim. */
  589. switch (ieee->sec.encode_alg[keyidx]) {
  590. case SEC_ALG_WEP:
  591. /* 4 byte IV */
  592. hdrlen += 4;
  593. /* 4 byte ICV */
  594. trimlen = 4;
  595. break;
  596. case SEC_ALG_TKIP:
  597. /* 4 byte IV, 4 byte ExtIV */
  598. hdrlen += 8;
  599. /* 8 byte MIC, 4 byte ICV */
  600. trimlen = 12;
  601. break;
  602. case SEC_ALG_CCMP:
  603. /* 8 byte CCMP header */
  604. hdrlen += 8;
  605. /* 8 byte MIC */
  606. trimlen = 8;
  607. break;
  608. }
  609. if (skb->len < trimlen)
  610. goto rx_dropped;
  611. __skb_trim(skb, skb->len - trimlen);
  612. if (skb->len < hdrlen)
  613. goto rx_dropped;
  614. }
  615. /* skb: hdr + (possible reassembled) full plaintext payload */
  616. payload = skb->data + hdrlen;
  617. ethertype = (payload[6] << 8) | payload[7];
  618. #ifdef NOT_YET
  619. /* If IEEE 802.1X is used, check whether the port is authorized to send
  620. * the received frame. */
  621. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  622. if (ethertype == ETH_P_PAE) {
  623. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  624. dev->name);
  625. if (ieee->hostapd && ieee->apdev) {
  626. /* Send IEEE 802.1X frames to the user
  627. * space daemon for processing */
  628. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  629. PRISM2_RX_MGMT);
  630. ieee->apdevstats.rx_packets++;
  631. ieee->apdevstats.rx_bytes += skb->len;
  632. goto rx_exit;
  633. }
  634. } else if (!frame_authorized) {
  635. printk(KERN_DEBUG "%s: dropped frame from "
  636. "unauthorized port (IEEE 802.1X): "
  637. "ethertype=0x%04x\n", dev->name, ethertype);
  638. goto rx_dropped;
  639. }
  640. }
  641. #endif
  642. /* convert hdr + possible LLC headers into Ethernet header */
  643. if (skb->len - hdrlen >= 8 &&
  644. ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
  645. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  646. memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
  647. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  648. * replace EtherType */
  649. skb_pull(skb, hdrlen + SNAP_SIZE);
  650. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  651. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  652. } else {
  653. __be16 len;
  654. /* Leave Ethernet header part of hdr and full payload */
  655. skb_pull(skb, hdrlen);
  656. len = htons(skb->len);
  657. memcpy(skb_push(skb, 2), &len, 2);
  658. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  659. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  660. }
  661. #ifdef NOT_YET
  662. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  663. IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
  664. /* Non-standard frame: get addr4 from its bogus location after
  665. * the payload */
  666. skb_copy_to_linear_data_offset(skb, ETH_ALEN,
  667. skb->data + skb->len - ETH_ALEN,
  668. ETH_ALEN);
  669. skb_trim(skb, skb->len - ETH_ALEN);
  670. }
  671. #endif
  672. stats->rx_packets++;
  673. stats->rx_bytes += skb->len;
  674. #ifdef NOT_YET
  675. if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
  676. if (dst[0] & 0x01) {
  677. /* copy multicast frame both to the higher layers and
  678. * to the wireless media */
  679. ieee->ap->bridged_multicast++;
  680. skb2 = skb_clone(skb, GFP_ATOMIC);
  681. if (skb2 == NULL)
  682. printk(KERN_DEBUG "%s: skb_clone failed for "
  683. "multicast frame\n", dev->name);
  684. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  685. /* send frame directly to the associated STA using
  686. * wireless media and not passing to higher layers */
  687. ieee->ap->bridged_unicast++;
  688. skb2 = skb;
  689. skb = NULL;
  690. }
  691. }
  692. if (skb2 != NULL) {
  693. /* send to wireless media */
  694. skb2->dev = dev;
  695. skb2->protocol = htons(ETH_P_802_3);
  696. skb_reset_mac_header(skb2);
  697. skb_reset_network_header(skb2);
  698. /* skb2->network_header += ETH_HLEN; */
  699. dev_queue_xmit(skb2);
  700. }
  701. #endif
  702. if (skb) {
  703. skb->protocol = eth_type_trans(skb, dev);
  704. memset(skb->cb, 0, sizeof(skb->cb));
  705. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  706. if (netif_rx(skb) == NET_RX_DROP) {
  707. /* netif_rx always succeeds, but it might drop
  708. * the packet. If it drops the packet, we log that
  709. * in our stats. */
  710. IEEE80211_DEBUG_DROP
  711. ("RX: netif_rx dropped the packet\n");
  712. stats->rx_dropped++;
  713. }
  714. }
  715. rx_exit:
  716. #ifdef NOT_YET
  717. if (sta)
  718. hostap_handle_sta_release(sta);
  719. #endif
  720. return 1;
  721. rx_dropped:
  722. stats->rx_dropped++;
  723. /* Returning 0 indicates to caller that we have not handled the SKB--
  724. * so it is still allocated and can be used again by underlying
  725. * hardware as a DMA target */
  726. return 0;
  727. }
  728. /* Filter out unrelated packets, call ieee80211_rx[_mgt]
  729. * This function takes over the skb, it should not be used again after calling
  730. * this function. */
  731. void ieee80211_rx_any(struct ieee80211_device *ieee,
  732. struct sk_buff *skb, struct ieee80211_rx_stats *stats)
  733. {
  734. struct ieee80211_hdr_4addr *hdr;
  735. int is_packet_for_us;
  736. u16 fc;
  737. if (ieee->iw_mode == IW_MODE_MONITOR) {
  738. if (!ieee80211_rx(ieee, skb, stats))
  739. dev_kfree_skb_irq(skb);
  740. return;
  741. }
  742. if (skb->len < sizeof(struct ieee80211_hdr))
  743. goto drop_free;
  744. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  745. fc = le16_to_cpu(hdr->frame_ctl);
  746. if ((fc & IEEE80211_FCTL_VERS) != 0)
  747. goto drop_free;
  748. switch (fc & IEEE80211_FCTL_FTYPE) {
  749. case IEEE80211_FTYPE_MGMT:
  750. if (skb->len < sizeof(struct ieee80211_hdr_3addr))
  751. goto drop_free;
  752. ieee80211_rx_mgt(ieee, hdr, stats);
  753. dev_kfree_skb_irq(skb);
  754. return;
  755. case IEEE80211_FTYPE_DATA:
  756. break;
  757. case IEEE80211_FTYPE_CTL:
  758. return;
  759. default:
  760. return;
  761. }
  762. is_packet_for_us = 0;
  763. switch (ieee->iw_mode) {
  764. case IW_MODE_ADHOC:
  765. /* our BSS and not from/to DS */
  766. if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
  767. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
  768. /* promisc: get all */
  769. if (ieee->dev->flags & IFF_PROMISC)
  770. is_packet_for_us = 1;
  771. /* to us */
  772. else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
  773. is_packet_for_us = 1;
  774. /* mcast */
  775. else if (is_multicast_ether_addr(hdr->addr1))
  776. is_packet_for_us = 1;
  777. }
  778. break;
  779. case IW_MODE_INFRA:
  780. /* our BSS (== from our AP) and from DS */
  781. if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
  782. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
  783. /* promisc: get all */
  784. if (ieee->dev->flags & IFF_PROMISC)
  785. is_packet_for_us = 1;
  786. /* to us */
  787. else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
  788. is_packet_for_us = 1;
  789. /* mcast */
  790. else if (is_multicast_ether_addr(hdr->addr1)) {
  791. /* not our own packet bcasted from AP */
  792. if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
  793. is_packet_for_us = 1;
  794. }
  795. }
  796. break;
  797. default:
  798. /* ? */
  799. break;
  800. }
  801. if (is_packet_for_us)
  802. if (!ieee80211_rx(ieee, skb, stats))
  803. dev_kfree_skb_irq(skb);
  804. return;
  805. drop_free:
  806. dev_kfree_skb_irq(skb);
  807. ieee->stats.rx_dropped++;
  808. return;
  809. }
  810. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  811. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  812. /*
  813. * Make ther structure we read from the beacon packet has
  814. * the right values
  815. */
  816. static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
  817. *info_element, int sub_type)
  818. {
  819. if (info_element->qui_subtype != sub_type)
  820. return -1;
  821. if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
  822. return -1;
  823. if (info_element->qui_type != QOS_OUI_TYPE)
  824. return -1;
  825. if (info_element->version != QOS_VERSION_1)
  826. return -1;
  827. return 0;
  828. }
  829. /*
  830. * Parse a QoS parameter element
  831. */
  832. static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
  833. *element_param, struct ieee80211_info_element
  834. *info_element)
  835. {
  836. int ret = 0;
  837. u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
  838. if ((info_element == NULL) || (element_param == NULL))
  839. return -1;
  840. if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
  841. memcpy(element_param->info_element.qui, info_element->data,
  842. info_element->len);
  843. element_param->info_element.elementID = info_element->id;
  844. element_param->info_element.length = info_element->len;
  845. } else
  846. ret = -1;
  847. if (ret == 0)
  848. ret = ieee80211_verify_qos_info(&element_param->info_element,
  849. QOS_OUI_PARAM_SUB_TYPE);
  850. return ret;
  851. }
  852. /*
  853. * Parse a QoS information element
  854. */
  855. static int ieee80211_read_qos_info_element(struct
  856. ieee80211_qos_information_element
  857. *element_info, struct ieee80211_info_element
  858. *info_element)
  859. {
  860. int ret = 0;
  861. u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
  862. if (element_info == NULL)
  863. return -1;
  864. if (info_element == NULL)
  865. return -1;
  866. if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
  867. memcpy(element_info->qui, info_element->data,
  868. info_element->len);
  869. element_info->elementID = info_element->id;
  870. element_info->length = info_element->len;
  871. } else
  872. ret = -1;
  873. if (ret == 0)
  874. ret = ieee80211_verify_qos_info(element_info,
  875. QOS_OUI_INFO_SUB_TYPE);
  876. return ret;
  877. }
  878. /*
  879. * Write QoS parameters from the ac parameters.
  880. */
  881. static int ieee80211_qos_convert_ac_to_parameters(struct
  882. ieee80211_qos_parameter_info
  883. *param_elm, struct
  884. ieee80211_qos_parameters
  885. *qos_param)
  886. {
  887. int rc = 0;
  888. int i;
  889. struct ieee80211_qos_ac_parameter *ac_params;
  890. u32 txop;
  891. u8 cw_min;
  892. u8 cw_max;
  893. for (i = 0; i < QOS_QUEUE_NUM; i++) {
  894. ac_params = &(param_elm->ac_params_record[i]);
  895. qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
  896. qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
  897. cw_min = ac_params->ecw_min_max & 0x0F;
  898. qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
  899. cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
  900. qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
  901. qos_param->flag[i] =
  902. (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
  903. txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
  904. qos_param->tx_op_limit[i] = cpu_to_le16(txop);
  905. }
  906. return rc;
  907. }
  908. /*
  909. * we have a generic data element which it may contain QoS information or
  910. * parameters element. check the information element length to decide
  911. * which type to read
  912. */
  913. static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
  914. *info_element,
  915. struct ieee80211_network *network)
  916. {
  917. int rc = 0;
  918. struct ieee80211_qos_parameters *qos_param = NULL;
  919. struct ieee80211_qos_information_element qos_info_element;
  920. rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
  921. if (rc == 0) {
  922. network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
  923. network->flags |= NETWORK_HAS_QOS_INFORMATION;
  924. } else {
  925. struct ieee80211_qos_parameter_info param_element;
  926. rc = ieee80211_read_qos_param_element(&param_element,
  927. info_element);
  928. if (rc == 0) {
  929. qos_param = &(network->qos_data.parameters);
  930. ieee80211_qos_convert_ac_to_parameters(&param_element,
  931. qos_param);
  932. network->flags |= NETWORK_HAS_QOS_PARAMETERS;
  933. network->qos_data.param_count =
  934. param_element.info_element.ac_info & 0x0F;
  935. }
  936. }
  937. if (rc == 0) {
  938. IEEE80211_DEBUG_QOS("QoS is supported\n");
  939. network->qos_data.supported = 1;
  940. }
  941. return rc;
  942. }
  943. #ifdef CONFIG_IEEE80211_DEBUG
  944. #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
  945. static const char *get_info_element_string(u16 id)
  946. {
  947. switch (id) {
  948. MFIE_STRING(SSID);
  949. MFIE_STRING(RATES);
  950. MFIE_STRING(FH_SET);
  951. MFIE_STRING(DS_SET);
  952. MFIE_STRING(CF_SET);
  953. MFIE_STRING(TIM);
  954. MFIE_STRING(IBSS_SET);
  955. MFIE_STRING(COUNTRY);
  956. MFIE_STRING(HOP_PARAMS);
  957. MFIE_STRING(HOP_TABLE);
  958. MFIE_STRING(REQUEST);
  959. MFIE_STRING(CHALLENGE);
  960. MFIE_STRING(POWER_CONSTRAINT);
  961. MFIE_STRING(POWER_CAPABILITY);
  962. MFIE_STRING(TPC_REQUEST);
  963. MFIE_STRING(TPC_REPORT);
  964. MFIE_STRING(SUPP_CHANNELS);
  965. MFIE_STRING(CSA);
  966. MFIE_STRING(MEASURE_REQUEST);
  967. MFIE_STRING(MEASURE_REPORT);
  968. MFIE_STRING(QUIET);
  969. MFIE_STRING(IBSS_DFS);
  970. MFIE_STRING(ERP_INFO);
  971. MFIE_STRING(RSN);
  972. MFIE_STRING(RATES_EX);
  973. MFIE_STRING(GENERIC);
  974. MFIE_STRING(QOS_PARAMETER);
  975. default:
  976. return "UNKNOWN";
  977. }
  978. }
  979. #endif
  980. static int ieee80211_parse_info_param(struct ieee80211_info_element
  981. *info_element, u16 length,
  982. struct ieee80211_network *network)
  983. {
  984. DECLARE_SSID_BUF(ssid);
  985. u8 i;
  986. #ifdef CONFIG_IEEE80211_DEBUG
  987. char rates_str[64];
  988. char *p;
  989. #endif
  990. while (length >= sizeof(*info_element)) {
  991. if (sizeof(*info_element) + info_element->len > length) {
  992. IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
  993. "info_element->len + 2 > left : "
  994. "info_element->len+2=%zd left=%d, id=%d.\n",
  995. info_element->len +
  996. sizeof(*info_element),
  997. length, info_element->id);
  998. /* We stop processing but don't return an error here
  999. * because some misbehaviour APs break this rule. ie.
  1000. * Orinoco AP1000. */
  1001. break;
  1002. }
  1003. switch (info_element->id) {
  1004. case MFIE_TYPE_SSID:
  1005. network->ssid_len = min(info_element->len,
  1006. (u8) IW_ESSID_MAX_SIZE);
  1007. memcpy(network->ssid, info_element->data,
  1008. network->ssid_len);
  1009. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  1010. memset(network->ssid + network->ssid_len, 0,
  1011. IW_ESSID_MAX_SIZE - network->ssid_len);
  1012. IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
  1013. print_ssid(ssid, network->ssid,
  1014. network->ssid_len),
  1015. network->ssid_len);
  1016. break;
  1017. case MFIE_TYPE_RATES:
  1018. #ifdef CONFIG_IEEE80211_DEBUG
  1019. p = rates_str;
  1020. #endif
  1021. network->rates_len = min(info_element->len,
  1022. MAX_RATES_LENGTH);
  1023. for (i = 0; i < network->rates_len; i++) {
  1024. network->rates[i] = info_element->data[i];
  1025. #ifdef CONFIG_IEEE80211_DEBUG
  1026. p += snprintf(p, sizeof(rates_str) -
  1027. (p - rates_str), "%02X ",
  1028. network->rates[i]);
  1029. #endif
  1030. if (ieee80211_is_ofdm_rate
  1031. (info_element->data[i])) {
  1032. network->flags |= NETWORK_HAS_OFDM;
  1033. if (info_element->data[i] &
  1034. IEEE80211_BASIC_RATE_MASK)
  1035. network->flags &=
  1036. ~NETWORK_HAS_CCK;
  1037. }
  1038. }
  1039. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
  1040. rates_str, network->rates_len);
  1041. break;
  1042. case MFIE_TYPE_RATES_EX:
  1043. #ifdef CONFIG_IEEE80211_DEBUG
  1044. p = rates_str;
  1045. #endif
  1046. network->rates_ex_len = min(info_element->len,
  1047. MAX_RATES_EX_LENGTH);
  1048. for (i = 0; i < network->rates_ex_len; i++) {
  1049. network->rates_ex[i] = info_element->data[i];
  1050. #ifdef CONFIG_IEEE80211_DEBUG
  1051. p += snprintf(p, sizeof(rates_str) -
  1052. (p - rates_str), "%02X ",
  1053. network->rates[i]);
  1054. #endif
  1055. if (ieee80211_is_ofdm_rate
  1056. (info_element->data[i])) {
  1057. network->flags |= NETWORK_HAS_OFDM;
  1058. if (info_element->data[i] &
  1059. IEEE80211_BASIC_RATE_MASK)
  1060. network->flags &=
  1061. ~NETWORK_HAS_CCK;
  1062. }
  1063. }
  1064. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
  1065. rates_str, network->rates_ex_len);
  1066. break;
  1067. case MFIE_TYPE_DS_SET:
  1068. IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
  1069. info_element->data[0]);
  1070. network->channel = info_element->data[0];
  1071. break;
  1072. case MFIE_TYPE_FH_SET:
  1073. IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
  1074. break;
  1075. case MFIE_TYPE_CF_SET:
  1076. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
  1077. break;
  1078. case MFIE_TYPE_TIM:
  1079. network->tim.tim_count = info_element->data[0];
  1080. network->tim.tim_period = info_element->data[1];
  1081. IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
  1082. break;
  1083. case MFIE_TYPE_ERP_INFO:
  1084. network->erp_value = info_element->data[0];
  1085. network->flags |= NETWORK_HAS_ERP_VALUE;
  1086. IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
  1087. network->erp_value);
  1088. break;
  1089. case MFIE_TYPE_IBSS_SET:
  1090. network->atim_window = info_element->data[0];
  1091. IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
  1092. network->atim_window);
  1093. break;
  1094. case MFIE_TYPE_CHALLENGE:
  1095. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
  1096. break;
  1097. case MFIE_TYPE_GENERIC:
  1098. IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
  1099. info_element->len);
  1100. if (!ieee80211_parse_qos_info_param_IE(info_element,
  1101. network))
  1102. break;
  1103. if (info_element->len >= 4 &&
  1104. info_element->data[0] == 0x00 &&
  1105. info_element->data[1] == 0x50 &&
  1106. info_element->data[2] == 0xf2 &&
  1107. info_element->data[3] == 0x01) {
  1108. network->wpa_ie_len = min(info_element->len + 2,
  1109. MAX_WPA_IE_LEN);
  1110. memcpy(network->wpa_ie, info_element,
  1111. network->wpa_ie_len);
  1112. }
  1113. break;
  1114. case MFIE_TYPE_RSN:
  1115. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
  1116. info_element->len);
  1117. network->rsn_ie_len = min(info_element->len + 2,
  1118. MAX_WPA_IE_LEN);
  1119. memcpy(network->rsn_ie, info_element,
  1120. network->rsn_ie_len);
  1121. break;
  1122. case MFIE_TYPE_QOS_PARAMETER:
  1123. printk(KERN_ERR
  1124. "QoS Error need to parse QOS_PARAMETER IE\n");
  1125. break;
  1126. /* 802.11h */
  1127. case MFIE_TYPE_POWER_CONSTRAINT:
  1128. network->power_constraint = info_element->data[0];
  1129. network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
  1130. break;
  1131. case MFIE_TYPE_CSA:
  1132. network->power_constraint = info_element->data[0];
  1133. network->flags |= NETWORK_HAS_CSA;
  1134. break;
  1135. case MFIE_TYPE_QUIET:
  1136. network->quiet.count = info_element->data[0];
  1137. network->quiet.period = info_element->data[1];
  1138. network->quiet.duration = info_element->data[2];
  1139. network->quiet.offset = info_element->data[3];
  1140. network->flags |= NETWORK_HAS_QUIET;
  1141. break;
  1142. case MFIE_TYPE_IBSS_DFS:
  1143. if (network->ibss_dfs)
  1144. break;
  1145. network->ibss_dfs = kmemdup(info_element->data,
  1146. info_element->len,
  1147. GFP_ATOMIC);
  1148. if (!network->ibss_dfs)
  1149. return 1;
  1150. network->flags |= NETWORK_HAS_IBSS_DFS;
  1151. break;
  1152. case MFIE_TYPE_TPC_REPORT:
  1153. network->tpc_report.transmit_power =
  1154. info_element->data[0];
  1155. network->tpc_report.link_margin = info_element->data[1];
  1156. network->flags |= NETWORK_HAS_TPC_REPORT;
  1157. break;
  1158. default:
  1159. IEEE80211_DEBUG_MGMT
  1160. ("Unsupported info element: %s (%d)\n",
  1161. get_info_element_string(info_element->id),
  1162. info_element->id);
  1163. break;
  1164. }
  1165. length -= sizeof(*info_element) + info_element->len;
  1166. info_element =
  1167. (struct ieee80211_info_element *)&info_element->
  1168. data[info_element->len];
  1169. }
  1170. return 0;
  1171. }
  1172. static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
  1173. *frame, struct ieee80211_rx_stats *stats)
  1174. {
  1175. struct ieee80211_network network_resp = {
  1176. .ibss_dfs = NULL,
  1177. };
  1178. struct ieee80211_network *network = &network_resp;
  1179. struct net_device *dev = ieee->dev;
  1180. network->flags = 0;
  1181. network->qos_data.active = 0;
  1182. network->qos_data.supported = 0;
  1183. network->qos_data.param_count = 0;
  1184. network->qos_data.old_param_count = 0;
  1185. //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
  1186. network->atim_window = le16_to_cpu(frame->aid);
  1187. network->listen_interval = le16_to_cpu(frame->status);
  1188. memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
  1189. network->capability = le16_to_cpu(frame->capability);
  1190. network->last_scanned = jiffies;
  1191. network->rates_len = network->rates_ex_len = 0;
  1192. network->last_associate = 0;
  1193. network->ssid_len = 0;
  1194. network->erp_value =
  1195. (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
  1196. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1197. /* for A band (No DS info) */
  1198. network->channel = stats->received_channel;
  1199. } else
  1200. network->flags |= NETWORK_HAS_CCK;
  1201. network->wpa_ie_len = 0;
  1202. network->rsn_ie_len = 0;
  1203. if (ieee80211_parse_info_param
  1204. (frame->info_element, stats->len - sizeof(*frame), network))
  1205. return 1;
  1206. network->mode = 0;
  1207. if (stats->freq == IEEE80211_52GHZ_BAND)
  1208. network->mode = IEEE_A;
  1209. else {
  1210. if (network->flags & NETWORK_HAS_OFDM)
  1211. network->mode |= IEEE_G;
  1212. if (network->flags & NETWORK_HAS_CCK)
  1213. network->mode |= IEEE_B;
  1214. }
  1215. memcpy(&network->stats, stats, sizeof(network->stats));
  1216. if (ieee->handle_assoc_response != NULL)
  1217. ieee->handle_assoc_response(dev, frame, network);
  1218. return 0;
  1219. }
  1220. /***************************************************/
  1221. static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
  1222. *beacon,
  1223. struct ieee80211_network *network,
  1224. struct ieee80211_rx_stats *stats)
  1225. {
  1226. DECLARE_SSID_BUF(ssid);
  1227. network->qos_data.active = 0;
  1228. network->qos_data.supported = 0;
  1229. network->qos_data.param_count = 0;
  1230. network->qos_data.old_param_count = 0;
  1231. /* Pull out fixed field data */
  1232. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  1233. network->capability = le16_to_cpu(beacon->capability);
  1234. network->last_scanned = jiffies;
  1235. network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
  1236. network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
  1237. network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
  1238. /* Where to pull this? beacon->listen_interval; */
  1239. network->listen_interval = 0x0A;
  1240. network->rates_len = network->rates_ex_len = 0;
  1241. network->last_associate = 0;
  1242. network->ssid_len = 0;
  1243. network->flags = 0;
  1244. network->atim_window = 0;
  1245. network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
  1246. 0x3 : 0x0;
  1247. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1248. /* for A band (No DS info) */
  1249. network->channel = stats->received_channel;
  1250. } else
  1251. network->flags |= NETWORK_HAS_CCK;
  1252. network->wpa_ie_len = 0;
  1253. network->rsn_ie_len = 0;
  1254. if (ieee80211_parse_info_param
  1255. (beacon->info_element, stats->len - sizeof(*beacon), network))
  1256. return 1;
  1257. network->mode = 0;
  1258. if (stats->freq == IEEE80211_52GHZ_BAND)
  1259. network->mode = IEEE_A;
  1260. else {
  1261. if (network->flags & NETWORK_HAS_OFDM)
  1262. network->mode |= IEEE_G;
  1263. if (network->flags & NETWORK_HAS_CCK)
  1264. network->mode |= IEEE_B;
  1265. }
  1266. if (network->mode == 0) {
  1267. IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' "
  1268. "network.\n",
  1269. print_ssid(ssid, network->ssid,
  1270. network->ssid_len),
  1271. network->bssid);
  1272. return 1;
  1273. }
  1274. memcpy(&network->stats, stats, sizeof(network->stats));
  1275. return 0;
  1276. }
  1277. static inline int is_same_network(struct ieee80211_network *src,
  1278. struct ieee80211_network *dst)
  1279. {
  1280. /* A network is only a duplicate if the channel, BSSID, and ESSID
  1281. * all match. We treat all <hidden> with the same BSSID and channel
  1282. * as one network */
  1283. return ((src->ssid_len == dst->ssid_len) &&
  1284. (src->channel == dst->channel) &&
  1285. !compare_ether_addr(src->bssid, dst->bssid) &&
  1286. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  1287. }
  1288. static void update_network(struct ieee80211_network *dst,
  1289. struct ieee80211_network *src)
  1290. {
  1291. int qos_active;
  1292. u8 old_param;
  1293. ieee80211_network_reset(dst);
  1294. dst->ibss_dfs = src->ibss_dfs;
  1295. /* We only update the statistics if they were created by receiving
  1296. * the network information on the actual channel the network is on.
  1297. *
  1298. * This keeps beacons received on neighbor channels from bringing
  1299. * down the signal level of an AP. */
  1300. if (dst->channel == src->stats.received_channel)
  1301. memcpy(&dst->stats, &src->stats,
  1302. sizeof(struct ieee80211_rx_stats));
  1303. else
  1304. IEEE80211_DEBUG_SCAN("Network %pM info received "
  1305. "off channel (%d vs. %d)\n", src->bssid,
  1306. dst->channel, src->stats.received_channel);
  1307. dst->capability = src->capability;
  1308. memcpy(dst->rates, src->rates, src->rates_len);
  1309. dst->rates_len = src->rates_len;
  1310. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  1311. dst->rates_ex_len = src->rates_ex_len;
  1312. dst->mode = src->mode;
  1313. dst->flags = src->flags;
  1314. dst->time_stamp[0] = src->time_stamp[0];
  1315. dst->time_stamp[1] = src->time_stamp[1];
  1316. dst->beacon_interval = src->beacon_interval;
  1317. dst->listen_interval = src->listen_interval;
  1318. dst->atim_window = src->atim_window;
  1319. dst->erp_value = src->erp_value;
  1320. dst->tim = src->tim;
  1321. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  1322. dst->wpa_ie_len = src->wpa_ie_len;
  1323. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  1324. dst->rsn_ie_len = src->rsn_ie_len;
  1325. dst->last_scanned = jiffies;
  1326. qos_active = src->qos_data.active;
  1327. old_param = dst->qos_data.old_param_count;
  1328. if (dst->flags & NETWORK_HAS_QOS_MASK)
  1329. memcpy(&dst->qos_data, &src->qos_data,
  1330. sizeof(struct ieee80211_qos_data));
  1331. else {
  1332. dst->qos_data.supported = src->qos_data.supported;
  1333. dst->qos_data.param_count = src->qos_data.param_count;
  1334. }
  1335. if (dst->qos_data.supported == 1) {
  1336. if (dst->ssid_len)
  1337. IEEE80211_DEBUG_QOS
  1338. ("QoS the network %s is QoS supported\n",
  1339. dst->ssid);
  1340. else
  1341. IEEE80211_DEBUG_QOS
  1342. ("QoS the network is QoS supported\n");
  1343. }
  1344. dst->qos_data.active = qos_active;
  1345. dst->qos_data.old_param_count = old_param;
  1346. /* dst->last_associate is not overwritten */
  1347. }
  1348. static inline int is_beacon(__le16 fc)
  1349. {
  1350. return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
  1351. }
  1352. static void ieee80211_process_probe_response(struct ieee80211_device
  1353. *ieee, struct
  1354. ieee80211_probe_response
  1355. *beacon, struct ieee80211_rx_stats
  1356. *stats)
  1357. {
  1358. struct net_device *dev = ieee->dev;
  1359. struct ieee80211_network network = {
  1360. .ibss_dfs = NULL,
  1361. };
  1362. struct ieee80211_network *target;
  1363. struct ieee80211_network *oldest = NULL;
  1364. #ifdef CONFIG_IEEE80211_DEBUG
  1365. struct ieee80211_info_element *info_element = beacon->info_element;
  1366. #endif
  1367. unsigned long flags;
  1368. DECLARE_SSID_BUF(ssid);
  1369. IEEE80211_DEBUG_SCAN("'%s' (%pM"
  1370. "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  1371. print_ssid(ssid, info_element->data, info_element->len),
  1372. beacon->header.addr3,
  1373. (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
  1374. (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
  1375. (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
  1376. (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
  1377. (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
  1378. (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
  1379. (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
  1380. (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
  1381. (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
  1382. (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
  1383. (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
  1384. (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
  1385. (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
  1386. (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
  1387. (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
  1388. (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
  1389. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  1390. IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n",
  1391. print_ssid(ssid, info_element->data,
  1392. info_element->len),
  1393. beacon->header.addr3,
  1394. is_beacon(beacon->header.frame_ctl) ?
  1395. "BEACON" : "PROBE RESPONSE");
  1396. return;
  1397. }
  1398. /* The network parsed correctly -- so now we scan our known networks
  1399. * to see if we can find it in our list.
  1400. *
  1401. * NOTE: This search is definitely not optimized. Once its doing
  1402. * the "right thing" we'll optimize it for efficiency if
  1403. * necessary */
  1404. /* Search for this entry in the list and update it if it is
  1405. * already there. */
  1406. spin_lock_irqsave(&ieee->lock, flags);
  1407. list_for_each_entry(target, &ieee->network_list, list) {
  1408. if (is_same_network(target, &network))
  1409. break;
  1410. if ((oldest == NULL) ||
  1411. (target->last_scanned < oldest->last_scanned))
  1412. oldest = target;
  1413. }
  1414. /* If we didn't find a match, then get a new network slot to initialize
  1415. * with this beacon's information */
  1416. if (&target->list == &ieee->network_list) {
  1417. if (list_empty(&ieee->network_free_list)) {
  1418. /* If there are no more slots, expire the oldest */
  1419. list_del(&oldest->list);
  1420. target = oldest;
  1421. IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from "
  1422. "network list.\n",
  1423. print_ssid(ssid, target->ssid,
  1424. target->ssid_len),
  1425. target->bssid);
  1426. ieee80211_network_reset(target);
  1427. } else {
  1428. /* Otherwise just pull from the free list */
  1429. target = list_entry(ieee->network_free_list.next,
  1430. struct ieee80211_network, list);
  1431. list_del(ieee->network_free_list.next);
  1432. }
  1433. #ifdef CONFIG_IEEE80211_DEBUG
  1434. IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n",
  1435. print_ssid(ssid, network.ssid,
  1436. network.ssid_len),
  1437. network.bssid,
  1438. is_beacon(beacon->header.frame_ctl) ?
  1439. "BEACON" : "PROBE RESPONSE");
  1440. #endif
  1441. memcpy(target, &network, sizeof(*target));
  1442. network.ibss_dfs = NULL;
  1443. list_add_tail(&target->list, &ieee->network_list);
  1444. } else {
  1445. IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
  1446. print_ssid(ssid, target->ssid,
  1447. target->ssid_len),
  1448. target->bssid,
  1449. is_beacon(beacon->header.frame_ctl) ?
  1450. "BEACON" : "PROBE RESPONSE");
  1451. update_network(target, &network);
  1452. network.ibss_dfs = NULL;
  1453. }
  1454. spin_unlock_irqrestore(&ieee->lock, flags);
  1455. if (is_beacon(beacon->header.frame_ctl)) {
  1456. if (ieee->handle_beacon != NULL)
  1457. ieee->handle_beacon(dev, beacon, target);
  1458. } else {
  1459. if (ieee->handle_probe_response != NULL)
  1460. ieee->handle_probe_response(dev, beacon, target);
  1461. }
  1462. }
  1463. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1464. struct ieee80211_hdr_4addr *header,
  1465. struct ieee80211_rx_stats *stats)
  1466. {
  1467. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1468. case IEEE80211_STYPE_ASSOC_RESP:
  1469. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1470. WLAN_FC_GET_STYPE(le16_to_cpu
  1471. (header->frame_ctl)));
  1472. ieee80211_handle_assoc_resp(ieee,
  1473. (struct ieee80211_assoc_response *)
  1474. header, stats);
  1475. break;
  1476. case IEEE80211_STYPE_REASSOC_RESP:
  1477. IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1478. WLAN_FC_GET_STYPE(le16_to_cpu
  1479. (header->frame_ctl)));
  1480. break;
  1481. case IEEE80211_STYPE_PROBE_REQ:
  1482. IEEE80211_DEBUG_MGMT("received auth (%d)\n",
  1483. WLAN_FC_GET_STYPE(le16_to_cpu
  1484. (header->frame_ctl)));
  1485. if (ieee->handle_probe_request != NULL)
  1486. ieee->handle_probe_request(ieee->dev,
  1487. (struct
  1488. ieee80211_probe_request *)
  1489. header, stats);
  1490. break;
  1491. case IEEE80211_STYPE_PROBE_RESP:
  1492. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1493. WLAN_FC_GET_STYPE(le16_to_cpu
  1494. (header->frame_ctl)));
  1495. IEEE80211_DEBUG_SCAN("Probe response\n");
  1496. ieee80211_process_probe_response(ieee,
  1497. (struct
  1498. ieee80211_probe_response *)
  1499. header, stats);
  1500. break;
  1501. case IEEE80211_STYPE_BEACON:
  1502. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1503. WLAN_FC_GET_STYPE(le16_to_cpu
  1504. (header->frame_ctl)));
  1505. IEEE80211_DEBUG_SCAN("Beacon\n");
  1506. ieee80211_process_probe_response(ieee,
  1507. (struct
  1508. ieee80211_probe_response *)
  1509. header, stats);
  1510. break;
  1511. case IEEE80211_STYPE_AUTH:
  1512. IEEE80211_DEBUG_MGMT("received auth (%d)\n",
  1513. WLAN_FC_GET_STYPE(le16_to_cpu
  1514. (header->frame_ctl)));
  1515. if (ieee->handle_auth != NULL)
  1516. ieee->handle_auth(ieee->dev,
  1517. (struct ieee80211_auth *)header);
  1518. break;
  1519. case IEEE80211_STYPE_DISASSOC:
  1520. if (ieee->handle_disassoc != NULL)
  1521. ieee->handle_disassoc(ieee->dev,
  1522. (struct ieee80211_disassoc *)
  1523. header);
  1524. break;
  1525. case IEEE80211_STYPE_ACTION:
  1526. IEEE80211_DEBUG_MGMT("ACTION\n");
  1527. if (ieee->handle_action)
  1528. ieee->handle_action(ieee->dev,
  1529. (struct ieee80211_action *)
  1530. header, stats);
  1531. break;
  1532. case IEEE80211_STYPE_REASSOC_REQ:
  1533. IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
  1534. WLAN_FC_GET_STYPE(le16_to_cpu
  1535. (header->frame_ctl)));
  1536. IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
  1537. ieee->dev->name);
  1538. if (ieee->handle_reassoc_request != NULL)
  1539. ieee->handle_reassoc_request(ieee->dev,
  1540. (struct ieee80211_reassoc_request *)
  1541. header);
  1542. break;
  1543. case IEEE80211_STYPE_ASSOC_REQ:
  1544. IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
  1545. WLAN_FC_GET_STYPE(le16_to_cpu
  1546. (header->frame_ctl)));
  1547. IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
  1548. ieee->dev->name);
  1549. if (ieee->handle_assoc_request != NULL)
  1550. ieee->handle_assoc_request(ieee->dev);
  1551. break;
  1552. case IEEE80211_STYPE_DEAUTH:
  1553. IEEE80211_DEBUG_MGMT("DEAUTH\n");
  1554. if (ieee->handle_deauth != NULL)
  1555. ieee->handle_deauth(ieee->dev,
  1556. (struct ieee80211_deauth *)
  1557. header);
  1558. break;
  1559. default:
  1560. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1561. WLAN_FC_GET_STYPE(le16_to_cpu
  1562. (header->frame_ctl)));
  1563. IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
  1564. ieee->dev->name,
  1565. WLAN_FC_GET_STYPE(le16_to_cpu
  1566. (header->frame_ctl)));
  1567. break;
  1568. }
  1569. }
  1570. EXPORT_SYMBOL_GPL(ieee80211_rx_any);
  1571. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1572. EXPORT_SYMBOL(ieee80211_rx);