ieee802_11.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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. if (hapd->conf->wpa && wpa_ie == NULL) {
  708. printf("STA " MACSTR ": No WPA/RSN IE in association "
  709. "request\n", MAC2STR(sta->addr));
  710. resp = WLAN_STATUS_INVALID_IE;
  711. goto fail;
  712. }
  713. if (hapd->conf->wpa && wpa_ie) {
  714. int res;
  715. wpa_ie -= 2;
  716. wpa_ie_len += 2;
  717. if (sta->wpa_sm == NULL)
  718. sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
  719. sta->addr);
  720. if (sta->wpa_sm == NULL) {
  721. printf("Failed to initialize WPA state machine\n");
  722. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  723. goto fail;
  724. }
  725. res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
  726. wpa_ie, wpa_ie_len,
  727. elems.mdie, elems.mdie_len);
  728. if (res == WPA_INVALID_GROUP)
  729. resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  730. else if (res == WPA_INVALID_PAIRWISE)
  731. resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  732. else if (res == WPA_INVALID_AKMP)
  733. resp = WLAN_STATUS_AKMP_NOT_VALID;
  734. else if (res == WPA_ALLOC_FAIL)
  735. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  736. #ifdef CONFIG_IEEE80211W
  737. else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
  738. resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
  739. else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
  740. resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
  741. #endif /* CONFIG_IEEE80211W */
  742. else if (res == WPA_INVALID_MDIE)
  743. resp = WLAN_STATUS_INVALID_MDIE;
  744. else if (res != WPA_IE_OK)
  745. resp = WLAN_STATUS_INVALID_IE;
  746. if (resp != WLAN_STATUS_SUCCESS)
  747. goto fail;
  748. #ifdef CONFIG_IEEE80211W
  749. if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
  750. /*
  751. * STA has already been associated with MFP and ping
  752. * timeout has not been reached. Reject the
  753. * association attempt temporarily and start ping, if
  754. * one is not pending.
  755. */
  756. if (sta->ping_count == 0)
  757. ap_sta_start_ping(hapd, sta);
  758. resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
  759. goto fail;
  760. }
  761. if (wpa_auth_uses_mfp(sta->wpa_sm))
  762. sta->flags |= WLAN_STA_MFP;
  763. else
  764. sta->flags &= ~WLAN_STA_MFP;
  765. #endif /* CONFIG_IEEE80211W */
  766. #ifdef CONFIG_IEEE80211R
  767. if (sta->auth_alg == WLAN_AUTH_FT) {
  768. if (!reassoc) {
  769. wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
  770. "to use association (not "
  771. "re-association) with FT auth_alg",
  772. MAC2STR(sta->addr));
  773. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  774. goto fail;
  775. }
  776. resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
  777. if (resp != WLAN_STATUS_SUCCESS)
  778. goto fail;
  779. }
  780. #endif /* CONFIG_IEEE80211R */
  781. }
  782. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  783. sta->flags |= WLAN_STA_NONERP;
  784. for (i = 0; i < sta->supported_rates_len; i++) {
  785. if ((sta->supported_rates[i] & 0x7f) > 22) {
  786. sta->flags &= ~WLAN_STA_NONERP;
  787. break;
  788. }
  789. }
  790. if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
  791. sta->nonerp_set = 1;
  792. hapd->iface->num_sta_non_erp++;
  793. if (hapd->iface->num_sta_non_erp == 1)
  794. ieee802_11_set_beacons(hapd->iface);
  795. }
  796. if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
  797. !sta->no_short_slot_time_set) {
  798. sta->no_short_slot_time_set = 1;
  799. hapd->iface->num_sta_no_short_slot_time++;
  800. if (hapd->iface->current_mode->mode ==
  801. HOSTAPD_MODE_IEEE80211G &&
  802. hapd->iface->num_sta_no_short_slot_time == 1)
  803. ieee802_11_set_beacons(hapd->iface);
  804. }
  805. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  806. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  807. else
  808. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  809. if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  810. !sta->no_short_preamble_set) {
  811. sta->no_short_preamble_set = 1;
  812. hapd->iface->num_sta_no_short_preamble++;
  813. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  814. && hapd->iface->num_sta_no_short_preamble == 1)
  815. ieee802_11_set_beacons(hapd->iface);
  816. }
  817. #ifdef CONFIG_IEEE80211N
  818. if (sta->flags & WLAN_STA_HT) {
  819. if ((sta->ht_capabilities.data.capabilities_info &
  820. HT_CAP_INFO_GREEN_FIELD) == 0) {
  821. hapd->iface->num_sta_ht_no_gf++;
  822. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
  823. "greenfield, num of non-gf stations %d",
  824. __func__, MAC2STR(sta->addr),
  825. hapd->iface->num_sta_ht_no_gf);
  826. }
  827. if ((sta->ht_capabilities.data.capabilities_info &
  828. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
  829. hapd->iface->num_sta_ht_20mhz++;
  830. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
  831. "num of 20MHz HT STAs %d",
  832. __func__, MAC2STR(sta->addr),
  833. hapd->iface->num_sta_ht_20mhz);
  834. }
  835. } else {
  836. hapd->iface->num_sta_no_ht++;
  837. if (hapd->iconf->ieee80211n) {
  838. wpa_printf(MSG_DEBUG, "%s STA " MACSTR
  839. " - no HT, num of non-HT stations %d",
  840. __func__, MAC2STR(sta->addr),
  841. hapd->iface->num_sta_no_ht);
  842. }
  843. }
  844. if (hostapd_ht_operation_update(hapd->iface) > 0)
  845. ieee802_11_set_beacons(hapd->iface);
  846. #endif /* CONFIG_IEEE80211N */
  847. /* get a unique AID */
  848. if (sta->aid > 0) {
  849. wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
  850. } else {
  851. for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
  852. if (hapd->sta_aid[sta->aid - 1] == NULL)
  853. break;
  854. if (sta->aid > MAX_AID_TABLE_SIZE) {
  855. sta->aid = 0;
  856. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  857. wpa_printf(MSG_ERROR, " no room for more AIDs");
  858. goto fail;
  859. } else {
  860. hapd->sta_aid[sta->aid - 1] = sta;
  861. wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
  862. }
  863. }
  864. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  865. HOSTAPD_LEVEL_DEBUG,
  866. "association OK (aid %d)", sta->aid);
  867. /* Station will be marked associated, after it acknowledges AssocResp
  868. */
  869. if (reassoc) {
  870. os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
  871. ETH_ALEN);
  872. }
  873. if (sta->last_assoc_req)
  874. os_free(sta->last_assoc_req);
  875. sta->last_assoc_req = os_malloc(len);
  876. if (sta->last_assoc_req)
  877. os_memcpy(sta->last_assoc_req, mgmt, len);
  878. /* Make sure that the previously registered inactivity timer will not
  879. * remove the STA immediately. */
  880. sta->timeout_next = STA_NULLFUNC;
  881. fail:
  882. os_memset(buf, 0, sizeof(buf));
  883. reply = (struct ieee80211_mgmt *) buf;
  884. reply->frame_control =
  885. IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  886. (send_deauth ? WLAN_FC_STYPE_DEAUTH :
  887. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  888. WLAN_FC_STYPE_ASSOC_RESP)));
  889. os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
  890. os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
  891. os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
  892. send_len = IEEE80211_HDRLEN;
  893. if (send_deauth) {
  894. send_len += sizeof(reply->u.deauth);
  895. reply->u.deauth.reason_code = host_to_le16(resp);
  896. } else {
  897. u8 *p;
  898. send_len += sizeof(reply->u.assoc_resp);
  899. reply->u.assoc_resp.capab_info =
  900. host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
  901. reply->u.assoc_resp.status_code = host_to_le16(resp);
  902. reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
  903. | BIT(14) | BIT(15));
  904. /* Supported rates */
  905. p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
  906. /* Extended supported rates */
  907. p = hostapd_eid_ext_supp_rates(hapd, p);
  908. if (sta->flags & WLAN_STA_WME)
  909. p = hostapd_eid_wme(hapd, p);
  910. p = hostapd_eid_ht_capabilities_info(hapd, p);
  911. p = hostapd_eid_ht_operation(hapd, p);
  912. #ifdef CONFIG_IEEE80211R
  913. if (resp == WLAN_STATUS_SUCCESS) {
  914. /* IEEE 802.11r: Mobility Domain Information, Fast BSS
  915. * Transition Information, RSN */
  916. p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
  917. buf + sizeof(buf) - p,
  918. sta->auth_alg);
  919. }
  920. #endif /* CONFIG_IEEE80211R */
  921. #ifdef CONFIG_IEEE80211W
  922. if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
  923. p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
  924. #endif /* CONFIG_IEEE80211W */
  925. send_len += p - reply->u.assoc_resp.variable;
  926. }
  927. if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
  928. perror("handle_assoc: send");
  929. }
  930. static void handle_disassoc(struct hostapd_data *hapd,
  931. struct ieee80211_mgmt *mgmt, size_t len)
  932. {
  933. struct sta_info *sta;
  934. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
  935. printf("handle_disassoc - too short payload (len=%lu)\n",
  936. (unsigned long) len);
  937. return;
  938. }
  939. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  940. MAC2STR(mgmt->sa),
  941. le_to_host16(mgmt->u.disassoc.reason_code));
  942. sta = ap_get_sta(hapd, mgmt->sa);
  943. if (sta == NULL) {
  944. printf("Station " MACSTR " trying to disassociate, but it "
  945. "is not associated.\n", MAC2STR(mgmt->sa));
  946. return;
  947. }
  948. sta->flags &= ~WLAN_STA_ASSOC;
  949. wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
  950. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  951. HOSTAPD_LEVEL_INFO, "disassociated");
  952. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  953. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  954. /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
  955. * authenticated. */
  956. accounting_sta_stop(hapd, sta);
  957. ieee802_1x_free_station(sta);
  958. hostapd_sta_remove(hapd, sta->addr);
  959. if (sta->timeout_next == STA_NULLFUNC ||
  960. sta->timeout_next == STA_DISASSOC) {
  961. sta->timeout_next = STA_DEAUTH;
  962. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  963. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  964. hapd, sta);
  965. }
  966. mlme_disassociate_indication(
  967. hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
  968. }
  969. static void handle_deauth(struct hostapd_data *hapd,
  970. struct ieee80211_mgmt *mgmt, size_t len)
  971. {
  972. struct sta_info *sta;
  973. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
  974. printf("handle_deauth - too short payload (len=%lu)\n",
  975. (unsigned long) len);
  976. return;
  977. }
  978. wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
  979. " reason_code=%d",
  980. MAC2STR(mgmt->sa),
  981. le_to_host16(mgmt->u.deauth.reason_code));
  982. sta = ap_get_sta(hapd, mgmt->sa);
  983. if (sta == NULL) {
  984. printf("Station " MACSTR " trying to deauthenticate, but it "
  985. "is not authenticated.\n", MAC2STR(mgmt->sa));
  986. return;
  987. }
  988. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  989. wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
  990. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  991. HOSTAPD_LEVEL_DEBUG, "deauthenticated");
  992. mlme_deauthenticate_indication(
  993. hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
  994. sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  995. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  996. ap_free_sta(hapd, sta);
  997. }
  998. static void handle_beacon(struct hostapd_data *hapd,
  999. struct ieee80211_mgmt *mgmt, size_t len,
  1000. struct hostapd_frame_info *fi)
  1001. {
  1002. struct ieee802_11_elems elems;
  1003. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
  1004. printf("handle_beacon - too short payload (len=%lu)\n",
  1005. (unsigned long) len);
  1006. return;
  1007. }
  1008. (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
  1009. len - (IEEE80211_HDRLEN +
  1010. sizeof(mgmt->u.beacon)), &elems,
  1011. 0);
  1012. ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
  1013. }
  1014. #ifdef CONFIG_IEEE80211W
  1015. static void hostapd_ping_action(struct hostapd_data *hapd,
  1016. struct ieee80211_mgmt *mgmt, size_t len)
  1017. {
  1018. struct sta_info *sta;
  1019. u8 *end;
  1020. int i;
  1021. end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
  1022. if (((u8 *) mgmt) + len < end) {
  1023. wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
  1024. "frame (len=%lu)", (unsigned long) len);
  1025. return;
  1026. }
  1027. if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
  1028. wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
  1029. mgmt->u.action.u.ping_resp.action);
  1030. return;
  1031. }
  1032. /* MLME-PING.confirm */
  1033. sta = ap_get_sta(hapd, mgmt->sa);
  1034. if (sta == NULL || sta->ping_trans_id == NULL) {
  1035. wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
  1036. "pending ping request found");
  1037. return;
  1038. }
  1039. for (i = 0; i < sta->ping_count; i++) {
  1040. if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
  1041. mgmt->u.action.u.ping_resp.trans_id,
  1042. WLAN_PING_TRANS_ID_LEN) == 0)
  1043. break;
  1044. }
  1045. if (i >= sta->ping_count) {
  1046. wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
  1047. "transaction identifier found");
  1048. return;
  1049. }
  1050. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1051. HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
  1052. ap_sta_stop_ping(hapd, sta);
  1053. }
  1054. #endif /* CONFIG_IEEE80211W */
  1055. static void handle_action(struct hostapd_data *hapd,
  1056. struct ieee80211_mgmt *mgmt, size_t len)
  1057. {
  1058. if (len < IEEE80211_HDRLEN + 1) {
  1059. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1060. HOSTAPD_LEVEL_DEBUG,
  1061. "handle_action - too short payload (len=%lu)",
  1062. (unsigned long) len);
  1063. return;
  1064. }
  1065. switch (mgmt->u.action.category) {
  1066. #ifdef CONFIG_IEEE80211R
  1067. case WLAN_ACTION_FT:
  1068. {
  1069. struct sta_info *sta;
  1070. sta = ap_get_sta(hapd, mgmt->sa);
  1071. if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
  1072. wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
  1073. "frame from unassociated STA " MACSTR,
  1074. MAC2STR(mgmt->sa));
  1075. return;
  1076. }
  1077. if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
  1078. len - IEEE80211_HDRLEN))
  1079. break;
  1080. return;
  1081. }
  1082. #endif /* CONFIG_IEEE80211R */
  1083. case WLAN_ACTION_WMM:
  1084. hostapd_wme_action(hapd, mgmt, len);
  1085. return;
  1086. #ifdef CONFIG_IEEE80211W
  1087. case WLAN_ACTION_PING:
  1088. hostapd_ping_action(hapd, mgmt, len);
  1089. return;
  1090. #endif /* CONFIG_IEEE80211W */
  1091. }
  1092. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1093. HOSTAPD_LEVEL_DEBUG,
  1094. "handle_action - unknown action category %d or invalid "
  1095. "frame",
  1096. mgmt->u.action.category);
  1097. if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
  1098. !(mgmt->sa[0] & 0x01)) {
  1099. /*
  1100. * IEEE 802.11-REVma/D9.0 - 7.3.1.11
  1101. * Return the Action frame to the source without change
  1102. * except that MSB of the Category set to 1.
  1103. */
  1104. wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
  1105. "frame back to sender");
  1106. os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
  1107. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  1108. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  1109. mgmt->u.action.category |= 0x80;
  1110. hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
  1111. }
  1112. }
  1113. /**
  1114. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  1115. * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  1116. * sent to)
  1117. * @buf: management frame data (starting from IEEE 802.11 header)
  1118. * @len: length of frame data in octets
  1119. * @stype: management frame subtype from frame control field
  1120. *
  1121. * Process all incoming IEEE 802.11 management frames. This will be called for
  1122. * each frame received from the kernel driver through wlan#ap interface. In
  1123. * addition, it can be called to re-inserted pending frames (e.g., when using
  1124. * external RADIUS server as an MAC ACL).
  1125. */
  1126. void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
  1127. struct hostapd_frame_info *fi)
  1128. {
  1129. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
  1130. int broadcast;
  1131. if (stype == WLAN_FC_STYPE_BEACON) {
  1132. handle_beacon(hapd, mgmt, len, fi);
  1133. return;
  1134. }
  1135. if (fi && fi->passive_scan)
  1136. return;
  1137. broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
  1138. mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
  1139. mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
  1140. if (!broadcast &&
  1141. os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
  1142. printf("MGMT: BSSID=" MACSTR " not our address\n",
  1143. MAC2STR(mgmt->bssid));
  1144. return;
  1145. }
  1146. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  1147. handle_probe_req(hapd, mgmt, len);
  1148. return;
  1149. }
  1150. if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
  1151. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1152. HOSTAPD_LEVEL_DEBUG,
  1153. "MGMT: DA=" MACSTR " not our address",
  1154. MAC2STR(mgmt->da));
  1155. return;
  1156. }
  1157. switch (stype) {
  1158. case WLAN_FC_STYPE_AUTH:
  1159. wpa_printf(MSG_DEBUG, "mgmt::auth");
  1160. handle_auth(hapd, mgmt, len);
  1161. break;
  1162. case WLAN_FC_STYPE_ASSOC_REQ:
  1163. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  1164. handle_assoc(hapd, mgmt, len, 0);
  1165. break;
  1166. case WLAN_FC_STYPE_REASSOC_REQ:
  1167. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  1168. handle_assoc(hapd, mgmt, len, 1);
  1169. break;
  1170. case WLAN_FC_STYPE_DISASSOC:
  1171. wpa_printf(MSG_DEBUG, "mgmt::disassoc");
  1172. handle_disassoc(hapd, mgmt, len);
  1173. break;
  1174. case WLAN_FC_STYPE_DEAUTH:
  1175. wpa_printf(MSG_DEBUG, "mgmt::deauth");
  1176. handle_deauth(hapd, mgmt, len);
  1177. break;
  1178. case WLAN_FC_STYPE_ACTION:
  1179. wpa_printf(MSG_DEBUG, "mgmt::action");
  1180. handle_action(hapd, mgmt, len);
  1181. break;
  1182. default:
  1183. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  1184. HOSTAPD_LEVEL_DEBUG,
  1185. "unknown mgmt frame subtype %d", stype);
  1186. break;
  1187. }
  1188. }
  1189. static void handle_auth_cb(struct hostapd_data *hapd,
  1190. struct ieee80211_mgmt *mgmt,
  1191. size_t len, int ok)
  1192. {
  1193. u16 auth_alg, auth_transaction, status_code;
  1194. struct sta_info *sta;
  1195. if (!ok) {
  1196. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1197. HOSTAPD_LEVEL_NOTICE,
  1198. "did not acknowledge authentication response");
  1199. return;
  1200. }
  1201. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  1202. printf("handle_auth_cb - too short payload (len=%lu)\n",
  1203. (unsigned long) len);
  1204. return;
  1205. }
  1206. auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  1207. auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
  1208. status_code = le_to_host16(mgmt->u.auth.status_code);
  1209. sta = ap_get_sta(hapd, mgmt->da);
  1210. if (!sta) {
  1211. printf("handle_auth_cb: STA " MACSTR " not found\n",
  1212. MAC2STR(mgmt->da));
  1213. return;
  1214. }
  1215. if (status_code == WLAN_STATUS_SUCCESS &&
  1216. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  1217. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  1218. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1219. HOSTAPD_LEVEL_INFO, "authenticated");
  1220. sta->flags |= WLAN_STA_AUTH;
  1221. }
  1222. }
  1223. static void handle_assoc_cb(struct hostapd_data *hapd,
  1224. struct ieee80211_mgmt *mgmt,
  1225. size_t len, int reassoc, int ok)
  1226. {
  1227. u16 status;
  1228. struct sta_info *sta;
  1229. int new_assoc = 1;
  1230. struct ht_cap_ie *ht_cap = NULL;
  1231. if (!ok) {
  1232. hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
  1233. HOSTAPD_LEVEL_DEBUG,
  1234. "did not acknowledge association response");
  1235. return;
  1236. }
  1237. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
  1238. sizeof(mgmt->u.assoc_resp))) {
  1239. printf("handle_assoc_cb(reassoc=%d) - too short payload "
  1240. "(len=%lu)\n", reassoc, (unsigned long) len);
  1241. return;
  1242. }
  1243. if (reassoc)
  1244. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  1245. else
  1246. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  1247. sta = ap_get_sta(hapd, mgmt->da);
  1248. if (!sta) {
  1249. printf("handle_assoc_cb: STA " MACSTR " not found\n",
  1250. MAC2STR(mgmt->da));
  1251. return;
  1252. }
  1253. if (status != WLAN_STATUS_SUCCESS)
  1254. goto fail;
  1255. /* Stop previous accounting session, if one is started, and allocate
  1256. * new session id for the new session. */
  1257. accounting_sta_stop(hapd, sta);
  1258. accounting_sta_get_id(hapd, sta);
  1259. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1260. HOSTAPD_LEVEL_INFO,
  1261. "associated (aid %d, accounting session %08X-%08X)",
  1262. sta->aid, sta->acct_session_id_hi,
  1263. sta->acct_session_id_lo);
  1264. if (sta->flags & WLAN_STA_ASSOC)
  1265. new_assoc = 0;
  1266. sta->flags |= WLAN_STA_ASSOC;
  1267. if (reassoc)
  1268. mlme_reassociate_indication(hapd, sta);
  1269. else
  1270. mlme_associate_indication(hapd, sta);
  1271. #ifdef CONFIG_IEEE80211N
  1272. if (sta->flags & WLAN_STA_HT)
  1273. ht_cap = &sta->ht_capabilities;
  1274. #endif /* CONFIG_IEEE80211N */
  1275. #ifdef CONFIG_IEEE80211W
  1276. sta->ping_timed_out = 0;
  1277. #endif /* CONFIG_IEEE80211W */
  1278. if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
  1279. sta->capability, sta->supported_rates,
  1280. sta->supported_rates_len, 0, sta->listen_interval,
  1281. ht_cap))
  1282. {
  1283. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  1284. HOSTAPD_LEVEL_NOTICE,
  1285. "Could not add STA to kernel driver");
  1286. }
  1287. if (sta->eapol_sm == NULL) {
  1288. /*
  1289. * This STA does not use RADIUS server for EAP authentication,
  1290. * so bind it to the selected VLAN interface now, since the
  1291. * interface selection is not going to change anymore.
  1292. */
  1293. ap_sta_bind_vlan(hapd, sta, 0);
  1294. } else if (sta->vlan_id) {
  1295. /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
  1296. ap_sta_bind_vlan(hapd, sta, 0);
  1297. }
  1298. if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
  1299. hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
  1300. WLAN_STA_SHORT_PREAMBLE, ~0);
  1301. } else {
  1302. hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
  1303. 0, ~WLAN_STA_SHORT_PREAMBLE);
  1304. }
  1305. if (sta->auth_alg == WLAN_AUTH_FT)
  1306. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
  1307. else
  1308. wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
  1309. hostapd_new_assoc_sta(hapd, sta, !new_assoc);
  1310. ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
  1311. fail:
  1312. /* Copy of the association request is not needed anymore */
  1313. if (sta->last_assoc_req) {
  1314. os_free(sta->last_assoc_req);
  1315. sta->last_assoc_req = NULL;
  1316. }
  1317. }
  1318. void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
  1319. u16 stype, int ok)
  1320. {
  1321. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
  1322. switch (stype) {
  1323. case WLAN_FC_STYPE_AUTH:
  1324. wpa_printf(MSG_DEBUG, "mgmt::auth cb");
  1325. handle_auth_cb(hapd, mgmt, len, ok);
  1326. break;
  1327. case WLAN_FC_STYPE_ASSOC_RESP:
  1328. wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
  1329. handle_assoc_cb(hapd, mgmt, len, 0, ok);
  1330. break;
  1331. case WLAN_FC_STYPE_REASSOC_RESP:
  1332. wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
  1333. handle_assoc_cb(hapd, mgmt, len, 1, ok);
  1334. break;
  1335. case WLAN_FC_STYPE_PROBE_RESP:
  1336. wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
  1337. break;
  1338. case WLAN_FC_STYPE_DEAUTH:
  1339. /* ignore */
  1340. break;
  1341. case WLAN_FC_STYPE_ACTION:
  1342. wpa_printf(MSG_DEBUG, "mgmt::action cb");
  1343. break;
  1344. default:
  1345. printf("unknown mgmt cb frame subtype %d\n", stype);
  1346. break;
  1347. }
  1348. }
  1349. static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
  1350. void *timeout_ctx)
  1351. {
  1352. struct hostapd_data *hapd = eloop_ctx;
  1353. hapd->tkip_countermeasures = 0;
  1354. hostapd_set_countermeasures(hapd, 0);
  1355. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  1356. HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
  1357. }
  1358. static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
  1359. {
  1360. struct sta_info *sta;
  1361. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  1362. HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
  1363. wpa_auth_countermeasures_start(hapd->wpa_auth);
  1364. hapd->tkip_countermeasures = 1;
  1365. hostapd_set_countermeasures(hapd, 1);
  1366. wpa_gtk_rekey(hapd->wpa_auth);
  1367. eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
  1368. eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
  1369. hapd, NULL);
  1370. for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
  1371. hostapd_sta_deauth(hapd, sta->addr,
  1372. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1373. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1374. WLAN_STA_AUTHORIZED);
  1375. hostapd_sta_remove(hapd, sta->addr);
  1376. }
  1377. }
  1378. void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
  1379. int local)
  1380. {
  1381. time_t now;
  1382. if (addr && local) {
  1383. struct sta_info *sta = ap_get_sta(hapd, addr);
  1384. if (sta != NULL) {
  1385. wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
  1386. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  1387. HOSTAPD_LEVEL_INFO,
  1388. "Michael MIC failure detected in "
  1389. "received frame");
  1390. mlme_michaelmicfailure_indication(hapd, addr);
  1391. } else {
  1392. wpa_printf(MSG_DEBUG,
  1393. "MLME-MICHAELMICFAILURE.indication "
  1394. "for not associated STA (" MACSTR
  1395. ") ignored", MAC2STR(addr));
  1396. return;
  1397. }
  1398. }
  1399. time(&now);
  1400. if (now > hapd->michael_mic_failure + 60) {
  1401. hapd->michael_mic_failures = 1;
  1402. } else {
  1403. hapd->michael_mic_failures++;
  1404. if (hapd->michael_mic_failures > 1)
  1405. ieee80211_tkip_countermeasures_start(hapd);
  1406. }
  1407. hapd->michael_mic_failure = now;
  1408. }
  1409. int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  1410. {
  1411. /* TODO */
  1412. return 0;
  1413. }
  1414. int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  1415. char *buf, size_t buflen)
  1416. {
  1417. /* TODO */
  1418. return 0;
  1419. }
  1420. #endif /* CONFIG_NATIVE_WINDOWS */