ieee802_1x.c 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668
  1. /*
  2. * hostapd / IEEE 802.1X-2004 Authenticator
  3. * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "crypto/md5.h"
  12. #include "crypto/crypto.h"
  13. #include "crypto/random.h"
  14. #include "common/ieee802_11_defs.h"
  15. #include "radius/radius.h"
  16. #include "radius/radius_client.h"
  17. #include "eap_server/eap.h"
  18. #include "eap_common/eap_wsc_common.h"
  19. #include "eapol_auth/eapol_auth_sm.h"
  20. #include "eapol_auth/eapol_auth_sm_i.h"
  21. #include "p2p/p2p.h"
  22. #include "hostapd.h"
  23. #include "accounting.h"
  24. #include "sta_info.h"
  25. #include "wpa_auth.h"
  26. #include "preauth_auth.h"
  27. #include "pmksa_cache_auth.h"
  28. #include "ap_config.h"
  29. #include "ap_drv_ops.h"
  30. #include "wps_hostapd.h"
  31. #include "hs20.h"
  32. #include "ieee802_1x.h"
  33. #ifdef CONFIG_HS20
  34. static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx);
  35. #endif /* CONFIG_HS20 */
  36. static void ieee802_1x_finished(struct hostapd_data *hapd,
  37. struct sta_info *sta, int success,
  38. int remediation);
  39. static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
  40. u8 type, const u8 *data, size_t datalen)
  41. {
  42. u8 *buf;
  43. struct ieee802_1x_hdr *xhdr;
  44. size_t len;
  45. int encrypt = 0;
  46. len = sizeof(*xhdr) + datalen;
  47. buf = os_zalloc(len);
  48. if (buf == NULL) {
  49. wpa_printf(MSG_ERROR, "malloc() failed for "
  50. "ieee802_1x_send(len=%lu)",
  51. (unsigned long) len);
  52. return;
  53. }
  54. xhdr = (struct ieee802_1x_hdr *) buf;
  55. xhdr->version = hapd->conf->eapol_version;
  56. xhdr->type = type;
  57. xhdr->length = host_to_be16(datalen);
  58. if (datalen > 0 && data != NULL)
  59. os_memcpy(xhdr + 1, data, datalen);
  60. if (wpa_auth_pairwise_set(sta->wpa_sm))
  61. encrypt = 1;
  62. #ifdef CONFIG_TESTING_OPTIONS
  63. if (hapd->ext_eapol_frame_io) {
  64. size_t hex_len = 2 * len + 1;
  65. char *hex = os_malloc(hex_len);
  66. if (hex) {
  67. wpa_snprintf_hex(hex, hex_len, buf, len);
  68. wpa_msg(hapd->msg_ctx, MSG_INFO,
  69. "EAPOL-TX " MACSTR " %s",
  70. MAC2STR(sta->addr), hex);
  71. os_free(hex);
  72. }
  73. } else
  74. #endif /* CONFIG_TESTING_OPTIONS */
  75. if (sta->flags & WLAN_STA_PREAUTH) {
  76. rsn_preauth_send(hapd, sta, buf, len);
  77. } else {
  78. hostapd_drv_hapd_send_eapol(
  79. hapd, sta->addr, buf, len,
  80. encrypt, hostapd_sta_flags_to_drv(sta->flags));
  81. }
  82. os_free(buf);
  83. }
  84. void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
  85. struct sta_info *sta, int authorized)
  86. {
  87. int res;
  88. if (sta->flags & WLAN_STA_PREAUTH)
  89. return;
  90. if (authorized) {
  91. ap_sta_set_authorized(hapd, sta, 1);
  92. res = hostapd_set_authorized(hapd, sta, 1);
  93. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  94. HOSTAPD_LEVEL_DEBUG, "authorizing port");
  95. } else {
  96. ap_sta_set_authorized(hapd, sta, 0);
  97. res = hostapd_set_authorized(hapd, sta, 0);
  98. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  99. HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
  100. }
  101. if (res && errno != ENOENT) {
  102. wpa_printf(MSG_DEBUG, "Could not set station " MACSTR
  103. " flags for kernel driver (errno=%d).",
  104. MAC2STR(sta->addr), errno);
  105. }
  106. if (authorized) {
  107. os_get_reltime(&sta->connected_time);
  108. accounting_sta_start(hapd, sta);
  109. }
  110. }
  111. #ifndef CONFIG_FIPS
  112. #ifndef CONFIG_NO_RC4
  113. static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
  114. struct sta_info *sta,
  115. int idx, int broadcast,
  116. u8 *key_data, size_t key_len)
  117. {
  118. u8 *buf, *ekey;
  119. struct ieee802_1x_hdr *hdr;
  120. struct ieee802_1x_eapol_key *key;
  121. size_t len, ekey_len;
  122. struct eapol_state_machine *sm = sta->eapol_sm;
  123. if (sm == NULL)
  124. return;
  125. len = sizeof(*key) + key_len;
  126. buf = os_zalloc(sizeof(*hdr) + len);
  127. if (buf == NULL)
  128. return;
  129. hdr = (struct ieee802_1x_hdr *) buf;
  130. key = (struct ieee802_1x_eapol_key *) (hdr + 1);
  131. key->type = EAPOL_KEY_TYPE_RC4;
  132. WPA_PUT_BE16(key->key_length, key_len);
  133. wpa_get_ntp_timestamp(key->replay_counter);
  134. if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
  135. wpa_printf(MSG_ERROR, "Could not get random numbers");
  136. os_free(buf);
  137. return;
  138. }
  139. key->key_index = idx | (broadcast ? 0 : BIT(7));
  140. if (hapd->conf->eapol_key_index_workaround) {
  141. /* According to some information, WinXP Supplicant seems to
  142. * interpret bit7 as an indication whether the key is to be
  143. * activated, so make it possible to enable workaround that
  144. * sets this bit for all keys. */
  145. key->key_index |= BIT(7);
  146. }
  147. /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
  148. * MSK[32..63] is used to sign the message. */
  149. if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
  150. wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
  151. "and signing EAPOL-Key");
  152. os_free(buf);
  153. return;
  154. }
  155. os_memcpy((u8 *) (key + 1), key_data, key_len);
  156. ekey_len = sizeof(key->key_iv) + 32;
  157. ekey = os_malloc(ekey_len);
  158. if (ekey == NULL) {
  159. wpa_printf(MSG_ERROR, "Could not encrypt key");
  160. os_free(buf);
  161. return;
  162. }
  163. os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
  164. os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
  165. rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
  166. os_free(ekey);
  167. /* This header is needed here for HMAC-MD5, but it will be regenerated
  168. * in ieee802_1x_send() */
  169. hdr->version = hapd->conf->eapol_version;
  170. hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
  171. hdr->length = host_to_be16(len);
  172. hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
  173. key->key_signature);
  174. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
  175. " (%s index=%d)", MAC2STR(sm->addr),
  176. broadcast ? "broadcast" : "unicast", idx);
  177. ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
  178. if (sta->eapol_sm)
  179. sta->eapol_sm->dot1xAuthEapolFramesTx++;
  180. os_free(buf);
  181. }
  182. static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
  183. {
  184. struct eapol_authenticator *eapol = hapd->eapol_auth;
  185. struct eapol_state_machine *sm = sta->eapol_sm;
  186. if (sm == NULL || !sm->eap_if->eapKeyData)
  187. return;
  188. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
  189. MAC2STR(sta->addr));
  190. #ifndef CONFIG_NO_VLAN
  191. if (sta->vlan_id > 0) {
  192. wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
  193. return;
  194. }
  195. #endif /* CONFIG_NO_VLAN */
  196. if (eapol->default_wep_key) {
  197. ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
  198. eapol->default_wep_key,
  199. hapd->conf->default_wep_key_len);
  200. }
  201. if (hapd->conf->individual_wep_key_len > 0) {
  202. u8 *ikey;
  203. ikey = os_malloc(hapd->conf->individual_wep_key_len);
  204. if (ikey == NULL ||
  205. random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
  206. {
  207. wpa_printf(MSG_ERROR, "Could not generate random "
  208. "individual WEP key.");
  209. os_free(ikey);
  210. return;
  211. }
  212. wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
  213. ikey, hapd->conf->individual_wep_key_len);
  214. ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
  215. hapd->conf->individual_wep_key_len);
  216. /* TODO: set encryption in TX callback, i.e., only after STA
  217. * has ACKed EAPOL-Key frame */
  218. if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
  219. sta->addr, 0, 1, NULL, 0, ikey,
  220. hapd->conf->individual_wep_key_len)) {
  221. wpa_printf(MSG_ERROR, "Could not set individual WEP "
  222. "encryption.");
  223. }
  224. os_free(ikey);
  225. }
  226. }
  227. #endif /* CONFIG_NO_RC4 */
  228. #endif /* CONFIG_FIPS */
  229. const char *radius_mode_txt(struct hostapd_data *hapd)
  230. {
  231. switch (hapd->iface->conf->hw_mode) {
  232. case HOSTAPD_MODE_IEEE80211AD:
  233. return "802.11ad";
  234. case HOSTAPD_MODE_IEEE80211A:
  235. return "802.11a";
  236. case HOSTAPD_MODE_IEEE80211G:
  237. return "802.11g";
  238. case HOSTAPD_MODE_IEEE80211B:
  239. default:
  240. return "802.11b";
  241. }
  242. }
  243. int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
  244. {
  245. int i;
  246. u8 rate = 0;
  247. for (i = 0; i < sta->supported_rates_len; i++)
  248. if ((sta->supported_rates[i] & 0x7f) > rate)
  249. rate = sta->supported_rates[i] & 0x7f;
  250. return rate;
  251. }
  252. #ifndef CONFIG_NO_RADIUS
  253. static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
  254. struct eapol_state_machine *sm,
  255. const u8 *eap, size_t len)
  256. {
  257. const u8 *identity;
  258. size_t identity_len;
  259. const struct eap_hdr *hdr = (const struct eap_hdr *) eap;
  260. if (len <= sizeof(struct eap_hdr) ||
  261. (hdr->code == EAP_CODE_RESPONSE &&
  262. eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) ||
  263. (hdr->code == EAP_CODE_INITIATE &&
  264. eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) ||
  265. (hdr->code != EAP_CODE_RESPONSE &&
  266. hdr->code != EAP_CODE_INITIATE))
  267. return;
  268. identity = eap_get_identity(sm->eap, &identity_len);
  269. if (identity == NULL)
  270. return;
  271. /* Save station identity for future RADIUS packets */
  272. os_free(sm->identity);
  273. sm->identity = (u8 *) dup_binstr(identity, identity_len);
  274. if (sm->identity == NULL) {
  275. sm->identity_len = 0;
  276. return;
  277. }
  278. sm->identity_len = identity_len;
  279. hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
  280. HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
  281. sm->dot1xAuthEapolRespIdFramesRx++;
  282. }
  283. static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd,
  284. struct hostapd_radius_attr *req_attr,
  285. struct sta_info *sta,
  286. struct radius_msg *msg)
  287. {
  288. u32 suite;
  289. int ver, val;
  290. ver = wpa_auth_sta_wpa_version(sta->wpa_sm);
  291. val = wpa_auth_get_pairwise(sta->wpa_sm);
  292. suite = wpa_cipher_to_suite(ver, val);
  293. if (val != -1 &&
  294. !hostapd_config_get_radius_attr(req_attr,
  295. RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) &&
  296. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER,
  297. suite)) {
  298. wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher");
  299. return -1;
  300. }
  301. suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) ||
  302. hapd->conf->osen) ?
  303. WPA_PROTO_RSN : WPA_PROTO_WPA,
  304. hapd->conf->wpa_group);
  305. if (!hostapd_config_get_radius_attr(req_attr,
  306. RADIUS_ATTR_WLAN_GROUP_CIPHER) &&
  307. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER,
  308. suite)) {
  309. wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher");
  310. return -1;
  311. }
  312. val = wpa_auth_sta_key_mgmt(sta->wpa_sm);
  313. suite = wpa_akm_to_suite(val);
  314. if (val != -1 &&
  315. !hostapd_config_get_radius_attr(req_attr,
  316. RADIUS_ATTR_WLAN_AKM_SUITE) &&
  317. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE,
  318. suite)) {
  319. wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite");
  320. return -1;
  321. }
  322. #ifdef CONFIG_IEEE80211W
  323. if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  324. suite = wpa_cipher_to_suite(WPA_PROTO_RSN,
  325. hapd->conf->group_mgmt_cipher);
  326. if (!hostapd_config_get_radius_attr(
  327. req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) &&
  328. !radius_msg_add_attr_int32(
  329. msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) {
  330. wpa_printf(MSG_ERROR,
  331. "Could not add WLAN-Group-Mgmt-Cipher");
  332. return -1;
  333. }
  334. }
  335. #endif /* CONFIG_IEEE80211W */
  336. return 0;
  337. }
  338. static int add_common_radius_sta_attr(struct hostapd_data *hapd,
  339. struct hostapd_radius_attr *req_attr,
  340. struct sta_info *sta,
  341. struct radius_msg *msg)
  342. {
  343. char buf[128];
  344. if (!hostapd_config_get_radius_attr(req_attr,
  345. RADIUS_ATTR_NAS_PORT) &&
  346. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
  347. wpa_printf(MSG_ERROR, "Could not add NAS-Port");
  348. return -1;
  349. }
  350. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  351. MAC2STR(sta->addr));
  352. buf[sizeof(buf) - 1] = '\0';
  353. if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
  354. (u8 *) buf, os_strlen(buf))) {
  355. wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id");
  356. return -1;
  357. }
  358. if (sta->flags & WLAN_STA_PREAUTH) {
  359. os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
  360. sizeof(buf));
  361. } else {
  362. os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
  363. radius_sta_rate(hapd, sta) / 2,
  364. (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
  365. radius_mode_txt(hapd));
  366. buf[sizeof(buf) - 1] = '\0';
  367. }
  368. if (!hostapd_config_get_radius_attr(req_attr,
  369. RADIUS_ATTR_CONNECT_INFO) &&
  370. !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
  371. (u8 *) buf, os_strlen(buf))) {
  372. wpa_printf(MSG_ERROR, "Could not add Connect-Info");
  373. return -1;
  374. }
  375. if (sta->acct_session_id) {
  376. os_snprintf(buf, sizeof(buf), "%016lX",
  377. (long unsigned int) sta->acct_session_id);
  378. if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
  379. (u8 *) buf, os_strlen(buf))) {
  380. wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
  381. return -1;
  382. }
  383. }
  384. if ((hapd->conf->wpa & 2) &&
  385. !hapd->conf->disable_pmksa_caching &&
  386. sta->eapol_sm && sta->eapol_sm->acct_multi_session_id) {
  387. os_snprintf(buf, sizeof(buf), "%016lX",
  388. (long unsigned int)
  389. sta->eapol_sm->acct_multi_session_id);
  390. if (!radius_msg_add_attr(
  391. msg, RADIUS_ATTR_ACCT_MULTI_SESSION_ID,
  392. (u8 *) buf, os_strlen(buf))) {
  393. wpa_printf(MSG_INFO,
  394. "Could not add Acct-Multi-Session-Id");
  395. return -1;
  396. }
  397. }
  398. #ifdef CONFIG_IEEE80211R
  399. if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
  400. sta->wpa_sm &&
  401. (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) ||
  402. sta->auth_alg == WLAN_AUTH_FT) &&
  403. !hostapd_config_get_radius_attr(req_attr,
  404. RADIUS_ATTR_MOBILITY_DOMAIN_ID) &&
  405. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID,
  406. WPA_GET_BE16(
  407. hapd->conf->mobility_domain))) {
  408. wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id");
  409. return -1;
  410. }
  411. #endif /* CONFIG_IEEE80211R */
  412. if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm &&
  413. add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0)
  414. return -1;
  415. return 0;
  416. }
  417. int add_common_radius_attr(struct hostapd_data *hapd,
  418. struct hostapd_radius_attr *req_attr,
  419. struct sta_info *sta,
  420. struct radius_msg *msg)
  421. {
  422. char buf[128];
  423. struct hostapd_radius_attr *attr;
  424. int len;
  425. if (!hostapd_config_get_radius_attr(req_attr,
  426. RADIUS_ATTR_NAS_IP_ADDRESS) &&
  427. hapd->conf->own_ip_addr.af == AF_INET &&
  428. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
  429. (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
  430. wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address");
  431. return -1;
  432. }
  433. #ifdef CONFIG_IPV6
  434. if (!hostapd_config_get_radius_attr(req_attr,
  435. RADIUS_ATTR_NAS_IPV6_ADDRESS) &&
  436. hapd->conf->own_ip_addr.af == AF_INET6 &&
  437. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
  438. (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
  439. wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address");
  440. return -1;
  441. }
  442. #endif /* CONFIG_IPV6 */
  443. if (!hostapd_config_get_radius_attr(req_attr,
  444. RADIUS_ATTR_NAS_IDENTIFIER) &&
  445. hapd->conf->nas_identifier &&
  446. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
  447. (u8 *) hapd->conf->nas_identifier,
  448. os_strlen(hapd->conf->nas_identifier))) {
  449. wpa_printf(MSG_ERROR, "Could not add NAS-Identifier");
  450. return -1;
  451. }
  452. len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
  453. MAC2STR(hapd->own_addr));
  454. os_memcpy(&buf[len], hapd->conf->ssid.ssid,
  455. hapd->conf->ssid.ssid_len);
  456. len += hapd->conf->ssid.ssid_len;
  457. if (!hostapd_config_get_radius_attr(req_attr,
  458. RADIUS_ATTR_CALLED_STATION_ID) &&
  459. !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
  460. (u8 *) buf, len)) {
  461. wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
  462. return -1;
  463. }
  464. if (!hostapd_config_get_radius_attr(req_attr,
  465. RADIUS_ATTR_NAS_PORT_TYPE) &&
  466. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
  467. RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
  468. wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type");
  469. return -1;
  470. }
  471. #ifdef CONFIG_INTERWORKING
  472. if (hapd->conf->interworking &&
  473. !is_zero_ether_addr(hapd->conf->hessid)) {
  474. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  475. MAC2STR(hapd->conf->hessid));
  476. buf[sizeof(buf) - 1] = '\0';
  477. if (!hostapd_config_get_radius_attr(req_attr,
  478. RADIUS_ATTR_WLAN_HESSID) &&
  479. !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID,
  480. (u8 *) buf, os_strlen(buf))) {
  481. wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID");
  482. return -1;
  483. }
  484. }
  485. #endif /* CONFIG_INTERWORKING */
  486. if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0)
  487. return -1;
  488. for (attr = req_attr; attr; attr = attr->next) {
  489. if (!radius_msg_add_attr(msg, attr->type,
  490. wpabuf_head(attr->val),
  491. wpabuf_len(attr->val))) {
  492. wpa_printf(MSG_ERROR, "Could not add RADIUS "
  493. "attribute");
  494. return -1;
  495. }
  496. }
  497. return 0;
  498. }
  499. static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
  500. struct sta_info *sta,
  501. const u8 *eap, size_t len)
  502. {
  503. struct radius_msg *msg;
  504. struct eapol_state_machine *sm = sta->eapol_sm;
  505. if (sm == NULL)
  506. return;
  507. ieee802_1x_learn_identity(hapd, sm, eap, len);
  508. wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
  509. "packet");
  510. sm->radius_identifier = radius_client_get_id(hapd->radius);
  511. msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
  512. sm->radius_identifier);
  513. if (msg == NULL) {
  514. wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
  515. return;
  516. }
  517. if (radius_msg_make_authenticator(msg) < 0) {
  518. wpa_printf(MSG_INFO, "Could not make Request Authenticator");
  519. goto fail;
  520. }
  521. if (sm->identity &&
  522. !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
  523. sm->identity, sm->identity_len)) {
  524. wpa_printf(MSG_INFO, "Could not add User-Name");
  525. goto fail;
  526. }
  527. if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
  528. msg) < 0)
  529. goto fail;
  530. /* TODO: should probably check MTU from driver config; 2304 is max for
  531. * IEEE 802.11, but use 1400 to avoid problems with too large packets
  532. */
  533. if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
  534. RADIUS_ATTR_FRAMED_MTU) &&
  535. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
  536. wpa_printf(MSG_INFO, "Could not add Framed-MTU");
  537. goto fail;
  538. }
  539. if (!radius_msg_add_eap(msg, eap, len)) {
  540. wpa_printf(MSG_INFO, "Could not add EAP-Message");
  541. goto fail;
  542. }
  543. /* State attribute must be copied if and only if this packet is
  544. * Access-Request reply to the previous Access-Challenge */
  545. if (sm->last_recv_radius &&
  546. radius_msg_get_hdr(sm->last_recv_radius)->code ==
  547. RADIUS_CODE_ACCESS_CHALLENGE) {
  548. int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
  549. RADIUS_ATTR_STATE);
  550. if (res < 0) {
  551. wpa_printf(MSG_INFO, "Could not copy State attribute from previous Access-Challenge");
  552. goto fail;
  553. }
  554. if (res > 0) {
  555. wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
  556. }
  557. }
  558. if (hapd->conf->radius_request_cui) {
  559. const u8 *cui;
  560. size_t cui_len;
  561. /* Add previously learned CUI or nul CUI to request CUI */
  562. if (sm->radius_cui) {
  563. cui = wpabuf_head(sm->radius_cui);
  564. cui_len = wpabuf_len(sm->radius_cui);
  565. } else {
  566. cui = (const u8 *) "\0";
  567. cui_len = 1;
  568. }
  569. if (!radius_msg_add_attr(msg,
  570. RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
  571. cui, cui_len)) {
  572. wpa_printf(MSG_ERROR, "Could not add CUI");
  573. goto fail;
  574. }
  575. }
  576. #ifdef CONFIG_HS20
  577. if (hapd->conf->hs20) {
  578. u8 ver = 1; /* Release 2 */
  579. if (!radius_msg_add_wfa(
  580. msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION,
  581. &ver, 1)) {
  582. wpa_printf(MSG_ERROR, "Could not add HS 2.0 AP "
  583. "version");
  584. goto fail;
  585. }
  586. if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) {
  587. const u8 *pos;
  588. u8 buf[3];
  589. u16 id;
  590. pos = wpabuf_head_u8(sta->hs20_ie);
  591. buf[0] = (*pos) >> 4;
  592. if (((*pos) & HS20_PPS_MO_ID_PRESENT) &&
  593. wpabuf_len(sta->hs20_ie) >= 3)
  594. id = WPA_GET_LE16(pos + 1);
  595. else
  596. id = 0;
  597. WPA_PUT_BE16(buf + 1, id);
  598. if (!radius_msg_add_wfa(
  599. msg,
  600. RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION,
  601. buf, sizeof(buf))) {
  602. wpa_printf(MSG_ERROR, "Could not add HS 2.0 "
  603. "STA version");
  604. goto fail;
  605. }
  606. }
  607. }
  608. #endif /* CONFIG_HS20 */
  609. if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
  610. goto fail;
  611. return;
  612. fail:
  613. radius_msg_free(msg);
  614. }
  615. #endif /* CONFIG_NO_RADIUS */
  616. static void handle_eap_response(struct hostapd_data *hapd,
  617. struct sta_info *sta, struct eap_hdr *eap,
  618. size_t len)
  619. {
  620. u8 type, *data;
  621. struct eapol_state_machine *sm = sta->eapol_sm;
  622. if (sm == NULL)
  623. return;
  624. data = (u8 *) (eap + 1);
  625. if (len < sizeof(*eap) + 1) {
  626. wpa_printf(MSG_INFO, "handle_eap_response: too short response data");
  627. return;
  628. }
  629. sm->eap_type_supp = type = data[0];
  630. hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
  631. HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
  632. "id=%d len=%d) from STA: EAP Response-%s (%d)",
  633. eap->code, eap->identifier, be_to_host16(eap->length),
  634. eap_server_get_name(0, type), type);
  635. sm->dot1xAuthEapolRespFramesRx++;
  636. wpabuf_free(sm->eap_if->eapRespData);
  637. sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
  638. sm->eapolEap = TRUE;
  639. }
  640. static void handle_eap_initiate(struct hostapd_data *hapd,
  641. struct sta_info *sta, struct eap_hdr *eap,
  642. size_t len)
  643. {
  644. #ifdef CONFIG_ERP
  645. u8 type, *data;
  646. struct eapol_state_machine *sm = sta->eapol_sm;
  647. if (sm == NULL)
  648. return;
  649. if (len < sizeof(*eap) + 1) {
  650. wpa_printf(MSG_INFO,
  651. "handle_eap_initiate: too short response data");
  652. return;
  653. }
  654. data = (u8 *) (eap + 1);
  655. type = data[0];
  656. hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
  657. HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
  658. "id=%d len=%d) from STA: EAP Initiate type %u",
  659. eap->code, eap->identifier, be_to_host16(eap->length),
  660. type);
  661. wpabuf_free(sm->eap_if->eapRespData);
  662. sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
  663. sm->eapolEap = TRUE;
  664. #endif /* CONFIG_ERP */
  665. }
  666. /* Process incoming EAP packet from Supplicant */
  667. static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
  668. u8 *buf, size_t len)
  669. {
  670. struct eap_hdr *eap;
  671. u16 eap_len;
  672. if (len < sizeof(*eap)) {
  673. wpa_printf(MSG_INFO, " too short EAP packet");
  674. return;
  675. }
  676. eap = (struct eap_hdr *) buf;
  677. eap_len = be_to_host16(eap->length);
  678. wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
  679. eap->code, eap->identifier, eap_len);
  680. if (eap_len < sizeof(*eap)) {
  681. wpa_printf(MSG_DEBUG, " Invalid EAP length");
  682. return;
  683. } else if (eap_len > len) {
  684. wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
  685. "packet");
  686. return;
  687. } else if (eap_len < len) {
  688. wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
  689. "packet", (unsigned long) len - eap_len);
  690. }
  691. switch (eap->code) {
  692. case EAP_CODE_REQUEST:
  693. wpa_printf(MSG_DEBUG, " (request)");
  694. return;
  695. case EAP_CODE_RESPONSE:
  696. wpa_printf(MSG_DEBUG, " (response)");
  697. handle_eap_response(hapd, sta, eap, eap_len);
  698. break;
  699. case EAP_CODE_SUCCESS:
  700. wpa_printf(MSG_DEBUG, " (success)");
  701. return;
  702. case EAP_CODE_FAILURE:
  703. wpa_printf(MSG_DEBUG, " (failure)");
  704. return;
  705. case EAP_CODE_INITIATE:
  706. wpa_printf(MSG_DEBUG, " (initiate)");
  707. handle_eap_initiate(hapd, sta, eap, eap_len);
  708. break;
  709. case EAP_CODE_FINISH:
  710. wpa_printf(MSG_DEBUG, " (finish)");
  711. break;
  712. default:
  713. wpa_printf(MSG_DEBUG, " (unknown code)");
  714. return;
  715. }
  716. }
  717. static struct eapol_state_machine *
  718. ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
  719. {
  720. int flags = 0;
  721. if (sta->flags & WLAN_STA_PREAUTH)
  722. flags |= EAPOL_SM_PREAUTH;
  723. if (sta->wpa_sm) {
  724. flags |= EAPOL_SM_USES_WPA;
  725. if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
  726. flags |= EAPOL_SM_FROM_PMKSA_CACHE;
  727. }
  728. return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
  729. sta->wps_ie, sta->p2p_ie, sta,
  730. sta->identity, sta->radius_cui);
  731. }
  732. /**
  733. * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
  734. * @hapd: hostapd BSS data
  735. * @sa: Source address (sender of the EAPOL frame)
  736. * @buf: EAPOL frame
  737. * @len: Length of buf in octets
  738. *
  739. * This function is called for each incoming EAPOL frame from the interface
  740. */
  741. void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
  742. size_t len)
  743. {
  744. struct sta_info *sta;
  745. struct ieee802_1x_hdr *hdr;
  746. struct ieee802_1x_eapol_key *key;
  747. u16 datalen;
  748. struct rsn_pmksa_cache_entry *pmksa;
  749. int key_mgmt;
  750. if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen &&
  751. !hapd->conf->wps_state)
  752. return;
  753. wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
  754. (unsigned long) len, MAC2STR(sa));
  755. sta = ap_get_sta(hapd, sa);
  756. if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
  757. !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
  758. wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
  759. "associated/Pre-authenticating STA");
  760. return;
  761. }
  762. if (len < sizeof(*hdr)) {
  763. wpa_printf(MSG_INFO, " too short IEEE 802.1X packet");
  764. return;
  765. }
  766. hdr = (struct ieee802_1x_hdr *) buf;
  767. datalen = be_to_host16(hdr->length);
  768. wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
  769. hdr->version, hdr->type, datalen);
  770. if (len - sizeof(*hdr) < datalen) {
  771. wpa_printf(MSG_INFO, " frame too short for this IEEE 802.1X packet");
  772. if (sta->eapol_sm)
  773. sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
  774. return;
  775. }
  776. if (len - sizeof(*hdr) > datalen) {
  777. wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
  778. "IEEE 802.1X packet",
  779. (unsigned long) len - sizeof(*hdr) - datalen);
  780. }
  781. if (sta->eapol_sm) {
  782. sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
  783. sta->eapol_sm->dot1xAuthEapolFramesRx++;
  784. }
  785. key = (struct ieee802_1x_eapol_key *) (hdr + 1);
  786. if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
  787. hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
  788. (key->type == EAPOL_KEY_TYPE_WPA ||
  789. key->type == EAPOL_KEY_TYPE_RSN)) {
  790. wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
  791. sizeof(*hdr) + datalen);
  792. return;
  793. }
  794. if (!hapd->conf->ieee802_1x && !hapd->conf->osen &&
  795. !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
  796. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
  797. "802.1X not enabled and WPS not used");
  798. return;
  799. }
  800. key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
  801. if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
  802. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
  803. "STA is using PSK");
  804. return;
  805. }
  806. if (!sta->eapol_sm) {
  807. sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
  808. if (!sta->eapol_sm)
  809. return;
  810. #ifdef CONFIG_WPS
  811. if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) {
  812. u32 wflags = sta->flags & (WLAN_STA_WPS |
  813. WLAN_STA_WPS2 |
  814. WLAN_STA_MAYBE_WPS);
  815. if (wflags == WLAN_STA_MAYBE_WPS ||
  816. wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
  817. /*
  818. * Delay EAPOL frame transmission until a
  819. * possible WPS STA initiates the handshake
  820. * with EAPOL-Start. Only allow the wait to be
  821. * skipped if the STA is known to support WPS
  822. * 2.0.
  823. */
  824. wpa_printf(MSG_DEBUG, "WPS: Do not start "
  825. "EAPOL until EAPOL-Start is "
  826. "received");
  827. sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
  828. }
  829. }
  830. #endif /* CONFIG_WPS */
  831. sta->eapol_sm->eap_if->portEnabled = TRUE;
  832. }
  833. /* since we support version 1, we can ignore version field and proceed
  834. * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
  835. /* TODO: actually, we are not version 1 anymore.. However, Version 2
  836. * does not change frame contents, so should be ok to process frames
  837. * more or less identically. Some changes might be needed for
  838. * verification of fields. */
  839. switch (hdr->type) {
  840. case IEEE802_1X_TYPE_EAP_PACKET:
  841. handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
  842. break;
  843. case IEEE802_1X_TYPE_EAPOL_START:
  844. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  845. HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
  846. "from STA");
  847. sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
  848. pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  849. if (pmksa) {
  850. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
  851. HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
  852. "available - ignore it since "
  853. "STA sent EAPOL-Start");
  854. wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
  855. }
  856. sta->eapol_sm->eapolStart = TRUE;
  857. sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
  858. eap_server_clear_identity(sta->eapol_sm->eap);
  859. wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
  860. break;
  861. case IEEE802_1X_TYPE_EAPOL_LOGOFF:
  862. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  863. HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
  864. "from STA");
  865. sta->acct_terminate_cause =
  866. RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  867. accounting_sta_stop(hapd, sta);
  868. sta->eapol_sm->eapolLogoff = TRUE;
  869. sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
  870. eap_server_clear_identity(sta->eapol_sm->eap);
  871. break;
  872. case IEEE802_1X_TYPE_EAPOL_KEY:
  873. wpa_printf(MSG_DEBUG, " EAPOL-Key");
  874. if (!ap_sta_is_authorized(sta)) {
  875. wpa_printf(MSG_DEBUG, " Dropped key data from "
  876. "unauthorized Supplicant");
  877. break;
  878. }
  879. break;
  880. case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
  881. wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
  882. /* TODO: implement support for this; show data */
  883. break;
  884. default:
  885. wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
  886. sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
  887. break;
  888. }
  889. eapol_auth_step(sta->eapol_sm);
  890. }
  891. /**
  892. * ieee802_1x_new_station - Start IEEE 802.1X authentication
  893. * @hapd: hostapd BSS data
  894. * @sta: The station
  895. *
  896. * This function is called to start IEEE 802.1X authentication when a new
  897. * station completes IEEE 802.11 association.
  898. */
  899. void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
  900. {
  901. struct rsn_pmksa_cache_entry *pmksa;
  902. int reassoc = 1;
  903. int force_1x = 0;
  904. int key_mgmt;
  905. #ifdef CONFIG_WPS
  906. if (hapd->conf->wps_state &&
  907. ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) ||
  908. (sta->flags & WLAN_STA_WPS))) {
  909. /*
  910. * Need to enable IEEE 802.1X/EAPOL state machines for possible
  911. * WPS handshake even if IEEE 802.1X/EAPOL is not used for
  912. * authentication in this BSS.
  913. */
  914. force_1x = 1;
  915. }
  916. #endif /* CONFIG_WPS */
  917. if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) {
  918. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
  919. "802.1X not enabled or forced for WPS");
  920. /*
  921. * Clear any possible EAPOL authenticator state to support
  922. * reassociation change from WPS to PSK.
  923. */
  924. ieee802_1x_free_station(hapd, sta);
  925. return;
  926. }
  927. key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
  928. if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
  929. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
  930. /*
  931. * Clear any possible EAPOL authenticator state to support
  932. * reassociation change from WPA-EAP to PSK.
  933. */
  934. ieee802_1x_free_station(hapd, sta);
  935. return;
  936. }
  937. if (sta->eapol_sm == NULL) {
  938. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  939. HOSTAPD_LEVEL_DEBUG, "start authentication");
  940. sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
  941. if (sta->eapol_sm == NULL) {
  942. hostapd_logger(hapd, sta->addr,
  943. HOSTAPD_MODULE_IEEE8021X,
  944. HOSTAPD_LEVEL_INFO,
  945. "failed to allocate state machine");
  946. return;
  947. }
  948. reassoc = 0;
  949. }
  950. #ifdef CONFIG_WPS
  951. sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
  952. if (!hapd->conf->ieee802_1x && hapd->conf->wps_state &&
  953. !(sta->flags & WLAN_STA_WPS2)) {
  954. /*
  955. * Delay EAPOL frame transmission until a possible WPS STA
  956. * initiates the handshake with EAPOL-Start. Only allow the
  957. * wait to be skipped if the STA is known to support WPS 2.0.
  958. */
  959. wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
  960. "EAPOL-Start is received");
  961. sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
  962. }
  963. #endif /* CONFIG_WPS */
  964. sta->eapol_sm->eap_if->portEnabled = TRUE;
  965. #ifdef CONFIG_IEEE80211R
  966. if (sta->auth_alg == WLAN_AUTH_FT) {
  967. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  968. HOSTAPD_LEVEL_DEBUG,
  969. "PMK from FT - skip IEEE 802.1X/EAP");
  970. /* Setup EAPOL state machines to already authenticated state
  971. * because of existing FT information from R0KH. */
  972. sta->eapol_sm->keyRun = TRUE;
  973. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  974. sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
  975. sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
  976. sta->eapol_sm->authSuccess = TRUE;
  977. sta->eapol_sm->authFail = FALSE;
  978. sta->eapol_sm->portValid = TRUE;
  979. if (sta->eapol_sm->eap)
  980. eap_sm_notify_cached(sta->eapol_sm->eap);
  981. /* TODO: get vlan_id from R0KH using RRB message */
  982. return;
  983. }
  984. #endif /* CONFIG_IEEE80211R */
  985. pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  986. if (pmksa) {
  987. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  988. HOSTAPD_LEVEL_DEBUG,
  989. "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
  990. /* Setup EAPOL state machines to already authenticated state
  991. * because of existing PMKSA information in the cache. */
  992. sta->eapol_sm->keyRun = TRUE;
  993. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  994. sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
  995. sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
  996. sta->eapol_sm->authSuccess = TRUE;
  997. sta->eapol_sm->authFail = FALSE;
  998. if (sta->eapol_sm->eap)
  999. eap_sm_notify_cached(sta->eapol_sm->eap);
  1000. pmksa_cache_to_eapol_data(hapd, pmksa, sta->eapol_sm);
  1001. ap_sta_bind_vlan(hapd, sta);
  1002. } else {
  1003. if (reassoc) {
  1004. /*
  1005. * Force EAPOL state machines to start
  1006. * re-authentication without having to wait for the
  1007. * Supplicant to send EAPOL-Start.
  1008. */
  1009. sta->eapol_sm->reAuthenticate = TRUE;
  1010. }
  1011. eapol_auth_step(sta->eapol_sm);
  1012. }
  1013. }
  1014. void ieee802_1x_free_station(struct hostapd_data *hapd, struct sta_info *sta)
  1015. {
  1016. struct eapol_state_machine *sm = sta->eapol_sm;
  1017. #ifdef CONFIG_HS20
  1018. eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
  1019. #endif /* CONFIG_HS20 */
  1020. if (sm == NULL)
  1021. return;
  1022. sta->eapol_sm = NULL;
  1023. #ifndef CONFIG_NO_RADIUS
  1024. radius_msg_free(sm->last_recv_radius);
  1025. radius_free_class(&sm->radius_class);
  1026. #endif /* CONFIG_NO_RADIUS */
  1027. eapol_auth_free(sm);
  1028. }
  1029. #ifndef CONFIG_NO_RADIUS
  1030. static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
  1031. struct sta_info *sta)
  1032. {
  1033. struct wpabuf *eap;
  1034. const struct eap_hdr *hdr;
  1035. int eap_type = -1;
  1036. char buf[64];
  1037. struct radius_msg *msg;
  1038. struct eapol_state_machine *sm = sta->eapol_sm;
  1039. if (sm == NULL || sm->last_recv_radius == NULL) {
  1040. if (sm)
  1041. sm->eap_if->aaaEapNoReq = TRUE;
  1042. return;
  1043. }
  1044. msg = sm->last_recv_radius;
  1045. eap = radius_msg_get_eap(msg);
  1046. if (eap == NULL) {
  1047. /* RFC 3579, Chap. 2.6.3:
  1048. * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
  1049. * attribute */
  1050. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1051. HOSTAPD_LEVEL_WARNING, "could not extract "
  1052. "EAP-Message from RADIUS message");
  1053. sm->eap_if->aaaEapNoReq = TRUE;
  1054. return;
  1055. }
  1056. if (wpabuf_len(eap) < sizeof(*hdr)) {
  1057. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1058. HOSTAPD_LEVEL_WARNING, "too short EAP packet "
  1059. "received from authentication server");
  1060. wpabuf_free(eap);
  1061. sm->eap_if->aaaEapNoReq = TRUE;
  1062. return;
  1063. }
  1064. if (wpabuf_len(eap) > sizeof(*hdr))
  1065. eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)];
  1066. hdr = wpabuf_head(eap);
  1067. switch (hdr->code) {
  1068. case EAP_CODE_REQUEST:
  1069. if (eap_type >= 0)
  1070. sm->eap_type_authsrv = eap_type;
  1071. os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
  1072. eap_server_get_name(0, eap_type), eap_type);
  1073. break;
  1074. case EAP_CODE_RESPONSE:
  1075. os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
  1076. eap_server_get_name(0, eap_type), eap_type);
  1077. break;
  1078. case EAP_CODE_SUCCESS:
  1079. os_strlcpy(buf, "EAP Success", sizeof(buf));
  1080. break;
  1081. case EAP_CODE_FAILURE:
  1082. os_strlcpy(buf, "EAP Failure", sizeof(buf));
  1083. break;
  1084. default:
  1085. os_strlcpy(buf, "unknown EAP code", sizeof(buf));
  1086. break;
  1087. }
  1088. buf[sizeof(buf) - 1] = '\0';
  1089. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1090. HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
  1091. "id=%d len=%d) from RADIUS server: %s",
  1092. hdr->code, hdr->identifier, be_to_host16(hdr->length),
  1093. buf);
  1094. sm->eap_if->aaaEapReq = TRUE;
  1095. wpabuf_free(sm->eap_if->aaaEapReqData);
  1096. sm->eap_if->aaaEapReqData = eap;
  1097. }
  1098. static void ieee802_1x_get_keys(struct hostapd_data *hapd,
  1099. struct sta_info *sta, struct radius_msg *msg,
  1100. struct radius_msg *req,
  1101. const u8 *shared_secret,
  1102. size_t shared_secret_len)
  1103. {
  1104. struct radius_ms_mppe_keys *keys;
  1105. struct eapol_state_machine *sm = sta->eapol_sm;
  1106. if (sm == NULL)
  1107. return;
  1108. keys = radius_msg_get_ms_keys(msg, req, shared_secret,
  1109. shared_secret_len);
  1110. if (keys && keys->send && keys->recv) {
  1111. size_t len = keys->send_len + keys->recv_len;
  1112. wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
  1113. keys->send, keys->send_len);
  1114. wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
  1115. keys->recv, keys->recv_len);
  1116. os_free(sm->eap_if->aaaEapKeyData);
  1117. sm->eap_if->aaaEapKeyData = os_malloc(len);
  1118. if (sm->eap_if->aaaEapKeyData) {
  1119. os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
  1120. keys->recv_len);
  1121. os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
  1122. keys->send, keys->send_len);
  1123. sm->eap_if->aaaEapKeyDataLen = len;
  1124. sm->eap_if->aaaEapKeyAvailable = TRUE;
  1125. }
  1126. } else {
  1127. wpa_printf(MSG_DEBUG,
  1128. "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
  1129. keys, keys ? keys->send : NULL,
  1130. keys ? keys->recv : NULL);
  1131. }
  1132. if (keys) {
  1133. os_free(keys->send);
  1134. os_free(keys->recv);
  1135. os_free(keys);
  1136. }
  1137. }
  1138. static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
  1139. struct sta_info *sta,
  1140. struct radius_msg *msg)
  1141. {
  1142. u8 *attr_class;
  1143. size_t class_len;
  1144. struct eapol_state_machine *sm = sta->eapol_sm;
  1145. int count, i;
  1146. struct radius_attr_data *nclass;
  1147. size_t nclass_count;
  1148. if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
  1149. sm == NULL)
  1150. return;
  1151. radius_free_class(&sm->radius_class);
  1152. count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
  1153. if (count <= 0)
  1154. return;
  1155. nclass = os_calloc(count, sizeof(struct radius_attr_data));
  1156. if (nclass == NULL)
  1157. return;
  1158. nclass_count = 0;
  1159. attr_class = NULL;
  1160. for (i = 0; i < count; i++) {
  1161. do {
  1162. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
  1163. &attr_class, &class_len,
  1164. attr_class) < 0) {
  1165. i = count;
  1166. break;
  1167. }
  1168. } while (class_len < 1);
  1169. nclass[nclass_count].data = os_malloc(class_len);
  1170. if (nclass[nclass_count].data == NULL)
  1171. break;
  1172. os_memcpy(nclass[nclass_count].data, attr_class, class_len);
  1173. nclass[nclass_count].len = class_len;
  1174. nclass_count++;
  1175. }
  1176. sm->radius_class.attr = nclass;
  1177. sm->radius_class.count = nclass_count;
  1178. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
  1179. "attributes for " MACSTR,
  1180. (unsigned long) sm->radius_class.count,
  1181. MAC2STR(sta->addr));
  1182. }
  1183. /* Update sta->identity based on User-Name attribute in Access-Accept */
  1184. static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
  1185. struct sta_info *sta,
  1186. struct radius_msg *msg)
  1187. {
  1188. u8 *buf, *identity;
  1189. size_t len;
  1190. struct eapol_state_machine *sm = sta->eapol_sm;
  1191. if (sm == NULL)
  1192. return;
  1193. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
  1194. NULL) < 0)
  1195. return;
  1196. identity = (u8 *) dup_binstr(buf, len);
  1197. if (identity == NULL)
  1198. return;
  1199. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1200. HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
  1201. "User-Name from Access-Accept '%s'",
  1202. sm->identity ? (char *) sm->identity : "N/A",
  1203. (char *) identity);
  1204. os_free(sm->identity);
  1205. sm->identity = identity;
  1206. sm->identity_len = len;
  1207. }
  1208. /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
  1209. static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
  1210. struct sta_info *sta,
  1211. struct radius_msg *msg)
  1212. {
  1213. struct eapol_state_machine *sm = sta->eapol_sm;
  1214. struct wpabuf *cui;
  1215. u8 *buf;
  1216. size_t len;
  1217. if (sm == NULL)
  1218. return;
  1219. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
  1220. &buf, &len, NULL) < 0)
  1221. return;
  1222. cui = wpabuf_alloc_copy(buf, len);
  1223. if (cui == NULL)
  1224. return;
  1225. wpabuf_free(sm->radius_cui);
  1226. sm->radius_cui = cui;
  1227. }
  1228. #ifdef CONFIG_HS20
  1229. static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len)
  1230. {
  1231. sta->remediation = 1;
  1232. os_free(sta->remediation_url);
  1233. if (len > 2) {
  1234. sta->remediation_url = os_malloc(len);
  1235. if (!sta->remediation_url)
  1236. return;
  1237. sta->remediation_method = pos[0];
  1238. os_memcpy(sta->remediation_url, pos + 1, len - 1);
  1239. sta->remediation_url[len - 1] = '\0';
  1240. wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
  1241. "for " MACSTR " - server method %u URL %s",
  1242. MAC2STR(sta->addr), sta->remediation_method,
  1243. sta->remediation_url);
  1244. } else {
  1245. sta->remediation_url = NULL;
  1246. wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
  1247. "for " MACSTR, MAC2STR(sta->addr));
  1248. }
  1249. /* TODO: assign the STA into remediation VLAN or add filtering */
  1250. }
  1251. static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd,
  1252. struct sta_info *sta, u8 *pos,
  1253. size_t len)
  1254. {
  1255. if (len < 3)
  1256. return; /* Malformed information */
  1257. sta->hs20_deauth_requested = 1;
  1258. wpa_printf(MSG_DEBUG, "HS 2.0: Deauthentication request - Code %u "
  1259. "Re-auth Delay %u",
  1260. *pos, WPA_GET_LE16(pos + 1));
  1261. wpabuf_free(sta->hs20_deauth_req);
  1262. sta->hs20_deauth_req = wpabuf_alloc(len + 1);
  1263. if (sta->hs20_deauth_req) {
  1264. wpabuf_put_data(sta->hs20_deauth_req, pos, 3);
  1265. wpabuf_put_u8(sta->hs20_deauth_req, len - 3);
  1266. wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3);
  1267. }
  1268. ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout);
  1269. }
  1270. static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd,
  1271. struct sta_info *sta, u8 *pos,
  1272. size_t len, int session_timeout)
  1273. {
  1274. unsigned int swt;
  1275. int warning_time, beacon_int;
  1276. if (len < 1)
  1277. return; /* Malformed information */
  1278. os_free(sta->hs20_session_info_url);
  1279. sta->hs20_session_info_url = os_malloc(len);
  1280. if (sta->hs20_session_info_url == NULL)
  1281. return;
  1282. swt = pos[0];
  1283. os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1);
  1284. sta->hs20_session_info_url[len - 1] = '\0';
  1285. wpa_printf(MSG_DEBUG, "HS 2.0: Session Information URL='%s' SWT=%u "
  1286. "(session_timeout=%d)",
  1287. sta->hs20_session_info_url, swt, session_timeout);
  1288. if (session_timeout < 0) {
  1289. wpa_printf(MSG_DEBUG, "HS 2.0: No Session-Timeout set - ignore session info URL");
  1290. return;
  1291. }
  1292. if (swt == 255)
  1293. swt = 1; /* Use one minute as the AP selected value */
  1294. if ((unsigned int) session_timeout < swt * 60)
  1295. warning_time = 0;
  1296. else
  1297. warning_time = session_timeout - swt * 60;
  1298. beacon_int = hapd->iconf->beacon_int;
  1299. if (beacon_int < 1)
  1300. beacon_int = 100; /* best guess */
  1301. sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128;
  1302. if (sta->hs20_disassoc_timer > 65535)
  1303. sta->hs20_disassoc_timer = 65535;
  1304. ap_sta_session_warning_timeout(hapd, sta, warning_time);
  1305. }
  1306. #endif /* CONFIG_HS20 */
  1307. static void ieee802_1x_check_hs20(struct hostapd_data *hapd,
  1308. struct sta_info *sta,
  1309. struct radius_msg *msg,
  1310. int session_timeout)
  1311. {
  1312. #ifdef CONFIG_HS20
  1313. u8 *buf, *pos, *end, type, sublen;
  1314. size_t len;
  1315. buf = NULL;
  1316. sta->remediation = 0;
  1317. sta->hs20_deauth_requested = 0;
  1318. for (;;) {
  1319. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC,
  1320. &buf, &len, buf) < 0)
  1321. break;
  1322. if (len < 6)
  1323. continue;
  1324. pos = buf;
  1325. end = buf + len;
  1326. if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA)
  1327. continue;
  1328. pos += 4;
  1329. type = *pos++;
  1330. sublen = *pos++;
  1331. if (sublen < 2)
  1332. continue; /* invalid length */
  1333. sublen -= 2; /* skip header */
  1334. if (pos + sublen > end)
  1335. continue; /* invalid WFA VSA */
  1336. switch (type) {
  1337. case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION:
  1338. ieee802_1x_hs20_sub_rem(sta, pos, sublen);
  1339. break;
  1340. case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ:
  1341. ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen);
  1342. break;
  1343. case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL:
  1344. ieee802_1x_hs20_session_info(hapd, sta, pos, sublen,
  1345. session_timeout);
  1346. break;
  1347. }
  1348. }
  1349. #endif /* CONFIG_HS20 */
  1350. }
  1351. struct sta_id_search {
  1352. u8 identifier;
  1353. struct eapol_state_machine *sm;
  1354. };
  1355. static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
  1356. struct sta_info *sta,
  1357. void *ctx)
  1358. {
  1359. struct sta_id_search *id_search = ctx;
  1360. struct eapol_state_machine *sm = sta->eapol_sm;
  1361. if (sm && sm->radius_identifier >= 0 &&
  1362. sm->radius_identifier == id_search->identifier) {
  1363. id_search->sm = sm;
  1364. return 1;
  1365. }
  1366. return 0;
  1367. }
  1368. static struct eapol_state_machine *
  1369. ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
  1370. {
  1371. struct sta_id_search id_search;
  1372. id_search.identifier = identifier;
  1373. id_search.sm = NULL;
  1374. ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
  1375. return id_search.sm;
  1376. }
  1377. /**
  1378. * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
  1379. * @msg: RADIUS response message
  1380. * @req: RADIUS request message
  1381. * @shared_secret: RADIUS shared secret
  1382. * @shared_secret_len: Length of shared_secret in octets
  1383. * @data: Context data (struct hostapd_data *)
  1384. * Returns: Processing status
  1385. */
  1386. static RadiusRxResult
  1387. ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
  1388. const u8 *shared_secret, size_t shared_secret_len,
  1389. void *data)
  1390. {
  1391. struct hostapd_data *hapd = data;
  1392. struct sta_info *sta;
  1393. u32 session_timeout = 0, termination_action, acct_interim_interval;
  1394. int session_timeout_set;
  1395. struct eapol_state_machine *sm;
  1396. int override_eapReq = 0;
  1397. struct radius_hdr *hdr = radius_msg_get_hdr(msg);
  1398. struct vlan_description vlan_desc;
  1399. #ifndef CONFIG_NO_VLAN
  1400. int *untagged, *tagged, *notempty;
  1401. #endif /* CONFIG_NO_VLAN */
  1402. os_memset(&vlan_desc, 0, sizeof(vlan_desc));
  1403. sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
  1404. if (sm == NULL) {
  1405. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
  1406. "station for this RADIUS message");
  1407. return RADIUS_RX_UNKNOWN;
  1408. }
  1409. sta = sm->sta;
  1410. /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
  1411. * present when packet contains an EAP-Message attribute */
  1412. if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
  1413. radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
  1414. 0) < 0 &&
  1415. radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
  1416. wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
  1417. "Message-Authenticator since it does not include "
  1418. "EAP-Message");
  1419. } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
  1420. req, 1)) {
  1421. wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
  1422. return RADIUS_RX_INVALID_AUTHENTICATOR;
  1423. }
  1424. if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
  1425. hdr->code != RADIUS_CODE_ACCESS_REJECT &&
  1426. hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
  1427. wpa_printf(MSG_INFO, "Unknown RADIUS message code");
  1428. return RADIUS_RX_UNKNOWN;
  1429. }
  1430. sm->radius_identifier = -1;
  1431. wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
  1432. MAC2STR(sta->addr));
  1433. radius_msg_free(sm->last_recv_radius);
  1434. sm->last_recv_radius = msg;
  1435. session_timeout_set =
  1436. !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
  1437. &session_timeout);
  1438. if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
  1439. &termination_action))
  1440. termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
  1441. if (hapd->conf->acct_interim_interval == 0 &&
  1442. hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
  1443. radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
  1444. &acct_interim_interval) == 0) {
  1445. if (acct_interim_interval < 60) {
  1446. hostapd_logger(hapd, sta->addr,
  1447. HOSTAPD_MODULE_IEEE8021X,
  1448. HOSTAPD_LEVEL_INFO,
  1449. "ignored too small "
  1450. "Acct-Interim-Interval %d",
  1451. acct_interim_interval);
  1452. } else
  1453. sta->acct_interim_interval = acct_interim_interval;
  1454. }
  1455. switch (hdr->code) {
  1456. case RADIUS_CODE_ACCESS_ACCEPT:
  1457. #ifndef CONFIG_NO_VLAN
  1458. if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED) {
  1459. notempty = &vlan_desc.notempty;
  1460. untagged = &vlan_desc.untagged;
  1461. tagged = vlan_desc.tagged;
  1462. *notempty = !!radius_msg_get_vlanid(msg, untagged,
  1463. MAX_NUM_TAGGED_VLAN,
  1464. tagged);
  1465. }
  1466. if (vlan_desc.notempty &&
  1467. !hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
  1468. sta->eapol_sm->authFail = TRUE;
  1469. hostapd_logger(hapd, sta->addr,
  1470. HOSTAPD_MODULE_RADIUS,
  1471. HOSTAPD_LEVEL_INFO,
  1472. "Invalid VLAN %d%s received from RADIUS server",
  1473. vlan_desc.untagged,
  1474. vlan_desc.tagged[0] ? "+" : "");
  1475. os_memset(&vlan_desc, 0, sizeof(vlan_desc));
  1476. ap_sta_set_vlan(hapd, sta, &vlan_desc);
  1477. break;
  1478. }
  1479. if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
  1480. !vlan_desc.notempty) {
  1481. sta->eapol_sm->authFail = TRUE;
  1482. hostapd_logger(hapd, sta->addr,
  1483. HOSTAPD_MODULE_IEEE8021X,
  1484. HOSTAPD_LEVEL_INFO, "authentication "
  1485. "server did not include required VLAN "
  1486. "ID in Access-Accept");
  1487. break;
  1488. }
  1489. #endif /* CONFIG_NO_VLAN */
  1490. if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0)
  1491. break;
  1492. #ifndef CONFIG_NO_VLAN
  1493. if (sta->vlan_id > 0) {
  1494. hostapd_logger(hapd, sta->addr,
  1495. HOSTAPD_MODULE_RADIUS,
  1496. HOSTAPD_LEVEL_INFO,
  1497. "VLAN ID %d", sta->vlan_id);
  1498. }
  1499. #endif /* CONFIG_NO_VLAN */
  1500. if ((sta->flags & WLAN_STA_ASSOC) &&
  1501. ap_sta_bind_vlan(hapd, sta) < 0)
  1502. break;
  1503. sta->session_timeout_set = !!session_timeout_set;
  1504. sta->session_timeout = session_timeout;
  1505. /* RFC 3580, Ch. 3.17 */
  1506. if (session_timeout_set && termination_action ==
  1507. RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
  1508. sm->reAuthPeriod = session_timeout;
  1509. } else if (session_timeout_set)
  1510. ap_sta_session_timeout(hapd, sta, session_timeout);
  1511. sm->eap_if->aaaSuccess = TRUE;
  1512. override_eapReq = 1;
  1513. ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
  1514. shared_secret_len);
  1515. ieee802_1x_store_radius_class(hapd, sta, msg);
  1516. ieee802_1x_update_sta_identity(hapd, sta, msg);
  1517. ieee802_1x_update_sta_cui(hapd, sta, msg);
  1518. ieee802_1x_check_hs20(hapd, sta, msg,
  1519. session_timeout_set ?
  1520. (int) session_timeout : -1);
  1521. break;
  1522. case RADIUS_CODE_ACCESS_REJECT:
  1523. sm->eap_if->aaaFail = TRUE;
  1524. override_eapReq = 1;
  1525. break;
  1526. case RADIUS_CODE_ACCESS_CHALLENGE:
  1527. sm->eap_if->aaaEapReq = TRUE;
  1528. if (session_timeout_set) {
  1529. /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
  1530. sm->eap_if->aaaMethodTimeout = session_timeout;
  1531. hostapd_logger(hapd, sm->addr,
  1532. HOSTAPD_MODULE_IEEE8021X,
  1533. HOSTAPD_LEVEL_DEBUG,
  1534. "using EAP timeout of %d seconds (from "
  1535. "RADIUS)",
  1536. sm->eap_if->aaaMethodTimeout);
  1537. } else {
  1538. /*
  1539. * Use dynamic retransmission behavior per EAP
  1540. * specification.
  1541. */
  1542. sm->eap_if->aaaMethodTimeout = 0;
  1543. }
  1544. break;
  1545. }
  1546. ieee802_1x_decapsulate_radius(hapd, sta);
  1547. if (override_eapReq)
  1548. sm->eap_if->aaaEapReq = FALSE;
  1549. eapol_auth_step(sm);
  1550. return RADIUS_RX_QUEUED;
  1551. }
  1552. #endif /* CONFIG_NO_RADIUS */
  1553. void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
  1554. {
  1555. struct eapol_state_machine *sm = sta->eapol_sm;
  1556. if (sm == NULL)
  1557. return;
  1558. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1559. HOSTAPD_LEVEL_DEBUG, "aborting authentication");
  1560. #ifndef CONFIG_NO_RADIUS
  1561. radius_msg_free(sm->last_recv_radius);
  1562. sm->last_recv_radius = NULL;
  1563. #endif /* CONFIG_NO_RADIUS */
  1564. if (sm->eap_if->eapTimeout) {
  1565. /*
  1566. * Disconnect the STA since it did not reply to the last EAP
  1567. * request and we cannot continue EAP processing (EAP-Failure
  1568. * could only be sent if the EAP peer actually replied).
  1569. */
  1570. wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
  1571. MAC2STR(sta->addr));
  1572. sm->eap_if->portEnabled = FALSE;
  1573. ap_sta_disconnect(hapd, sta, sta->addr,
  1574. WLAN_REASON_PREV_AUTH_NOT_VALID);
  1575. }
  1576. }
  1577. static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
  1578. {
  1579. struct eapol_authenticator *eapol = hapd->eapol_auth;
  1580. if (hapd->conf->default_wep_key_len < 1)
  1581. return 0;
  1582. os_free(eapol->default_wep_key);
  1583. eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
  1584. if (eapol->default_wep_key == NULL ||
  1585. random_get_bytes(eapol->default_wep_key,
  1586. hapd->conf->default_wep_key_len)) {
  1587. wpa_printf(MSG_INFO, "Could not generate random WEP key");
  1588. os_free(eapol->default_wep_key);
  1589. eapol->default_wep_key = NULL;
  1590. return -1;
  1591. }
  1592. wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
  1593. eapol->default_wep_key,
  1594. hapd->conf->default_wep_key_len);
  1595. return 0;
  1596. }
  1597. static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
  1598. struct sta_info *sta, void *ctx)
  1599. {
  1600. if (sta->eapol_sm) {
  1601. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  1602. eapol_auth_step(sta->eapol_sm);
  1603. }
  1604. return 0;
  1605. }
  1606. static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
  1607. {
  1608. struct hostapd_data *hapd = eloop_ctx;
  1609. struct eapol_authenticator *eapol = hapd->eapol_auth;
  1610. if (eapol->default_wep_key_idx >= 3)
  1611. eapol->default_wep_key_idx =
  1612. hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
  1613. else
  1614. eapol->default_wep_key_idx++;
  1615. wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
  1616. eapol->default_wep_key_idx);
  1617. if (ieee802_1x_rekey_broadcast(hapd)) {
  1618. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
  1619. HOSTAPD_LEVEL_WARNING, "failed to generate a "
  1620. "new broadcast key");
  1621. os_free(eapol->default_wep_key);
  1622. eapol->default_wep_key = NULL;
  1623. return;
  1624. }
  1625. /* TODO: Could setup key for RX here, but change default TX keyid only
  1626. * after new broadcast key has been sent to all stations. */
  1627. if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
  1628. broadcast_ether_addr,
  1629. eapol->default_wep_key_idx, 1, NULL, 0,
  1630. eapol->default_wep_key,
  1631. hapd->conf->default_wep_key_len)) {
  1632. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
  1633. HOSTAPD_LEVEL_WARNING, "failed to configure a "
  1634. "new broadcast key");
  1635. os_free(eapol->default_wep_key);
  1636. eapol->default_wep_key = NULL;
  1637. return;
  1638. }
  1639. ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
  1640. if (hapd->conf->wep_rekeying_period > 0) {
  1641. eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
  1642. ieee802_1x_rekey, hapd, NULL);
  1643. }
  1644. }
  1645. static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
  1646. const u8 *data, size_t datalen)
  1647. {
  1648. #ifdef CONFIG_WPS
  1649. struct sta_info *sta = sta_ctx;
  1650. if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
  1651. WLAN_STA_MAYBE_WPS) {
  1652. const u8 *identity;
  1653. size_t identity_len;
  1654. struct eapol_state_machine *sm = sta->eapol_sm;
  1655. identity = eap_get_identity(sm->eap, &identity_len);
  1656. if (identity &&
  1657. ((identity_len == WSC_ID_ENROLLEE_LEN &&
  1658. os_memcmp(identity, WSC_ID_ENROLLEE,
  1659. WSC_ID_ENROLLEE_LEN) == 0) ||
  1660. (identity_len == WSC_ID_REGISTRAR_LEN &&
  1661. os_memcmp(identity, WSC_ID_REGISTRAR,
  1662. WSC_ID_REGISTRAR_LEN) == 0))) {
  1663. wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
  1664. "WLAN_STA_WPS");
  1665. sta->flags |= WLAN_STA_WPS;
  1666. }
  1667. }
  1668. #endif /* CONFIG_WPS */
  1669. ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
  1670. }
  1671. static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
  1672. const u8 *data, size_t datalen)
  1673. {
  1674. #ifndef CONFIG_NO_RADIUS
  1675. struct hostapd_data *hapd = ctx;
  1676. struct sta_info *sta = sta_ctx;
  1677. ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
  1678. #endif /* CONFIG_NO_RADIUS */
  1679. }
  1680. static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
  1681. int preauth, int remediation)
  1682. {
  1683. struct hostapd_data *hapd = ctx;
  1684. struct sta_info *sta = sta_ctx;
  1685. if (preauth)
  1686. rsn_preauth_finished(hapd, sta, success);
  1687. else
  1688. ieee802_1x_finished(hapd, sta, success, remediation);
  1689. }
  1690. static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
  1691. size_t identity_len, int phase2,
  1692. struct eap_user *user)
  1693. {
  1694. struct hostapd_data *hapd = ctx;
  1695. const struct hostapd_eap_user *eap_user;
  1696. int i;
  1697. int rv = -1;
  1698. eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2);
  1699. if (eap_user == NULL)
  1700. goto out;
  1701. os_memset(user, 0, sizeof(*user));
  1702. user->phase2 = phase2;
  1703. for (i = 0; i < EAP_MAX_METHODS; i++) {
  1704. user->methods[i].vendor = eap_user->methods[i].vendor;
  1705. user->methods[i].method = eap_user->methods[i].method;
  1706. }
  1707. if (eap_user->password) {
  1708. user->password = os_malloc(eap_user->password_len);
  1709. if (user->password == NULL)
  1710. goto out;
  1711. os_memcpy(user->password, eap_user->password,
  1712. eap_user->password_len);
  1713. user->password_len = eap_user->password_len;
  1714. user->password_hash = eap_user->password_hash;
  1715. }
  1716. user->force_version = eap_user->force_version;
  1717. user->macacl = eap_user->macacl;
  1718. user->ttls_auth = eap_user->ttls_auth;
  1719. user->remediation = eap_user->remediation;
  1720. rv = 0;
  1721. out:
  1722. if (rv)
  1723. wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
  1724. return rv;
  1725. }
  1726. static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
  1727. {
  1728. struct hostapd_data *hapd = ctx;
  1729. struct sta_info *sta;
  1730. sta = ap_get_sta(hapd, addr);
  1731. if (sta == NULL || sta->eapol_sm == NULL)
  1732. return 0;
  1733. return 1;
  1734. }
  1735. static void ieee802_1x_logger(void *ctx, const u8 *addr,
  1736. eapol_logger_level level, const char *txt)
  1737. {
  1738. #ifndef CONFIG_NO_HOSTAPD_LOGGER
  1739. struct hostapd_data *hapd = ctx;
  1740. int hlevel;
  1741. switch (level) {
  1742. case EAPOL_LOGGER_WARNING:
  1743. hlevel = HOSTAPD_LEVEL_WARNING;
  1744. break;
  1745. case EAPOL_LOGGER_INFO:
  1746. hlevel = HOSTAPD_LEVEL_INFO;
  1747. break;
  1748. case EAPOL_LOGGER_DEBUG:
  1749. default:
  1750. hlevel = HOSTAPD_LEVEL_DEBUG;
  1751. break;
  1752. }
  1753. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
  1754. txt);
  1755. #endif /* CONFIG_NO_HOSTAPD_LOGGER */
  1756. }
  1757. static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
  1758. int authorized)
  1759. {
  1760. struct hostapd_data *hapd = ctx;
  1761. struct sta_info *sta = sta_ctx;
  1762. ieee802_1x_set_sta_authorized(hapd, sta, authorized);
  1763. }
  1764. static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
  1765. {
  1766. struct hostapd_data *hapd = ctx;
  1767. struct sta_info *sta = sta_ctx;
  1768. ieee802_1x_abort_auth(hapd, sta);
  1769. }
  1770. static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
  1771. {
  1772. #ifndef CONFIG_FIPS
  1773. #ifndef CONFIG_NO_RC4
  1774. struct hostapd_data *hapd = ctx;
  1775. struct sta_info *sta = sta_ctx;
  1776. ieee802_1x_tx_key(hapd, sta);
  1777. #endif /* CONFIG_NO_RC4 */
  1778. #endif /* CONFIG_FIPS */
  1779. }
  1780. static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
  1781. enum eapol_event type)
  1782. {
  1783. /* struct hostapd_data *hapd = ctx; */
  1784. struct sta_info *sta = sta_ctx;
  1785. switch (type) {
  1786. case EAPOL_AUTH_SM_CHANGE:
  1787. wpa_auth_sm_notify(sta->wpa_sm);
  1788. break;
  1789. case EAPOL_AUTH_REAUTHENTICATE:
  1790. wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
  1791. break;
  1792. }
  1793. }
  1794. #ifdef CONFIG_ERP
  1795. static struct eap_server_erp_key *
  1796. ieee802_1x_erp_get_key(void *ctx, const char *keyname)
  1797. {
  1798. struct hostapd_data *hapd = ctx;
  1799. struct eap_server_erp_key *erp;
  1800. dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key,
  1801. list) {
  1802. if (os_strcmp(erp->keyname_nai, keyname) == 0)
  1803. return erp;
  1804. }
  1805. return NULL;
  1806. }
  1807. static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp)
  1808. {
  1809. struct hostapd_data *hapd = ctx;
  1810. dl_list_add(&hapd->erp_keys, &erp->list);
  1811. return 0;
  1812. }
  1813. #endif /* CONFIG_ERP */
  1814. int ieee802_1x_init(struct hostapd_data *hapd)
  1815. {
  1816. int i;
  1817. struct eapol_auth_config conf;
  1818. struct eapol_auth_cb cb;
  1819. dl_list_init(&hapd->erp_keys);
  1820. os_memset(&conf, 0, sizeof(conf));
  1821. conf.ctx = hapd;
  1822. conf.eap_reauth_period = hapd->conf->eap_reauth_period;
  1823. conf.wpa = hapd->conf->wpa;
  1824. conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
  1825. conf.eap_server = hapd->conf->eap_server;
  1826. conf.ssl_ctx = hapd->ssl_ctx;
  1827. conf.msg_ctx = hapd->msg_ctx;
  1828. conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
  1829. conf.eap_req_id_text = hapd->conf->eap_req_id_text;
  1830. conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
  1831. conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start;
  1832. conf.erp_domain = hapd->conf->erp_domain;
  1833. conf.erp = hapd->conf->eap_server_erp;
  1834. conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
  1835. conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
  1836. conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
  1837. conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
  1838. conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
  1839. conf.eap_fast_prov = hapd->conf->eap_fast_prov;
  1840. conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
  1841. conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
  1842. conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
  1843. conf.tnc = hapd->conf->tnc;
  1844. conf.wps = hapd->wps;
  1845. conf.fragment_size = hapd->conf->fragment_size;
  1846. conf.pwd_group = hapd->conf->pwd_group;
  1847. conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
  1848. if (hapd->conf->server_id) {
  1849. conf.server_id = (const u8 *) hapd->conf->server_id;
  1850. conf.server_id_len = os_strlen(hapd->conf->server_id);
  1851. } else {
  1852. conf.server_id = (const u8 *) "hostapd";
  1853. conf.server_id_len = 7;
  1854. }
  1855. os_memset(&cb, 0, sizeof(cb));
  1856. cb.eapol_send = ieee802_1x_eapol_send;
  1857. cb.aaa_send = ieee802_1x_aaa_send;
  1858. cb.finished = _ieee802_1x_finished;
  1859. cb.get_eap_user = ieee802_1x_get_eap_user;
  1860. cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
  1861. cb.logger = ieee802_1x_logger;
  1862. cb.set_port_authorized = ieee802_1x_set_port_authorized;
  1863. cb.abort_auth = _ieee802_1x_abort_auth;
  1864. cb.tx_key = _ieee802_1x_tx_key;
  1865. cb.eapol_event = ieee802_1x_eapol_event;
  1866. #ifdef CONFIG_ERP
  1867. cb.erp_get_key = ieee802_1x_erp_get_key;
  1868. cb.erp_add_key = ieee802_1x_erp_add_key;
  1869. #endif /* CONFIG_ERP */
  1870. hapd->eapol_auth = eapol_auth_init(&conf, &cb);
  1871. if (hapd->eapol_auth == NULL)
  1872. return -1;
  1873. if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
  1874. hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
  1875. return -1;
  1876. #ifndef CONFIG_NO_RADIUS
  1877. if (radius_client_register(hapd->radius, RADIUS_AUTH,
  1878. ieee802_1x_receive_auth, hapd))
  1879. return -1;
  1880. #endif /* CONFIG_NO_RADIUS */
  1881. if (hapd->conf->default_wep_key_len) {
  1882. for (i = 0; i < 4; i++)
  1883. hostapd_drv_set_key(hapd->conf->iface, hapd,
  1884. WPA_ALG_NONE, NULL, i, 0, NULL, 0,
  1885. NULL, 0);
  1886. ieee802_1x_rekey(hapd, NULL);
  1887. if (hapd->eapol_auth->default_wep_key == NULL)
  1888. return -1;
  1889. }
  1890. return 0;
  1891. }
  1892. void ieee802_1x_erp_flush(struct hostapd_data *hapd)
  1893. {
  1894. struct eap_server_erp_key *erp;
  1895. while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key,
  1896. list)) != NULL) {
  1897. dl_list_del(&erp->list);
  1898. bin_clear_free(erp, sizeof(*erp));
  1899. }
  1900. }
  1901. void ieee802_1x_deinit(struct hostapd_data *hapd)
  1902. {
  1903. eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
  1904. if (hapd->driver && hapd->drv_priv &&
  1905. (hapd->conf->ieee802_1x || hapd->conf->wpa))
  1906. hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
  1907. eapol_auth_deinit(hapd->eapol_auth);
  1908. hapd->eapol_auth = NULL;
  1909. ieee802_1x_erp_flush(hapd);
  1910. }
  1911. int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
  1912. const u8 *buf, size_t len, int ack)
  1913. {
  1914. struct ieee80211_hdr *hdr;
  1915. u8 *pos;
  1916. const unsigned char rfc1042_hdr[ETH_ALEN] =
  1917. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  1918. if (sta == NULL)
  1919. return -1;
  1920. if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
  1921. return 0;
  1922. hdr = (struct ieee80211_hdr *) buf;
  1923. pos = (u8 *) (hdr + 1);
  1924. if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
  1925. return 0;
  1926. pos += sizeof(rfc1042_hdr);
  1927. if (WPA_GET_BE16(pos) != ETH_P_PAE)
  1928. return 0;
  1929. pos += 2;
  1930. return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
  1931. ack);
  1932. }
  1933. int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
  1934. const u8 *buf, int len, int ack)
  1935. {
  1936. const struct ieee802_1x_hdr *xhdr =
  1937. (const struct ieee802_1x_hdr *) buf;
  1938. const u8 *pos = buf + sizeof(*xhdr);
  1939. struct ieee802_1x_eapol_key *key;
  1940. if (len < (int) sizeof(*xhdr))
  1941. return 0;
  1942. wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
  1943. "type=%d length=%d - ack=%d",
  1944. MAC2STR(sta->addr), xhdr->version, xhdr->type,
  1945. be_to_host16(xhdr->length), ack);
  1946. if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
  1947. return 0;
  1948. if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
  1949. const struct wpa_eapol_key *wpa;
  1950. wpa = (const struct wpa_eapol_key *) pos;
  1951. if (wpa->type == EAPOL_KEY_TYPE_RSN ||
  1952. wpa->type == EAPOL_KEY_TYPE_WPA)
  1953. wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
  1954. sta->wpa_sm, ack);
  1955. }
  1956. /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
  1957. * or Authenticator state machines, but EAPOL-Key packets are not
  1958. * retransmitted in case of failure. Try to re-send failed EAPOL-Key
  1959. * packets couple of times because otherwise STA keys become
  1960. * unsynchronized with AP. */
  1961. if (!ack && pos + sizeof(*key) <= buf + len) {
  1962. key = (struct ieee802_1x_eapol_key *) pos;
  1963. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1964. HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
  1965. "frame (%scast index=%d)",
  1966. key->key_index & BIT(7) ? "uni" : "broad",
  1967. key->key_index & ~BIT(7));
  1968. /* TODO: re-send EAPOL-Key couple of times (with short delay
  1969. * between them?). If all attempt fail, report error and
  1970. * deauthenticate STA so that it will get new keys when
  1971. * authenticating again (e.g., after returning in range).
  1972. * Separate limit/transmit state needed both for unicast and
  1973. * broadcast keys(?) */
  1974. }
  1975. /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
  1976. * to here and change the key only if the EAPOL-Key packet was Acked.
  1977. */
  1978. return 1;
  1979. }
  1980. u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
  1981. {
  1982. if (sm == NULL || sm->identity == NULL)
  1983. return NULL;
  1984. *len = sm->identity_len;
  1985. return sm->identity;
  1986. }
  1987. u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
  1988. int idx)
  1989. {
  1990. if (sm == NULL || sm->radius_class.attr == NULL ||
  1991. idx >= (int) sm->radius_class.count)
  1992. return NULL;
  1993. *len = sm->radius_class.attr[idx].len;
  1994. return sm->radius_class.attr[idx].data;
  1995. }
  1996. struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
  1997. {
  1998. if (sm == NULL)
  1999. return NULL;
  2000. return sm->radius_cui;
  2001. }
  2002. const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
  2003. {
  2004. *len = 0;
  2005. if (sm == NULL)
  2006. return NULL;
  2007. *len = sm->eap_if->eapKeyDataLen;
  2008. return sm->eap_if->eapKeyData;
  2009. }
  2010. void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
  2011. int enabled)
  2012. {
  2013. if (sm == NULL)
  2014. return;
  2015. sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
  2016. eapol_auth_step(sm);
  2017. }
  2018. void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
  2019. int valid)
  2020. {
  2021. if (sm == NULL)
  2022. return;
  2023. sm->portValid = valid ? TRUE : FALSE;
  2024. eapol_auth_step(sm);
  2025. }
  2026. void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
  2027. {
  2028. if (sm == NULL)
  2029. return;
  2030. if (pre_auth)
  2031. sm->flags |= EAPOL_SM_PREAUTH;
  2032. else
  2033. sm->flags &= ~EAPOL_SM_PREAUTH;
  2034. }
  2035. static const char * bool_txt(Boolean val)
  2036. {
  2037. return val ? "TRUE" : "FALSE";
  2038. }
  2039. int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  2040. {
  2041. /* TODO */
  2042. return 0;
  2043. }
  2044. int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  2045. char *buf, size_t buflen)
  2046. {
  2047. int len = 0, ret;
  2048. struct eapol_state_machine *sm = sta->eapol_sm;
  2049. struct os_reltime diff;
  2050. const char *name1;
  2051. const char *name2;
  2052. if (sm == NULL)
  2053. return 0;
  2054. ret = os_snprintf(buf + len, buflen - len,
  2055. "dot1xPaePortNumber=%d\n"
  2056. "dot1xPaePortProtocolVersion=%d\n"
  2057. "dot1xPaePortCapabilities=1\n"
  2058. "dot1xPaePortInitialize=%d\n"
  2059. "dot1xPaePortReauthenticate=FALSE\n",
  2060. sta->aid,
  2061. EAPOL_VERSION,
  2062. sm->initialize);
  2063. if (os_snprintf_error(buflen - len, ret))
  2064. return len;
  2065. len += ret;
  2066. /* dot1xAuthConfigTable */
  2067. ret = os_snprintf(buf + len, buflen - len,
  2068. "dot1xAuthPaeState=%d\n"
  2069. "dot1xAuthBackendAuthState=%d\n"
  2070. "dot1xAuthAdminControlledDirections=%d\n"
  2071. "dot1xAuthOperControlledDirections=%d\n"
  2072. "dot1xAuthAuthControlledPortStatus=%d\n"
  2073. "dot1xAuthAuthControlledPortControl=%d\n"
  2074. "dot1xAuthQuietPeriod=%u\n"
  2075. "dot1xAuthServerTimeout=%u\n"
  2076. "dot1xAuthReAuthPeriod=%u\n"
  2077. "dot1xAuthReAuthEnabled=%s\n"
  2078. "dot1xAuthKeyTxEnabled=%s\n",
  2079. sm->auth_pae_state + 1,
  2080. sm->be_auth_state + 1,
  2081. sm->adminControlledDirections,
  2082. sm->operControlledDirections,
  2083. sm->authPortStatus,
  2084. sm->portControl,
  2085. sm->quietPeriod,
  2086. sm->serverTimeout,
  2087. sm->reAuthPeriod,
  2088. bool_txt(sm->reAuthEnabled),
  2089. bool_txt(sm->keyTxEnabled));
  2090. if (os_snprintf_error(buflen - len, ret))
  2091. return len;
  2092. len += ret;
  2093. /* dot1xAuthStatsTable */
  2094. ret = os_snprintf(buf + len, buflen - len,
  2095. "dot1xAuthEapolFramesRx=%u\n"
  2096. "dot1xAuthEapolFramesTx=%u\n"
  2097. "dot1xAuthEapolStartFramesRx=%u\n"
  2098. "dot1xAuthEapolLogoffFramesRx=%u\n"
  2099. "dot1xAuthEapolRespIdFramesRx=%u\n"
  2100. "dot1xAuthEapolRespFramesRx=%u\n"
  2101. "dot1xAuthEapolReqIdFramesTx=%u\n"
  2102. "dot1xAuthEapolReqFramesTx=%u\n"
  2103. "dot1xAuthInvalidEapolFramesRx=%u\n"
  2104. "dot1xAuthEapLengthErrorFramesRx=%u\n"
  2105. "dot1xAuthLastEapolFrameVersion=%u\n"
  2106. "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
  2107. sm->dot1xAuthEapolFramesRx,
  2108. sm->dot1xAuthEapolFramesTx,
  2109. sm->dot1xAuthEapolStartFramesRx,
  2110. sm->dot1xAuthEapolLogoffFramesRx,
  2111. sm->dot1xAuthEapolRespIdFramesRx,
  2112. sm->dot1xAuthEapolRespFramesRx,
  2113. sm->dot1xAuthEapolReqIdFramesTx,
  2114. sm->dot1xAuthEapolReqFramesTx,
  2115. sm->dot1xAuthInvalidEapolFramesRx,
  2116. sm->dot1xAuthEapLengthErrorFramesRx,
  2117. sm->dot1xAuthLastEapolFrameVersion,
  2118. MAC2STR(sm->addr));
  2119. if (os_snprintf_error(buflen - len, ret))
  2120. return len;
  2121. len += ret;
  2122. /* dot1xAuthDiagTable */
  2123. ret = os_snprintf(buf + len, buflen - len,
  2124. "dot1xAuthEntersConnecting=%u\n"
  2125. "dot1xAuthEapLogoffsWhileConnecting=%u\n"
  2126. "dot1xAuthEntersAuthenticating=%u\n"
  2127. "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
  2128. "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
  2129. "dot1xAuthAuthFailWhileAuthenticating=%u\n"
  2130. "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
  2131. "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
  2132. "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
  2133. "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
  2134. "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
  2135. "dot1xAuthBackendResponses=%u\n"
  2136. "dot1xAuthBackendAccessChallenges=%u\n"
  2137. "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
  2138. "dot1xAuthBackendAuthSuccesses=%u\n"
  2139. "dot1xAuthBackendAuthFails=%u\n",
  2140. sm->authEntersConnecting,
  2141. sm->authEapLogoffsWhileConnecting,
  2142. sm->authEntersAuthenticating,
  2143. sm->authAuthSuccessesWhileAuthenticating,
  2144. sm->authAuthTimeoutsWhileAuthenticating,
  2145. sm->authAuthFailWhileAuthenticating,
  2146. sm->authAuthEapStartsWhileAuthenticating,
  2147. sm->authAuthEapLogoffWhileAuthenticating,
  2148. sm->authAuthReauthsWhileAuthenticated,
  2149. sm->authAuthEapStartsWhileAuthenticated,
  2150. sm->authAuthEapLogoffWhileAuthenticated,
  2151. sm->backendResponses,
  2152. sm->backendAccessChallenges,
  2153. sm->backendOtherRequestsToSupplicant,
  2154. sm->backendAuthSuccesses,
  2155. sm->backendAuthFails);
  2156. if (os_snprintf_error(buflen - len, ret))
  2157. return len;
  2158. len += ret;
  2159. /* dot1xAuthSessionStatsTable */
  2160. os_reltime_age(&sta->acct_session_start, &diff);
  2161. ret = os_snprintf(buf + len, buflen - len,
  2162. /* TODO: dot1xAuthSessionOctetsRx */
  2163. /* TODO: dot1xAuthSessionOctetsTx */
  2164. /* TODO: dot1xAuthSessionFramesRx */
  2165. /* TODO: dot1xAuthSessionFramesTx */
  2166. "dot1xAuthSessionId=%016lX\n"
  2167. "dot1xAuthSessionAuthenticMethod=%d\n"
  2168. "dot1xAuthSessionTime=%u\n"
  2169. "dot1xAuthSessionTerminateCause=999\n"
  2170. "dot1xAuthSessionUserName=%s\n",
  2171. (long unsigned int) sta->acct_session_id,
  2172. (wpa_key_mgmt_wpa_ieee8021x(
  2173. wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
  2174. 1 : 2,
  2175. (unsigned int) diff.sec,
  2176. sm->identity);
  2177. if (os_snprintf_error(buflen - len, ret))
  2178. return len;
  2179. len += ret;
  2180. if (sm->acct_multi_session_id) {
  2181. ret = os_snprintf(buf + len, buflen - len,
  2182. "authMultiSessionId=%016lX\n",
  2183. (long unsigned int)
  2184. sm->acct_multi_session_id);
  2185. if (os_snprintf_error(buflen - len, ret))
  2186. return len;
  2187. len += ret;
  2188. }
  2189. name1 = eap_server_get_name(0, sm->eap_type_authsrv);
  2190. name2 = eap_server_get_name(0, sm->eap_type_supp);
  2191. ret = os_snprintf(buf + len, buflen - len,
  2192. "last_eap_type_as=%d (%s)\n"
  2193. "last_eap_type_sta=%d (%s)\n",
  2194. sm->eap_type_authsrv, name1,
  2195. sm->eap_type_supp, name2);
  2196. if (os_snprintf_error(buflen - len, ret))
  2197. return len;
  2198. len += ret;
  2199. return len;
  2200. }
  2201. #ifdef CONFIG_HS20
  2202. static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx)
  2203. {
  2204. struct hostapd_data *hapd = eloop_ctx;
  2205. struct sta_info *sta = timeout_ctx;
  2206. if (sta->remediation) {
  2207. wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
  2208. MACSTR " to indicate Subscription Remediation",
  2209. MAC2STR(sta->addr));
  2210. hs20_send_wnm_notification(hapd, sta->addr,
  2211. sta->remediation_method,
  2212. sta->remediation_url);
  2213. os_free(sta->remediation_url);
  2214. sta->remediation_url = NULL;
  2215. }
  2216. if (sta->hs20_deauth_req) {
  2217. wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
  2218. MACSTR " to indicate imminent deauthentication",
  2219. MAC2STR(sta->addr));
  2220. hs20_send_wnm_notification_deauth_req(hapd, sta->addr,
  2221. sta->hs20_deauth_req);
  2222. }
  2223. }
  2224. #endif /* CONFIG_HS20 */
  2225. static void ieee802_1x_finished(struct hostapd_data *hapd,
  2226. struct sta_info *sta, int success,
  2227. int remediation)
  2228. {
  2229. const u8 *key;
  2230. size_t len;
  2231. /* TODO: get PMKLifetime from WPA parameters */
  2232. static const int dot11RSNAConfigPMKLifetime = 43200;
  2233. unsigned int session_timeout;
  2234. #ifdef CONFIG_HS20
  2235. if (remediation && !sta->remediation) {
  2236. sta->remediation = 1;
  2237. os_free(sta->remediation_url);
  2238. sta->remediation_url =
  2239. os_strdup(hapd->conf->subscr_remediation_url);
  2240. sta->remediation_method = 1; /* SOAP-XML SPP */
  2241. }
  2242. if (success && (sta->remediation || sta->hs20_deauth_req)) {
  2243. wpa_printf(MSG_DEBUG, "HS 2.0: Schedule WNM-Notification to "
  2244. MACSTR " in 100 ms", MAC2STR(sta->addr));
  2245. eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
  2246. eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send,
  2247. hapd, sta);
  2248. }
  2249. #endif /* CONFIG_HS20 */
  2250. key = ieee802_1x_get_key(sta->eapol_sm, &len);
  2251. if (sta->session_timeout_set)
  2252. session_timeout = sta->session_timeout;
  2253. else
  2254. session_timeout = dot11RSNAConfigPMKLifetime;
  2255. if (success && key && len >= PMK_LEN && !sta->remediation &&
  2256. !sta->hs20_deauth_requested &&
  2257. wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout,
  2258. sta->eapol_sm) == 0) {
  2259. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
  2260. HOSTAPD_LEVEL_DEBUG,
  2261. "Added PMKSA cache entry (IEEE 802.1X)");
  2262. }
  2263. if (!success) {
  2264. /*
  2265. * Many devices require deauthentication after WPS provisioning
  2266. * and some may not be be able to do that themselves, so
  2267. * disconnect the client here. In addition, this may also
  2268. * benefit IEEE 802.1X/EAPOL authentication cases, too since
  2269. * the EAPOL PAE state machine would remain in HELD state for
  2270. * considerable amount of time and some EAP methods, like
  2271. * EAP-FAST with anonymous provisioning, may require another
  2272. * EAPOL authentication to be started to complete connection.
  2273. */
  2274. wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "IEEE 802.1X: Force "
  2275. "disconnection after EAP-Failure");
  2276. /* Add a small sleep to increase likelihood of previously
  2277. * requested EAP-Failure TX getting out before this should the
  2278. * driver reorder operations.
  2279. */
  2280. os_sleep(0, 10000);
  2281. ap_sta_disconnect(hapd, sta, sta->addr,
  2282. WLAN_REASON_IEEE_802_1X_AUTH_FAILED);
  2283. hostapd_wps_eap_completed(hapd);
  2284. }
  2285. }