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> |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 11 | |
Martijn Coenen | b7fca8a | 2016-12-28 17:11:37 +0100 | [diff] [blame] | 12 | #include <hidl/HidlTransportSupport.h> |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 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 | |
Martijn Coenen | b7fca8a | 2016-12-28 17:11:37 +0100 | [diff] [blame] | 23 | using android::hardware::configureRpcThreadpool; |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 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( |
Roshan Pius | cb5faa0 | 2017-01-10 09:51:00 -0800 | [diff] [blame^] | 28 | int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */) |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 29 | { |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 30 | IPCThreadState::self()->handlePolledCommands(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global) |
| 34 | { |
| 35 | struct wpas_hidl_priv *priv; |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 36 | HidlManager *hidl_manager; |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 37 | |
| 38 | priv = (wpas_hidl_priv *)os_zalloc(sizeof(*priv)); |
| 39 | if (!priv) |
| 40 | return NULL; |
| 41 | priv->global = global; |
| 42 | |
| 43 | wpa_printf(MSG_DEBUG, "Initing hidl control"); |
| 44 | |
Martijn Coenen | b7fca8a | 2016-12-28 17:11:37 +0100 | [diff] [blame] | 45 | configureRpcThreadpool(1, true /* callerWillJoin */); |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 46 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 47 | IPCThreadState::self()->setupPolling(&priv->hidl_fd); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 48 | if (priv->hidl_fd < 0) |
| 49 | goto err; |
| 50 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 51 | wpa_printf(MSG_INFO, "Processing hidl events on FD %d", priv->hidl_fd); |
| 52 | // Look for read events from the hidl socket in the eloop. |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 53 | if (eloop_register_read_sock( |
| 54 | priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0) |
| 55 | goto err; |
| 56 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 57 | hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 58 | if (!hidl_manager) |
| 59 | goto err; |
| 60 | hidl_manager->registerHidlService(global); |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 61 | // We may not need to store this hidl manager reference in the |
| 62 | // global data strucure because we've made it a singleton class. |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 63 | priv->hidl_manager = (void *)hidl_manager; |
| 64 | |
| 65 | return priv; |
| 66 | err: |
| 67 | wpas_hidl_deinit(priv); |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | void wpas_hidl_deinit(struct wpas_hidl_priv *priv) |
| 72 | { |
| 73 | if (!priv) |
| 74 | return; |
| 75 | |
| 76 | wpa_printf(MSG_DEBUG, "Deiniting hidl control"); |
| 77 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 78 | HidlManager::destroyInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 79 | eloop_unregister_read_sock(priv->hidl_fd); |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 80 | IPCThreadState::shutdown(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 81 | os_free(priv); |
| 82 | } |
| 83 | |
| 84 | int wpas_hidl_register_interface(struct wpa_supplicant *wpa_s) |
| 85 | { |
| 86 | if (!wpa_s || !wpa_s->global->hidl) |
| 87 | return 1; |
| 88 | |
| 89 | wpa_printf( |
| 90 | MSG_DEBUG, "Registering interface to hidl control: %s", |
| 91 | wpa_s->ifname); |
| 92 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 93 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 94 | if (!hidl_manager) |
| 95 | return 1; |
| 96 | |
| 97 | return hidl_manager->registerInterface(wpa_s); |
| 98 | } |
| 99 | |
| 100 | int wpas_hidl_unregister_interface(struct wpa_supplicant *wpa_s) |
| 101 | { |
| 102 | if (!wpa_s || !wpa_s->global->hidl) |
| 103 | return 1; |
| 104 | |
| 105 | wpa_printf( |
| 106 | MSG_DEBUG, "Deregistering interface from hidl control: %s", |
| 107 | wpa_s->ifname); |
| 108 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 109 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 110 | if (!hidl_manager) |
| 111 | return 1; |
| 112 | |
| 113 | return hidl_manager->unregisterInterface(wpa_s); |
| 114 | } |
| 115 | |
| 116 | int wpas_hidl_register_network( |
| 117 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 118 | { |
| 119 | if (!wpa_s || !wpa_s->global->hidl || !ssid) |
| 120 | return 1; |
| 121 | |
| 122 | wpa_printf( |
| 123 | MSG_DEBUG, "Registering network to hidl control: %d", ssid->id); |
| 124 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 125 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 126 | if (!hidl_manager) |
| 127 | return 1; |
| 128 | |
| 129 | return hidl_manager->registerNetwork(wpa_s, ssid); |
| 130 | } |
| 131 | |
| 132 | int wpas_hidl_unregister_network( |
| 133 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 134 | { |
| 135 | if (!wpa_s || !wpa_s->global->hidl || !ssid) |
| 136 | return 1; |
| 137 | |
| 138 | wpa_printf( |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 139 | MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 140 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 141 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 142 | if (!hidl_manager) |
| 143 | return 1; |
| 144 | |
| 145 | return hidl_manager->unregisterNetwork(wpa_s, ssid); |
| 146 | } |
| 147 | |
| 148 | int wpas_hidl_notify_state_changed(struct wpa_supplicant *wpa_s) |
| 149 | { |
| 150 | if (!wpa_s || !wpa_s->global->hidl) |
| 151 | return 1; |
| 152 | |
| 153 | wpa_printf( |
| 154 | MSG_DEBUG, "Notifying state change event to hidl control: %d", |
| 155 | wpa_s->wpa_state); |
| 156 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 157 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 158 | if (!hidl_manager) |
| 159 | return 1; |
| 160 | |
| 161 | return hidl_manager->notifyStateChange(wpa_s); |
| 162 | } |
| 163 | |
| 164 | int wpas_hidl_notify_network_request( |
| 165 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 166 | enum wpa_ctrl_req_type rtype, const char *default_txt) |
| 167 | { |
| 168 | if (!wpa_s || !wpa_s->global->hidl || !ssid) |
| 169 | return 1; |
| 170 | |
| 171 | wpa_printf( |
| 172 | MSG_DEBUG, "Notifying network request to hidl control: %d", |
| 173 | ssid->id); |
| 174 | |
Roshan Pius | 7c0ebf2 | 2016-09-20 15:11:56 -0700 | [diff] [blame] | 175 | HidlManager *hidl_manager = HidlManager::getInstance(); |
Roshan Pius | 57ffbcf | 2016-09-27 09:12:46 -0700 | [diff] [blame] | 176 | if (!hidl_manager) |
| 177 | return 1; |
| 178 | |
| 179 | return hidl_manager->notifyNetworkRequest( |
| 180 | wpa_s, ssid, rtype, default_txt); |
| 181 | } |
Roshan Pius | 9322a34 | 2016-12-12 14:45:02 -0800 | [diff] [blame] | 182 | |
| 183 | void wpas_hidl_notify_anqp_query_done( |
| 184 | struct wpa_supplicant *wpa_s, const u8 *bssid, const char *result, |
| 185 | const struct wpa_bss_anqp *anqp) |
| 186 | { |
| 187 | if (!wpa_s || !wpa_s->global->hidl || !bssid || !result || !anqp) |
| 188 | return; |
| 189 | |
| 190 | wpa_printf( |
| 191 | MSG_DEBUG, |
| 192 | "Notifying ANQP query done to hidl control: " MACSTR "result: %s", |
| 193 | MAC2STR(bssid), result); |
| 194 | |
| 195 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 196 | if (!hidl_manager) |
| 197 | return; |
| 198 | |
| 199 | hidl_manager->notifyAnqpQueryDone(wpa_s, bssid, result, anqp); |
| 200 | } |
| 201 | |
| 202 | void wpas_hidl_notify_hs20_icon_query_done( |
| 203 | struct wpa_supplicant *wpa_s, const u8 *bssid, const char *file_name, |
| 204 | const u8 *image, u32 image_length) |
| 205 | { |
| 206 | if (!wpa_s || !wpa_s->global->hidl || !bssid || !file_name || !image) |
| 207 | return; |
| 208 | |
| 209 | wpa_printf( |
| 210 | MSG_DEBUG, "Notifying HS20 icon query done to hidl control: " MACSTR |
| 211 | "file_name: %s", |
| 212 | MAC2STR(bssid), file_name); |
| 213 | |
| 214 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 215 | if (!hidl_manager) |
| 216 | return; |
| 217 | |
| 218 | hidl_manager->notifyHs20IconQueryDone( |
| 219 | wpa_s, bssid, file_name, image, image_length); |
| 220 | } |
| 221 | |
| 222 | void wpas_hidl_notify_hs20_rx_subscription_remediation( |
| 223 | struct wpa_supplicant *wpa_s, const char *url, u8 osu_method) |
| 224 | { |
| 225 | if (!wpa_s || !wpa_s->global->hidl || !url) |
| 226 | return; |
| 227 | |
| 228 | wpa_printf( |
| 229 | MSG_DEBUG, |
| 230 | "Notifying HS20 subscription remediation rx to hidl control: %s", |
| 231 | url); |
| 232 | |
| 233 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 234 | if (!hidl_manager) |
| 235 | return; |
| 236 | |
| 237 | hidl_manager->notifyHs20RxSubscriptionRemediation( |
| 238 | wpa_s, url, osu_method); |
| 239 | } |
| 240 | |
| 241 | void wpas_hidl_notify_hs20_rx_deauth_imminent_notice( |
| 242 | struct wpa_supplicant *wpa_s, u8 code, u16 reauth_delay, const char *url) |
| 243 | { |
| 244 | if (!wpa_s || !wpa_s->global->hidl || !url) |
| 245 | return; |
| 246 | |
| 247 | wpa_printf( |
| 248 | MSG_DEBUG, |
| 249 | "Notifying HS20 deauth imminent notice rx to hidl control: %s", |
| 250 | url); |
| 251 | |
| 252 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 253 | if (!hidl_manager) |
| 254 | return; |
| 255 | |
| 256 | hidl_manager->notifyHs20RxDeauthImminentNotice( |
| 257 | wpa_s, code, reauth_delay, url); |
| 258 | } |
Roshan Pius | 0974e96 | 2016-12-12 17:05:51 -0800 | [diff] [blame] | 259 | |
| 260 | void wpas_hidl_notify_disconnect_reason(struct wpa_supplicant *wpa_s) |
| 261 | { |
| 262 | if (!wpa_s) |
| 263 | return; |
| 264 | |
| 265 | wpa_printf( |
| 266 | MSG_DEBUG, "Notifying disconnect reason to hidl control: %d", |
| 267 | wpa_s->disconnect_reason); |
| 268 | |
| 269 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 270 | if (!hidl_manager) |
| 271 | return; |
| 272 | |
| 273 | hidl_manager->notifyDisconnectReason(wpa_s); |
| 274 | } |
| 275 | |
| 276 | void wpas_hidl_notify_assoc_reject(struct wpa_supplicant *wpa_s) |
| 277 | { |
| 278 | if (!wpa_s) |
| 279 | return; |
| 280 | |
| 281 | wpa_printf( |
| 282 | MSG_DEBUG, "Notifying assoc reject to hidl control: %d", |
| 283 | wpa_s->assoc_status_code); |
| 284 | |
| 285 | HidlManager *hidl_manager = HidlManager::getInstance(); |
| 286 | if (!hidl_manager) |
| 287 | return; |
| 288 | |
| 289 | hidl_manager->notifyAssocReject(wpa_s); |
| 290 | } |