eap.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /*
  2. * hostapd / EAP Full Authenticator state machine (RFC 4137)
  3. * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. *
  14. * This state machine is based on the full authenticator state machine defined
  15. * in RFC 4137. However, to support backend authentication in RADIUS
  16. * authentication server functionality, parts of backend authenticator (also
  17. * from RFC 4137) are mixed in. This functionality is enabled by setting
  18. * backend_auth configuration variable to TRUE.
  19. */
  20. #include "includes.h"
  21. #include "common.h"
  22. #include "eap_i.h"
  23. #include "state_machine.h"
  24. #define STATE_MACHINE_DATA struct eap_sm
  25. #define STATE_MACHINE_DEBUG_PREFIX "EAP"
  26. #define EAP_MAX_AUTH_ROUNDS 50
  27. static void eap_user_free(struct eap_user *user);
  28. /* EAP state machines are described in RFC 4137 */
  29. static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
  30. int eapSRTT, int eapRTTVAR,
  31. int methodTimeout);
  32. static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp);
  33. static int eap_sm_getId(const struct wpabuf *data);
  34. static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id);
  35. static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
  36. static int eap_sm_nextId(struct eap_sm *sm, int id);
  37. static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
  38. size_t len);
  39. static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
  40. static int eap_sm_Policy_getDecision(struct eap_sm *sm);
  41. static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
  42. static int eap_copy_buf(struct wpabuf **dst, const struct wpabuf *src)
  43. {
  44. if (src == NULL)
  45. return -1;
  46. wpabuf_free(*dst);
  47. *dst = wpabuf_dup(src);
  48. return *dst ? 0 : -1;
  49. }
  50. static int eap_copy_data(u8 **dst, size_t *dst_len,
  51. const u8 *src, size_t src_len)
  52. {
  53. if (src == NULL)
  54. return -1;
  55. os_free(*dst);
  56. *dst = os_malloc(src_len);
  57. if (*dst) {
  58. os_memcpy(*dst, src, src_len);
  59. *dst_len = src_len;
  60. return 0;
  61. } else {
  62. *dst_len = 0;
  63. return -1;
  64. }
  65. }
  66. #define EAP_COPY(dst, src) \
  67. eap_copy_data((dst), (dst ## Len), (src), (src ## Len))
  68. /**
  69. * eap_user_get - Fetch user information from the database
  70. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  71. * @identity: Identity (User-Name) of the user
  72. * @identity_len: Length of identity in bytes
  73. * @phase2: 0 = EAP phase1 user, 1 = EAP phase2 (tunneled) user
  74. * Returns: 0 on success, or -1 on failure
  75. *
  76. * This function is used to fetch user information for EAP. The user will be
  77. * selected based on the specified identity. sm->user and
  78. * sm->user_eap_method_index are updated for the new user when a matching user
  79. * is found. sm->user can be used to get user information (e.g., password).
  80. */
  81. int eap_user_get(struct eap_sm *sm, const u8 *identity, size_t identity_len,
  82. int phase2)
  83. {
  84. struct eap_user *user;
  85. if (sm == NULL || sm->eapol_cb == NULL ||
  86. sm->eapol_cb->get_eap_user == NULL)
  87. return -1;
  88. eap_user_free(sm->user);
  89. sm->user = NULL;
  90. user = os_zalloc(sizeof(*user));
  91. if (user == NULL)
  92. return -1;
  93. if (sm->eapol_cb->get_eap_user(sm->eapol_ctx, identity,
  94. identity_len, phase2, user) != 0) {
  95. eap_user_free(user);
  96. return -1;
  97. }
  98. sm->user = user;
  99. sm->user_eap_method_index = 0;
  100. return 0;
  101. }
  102. SM_STATE(EAP, DISABLED)
  103. {
  104. SM_ENTRY(EAP, DISABLED);
  105. sm->num_rounds = 0;
  106. }
  107. SM_STATE(EAP, INITIALIZE)
  108. {
  109. SM_ENTRY(EAP, INITIALIZE);
  110. sm->currentId = -1;
  111. sm->eap_if.eapSuccess = FALSE;
  112. sm->eap_if.eapFail = FALSE;
  113. sm->eap_if.eapTimeout = FALSE;
  114. os_free(sm->eap_if.eapKeyData);
  115. sm->eap_if.eapKeyData = NULL;
  116. sm->eap_if.eapKeyDataLen = 0;
  117. sm->eap_if.eapKeyAvailable = FALSE;
  118. sm->eap_if.eapRestart = FALSE;
  119. /*
  120. * This is not defined in RFC 4137, but method state needs to be
  121. * reseted here so that it does not remain in success state when
  122. * re-authentication starts.
  123. */
  124. if (sm->m && sm->eap_method_priv) {
  125. sm->m->reset(sm, sm->eap_method_priv);
  126. sm->eap_method_priv = NULL;
  127. }
  128. sm->m = NULL;
  129. sm->user_eap_method_index = 0;
  130. if (sm->backend_auth) {
  131. sm->currentMethod = EAP_TYPE_NONE;
  132. /* parse rxResp, respId, respMethod */
  133. eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
  134. if (sm->rxResp) {
  135. sm->currentId = sm->respId;
  136. }
  137. }
  138. sm->num_rounds = 0;
  139. sm->method_pending = METHOD_PENDING_NONE;
  140. }
  141. SM_STATE(EAP, PICK_UP_METHOD)
  142. {
  143. SM_ENTRY(EAP, PICK_UP_METHOD);
  144. if (eap_sm_Policy_doPickUp(sm, sm->respMethod)) {
  145. sm->currentMethod = sm->respMethod;
  146. if (sm->m && sm->eap_method_priv) {
  147. sm->m->reset(sm, sm->eap_method_priv);
  148. sm->eap_method_priv = NULL;
  149. }
  150. sm->m = eap_server_get_eap_method(EAP_VENDOR_IETF,
  151. sm->currentMethod);
  152. if (sm->m && sm->m->initPickUp) {
  153. sm->eap_method_priv = sm->m->initPickUp(sm);
  154. if (sm->eap_method_priv == NULL) {
  155. wpa_printf(MSG_DEBUG, "EAP: Failed to "
  156. "initialize EAP method %d",
  157. sm->currentMethod);
  158. sm->m = NULL;
  159. sm->currentMethod = EAP_TYPE_NONE;
  160. }
  161. } else {
  162. sm->m = NULL;
  163. sm->currentMethod = EAP_TYPE_NONE;
  164. }
  165. }
  166. }
  167. SM_STATE(EAP, IDLE)
  168. {
  169. SM_ENTRY(EAP, IDLE);
  170. sm->eap_if.retransWhile = eap_sm_calculateTimeout(
  171. sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
  172. sm->methodTimeout);
  173. }
  174. SM_STATE(EAP, RETRANSMIT)
  175. {
  176. SM_ENTRY(EAP, RETRANSMIT);
  177. sm->retransCount++;
  178. if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
  179. if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
  180. sm->eap_if.eapReq = TRUE;
  181. }
  182. }
  183. SM_STATE(EAP, RECEIVED)
  184. {
  185. SM_ENTRY(EAP, RECEIVED);
  186. /* parse rxResp, respId, respMethod */
  187. eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
  188. sm->num_rounds++;
  189. }
  190. SM_STATE(EAP, DISCARD)
  191. {
  192. SM_ENTRY(EAP, DISCARD);
  193. sm->eap_if.eapResp = FALSE;
  194. sm->eap_if.eapNoReq = TRUE;
  195. }
  196. SM_STATE(EAP, SEND_REQUEST)
  197. {
  198. SM_ENTRY(EAP, SEND_REQUEST);
  199. sm->retransCount = 0;
  200. if (sm->eap_if.eapReqData) {
  201. if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
  202. {
  203. sm->eap_if.eapResp = FALSE;
  204. sm->eap_if.eapReq = TRUE;
  205. } else {
  206. sm->eap_if.eapResp = FALSE;
  207. sm->eap_if.eapReq = FALSE;
  208. }
  209. } else {
  210. wpa_printf(MSG_INFO, "EAP: SEND_REQUEST - no eapReqData");
  211. sm->eap_if.eapResp = FALSE;
  212. sm->eap_if.eapReq = FALSE;
  213. sm->eap_if.eapNoReq = TRUE;
  214. }
  215. }
  216. SM_STATE(EAP, INTEGRITY_CHECK)
  217. {
  218. SM_ENTRY(EAP, INTEGRITY_CHECK);
  219. if (sm->m->check) {
  220. sm->ignore = sm->m->check(sm, sm->eap_method_priv,
  221. sm->eap_if.eapRespData);
  222. }
  223. }
  224. SM_STATE(EAP, METHOD_REQUEST)
  225. {
  226. SM_ENTRY(EAP, METHOD_REQUEST);
  227. if (sm->m == NULL) {
  228. wpa_printf(MSG_DEBUG, "EAP: method not initialized");
  229. return;
  230. }
  231. sm->currentId = eap_sm_nextId(sm, sm->currentId);
  232. wpa_printf(MSG_DEBUG, "EAP: building EAP-Request: Identifier %d",
  233. sm->currentId);
  234. sm->lastId = sm->currentId;
  235. wpabuf_free(sm->eap_if.eapReqData);
  236. sm->eap_if.eapReqData = sm->m->buildReq(sm, sm->eap_method_priv,
  237. sm->currentId);
  238. if (sm->m->getTimeout)
  239. sm->methodTimeout = sm->m->getTimeout(sm, sm->eap_method_priv);
  240. else
  241. sm->methodTimeout = 0;
  242. }
  243. SM_STATE(EAP, METHOD_RESPONSE)
  244. {
  245. SM_ENTRY(EAP, METHOD_RESPONSE);
  246. sm->m->process(sm, sm->eap_method_priv, sm->eap_if.eapRespData);
  247. if (sm->m->isDone(sm, sm->eap_method_priv)) {
  248. eap_sm_Policy_update(sm, NULL, 0);
  249. os_free(sm->eap_if.eapKeyData);
  250. if (sm->m->getKey) {
  251. sm->eap_if.eapKeyData = sm->m->getKey(
  252. sm, sm->eap_method_priv,
  253. &sm->eap_if.eapKeyDataLen);
  254. } else {
  255. sm->eap_if.eapKeyData = NULL;
  256. sm->eap_if.eapKeyDataLen = 0;
  257. }
  258. sm->methodState = METHOD_END;
  259. } else {
  260. sm->methodState = METHOD_CONTINUE;
  261. }
  262. }
  263. SM_STATE(EAP, PROPOSE_METHOD)
  264. {
  265. int vendor;
  266. EapType type;
  267. SM_ENTRY(EAP, PROPOSE_METHOD);
  268. type = eap_sm_Policy_getNextMethod(sm, &vendor);
  269. if (vendor == EAP_VENDOR_IETF)
  270. sm->currentMethod = type;
  271. else
  272. sm->currentMethod = EAP_TYPE_EXPANDED;
  273. if (sm->m && sm->eap_method_priv) {
  274. sm->m->reset(sm, sm->eap_method_priv);
  275. sm->eap_method_priv = NULL;
  276. }
  277. sm->m = eap_server_get_eap_method(vendor, type);
  278. if (sm->m) {
  279. sm->eap_method_priv = sm->m->init(sm);
  280. if (sm->eap_method_priv == NULL) {
  281. wpa_printf(MSG_DEBUG, "EAP: Failed to initialize EAP "
  282. "method %d", sm->currentMethod);
  283. sm->m = NULL;
  284. sm->currentMethod = EAP_TYPE_NONE;
  285. }
  286. }
  287. if (sm->currentMethod == EAP_TYPE_IDENTITY ||
  288. sm->currentMethod == EAP_TYPE_NOTIFICATION)
  289. sm->methodState = METHOD_CONTINUE;
  290. else
  291. sm->methodState = METHOD_PROPOSED;
  292. }
  293. SM_STATE(EAP, NAK)
  294. {
  295. const struct eap_hdr *nak;
  296. size_t len = 0;
  297. const u8 *pos;
  298. const u8 *nak_list = NULL;
  299. SM_ENTRY(EAP, NAK);
  300. if (sm->eap_method_priv) {
  301. sm->m->reset(sm, sm->eap_method_priv);
  302. sm->eap_method_priv = NULL;
  303. }
  304. sm->m = NULL;
  305. nak = wpabuf_head(sm->eap_if.eapRespData);
  306. if (nak && wpabuf_len(sm->eap_if.eapRespData) > sizeof(*nak)) {
  307. len = be_to_host16(nak->length);
  308. if (len > wpabuf_len(sm->eap_if.eapRespData))
  309. len = wpabuf_len(sm->eap_if.eapRespData);
  310. pos = (const u8 *) (nak + 1);
  311. len -= sizeof(*nak);
  312. if (*pos == EAP_TYPE_NAK) {
  313. pos++;
  314. len--;
  315. nak_list = pos;
  316. }
  317. }
  318. eap_sm_Policy_update(sm, nak_list, len);
  319. }
  320. SM_STATE(EAP, SELECT_ACTION)
  321. {
  322. SM_ENTRY(EAP, SELECT_ACTION);
  323. sm->decision = eap_sm_Policy_getDecision(sm);
  324. }
  325. SM_STATE(EAP, TIMEOUT_FAILURE)
  326. {
  327. SM_ENTRY(EAP, TIMEOUT_FAILURE);
  328. sm->eap_if.eapTimeout = TRUE;
  329. }
  330. SM_STATE(EAP, FAILURE)
  331. {
  332. SM_ENTRY(EAP, FAILURE);
  333. wpabuf_free(sm->eap_if.eapReqData);
  334. sm->eap_if.eapReqData = eap_sm_buildFailure(sm, sm->currentId);
  335. wpabuf_free(sm->lastReqData);
  336. sm->lastReqData = NULL;
  337. sm->eap_if.eapFail = TRUE;
  338. }
  339. SM_STATE(EAP, SUCCESS)
  340. {
  341. SM_ENTRY(EAP, SUCCESS);
  342. wpabuf_free(sm->eap_if.eapReqData);
  343. sm->eap_if.eapReqData = eap_sm_buildSuccess(sm, sm->currentId);
  344. wpabuf_free(sm->lastReqData);
  345. sm->lastReqData = NULL;
  346. if (sm->eap_if.eapKeyData)
  347. sm->eap_if.eapKeyAvailable = TRUE;
  348. sm->eap_if.eapSuccess = TRUE;
  349. }
  350. SM_STATE(EAP, INITIALIZE_PASSTHROUGH)
  351. {
  352. SM_ENTRY(EAP, INITIALIZE_PASSTHROUGH);
  353. wpabuf_free(sm->eap_if.aaaEapRespData);
  354. sm->eap_if.aaaEapRespData = NULL;
  355. }
  356. SM_STATE(EAP, IDLE2)
  357. {
  358. SM_ENTRY(EAP, IDLE2);
  359. sm->eap_if.retransWhile = eap_sm_calculateTimeout(
  360. sm, sm->retransCount, sm->eap_if.eapSRTT, sm->eap_if.eapRTTVAR,
  361. sm->methodTimeout);
  362. }
  363. SM_STATE(EAP, RETRANSMIT2)
  364. {
  365. SM_ENTRY(EAP, RETRANSMIT2);
  366. sm->retransCount++;
  367. if (sm->retransCount <= sm->MaxRetrans && sm->lastReqData) {
  368. if (eap_copy_buf(&sm->eap_if.eapReqData, sm->lastReqData) == 0)
  369. sm->eap_if.eapReq = TRUE;
  370. }
  371. }
  372. SM_STATE(EAP, RECEIVED2)
  373. {
  374. SM_ENTRY(EAP, RECEIVED2);
  375. /* parse rxResp, respId, respMethod */
  376. eap_sm_parseEapResp(sm, sm->eap_if.eapRespData);
  377. }
  378. SM_STATE(EAP, DISCARD2)
  379. {
  380. SM_ENTRY(EAP, DISCARD2);
  381. sm->eap_if.eapResp = FALSE;
  382. sm->eap_if.eapNoReq = TRUE;
  383. }
  384. SM_STATE(EAP, SEND_REQUEST2)
  385. {
  386. SM_ENTRY(EAP, SEND_REQUEST2);
  387. sm->retransCount = 0;
  388. if (sm->eap_if.eapReqData) {
  389. if (eap_copy_buf(&sm->lastReqData, sm->eap_if.eapReqData) == 0)
  390. {
  391. sm->eap_if.eapResp = FALSE;
  392. sm->eap_if.eapReq = TRUE;
  393. } else {
  394. sm->eap_if.eapResp = FALSE;
  395. sm->eap_if.eapReq = FALSE;
  396. }
  397. } else {
  398. wpa_printf(MSG_INFO, "EAP: SEND_REQUEST2 - no eapReqData");
  399. sm->eap_if.eapResp = FALSE;
  400. sm->eap_if.eapReq = FALSE;
  401. sm->eap_if.eapNoReq = TRUE;
  402. }
  403. }
  404. SM_STATE(EAP, AAA_REQUEST)
  405. {
  406. SM_ENTRY(EAP, AAA_REQUEST);
  407. if (sm->eap_if.eapRespData == NULL) {
  408. wpa_printf(MSG_INFO, "EAP: AAA_REQUEST - no eapRespData");
  409. return;
  410. }
  411. /*
  412. * if (respMethod == IDENTITY)
  413. * aaaIdentity = eapRespData
  414. * This is already taken care of by the EAP-Identity method which
  415. * stores the identity into sm->identity.
  416. */
  417. eap_copy_buf(&sm->eap_if.aaaEapRespData, sm->eap_if.eapRespData);
  418. }
  419. SM_STATE(EAP, AAA_RESPONSE)
  420. {
  421. SM_ENTRY(EAP, AAA_RESPONSE);
  422. eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
  423. sm->currentId = eap_sm_getId(sm->eap_if.eapReqData);
  424. sm->methodTimeout = sm->eap_if.aaaMethodTimeout;
  425. }
  426. SM_STATE(EAP, AAA_IDLE)
  427. {
  428. SM_ENTRY(EAP, AAA_IDLE);
  429. sm->eap_if.aaaFail = FALSE;
  430. sm->eap_if.aaaSuccess = FALSE;
  431. sm->eap_if.aaaEapReq = FALSE;
  432. sm->eap_if.aaaEapNoReq = FALSE;
  433. sm->eap_if.aaaEapResp = TRUE;
  434. }
  435. SM_STATE(EAP, TIMEOUT_FAILURE2)
  436. {
  437. SM_ENTRY(EAP, TIMEOUT_FAILURE2);
  438. sm->eap_if.eapTimeout = TRUE;
  439. }
  440. SM_STATE(EAP, FAILURE2)
  441. {
  442. SM_ENTRY(EAP, FAILURE2);
  443. eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
  444. sm->eap_if.eapFail = TRUE;
  445. }
  446. SM_STATE(EAP, SUCCESS2)
  447. {
  448. SM_ENTRY(EAP, SUCCESS2);
  449. eap_copy_buf(&sm->eap_if.eapReqData, sm->eap_if.aaaEapReqData);
  450. sm->eap_if.eapKeyAvailable = sm->eap_if.aaaEapKeyAvailable;
  451. if (sm->eap_if.aaaEapKeyAvailable) {
  452. EAP_COPY(&sm->eap_if.eapKeyData, sm->eap_if.aaaEapKeyData);
  453. } else {
  454. os_free(sm->eap_if.eapKeyData);
  455. sm->eap_if.eapKeyData = NULL;
  456. sm->eap_if.eapKeyDataLen = 0;
  457. }
  458. sm->eap_if.eapSuccess = TRUE;
  459. }
  460. SM_STEP(EAP)
  461. {
  462. if (sm->eap_if.eapRestart && sm->eap_if.portEnabled)
  463. SM_ENTER_GLOBAL(EAP, INITIALIZE);
  464. else if (!sm->eap_if.portEnabled)
  465. SM_ENTER_GLOBAL(EAP, DISABLED);
  466. else if (sm->num_rounds > EAP_MAX_AUTH_ROUNDS) {
  467. if (sm->num_rounds == EAP_MAX_AUTH_ROUNDS + 1) {
  468. wpa_printf(MSG_DEBUG, "EAP: more than %d "
  469. "authentication rounds - abort",
  470. EAP_MAX_AUTH_ROUNDS);
  471. sm->num_rounds++;
  472. SM_ENTER_GLOBAL(EAP, FAILURE);
  473. }
  474. } else switch (sm->EAP_state) {
  475. case EAP_INITIALIZE:
  476. if (sm->backend_auth) {
  477. if (!sm->rxResp)
  478. SM_ENTER(EAP, SELECT_ACTION);
  479. else if (sm->rxResp &&
  480. (sm->respMethod == EAP_TYPE_NAK ||
  481. (sm->respMethod == EAP_TYPE_EXPANDED &&
  482. sm->respVendor == EAP_VENDOR_IETF &&
  483. sm->respVendorMethod == EAP_TYPE_NAK)))
  484. SM_ENTER(EAP, NAK);
  485. else
  486. SM_ENTER(EAP, PICK_UP_METHOD);
  487. } else {
  488. SM_ENTER(EAP, SELECT_ACTION);
  489. }
  490. break;
  491. case EAP_PICK_UP_METHOD:
  492. if (sm->currentMethod == EAP_TYPE_NONE) {
  493. SM_ENTER(EAP, SELECT_ACTION);
  494. } else {
  495. SM_ENTER(EAP, METHOD_RESPONSE);
  496. }
  497. break;
  498. case EAP_DISABLED:
  499. if (sm->eap_if.portEnabled)
  500. SM_ENTER(EAP, INITIALIZE);
  501. break;
  502. case EAP_IDLE:
  503. if (sm->eap_if.retransWhile == 0)
  504. SM_ENTER(EAP, RETRANSMIT);
  505. else if (sm->eap_if.eapResp)
  506. SM_ENTER(EAP, RECEIVED);
  507. break;
  508. case EAP_RETRANSMIT:
  509. if (sm->retransCount > sm->MaxRetrans)
  510. SM_ENTER(EAP, TIMEOUT_FAILURE);
  511. else
  512. SM_ENTER(EAP, IDLE);
  513. break;
  514. case EAP_RECEIVED:
  515. if (sm->rxResp && (sm->respId == sm->currentId) &&
  516. (sm->respMethod == EAP_TYPE_NAK ||
  517. (sm->respMethod == EAP_TYPE_EXPANDED &&
  518. sm->respVendor == EAP_VENDOR_IETF &&
  519. sm->respVendorMethod == EAP_TYPE_NAK))
  520. && (sm->methodState == METHOD_PROPOSED))
  521. SM_ENTER(EAP, NAK);
  522. else if (sm->rxResp && (sm->respId == sm->currentId) &&
  523. ((sm->respMethod == sm->currentMethod) ||
  524. (sm->respMethod == EAP_TYPE_EXPANDED &&
  525. sm->respVendor == EAP_VENDOR_IETF &&
  526. sm->respVendorMethod == sm->currentMethod)))
  527. SM_ENTER(EAP, INTEGRITY_CHECK);
  528. else {
  529. wpa_printf(MSG_DEBUG, "EAP: RECEIVED->DISCARD: "
  530. "rxResp=%d respId=%d currentId=%d "
  531. "respMethod=%d currentMethod=%d",
  532. sm->rxResp, sm->respId, sm->currentId,
  533. sm->respMethod, sm->currentMethod);
  534. SM_ENTER(EAP, DISCARD);
  535. }
  536. break;
  537. case EAP_DISCARD:
  538. SM_ENTER(EAP, IDLE);
  539. break;
  540. case EAP_SEND_REQUEST:
  541. SM_ENTER(EAP, IDLE);
  542. break;
  543. case EAP_INTEGRITY_CHECK:
  544. if (sm->ignore)
  545. SM_ENTER(EAP, DISCARD);
  546. else
  547. SM_ENTER(EAP, METHOD_RESPONSE);
  548. break;
  549. case EAP_METHOD_REQUEST:
  550. SM_ENTER(EAP, SEND_REQUEST);
  551. break;
  552. case EAP_METHOD_RESPONSE:
  553. /*
  554. * Note: Mechanism to allow EAP methods to wait while going
  555. * through pending processing is an extension to RFC 4137
  556. * which only defines the transits to SELECT_ACTION and
  557. * METHOD_REQUEST from this METHOD_RESPONSE state.
  558. */
  559. if (sm->methodState == METHOD_END)
  560. SM_ENTER(EAP, SELECT_ACTION);
  561. else if (sm->method_pending == METHOD_PENDING_WAIT) {
  562. wpa_printf(MSG_DEBUG, "EAP: Method has pending "
  563. "processing - wait before proceeding to "
  564. "METHOD_REQUEST state");
  565. } else if (sm->method_pending == METHOD_PENDING_CONT) {
  566. wpa_printf(MSG_DEBUG, "EAP: Method has completed "
  567. "pending processing - reprocess pending "
  568. "EAP message");
  569. sm->method_pending = METHOD_PENDING_NONE;
  570. SM_ENTER(EAP, METHOD_RESPONSE);
  571. } else
  572. SM_ENTER(EAP, METHOD_REQUEST);
  573. break;
  574. case EAP_PROPOSE_METHOD:
  575. /*
  576. * Note: Mechanism to allow EAP methods to wait while going
  577. * through pending processing is an extension to RFC 4137
  578. * which only defines the transit to METHOD_REQUEST from this
  579. * PROPOSE_METHOD state.
  580. */
  581. if (sm->method_pending == METHOD_PENDING_WAIT) {
  582. wpa_printf(MSG_DEBUG, "EAP: Method has pending "
  583. "processing - wait before proceeding to "
  584. "METHOD_REQUEST state");
  585. if (sm->user_eap_method_index > 0)
  586. sm->user_eap_method_index--;
  587. } else if (sm->method_pending == METHOD_PENDING_CONT) {
  588. wpa_printf(MSG_DEBUG, "EAP: Method has completed "
  589. "pending processing - reprocess pending "
  590. "EAP message");
  591. sm->method_pending = METHOD_PENDING_NONE;
  592. SM_ENTER(EAP, PROPOSE_METHOD);
  593. } else
  594. SM_ENTER(EAP, METHOD_REQUEST);
  595. break;
  596. case EAP_NAK:
  597. SM_ENTER(EAP, SELECT_ACTION);
  598. break;
  599. case EAP_SELECT_ACTION:
  600. if (sm->decision == DECISION_FAILURE)
  601. SM_ENTER(EAP, FAILURE);
  602. else if (sm->decision == DECISION_SUCCESS)
  603. SM_ENTER(EAP, SUCCESS);
  604. else if (sm->decision == DECISION_PASSTHROUGH)
  605. SM_ENTER(EAP, INITIALIZE_PASSTHROUGH);
  606. else
  607. SM_ENTER(EAP, PROPOSE_METHOD);
  608. break;
  609. case EAP_TIMEOUT_FAILURE:
  610. break;
  611. case EAP_FAILURE:
  612. break;
  613. case EAP_SUCCESS:
  614. break;
  615. case EAP_INITIALIZE_PASSTHROUGH:
  616. if (sm->currentId == -1)
  617. SM_ENTER(EAP, AAA_IDLE);
  618. else
  619. SM_ENTER(EAP, AAA_REQUEST);
  620. break;
  621. case EAP_IDLE2:
  622. if (sm->eap_if.eapResp)
  623. SM_ENTER(EAP, RECEIVED2);
  624. else if (sm->eap_if.retransWhile == 0)
  625. SM_ENTER(EAP, RETRANSMIT2);
  626. break;
  627. case EAP_RETRANSMIT2:
  628. if (sm->retransCount > sm->MaxRetrans)
  629. SM_ENTER(EAP, TIMEOUT_FAILURE2);
  630. else
  631. SM_ENTER(EAP, IDLE2);
  632. break;
  633. case EAP_RECEIVED2:
  634. if (sm->rxResp && (sm->respId == sm->currentId))
  635. SM_ENTER(EAP, AAA_REQUEST);
  636. else
  637. SM_ENTER(EAP, DISCARD2);
  638. break;
  639. case EAP_DISCARD2:
  640. SM_ENTER(EAP, IDLE2);
  641. break;
  642. case EAP_SEND_REQUEST2:
  643. SM_ENTER(EAP, IDLE2);
  644. break;
  645. case EAP_AAA_REQUEST:
  646. SM_ENTER(EAP, AAA_IDLE);
  647. break;
  648. case EAP_AAA_RESPONSE:
  649. SM_ENTER(EAP, SEND_REQUEST2);
  650. break;
  651. case EAP_AAA_IDLE:
  652. if (sm->eap_if.aaaFail)
  653. SM_ENTER(EAP, FAILURE2);
  654. else if (sm->eap_if.aaaSuccess)
  655. SM_ENTER(EAP, SUCCESS2);
  656. else if (sm->eap_if.aaaEapReq)
  657. SM_ENTER(EAP, AAA_RESPONSE);
  658. else if (sm->eap_if.aaaTimeout)
  659. SM_ENTER(EAP, TIMEOUT_FAILURE2);
  660. break;
  661. case EAP_TIMEOUT_FAILURE2:
  662. break;
  663. case EAP_FAILURE2:
  664. break;
  665. case EAP_SUCCESS2:
  666. break;
  667. }
  668. }
  669. static int eap_sm_calculateTimeout(struct eap_sm *sm, int retransCount,
  670. int eapSRTT, int eapRTTVAR,
  671. int methodTimeout)
  672. {
  673. /* For now, retransmission is done in EAPOL state machines, so make
  674. * sure EAP state machine does not end up trying to retransmit packets.
  675. */
  676. return 1;
  677. }
  678. static void eap_sm_parseEapResp(struct eap_sm *sm, const struct wpabuf *resp)
  679. {
  680. const struct eap_hdr *hdr;
  681. size_t plen;
  682. /* parse rxResp, respId, respMethod */
  683. sm->rxResp = FALSE;
  684. sm->respId = -1;
  685. sm->respMethod = EAP_TYPE_NONE;
  686. sm->respVendor = EAP_VENDOR_IETF;
  687. sm->respVendorMethod = EAP_TYPE_NONE;
  688. if (resp == NULL || wpabuf_len(resp) < sizeof(*hdr)) {
  689. wpa_printf(MSG_DEBUG, "EAP: parseEapResp: invalid resp=%p "
  690. "len=%lu", resp,
  691. resp ? (unsigned long) wpabuf_len(resp) : 0);
  692. return;
  693. }
  694. hdr = wpabuf_head(resp);
  695. plen = be_to_host16(hdr->length);
  696. if (plen > wpabuf_len(resp)) {
  697. wpa_printf(MSG_DEBUG, "EAP: Ignored truncated EAP-Packet "
  698. "(len=%lu plen=%lu)",
  699. (unsigned long) wpabuf_len(resp),
  700. (unsigned long) plen);
  701. return;
  702. }
  703. sm->respId = hdr->identifier;
  704. if (hdr->code == EAP_CODE_RESPONSE)
  705. sm->rxResp = TRUE;
  706. if (plen > sizeof(*hdr)) {
  707. u8 *pos = (u8 *) (hdr + 1);
  708. sm->respMethod = *pos++;
  709. if (sm->respMethod == EAP_TYPE_EXPANDED) {
  710. if (plen < sizeof(*hdr) + 8) {
  711. wpa_printf(MSG_DEBUG, "EAP: Ignored truncated "
  712. "expanded EAP-Packet (plen=%lu)",
  713. (unsigned long) plen);
  714. return;
  715. }
  716. sm->respVendor = WPA_GET_BE24(pos);
  717. pos += 3;
  718. sm->respVendorMethod = WPA_GET_BE32(pos);
  719. }
  720. }
  721. wpa_printf(MSG_DEBUG, "EAP: parseEapResp: rxResp=%d respId=%d "
  722. "respMethod=%u respVendor=%u respVendorMethod=%u",
  723. sm->rxResp, sm->respId, sm->respMethod, sm->respVendor,
  724. sm->respVendorMethod);
  725. }
  726. static int eap_sm_getId(const struct wpabuf *data)
  727. {
  728. const struct eap_hdr *hdr;
  729. if (data == NULL || wpabuf_len(data) < sizeof(*hdr))
  730. return -1;
  731. hdr = wpabuf_head(data);
  732. wpa_printf(MSG_DEBUG, "EAP: getId: id=%d", hdr->identifier);
  733. return hdr->identifier;
  734. }
  735. static struct wpabuf * eap_sm_buildSuccess(struct eap_sm *sm, u8 id)
  736. {
  737. struct wpabuf *msg;
  738. struct eap_hdr *resp;
  739. wpa_printf(MSG_DEBUG, "EAP: Building EAP-Success (id=%d)", id);
  740. msg = wpabuf_alloc(sizeof(*resp));
  741. if (msg == NULL)
  742. return NULL;
  743. resp = wpabuf_put(msg, sizeof(*resp));
  744. resp->code = EAP_CODE_SUCCESS;
  745. resp->identifier = id;
  746. resp->length = host_to_be16(sizeof(*resp));
  747. return msg;
  748. }
  749. static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id)
  750. {
  751. struct wpabuf *msg;
  752. struct eap_hdr *resp;
  753. wpa_printf(MSG_DEBUG, "EAP: Building EAP-Failure (id=%d)", id);
  754. msg = wpabuf_alloc(sizeof(*resp));
  755. if (msg == NULL)
  756. return NULL;
  757. resp = wpabuf_put(msg, sizeof(*resp));
  758. resp->code = EAP_CODE_FAILURE;
  759. resp->identifier = id;
  760. resp->length = host_to_be16(sizeof(*resp));
  761. return msg;
  762. }
  763. static int eap_sm_nextId(struct eap_sm *sm, int id)
  764. {
  765. if (id < 0) {
  766. /* RFC 3748 Ch 4.1: recommended to initialize Identifier with a
  767. * random number */
  768. id = rand() & 0xff;
  769. if (id != sm->lastId)
  770. return id;
  771. }
  772. return (id + 1) & 0xff;
  773. }
  774. /**
  775. * eap_sm_process_nak - Process EAP-Response/Nak
  776. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  777. * @nak_list: Nak list (allowed methods) from the supplicant
  778. * @len: Length of nak_list in bytes
  779. *
  780. * This function is called when EAP-Response/Nak is received from the
  781. * supplicant. This can happen for both phase 1 and phase 2 authentications.
  782. */
  783. void eap_sm_process_nak(struct eap_sm *sm, const u8 *nak_list, size_t len)
  784. {
  785. int i;
  786. size_t j;
  787. if (sm->user == NULL)
  788. return;
  789. wpa_printf(MSG_MSGDUMP, "EAP: processing NAK (current EAP method "
  790. "index %d)", sm->user_eap_method_index);
  791. wpa_hexdump(MSG_MSGDUMP, "EAP: configured methods",
  792. (u8 *) sm->user->methods,
  793. EAP_MAX_METHODS * sizeof(sm->user->methods[0]));
  794. wpa_hexdump(MSG_MSGDUMP, "EAP: list of methods supported by the peer",
  795. nak_list, len);
  796. i = sm->user_eap_method_index;
  797. while (i < EAP_MAX_METHODS &&
  798. (sm->user->methods[i].vendor != EAP_VENDOR_IETF ||
  799. sm->user->methods[i].method != EAP_TYPE_NONE)) {
  800. if (sm->user->methods[i].vendor != EAP_VENDOR_IETF)
  801. goto not_found;
  802. for (j = 0; j < len; j++) {
  803. if (nak_list[j] == sm->user->methods[i].method) {
  804. break;
  805. }
  806. }
  807. if (j < len) {
  808. /* found */
  809. i++;
  810. continue;
  811. }
  812. not_found:
  813. /* not found - remove from the list */
  814. os_memmove(&sm->user->methods[i], &sm->user->methods[i + 1],
  815. (EAP_MAX_METHODS - i - 1) *
  816. sizeof(sm->user->methods[0]));
  817. sm->user->methods[EAP_MAX_METHODS - 1].vendor =
  818. EAP_VENDOR_IETF;
  819. sm->user->methods[EAP_MAX_METHODS - 1].method = EAP_TYPE_NONE;
  820. }
  821. wpa_hexdump(MSG_MSGDUMP, "EAP: new list of configured methods",
  822. (u8 *) sm->user->methods, EAP_MAX_METHODS *
  823. sizeof(sm->user->methods[0]));
  824. }
  825. static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
  826. size_t len)
  827. {
  828. if (nak_list == NULL || sm == NULL || sm->user == NULL)
  829. return;
  830. if (sm->user->phase2) {
  831. wpa_printf(MSG_DEBUG, "EAP: EAP-Nak received after Phase2 user"
  832. " info was selected - reject");
  833. sm->decision = DECISION_FAILURE;
  834. return;
  835. }
  836. eap_sm_process_nak(sm, nak_list, len);
  837. }
  838. static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
  839. {
  840. EapType next;
  841. int idx = sm->user_eap_method_index;
  842. /* In theory, there should be no problems with starting
  843. * re-authentication with something else than EAP-Request/Identity and
  844. * this does indeed work with wpa_supplicant. However, at least Funk
  845. * Supplicant seemed to ignore re-auth if it skipped
  846. * EAP-Request/Identity.
  847. * Re-auth sets currentId == -1, so that can be used here to select
  848. * whether Identity needs to be requested again. */
  849. if (sm->identity == NULL || sm->currentId == -1) {
  850. *vendor = EAP_VENDOR_IETF;
  851. next = EAP_TYPE_IDENTITY;
  852. sm->update_user = TRUE;
  853. } else if (sm->user && idx < EAP_MAX_METHODS &&
  854. (sm->user->methods[idx].vendor != EAP_VENDOR_IETF ||
  855. sm->user->methods[idx].method != EAP_TYPE_NONE)) {
  856. *vendor = sm->user->methods[idx].vendor;
  857. next = sm->user->methods[idx].method;
  858. sm->user_eap_method_index++;
  859. } else {
  860. *vendor = EAP_VENDOR_IETF;
  861. next = EAP_TYPE_NONE;
  862. }
  863. wpa_printf(MSG_DEBUG, "EAP: getNextMethod: vendor %d type %d",
  864. *vendor, next);
  865. return next;
  866. }
  867. static int eap_sm_Policy_getDecision(struct eap_sm *sm)
  868. {
  869. if (!sm->eap_server && sm->identity) {
  870. wpa_printf(MSG_DEBUG, "EAP: getDecision: -> PASSTHROUGH");
  871. return DECISION_PASSTHROUGH;
  872. }
  873. if (sm->m && sm->currentMethod != EAP_TYPE_IDENTITY &&
  874. sm->m->isSuccess(sm, sm->eap_method_priv)) {
  875. wpa_printf(MSG_DEBUG, "EAP: getDecision: method succeeded -> "
  876. "SUCCESS");
  877. sm->update_user = TRUE;
  878. return DECISION_SUCCESS;
  879. }
  880. if (sm->m && sm->m->isDone(sm, sm->eap_method_priv) &&
  881. !sm->m->isSuccess(sm, sm->eap_method_priv)) {
  882. wpa_printf(MSG_DEBUG, "EAP: getDecision: method failed -> "
  883. "FAILURE");
  884. sm->update_user = TRUE;
  885. return DECISION_FAILURE;
  886. }
  887. if ((sm->user == NULL || sm->update_user) && sm->identity) {
  888. if (eap_user_get(sm, sm->identity, sm->identity_len, 0) != 0) {
  889. wpa_printf(MSG_DEBUG, "EAP: getDecision: user not "
  890. "found from database -> FAILURE");
  891. return DECISION_FAILURE;
  892. }
  893. sm->update_user = FALSE;
  894. }
  895. if (sm->user && sm->user_eap_method_index < EAP_MAX_METHODS &&
  896. (sm->user->methods[sm->user_eap_method_index].vendor !=
  897. EAP_VENDOR_IETF ||
  898. sm->user->methods[sm->user_eap_method_index].method !=
  899. EAP_TYPE_NONE)) {
  900. wpa_printf(MSG_DEBUG, "EAP: getDecision: another method "
  901. "available -> CONTINUE");
  902. return DECISION_CONTINUE;
  903. }
  904. if (sm->identity == NULL || sm->currentId == -1) {
  905. wpa_printf(MSG_DEBUG, "EAP: getDecision: no identity known "
  906. "yet -> CONTINUE");
  907. return DECISION_CONTINUE;
  908. }
  909. wpa_printf(MSG_DEBUG, "EAP: getDecision: no more methods available -> "
  910. "FAILURE");
  911. return DECISION_FAILURE;
  912. }
  913. static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
  914. {
  915. return method == EAP_TYPE_IDENTITY ? TRUE : FALSE;
  916. }
  917. /**
  918. * eap_server_sm_step - Step EAP server state machine
  919. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  920. * Returns: 1 if EAP state was changed or 0 if not
  921. *
  922. * This function advances EAP state machine to a new state to match with the
  923. * current variables. This should be called whenever variables used by the EAP
  924. * state machine have changed.
  925. */
  926. int eap_server_sm_step(struct eap_sm *sm)
  927. {
  928. int res = 0;
  929. do {
  930. sm->changed = FALSE;
  931. SM_STEP_RUN(EAP);
  932. if (sm->changed)
  933. res = 1;
  934. } while (sm->changed);
  935. return res;
  936. }
  937. static void eap_user_free(struct eap_user *user)
  938. {
  939. if (user == NULL)
  940. return;
  941. os_free(user->password);
  942. user->password = NULL;
  943. os_free(user);
  944. }
  945. /**
  946. * eap_server_sm_init - Allocate and initialize EAP server state machine
  947. * @eapol_ctx: Context data to be used with eapol_cb calls
  948. * @eapol_cb: Pointer to EAPOL callback functions
  949. * @conf: EAP configuration
  950. * Returns: Pointer to the allocated EAP state machine or %NULL on failure
  951. *
  952. * This function allocates and initializes an EAP state machine.
  953. */
  954. struct eap_sm * eap_server_sm_init(void *eapol_ctx,
  955. struct eapol_callbacks *eapol_cb,
  956. struct eap_config *conf)
  957. {
  958. struct eap_sm *sm;
  959. sm = os_zalloc(sizeof(*sm));
  960. if (sm == NULL)
  961. return NULL;
  962. sm->eapol_ctx = eapol_ctx;
  963. sm->eapol_cb = eapol_cb;
  964. sm->MaxRetrans = 10;
  965. sm->ssl_ctx = conf->ssl_ctx;
  966. sm->eap_sim_db_priv = conf->eap_sim_db_priv;
  967. sm->backend_auth = conf->backend_auth;
  968. sm->eap_server = conf->eap_server;
  969. if (conf->pac_opaque_encr_key) {
  970. sm->pac_opaque_encr_key = os_malloc(16);
  971. if (sm->pac_opaque_encr_key) {
  972. os_memcpy(sm->pac_opaque_encr_key,
  973. conf->pac_opaque_encr_key, 16);
  974. }
  975. }
  976. if (conf->eap_fast_a_id) {
  977. sm->eap_fast_a_id = os_malloc(conf->eap_fast_a_id_len);
  978. if (sm->eap_fast_a_id) {
  979. os_memcpy(sm->eap_fast_a_id, conf->eap_fast_a_id,
  980. conf->eap_fast_a_id_len);
  981. sm->eap_fast_a_id_len = conf->eap_fast_a_id_len;
  982. }
  983. }
  984. if (conf->eap_fast_a_id_info)
  985. sm->eap_fast_a_id_info = os_strdup(conf->eap_fast_a_id_info);
  986. sm->eap_fast_prov = conf->eap_fast_prov;
  987. sm->pac_key_lifetime = conf->pac_key_lifetime;
  988. sm->pac_key_refresh_time = conf->pac_key_refresh_time;
  989. sm->eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
  990. sm->tnc = conf->tnc;
  991. sm->wps = conf->wps;
  992. wpa_printf(MSG_DEBUG, "EAP: Server state machine created");
  993. return sm;
  994. }
  995. /**
  996. * eap_server_sm_deinit - Deinitialize and free an EAP server state machine
  997. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  998. *
  999. * This function deinitializes EAP state machine and frees all allocated
  1000. * resources.
  1001. */
  1002. void eap_server_sm_deinit(struct eap_sm *sm)
  1003. {
  1004. if (sm == NULL)
  1005. return;
  1006. wpa_printf(MSG_DEBUG, "EAP: Server state machine removed");
  1007. if (sm->m && sm->eap_method_priv)
  1008. sm->m->reset(sm, sm->eap_method_priv);
  1009. wpabuf_free(sm->eap_if.eapReqData);
  1010. os_free(sm->eap_if.eapKeyData);
  1011. os_free(sm->lastReqData);
  1012. wpabuf_free(sm->eap_if.eapRespData);
  1013. os_free(sm->identity);
  1014. os_free(sm->pac_opaque_encr_key);
  1015. os_free(sm->eap_fast_a_id);
  1016. os_free(sm->eap_fast_a_id_info);
  1017. wpabuf_free(sm->eap_if.aaaEapReqData);
  1018. wpabuf_free(sm->eap_if.aaaEapRespData);
  1019. os_free(sm->eap_if.aaaEapKeyData);
  1020. eap_user_free(sm->user);
  1021. os_free(sm);
  1022. }
  1023. /**
  1024. * eap_sm_notify_cached - Notify EAP state machine of cached PMK
  1025. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  1026. *
  1027. * This function is called when PMKSA caching is used to skip EAP
  1028. * authentication.
  1029. */
  1030. void eap_sm_notify_cached(struct eap_sm *sm)
  1031. {
  1032. if (sm == NULL)
  1033. return;
  1034. sm->EAP_state = EAP_SUCCESS;
  1035. }
  1036. /**
  1037. * eap_sm_pending_cb - EAP state machine callback for a pending EAP request
  1038. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  1039. *
  1040. * This function is called when data for a pending EAP-Request is received.
  1041. */
  1042. void eap_sm_pending_cb(struct eap_sm *sm)
  1043. {
  1044. if (sm == NULL)
  1045. return;
  1046. wpa_printf(MSG_DEBUG, "EAP: Callback for pending request received");
  1047. if (sm->method_pending == METHOD_PENDING_WAIT)
  1048. sm->method_pending = METHOD_PENDING_CONT;
  1049. }
  1050. /**
  1051. * eap_sm_method_pending - Query whether EAP method is waiting for pending data
  1052. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  1053. * Returns: 1 if method is waiting for pending data or 0 if not
  1054. */
  1055. int eap_sm_method_pending(struct eap_sm *sm)
  1056. {
  1057. if (sm == NULL)
  1058. return 0;
  1059. return sm->method_pending == METHOD_PENDING_WAIT;
  1060. }
  1061. /**
  1062. * eap_get_identity - Get the user identity (from EAP-Response/Identity)
  1063. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  1064. * @len: Buffer for returning identity length
  1065. * Returns: Pointer to the user identity or %NULL if not available
  1066. */
  1067. const u8 * eap_get_identity(struct eap_sm *sm, size_t *len)
  1068. {
  1069. *len = sm->identity_len;
  1070. return sm->identity;
  1071. }
  1072. /**
  1073. * eap_get_interface - Get pointer to EAP-EAPOL interface data
  1074. * @sm: Pointer to EAP state machine allocated with eap_server_sm_init()
  1075. * Returns: Pointer to the EAP-EAPOL interface data
  1076. */
  1077. struct eap_eapol_interface * eap_get_interface(struct eap_sm *sm)
  1078. {
  1079. return &sm->eap_if;
  1080. }