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, int 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 *pos++ = nak_type >> 8;
52 *pos++ = nak_type & 0xff;
58 u8 * eap_tlv_build_result(int id, int status, size_t *resp_len)
63 *resp_len = sizeof(struct eap_hdr) + 1 + 6;
64 hdr = malloc(*resp_len);
68 hdr->code = EAP_CODE_RESPONSE;
70 hdr->length = host_to_be16(*resp_len);
71 pos = (u8 *) (hdr + 1);
72 *pos++ = EAP_TYPE_TLV;
73 *pos++ = 0x80; /* Mandatory */
74 *pos++ = EAP_TLV_RESULT_TLV;
80 *pos++ = status & 0xff;
86 int eap_tlv_process(struct eap_sm *sm, struct eap_method_ret *ret,
87 struct eap_hdr *hdr, u8 **resp, size_t *resp_len)
91 u8 *result_tlv = NULL;
92 size_t result_tlv_len = 0;
93 int tlv_type, mandatory, tlv_len;
96 left = be_to_host16(hdr->length) - sizeof(struct eap_hdr) - 1;
97 pos = (u8 *) (hdr + 1);
99 wpa_hexdump(MSG_DEBUG, "EAP-TLV: Received TLVs", pos, left);
101 mandatory = !!(pos[0] & 0x80);
102 tlv_type = pos[0] & 0x3f;
103 tlv_type = (tlv_type << 8) | pos[1];
104 tlv_len = ((int) pos[2] << 8) | pos[3];
107 if (tlv_len > left) {
108 wpa_printf(MSG_DEBUG, "EAP-TLV: TLV underrun "
109 "(tlv_len=%d left=%lu)", tlv_len,
110 (unsigned long) left);
114 case EAP_TLV_RESULT_TLV:
116 result_tlv_len = tlv_len;
119 wpa_printf(MSG_DEBUG, "EAP-TLV: Unsupported TLV Type "
121 mandatory ? " (mandatory)" : "");
123 /* NAK TLV and ignore all TLVs in this packet.
125 *resp = eap_tlv_build_nak(hdr->identifier,
127 return *resp == NULL ? -1 : 0;
129 /* Ignore this TLV, but process other TLVs */
137 wpa_printf(MSG_DEBUG, "EAP-TLV: Last TLV too short in "
138 "Request (left=%lu)", (unsigned long) left);
142 /* Process supported TLVs */
144 int status, resp_status;
145 wpa_hexdump(MSG_DEBUG, "EAP-TLV: Result TLV",
146 result_tlv, result_tlv_len);
147 if (result_tlv_len < 2) {
148 wpa_printf(MSG_INFO, "EAP-TLV: Too short Result TLV "
150 (unsigned long) result_tlv_len);
153 status = ((int) result_tlv[0] << 8) | result_tlv[1];
154 if (status == EAP_TLV_RESULT_SUCCESS) {
155 wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Success "
156 "- EAP-TLV/Phase2 Completed");
157 resp_status = EAP_TLV_RESULT_SUCCESS;
158 ret->decision = DECISION_UNCOND_SUCC;
159 } else if (status == EAP_TLV_RESULT_FAILURE) {
160 wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Failure");
161 resp_status = EAP_TLV_RESULT_FAILURE;
162 ret->decision = DECISION_FAIL;
164 wpa_printf(MSG_INFO, "EAP-TLV: Unknown TLV Result "
165 "Status %d", status);
166 resp_status = EAP_TLV_RESULT_FAILURE;
167 ret->decision = DECISION_FAIL;
169 ret->methodState = METHOD_DONE;
171 *resp = eap_tlv_build_result(hdr->identifier, resp_status,