~ubuntu-branches/ubuntu/vivid/wpasupplicant/vivid

« back to all changes in this revision

Viewing changes to src/eap_peer/eap_tlv.c

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2008-03-12 20:03:04 UTC
  • mfrom: (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080312200304-4331y9wj46pdd34z
Tags: 0.6.3-1
* New upstream release.
* Drop patches applied upstream:
  - debian/patches/30_wpa_gui_qt4_eventhistoryui_rework.patch
  - debian/patches/31_wpa_gui_qt4_eventhistory_always_scrollbar.patch
  - debian/patches/32_wpa_gui_qt4_eventhistory_scroll_with_events.patch
  - debian/patches/40_dbus_ssid_data.patch
* Tidy up the clean target of debian/rules. Now that the madwifi headers are
  handled differently we no longer need to do any cleanup.
* Fix formatting error in debian/ifupdown/wpa_action.8 to make lintian
  quieter.
* Add patch to fix formatting errors in manpages build from sgml source. Use
  <emphasis> tags to hightlight keywords instead of surrounding them in
  strong quotes.
  - debian/patches/41_manpage_format_fixes.patch
* wpasupplicant binary package no longer suggests pcscd, guessnet, iproute
  or wireless-tools, nor does it recommend dhcp3-client. These are not
  needed.
* Add debian/patches/10_silence_siocsiwauth_icotl_failure.patch to disable
  ioctl failure messages that occur under normal conditions.
* Cherry pick two upstream git commits concerning the dbus interface:
  - debian/patches/11_avoid_dbus_version_namespace.patch
  - debian/patches/12_fix_potential_use_after_free.patch
* Add debian/patches/42_manpage_explain_available_drivers.patch to explain
  that not all of the driver backends are available in the provided
  wpa_supplicant binary, and that the canonical list of supported driver
  backends can be retrieved from the wpa_supplicant -h (help) output.
  (Closes: #466910)
* Add debian/patches/20_wpa_gui_qt4_disable_link_prl.patch to remove
  link_prl CONFIG compile flag added by qmake-qt4 >= 4.3.4-2 to avoid excess
  linking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * EAP peer method: EAP-TLV (draft-josefsson-pppext-eap-tls-eap-07.txt)
 
3
 * Copyright (c) 2004-2008, 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
 
 
15
#include "includes.h"
 
16
 
 
17
#include "common.h"
 
18
#include "eap_i.h"
 
19
#include "eap_tlv.h"
 
20
 
 
21
 
 
22
/**
 
23
 * eap_tlv_build_nak - Build EAP-TLV NAK message
 
24
 * @id: EAP identifier for the header
 
25
 * @nak_type: TLV type (EAP_TLV_*)
 
26
 * Returns: Buffer to the allocated EAP-TLV NAK message or %NULL on failure
 
27
 *
 
28
 * This funtion builds an EAP-TLV NAK message. The caller is responsible for
 
29
 * freeing the returned buffer.
 
30
 */
 
31
struct wpabuf * eap_tlv_build_nak(int id, u16 nak_type)
 
32
{
 
33
        struct wpabuf *msg;
 
34
 
 
35
        msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TLV, 10,
 
36
                            EAP_CODE_RESPONSE, id);
 
37
        if (msg == NULL)
 
38
                return NULL;
 
39
 
 
40
        wpabuf_put_u8(msg, 0x80); /* Mandatory */
 
41
        wpabuf_put_u8(msg, EAP_TLV_NAK_TLV);
 
42
        wpabuf_put_be16(msg, 6); /* Length */
 
43
        wpabuf_put_be32(msg, 0); /* Vendor-Id */
 
44
        wpabuf_put_be16(msg, nak_type); /* NAK-Type */
 
45
 
 
46
        return msg;
 
47
}
 
48
 
 
49
 
 
50
/**
 
51
 * eap_tlv_build_result - Build EAP-TLV Result message
 
52
 * @id: EAP identifier for the header
 
53
 * @status: Status (EAP_TLV_RESULT_SUCCESS or EAP_TLV_RESULT_FAILURE)
 
54
 * Returns: Buffer to the allocated EAP-TLV Result message or %NULL on failure
 
55
 *
 
56
 * This funtion builds an EAP-TLV Result message. The caller is responsible for
 
57
 * freeing the returned buffer.
 
58
 */
 
59
struct wpabuf * eap_tlv_build_result(int id, u16 status)
 
60
{
 
61
        struct wpabuf *msg;
 
62
 
 
63
        msg = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TLV, 6,
 
64
                            EAP_CODE_RESPONSE, id);
 
65
        if (msg == NULL)
 
66
                return NULL;
 
67
 
 
68
        wpabuf_put_u8(msg, 0x80); /* Mandatory */
 
69
        wpabuf_put_u8(msg, EAP_TLV_RESULT_TLV);
 
70
        wpabuf_put_be16(msg, 2); /* Length */
 
71
        wpabuf_put_be16(msg, status); /* Status */
 
72
 
 
73
        return msg;
 
74
}
 
