static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e) { u8 *eap; size_t len; struct eap_hdr *hdr; int eap_type = -1; char buf[64]; struct radius_msg *msg; if (e->last_recv_radius == NULL) return; msg = e->last_recv_radius; eap = radius_msg_get_eap(msg, &len); if (eap == NULL) { /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3: * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message * attribute */ wpa_printf(MSG_DEBUG, "could not extract " "EAP-Message from RADIUS message"); os_free(e->last_eap_radius); e->last_eap_radius = NULL; e->last_eap_radius_len = 0; return; } if (len < sizeof(*hdr)) { wpa_printf(MSG_DEBUG, "too short EAP packet " "received from authentication server"); os_free(eap); return; } if (len > sizeof(*hdr)) eap_type = eap[sizeof(*hdr)]; hdr = (struct eap_hdr *) eap; switch (hdr->code) { case EAP_CODE_REQUEST: os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)", eap_type >= 0 ? eap_type_text(eap_type) : "??", eap_type); break; case EAP_CODE_RESPONSE: os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)", eap_type >= 0 ? eap_type_text(eap_type) : "??", eap_type); break; case EAP_CODE_SUCCESS: os_strlcpy(buf, "EAP Success", sizeof(buf)); /* LEAP uses EAP Success within an authentication, so must not * stop here with eloop_terminate(); */ break; case EAP_CODE_FAILURE: os_strlcpy(buf, "EAP Failure", sizeof(buf)); eloop_terminate(); break; default: os_strlcpy(buf, "unknown EAP code", sizeof(buf)); wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len); break; } wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d " "id=%d len=%d) from RADIUS server: %s", hdr->code, hdr->identifier, ntohs(hdr->length), buf); /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */ os_free(e->last_eap_radius); e->last_eap_radius = eap; e->last_eap_radius_len = len; { struct ieee802_1x_hdr *dot1x; dot1x = os_malloc(sizeof(*dot1x) + len); assert(dot1x != NULL); dot1x->version = EAPOL_VERSION; dot1x->type = IEEE802_1X_TYPE_EAP_PACKET; dot1x->length = htons(len); os_memcpy((u8 *) (dot1x + 1), eap, len); eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid, (u8 *) dot1x, sizeof(*dot1x) + len); os_free(dot1x); } }
CSCM_EXPORT void ieee802_1x_EAP_packet_received (int bFromRADIUS, u8 *eap, size_t len) { struct eapol_test_data *e = p_eapol_test; struct eap_hdr *hdr; int eap_type = -1; char buf[64]; if (len < sizeof(*hdr)) { wpa_printf(MSG_DEBUG, "too short EAP packet " "received from authentication server"); free(eap); return; } if (len > sizeof(*hdr)) eap_type = eap[sizeof(*hdr)]; hdr = (struct eap_hdr *) eap; switch (hdr->code) { case EAP_CODE_REQUEST: snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)", eap_type >= 0 ? eap_type_text(eap_type) : "??", eap_type); break; case EAP_CODE_RESPONSE: snprintf(buf, sizeof(buf), "EAP Response-%s (%d)", eap_type >= 0 ? eap_type_text(eap_type) : "??", eap_type); break; case EAP_CODE_SUCCESS: snprintf(buf, sizeof(buf), "EAP Success"); /* LEAP uses EAP Success within an authentication, so must not * stop here with eloop_terminate(); */ break; case EAP_CODE_FAILURE: snprintf(buf, sizeof(buf), "EAP Failure"); eloop_terminate(); break; default: snprintf(buf, sizeof(buf), "unknown EAP code"); wpa_hexdump(MSG_DEBUG, "EAP packet", eap, len); break; } wpa_printf(MSG_DEBUG, "EAP packet (code=%d " "id=%d len=%d) from %s server: %s", hdr->code, hdr->identifier, ntohs(hdr->length), bFromRADIUS ? "RADIUS" : "non-RADIUS", buf); if (bFromRADIUS) { /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */ free(e->last_eap_radius); e->last_eap_radius = eap; e->last_eap_radius_len = len; } { struct ieee802_1x_hdr *hdr; hdr = malloc(sizeof(*hdr) + len); assert(hdr != NULL); hdr->version = EAPOL_VERSION; hdr->type = IEEE802_1X_TYPE_EAP_PACKET; hdr->length = htons(len); memcpy((u8 *) (hdr + 1), eap, len); eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid, (u8 *) hdr, sizeof(*hdr) + len); free(hdr); } }