blob: 3ff514edc2cf31f2596b84750c5e7242acb523ad [file] [log] [blame]
Dmitry Shmidte4663042016-04-04 10:07:49 -07001/*
Roshan Pius57ffbcf2016-09-27 09:12:46 -07002 * hidl interface for wpa_supplicant daemon
Dmitry Shmidte4663042016-04-04 10:07:49 -07003 * 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
Roshan Pius0470cc82016-07-14 16:37:07 -070010#include "supplicant.h"
Roshan Pius57ffbcf2016-09-27 09:12:46 -070011#include "hidl_manager.h"
12#include "../src/utils/wpa_debug.h"
Dmitry Shmidte4663042016-04-04 10:07:49 -070013
Roshan Pius57ffbcf2016-09-27 09:12:46 -070014namespace wpa_supplicant_hidl {
Dmitry Shmidte4663042016-04-04 10:07:49 -070015
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070016Supplicant::Supplicant(struct wpa_global *global) : wpa_global_(global) {}
Roshan Pius57ffbcf2016-09-27 09:12:46 -070017android::hidl::Status Supplicant::CreateInterface(
Roshan Piusb01b7962016-07-11 15:25:47 -070018 const fi::w1::wpa_supplicant::ParcelableIfaceParams &params,
Roshan Piusc9422c72016-07-11 10:18:22 -070019 android::sp<fi::w1::wpa_supplicant::IIface> *iface_object_out)
Dmitry Shmidte4663042016-04-04 10:07:49 -070020{
Dmitry Shmidte4663042016-04-04 10:07:49 -070021 /* Check if required Ifname argument is missing */
Roshan Piusb01b7962016-07-11 15:25:47 -070022 if (params.ifname_.isEmpty()) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070023 return android::hidl::Status::fromExceptionCode(
24 android::hidl::Status::EX_ILLEGAL_ARGUMENT,
Roshan Piusd6e37512016-07-07 13:20:46 -070025 "Ifname missing in params.");
Roshan Pius32c15e22016-07-07 13:46:39 -070026 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070027 /*
28 * Try to get the wpa_supplicant record for this iface, return
29 * an error if we already control it.
30 */
Roshan Piusb01b7962016-07-11 15:25:47 -070031 if (wpa_supplicant_get_iface(wpa_global_, params.ifname_.string()) !=
32 NULL) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070033 return android::hidl::Status::fromServiceSpecificError(
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070034 ERROR_IFACE_EXISTS,
Roshan Piusd6e37512016-07-07 13:20:46 -070035 "wpa_supplicant already controls this interface.");
Roshan Pius32c15e22016-07-07 13:46:39 -070036 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070037
Roshan Pius57ffbcf2016-09-27 09:12:46 -070038 android::hidl::Status status;
Dmitry Shmidte4663042016-04-04 10:07:49 -070039 struct wpa_supplicant *wpa_s = NULL;
40 struct wpa_interface iface;
41
42 os_memset(&iface, 0, sizeof(iface));
Roshan Piusb01b7962016-07-11 15:25:47 -070043 iface.driver = os_strdup(params.driver_.string());
44 iface.ifname = os_strdup(params.ifname_.string());
45 iface.confname = os_strdup(params.config_file_.string());
46 iface.bridge_ifname = os_strdup(params.bridge_ifname_.string());
Dmitry Shmidte4663042016-04-04 10:07:49 -070047 /* Otherwise, have wpa_supplicant attach to it. */
48 wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface, NULL);
Roshan Pius57ffbcf2016-09-27 09:12:46 -070049 /* The supplicant core creates a corresponding hidl object via
50 * HidlManager when |wpa_supplicant_add_iface| is called. */
Roshan Pius32c15e22016-07-07 13:46:39 -070051 if (!wpa_s) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070052 status = android::hidl::Status::fromServiceSpecificError(
Roshan Piusd6e37512016-07-07 13:20:46 -070053 ERROR_GENERIC,
54 "wpa_supplicant couldn't grab this interface.");
Dmitry Shmidte4663042016-04-04 10:07:49 -070055 } else {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070056 HidlManager *hidl_manager = HidlManager::getInstance();
Dmitry Shmidte4663042016-04-04 10:07:49 -070057
Roshan Pius57ffbcf2016-09-27 09:12:46 -070058 if (!hidl_manager ||
59 hidl_manager->getIfaceHidlObjectByIfname(
Roshan Piusc9422c72016-07-11 10:18:22 -070060 wpa_s->ifname, iface_object_out)) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070061 status =
Roshan Pius57ffbcf2016-09-27 09:12:46 -070062 android::hidl::Status::fromServiceSpecificError(
Roshan Piusd6e37512016-07-07 13:20:46 -070063 ERROR_GENERIC,
Roshan Pius57ffbcf2016-09-27 09:12:46 -070064 "wpa_supplicant encountered a hidl error.");
Roshan Pius32c15e22016-07-07 13:46:39 -070065 } else {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070066 status = android::hidl::Status::ok();
Roshan Pius32c15e22016-07-07 13:46:39 -070067 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070068 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070069 os_free((void *)iface.driver);
70 os_free((void *)iface.ifname);
71 os_free((void *)iface.confname);
72 os_free((void *)iface.bridge_ifname);
Dmitry Shmidte4663042016-04-04 10:07:49 -070073 return status;
74}
75
Roshan Pius57ffbcf2016-09-27 09:12:46 -070076android::hidl::Status Supplicant::RemoveInterface(const std::string &ifname)
Dmitry Shmidte4663042016-04-04 10:07:49 -070077{
78 struct wpa_supplicant *wpa_s;
79
80 wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
Roshan Pius32c15e22016-07-07 13:46:39 -070081 if (!wpa_s) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070082 return android::hidl::Status::fromServiceSpecificError(
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070083 ERROR_IFACE_UNKNOWN,
Roshan Piusd6e37512016-07-07 13:20:46 -070084 "wpa_supplicant does not control this interface.");
Roshan Pius32c15e22016-07-07 13:46:39 -070085 }
86 if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0)) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -070087 return android::hidl::Status::fromServiceSpecificError(
Roshan Piusd6e37512016-07-07 13:20:46 -070088 ERROR_GENERIC,
89 "wpa_supplicant couldn't remove this interface.");
Roshan Pius32c15e22016-07-07 13:46:39 -070090 }
Roshan Pius57ffbcf2016-09-27 09:12:46 -070091 return android::hidl::Status::ok();
Dmitry Shmidte4663042016-04-04 10:07:49 -070092}
93
Roshan Pius57ffbcf2016-09-27 09:12:46 -070094android::hidl::Status Supplicant::GetInterface(
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070095 const std::string &ifname,
Roshan Piusc9422c72016-07-11 10:18:22 -070096 android::sp<fi::w1::wpa_supplicant::IIface> *iface_object_out)
Dmitry Shmidte4663042016-04-04 10:07:49 -070097{
98 struct wpa_supplicant *wpa_s;
99
100 wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
Roshan Pius32c15e22016-07-07 13:46:39 -0700101 if (!wpa_s) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700102 return android::hidl::Status::fromServiceSpecificError(
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700103 ERROR_IFACE_UNKNOWN,
Roshan Piusd6e37512016-07-07 13:20:46 -0700104 "wpa_supplicant does not control this interface.");
Roshan Pius32c15e22016-07-07 13:46:39 -0700105 }
Dmitry Shmidte4663042016-04-04 10:07:49 -0700106
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700107 HidlManager *hidl_manager = HidlManager::getInstance();
108 if (!hidl_manager ||
109 hidl_manager->getIfaceHidlObjectByIfname(
Roshan Piusc9422c72016-07-11 10:18:22 -0700110 wpa_s->ifname, iface_object_out)) {
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700111 return android::hidl::Status::fromServiceSpecificError(
Roshan Piusd6e37512016-07-07 13:20:46 -0700112 ERROR_GENERIC,
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700113 "wpa_supplicant encountered a hidl error.");
Roshan Pius32c15e22016-07-07 13:46:39 -0700114 }
Dmitry Shmidte4663042016-04-04 10:07:49 -0700115
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700116 return android::hidl::Status::ok();
Dmitry Shmidte4663042016-04-04 10:07:49 -0700117}
118
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700119android::hidl::Status Supplicant::SetDebugParams(
Roshan Pius32f9f5f2016-08-15 14:44:22 -0700120 int level, bool show_timestamp, bool show_keys)
Roshan Piusc9422c72016-07-11 10:18:22 -0700121{
122 int internal_level;
123 if (convertDebugLevelToInternalLevel(level, &internal_level)) {
124 const std::string error_msg =
125 "invalid debug level: " + std::to_string(level);
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700126 return android::hidl::Status::fromExceptionCode(
127 android::hidl::Status::EX_ILLEGAL_ARGUMENT,
Roshan Piusc9422c72016-07-11 10:18:22 -0700128 error_msg.c_str());
129 }
130 if (wpa_supplicant_set_debug_params(
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700131<<<<<<< 390ba2881ef621db480848b7e50b93d61542206a:wpa_supplicant/binder/supplicant.cpp
Roshan Piusc9422c72016-07-11 10:18:22 -0700132 wpa_global_, internal_level, show_timestamp, show_keys)) {
133 return android::binder::Status::fromServiceSpecificError(
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700134=======
135 wpa_global_, level, show_timestamp, show_keys)) {
136 return android::hidl::Status::fromServiceSpecificError(
137>>>>>>> wpa_supplicant: HIDL implementation (1/2):wpa_supplicant/hidl/supplicant.cpp
Roshan Piusc9422c72016-07-11 10:18:22 -0700138 ERROR_GENERIC,
139 "wpa_supplicant could not set debug params.");
140 }
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700141 return android::hidl::Status::ok();
Roshan Piusc9422c72016-07-11 10:18:22 -0700142}
143
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700144android::hidl::Status Supplicant::GetDebugLevel(int *level_out)
Roshan Piusc9422c72016-07-11 10:18:22 -0700145{
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700146<<<<<<< 390ba2881ef621db480848b7e50b93d61542206a:wpa_supplicant/binder/supplicant.cpp
Roshan Piusc9422c72016-07-11 10:18:22 -0700147 if (convertDebugLevelToExternalLevel(wpa_debug_level, level_out)) {
148 const std::string error_msg =
149 "invalid debug level: " + std::to_string(wpa_debug_level);
150 return android::binder::Status::fromExceptionCode(
151 android::binder::Status::EX_ILLEGAL_ARGUMENT,
152 error_msg.c_str());
153 }
154 return android::binder::Status::ok();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700155=======
156 *level_out = wpa_debug_level;
157 return android::hidl::Status::ok();
158>>>>>>> wpa_supplicant: HIDL implementation (1/2):wpa_supplicant/hidl/supplicant.cpp
Roshan Piusc9422c72016-07-11 10:18:22 -0700159}
160
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700161android::hidl::Status Supplicant::GetDebugShowTimestamp(
Roshan Pius32f9f5f2016-08-15 14:44:22 -0700162 bool *show_timestamp_out)
Roshan Piusc9422c72016-07-11 10:18:22 -0700163{
164 *show_timestamp_out = wpa_debug_timestamp ? true : false;
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700165 return android::hidl::Status::ok();
Roshan Piusc9422c72016-07-11 10:18:22 -0700166}
167
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700168android::hidl::Status Supplicant::GetDebugShowKeys(bool *show_keys_out)
Roshan Piusc9422c72016-07-11 10:18:22 -0700169{
170 *show_keys_out = wpa_debug_show_keys ? true : false;
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700171 return android::hidl::Status::ok();
Roshan Piusc9422c72016-07-11 10:18:22 -0700172}
173
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700174android::hidl::Status Supplicant::RegisterCallback(
Roshan Pius0470cc82016-07-14 16:37:07 -0700175 const android::sp<fi::w1::wpa_supplicant::ISupplicantCallback> &callback)
176{
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700177 HidlManager *hidl_manager = HidlManager::getInstance();
178 if (!hidl_manager ||
179 hidl_manager->addSupplicantCallbackHidlObject(callback)) {
180 return android::hidl::Status::fromServiceSpecificError(
Roshan Pius0470cc82016-07-14 16:37:07 -0700181 ERROR_GENERIC,
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700182 "wpa_supplicant encountered a hidl error.");
Roshan Pius0470cc82016-07-14 16:37:07 -0700183 }
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700184 return android::hidl::Status::ok();
Roshan Pius0470cc82016-07-14 16:37:07 -0700185}
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700186<<<<<<< 390ba2881ef621db480848b7e50b93d61542206a:wpa_supplicant/binder/supplicant.cpp
Roshan Pius0470cc82016-07-14 16:37:07 -0700187
Roshan Piusc9422c72016-07-11 10:18:22 -0700188/**
189 * Helper function to convert the debug level parameter from the binder
190 * interface values to internal values.
191 */
192int Supplicant::convertDebugLevelToInternalLevel(
193 int external_level, int *internal_level)
194{
195 switch (external_level) {
196 case DEBUG_LEVEL_EXCESSIVE:
197 *internal_level = MSG_EXCESSIVE;
198 return 0;
199 case DEBUG_LEVEL_MSGDUMP:
200 *internal_level = MSG_MSGDUMP;
201 return 0;
202 case DEBUG_LEVEL_DEBUG:
203 *internal_level = MSG_DEBUG;
204 return 0;
205 case DEBUG_LEVEL_INFO:
206 *internal_level = MSG_INFO;
207 return 0;
208 case DEBUG_LEVEL_WARNING:
209 *internal_level = MSG_WARNING;
210 return 0;
211 case DEBUG_LEVEL_ERROR:
212 *internal_level = MSG_ERROR;
213 return 0;
214 default:
215 wpa_printf(
216 MSG_ERROR, "Invalid external log level: %d",
217 external_level);
218 return 1;
219 }
220}
221
222/**
223 * Helper function to convert the debug level parameter from the internal values
224 * to binder interface values.
225 */
226int Supplicant::convertDebugLevelToExternalLevel(
227 int internal_level, int *external_level)
228{
229 switch (internal_level) {
230 case MSG_EXCESSIVE:
231 *external_level = DEBUG_LEVEL_EXCESSIVE;
232 return 0;
233 case MSG_MSGDUMP:
234 *external_level = DEBUG_LEVEL_MSGDUMP;
235 return 0;
236 case MSG_DEBUG:
237 *external_level = DEBUG_LEVEL_DEBUG;
238 return 0;
239 case MSG_INFO:
240 *external_level = DEBUG_LEVEL_INFO;
241 return 0;
242 case MSG_WARNING:
243 *external_level = DEBUG_LEVEL_WARNING;
244 return 0;
245 case MSG_ERROR:
246 *external_level = DEBUG_LEVEL_ERROR;
247 return 0;
248 default:
249 wpa_printf(
250 MSG_ERROR, "Invalid internal log level: %d",
251 internal_level);
252 return 1;
253 }
254}
Dmitry Shmidte4663042016-04-04 10:07:49 -0700255} /* namespace wpa_supplicant_binder */
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700256=======
257} /* namespace wpa_supplicant_hidl */
258>>>>>>> wpa_supplicant: HIDL implementation (1/2):wpa_supplicant/hidl/supplicant.cpp