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