ieee80211_rx.c 49 KB

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