ieee802_1x.c 75 KB

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