ieee802_11.c 46 KB

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