• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hidl interface for wpa_supplicant daemon
3  * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #include "hidl_manager.h"
11 #include "hidl_return_util.h"
12 #include "supplicant.h"
13 
14 namespace android {
15 namespace hardware {
16 namespace wifi {
17 namespace supplicant {
18 namespace V1_0 {
19 namespace implementation {
20 using hidl_return_util::validateAndCall;
21 
22 // These are hardcoded for android.
23 const char Supplicant::kDriverName[] = "nl80211";
24 const char Supplicant::kConfigFilePath[] =
25     "/data/misc/wifi/wpa_supplicant.conf";
26 
Supplicant(struct wpa_global * global)27 Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
isValid()28 bool Supplicant::isValid()
29 {
30 	// This top level object cannot be invalidated.
31 	return true;
32 }
33 
getInterface(const IfaceInfo & iface_info,getInterface_cb _hidl_cb)34 Return<void> Supplicant::getInterface(
35     const IfaceInfo& iface_info, getInterface_cb _hidl_cb)
36 {
37 	return validateAndCall(
38 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
39 	    &Supplicant::getInterfaceInternal, _hidl_cb, iface_info);
40 }
41 
listInterfaces(listInterfaces_cb _hidl_cb)42 Return<void> Supplicant::listInterfaces(listInterfaces_cb _hidl_cb)
43 {
44 	return validateAndCall(
45 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
46 	    &Supplicant::listInterfacesInternal, _hidl_cb);
47 }
48 
registerCallback(const sp<ISupplicantCallback> & callback,registerCallback_cb _hidl_cb)49 Return<void> Supplicant::registerCallback(
50     const sp<ISupplicantCallback>& callback, registerCallback_cb _hidl_cb)
51 {
52 	return validateAndCall(
53 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
54 	    &Supplicant::registerCallbackInternal, _hidl_cb, callback);
55 }
56 
setDebugParams(ISupplicant::DebugLevel level,bool show_timestamp,bool show_keys,setDebugParams_cb _hidl_cb)57 Return<void> Supplicant::setDebugParams(
58     ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys,
59     setDebugParams_cb _hidl_cb)
60 {
61 	return validateAndCall(
62 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
63 	    &Supplicant::setDebugParamsInternal, _hidl_cb, level,
64 	    show_timestamp, show_keys);
65 }
66 
setConcurrencyPriority(IfaceType type,setConcurrencyPriority_cb _hidl_cb)67 Return<void> Supplicant::setConcurrencyPriority(
68     IfaceType type, setConcurrencyPriority_cb _hidl_cb)
69 {
70 	return validateAndCall(
71 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
72 	    &Supplicant::setConcurrencyPriorityInternal, _hidl_cb, type);
73 }
74 
getDebugLevel()75 Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
76 {
77 	// TODO: Add SupplicantStatus in this method return for uniformity with
78 	// the other methods in supplicant HIDL interface.
79 	return (ISupplicant::DebugLevel)wpa_debug_level;
80 }
81 
isDebugShowTimestampEnabled()82 Return<bool> Supplicant::isDebugShowTimestampEnabled()
83 {
84 	// TODO: Add SupplicantStatus in this method return for uniformity with
85 	// the other methods in supplicant HIDL interface.
86 	return ((wpa_debug_timestamp != 0) ? true : false);
87 }
88 
isDebugShowKeysEnabled()89 Return<bool> Supplicant::isDebugShowKeysEnabled()
90 {
91 	// TODO: Add SupplicantStatus in this method return for uniformity with
92 	// the other methods in supplicant HIDL interface.
93 	return ((wpa_debug_show_keys != 0) ? true : false);
94 }
95 
96 std::pair<SupplicantStatus, sp<ISupplicantIface>>
getInterfaceInternal(const IfaceInfo & iface_info)97 Supplicant::getInterfaceInternal(const IfaceInfo& iface_info)
98 {
99 	struct wpa_supplicant* wpa_s =
100 	    wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
101 	if (!wpa_s) {
102 		return {{SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, ""},
103 			nullptr};
104 	}
105 	HidlManager* hidl_manager = HidlManager::getInstance();
106 	if (iface_info.type == IfaceType::P2P) {
107 		android::sp<ISupplicantP2pIface> iface;
108 		if (!hidl_manager ||
109 		    hidl_manager->getP2pIfaceHidlObjectByIfname(
110 			wpa_s->ifname, &iface)) {
111 			return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
112 				iface};
113 		}
114 		// Set this flag true here, since there is no HIDL initialize method for the p2p
115 		// config, and the supplicant interface is not ready when the p2p iface is created.
116 		wpa_s->conf->persistent_reconnect = true;
117 		return {{SupplicantStatusCode::SUCCESS, ""}, iface};
118 	} else {
119 		android::sp<ISupplicantStaIface> iface;
120 		if (!hidl_manager ||
121 		    hidl_manager->getStaIfaceHidlObjectByIfname(
122 			wpa_s->ifname, &iface)) {
123 			return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
124 				iface};
125 		}
126 		return {{SupplicantStatusCode::SUCCESS, ""}, iface};
127 	}
128 }
129 
130 std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
listInterfacesInternal()131 Supplicant::listInterfacesInternal()
132 {
133 	std::vector<ISupplicant::IfaceInfo> ifaces;
134 	for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
135 	     wpa_s = wpa_s->next) {
136 		if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
137 			ifaces.emplace_back(ISupplicant::IfaceInfo{
138 			    IfaceType::P2P, wpa_s->ifname});
139 		} else {
140 			ifaces.emplace_back(ISupplicant::IfaceInfo{
141 			    IfaceType::STA, wpa_s->ifname});
142 		}
143 	}
144 	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ifaces)};
145 }
146 
registerCallbackInternal(const sp<ISupplicantCallback> & callback)147 SupplicantStatus Supplicant::registerCallbackInternal(
148     const sp<ISupplicantCallback>& callback)
149 {
150 	HidlManager* hidl_manager = HidlManager::getInstance();
151 	if (!hidl_manager ||
152 	    hidl_manager->addSupplicantCallbackHidlObject(callback)) {
153 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
154 	}
155 	return {SupplicantStatusCode::SUCCESS, ""};
156 }
157 
setDebugParamsInternal(ISupplicant::DebugLevel level,bool show_timestamp,bool show_keys)158 SupplicantStatus Supplicant::setDebugParamsInternal(
159     ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys)
160 {
161 	if (wpa_supplicant_set_debug_params(
162 		wpa_global_, static_cast<uint32_t>(level), show_timestamp,
163 		show_keys)) {
164 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
165 	}
166 	return {SupplicantStatusCode::SUCCESS, ""};
167 }
168 
setConcurrencyPriorityInternal(IfaceType type)169 SupplicantStatus Supplicant::setConcurrencyPriorityInternal(IfaceType type)
170 {
171 	if (type == IfaceType::STA) {
172 		wpa_global_->conc_pref =
173 		    wpa_global::wpa_conc_pref::WPA_CONC_PREF_STA;
174 	} else if (type == IfaceType::P2P) {
175 		wpa_global_->conc_pref =
176 		    wpa_global::wpa_conc_pref::WPA_CONC_PREF_P2P;
177 	} else {
178 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
179 	}
180 	return SupplicantStatus{SupplicantStatusCode::SUCCESS, ""};
181 }
182 }  // namespace implementation
183 }  // namespace V1_0
184 }  // namespace wifi
185 }  // namespace supplicant
186 }  // namespace hardware
187 }  // namespace android
188