Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 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 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 10 | #include <hwbinder/IPCThreadState.h> |
| 11 | #include <hwbinder/ProcessState.h> |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 12 | |
| 13 | #include "hidl_manager.h" |
| 14 | |
| 15 | extern "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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 23 | using android::hardware::ProcessState; |
| 24 | using android::hardware::IPCThreadState; |
| 25 | using android::hardware::wifi::supplicant::V1_0::implementation::HidlManager; |
| 26 | |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 27 | void 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 31 | wpa_printf(MSG_DEBUG, "Processing hidl events on FD %d", priv->hidl_fd); |
| 32 | IPCThreadState::self()->handlePolledCommands(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global) |
| 36 | { |
| 37 | struct wpas_hidl_priv *priv; |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 38 | HidlManager *hidl_manager; |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 39 | |
| 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 47 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
| 48 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 49 | IPCThreadState::self()->setupPolling(&priv->hidl_fd); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 50 | if (priv->hidl_fd < 0) |
| 51 | goto err; |
| 52 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 53 | 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 Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 55 | if (eloop_register_read_sock( |
| 56 | priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0) |
| 57 | goto err; |
| 58 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 59 | hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 60 | if (!hidl_manager) |
| 61 | goto err; |
| 62 | hidl_manager->registerHidlService(global); |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 63 | // 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 Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 65 | priv->hidl_manager = (void *)hidl_manager; |
| 66 | |
| 67 | return priv; |
| 68 | err: |
| 69 | wpas_hidl_deinit(priv); |
| 70 | return NULL; |
| 71 | } |
| 72 | |
| 73 | void 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 80 | HidlManager::destroyInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 81 | eloop_unregister_read_sock(priv->hidl_fd); |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 82 | IPCThreadState::shutdown(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 83 | os_free(priv); |
| 84 | } |
| 85 | |
| 86 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 95 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 96 | if (!hidl_manager) |
| 97 | return 1; |
| 98 | |
| 99 | return hidl_manager->registerInterface(wpa_s); |
| 100 | } |
| 101 | |
| 102 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 111 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 112 | if (!hidl_manager) |
| 113 | return 1; |
| 114 | |
| 115 | return hidl_manager->unregisterInterface(wpa_s); |
| 116 | } |
| 117 | |
| 118 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 127 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 128 | if (!hidl_manager) |
| 129 | return 1; |
| 130 | |
| 131 | return hidl_manager->registerNetwork(wpa_s, ssid); |
| 132 | } |
| 133 | |
| 134 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 141 | MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 142 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 143 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 144 | if (!hidl_manager) |
| 145 | return 1; |
| 146 | |
| 147 | return hidl_manager->unregisterNetwork(wpa_s, ssid); |
| 148 | } |
| 149 | |
| 150 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 159 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 160 | if (!hidl_manager) |
| 161 | return 1; |
| 162 | |
| 163 | return hidl_manager->notifyStateChange(wpa_s); |
| 164 | } |
| 165 | |
| 166 | int 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 Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 177 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 178 | if (!hidl_manager) |
| 179 | return 1; |
| 180 | |
| 181 | return hidl_manager->notifyNetworkRequest( |
| 182 | wpa_s, ssid, rtype, default_txt); |
| 183 | } |
Roshan Pius | 9322a34 | 2016-12-12 14:45:02 -0800 | [diff] [blame^] | 184 | |
| 185 | void 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 | |
| 204 | void 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 | |
| 224 | void 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 | |
| 243 | void 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 | } |