ieee802_11.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. /*
  2. * hostapd / IEEE 802.11 Management
  3. * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2007-2008, Intel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #include "includes.h"
  16. #ifndef CONFIG_NATIVE_WINDOWS
  17. #include <net/if.h>
  18. #include "eloop.h"
  19. #include "hostapd.h"
  20. #include "ieee802_11.h"
  21. #include "beacon.h"
  22. #include "hw_features.h"
  23. #include "radius/radius.h"
  24. #include "radius/radius_client.h"
  25. #include "ieee802_11_auth.h"
  26. #include "sta_info.h"
  27. #include "rc4.h"
  28. #include "ieee802_1x.h"
  29. #include "wpa.h"
  30. #include "wme.h"
  31. #include "ap_list.h"
  32. #include "accounting.h"
  33. #include "driver.h"
  34. #include "mlme.h"
  35. u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
  36. {
  37. u8 *pos = eid;
  38. int i, num, count;
  39. if (hapd->iface->current_rates == NULL)
  40. return eid;
  41. *pos++ = WLAN_EID_SUPP_RATES;
  42. num = hapd->iface->num_rates;
  43. if (num > 8) {
  44. /* rest of the rates are encoded in Extended supported
  45. * rates element */
  46. num = 8;
  47. }
  48. *pos++ = num;
  49. count = 0;
  50. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
  51. i++) {
  52. count++;
  53. *pos = hapd->iface->current_rates[i].rate / 5;
  54. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  55. *pos |= 0x80;
  56. pos++;
  57. }
  58. return pos;
  59. }
  60. u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
  61. {
  62. u8 *pos = eid;
  63. int i, num, count;
  64. if (hapd->iface->current_rates == NULL)
  65. return eid;
  66. num = hapd->iface->num_rates;
  67. if (num <= 8)
  68. return eid;
  69. num -= 8;
  70. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  71. *pos++ = num;
  72. count = 0;
  73. for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
  74. i++) {
  75. count++;
  76. if (count <= 8)
  77. continue; /* already in SuppRates IE */
  78. *pos = hapd->iface->current_rates[i].rate / 5;
  79. if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
  80. *pos |= 0x80;
  81. pos++;
  82. }
  83. return pos;
  84. }
  85. u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid)
  86. {
  87. #ifdef CONFIG_IEEE80211N
  88. struct ieee80211_ht_capability *cap;
  89. u8 *pos = eid;
  90. if (!hapd->iconf->ieee80211n)
  91. return eid;
  92. *pos++ = WLAN_EID_HT_CAP;
  93. *pos++ = sizeof(*cap);
  94. cap = (struct ieee80211_ht_capability *) pos;
  95. os_memset(cap, 0, sizeof(*cap));
  96. SET_2BIT_U8(&cap->mac_ht_params_info,
  97. MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
  98. MAX_RX_AMPDU_FACTOR_64KB);
  99. cap->capabilities_info = host_to_le16(hapd->iconf->ht_capab);
  100. cap->supported_mcs_set[0] = 0xff;
  101. cap->supported_mcs_set[1] = 0xff;
  102. pos += sizeof(*cap);
  103. return pos;
  104. #else /* CONFIG_IEEE80211N */
  105. return eid;
  106. #endif /* CONFIG_IEEE80211N */
  107. }
  108. u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
  109. {
  110. #ifdef CONFIG_IEEE80211N
  111. struct ieee80211_ht_operation *oper;
  112. u8 *pos = eid;
  113. if (!hapd->iconf->ieee80211n)
  114. return eid;
  115. *pos++ = WLAN_EID_HT_OPERATION;
  116. *pos++ = sizeof(*oper);
  117. oper = (struct ieee80211_ht_operation *) pos;
  118. os_memset(oper, 0, sizeof(*oper));
  119. oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
  120. pos += sizeof(*oper);
  121. return pos;
  122. #else /* CONFIG_IEEE80211N */
  123. return eid;
  124. #endif /* CONFIG_IEEE80211N */
  125. }
  126. #ifdef CONFIG_IEEE80211N
  127. /*
  128. op_mode
  129. Set to 0 (HT pure) under the followign conditions
  130. - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
  131. - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
  132. Set to 1 (HT non-member protection) if there may be non-HT STAs
  133. in both the primary and the secondary channel
  134. Set to 2 if only HT STAs are associated in BSS,
  135. however and at least one 20 MHz HT STA is associated
  136. Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
  137. (currently non-GF HT station is considered as non-HT STA also)
  138. */
  139. int hostapd_ht_operation_update(struct hostapd_iface *iface)
  140. {
  141. u16 cur_op_mode, new_op_mode;
  142. int op_mode_changes = 0;
  143. if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
  144. return 0;
  145. wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
  146. __func__, iface->ht_op_mode);
  147. if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
  148. && iface->num_sta_ht_no_gf) {
  149. iface->ht_op_mode |=
  150. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  151. op_mode_changes++;
  152. } else if ((iface->ht_op_mode &
  153. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
  154. iface->num_sta_ht_no_gf == 0) {
  155. iface->ht_op_mode &=
  156. ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  157. op_mode_changes++;
  158. }
  159. if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  160. (iface->num_sta_no_ht || iface->olbc_ht)) {
  161. iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  162. op_mode_changes++;
  163. } else if ((iface->ht_op_mode &
  164. HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  165. (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
  166. iface->ht_op_mode &=
  167. ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  168. op_mode_changes++;
  169. }
  170. /* Note: currently we switch to the MIXED op mode if HT non-greenfield
  171. * station is associated. Probably it's a theoretical case, since
  172. * it looks like all known HT STAs support greenfield.
  173. */
  174. new_op_mode = 0;
  175. if (iface->num_sta_no_ht ||
  176. (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
  177. new_op_mode = OP_MODE_MIXED;
  178. else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
  179. && iface->num_sta_ht_20mhz)
  180. new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
  181. else if (iface->olbc_ht)
  182. new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
  183. else
  184. new_op_mode = OP_MODE_PURE;
  185. cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  186. if (cur_op_mode != new_op_mode) {
  187. iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  188. iface->ht_op_mode |= new_op_mode;
  189. op_mode_changes++;
  190. }
  191. wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
  192. __func__, iface->ht_op_mode, op_mode_changes);
  193. return op_mode_changes;
  194. }
  195. #endif /* CONFIG_IEEE80211N */
  196. u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
  197. int probe)
  198. {
  199. int capab = WLAN_CAPABILITY_ESS;
  200. int privacy;
  201. if (hapd->iface->num_sta_no_short_preamble == 0 &&
  202. hapd->iconf->preamble == SHORT_PREAMBLE)
  203. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  204. privacy = hapd->conf->ssid.wep.keys_set;
  205. if (hapd->conf->ieee802_1x &&
  206. (hapd->conf->default_wep_key_len ||
  207. hapd->conf->individual_wep_key_len))
  208. privacy = 1;
  209. if (hapd->conf->wpa)
  210. privacy = 1;
  211. if (sta) {
  212. int policy, def_klen;
  213. if (probe && sta->ssid_probe) {
  214. policy = sta->ssid_probe->security_policy;
  215. def_klen = sta->ssid_probe->wep.default_len;
  216. } else {
  217. policy = sta->ssid->security_policy;
  218. def_klen = sta->ssid->wep.default_len;
  219. }
  220. privacy = policy != SECURITY_PLAINTEXT;
  221. if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
  222. privacy = 0;
  223. }
  224. if (privacy)
  225. capab |= WLAN_CAPABILITY_PRIVACY;
  226. if (hapd->iface->current_mode &&
  227. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
  228. hapd->iface->num_sta_no_short_slot_time == 0)
  229. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  230. return capab;
  231. }
  232. #ifdef CONFIG_IEEE80211W
  233. static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
  234. struct sta_info *sta, u8 *eid)
  235. {
  236. u8 *pos = eid;
  237. u32 timeout;
  238. *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
  239. *pos++ = 4;
  240. timeout = (hapd->conf->assoc_ping_attempts - sta->ping_count + 1) *
  241. hapd->conf->assoc_ping_timeout;
  242. WPA_PUT_LE32(pos, timeout);
  243. pos += 4;
  244. return pos;
  245. }
  246. #endif /* CONFIG_IEEE80211W */
  247. void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
  248. {
  249. int i;
  250. if (len > HOSTAPD_MAX_SSID_LEN)
  251. len = HOSTAPD_MAX_SSID_LEN;
  252. for (i = 0; i < len; i++) {
  253. if (ssid[i] >= 32 && ssid[i] < 127)
  254. buf[i] = ssid[i];
  255. else
  256. buf[i] = '.';
  257. }
  258. buf[len] = '\0';
  259. }
  260. void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
  261. {
  262. struct ieee80211_mgmt mgmt;
  263. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  264. HOSTAPD_LEVEL_DEBUG,
  265. "deauthenticate - reason %d", reason);
  266. os_memset(&mgmt, 0, sizeof(mgmt));
  267. mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  268. WLAN_FC_STYPE_DEAUTH);
  269. os_memcpy(mgmt.da, addr, ETH_ALEN);
  270. os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
  271. os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
  272. mgmt.u.deauth.reason_code = host_to_le16(reason);
  273. if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
  274. sizeof(mgmt.u.deauth), 0) < 0)
  275. perror("ieee802_11_send_deauth: send");
  276. }
  277. static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
  278. u16 auth_transaction, u8 *challenge, int iswep)
  279. {
  280. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  281. HOSTAPD_LEVEL_DEBUG,
  282. "authentication (shared key, transaction %d)",
  283. auth_transaction);
  284. if (auth_transaction == 1) {
  285. if (!sta->challenge) {
  286. /* Generate a pseudo-random challenge */
  287. u8 key[8];
  288. time_t now;
  289. int r;
  290. sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
  291. if (sta->challenge == NULL)
  292. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  293. now = time(NULL);
  294. r = random();
  295. os_memcpy(key, &now, 4);
  296. os_memcpy(key + 4, &r, 4);
  297. rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
  298. key, sizeof(key));
  299. }
  300. return 0;
  301. }
  302. if (auth_transaction != 3)
  303. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  304. /* Transaction 3 */
  305. if (!iswep || !sta->challenge || !challenge ||
  306. os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
  307. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  308. HOSTAPD_LEVEL_INFO,
  309. "shared key authentication - invalid "
  310. "challenge-response");
  311. return WLAN_STATUS_CHALLENGE_FAIL;
  312. }
  313. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  314. HOSTAPD_LEVEL_DEBUG,
  315. "authentication OK (shared key)");
  316. #ifdef IEEE80211_REQUIRE_AUTH_ACK
  317. /* Station will be marked authenticated if it ACKs the
  318. * authentication reply. */
  319. #else
  320. sta->flags |= WLAN_STA_AUTH;
  321. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  322. #endif
  323. os_free(sta->challenge);
  324. sta->challenge = NULL;
  325. return 0;
  326. }
  327. static void send_auth_reply(struct hostapd_data *hapd,
  328. const u8 *dst, const u8 *bssid,
  329. u16 auth_alg, u16 auth_transaction, u16 resp,
  330. const u8 *ies, size_t ies_len)
  331. {
  332. struct ieee80211_mgmt *reply;
  333. u8 *buf;
  334. size_t rlen;
  335. rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
  336. buf = os_zalloc(rlen);
  337. if (buf == NULL)
  338. return;
  339. reply = (struct ieee80211_mgmt *) buf;
  340. reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  341. WLAN_FC_STYPE_AUTH);
  342. os_memcpy(reply->da, dst, ETH_ALEN);
  343. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  344. os_memcpy(reply->bssid, bssid, ETH_ALEN);
  345. reply->u.auth.auth_alg = host_to_le16(auth_alg);
  346. reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
  347. reply->u.auth.status_code = host_to_le16(resp);
  348. if (ies && ies_len)
  349. os_memcpy(reply->u.auth.variable, ies, ies_len);
  350. wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
  351. " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
  352. MAC2STR(dst), auth_alg, auth_transaction,
  353. resp, (unsigned long) ies_len);
  354. if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
  355. perror("send_auth_reply: send");
  356. os_free(buf);
  357. }
  358. #ifdef CONFIG_IEEE80211R
  359. static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
  360. u16 auth_transaction, u16 status,
  361. const u8 *ies, size_t ies_len)
  362. {
  363. struct hostapd_data *hapd = ctx;
  364. struct sta_info *sta;
  365. send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
  366. status, ies, ies_len);
  367. if (status != WLAN_STATUS_SUCCESS)
  368. return;
  369. sta = ap_get_sta(hapd, dst);
  370. if (sta == NULL)
  371. return;
  372. hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
  373. HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
  374. sta->flags |= WLAN_STA_AUTH;
  375. mlme_authenticate_indication(hapd, sta);
  376. }
  377. #endif /* CONFIG_IEEE80211R */
  378. static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
  379. size_t len)
  380. {
  381. u16 auth_alg, auth_transaction, status_code;
  382. u16 resp = WLAN_STATUS_SUCCESS;
  383. struct sta_info *sta = NULL;
  384. int res;
  385. u16 fc;
  386. u8 *challenge = NULL;
  387. u32 session_timeout, acct_interim_interval;
  388. int vlan_id = 0;
  389. u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
  390. size_t resp_ies_len = 0;
  391. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  392. printf("handle_auth - too short payload (len=%lu)\n",
  393. (unsigned long) len);
  394. return;
  395. }
  396. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  397. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  398. status_code = le_to_host16(mgmt->u.auth.status_code);
  399. fc = le_to_host16(mgmt->frame_control);
  400. if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
  401. 2 + WLAN_AUTH_CHALLENGE_LEN &&
  402. mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
  403. mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
  404. challenge = &mgmt->u.auth.variable[2];
  405. wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
  406. "auth_transaction=%d status_code=%d wep=%d%s",
  407. MAC2STR(mgmt->sa), auth_alg, auth_transaction,
  408. status_code, !!(fc & WLAN_FC_ISWEP),
  409. challenge ? " challenge" : "");
  410. if (hapd->tkip_countermeasures) {
  411. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  412. goto fail;
  413. }
  414. if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
  415. auth_alg == WLAN_AUTH_OPEN) ||
  416. #ifdef CONFIG_IEEE80211R
  417. (hapd->conf->wpa &&
  418. (hapd->conf->wpa_key_mgmt &
  419. (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
  420. auth_alg == WLAN_AUTH_FT) ||
  421. #endif /* CONFIG_IEEE80211R */
  422. ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
  423. auth_alg == WLAN_AUTH_SHARED_KEY))) {
  424. printf("Unsupported authentication algorithm (%d)\n",
  425. auth_alg);
  426. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  427. goto fail;
  428. }
  429. if (!(auth_transaction == 1 ||
  430. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
  431. printf("Unknown authentication transaction number (%d)\n",
  432. auth_transaction);
  433. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  434. goto fail;
  435. }
  436. if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
  437. printf("Station " MACSTR " not allowed to authenticate.\n",
  438. MAC2STR(mgmt->sa));
  439. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  440. goto fail;
  441. }
  442. res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
  443. &session_timeout,
  444. &acct_interim_interval, &vlan_id);
  445. if (res == HOSTAPD_ACL_REJECT) {
  446. printf("Station " MACSTR " not allowed to authenticate.\n",
  447. MAC2STR(mgmt->sa));
  448. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  449. goto fail;
  450. }
  451. if (res == HOSTAPD_ACL_PENDING) {
  452. wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  453. " waiting for an external authentication",
  454. MAC2STR(mgmt->sa));
  455. /* Authentication code will re-send the authentication frame
  456. * after it has received (and cached) information from the
  457. * external source. */
  458. return;
  459. }
  460. sta = ap_sta_add(hapd, mgmt->sa);
  461. if (!sta) {
  462. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  463. goto fail;
  464. }
  465. if (vlan_id > 0) {
  466. if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
  467. sta->vlan_id) == NULL) {
  468. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  469. HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
  470. "%d received from RADIUS server",
  471. vlan_id);
  472. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  473. goto fail;
  474. }
  475. sta->vlan_id = vlan_id;
  476. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
  477. HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
  478. }
  479. sta->flags &= ~WLAN_STA_PREAUTH;
  480. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  481. if (hapd->conf->radius->acct_interim_interval == 0 &&
  482. acct_interim_interval)
  483. sta->acct_interim_interval = acct_interim_interval;
  484. if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
  485. ap_sta_session_timeout(hapd, sta, session_timeout);
  486. else
  487. ap_sta_no_session_timeout(hapd, sta);
  488. switch (auth_alg) {
  489. case WLAN_AUTH_OPEN:
  490. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  491. HOSTAPD_LEVEL_DEBUG,
  492. "authentication OK (open system)");
  493. #ifdef IEEE80211_REQUIRE_AUTH_ACK
  494. /* Station will be marked authenticated if it ACKs the
  495. * authentication reply. */
  496. #else
  497. sta->flags |= WLAN_STA_AUTH;
  498. wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
  499. sta->auth_alg = WLAN_AUTH_OPEN;
  500. mlme_authenticate_indication(hapd, sta);
  501. #endif
  502. break;
  503. case WLAN_AUTH_SHARED_KEY:
  504. resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
  505. fc & WLAN_FC_ISWEP);
  506. sta->auth_alg = WLAN_AUTH_SHARED_KEY;
  507. mlme_authenticate_indication(hapd, sta);
  508. if (sta->challenge && auth_transaction == 1) {
  509. resp_ies[0] = WLAN_EID_CHALLENGE;
  510. resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
  511. os_memcpy(resp_ies + 2, sta->challenge,
  512. WLAN_AUTH_CHALLENGE_LEN);
  513. resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
  514. }
  515. break;
  516. #ifdef CONFIG_IEEE80211R
  517. case WLAN_AUTH_FT:
  518. sta->auth_alg = WLAN_AUTH_FT;
  519. if (sta->wpa_sm == NULL)
  520. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  521. sta->addr);
  522. if (sta->wpa_sm == NULL) {
  523. wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
  524. "state machine");
  525. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  526. goto fail;
  527. }
  528. wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
  529. auth_transaction, mgmt->u.auth.variable,
  530. len - IEEE80211_HDRLEN -
  531. sizeof(mgmt->u.auth),
  532. handle_auth_ft_finish, hapd);
  533. /* handle_auth_ft_finish() callback will complete auth. */
  534. return;
  535. #endif /* CONFIG_IEEE80211R */
  536. }
  537. fail:
  538. send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
  539. auth_transaction + 1, resp, resp_ies, resp_ies_len);
  540. }
  541. static void handle_assoc(struct hostapd_data *hapd,
  542. struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
  543. {
  544. u16 capab_info, listen_interval;
  545. u16 resp = WLAN_STATUS_SUCCESS;
  546. u8 *pos, *wpa_ie;
  547. size_t wpa_ie_len;
  548. int send_deauth = 0, send_len, left, i;
  549. struct sta_info *sta;
  550. struct ieee802_11_elems elems;
  551. u8 buf[sizeof(struct ieee80211_mgmt) + 512];
  552. struct ieee80211_mgmt *reply;
  553. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  554. sizeof(mgmt->u.assoc_req))) {
  555. printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
  556. "\n", reassoc, (unsigned long) len);
  557. return;
  558. }
  559. if (reassoc) {
  560. capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
  561. listen_interval = le_to_host16(
  562. mgmt->u.reassoc_req.listen_interval);
  563. wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
  564. " capab_info=0x%02x listen_interval=%d current_ap="
  565. MACSTR,
  566. MAC2STR(mgmt->sa), capab_info, listen_interval,
  567. MAC2STR(mgmt->u.reassoc_req.current_ap));
  568. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
  569. pos = mgmt->u.reassoc_req.variable;
  570. } else {
  571. capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  572. listen_interval = le_to_host16(
  573. mgmt->u.assoc_req.listen_interval);
  574. wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
  575. " capab_info=0x%02x listen_interval=%d",
  576. MAC2STR(mgmt->sa), capab_info, listen_interval);
  577. left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
  578. pos = mgmt->u.assoc_req.variable;
  579. }
  580. sta = ap_get_sta(hapd, mgmt->sa);
  581. #ifdef CONFIG_IEEE80211R
  582. if (sta && sta->auth_alg == WLAN_AUTH_FT &&
  583. (sta->flags & WLAN_STA_AUTH) == 0) {
  584. wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
  585. "prior to authentication since it is using "
  586. "over-the-DS FT", MAC2STR(mgmt->sa));
  587. } else
  588. #endif /* CONFIG_IEEE80211R */
  589. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  590. printf("STA " MACSTR " trying to associate before "
  591. "authentication\n", MAC2STR(mgmt->sa));
  592. if (sta) {
  593. printf(" sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
  594. MAC2STR(sta->addr), sta->aid, sta->flags);
  595. }
  596. send_deauth = 1;
  597. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  598. goto fail;
  599. }
  600. if (hapd->tkip_countermeasures) {
  601. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  602. goto fail;
  603. }
  604. if (listen_interval > hapd->conf->max_listen_interval) {
  605. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  606. HOSTAPD_LEVEL_DEBUG,
  607. "Too large Listen Interval (%d)",
  608. listen_interval);
  609. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  610. goto fail;
  611. }
  612. sta->capability = capab_info;
  613. sta->listen_interval = listen_interval;
  614. /* followed by SSID and Supported rates; and HT capabilities if 802.11n
  615. * is used */
  616. if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
  617. !elems.ssid) {
  618. printf("STA " MACSTR " sent invalid association request\n",
  619. MAC2STR(sta->addr));
  620. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  621. goto fail;
  622. }
  623. if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
  624. os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
  625. {
  626. char ssid_txt[33];
  627. ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
  628. printf("Station " MACSTR " tried to associate with "
  629. "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
  630. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  631. goto fail;
  632. }
  633. sta->flags &= ~WLAN_STA_WME;
  634. if (elems.wme && hapd->conf->wme_enabled) {
  635. if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
  636. hostapd_logger(hapd, sta->addr,
  637. HOSTAPD_MODULE_WPA,
  638. HOSTAPD_LEVEL_DEBUG,
  639. "invalid WME element in association "
  640. "request");
  641. else
  642. sta->flags |= WLAN_STA_WME;
  643. }
  644. if (!elems.supp_rates) {
  645. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  646. HOSTAPD_LEVEL_DEBUG,
  647. "No supported rates element in AssocReq");
  648. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  649. goto fail;
  650. }
  651. if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
  652. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  653. HOSTAPD_LEVEL_DEBUG,
  654. "Invalid supported rates element length %d",
  655. elems.supp_rates_len);
  656. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  657. goto fail;
  658. }
  659. os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
  660. os_memcpy(sta->supported_rates, elems.supp_rates,
  661. elems.supp_rates_len);
  662. sta->supported_rates_len = elems.supp_rates_len;
  663. if (elems.ext_supp_rates) {
  664. if (elems.supp_rates_len + elems.ext_supp_rates_len >
  665. sizeof(sta->supported_rates)) {
  666. hostapd_logger(hapd, mgmt->sa,
  667. HOSTAPD_MODULE_IEEE80211,
  668. HOSTAPD_LEVEL_DEBUG,
  669. "Invalid supported rates element length"
  670. " %d+%d", elems.supp_rates_len,
  671. elems.ext_supp_rates_len);
  672. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  673. goto fail;
  674. }
  675. os_memcpy(sta->supported_rates + elems.supp_rates_len,
  676. elems.ext_supp_rates, elems.ext_supp_rates_len);
  677. sta->supported_rates_len += elems.ext_supp_rates_len;
  678. }
  679. #ifdef CONFIG_IEEE80211N
  680. /* save HT capabilities in the sta object */
  681. os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
  682. if (elems.ht_capabilities &&
  683. elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
  684. && (sta->flags & WLAN_STA_WME)) {
  685. /* note: without WMM capability, treat the sta as non-HT */
  686. sta->flags |= WLAN_STA_HT;
  687. sta->ht_capabilities.id = WLAN_EID_HT_CAP;
  688. sta->ht_capabilities.length =
  689. sizeof(struct ieee80211_ht_capability);
  690. os_memcpy(&sta->ht_capabilities.data,
  691. elems.ht_capabilities,
  692. sizeof(struct ieee80211_ht_capability));
  693. } else
  694. sta->flags &= ~WLAN_STA_HT;
  695. #endif /* CONFIG_IEEE80211N */
  696. if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
  697. wpa_ie = elems.rsn_ie;
  698. wpa_ie_len = elems.rsn_ie_len;
  699. } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
  700. elems.wpa_ie) {
  701. wpa_ie = elems.wpa_ie;
  702. wpa_ie_len = elems.wpa_ie_len;
  703. } else {
  704. wpa_ie = NULL;
  705. wpa_ie_len = 0;
  706. }
  707. #ifdef CONFIG_WPS
  708. if (hapd->conf->wps_state && wpa_ie == NULL) {
  709. if (elems.wps_ie) {
  710. wpa_printf(MSG_DEBUG, "STA included WPS IE in "
  711. "(Re)Association Request - assume WPS is "
  712. "used");
  713. sta->flags |= WLAN_STA_WPS;
  714. } else {
  715. wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE "
  716. "in (Re)Association Request - possible WPS "
  717. "use");
  718. sta->flags |= WLAN_STA_MAYBE_WPS;
  719. }
  720. } else
  721. #endif /* CONFIG_WPS */
  722. if (hapd->conf->wpa && wpa_ie == NULL) {
  723. printf("STA " MACSTR ": No WPA/RSN IE in association "
  724. "request\n", MAC2STR(sta->addr));
  725. resp = WLAN_STATUS_INVALID_IE;
  726. goto fail;
  727. }
  728. if (hapd->conf->wpa && wpa_ie) {
  729. int res;
  730. wpa_ie -= 2;
  731. wpa_ie_len += 2;
  732. if (sta->wpa_sm == NULL)
  733. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  734. sta->addr);
  735. if (sta->wpa_sm == NULL) {
  736. printf("Failed to initialize WPA state machine\n");
  737. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  738. goto fail;
  739. }
  740. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  741. wpa_ie, wpa_ie_len,
  742. elems.mdie, elems.mdie_len);
  743. if (res == WPA_INVALID_GROUP)
  744. resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  745. else if (res == WPA_INVALID_PAIRWISE)
  746. resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  747. else if (res == WPA_INVALID_AKMP)
  748. resp = WLAN_STATUS_AKMP_NOT_VALID;
  749. else if (res == WPA_ALLOC_FAIL)
  750. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  751. #ifdef CONFIG_IEEE80211W
  752. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  753. resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
  754. else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  755. resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
  756. #endif /* CONFIG_IEEE80211W */
  757. else if (res == WPA_INVALID_MDIE)
  758. resp = WLAN_STATUS_INVALID_MDIE;
  759. else if (res != WPA_IE_OK)
  760. resp = WLAN_STATUS_INVALID_IE;
  761. if (resp != WLAN_STATUS_SUCCESS)
  762. goto fail;
  763. #ifdef CONFIG_IEEE80211W
  764. if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
  765. /*
  766. * STA has already been associated with MFP and ping
  767. * timeout has not been reached. Reject the
  768. * association attempt temporarily and start ping, if
  769. * one is not pending.
  770. */
  771. if (sta->ping_count == 0)
  772. ap_sta_start_ping(hapd, sta);
  773. resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  774. goto fail;
  775. }
  776. if (wpa_auth_uses_mfp(sta->wpa_sm))
  777. sta->flags |= WLAN_STA_MFP;
  778. else
  779. sta->flags &= ~WLAN_STA_MFP;
  780. #endif /* CONFIG_IEEE80211W */
  781. #ifdef CONFIG_IEEE80211R
  782. if (sta->auth_alg == WLAN_AUTH_FT) {
  783. if (!reassoc) {
  784. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  785. "to use association (not "
  786. "re-association) with FT auth_alg",
  787. MAC2STR(sta->addr));
  788. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  789. goto fail;
  790. }
  791. resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
  792. if (resp != WLAN_STATUS_SUCCESS)
  793. goto fail;
  794. }
  795. #endif /* CONFIG_IEEE80211R */
  796. }
  797. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  798. sta->flags |= WLAN_STA_NONERP;
  799. for (i = 0; i < sta->supported_rates_len; i++) {
  800. if ((sta->supported_rates[i] & 0x7f) > 22) {
  801. sta->flags &= ~WLAN_STA_NONERP;
  802. break;
  803. }
  804. }
  805. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  806. sta->nonerp_set = 1;
  807. hapd->iface->num_sta_non_erp++;
  808. if (hapd->iface->num_sta_non_erp == 1)
  809. ieee802_11_set_beacons(hapd->iface);
  810. }
  811. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  812. !sta->no_short_slot_time_set) {
  813. sta->no_short_slot_time_set = 1;
  814. hapd->iface->num_sta_no_short_slot_time++;
  815. if (hapd->iface->current_mode->mode ==
  816. HOSTAPD_MODE_IEEE80211G &&
  817. hapd->iface->num_sta_no_short_slot_time == 1)
  818. ieee802_11_set_beacons(hapd->iface);
  819. }
  820. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  821. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  822. else
  823. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  824. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  825. !sta->no_short_preamble_set) {
  826. sta->no_short_preamble_set = 1;
  827. hapd->iface->num_sta_no_short_preamble++;
  828. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  829. && hapd->iface->num_sta_no_short_preamble == 1)
  830. ieee802_11_set_beacons(hapd->iface);
  831. }
  832. #ifdef CONFIG_IEEE80211N
  833. if (sta->flags & WLAN_STA_HT) {
  834. if ((sta->ht_capabilities.data.capabilities_info &
  835. HT_CAP_INFO_GREEN_FIELD) == 0) {
  836. hapd->iface->num_sta_ht_no_gf++;
  837. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
  838. "greenfield, num of non-gf stations %d",
  839. __func__, MAC2STR(sta->addr),
  840. hapd->iface->num_sta_ht_no_gf);
  841. }
  842. if ((sta->ht_capabilities.data.capabilities_info &
  843. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
  844. hapd->iface->num_sta_ht_20mhz++;
  845. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
  846. "num of 20MHz HT STAs %d",
  847. __func__, MAC2STR(sta->addr),
  848. hapd->iface->num_sta_ht_20mhz);
  849. }
  850. } else {
  851. hapd->iface->num_sta_no_ht++;
  852. if (hapd->iconf->ieee80211n) {
  853. wpa_printf(MSG_DEBUG, "%s STA " MACSTR
  854. " - no HT, num of non-HT stations %d",
  855. __func__, MAC2STR(sta->addr),
  856. hapd->iface->num_sta_no_ht);
  857. }
  858. }
  859. if (hostapd_ht_operation_update(hapd->iface) > 0)
  860. ieee802_11_set_beacons(hapd->iface);
  861. #endif /* CONFIG_IEEE80211N */
  862. /* get a unique AID */
  863. if (sta->aid > 0) {
  864. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  865. } else {
  866. for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
  867. if (hapd->sta_aid[sta->aid - 1] == NULL)
  868. break;
  869. if (sta->aid > MAX_AID_TABLE_SIZE) {
  870. sta->aid = 0;
  871. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  872. wpa_printf(MSG_ERROR, " no room for more AIDs");
  873. goto fail;
  874. } else {
  875. hapd->sta_aid[sta->aid - 1] = sta;
  876. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  877. }
  878. }
  879. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  880. HOSTAPD_LEVEL_DEBUG,
  881. "association OK (aid %d)", sta->aid);
  882. /* Station will be marked associated, after it acknowledges AssocResp
  883. */
  884. if (reassoc) {
  885. os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
  886. ETH_ALEN);
  887. }
  888. if (sta->last_assoc_req)
  889. os_free(sta->last_assoc_req);
  890. sta->last_assoc_req = os_malloc(len);
  891. if (sta->last_assoc_req)
  892. os_memcpy(sta->last_assoc_req, mgmt, len);
  893. /* Make sure that the previously registered inactivity timer will not
  894. * remove the STA immediately. */
  895. sta->timeout_next = STA_NULLFUNC;
  896. fail:
  897. os_memset(buf, 0, sizeof(buf));
  898. reply = (struct ieee80211_mgmt *) buf;
  899. reply->frame_control =
  900. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  901. (send_deauth ? WLAN_FC_STYPE_DEAUTH :
  902. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  903. WLAN_FC_STYPE_ASSOC_RESP)));
  904. os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
  905. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  906. os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
  907. send_len = IEEE80211_HDRLEN;
  908. if (send_deauth) {
  909. send_len += sizeof(reply->u.deauth);
  910. reply->u.deauth.reason_code = host_to_le16(resp);
  911. } else {
  912. u8 *p;
  913. send_len += sizeof(reply->u.assoc_resp);
  914. reply->u.assoc_resp.capab_info =
  915. host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
  916. reply->u.assoc_resp.status_code = host_to_le16(resp);
  917. reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
  918. | BIT(14) | BIT(15));
  919. /* Supported rates */
  920. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  921. /* Extended supported rates */
  922. p = hostapd_eid_ext_supp_rates(hapd, p);
  923. if (sta->flags & WLAN_STA_WME)
  924. p = hostapd_eid_wme(hapd, p);
  925. p = hostapd_eid_ht_capabilities_info(hapd, p);
  926. p = hostapd_eid_ht_operation(hapd, p);
  927. #ifdef CONFIG_IEEE80211R
  928. if (resp == WLAN_STATUS_SUCCESS) {
  929. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  930. * Transition Information, RSN */
  931. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  932. buf + sizeof(buf) - p,
  933. sta->auth_alg);
  934. }
  935. #endif /* CONFIG_IEEE80211R */
  936. #ifdef CONFIG_IEEE80211W
  937. if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  938. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  939. #endif /* CONFIG_IEEE80211W */
  940. send_len += p - reply->u.assoc_resp.variable;
  941. }
  942. if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
  943. perror("handle_assoc: send");
  944. }
  945. static void handle_disassoc(struct hostapd_data *hapd,
  946. struct ieee80211_mgmt *mgmt, size_t len)
  947. {
  948. struct sta_info *sta;
  949. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  950. printf("handle_disassoc - too short payload (len=%lu)\n",
  951. (unsigned long) len);
  952. return;
  953. }
  954. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  955. MAC2STR(mgmt->sa),
  956. le_to_host16(mgmt->u.disassoc.reason_code));
  957. sta = ap_get_sta(hapd, mgmt->sa);
  958. if (sta == NULL) {
  959. printf("Station " MACSTR " trying to disassociate, but it "
  960. "is not associated.\n", MAC2STR(mgmt->sa));
  961. return;
  962. }
  963. sta->flags &= ~WLAN_STA_ASSOC;
  964. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  965. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  966. HOSTAPD_LEVEL_INFO, "disassociated");
  967. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  968. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  969. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  970. * authenticated. */
  971. accounting_sta_stop(hapd, sta);
  972. ieee802_1x_free_station(sta);
  973. hostapd_sta_remove(hapd, sta->addr);
  974. if (sta->timeout_next == STA_NULLFUNC ||
  975. sta->timeout_next == STA_DISASSOC) {
  976. sta->timeout_next = STA_DEAUTH;
  977. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  978. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  979. hapd, sta);
  980. }
  981. mlme_disassociate_indication(
  982. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  983. }
  984. static void handle_deauth(struct hostapd_data *hapd,
  985. struct ieee80211_mgmt *mgmt, size_t len)
  986. {
  987. struct sta_info *sta;
  988. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  989. printf("handle_deauth - too short payload (len=%lu)\n",
  990. (unsigned long) len);
  991. return;
  992. }
  993. wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
  994. " reason_code=%d",
  995. MAC2STR(mgmt->sa),
  996. le_to_host16(mgmt->u.deauth.reason_code));
  997. sta = ap_get_sta(hapd, mgmt->sa);
  998. if (sta == NULL) {
  999. printf("Station " MACSTR " trying to deauthenticate, but it "
  1000. "is not authenticated.\n", MAC2STR(mgmt->sa));
  1001. return;
  1002. }
  1003. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  1004. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  1005. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1006. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  1007. mlme_deauthenticate_indication(
  1008. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  1009. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  1010. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  1011. ap_free_sta(hapd, sta);
  1012. }
  1013. static void handle_beacon(struct hostapd_data *hapd,
  1014. struct ieee80211_mgmt *mgmt, size_t len,
  1015. struct hostapd_frame_info *fi)
  1016. {
  1017. struct ieee802_11_elems elems;
  1018. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  1019. printf("handle_beacon - too short payload (len=%lu)\n",
  1020. (unsigned long) len);
  1021. return;
  1022. }
  1023. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  1024. len - (IEEE80211_HDRLEN +
  1025. sizeof(mgmt->u.beacon)), &elems,
  1026. 0);
  1027. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  1028. }
  1029. #ifdef CONFIG_IEEE80211W
  1030. static void hostapd_ping_action(struct hostapd_data *hapd,
  1031. struct ieee80211_mgmt *mgmt, size_t len)
  1032. {
  1033. struct sta_info *sta;
  1034. u8 *end;
  1035. int i;
  1036. end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
  1037. if (((u8 *) mgmt) + len < end) {
  1038. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
  1039. "frame (len=%lu)", (unsigned long) len);
  1040. return;
  1041. }
  1042. if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
  1043. wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
  1044. mgmt->u.action.u.ping_resp.action);
  1045. return;
  1046. }
  1047. /* MLME-PING.confirm */
  1048. sta = ap_get_sta(hapd, mgmt->sa);
  1049. if (sta == NULL || sta->ping_trans_id == NULL) {
  1050. wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
  1051. "pending ping request found");
  1052. return;
  1053. }
  1054. for (i = 0; i < sta->ping_count; i++) {
  1055. if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
  1056. mgmt->u.action.u.ping_resp.trans_id,
  1057. WLAN_PING_TRANS_ID_LEN) == 0)
  1058. break;
  1059. }
  1060. if (i >= sta->ping_count) {
  1061. wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
  1062. "transaction identifier found");
  1063. return;
  1064. }
  1065. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1066. HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
  1067. ap_sta_stop_ping(hapd, sta);
  1068. }
  1069. #endif /* CONFIG_IEEE80211W */
  1070. static void handle_action(struct hostapd_data *hapd,
  1071. struct ieee80211_mgmt *mgmt, size_t len)
  1072. {
  1073. if (len < IEEE80211_HDRLEN + 1) {
  1074. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1075. HOSTAPD_LEVEL_DEBUG,
  1076. "handle_action - too short payload (len=%lu)",
  1077. (unsigned long) len);
  1078. return;
  1079. }
  1080. switch (mgmt->u.action.category) {
  1081. #ifdef CONFIG_IEEE80211R
  1082. case WLAN_ACTION_FT:
  1083. {
  1084. struct sta_info *sta;
  1085. sta = ap_get_sta(hapd, mgmt->sa);
  1086. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  1087. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
  1088. "frame from unassociated STA " MACSTR,
  1089. MAC2STR(mgmt->sa));
  1090. return;
  1091. }
  1092. if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  1093. len - IEEE80211_HDRLEN))
  1094. break;
  1095. return;
  1096. }
  1097. #endif /* CONFIG_IEEE80211R */
  1098. case WLAN_ACTION_WMM:
  1099. hostapd_wme_action(hapd, mgmt, len);
  1100. return;
  1101. #ifdef CONFIG_IEEE80211W
  1102. case WLAN_ACTION_PING:
  1103. hostapd_ping_action(hapd, mgmt, len);
  1104. return;
  1105. #endif /* CONFIG_IEEE80211W */
  1106. }
  1107. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1108. HOSTAPD_LEVEL_DEBUG,
  1109. "handle_action - unknown action category %d or invalid "
  1110. "frame",
  1111. mgmt->u.action.category);
  1112. if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
  1113. !(mgmt->sa[0] & 0x01)) {
  1114. /*
  1115. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  1116. * Return the Action frame to the source without change
  1117. * except that MSB of the Category set to 1.
  1118. */
  1119. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  1120. "frame back to sender");
  1121. os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
  1122. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  1123. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  1124. mgmt->u.action.category |= 0x80;
  1125. hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
  1126. }
  1127. }
  1128. /**
  1129. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  1130. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  1131. * sent to)
  1132. * @buf: management frame data (starting from IEEE 802.11 header)
  1133. * @len: length of frame data in octets
  1134. * @stype: management frame subtype from frame control field
  1135. *
  1136. * Process all incoming IEEE 802.11 management frames. This will be called for
  1137. * each frame received from the kernel driver through wlan#ap interface. In
  1138. * addition, it can be called to re-inserted pending frames (e.g., when using
  1139. * external RADIUS server as an MAC ACL).
  1140. */
  1141. void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
  1142. struct hostapd_frame_info *fi)
  1143. {
  1144. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
  1145. int broadcast;
  1146. if (stype == WLAN_FC_STYPE_BEACON) {
  1147. handle_beacon(hapd, mgmt, len, fi);
  1148. return;
  1149. }
  1150. if (fi && fi->passive_scan)
  1151. return;
  1152. broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
  1153. mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
  1154. mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
  1155. if (!broadcast &&
  1156. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  1157. printf("MGMT: BSSID=" MACSTR " not our address\n",
  1158. MAC2STR(mgmt->bssid));
  1159. return;
  1160. }
  1161. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  1162. handle_probe_req(hapd, mgmt, len);
  1163. return;
  1164. }
  1165. if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  1166. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1167. HOSTAPD_LEVEL_DEBUG,
  1168. "MGMT: DA=" MACSTR " not our address",
  1169. MAC2STR(mgmt->da));
  1170. return;
  1171. }
  1172. switch (stype) {
  1173. case WLAN_FC_STYPE_AUTH:
  1174. wpa_printf(MSG_DEBUG, "mgmt::auth");
  1175. handle_auth(hapd, mgmt, len);
  1176. break;
  1177. case WLAN_FC_STYPE_ASSOC_REQ:
  1178. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  1179. handle_assoc(hapd, mgmt, len, 0);
  1180. break;
  1181. case WLAN_FC_STYPE_REASSOC_REQ:
  1182. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  1183. handle_assoc(hapd, mgmt, len, 1);
  1184. break;
  1185. case WLAN_FC_STYPE_DISASSOC:
  1186. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  1187. handle_disassoc(hapd, mgmt, len);
  1188. break;
  1189. case WLAN_FC_STYPE_DEAUTH:
  1190. wpa_printf(MSG_DEBUG, "mgmt::deauth");
  1191. handle_deauth(hapd, mgmt, len);
  1192. break;
  1193. case WLAN_FC_STYPE_ACTION:
  1194. wpa_printf(MSG_DEBUG, "mgmt::action");
  1195. handle_action(hapd, mgmt, len);
  1196. break;
  1197. default:
  1198. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1199. HOSTAPD_LEVEL_DEBUG,
  1200. "unknown mgmt frame subtype %d", stype);
  1201. break;
  1202. }
  1203. }
  1204. static void handle_auth_cb(struct hostapd_data *hapd,
  1205. struct ieee80211_mgmt *mgmt,
  1206. size_t len, int ok)
  1207. {
  1208. u16 auth_alg, auth_transaction, status_code;
  1209. struct sta_info *sta;
  1210. if (!ok) {
  1211. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1212. HOSTAPD_LEVEL_NOTICE,
  1213. "did not acknowledge authentication response");
  1214. return;
  1215. }
  1216. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  1217. printf("handle_auth_cb - too short payload (len=%lu)\n",
  1218. (unsigned long) len);
  1219. return;
  1220. }
  1221. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  1222. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  1223. status_code = le_to_host16(mgmt->u.auth.status_code);
  1224. sta = ap_get_sta(hapd, mgmt->da);
  1225. if (!sta) {
  1226. printf("handle_auth_cb: STA " MACSTR " not found\n",
  1227. MAC2STR(mgmt->da));
  1228. return;
  1229. }
  1230. if (status_code == WLAN_STATUS_SUCCESS &&
  1231. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  1232. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  1233. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1234. HOSTAPD_LEVEL_INFO, "authenticated");
  1235. sta->flags |= WLAN_STA_AUTH;
  1236. }
  1237. }
  1238. static void handle_assoc_cb(struct hostapd_data *hapd,
  1239. struct ieee80211_mgmt *mgmt,
  1240. size_t len, int reassoc, int ok)
  1241. {
  1242. u16 status;
  1243. struct sta_info *sta;
  1244. int new_assoc = 1;
  1245. struct ht_cap_ie *ht_cap = NULL;
  1246. if (!ok) {
  1247. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1248. HOSTAPD_LEVEL_DEBUG,
  1249. "did not acknowledge association response");
  1250. return;
  1251. }
  1252. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  1253. sizeof(mgmt->u.assoc_resp))) {
  1254. printf("handle_assoc_cb(reassoc=%d) - too short payload "
  1255. "(len=%lu)\n", reassoc, (unsigned long) len);
  1256. return;
  1257. }
  1258. if (reassoc)
  1259. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  1260. else
  1261. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  1262. sta = ap_get_sta(hapd, mgmt->da);
  1263. if (!sta) {
  1264. printf("handle_assoc_cb: STA " MACSTR " not found\n",
  1265. MAC2STR(mgmt->da));
  1266. return;
  1267. }
  1268. if (status != WLAN_STATUS_SUCCESS)
  1269. goto fail;
  1270. /* Stop previous accounting session, if one is started, and allocate
  1271. * new session id for the new session. */
  1272. accounting_sta_stop(hapd, sta);
  1273. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1274. HOSTAPD_LEVEL_INFO,
  1275. "associated (aid %d)",
  1276. sta->aid);
  1277. if (sta->flags & WLAN_STA_ASSOC)
  1278. new_assoc = 0;
  1279. sta->flags |= WLAN_STA_ASSOC;
  1280. if (reassoc)
  1281. mlme_reassociate_indication(hapd, sta);
  1282. else
  1283. mlme_associate_indication(hapd, sta);
  1284. #ifdef CONFIG_IEEE80211N
  1285. if (sta->flags & WLAN_STA_HT)
  1286. ht_cap = &sta->ht_capabilities;
  1287. #endif /* CONFIG_IEEE80211N */
  1288. #ifdef CONFIG_IEEE80211W
  1289. sta->ping_timed_out = 0;
  1290. #endif /* CONFIG_IEEE80211W */
  1291. if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
  1292. sta->capability, sta->supported_rates,
  1293. sta->supported_rates_len, 0, sta->listen_interval,
  1294. ht_cap))
  1295. {
  1296. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1297. HOSTAPD_LEVEL_NOTICE,
  1298. "Could not add STA to kernel driver");
  1299. }
  1300. if (sta->eapol_sm == NULL) {
  1301. /*
  1302. * This STA does not use RADIUS server for EAP authentication,
  1303. * so bind it to the selected VLAN interface now, since the
  1304. * interface selection is not going to change anymore.
  1305. */
  1306. ap_sta_bind_vlan(hapd, sta, 0);
  1307. } else if (sta->vlan_id) {
  1308. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  1309. ap_sta_bind_vlan(hapd, sta, 0);
  1310. }
  1311. if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
  1312. hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
  1313. WLAN_STA_SHORT_PREAMBLE, ~0);
  1314. } else {
  1315. hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
  1316. 0, ~WLAN_STA_SHORT_PREAMBLE);
  1317. }
  1318. if (sta->auth_alg == WLAN_AUTH_FT)
  1319. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  1320. else
  1321. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  1322. hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  1323. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  1324. fail:
  1325. /* Copy of the association request is not needed anymore */
  1326. if (sta->last_assoc_req) {
  1327. os_free(sta->last_assoc_req);
  1328. sta->last_assoc_req = NULL;
  1329. }
  1330. }
  1331. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
  1332. u16 stype, int ok)
  1333. {
  1334. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
  1335. switch (stype) {
  1336. case WLAN_FC_STYPE_AUTH:
  1337. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  1338. handle_auth_cb(hapd, mgmt, len, ok);
  1339. break;
  1340. case WLAN_FC_STYPE_ASSOC_RESP:
  1341. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  1342. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  1343. break;
  1344. case WLAN_FC_STYPE_REASSOC_RESP:
  1345. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  1346. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  1347. break;
  1348. case WLAN_FC_STYPE_PROBE_RESP:
  1349. wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
  1350. break;
  1351. case WLAN_FC_STYPE_DEAUTH:
  1352. /* ignore */
  1353. break;
  1354. case WLAN_FC_STYPE_ACTION:
  1355. wpa_printf(MSG_DEBUG, "mgmt::action cb");
  1356. break;
  1357. default:
  1358. printf("unknown mgmt cb frame subtype %d\n", stype);
  1359. break;
  1360. }
  1361. }
  1362. static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
  1363. void *timeout_ctx)
  1364. {
  1365. struct hostapd_data *hapd = eloop_ctx;
  1366. hapd->tkip_countermeasures = 0;
  1367. hostapd_set_countermeasures(hapd, 0);
  1368. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  1369. HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
  1370. }
  1371. static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
  1372. {
  1373. struct sta_info *sta;
  1374. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  1375. HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
  1376. wpa_auth_countermeasures_start(hapd->wpa_auth);
  1377. hapd->tkip_countermeasures = 1;
  1378. hostapd_set_countermeasures(hapd, 1);
  1379. wpa_gtk_rekey(hapd->wpa_auth);
  1380. eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
  1381. eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
  1382. hapd, NULL);
  1383. for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
  1384. hostapd_sta_deauth(hapd, sta->addr,
  1385. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1386. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1387. WLAN_STA_AUTHORIZED);
  1388. hostapd_sta_remove(hapd, sta->addr);
  1389. }
  1390. }
  1391. void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
  1392. int local)
  1393. {
  1394. time_t now;
  1395. if (addr && local) {
  1396. struct sta_info *sta = ap_get_sta(hapd, addr);
  1397. if (sta != NULL) {
  1398. wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
  1399. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  1400. HOSTAPD_LEVEL_INFO,
  1401. "Michael MIC failure detected in "
  1402. "received frame");
  1403. mlme_michaelmicfailure_indication(hapd, addr);
  1404. } else {
  1405. wpa_printf(MSG_DEBUG,
  1406. "MLME-MICHAELMICFAILURE.indication "
  1407. "for not associated STA (" MACSTR
  1408. ") ignored", MAC2STR(addr));
  1409. return;
  1410. }
  1411. }
  1412. time(&now);
  1413. if (now > hapd->michael_mic_failure + 60) {
  1414. hapd->michael_mic_failures = 1;
  1415. } else {
  1416. hapd->michael_mic_failures++;
  1417. if (hapd->michael_mic_failures > 1)
  1418. ieee80211_tkip_countermeasures_start(hapd);
  1419. }
  1420. hapd->michael_mic_failure = now;
  1421. }
  1422. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  1423. {
  1424. /* TODO */
  1425. return 0;
  1426. }
  1427. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  1428. char *buf, size_t buflen)
  1429. {
  1430. /* TODO */
  1431. return 0;
  1432. }
  1433. #endif /* CONFIG_NATIVE_WINDOWS */