ieee80211_rx.c 51 KB

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