ieee80211_rx.c 51 KB

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