ieee802_1x.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  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 "ieee802_1x.h"
  31. static void ieee802_1x_finished(struct hostapd_data *hapd,
  32. struct sta_info *sta, int success);
  33. static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
  34. u8 type, const u8 *data, size_t datalen)
  35. {
  36. u8 *buf;
  37. struct ieee802_1x_hdr *xhdr;
  38. size_t len;
  39. int encrypt = 0;
  40. len = sizeof(*xhdr) + datalen;
  41. buf = os_zalloc(len);
  42. if (buf == NULL) {
  43. wpa_printf(MSG_ERROR, "malloc() failed for "
  44. "ieee802_1x_send(len=%lu)",
  45. (unsigned long) len);
  46. return;
  47. }
  48. xhdr = (struct ieee802_1x_hdr *) buf;
  49. xhdr->version = hapd->conf->eapol_version;
  50. xhdr->type = type;
  51. xhdr->length = host_to_be16(datalen);
  52. if (datalen > 0 && data != NULL)
  53. os_memcpy(xhdr + 1, data, datalen);
  54. if (wpa_auth_pairwise_set(sta->wpa_sm))
  55. encrypt = 1;
  56. if (sta->flags & WLAN_STA_PREAUTH) {
  57. rsn_preauth_send(hapd, sta, buf, len);
  58. } else {
  59. hostapd_drv_hapd_send_eapol(hapd, sta->addr, buf, len,
  60. encrypt, sta->flags);
  61. }
  62. os_free(buf);
  63. }
  64. void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
  65. struct sta_info *sta, int authorized)
  66. {
  67. int res;
  68. if (sta->flags & WLAN_STA_PREAUTH)
  69. return;
  70. if (authorized) {
  71. ap_sta_set_authorized(hapd, sta, 1);
  72. res = hostapd_set_authorized(hapd, sta, 1);
  73. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  74. HOSTAPD_LEVEL_DEBUG, "authorizing port");
  75. } else {
  76. ap_sta_set_authorized(hapd, sta, 0);
  77. res = hostapd_set_authorized(hapd, sta, 0);
  78. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  79. HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
  80. }
  81. if (res && errno != ENOENT) {
  82. printf("Could not set station " MACSTR " flags for kernel "
  83. "driver (errno=%d).\n", MAC2STR(sta->addr), errno);
  84. }
  85. if (authorized)
  86. accounting_sta_start(hapd, sta);
  87. }
  88. static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
  89. struct sta_info *sta,
  90. int idx, int broadcast,
  91. u8 *key_data, size_t key_len)
  92. {
  93. u8 *buf, *ekey;
  94. struct ieee802_1x_hdr *hdr;
  95. struct ieee802_1x_eapol_key *key;
  96. size_t len, ekey_len;
  97. struct eapol_state_machine *sm = sta->eapol_sm;
  98. if (sm == NULL)
  99. return;
  100. len = sizeof(*key) + key_len;
  101. buf = os_zalloc(sizeof(*hdr) + len);
  102. if (buf == NULL)
  103. return;
  104. hdr = (struct ieee802_1x_hdr *) buf;
  105. key = (struct ieee802_1x_eapol_key *) (hdr + 1);
  106. key->type = EAPOL_KEY_TYPE_RC4;
  107. key->key_length = htons(key_len);
  108. wpa_get_ntp_timestamp(key->replay_counter);
  109. if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
  110. wpa_printf(MSG_ERROR, "Could not get random numbers");
  111. os_free(buf);
  112. return;
  113. }
  114. key->key_index = idx | (broadcast ? 0 : BIT(7));
  115. if (hapd->conf->eapol_key_index_workaround) {
  116. /* According to some information, WinXP Supplicant seems to
  117. * interpret bit7 as an indication whether the key is to be
  118. * activated, so make it possible to enable workaround that
  119. * sets this bit for all keys. */
  120. key->key_index |= BIT(7);
  121. }
  122. /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
  123. * MSK[32..63] is used to sign the message. */
  124. if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
  125. wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
  126. "and signing EAPOL-Key");
  127. os_free(buf);
  128. return;
  129. }
  130. os_memcpy((u8 *) (key + 1), key_data, key_len);
  131. ekey_len = sizeof(key->key_iv) + 32;
  132. ekey = os_malloc(ekey_len);
  133. if (ekey == NULL) {
  134. wpa_printf(MSG_ERROR, "Could not encrypt key");
  135. os_free(buf);
  136. return;
  137. }
  138. os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
  139. os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
  140. rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
  141. os_free(ekey);
  142. /* This header is needed here for HMAC-MD5, but it will be regenerated
  143. * in ieee802_1x_send() */
  144. hdr->version = hapd->conf->eapol_version;
  145. hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
  146. hdr->length = host_to_be16(len);
  147. hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
  148. key->key_signature);
  149. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
  150. " (%s index=%d)", MAC2STR(sm->addr),
  151. broadcast ? "broadcast" : "unicast", idx);
  152. ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
  153. if (sta->eapol_sm)
  154. sta->eapol_sm->dot1xAuthEapolFramesTx++;
  155. os_free(buf);
  156. }
  157. #ifndef CONFIG_NO_VLAN
  158. static struct hostapd_wep_keys *
  159. ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
  160. {
  161. struct hostapd_wep_keys *key;
  162. key = os_zalloc(sizeof(*key));
  163. if (key == NULL)
  164. return NULL;
  165. key->default_len = hapd->conf->default_wep_key_len;
  166. if (key->idx >= hapd->conf->broadcast_key_idx_max ||
  167. key->idx < hapd->conf->broadcast_key_idx_min)
  168. key->idx = hapd->conf->broadcast_key_idx_min;
  169. else
  170. key->idx++;
  171. if (!key->key[key->idx])
  172. key->key[key->idx] = os_malloc(key->default_len);
  173. if (key->key[key->idx] == NULL ||
  174. random_get_bytes(key->key[key->idx], key->default_len)) {
  175. printf("Could not generate random WEP key (dynamic VLAN).\n");
  176. os_free(key->key[key->idx]);
  177. key->key[key->idx] = NULL;
  178. os_free(key);
  179. return NULL;
  180. }
  181. key->len[key->idx] = key->default_len;
  182. wpa_printf(MSG_DEBUG, "%s: Default WEP idx %d for dynamic VLAN\n",
  183. ifname, key->idx);
  184. wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
  185. key->key[key->idx], key->len[key->idx]);
  186. if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
  187. broadcast_ether_addr, key->idx, 1,
  188. NULL, 0, key->key[key->idx],
  189. key->len[key->idx]))
  190. printf("Could not set dynamic VLAN WEP encryption key.\n");
  191. hostapd_set_drv_ieee8021x(hapd, ifname, 1);
  192. return key;
  193. }
  194. static struct hostapd_wep_keys *
  195. ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
  196. size_t vlan_id)
  197. {
  198. const char *ifname;
  199. if (vlan_id == 0)
  200. return &ssid->wep;
  201. if (vlan_id <= ssid->max_dyn_vlan_keys && ssid->dyn_vlan_keys &&
  202. ssid->dyn_vlan_keys[vlan_id])
  203. return ssid->dyn_vlan_keys[vlan_id];
  204. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Creating new group "
  205. "state machine for VLAN ID %lu",
  206. (unsigned long) vlan_id);
  207. ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
  208. if (ifname == NULL) {
  209. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Unknown VLAN ID %lu - "
  210. "cannot create group key state machine",
  211. (unsigned long) vlan_id);
  212. return NULL;
  213. }
  214. if (ssid->dyn_vlan_keys == NULL) {
  215. int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
  216. ssid->dyn_vlan_keys = os_zalloc(size);
  217. if (ssid->dyn_vlan_keys == NULL)
  218. return NULL;
  219. ssid->max_dyn_vlan_keys = vlan_id;
  220. }
  221. if (ssid->max_dyn_vlan_keys < vlan_id) {
  222. struct hostapd_wep_keys **na;
  223. int size = (vlan_id + 1) * sizeof(ssid->dyn_vlan_keys[0]);
  224. na = os_realloc(ssid->dyn_vlan_keys, size);
  225. if (na == NULL)
  226. return NULL;
  227. ssid->dyn_vlan_keys = na;
  228. os_memset(&ssid->dyn_vlan_keys[ssid->max_dyn_vlan_keys + 1], 0,
  229. (vlan_id - ssid->max_dyn_vlan_keys) *
  230. sizeof(ssid->dyn_vlan_keys[0]));
  231. ssid->max_dyn_vlan_keys = vlan_id;
  232. }
  233. ssid->dyn_vlan_keys[vlan_id] = ieee802_1x_group_alloc(hapd, ifname);
  234. return ssid->dyn_vlan_keys[vlan_id];
  235. }
  236. #endif /* CONFIG_NO_VLAN */
  237. void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
  238. {
  239. struct eapol_authenticator *eapol = hapd->eapol_auth;
  240. struct eapol_state_machine *sm = sta->eapol_sm;
  241. #ifndef CONFIG_NO_VLAN
  242. struct hostapd_wep_keys *key = NULL;
  243. int vlan_id;
  244. #endif /* CONFIG_NO_VLAN */
  245. if (sm == NULL || !sm->eap_if->eapKeyData)
  246. return;
  247. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
  248. MAC2STR(sta->addr));
  249. #ifndef CONFIG_NO_VLAN
  250. vlan_id = sta->vlan_id;
  251. if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
  252. vlan_id = 0;
  253. if (vlan_id) {
  254. key = ieee802_1x_get_group(hapd, sta->ssid, vlan_id);
  255. if (key && key->key[key->idx])
  256. ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
  257. key->key[key->idx],
  258. key->len[key->idx]);
  259. } else
  260. #endif /* CONFIG_NO_VLAN */
  261. if (eapol->default_wep_key) {
  262. ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
  263. eapol->default_wep_key,
  264. hapd->conf->default_wep_key_len);
  265. }
  266. if (hapd->conf->individual_wep_key_len > 0) {
  267. u8 *ikey;
  268. ikey = os_malloc(hapd->conf->individual_wep_key_len);
  269. if (ikey == NULL ||
  270. random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
  271. {
  272. wpa_printf(MSG_ERROR, "Could not generate random "
  273. "individual WEP key.");
  274. os_free(ikey);
  275. return;
  276. }
  277. wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
  278. ikey, hapd->conf->individual_wep_key_len);
  279. ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
  280. hapd->conf->individual_wep_key_len);
  281. /* TODO: set encryption in TX callback, i.e., only after STA
  282. * has ACKed EAPOL-Key frame */
  283. if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
  284. sta->addr, 0, 1, NULL, 0, ikey,
  285. hapd->conf->individual_wep_key_len)) {
  286. wpa_printf(MSG_ERROR, "Could not set individual WEP "
  287. "encryption.");
  288. }
  289. os_free(ikey);
  290. }
  291. }
  292. const char *radius_mode_txt(struct hostapd_data *hapd)
  293. {
  294. switch (hapd->iface->conf->hw_mode) {
  295. case HOSTAPD_MODE_IEEE80211A:
  296. return "802.11a";
  297. case HOSTAPD_MODE_IEEE80211G:
  298. return "802.11g";
  299. case HOSTAPD_MODE_IEEE80211B:
  300. default:
  301. return "802.11b";
  302. }
  303. }
  304. int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
  305. {
  306. int i;
  307. u8 rate = 0;
  308. for (i = 0; i < sta->supported_rates_len; i++)
  309. if ((sta->supported_rates[i] & 0x7f) > rate)
  310. rate = sta->supported_rates[i] & 0x7f;
  311. return rate;
  312. }
  313. #ifndef CONFIG_NO_RADIUS
  314. static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
  315. struct eapol_state_machine *sm,
  316. const u8 *eap, size_t len)
  317. {
  318. const u8 *identity;
  319. size_t identity_len;
  320. if (len <= sizeof(struct eap_hdr) ||
  321. eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY)
  322. return;
  323. identity = eap_get_identity(sm->eap, &identity_len);
  324. if (identity == NULL)
  325. return;
  326. /* Save station identity for future RADIUS packets */
  327. os_free(sm->identity);
  328. sm->identity = os_malloc(identity_len + 1);
  329. if (sm->identity == NULL) {
  330. sm->identity_len = 0;
  331. return;
  332. }
  333. os_memcpy(sm->identity, identity, identity_len);
  334. sm->identity_len = identity_len;
  335. sm->identity[identity_len] = '\0';
  336. hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
  337. HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
  338. sm->dot1xAuthEapolRespIdFramesRx++;
  339. }
  340. static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
  341. struct sta_info *sta,
  342. const u8 *eap, size_t len)
  343. {
  344. struct radius_msg *msg;
  345. char buf[128];
  346. struct eapol_state_machine *sm = sta->eapol_sm;
  347. if (sm == NULL)
  348. return;
  349. ieee802_1x_learn_identity(hapd, sm, eap, len);
  350. wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
  351. "packet");
  352. sm->radius_identifier = radius_client_get_id(hapd->radius);
  353. msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
  354. sm->radius_identifier);
  355. if (msg == NULL) {
  356. printf("Could not create net RADIUS packet\n");
  357. return;
  358. }
  359. radius_msg_make_authenticator(msg, (u8 *) sta, sizeof(*sta));
  360. if (sm->identity &&
  361. !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
  362. sm->identity, sm->identity_len)) {
  363. printf("Could not add User-Name\n");
  364. goto fail;
  365. }
  366. if (hapd->conf->own_ip_addr.af == AF_INET &&
  367. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
  368. (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
  369. printf("Could not add NAS-IP-Address\n");
  370. goto fail;
  371. }
  372. #ifdef CONFIG_IPV6
  373. if (hapd->conf->own_ip_addr.af == AF_INET6 &&
  374. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
  375. (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
  376. printf("Could not add NAS-IPv6-Address\n");
  377. goto fail;
  378. }
  379. #endif /* CONFIG_IPV6 */
  380. if (hapd->conf->nas_identifier &&
  381. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
  382. (u8 *) hapd->conf->nas_identifier,
  383. os_strlen(hapd->conf->nas_identifier))) {
  384. printf("Could not add NAS-Identifier\n");
  385. goto fail;
  386. }
  387. if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
  388. printf("Could not add NAS-Port\n");
  389. goto fail;
  390. }
  391. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
  392. MAC2STR(hapd->own_addr), hapd->conf->ssid.ssid);
  393. buf[sizeof(buf) - 1] = '\0';
  394. if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
  395. (u8 *) buf, os_strlen(buf))) {
  396. printf("Could not add Called-Station-Id\n");
  397. goto fail;
  398. }
  399. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  400. MAC2STR(sta->addr));
  401. buf[sizeof(buf) - 1] = '\0';
  402. if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
  403. (u8 *) buf, os_strlen(buf))) {
  404. printf("Could not add Calling-Station-Id\n");
  405. goto fail;
  406. }
  407. /* TODO: should probably check MTU from driver config; 2304 is max for
  408. * IEEE 802.11, but use 1400 to avoid problems with too large packets
  409. */
  410. if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
  411. printf("Could not add Framed-MTU\n");
  412. goto fail;
  413. }
  414. if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
  415. RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
  416. printf("Could not add NAS-Port-Type\n");
  417. goto fail;
  418. }
  419. if (sta->flags & WLAN_STA_PREAUTH) {
  420. os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
  421. sizeof(buf));
  422. } else {
  423. os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
  424. radius_sta_rate(hapd, sta) / 2,
  425. (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
  426. radius_mode_txt(hapd));
  427. buf[sizeof(buf) - 1] = '\0';
  428. }
  429. if (!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
  430. (u8 *) buf, os_strlen(buf))) {
  431. printf("Could not add Connect-Info\n");
  432. goto fail;
  433. }
  434. if (eap && !radius_msg_add_eap(msg, eap, len)) {
  435. printf("Could not add EAP-Message\n");
  436. goto fail;
  437. }
  438. /* State attribute must be copied if and only if this packet is
  439. * Access-Request reply to the previous Access-Challenge */
  440. if (sm->last_recv_radius &&
  441. radius_msg_get_hdr(sm->last_recv_radius)->code ==
  442. RADIUS_CODE_ACCESS_CHALLENGE) {
  443. int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
  444. RADIUS_ATTR_STATE);
  445. if (res < 0) {
  446. printf("Could not copy State attribute from previous "
  447. "Access-Challenge\n");
  448. goto fail;
  449. }
  450. if (res > 0) {
  451. wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
  452. }
  453. }
  454. if (hapd->conf->radius_request_cui) {
  455. const u8 *cui;
  456. size_t cui_len;
  457. /* Add previously learned CUI or nul CUI to request CUI */
  458. if (sm->radius_cui) {
  459. cui = wpabuf_head(sm->radius_cui);
  460. cui_len = wpabuf_len(sm->radius_cui);
  461. } else {
  462. cui = (const u8 *) "\0";
  463. cui_len = 1;
  464. }
  465. if (!radius_msg_add_attr(msg,
  466. RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
  467. cui, cui_len)) {
  468. wpa_printf(MSG_ERROR, "Could not add CUI");
  469. goto fail;
  470. }
  471. }
  472. if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
  473. goto fail;
  474. return;
  475. fail:
  476. radius_msg_free(msg);
  477. }
  478. #endif /* CONFIG_NO_RADIUS */
  479. static void handle_eap_response(struct hostapd_data *hapd,
  480. struct sta_info *sta, struct eap_hdr *eap,
  481. size_t len)
  482. {
  483. u8 type, *data;
  484. struct eapol_state_machine *sm = sta->eapol_sm;
  485. if (sm == NULL)
  486. return;
  487. data = (u8 *) (eap + 1);
  488. if (len < sizeof(*eap) + 1) {
  489. printf("handle_eap_response: too short response data\n");
  490. return;
  491. }
  492. sm->eap_type_supp = type = data[0];
  493. hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
  494. HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
  495. "id=%d len=%d) from STA: EAP Response-%s (%d)",
  496. eap->code, eap->identifier, be_to_host16(eap->length),
  497. eap_server_get_name(0, type), type);
  498. sm->dot1xAuthEapolRespFramesRx++;
  499. wpabuf_free(sm->eap_if->eapRespData);
  500. sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
  501. sm->eapolEap = TRUE;
  502. }
  503. /* Process incoming EAP packet from Supplicant */
  504. static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
  505. u8 *buf, size_t len)
  506. {
  507. struct eap_hdr *eap;
  508. u16 eap_len;
  509. if (len < sizeof(*eap)) {
  510. printf(" too short EAP packet\n");
  511. return;
  512. }
  513. eap = (struct eap_hdr *) buf;
  514. eap_len = be_to_host16(eap->length);
  515. wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
  516. eap->code, eap->identifier, eap_len);
  517. if (eap_len < sizeof(*eap)) {
  518. wpa_printf(MSG_DEBUG, " Invalid EAP length");
  519. return;
  520. } else if (eap_len > len) {
  521. wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
  522. "packet");
  523. return;
  524. } else if (eap_len < len) {
  525. wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
  526. "packet", (unsigned long) len - eap_len);
  527. }
  528. switch (eap->code) {
  529. case EAP_CODE_REQUEST:
  530. wpa_printf(MSG_DEBUG, " (request)");
  531. return;
  532. case EAP_CODE_RESPONSE:
  533. wpa_printf(MSG_DEBUG, " (response)");
  534. handle_eap_response(hapd, sta, eap, eap_len);
  535. break;
  536. case EAP_CODE_SUCCESS:
  537. wpa_printf(MSG_DEBUG, " (success)");
  538. return;
  539. case EAP_CODE_FAILURE:
  540. wpa_printf(MSG_DEBUG, " (failure)");
  541. return;
  542. default:
  543. wpa_printf(MSG_DEBUG, " (unknown code)");
  544. return;
  545. }
  546. }
  547. static struct eapol_state_machine *
  548. ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
  549. {
  550. int flags = 0;
  551. if (sta->flags & WLAN_STA_PREAUTH)
  552. flags |= EAPOL_SM_PREAUTH;
  553. if (sta->wpa_sm) {
  554. flags |= EAPOL_SM_USES_WPA;
  555. if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
  556. flags |= EAPOL_SM_FROM_PMKSA_CACHE;
  557. }
  558. return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
  559. sta->wps_ie, sta->p2p_ie, sta);
  560. }
  561. /**
  562. * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
  563. * @hapd: hostapd BSS data
  564. * @sa: Source address (sender of the EAPOL frame)
  565. * @buf: EAPOL frame
  566. * @len: Length of buf in octets
  567. *
  568. * This function is called for each incoming EAPOL frame from the interface
  569. */
  570. void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
  571. size_t len)
  572. {
  573. struct sta_info *sta;
  574. struct ieee802_1x_hdr *hdr;
  575. struct ieee802_1x_eapol_key *key;
  576. u16 datalen;
  577. struct rsn_pmksa_cache_entry *pmksa;
  578. int key_mgmt;
  579. if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
  580. !hapd->conf->wps_state)
  581. return;
  582. wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
  583. (unsigned long) len, MAC2STR(sa));
  584. sta = ap_get_sta(hapd, sa);
  585. if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
  586. !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
  587. wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
  588. "associated/Pre-authenticating STA");
  589. return;
  590. }
  591. if (len < sizeof(*hdr)) {
  592. printf(" too short IEEE 802.1X packet\n");
  593. return;
  594. }
  595. hdr = (struct ieee802_1x_hdr *) buf;
  596. datalen = be_to_host16(hdr->length);
  597. wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
  598. hdr->version, hdr->type, datalen);
  599. if (len - sizeof(*hdr) < datalen) {
  600. printf(" frame too short for this IEEE 802.1X packet\n");
  601. if (sta->eapol_sm)
  602. sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
  603. return;
  604. }
  605. if (len - sizeof(*hdr) > datalen) {
  606. wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
  607. "IEEE 802.1X packet",
  608. (unsigned long) len - sizeof(*hdr) - datalen);
  609. }
  610. if (sta->eapol_sm) {
  611. sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
  612. sta->eapol_sm->dot1xAuthEapolFramesRx++;
  613. }
  614. key = (struct ieee802_1x_eapol_key *) (hdr + 1);
  615. if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
  616. hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
  617. (key->type == EAPOL_KEY_TYPE_WPA ||
  618. key->type == EAPOL_KEY_TYPE_RSN)) {
  619. wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
  620. sizeof(*hdr) + datalen);
  621. return;
  622. }
  623. if (!hapd->conf->ieee802_1x &&
  624. !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
  625. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
  626. "802.1X not enabled and WPS not used");
  627. return;
  628. }
  629. key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
  630. if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
  631. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
  632. "STA is using PSK");
  633. return;
  634. }
  635. if (!sta->eapol_sm) {
  636. sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
  637. if (!sta->eapol_sm)
  638. return;
  639. #ifdef CONFIG_WPS
  640. if (!hapd->conf->ieee802_1x) {
  641. u32 wflags = sta->flags & (WLAN_STA_WPS |
  642. WLAN_STA_WPS2 |
  643. WLAN_STA_MAYBE_WPS);
  644. if (wflags == WLAN_STA_MAYBE_WPS ||
  645. wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
  646. /*
  647. * Delay EAPOL frame transmission until a
  648. * possible WPS STA initiates the handshake
  649. * with EAPOL-Start. Only allow the wait to be
  650. * skipped if the STA is known to support WPS
  651. * 2.0.
  652. */
  653. wpa_printf(MSG_DEBUG, "WPS: Do not start "
  654. "EAPOL until EAPOL-Start is "
  655. "received");
  656. sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
  657. }
  658. }
  659. #endif /* CONFIG_WPS */
  660. sta->eapol_sm->eap_if->portEnabled = TRUE;
  661. }
  662. /* since we support version 1, we can ignore version field and proceed
  663. * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
  664. /* TODO: actually, we are not version 1 anymore.. However, Version 2
  665. * does not change frame contents, so should be ok to process frames
  666. * more or less identically. Some changes might be needed for
  667. * verification of fields. */
  668. switch (hdr->type) {
  669. case IEEE802_1X_TYPE_EAP_PACKET:
  670. handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
  671. break;
  672. case IEEE802_1X_TYPE_EAPOL_START:
  673. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  674. HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
  675. "from STA");
  676. sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
  677. pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  678. if (pmksa) {
  679. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
  680. HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
  681. "available - ignore it since "
  682. "STA sent EAPOL-Start");
  683. wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
  684. }
  685. sta->eapol_sm->eapolStart = TRUE;
  686. sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
  687. eap_server_clear_identity(sta->eapol_sm->eap);
  688. wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
  689. break;
  690. case IEEE802_1X_TYPE_EAPOL_LOGOFF:
  691. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  692. HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
  693. "from STA");
  694. sta->acct_terminate_cause =
  695. RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
  696. accounting_sta_stop(hapd, sta);
  697. sta->eapol_sm->eapolLogoff = TRUE;
  698. sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
  699. eap_server_clear_identity(sta->eapol_sm->eap);
  700. break;
  701. case IEEE802_1X_TYPE_EAPOL_KEY:
  702. wpa_printf(MSG_DEBUG, " EAPOL-Key");
  703. if (!ap_sta_is_authorized(sta)) {
  704. wpa_printf(MSG_DEBUG, " Dropped key data from "
  705. "unauthorized Supplicant");
  706. break;
  707. }
  708. break;
  709. case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
  710. wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
  711. /* TODO: implement support for this; show data */
  712. break;
  713. default:
  714. wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
  715. sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
  716. break;
  717. }
  718. eapol_auth_step(sta->eapol_sm);
  719. }
  720. /**
  721. * ieee802_1x_new_station - Start IEEE 802.1X authentication
  722. * @hapd: hostapd BSS data
  723. * @sta: The station
  724. *
  725. * This function is called to start IEEE 802.1X authentication when a new
  726. * station completes IEEE 802.11 association.
  727. */
  728. void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
  729. {
  730. struct rsn_pmksa_cache_entry *pmksa;
  731. int reassoc = 1;
  732. int force_1x = 0;
  733. int key_mgmt;
  734. #ifdef CONFIG_WPS
  735. if (hapd->conf->wps_state && hapd->conf->wpa &&
  736. (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
  737. /*
  738. * Need to enable IEEE 802.1X/EAPOL state machines for possible
  739. * WPS handshake even if IEEE 802.1X/EAPOL is not used for
  740. * authentication in this BSS.
  741. */
  742. force_1x = 1;
  743. }
  744. #endif /* CONFIG_WPS */
  745. if (!force_1x && !hapd->conf->ieee802_1x) {
  746. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
  747. "802.1X not enabled or forced for WPS");
  748. /*
  749. * Clear any possible EAPOL authenticator state to support
  750. * reassociation change from WPS to PSK.
  751. */
  752. ieee802_1x_free_station(sta);
  753. return;
  754. }
  755. key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
  756. if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
  757. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
  758. /*
  759. * Clear any possible EAPOL authenticator state to support
  760. * reassociation change from WPA-EAP to PSK.
  761. */
  762. ieee802_1x_free_station(sta);
  763. return;
  764. }
  765. if (sta->eapol_sm == NULL) {
  766. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  767. HOSTAPD_LEVEL_DEBUG, "start authentication");
  768. sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
  769. if (sta->eapol_sm == NULL) {
  770. hostapd_logger(hapd, sta->addr,
  771. HOSTAPD_MODULE_IEEE8021X,
  772. HOSTAPD_LEVEL_INFO,
  773. "failed to allocate state machine");
  774. return;
  775. }
  776. reassoc = 0;
  777. }
  778. #ifdef CONFIG_WPS
  779. sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
  780. if (!hapd->conf->ieee802_1x && !(sta->flags & WLAN_STA_WPS2)) {
  781. /*
  782. * Delay EAPOL frame transmission until a possible WPS STA
  783. * initiates the handshake with EAPOL-Start. Only allow the
  784. * wait to be skipped if the STA is known to support WPS 2.0.
  785. */
  786. wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
  787. "EAPOL-Start is received");
  788. sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
  789. }
  790. #endif /* CONFIG_WPS */
  791. sta->eapol_sm->eap_if->portEnabled = TRUE;
  792. #ifdef CONFIG_IEEE80211R
  793. if (sta->auth_alg == WLAN_AUTH_FT) {
  794. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  795. HOSTAPD_LEVEL_DEBUG,
  796. "PMK from FT - skip IEEE 802.1X/EAP");
  797. /* Setup EAPOL state machines to already authenticated state
  798. * because of existing FT information from R0KH. */
  799. sta->eapol_sm->keyRun = TRUE;
  800. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  801. sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
  802. sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
  803. sta->eapol_sm->authSuccess = TRUE;
  804. sta->eapol_sm->authFail = FALSE;
  805. if (sta->eapol_sm->eap)
  806. eap_sm_notify_cached(sta->eapol_sm->eap);
  807. /* TODO: get vlan_id from R0KH using RRB message */
  808. return;
  809. }
  810. #endif /* CONFIG_IEEE80211R */
  811. pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
  812. if (pmksa) {
  813. int old_vlanid;
  814. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  815. HOSTAPD_LEVEL_DEBUG,
  816. "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
  817. /* Setup EAPOL state machines to already authenticated state
  818. * because of existing PMKSA information in the cache. */
  819. sta->eapol_sm->keyRun = TRUE;
  820. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  821. sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
  822. sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
  823. sta->eapol_sm->authSuccess = TRUE;
  824. sta->eapol_sm->authFail = FALSE;
  825. if (sta->eapol_sm->eap)
  826. eap_sm_notify_cached(sta->eapol_sm->eap);
  827. old_vlanid = sta->vlan_id;
  828. pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
  829. if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
  830. sta->vlan_id = 0;
  831. ap_sta_bind_vlan(hapd, sta, old_vlanid);
  832. } else {
  833. if (reassoc) {
  834. /*
  835. * Force EAPOL state machines to start
  836. * re-authentication without having to wait for the
  837. * Supplicant to send EAPOL-Start.
  838. */
  839. sta->eapol_sm->reAuthenticate = TRUE;
  840. }
  841. eapol_auth_step(sta->eapol_sm);
  842. }
  843. }
  844. void ieee802_1x_free_station(struct sta_info *sta)
  845. {
  846. struct eapol_state_machine *sm = sta->eapol_sm;
  847. if (sm == NULL)
  848. return;
  849. sta->eapol_sm = NULL;
  850. #ifndef CONFIG_NO_RADIUS
  851. radius_msg_free(sm->last_recv_radius);
  852. radius_free_class(&sm->radius_class);
  853. wpabuf_free(sm->radius_cui);
  854. #endif /* CONFIG_NO_RADIUS */
  855. os_free(sm->identity);
  856. eapol_auth_free(sm);
  857. }
  858. #ifndef CONFIG_NO_RADIUS
  859. static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
  860. struct sta_info *sta)
  861. {
  862. u8 *eap;
  863. size_t len;
  864. struct eap_hdr *hdr;
  865. int eap_type = -1;
  866. char buf[64];
  867. struct radius_msg *msg;
  868. struct eapol_state_machine *sm = sta->eapol_sm;
  869. if (sm == NULL || sm->last_recv_radius == NULL) {
  870. if (sm)
  871. sm->eap_if->aaaEapNoReq = TRUE;
  872. return;
  873. }
  874. msg = sm->last_recv_radius;
  875. eap = radius_msg_get_eap(msg, &len);
  876. if (eap == NULL) {
  877. /* RFC 3579, Chap. 2.6.3:
  878. * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
  879. * attribute */
  880. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  881. HOSTAPD_LEVEL_WARNING, "could not extract "
  882. "EAP-Message from RADIUS message");
  883. sm->eap_if->aaaEapNoReq = TRUE;
  884. return;
  885. }
  886. if (len < sizeof(*hdr)) {
  887. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  888. HOSTAPD_LEVEL_WARNING, "too short EAP packet "
  889. "received from authentication server");
  890. os_free(eap);
  891. sm->eap_if->aaaEapNoReq = TRUE;
  892. return;
  893. }
  894. if (len > sizeof(*hdr))
  895. eap_type = eap[sizeof(*hdr)];
  896. hdr = (struct eap_hdr *) eap;
  897. switch (hdr->code) {
  898. case EAP_CODE_REQUEST:
  899. if (eap_type >= 0)
  900. sm->eap_type_authsrv = eap_type;
  901. os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
  902. eap_type >= 0 ? eap_server_get_name(0, eap_type) :
  903. "??",
  904. eap_type);
  905. break;
  906. case EAP_CODE_RESPONSE:
  907. os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
  908. eap_type >= 0 ? eap_server_get_name(0, eap_type) :
  909. "??",
  910. eap_type);
  911. break;
  912. case EAP_CODE_SUCCESS:
  913. os_strlcpy(buf, "EAP Success", sizeof(buf));
  914. break;
  915. case EAP_CODE_FAILURE:
  916. os_strlcpy(buf, "EAP Failure", sizeof(buf));
  917. break;
  918. default:
  919. os_strlcpy(buf, "unknown EAP code", sizeof(buf));
  920. break;
  921. }
  922. buf[sizeof(buf) - 1] = '\0';
  923. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  924. HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
  925. "id=%d len=%d) from RADIUS server: %s",
  926. hdr->code, hdr->identifier, be_to_host16(hdr->length),
  927. buf);
  928. sm->eap_if->aaaEapReq = TRUE;
  929. wpabuf_free(sm->eap_if->aaaEapReqData);
  930. sm->eap_if->aaaEapReqData = wpabuf_alloc_ext_data(eap, len);
  931. }
  932. static void ieee802_1x_get_keys(struct hostapd_data *hapd,
  933. struct sta_info *sta, struct radius_msg *msg,
  934. struct radius_msg *req,
  935. const u8 *shared_secret,
  936. size_t shared_secret_len)
  937. {
  938. struct radius_ms_mppe_keys *keys;
  939. struct eapol_state_machine *sm = sta->eapol_sm;
  940. if (sm == NULL)
  941. return;
  942. keys = radius_msg_get_ms_keys(msg, req, shared_secret,
  943. shared_secret_len);
  944. if (keys && keys->send && keys->recv) {
  945. size_t len = keys->send_len + keys->recv_len;
  946. wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
  947. keys->send, keys->send_len);
  948. wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
  949. keys->recv, keys->recv_len);
  950. os_free(sm->eap_if->aaaEapKeyData);
  951. sm->eap_if->aaaEapKeyData = os_malloc(len);
  952. if (sm->eap_if->aaaEapKeyData) {
  953. os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
  954. keys->recv_len);
  955. os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
  956. keys->send, keys->send_len);
  957. sm->eap_if->aaaEapKeyDataLen = len;
  958. sm->eap_if->aaaEapKeyAvailable = TRUE;
  959. }
  960. }
  961. if (keys) {
  962. os_free(keys->send);
  963. os_free(keys->recv);
  964. os_free(keys);
  965. }
  966. }
  967. static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
  968. struct sta_info *sta,
  969. struct radius_msg *msg)
  970. {
  971. u8 *class;
  972. size_t class_len;
  973. struct eapol_state_machine *sm = sta->eapol_sm;
  974. int count, i;
  975. struct radius_attr_data *nclass;
  976. size_t nclass_count;
  977. if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
  978. sm == NULL)
  979. return;
  980. radius_free_class(&sm->radius_class);
  981. count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
  982. if (count <= 0)
  983. return;
  984. nclass = os_zalloc(count * sizeof(struct radius_attr_data));
  985. if (nclass == NULL)
  986. return;
  987. nclass_count = 0;
  988. class = NULL;
  989. for (i = 0; i < count; i++) {
  990. do {
  991. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
  992. &class, &class_len,
  993. class) < 0) {
  994. i = count;
  995. break;
  996. }
  997. } while (class_len < 1);
  998. nclass[nclass_count].data = os_malloc(class_len);
  999. if (nclass[nclass_count].data == NULL)
  1000. break;
  1001. os_memcpy(nclass[nclass_count].data, class, class_len);
  1002. nclass[nclass_count].len = class_len;
  1003. nclass_count++;
  1004. }
  1005. sm->radius_class.attr = nclass;
  1006. sm->radius_class.count = nclass_count;
  1007. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
  1008. "attributes for " MACSTR,
  1009. (unsigned long) sm->radius_class.count,
  1010. MAC2STR(sta->addr));
  1011. }
  1012. /* Update sta->identity based on User-Name attribute in Access-Accept */
  1013. static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
  1014. struct sta_info *sta,
  1015. struct radius_msg *msg)
  1016. {
  1017. u8 *buf, *identity;
  1018. size_t len;
  1019. struct eapol_state_machine *sm = sta->eapol_sm;
  1020. if (sm == NULL)
  1021. return;
  1022. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
  1023. NULL) < 0)
  1024. return;
  1025. identity = os_malloc(len + 1);
  1026. if (identity == NULL)
  1027. return;
  1028. os_memcpy(identity, buf, len);
  1029. identity[len] = '\0';
  1030. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1031. HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
  1032. "User-Name from Access-Accept '%s'",
  1033. sm->identity ? (char *) sm->identity : "N/A",
  1034. (char *) identity);
  1035. os_free(sm->identity);
  1036. sm->identity = identity;
  1037. sm->identity_len = len;
  1038. }
  1039. /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
  1040. static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
  1041. struct sta_info *sta,
  1042. struct radius_msg *msg)
  1043. {
  1044. struct eapol_state_machine *sm = sta->eapol_sm;
  1045. struct wpabuf *cui;
  1046. u8 *buf;
  1047. size_t len;
  1048. if (sm == NULL)
  1049. return;
  1050. if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
  1051. &buf, &len, NULL) < 0)
  1052. return;
  1053. cui = wpabuf_alloc_copy(buf, len);
  1054. if (cui == NULL)
  1055. return;
  1056. wpabuf_free(sm->radius_cui);
  1057. sm->radius_cui = cui;
  1058. }
  1059. struct sta_id_search {
  1060. u8 identifier;
  1061. struct eapol_state_machine *sm;
  1062. };
  1063. static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
  1064. struct sta_info *sta,
  1065. void *ctx)
  1066. {
  1067. struct sta_id_search *id_search = ctx;
  1068. struct eapol_state_machine *sm = sta->eapol_sm;
  1069. if (sm && sm->radius_identifier >= 0 &&
  1070. sm->radius_identifier == id_search->identifier) {
  1071. id_search->sm = sm;
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. static struct eapol_state_machine *
  1077. ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
  1078. {
  1079. struct sta_id_search id_search;
  1080. id_search.identifier = identifier;
  1081. id_search.sm = NULL;
  1082. ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
  1083. return id_search.sm;
  1084. }
  1085. /**
  1086. * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
  1087. * @msg: RADIUS response message
  1088. * @req: RADIUS request message
  1089. * @shared_secret: RADIUS shared secret
  1090. * @shared_secret_len: Length of shared_secret in octets
  1091. * @data: Context data (struct hostapd_data *)
  1092. * Returns: Processing status
  1093. */
  1094. static RadiusRxResult
  1095. ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
  1096. const u8 *shared_secret, size_t shared_secret_len,
  1097. void *data)
  1098. {
  1099. struct hostapd_data *hapd = data;
  1100. struct sta_info *sta;
  1101. u32 session_timeout = 0, termination_action, acct_interim_interval;
  1102. int session_timeout_set, old_vlanid = 0;
  1103. struct eapol_state_machine *sm;
  1104. int override_eapReq = 0;
  1105. struct radius_hdr *hdr = radius_msg_get_hdr(msg);
  1106. sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
  1107. if (sm == NULL) {
  1108. wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
  1109. "station for this RADIUS message");
  1110. return RADIUS_RX_UNKNOWN;
  1111. }
  1112. sta = sm->sta;
  1113. /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
  1114. * present when packet contains an EAP-Message attribute */
  1115. if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
  1116. radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
  1117. 0) < 0 &&
  1118. radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
  1119. wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
  1120. "Message-Authenticator since it does not include "
  1121. "EAP-Message");
  1122. } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
  1123. req, 1)) {
  1124. printf("Incoming RADIUS packet did not have correct "
  1125. "Message-Authenticator - dropped\n");
  1126. return RADIUS_RX_INVALID_AUTHENTICATOR;
  1127. }
  1128. if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
  1129. hdr->code != RADIUS_CODE_ACCESS_REJECT &&
  1130. hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
  1131. printf("Unknown RADIUS message code\n");
  1132. return RADIUS_RX_UNKNOWN;
  1133. }
  1134. sm->radius_identifier = -1;
  1135. wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
  1136. MAC2STR(sta->addr));
  1137. radius_msg_free(sm->last_recv_radius);
  1138. sm->last_recv_radius = msg;
  1139. session_timeout_set =
  1140. !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
  1141. &session_timeout);
  1142. if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
  1143. &termination_action))
  1144. termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
  1145. if (hapd->conf->acct_interim_interval == 0 &&
  1146. hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
  1147. radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
  1148. &acct_interim_interval) == 0) {
  1149. if (acct_interim_interval < 60) {
  1150. hostapd_logger(hapd, sta->addr,
  1151. HOSTAPD_MODULE_IEEE8021X,
  1152. HOSTAPD_LEVEL_INFO,
  1153. "ignored too small "
  1154. "Acct-Interim-Interval %d",
  1155. acct_interim_interval);
  1156. } else
  1157. sta->acct_interim_interval = acct_interim_interval;
  1158. }
  1159. switch (hdr->code) {
  1160. case RADIUS_CODE_ACCESS_ACCEPT:
  1161. if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
  1162. sta->vlan_id = 0;
  1163. #ifndef CONFIG_NO_VLAN
  1164. else {
  1165. old_vlanid = sta->vlan_id;
  1166. sta->vlan_id = radius_msg_get_vlanid(msg);
  1167. }
  1168. if (sta->vlan_id > 0 &&
  1169. hostapd_get_vlan_id_ifname(hapd->conf->vlan,
  1170. sta->vlan_id)) {
  1171. hostapd_logger(hapd, sta->addr,
  1172. HOSTAPD_MODULE_RADIUS,
  1173. HOSTAPD_LEVEL_INFO,
  1174. "VLAN ID %d", sta->vlan_id);
  1175. } else if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_REQUIRED) {
  1176. sta->eapol_sm->authFail = TRUE;
  1177. hostapd_logger(hapd, sta->addr,
  1178. HOSTAPD_MODULE_IEEE8021X,
  1179. HOSTAPD_LEVEL_INFO, "authentication "
  1180. "server did not include required VLAN "
  1181. "ID in Access-Accept");
  1182. break;
  1183. }
  1184. #endif /* CONFIG_NO_VLAN */
  1185. if (ap_sta_bind_vlan(hapd, sta, old_vlanid) < 0)
  1186. break;
  1187. /* RFC 3580, Ch. 3.17 */
  1188. if (session_timeout_set && termination_action ==
  1189. RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
  1190. sm->reAuthPeriod = session_timeout;
  1191. } else if (session_timeout_set)
  1192. ap_sta_session_timeout(hapd, sta, session_timeout);
  1193. sm->eap_if->aaaSuccess = TRUE;
  1194. override_eapReq = 1;
  1195. ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
  1196. shared_secret_len);
  1197. ieee802_1x_store_radius_class(hapd, sta, msg);
  1198. ieee802_1x_update_sta_identity(hapd, sta, msg);
  1199. ieee802_1x_update_sta_cui(hapd, sta, msg);
  1200. if (sm->eap_if->eapKeyAvailable &&
  1201. wpa_auth_pmksa_add(sta->wpa_sm, sm->eapol_key_crypt,
  1202. session_timeout_set ?
  1203. (int) session_timeout : -1, sm) == 0) {
  1204. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
  1205. HOSTAPD_LEVEL_DEBUG,
  1206. "Added PMKSA cache entry");
  1207. }
  1208. break;
  1209. case RADIUS_CODE_ACCESS_REJECT:
  1210. sm->eap_if->aaaFail = TRUE;
  1211. override_eapReq = 1;
  1212. break;
  1213. case RADIUS_CODE_ACCESS_CHALLENGE:
  1214. sm->eap_if->aaaEapReq = TRUE;
  1215. if (session_timeout_set) {
  1216. /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
  1217. sm->eap_if->aaaMethodTimeout = session_timeout;
  1218. hostapd_logger(hapd, sm->addr,
  1219. HOSTAPD_MODULE_IEEE8021X,
  1220. HOSTAPD_LEVEL_DEBUG,
  1221. "using EAP timeout of %d seconds (from "
  1222. "RADIUS)",
  1223. sm->eap_if->aaaMethodTimeout);
  1224. } else {
  1225. /*
  1226. * Use dynamic retransmission behavior per EAP
  1227. * specification.
  1228. */
  1229. sm->eap_if->aaaMethodTimeout = 0;
  1230. }
  1231. break;
  1232. }
  1233. ieee802_1x_decapsulate_radius(hapd, sta);
  1234. if (override_eapReq)
  1235. sm->eap_if->aaaEapReq = FALSE;
  1236. eapol_auth_step(sm);
  1237. return RADIUS_RX_QUEUED;
  1238. }
  1239. #endif /* CONFIG_NO_RADIUS */
  1240. void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
  1241. {
  1242. struct eapol_state_machine *sm = sta->eapol_sm;
  1243. if (sm == NULL)
  1244. return;
  1245. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1246. HOSTAPD_LEVEL_DEBUG, "aborting authentication");
  1247. #ifndef CONFIG_NO_RADIUS
  1248. radius_msg_free(sm->last_recv_radius);
  1249. sm->last_recv_radius = NULL;
  1250. #endif /* CONFIG_NO_RADIUS */
  1251. if (sm->eap_if->eapTimeout) {
  1252. /*
  1253. * Disconnect the STA since it did not reply to the last EAP
  1254. * request and we cannot continue EAP processing (EAP-Failure
  1255. * could only be sent if the EAP peer actually replied).
  1256. */
  1257. wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
  1258. MAC2STR(sta->addr));
  1259. sm->eap_if->portEnabled = FALSE;
  1260. ap_sta_disconnect(hapd, sta, sta->addr,
  1261. WLAN_REASON_PREV_AUTH_NOT_VALID);
  1262. }
  1263. }
  1264. static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
  1265. {
  1266. struct eapol_authenticator *eapol = hapd->eapol_auth;
  1267. if (hapd->conf->default_wep_key_len < 1)
  1268. return 0;
  1269. os_free(eapol->default_wep_key);
  1270. eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
  1271. if (eapol->default_wep_key == NULL ||
  1272. random_get_bytes(eapol->default_wep_key,
  1273. hapd->conf->default_wep_key_len)) {
  1274. printf("Could not generate random WEP key.\n");
  1275. os_free(eapol->default_wep_key);
  1276. eapol->default_wep_key = NULL;
  1277. return -1;
  1278. }
  1279. wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
  1280. eapol->default_wep_key,
  1281. hapd->conf->default_wep_key_len);
  1282. return 0;
  1283. }
  1284. static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
  1285. struct sta_info *sta, void *ctx)
  1286. {
  1287. if (sta->eapol_sm) {
  1288. sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
  1289. eapol_auth_step(sta->eapol_sm);
  1290. }
  1291. return 0;
  1292. }
  1293. static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
  1294. {
  1295. struct hostapd_data *hapd = eloop_ctx;
  1296. struct eapol_authenticator *eapol = hapd->eapol_auth;
  1297. if (eapol->default_wep_key_idx >= 3)
  1298. eapol->default_wep_key_idx =
  1299. hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
  1300. else
  1301. eapol->default_wep_key_idx++;
  1302. wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
  1303. eapol->default_wep_key_idx);
  1304. if (ieee802_1x_rekey_broadcast(hapd)) {
  1305. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
  1306. HOSTAPD_LEVEL_WARNING, "failed to generate a "
  1307. "new broadcast key");
  1308. os_free(eapol->default_wep_key);
  1309. eapol->default_wep_key = NULL;
  1310. return;
  1311. }
  1312. /* TODO: Could setup key for RX here, but change default TX keyid only
  1313. * after new broadcast key has been sent to all stations. */
  1314. if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
  1315. broadcast_ether_addr,
  1316. eapol->default_wep_key_idx, 1, NULL, 0,
  1317. eapol->default_wep_key,
  1318. hapd->conf->default_wep_key_len)) {
  1319. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
  1320. HOSTAPD_LEVEL_WARNING, "failed to configure a "
  1321. "new broadcast key");
  1322. os_free(eapol->default_wep_key);
  1323. eapol->default_wep_key = NULL;
  1324. return;
  1325. }
  1326. ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
  1327. if (hapd->conf->wep_rekeying_period > 0) {
  1328. eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
  1329. ieee802_1x_rekey, hapd, NULL);
  1330. }
  1331. }
  1332. static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
  1333. const u8 *data, size_t datalen)
  1334. {
  1335. #ifdef CONFIG_WPS
  1336. struct sta_info *sta = sta_ctx;
  1337. if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
  1338. WLAN_STA_MAYBE_WPS) {
  1339. const u8 *identity;
  1340. size_t identity_len;
  1341. struct eapol_state_machine *sm = sta->eapol_sm;
  1342. identity = eap_get_identity(sm->eap, &identity_len);
  1343. if (identity &&
  1344. ((identity_len == WSC_ID_ENROLLEE_LEN &&
  1345. os_memcmp(identity, WSC_ID_ENROLLEE,
  1346. WSC_ID_ENROLLEE_LEN) == 0) ||
  1347. (identity_len == WSC_ID_REGISTRAR_LEN &&
  1348. os_memcmp(identity, WSC_ID_REGISTRAR,
  1349. WSC_ID_REGISTRAR_LEN) == 0))) {
  1350. wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
  1351. "WLAN_STA_WPS");
  1352. sta->flags |= WLAN_STA_WPS;
  1353. }
  1354. }
  1355. #endif /* CONFIG_WPS */
  1356. ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
  1357. }
  1358. static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
  1359. const u8 *data, size_t datalen)
  1360. {
  1361. #ifndef CONFIG_NO_RADIUS
  1362. struct hostapd_data *hapd = ctx;
  1363. struct sta_info *sta = sta_ctx;
  1364. ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
  1365. #endif /* CONFIG_NO_RADIUS */
  1366. }
  1367. static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
  1368. int preauth)
  1369. {
  1370. struct hostapd_data *hapd = ctx;
  1371. struct sta_info *sta = sta_ctx;
  1372. if (preauth)
  1373. rsn_preauth_finished(hapd, sta, success);
  1374. else
  1375. ieee802_1x_finished(hapd, sta, success);
  1376. }
  1377. static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
  1378. size_t identity_len, int phase2,
  1379. struct eap_user *user)
  1380. {
  1381. struct hostapd_data *hapd = ctx;
  1382. const struct hostapd_eap_user *eap_user;
  1383. int i;
  1384. eap_user = hostapd_get_eap_user(hapd->conf, identity,
  1385. identity_len, phase2);
  1386. if (eap_user == NULL)
  1387. return -1;
  1388. os_memset(user, 0, sizeof(*user));
  1389. user->phase2 = phase2;
  1390. for (i = 0; i < EAP_MAX_METHODS; i++) {
  1391. user->methods[i].vendor = eap_user->methods[i].vendor;
  1392. user->methods[i].method = eap_user->methods[i].method;
  1393. }
  1394. if (eap_user->password) {
  1395. user->password = os_malloc(eap_user->password_len);
  1396. if (user->password == NULL)
  1397. return -1;
  1398. os_memcpy(user->password, eap_user->password,
  1399. eap_user->password_len);
  1400. user->password_len = eap_user->password_len;
  1401. user->password_hash = eap_user->password_hash;
  1402. }
  1403. user->force_version = eap_user->force_version;
  1404. user->ttls_auth = eap_user->ttls_auth;
  1405. return 0;
  1406. }
  1407. static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
  1408. {
  1409. struct hostapd_data *hapd = ctx;
  1410. struct sta_info *sta;
  1411. sta = ap_get_sta(hapd, addr);
  1412. if (sta == NULL || sta->eapol_sm == NULL)
  1413. return 0;
  1414. return 1;
  1415. }
  1416. static void ieee802_1x_logger(void *ctx, const u8 *addr,
  1417. eapol_logger_level level, const char *txt)
  1418. {
  1419. #ifndef CONFIG_NO_HOSTAPD_LOGGER
  1420. struct hostapd_data *hapd = ctx;
  1421. int hlevel;
  1422. switch (level) {
  1423. case EAPOL_LOGGER_WARNING:
  1424. hlevel = HOSTAPD_LEVEL_WARNING;
  1425. break;
  1426. case EAPOL_LOGGER_INFO:
  1427. hlevel = HOSTAPD_LEVEL_INFO;
  1428. break;
  1429. case EAPOL_LOGGER_DEBUG:
  1430. default:
  1431. hlevel = HOSTAPD_LEVEL_DEBUG;
  1432. break;
  1433. }
  1434. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
  1435. txt);
  1436. #endif /* CONFIG_NO_HOSTAPD_LOGGER */
  1437. }
  1438. static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
  1439. int authorized)
  1440. {
  1441. struct hostapd_data *hapd = ctx;
  1442. struct sta_info *sta = sta_ctx;
  1443. ieee802_1x_set_sta_authorized(hapd, sta, authorized);
  1444. }
  1445. static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
  1446. {
  1447. struct hostapd_data *hapd = ctx;
  1448. struct sta_info *sta = sta_ctx;
  1449. ieee802_1x_abort_auth(hapd, sta);
  1450. }
  1451. static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
  1452. {
  1453. struct hostapd_data *hapd = ctx;
  1454. struct sta_info *sta = sta_ctx;
  1455. ieee802_1x_tx_key(hapd, sta);
  1456. }
  1457. static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
  1458. enum eapol_event type)
  1459. {
  1460. /* struct hostapd_data *hapd = ctx; */
  1461. struct sta_info *sta = sta_ctx;
  1462. switch (type) {
  1463. case EAPOL_AUTH_SM_CHANGE:
  1464. wpa_auth_sm_notify(sta->wpa_sm);
  1465. break;
  1466. case EAPOL_AUTH_REAUTHENTICATE:
  1467. wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
  1468. break;
  1469. }
  1470. }
  1471. int ieee802_1x_init(struct hostapd_data *hapd)
  1472. {
  1473. int i;
  1474. struct eapol_auth_config conf;
  1475. struct eapol_auth_cb cb;
  1476. os_memset(&conf, 0, sizeof(conf));
  1477. conf.ctx = hapd;
  1478. conf.eap_reauth_period = hapd->conf->eap_reauth_period;
  1479. conf.wpa = hapd->conf->wpa;
  1480. conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
  1481. conf.eap_server = hapd->conf->eap_server;
  1482. conf.ssl_ctx = hapd->ssl_ctx;
  1483. conf.msg_ctx = hapd->msg_ctx;
  1484. conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
  1485. conf.eap_req_id_text = hapd->conf->eap_req_id_text;
  1486. conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
  1487. conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
  1488. conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
  1489. conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
  1490. conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
  1491. conf.eap_fast_prov = hapd->conf->eap_fast_prov;
  1492. conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
  1493. conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
  1494. conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
  1495. conf.tnc = hapd->conf->tnc;
  1496. conf.wps = hapd->wps;
  1497. conf.fragment_size = hapd->conf->fragment_size;
  1498. conf.pwd_group = hapd->conf->pwd_group;
  1499. conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
  1500. os_memset(&cb, 0, sizeof(cb));
  1501. cb.eapol_send = ieee802_1x_eapol_send;
  1502. cb.aaa_send = ieee802_1x_aaa_send;
  1503. cb.finished = _ieee802_1x_finished;
  1504. cb.get_eap_user = ieee802_1x_get_eap_user;
  1505. cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
  1506. cb.logger = ieee802_1x_logger;
  1507. cb.set_port_authorized = ieee802_1x_set_port_authorized;
  1508. cb.abort_auth = _ieee802_1x_abort_auth;
  1509. cb.tx_key = _ieee802_1x_tx_key;
  1510. cb.eapol_event = ieee802_1x_eapol_event;
  1511. hapd->eapol_auth = eapol_auth_init(&conf, &cb);
  1512. if (hapd->eapol_auth == NULL)
  1513. return -1;
  1514. if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
  1515. hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
  1516. return -1;
  1517. #ifndef CONFIG_NO_RADIUS
  1518. if (radius_client_register(hapd->radius, RADIUS_AUTH,
  1519. ieee802_1x_receive_auth, hapd))
  1520. return -1;
  1521. #endif /* CONFIG_NO_RADIUS */
  1522. if (hapd->conf->default_wep_key_len) {
  1523. for (i = 0; i < 4; i++)
  1524. hostapd_drv_set_key(hapd->conf->iface, hapd,
  1525. WPA_ALG_NONE, NULL, i, 0, NULL, 0,
  1526. NULL, 0);
  1527. ieee802_1x_rekey(hapd, NULL);
  1528. if (hapd->eapol_auth->default_wep_key == NULL)
  1529. return -1;
  1530. }
  1531. return 0;
  1532. }
  1533. void ieee802_1x_deinit(struct hostapd_data *hapd)
  1534. {
  1535. eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
  1536. if (hapd->driver != NULL &&
  1537. (hapd->conf->ieee802_1x || hapd->conf->wpa))
  1538. hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
  1539. eapol_auth_deinit(hapd->eapol_auth);
  1540. hapd->eapol_auth = NULL;
  1541. }
  1542. int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
  1543. const u8 *buf, size_t len, int ack)
  1544. {
  1545. struct ieee80211_hdr *hdr;
  1546. u8 *pos;
  1547. const unsigned char rfc1042_hdr[ETH_ALEN] =
  1548. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  1549. if (sta == NULL)
  1550. return -1;
  1551. if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
  1552. return 0;
  1553. hdr = (struct ieee80211_hdr *) buf;
  1554. pos = (u8 *) (hdr + 1);
  1555. if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
  1556. return 0;
  1557. pos += sizeof(rfc1042_hdr);
  1558. if (WPA_GET_BE16(pos) != ETH_P_PAE)
  1559. return 0;
  1560. pos += 2;
  1561. return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
  1562. ack);
  1563. }
  1564. int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
  1565. const u8 *buf, int len, int ack)
  1566. {
  1567. const struct ieee802_1x_hdr *xhdr =
  1568. (const struct ieee802_1x_hdr *) buf;
  1569. const u8 *pos = buf + sizeof(*xhdr);
  1570. struct ieee802_1x_eapol_key *key;
  1571. if (len < (int) sizeof(*xhdr))
  1572. return 0;
  1573. wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
  1574. "type=%d length=%d - ack=%d",
  1575. MAC2STR(sta->addr), xhdr->version, xhdr->type,
  1576. be_to_host16(xhdr->length), ack);
  1577. if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
  1578. return 0;
  1579. if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
  1580. const struct wpa_eapol_key *wpa;
  1581. wpa = (const struct wpa_eapol_key *) pos;
  1582. if (wpa->type == EAPOL_KEY_TYPE_RSN ||
  1583. wpa->type == EAPOL_KEY_TYPE_WPA)
  1584. wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
  1585. sta->wpa_sm, ack);
  1586. }
  1587. /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
  1588. * or Authenticator state machines, but EAPOL-Key packets are not
  1589. * retransmitted in case of failure. Try to re-send failed EAPOL-Key
  1590. * packets couple of times because otherwise STA keys become
  1591. * unsynchronized with AP. */
  1592. if (!ack && pos + sizeof(*key) <= buf + len) {
  1593. key = (struct ieee802_1x_eapol_key *) pos;
  1594. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
  1595. HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
  1596. "frame (%scast index=%d)",
  1597. key->key_index & BIT(7) ? "uni" : "broad",
  1598. key->key_index & ~BIT(7));
  1599. /* TODO: re-send EAPOL-Key couple of times (with short delay
  1600. * between them?). If all attempt fail, report error and
  1601. * deauthenticate STA so that it will get new keys when
  1602. * authenticating again (e.g., after returning in range).
  1603. * Separate limit/transmit state needed both for unicast and
  1604. * broadcast keys(?) */
  1605. }
  1606. /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
  1607. * to here and change the key only if the EAPOL-Key packet was Acked.
  1608. */
  1609. return 1;
  1610. }
  1611. u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
  1612. {
  1613. if (sm == NULL || sm->identity == NULL)
  1614. return NULL;
  1615. *len = sm->identity_len;
  1616. return sm->identity;
  1617. }
  1618. u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
  1619. int idx)
  1620. {
  1621. if (sm == NULL || sm->radius_class.attr == NULL ||
  1622. idx >= (int) sm->radius_class.count)
  1623. return NULL;
  1624. *len = sm->radius_class.attr[idx].len;
  1625. return sm->radius_class.attr[idx].data;
  1626. }
  1627. struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
  1628. {
  1629. if (sm == NULL)
  1630. return NULL;
  1631. return sm->radius_cui;
  1632. }
  1633. const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
  1634. {
  1635. *len = 0;
  1636. if (sm == NULL)
  1637. return NULL;
  1638. *len = sm->eap_if->eapKeyDataLen;
  1639. return sm->eap_if->eapKeyData;
  1640. }
  1641. void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
  1642. int enabled)
  1643. {
  1644. if (sm == NULL)
  1645. return;
  1646. sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
  1647. eapol_auth_step(sm);
  1648. }
  1649. void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
  1650. int valid)
  1651. {
  1652. if (sm == NULL)
  1653. return;
  1654. sm->portValid = valid ? TRUE : FALSE;
  1655. eapol_auth_step(sm);
  1656. }
  1657. void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
  1658. {
  1659. if (sm == NULL)
  1660. return;
  1661. if (pre_auth)
  1662. sm->flags |= EAPOL_SM_PREAUTH;
  1663. else
  1664. sm->flags &= ~EAPOL_SM_PREAUTH;
  1665. }
  1666. static const char * bool_txt(Boolean bool)
  1667. {
  1668. return bool ? "TRUE" : "FALSE";
  1669. }
  1670. int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  1671. {
  1672. /* TODO */
  1673. return 0;
  1674. }
  1675. int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
  1676. char *buf, size_t buflen)
  1677. {
  1678. int len = 0, ret;
  1679. struct eapol_state_machine *sm = sta->eapol_sm;
  1680. struct os_time t;
  1681. if (sm == NULL)
  1682. return 0;
  1683. ret = os_snprintf(buf + len, buflen - len,
  1684. "dot1xPaePortNumber=%d\n"
  1685. "dot1xPaePortProtocolVersion=%d\n"
  1686. "dot1xPaePortCapabilities=1\n"
  1687. "dot1xPaePortInitialize=%d\n"
  1688. "dot1xPaePortReauthenticate=FALSE\n",
  1689. sta->aid,
  1690. EAPOL_VERSION,
  1691. sm->initialize);
  1692. if (ret < 0 || (size_t) ret >= buflen - len)
  1693. return len;
  1694. len += ret;
  1695. /* dot1xAuthConfigTable */
  1696. ret = os_snprintf(buf + len, buflen - len,
  1697. "dot1xAuthPaeState=%d\n"
  1698. "dot1xAuthBackendAuthState=%d\n"
  1699. "dot1xAuthAdminControlledDirections=%d\n"
  1700. "dot1xAuthOperControlledDirections=%d\n"
  1701. "dot1xAuthAuthControlledPortStatus=%d\n"
  1702. "dot1xAuthAuthControlledPortControl=%d\n"
  1703. "dot1xAuthQuietPeriod=%u\n"
  1704. "dot1xAuthServerTimeout=%u\n"
  1705. "dot1xAuthReAuthPeriod=%u\n"
  1706. "dot1xAuthReAuthEnabled=%s\n"
  1707. "dot1xAuthKeyTxEnabled=%s\n",
  1708. sm->auth_pae_state + 1,
  1709. sm->be_auth_state + 1,
  1710. sm->adminControlledDirections,
  1711. sm->operControlledDirections,
  1712. sm->authPortStatus,
  1713. sm->portControl,
  1714. sm->quietPeriod,
  1715. sm->serverTimeout,
  1716. sm->reAuthPeriod,
  1717. bool_txt(sm->reAuthEnabled),
  1718. bool_txt(sm->keyTxEnabled));
  1719. if (ret < 0 || (size_t) ret >= buflen - len)
  1720. return len;
  1721. len += ret;
  1722. /* dot1xAuthStatsTable */
  1723. ret = os_snprintf(buf + len, buflen - len,
  1724. "dot1xAuthEapolFramesRx=%u\n"
  1725. "dot1xAuthEapolFramesTx=%u\n"
  1726. "dot1xAuthEapolStartFramesRx=%u\n"
  1727. "dot1xAuthEapolLogoffFramesRx=%u\n"
  1728. "dot1xAuthEapolRespIdFramesRx=%u\n"
  1729. "dot1xAuthEapolRespFramesRx=%u\n"
  1730. "dot1xAuthEapolReqIdFramesTx=%u\n"
  1731. "dot1xAuthEapolReqFramesTx=%u\n"
  1732. "dot1xAuthInvalidEapolFramesRx=%u\n"
  1733. "dot1xAuthEapLengthErrorFramesRx=%u\n"
  1734. "dot1xAuthLastEapolFrameVersion=%u\n"
  1735. "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
  1736. sm->dot1xAuthEapolFramesRx,
  1737. sm->dot1xAuthEapolFramesTx,
  1738. sm->dot1xAuthEapolStartFramesRx,
  1739. sm->dot1xAuthEapolLogoffFramesRx,
  1740. sm->dot1xAuthEapolRespIdFramesRx,
  1741. sm->dot1xAuthEapolRespFramesRx,
  1742. sm->dot1xAuthEapolReqIdFramesTx,
  1743. sm->dot1xAuthEapolReqFramesTx,
  1744. sm->dot1xAuthInvalidEapolFramesRx,
  1745. sm->dot1xAuthEapLengthErrorFramesRx,
  1746. sm->dot1xAuthLastEapolFrameVersion,
  1747. MAC2STR(sm->addr));
  1748. if (ret < 0 || (size_t) ret >= buflen - len)
  1749. return len;
  1750. len += ret;
  1751. /* dot1xAuthDiagTable */
  1752. ret = os_snprintf(buf + len, buflen - len,
  1753. "dot1xAuthEntersConnecting=%u\n"
  1754. "dot1xAuthEapLogoffsWhileConnecting=%u\n"
  1755. "dot1xAuthEntersAuthenticating=%u\n"
  1756. "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
  1757. "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
  1758. "dot1xAuthAuthFailWhileAuthenticating=%u\n"
  1759. "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
  1760. "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
  1761. "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
  1762. "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
  1763. "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
  1764. "dot1xAuthBackendResponses=%u\n"
  1765. "dot1xAuthBackendAccessChallenges=%u\n"
  1766. "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
  1767. "dot1xAuthBackendAuthSuccesses=%u\n"
  1768. "dot1xAuthBackendAuthFails=%u\n",
  1769. sm->authEntersConnecting,
  1770. sm->authEapLogoffsWhileConnecting,
  1771. sm->authEntersAuthenticating,
  1772. sm->authAuthSuccessesWhileAuthenticating,
  1773. sm->authAuthTimeoutsWhileAuthenticating,
  1774. sm->authAuthFailWhileAuthenticating,
  1775. sm->authAuthEapStartsWhileAuthenticating,
  1776. sm->authAuthEapLogoffWhileAuthenticating,
  1777. sm->authAuthReauthsWhileAuthenticated,
  1778. sm->authAuthEapStartsWhileAuthenticated,
  1779. sm->authAuthEapLogoffWhileAuthenticated,
  1780. sm->backendResponses,
  1781. sm->backendAccessChallenges,
  1782. sm->backendOtherRequestsToSupplicant,
  1783. sm->backendAuthSuccesses,
  1784. sm->backendAuthFails);
  1785. if (ret < 0 || (size_t) ret >= buflen - len)
  1786. return len;
  1787. len += ret;
  1788. /* dot1xAuthSessionStatsTable */
  1789. os_get_time(&t);
  1790. ret = os_snprintf(buf + len, buflen - len,
  1791. /* TODO: dot1xAuthSessionOctetsRx */
  1792. /* TODO: dot1xAuthSessionOctetsTx */
  1793. /* TODO: dot1xAuthSessionFramesRx */
  1794. /* TODO: dot1xAuthSessionFramesTx */
  1795. "dot1xAuthSessionId=%08X-%08X\n"
  1796. "dot1xAuthSessionAuthenticMethod=%d\n"
  1797. "dot1xAuthSessionTime=%u\n"
  1798. "dot1xAuthSessionTerminateCause=999\n"
  1799. "dot1xAuthSessionUserName=%s\n",
  1800. sta->acct_session_id_hi, sta->acct_session_id_lo,
  1801. (wpa_key_mgmt_wpa_ieee8021x(
  1802. wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
  1803. 1 : 2,
  1804. (unsigned int) (t.sec - sta->acct_session_start),
  1805. sm->identity);
  1806. if (ret < 0 || (size_t) ret >= buflen - len)
  1807. return len;
  1808. len += ret;
  1809. return len;
  1810. }
  1811. static void ieee802_1x_finished(struct hostapd_data *hapd,
  1812. struct sta_info *sta, int success)
  1813. {
  1814. const u8 *key;
  1815. size_t len;
  1816. /* TODO: get PMKLifetime from WPA parameters */
  1817. static const int dot11RSNAConfigPMKLifetime = 43200;
  1818. key = ieee802_1x_get_key(sta->eapol_sm, &len);
  1819. if (success && key && len >= PMK_LEN &&
  1820. wpa_auth_pmksa_add(sta->wpa_sm, key, dot11RSNAConfigPMKLifetime,
  1821. sta->eapol_sm) == 0) {
  1822. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
  1823. HOSTAPD_LEVEL_DEBUG,
  1824. "Added PMKSA cache entry (IEEE 802.1X)");
  1825. }
  1826. if (!success) {
  1827. /*
  1828. * Many devices require deauthentication after WPS provisioning
  1829. * and some may not be be able to do that themselves, so
  1830. * disconnect the client here. In addition, this may also
  1831. * benefit IEEE 802.1X/EAPOL authentication cases, too since
  1832. * the EAPOL PAE state machine would remain in HELD state for
  1833. * considerable amount of time and some EAP methods, like
  1834. * EAP-FAST with anonymous provisioning, may require another
  1835. * EAPOL authentication to be started to complete connection.
  1836. */
  1837. wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "IEEE 802.1X: Force "
  1838. "disconnection after EAP-Failure");
  1839. /* Add a small sleep to increase likelihood of previously
  1840. * requested EAP-Failure TX getting out before this should the
  1841. * driver reorder operations.
  1842. */
  1843. os_sleep(0, 10000);
  1844. ap_sta_disconnect(hapd, sta, sta->addr,
  1845. WLAN_REASON_IEEE_802_1X_AUTH_FAILED);
  1846. }
  1847. }