75
 
 
76
 
 
77
/**
 
78
 * eap_tlv_process - Process a received EAP-TLV message and generate a response
 
79
 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
 
80
 * @ret: Return values from EAP request validation and processing
 
81
 * @req: EAP-TLV request to be processed. The caller must have validated that
 
82
 * the buffer is large enough to contain full request (hdr->length bytes) and
 
83
 * that the EAP type is EAP_TYPE_TLV.
 
84
 * @resp: Buffer to return a pointer to the allocated response message. This
 
85
 * field should be initialized to %NULL before the call. The value will be
 
86
 * updated if a response message is generated. The caller is responsible for
 
87
 * freeing the allocated message.
 
88
 * @force_failure: Force negotiation to fail
 
89
 * Returns: 0 on success, -1 on failure
 
90
 */
 
91
int eap_tlv_process(struct eap_sm *sm, struct eap_method_ret *ret,
 
92
                    const struct wpabuf *req, struct wpabuf **resp,
 
93
                    int force_failure)
 
94
{
 
95
        size_t left, tlv_len;
 
96
        const u8 *pos;
 
97
        const u8 *result_tlv = NULL;
 
98
        size_t result_tlv_len = 0;
 
99
        int tlv_type, mandatory;
 
100
 
 
101
        /* Parse TLVs */
 
102
        pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_TLV, req, &left);
 
103
        if (pos == NULL)
 
104
                return -1;
 
105
        wpa_hexdump(MSG_DEBUG, "EAP-TLV: Received TLVs", pos, left);
 
106
        while (left >= 4) {
 
107
                mandatory = !!(pos[0] & 0x80);
 
108
                tlv_type = WPA_GET_BE16(pos) & 0x3fff;
 
109
                pos += 2;
 
110
                tlv_len = WPA_GET_BE16(pos);
 
111
                pos += 2;
 
112
                left -= 4;
 
113
                if (tlv_len > left) {
 
114
                        wpa_printf(MSG_DEBUG, "EAP-TLV: TLV underrun "
 
115
                                   "(tlv_len=%lu left=%lu)",
 
116
                                   (unsigned long) tlv_len,
 
117
                                   (unsigned long) left);
 
118
                        return -1;
 
119
                }
 
120
                switch (tlv_type) {
 
121
                case EAP_TLV_RESULT_TLV:
 
122
                        result_tlv = pos;
 
123
                        result_tlv_len = tlv_len;
 
124
                        break;
 
125
                default:
 
126
                        wpa_printf(MSG_DEBUG, "EAP-TLV: Unsupported TLV Type "
 
127
                                   "%d%s", tlv_type,
 
128
                                   mandatory ? " (mandatory)" : "");
 
129
                        if (mandatory) {
 
130
                                /* NAK TLV and ignore all TLVs in this packet.
 
131
                                 */
 
132
                                *resp = eap_tlv_build_nak(eap_get_id(req),
 
133
                                                          tlv_type);
 
134
                                return *resp == NULL ? -1 : 0;
 
135
                        }
 
136
                        /* Ignore this TLV, but process other TLVs */
 
137
                        break;
 
138
                }
 
139
 
 
140
                pos += tlv_len;
 
141
                left -= tlv_len;
 
142
        }
 
143
        if (left) {
 
144
                wpa_printf(MSG_DEBUG, "EAP-TLV: Last TLV too short in "
 
145
                           "Request (left=%lu)", (unsigned long) left);
 
146
                return -1;
 
147
        }
 
148
 
 
149
        /* Process supported TLVs */
 
150
        if (result_tlv) {
 
151
                int status, resp_status;
 
152
                wpa_hexdump(MSG_DEBUG, "EAP-TLV: Result TLV",
 
153
                            result_tlv, result_tlv_len);
 
154
                if (result_tlv_len < 2) {
 
155
                        wpa_printf(MSG_INFO, "EAP-TLV: Too short Result TLV "
 
156
                                   "(len=%lu)",
 
157
                                   (unsigned long) result_tlv_len);
 
158
                        return -1;
 
159
                }
 
160
                status = WPA_GET_BE16(result_tlv);
 
161
                if (status == EAP_TLV_RESULT_SUCCESS) {
 
162
                        wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Success "
 
163
                                   "- EAP-TLV/Phase2 Completed");
 
164
                        if (force_failure) {
 
165
                                wpa_printf(MSG_INFO, "EAP-TLV: Earlier failure"
 
166
                                           " - force failed Phase 2");
 
167
                                resp_status = EAP_TLV_RESULT_FAILURE;
 
168
                                ret->decision = DECISION_FAIL;
 
169
                        } else {
 
170
                                resp_status = EAP_TLV_RESULT_SUCCESS;
 
171
                                ret->decision = DECISION_UNCOND_SUCC;
 
172
                        }
 
173
                } else if (status == EAP_TLV_RESULT_FAILURE) {
 
174
                        wpa_printf(MSG_INFO, "EAP-TLV: TLV Result - Failure");
 
175
                        resp_status = EAP_TLV_RESULT_FAILURE;
 
176
                        ret->decision = DECISION_FAIL;
 
177
                } else {
 
178
                        wpa_printf(MSG_INFO, "EAP-TLV: Unknown TLV Result "
 
179
                                   "Status %d", status);
 
180
                        resp_status = EAP_TLV_RESULT_FAILURE;
 
181
                        ret->decision = DECISION_FAIL;
 
182
                }
 
183
                ret->methodState = METHOD_DONE;
 
184
 
 
185
                *resp = eap_tlv_build_result(eap_get_id(req), resp_status);
 
186
        }
 
187
 
 
188
        return 0;
 
189
}