Home | History | Annotate | Download | only in 1.0
      1 /*
      2  * hidl interface for wpa_supplicant daemon
      3  * Copyright (c) 2004-2016, Jouni Malinen <j (at) w1.fi>
      4  * Copyright (c) 2004-2016, Roshan Pius <rpius (at) 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 <hwbinder/IPCThreadState.h>
     11 
     12 #include <hidl/HidlTransportSupport.h>
     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 
     23 using android::hardware::configureRpcThreadpool;
     24 using android::hardware::IPCThreadState;
     25 using android::hardware::wifi::supplicant::V1_0::implementation::HidlManager;
     26 
     27 void wpas_hidl_sock_handler(
     28     int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */)
     29 {
     30 	IPCThreadState::self()->handlePolledCommands();
     31 }
     32 
     33 struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global)
     34 {
     35 	struct wpas_hidl_priv *priv;
     36 	HidlManager *hidl_manager;
     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 
     45 	configureRpcThreadpool(1, true /* callerWillJoin */);
     46 	IPCThreadState::self()->disableBackgroundScheduling(true);
     47 	IPCThreadState::self()->setupPolling(&priv->hidl_fd);
     48 	if (priv->hidl_fd < 0)
     49 		goto err;
     50 
     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.
     53 	if (eloop_register_read_sock(
     54 		priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0)
     55 		goto err;
     56 
     57 	hidl_manager = HidlManager::getInstance();
     58 	if (!hidl_manager)
     59 		goto err;
     60 	hidl_manager->registerHidlService(global);
     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.
     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 
     78 	HidlManager::destroyInstance();
     79 	eloop_unregister_read_sock(priv->hidl_fd);
     80 	IPCThreadState::shutdown();
     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 
     93 	HidlManager *hidl_manager = HidlManager::getInstance();
     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 
    109 	HidlManager *hidl_manager = HidlManager::getInstance();
    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 
    125 	HidlManager *hidl_manager = HidlManager::getInstance();
    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(
    139 	    MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id);
    140 
    141 	HidlManager *hidl_manager = HidlManager::getInstance();
    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 
    157 	HidlManager *hidl_manager = HidlManager::getInstance();
    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 
    175 	HidlManager *hidl_manager = HidlManager::getInstance();
    176 	if (!hidl_manager)
    177 		return 1;
    178 
    179 	return hidl_manager->notifyNetworkRequest(
    180 	    wpa_s, ssid, rtype, default_txt);
    181 }
    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 }
    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 }
    291 
    292 void wpas_hidl_notify_auth_timeout(struct wpa_supplicant *wpa_s)
    293 {
    294 	if (!wpa_s)
    295 		return;
    296 
    297 	wpa_printf(MSG_DEBUG, "Notifying auth timeout to hidl control");
    298 
    299 	HidlManager *hidl_manager = HidlManager::getInstance();
    300 	if (!hidl_manager)
    301 		return;
    302 
    303 	hidl_manager->notifyAuthTimeout(wpa_s);
    304 }
    305 
    306 void wpas_hidl_notify_bssid_changed(struct wpa_supplicant *wpa_s)
    307 {
    308 	if (!wpa_s)
    309 		return;
    310 
    311 	wpa_printf(MSG_DEBUG, "Notifying bssid changed to hidl control");
    312 
    313 	HidlManager *hidl_manager = HidlManager::getInstance();
    314 	if (!hidl_manager)
    315 		return;
    316 
    317 	hidl_manager->notifyBssidChanged(wpa_s);
    318 }
    319 
    320 void wpas_hidl_notify_wps_event_fail(
    321     struct wpa_supplicant *wpa_s, uint8_t *peer_macaddr, uint16_t config_error,
    322     uint16_t error_indication)
    323 {
    324 	if (!wpa_s || !peer_macaddr)
    325 		return;
    326 
    327 	wpa_printf(
    328 	    MSG_DEBUG, "Notifying Wps event fail to hidl control: %d, %d",
    329 	    config_error, error_indication);
    330 
    331 	HidlManager *hidl_manager = HidlManager::getInstance();
    332 	if (!hidl_manager)
    333 		return;
    334 
    335 	hidl_manager->notifyWpsEventFail(
    336 	    wpa_s, peer_macaddr, config_error, error_indication);
    337 }
    338 
    339 void wpas_hidl_notify_wps_event_success(struct wpa_supplicant *wpa_s)
    340 {
    341 	if (!wpa_s)
    342 		return;
    343 
    344 	wpa_printf(MSG_DEBUG, "Notifying Wps event success to hidl control");
    345 
    346 	HidlManager *hidl_manager = HidlManager::getInstance();
    347 	if (!hidl_manager)
    348 		return;
    349 
    350 	hidl_manager->notifyWpsEventSuccess(wpa_s);
    351 }
    352 
    353 void wpas_hidl_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
    354 {
    355 	if (!wpa_s)
    356 		return;
    357 
    358 	wpa_printf(
    359 	    MSG_DEBUG, "Notifying Wps event PBC overlap to hidl control");
    360 
    361 	HidlManager *hidl_manager = HidlManager::getInstance();
    362 	if (!hidl_manager)
    363 		return;
    364 
    365 	hidl_manager->notifyWpsEventPbcOverlap(wpa_s);
    366 }
    367 
    368 void wpas_hidl_notify_p2p_device_found(
    369     struct wpa_supplicant *wpa_s, const u8 *addr,
    370     const struct p2p_peer_info *info, const u8 *peer_wfd_device_info,
    371     u8 peer_wfd_device_info_len)
    372 {
    373 	if (!wpa_s || !addr || !info)
    374 		return;
    375 
    376 	wpa_printf(
    377 	    MSG_DEBUG, "Notifying P2P device found to hidl control " MACSTR,
    378 	    MAC2STR(info->p2p_device_addr));
    379 
    380 	HidlManager *hidl_manager = HidlManager::getInstance();
    381 	if (!hidl_manager)
    382 		return;
    383 
    384 	hidl_manager->notifyP2pDeviceFound(
    385 	    wpa_s, addr, info, peer_wfd_device_info, peer_wfd_device_info_len);
    386 }
    387 
    388 void wpas_hidl_notify_p2p_device_lost(
    389     struct wpa_supplicant *wpa_s, const u8 *p2p_device_addr)
    390 {
    391 	if (!wpa_s || !p2p_device_addr)
    392 		return;
    393 
    394 	wpa_printf(
    395 	    MSG_DEBUG, "Notifying P2P device lost to hidl control " MACSTR,
    396 	    MAC2STR(p2p_device_addr));
    397 
    398 	HidlManager *hidl_manager = HidlManager::getInstance();
    399 	if (!hidl_manager)
    400 		return;
    401 
    402 	hidl_manager->notifyP2pDeviceLost(wpa_s, p2p_device_addr);
    403 }
    404 
    405 void wpas_hidl_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
    406 {
    407 	if (!wpa_s)
    408 		return;
    409 
    410 	wpa_printf(MSG_DEBUG, "Notifying P2P find stop to hidl control");
    411 
    412 	HidlManager *hidl_manager = HidlManager::getInstance();
    413 	if (!hidl_manager)
    414 		return;
    415 
    416 	hidl_manager->notifyP2pFindStopped(wpa_s);
    417 }
    418 
    419 void wpas_hidl_notify_p2p_go_neg_req(
    420     struct wpa_supplicant *wpa_s, const u8 *src_addr, u16 dev_passwd_id,
    421     u8 go_intent)
    422 {
    423 	if (!wpa_s || !src_addr)
    424 		return;
    425 
    426 	wpa_printf(
    427 	    MSG_DEBUG,
    428 	    "Notifying P2P GO negotiation request to hidl control " MACSTR,
    429 	    MAC2STR(src_addr));
    430 
    431 	HidlManager *hidl_manager = HidlManager::getInstance();
    432 	if (!hidl_manager)
    433 		return;
    434 
    435 	hidl_manager->notifyP2pGoNegReq(
    436 	    wpa_s, src_addr, dev_passwd_id, go_intent);
    437 }
    438 
    439 void wpas_hidl_notify_p2p_go_neg_completed(
    440     struct wpa_supplicant *wpa_s, const struct p2p_go_neg_results *res)
    441 {
    442 	if (!wpa_s || !res)
    443 		return;
    444 
    445 	wpa_printf(
    446 	    MSG_DEBUG,
    447 	    "Notifying P2P GO negotiation completed to hidl control: %d",
    448 	    res->status);
    449 
    450 	HidlManager *hidl_manager = HidlManager::getInstance();
    451 	if (!hidl_manager)
    452 		return;
    453 
    454 	hidl_manager->notifyP2pGoNegCompleted(wpa_s, res);
    455 }
    456 
    457 void wpas_hidl_notify_p2p_group_formation_failure(
    458     struct wpa_supplicant *wpa_s, const char *reason)
    459 {
    460 	if (!wpa_s || !reason)
    461 		return;
    462 
    463 	wpa_printf(
    464 	    MSG_DEBUG,
    465 	    "Notifying P2P Group formation failure to hidl control: %s",
    466 	    reason);
    467 
    468 	HidlManager *hidl_manager = HidlManager::getInstance();
    469 	if (!hidl_manager)
    470 		return;
    471 
    472 	hidl_manager->notifyP2pGroupFormationFailure(wpa_s, reason);
    473 }
    474 
    475 void wpas_hidl_notify_p2p_group_started(
    476     struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, int persistent,
    477     int client)
    478 {
    479 	if (!wpa_s || !ssid)
    480 		return;
    481 
    482 	wpa_printf(
    483 	    MSG_DEBUG, "Notifying P2P Group start to hidl control: %d",
    484 	    ssid->id);
    485 
    486 	HidlManager *hidl_manager = HidlManager::getInstance();
    487 	if (!hidl_manager)
    488 		return;
    489 
    490 	hidl_manager->notifyP2pGroupStarted(wpa_s, ssid, persistent, client);
    491 }
    492 
    493 void wpas_hidl_notify_p2p_group_removed(
    494     struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, const char *role)
    495 {
    496 	if (!wpa_s || !ssid || !role)
    497 		return;
    498 
    499 	wpa_printf(
    500 	    MSG_DEBUG, "Notifying P2P Group removed to hidl control: %d",
    501 	    ssid->id);
    502 
    503 	HidlManager *hidl_manager = HidlManager::getInstance();
    504 	if (!hidl_manager)
    505 		return;
    506 
    507 	hidl_manager->notifyP2pGroupRemoved(wpa_s, ssid, role);
    508 }
    509 
    510 void wpas_hidl_notify_p2p_invitation_received(
    511     struct wpa_supplicant *wpa_s, const u8 *sa, const u8 *go_dev_addr,
    512     const u8 *bssid, int id, int op_freq)
    513 {
    514 	if (!wpa_s || !sa || !go_dev_addr || !bssid)
    515 		return;
    516 
    517 	wpa_printf(
    518 	    MSG_DEBUG,
    519 	    "Notifying P2P invitation received to hidl control: %d " MACSTR, id,
    520 	    MAC2STR(bssid));
    521 
    522 	HidlManager *hidl_manager = HidlManager::getInstance();
    523 	if (!hidl_manager)
    524 		return;
    525 
    526 	hidl_manager->notifyP2pInvitationReceived(
    527 	    wpa_s, sa, go_dev_addr, bssid, id, op_freq);
    528 }
    529 
    530 void wpas_hidl_notify_p2p_invitation_result(
    531     struct wpa_supplicant *wpa_s, int status, const u8 *bssid)
    532 {
    533 	if (!wpa_s || !bssid)
    534 		return;
    535 
    536 	wpa_printf(
    537 	    MSG_DEBUG,
    538 	    "Notifying P2P invitation result to hidl control: " MACSTR,
    539 	    MAC2STR(bssid));
    540 
    541 	HidlManager *hidl_manager = HidlManager::getInstance();
    542 	if (!hidl_manager)
    543 		return;
    544 
    545 	hidl_manager->notifyP2pInvitationResult(wpa_s, status, bssid);
    546 }
    547 
    548 void wpas_hidl_notify_p2p_provision_discovery(
    549     struct wpa_supplicant *wpa_s, const u8 *dev_addr, int request,
    550     enum p2p_prov_disc_status status, u16 config_methods,
    551     unsigned int generated_pin)
    552 {
    553 	if (!wpa_s || !dev_addr)
    554 		return;
    555 
    556 	wpa_printf(
    557 	    MSG_DEBUG,
    558 	    "Notifying P2P provision discovery to hidl control " MACSTR,
    559 	    MAC2STR(dev_addr));
    560 
    561 	HidlManager *hidl_manager = HidlManager::getInstance();
    562 	if (!hidl_manager)
    563 		return;
    564 
    565 	hidl_manager->notifyP2pProvisionDiscovery(
    566 	    wpa_s, dev_addr, request, status, config_methods, generated_pin);
    567 }
    568 
    569 void wpas_hidl_notify_p2p_sd_response(
    570     struct wpa_supplicant *wpa_s, const u8 *sa, u16 update_indic,
    571     const u8 *tlvs, size_t tlvs_len)
    572 {
    573 	if (!wpa_s || !sa || !tlvs)
    574 		return;
    575 
    576 	wpa_printf(
    577 	    MSG_DEBUG,
    578 	    "Notifying P2P service discovery response to hidl control " MACSTR,
    579 	    MAC2STR(sa));
    580 
    581 	HidlManager *hidl_manager = HidlManager::getInstance();
    582 	if (!hidl_manager)
    583 		return;
    584 
    585 	hidl_manager->notifyP2pSdResponse(
    586 	    wpa_s, sa, update_indic, tlvs, tlvs_len);
    587 }
    588 
    589 void wpas_hidl_notify_ap_sta_authorized(
    590     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
    591 {
    592 	if (!wpa_s || !sta)
    593 		return;
    594 
    595 	wpa_printf(
    596 	    MSG_DEBUG,
    597 	    "Notifying P2P AP STA authorized to hidl control " MACSTR,
    598 	    MAC2STR(sta));
    599 
    600 	HidlManager *hidl_manager = HidlManager::getInstance();
    601 	if (!hidl_manager)
    602 		return;
    603 
    604 	hidl_manager->notifyApStaAuthorized(wpa_s, sta, p2p_dev_addr);
    605 }
    606 
    607 void wpas_hidl_notify_ap_sta_deauthorized(
    608     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
    609 {
    610 	if (!wpa_s || !sta)
    611 		return;
    612 
    613 	wpa_printf(
    614 	    MSG_DEBUG,
    615 	    "Notifying P2P AP STA deauthorized to hidl control " MACSTR,
    616 	    MAC2STR(sta));
    617 
    618 	HidlManager *hidl_manager = HidlManager::getInstance();
    619 	if (!hidl_manager)
    620 		return;
    621 
    622 	hidl_manager->notifyApStaDeauthorized(wpa_s, sta, p2p_dev_addr);
    623 }
    624