blob: 39c94218b87b259940df913ef44b989a7c8e238c [file] [log] [blame]
Paul Stewart735eab52013-03-29 09:19:23 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/supplicant_eap_state_handler.h"
6
7#include "shill/logging.h"
8#include "shill/wpa_supplicant.h"
9
10namespace shill {
11
12using std::string;
13
14SupplicantEAPStateHandler::SupplicantEAPStateHandler()
15 : is_eap_in_progress_(false) {}
16
17SupplicantEAPStateHandler::~SupplicantEAPStateHandler() {}
18
19bool SupplicantEAPStateHandler::ParseStatus(const string &status,
20 const string &parameter,
21 Service::ConnectFailure *failure) {
22 if (status == WPASupplicant::kEAPStatusAcceptProposedMethod) {
23 LOG(INFO) << "EAP: accepted method " << parameter;
24 } else if (status == WPASupplicant::kEAPStatusCompletion) {
25 if (parameter == WPASupplicant::kEAPParameterSuccess) {
26 LOG(INFO) << "EAP: Completed authentication successfully.";
27 is_eap_in_progress_ = false;
28 return true;
29 } else if (parameter == WPASupplicant::kEAPParameterFailure) {
30 // If there was a TLS error, use this instead of the generic failure.
31 if (tls_error_ == WPASupplicant::kEAPStatusLocalTLSAlert) {
32 *failure = Service::kFailureEAPLocalTLS;
33 } else if (tls_error_ ==
34 WPASupplicant::kEAPStatusRemoteTLSAlert) {
35 *failure = Service::kFailureEAPRemoteTLS;
36 } else {
37 *failure = Service::kFailureEAPAuthentication;
38 }
39 } else {
40 LOG(ERROR) << "EAP: Unexpected " << status << " parameter: " << parameter;
41 }
42 } else if (status == WPASupplicant::kEAPStatusLocalTLSAlert ||
43 status == WPASupplicant::kEAPStatusRemoteTLSAlert) {
44 tls_error_ = status;
45 } else if (status ==
46 WPASupplicant::kEAPStatusRemoteCertificateVerification) {
47 if (parameter == WPASupplicant::kEAPParameterSuccess) {
48 LOG(INFO) << "EAP: Completed remote certificate verification.";
49 } else {
50 // wpa_supplicant doesn't currently have a verification failure
51 // message. We will instead get a RemoteTLSAlert above.
52 LOG(ERROR) << "EAP: Unexpected " << status << " parameter: " << parameter;
53 }
54 } else if (status == WPASupplicant::kEAPStatusParameterNeeded) {
55 LOG(ERROR) << "EAP: Authentication aborted due to missing authentication "
56 << "parameter: " << parameter;
57 *failure = Service::kFailureEAPAuthentication;
58 } else if (status == WPASupplicant::kEAPStatusStarted) {
59 LOG(INFO) << "EAP: Authentication starting.";
60 is_eap_in_progress_ = true;
61 }
62
63 return false;
64}
65
66void SupplicantEAPStateHandler::Reset() {
67 is_eap_in_progress_ = false;
68 tls_error_ = "";
69}
70
71} // namespace shill