blob: 55a541e8405bdc85579236c626260356f99b649b [file] [log] [blame]
Roshan Pius57ffbcf2016-09-27 09:12:46 -07001/*
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
Roshan Pius7c0ebf22016-09-20 15:11:56 -070010#include <hwbinder/IPCThreadState.h>
11#include <hwbinder/ProcessState.h>
Roshan Pius57ffbcf2016-09-27 09:12:46 -070012
13#include "hidl_manager.h"
14
15extern "C" {
16#include "hidl.h"
17#include "hidl_i.h"
18#include "utils/common.h"
19#include "utils/eloop.h"
20#include "utils/includes.h"
21}
22
Roshan Pius7c0ebf22016-09-20 15:11:56 -070023using android::hardware::ProcessState;
24using android::hardware::IPCThreadState;
25using android::hardware::wifi::supplicant::V1_0::implementation::HidlManager;
26
Roshan Pius57ffbcf2016-09-27 09:12:46 -070027void wpas_hidl_sock_handler(
28 int /* sock */, void * /* eloop_ctx */, void *sock_ctx)
29{
30 struct wpas_hidl_priv *priv = (wpas_hidl_priv *)sock_ctx;
Roshan Pius7c0ebf22016-09-20 15:11:56 -070031 wpa_printf(MSG_DEBUG, "Processing hidl events on FD %d", priv->hidl_fd);
32 IPCThreadState::self()->handlePolledCommands();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070033}
34
35struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global)
36{
37 struct wpas_hidl_priv *priv;
Roshan Pius7c0ebf22016-09-20 15:11:56 -070038 HidlManager *hidl_manager;
Roshan Pius57ffbcf2016-09-27 09:12:46 -070039
40 priv = (wpas_hidl_priv *)os_zalloc(sizeof(*priv));
41 if (!priv)
42 return NULL;
43 priv->global = global;
44
45 wpa_printf(MSG_DEBUG, "Initing hidl control");
46
Roshan Pius7c0ebf22016-09-20 15:11:56 -070047 ProcessState::self()->setThreadPoolMaxThreadCount(0);
48 IPCThreadState::self()->disableBackgroundScheduling(true);
49 IPCThreadState::self()->setupPolling(&priv->hidl_fd);
Roshan Pius57ffbcf2016-09-27 09:12:46 -070050 if (priv->hidl_fd < 0)
51 goto err;
52
Roshan Pius7c0ebf22016-09-20 15:11:56 -070053 wpa_printf(MSG_INFO, "Processing hidl events on FD %d", priv->hidl_fd);
54 // Look for read events from the hidl socket in the eloop.
Roshan Pius57ffbcf2016-09-27 09:12:46 -070055 if (eloop_register_read_sock(
56 priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0)
57 goto err;
58
Roshan Pius7c0ebf22016-09-20 15:11:56 -070059 hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070060 if (!hidl_manager)
61 goto err;
62 hidl_manager->registerHidlService(global);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070063 // We may not need to store this hidl manager reference in the
64 // global data strucure because we've made it a singleton class.
Roshan Pius57ffbcf2016-09-27 09:12:46 -070065 priv->hidl_manager = (void *)hidl_manager;
66
67 return priv;
68err:
69 wpas_hidl_deinit(priv);
70 return NULL;
71}
72
73void wpas_hidl_deinit(struct wpas_hidl_priv *priv)
74{
75 if (!priv)
76 return;
77
78 wpa_printf(MSG_DEBUG, "Deiniting hidl control");
79
Roshan Pius7c0ebf22016-09-20 15:11:56 -070080 HidlManager::destroyInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070081 eloop_unregister_read_sock(priv->hidl_fd);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070082 IPCThreadState::shutdown();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070083 os_free(priv);
84}
85
86int wpas_hidl_register_interface(struct wpa_supplicant *wpa_s)
87{
88 if (!wpa_s || !wpa_s->global->hidl)
89 return 1;
90
91 wpa_printf(
92 MSG_DEBUG, "Registering interface to hidl control: %s",
93 wpa_s->ifname);
94
Roshan Pius7c0ebf22016-09-20 15:11:56 -070095 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070096 if (!hidl_manager)
97 return 1;
98
99 return hidl_manager->registerInterface(wpa_s);
100}
101
102int wpas_hidl_unregister_interface(struct wpa_supplicant *wpa_s)
103{
104 if (!wpa_s || !wpa_s->global->hidl)
105 return 1;
106
107 wpa_printf(
108 MSG_DEBUG, "Deregistering interface from hidl control: %s",
109 wpa_s->ifname);
110
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700111 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700112 if (!hidl_manager)
113 return 1;
114
115 return hidl_manager->unregisterInterface(wpa_s);
116}
117
118int wpas_hidl_register_network(
119 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
120{
121 if (!wpa_s || !wpa_s->global->hidl || !ssid)
122 return 1;
123
124 wpa_printf(
125 MSG_DEBUG, "Registering network to hidl control: %d", ssid->id);
126
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700127 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700128 if (!hidl_manager)
129 return 1;
130
131 return hidl_manager->registerNetwork(wpa_s, ssid);
132}
133
134int wpas_hidl_unregister_network(
135 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
136{
137 if (!wpa_s || !wpa_s->global->hidl || !ssid)
138 return 1;
139
140 wpa_printf(
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700141 MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id);
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700142
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700143 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700144 if (!hidl_manager)
145 return 1;
146
147 return hidl_manager->unregisterNetwork(wpa_s, ssid);
148}
149
150int wpas_hidl_notify_state_changed(struct wpa_supplicant *wpa_s)
151{
152 if (!wpa_s || !wpa_s->global->hidl)
153 return 1;
154
155 wpa_printf(
156 MSG_DEBUG, "Notifying state change event to hidl control: %d",
157 wpa_s->wpa_state);
158
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700159 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700160 if (!hidl_manager)
161 return 1;
162
163 return hidl_manager->notifyStateChange(wpa_s);
164}
165
166int wpas_hidl_notify_network_request(
167 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
168 enum wpa_ctrl_req_type rtype, const char *default_txt)
169{
170 if (!wpa_s || !wpa_s->global->hidl || !ssid)
171 return 1;
172
173 wpa_printf(
174 MSG_DEBUG, "Notifying network request to hidl control: %d",
175 ssid->id);
176
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700177 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700178 if (!hidl_manager)
179 return 1;
180
181 return hidl_manager->notifyNetworkRequest(
182 wpa_s, ssid, rtype, default_txt);
183}
Roshan Pius9322a342016-12-12 14:45:02 -0800184
185void wpas_hidl_notify_anqp_query_done(
186 struct wpa_supplicant *wpa_s, const u8 *bssid, const char *result,
187 const struct wpa_bss_anqp *anqp)
188{
189 if (!wpa_s || !wpa_s->global->hidl || !bssid || !result || !anqp)
190 return;
191
192 wpa_printf(
193 MSG_DEBUG,
194 "Notifying ANQP query done to hidl control: " MACSTR "result: %s",
195 MAC2STR(bssid), result);
196
197 HidlManager *hidl_manager = HidlManager::getInstance();
198 if (!hidl_manager)
199 return;
200
201 hidl_manager->notifyAnqpQueryDone(wpa_s, bssid, result, anqp);
202}
203
204void wpas_hidl_notify_hs20_icon_query_done(
205 struct wpa_supplicant *wpa_s, const u8 *bssid, const char *file_name,
206 const u8 *image, u32 image_length)
207{
208 if (!wpa_s || !wpa_s->global->hidl || !bssid || !file_name || !image)
209 return;
210
211 wpa_printf(
212 MSG_DEBUG, "Notifying HS20 icon query done to hidl control: " MACSTR
213 "file_name: %s",
214 MAC2STR(bssid), file_name);
215
216 HidlManager *hidl_manager = HidlManager::getInstance();
217 if (!hidl_manager)
218 return;
219
220 hidl_manager->notifyHs20IconQueryDone(
221 wpa_s, bssid, file_name, image, image_length);
222}
223
224void wpas_hidl_notify_hs20_rx_subscription_remediation(
225 struct wpa_supplicant *wpa_s, const char *url, u8 osu_method)
226{
227 if (!wpa_s || !wpa_s->global->hidl || !url)
228 return;
229
230 wpa_printf(
231 MSG_DEBUG,
232 "Notifying HS20 subscription remediation rx to hidl control: %s",
233 url);
234
235 HidlManager *hidl_manager = HidlManager::getInstance();
236 if (!hidl_manager)
237 return;
238
239 hidl_manager->notifyHs20RxSubscriptionRemediation(
240 wpa_s, url, osu_method);
241}
242
243void wpas_hidl_notify_hs20_rx_deauth_imminent_notice(
244 struct wpa_supplicant *wpa_s, u8 code, u16 reauth_delay, const char *url)
245{
246 if (!wpa_s || !wpa_s->global->hidl || !url)
247 return;
248
249 wpa_printf(
250 MSG_DEBUG,
251 "Notifying HS20 deauth imminent notice rx to hidl control: %s",
252 url);
253
254 HidlManager *hidl_manager = HidlManager::getInstance();
255 if (!hidl_manager)
256 return;
257
258 hidl_manager->notifyHs20RxDeauthImminentNotice(
259 wpa_s, code, reauth_delay, url);
260}