2 * WPA Supplicant / EAP-TLV (draft-josefsson-pppext-eap-tls-eap-07.txt)
3 * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
20 #include "wpa_supplicant.h"
25 u8 * eap_tlv_build_nak(int id, u16 nak_type, size_t *resp_len)
30 *resp_len = sizeof(struct eap_hdr) + 1 + 10;
31 hdr = malloc(*resp_len);
35 hdr->code = EAP_CODE_RESPONSE;
37 hdr->length = host_to_be16(*resp_len);
38 pos = (u8 *) (hdr + 1);
39 *pos++ = EAP_TYPE_TLV;
40 *pos++ = 0x80; /* Mandatory */
41 *pos++ = EAP_TLV_NAK_TLV;
51 WPA_PUT_BE16(pos, nak_type);
57 u8 * eap_tlv_build_result(int id, u16 status, size_t *resp_len)
62 *resp_len = sizeof(struct eap_hdr) + 1 + 6;
63 hdr = malloc(*resp_len);
67 hdr->code = EAP_CODE_RESPONSE;
69 hdr->length = host_to_be16(*resp_len);
70 pos = (u8 *) (hdr + 1);
71 *pos++ = EAP_TYPE_TLV;
72 *pos++ = 0x80; /* Mandatory */
73 *pos++ = EAP_TLV_RESULT_TLV;
78 WPA_PUT_BE16(pos, status);
84 int eap_tlv_process(struct eap_sm *sm, struct eap_method_ret *ret,
85 const struct eap_hdr *hdr, u8 **resp, size_t *resp_len)
89 const u8 *result_tlv = NULL;
90 size_t result_tlv_len = 0;
91 int tlv_type, mandatory, tlv_len;
94 left = be_to_host16(hdr->length) - sizeof(struct eap_hdr) - 1;
95 pos = (const u8 *) (hdr + 1);
97 wpa_hexdump(MSG_DEBUG, "EAP-TLV: Received TLVs", pos, left);
99 mandatory = !!(pos[0] & 0x80);
100 tlv_type = WPA_GET_BE16(pos) & 0x3fff;
102 tlv_len = WPA_GET_BE16(pos);
105 if (tlv_len > left) {
106 wpa_printf(MSG_DEBUG, "EAP-TLV: TLV underrun "
107 "(tlv_len=%d left=%lu)", tlv_len,
108 (unsigned long) left);
112 case EAP_TLV_RESULT_TLV:
114 result_tlv_len = tlv_len;
117 wpa_printf(MSG_DEBUG, "EAP-TLV: Unsupported TLV Type "
119 mandatory ? " (mandatory)" : "");
121 /* NAK TLV and ignore all TLVs in this packet.
123 *resp = eap_tlv_build_nak(hdr->identifier,
125 return *resp == NULL ? -1 : 0;
127 /* Ignore this TLV, but process other TLVs */
135 wpa_printf(MSG_DEBUG, "EAP-TLV: Last TLV too short in "
136 "Request (left=%lu)", (unsigned long) left);
140 /* Process supported TLVs */
142 int status, resp_status;
143 wpa_hexdump(MSG_DEBUG, "EAP-TLV: Result TLV",
144 result_tlv, result_tlv_len);
145 if (result_tlv_len < 2) {
146 wpa_printf(MSG_INFO, "EAP-TLV: Too short Result TLV "
148 (unsigned long) result_tlv_len);
151 status = WPA_GET_BE16(result_tlv);
152 if (status == EAP_TLV_RESULT_SUCCESS) {
153 wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Success "
154 "- EAP-TLV/Phase2 Completed");
155 resp_status = EAP_TLV_RESULT_SUCCESS;
156 ret->decision = DECISION_UNCOND_SUCC;
157 } else if (status == EAP_TLV_RESULT_FAILURE) {
158 wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Failure");
159 resp_status = EAP_TLV_RESULT_FAILURE;
160 ret->decision = DECISION_FAIL;
162 wpa_printf(MSG_INFO, "EAP-TLV: Unknown TLV Result "
163 "Status %d", status);
164 resp_status = EAP_TLV_RESULT_FAILURE;
165 ret->decision = DECISION_FAIL;
167 ret->methodState = METHOD_DONE;
169 *resp = eap_tlv_build_result(hdr->identifier, resp_status,