(一百零九)Android O wpa_supplicant初始化学习(三)—— hidl
前言:之前在(一百零三)Android O wpa_supplicant初始化学习(二)梳理到了wpa_supplicant_init方法,但是里面代码太多了,也不知道哪里是重点,这次凑巧梳理了其中一条关于hidl的初始化。
1.流程梳理
1.1 wpa_supplicant_init
wpa_supplicant.c
/**
* wpa_supplicant_init - Initialize %wpa_supplicant
* @params: Parameters for %wpa_supplicant
* Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
*
* This function is used to initialize %wpa_supplicant. After successful
* initialization, the returned data pointer can be used to add and remove
* network interfaces, and eventually, to deinitialize %wpa_supplicant.
*/
struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
{
struct wpa_global *global;
int ret, i;
if (params == NULL)
return NULL;
#ifdef CONFIG_DRIVER_NDIS
{
void driver_ndis_init_ops(void);
driver_ndis_init_ops();
}
#endif /* CONFIG_DRIVER_NDIS */
#ifndef CONFIG_NO_WPA_MSG
wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
#endif /* CONFIG_NO_WPA_MSG */
if (params->wpa_debug_file_path)
wpa_debug_open_file(params->wpa_debug_file_path);
else
wpa_debug_setup_stdout();
if (params->wpa_debug_syslog)
wpa_debug_open_syslog();
if (params->wpa_debug_tracing) {
ret = wpa_debug_open_linux_tracing();
if (ret) {
wpa_printf(MSG_ERROR,
"Failed to enable trace logging");
return NULL;
}
}
ret = eap_register_methods();
if (ret) {
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
if (ret == -2)
wpa_printf(MSG_ERROR, "Two or more EAP methods used "
"the same EAP type.");
return NULL;
}
global = os_zalloc(sizeof(*global));
if (global == NULL)
return NULL;
dl_list_init(&global->p2p_srv_bonjour);
dl_list_init(&global->p2p_srv_upnp);
global->params.daemonize = params->daemonize;
global->params.wait_for_monitor = params->wait_for_monitor;
global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
if (params->pid_file)
global->params.pid_file = os_strdup(params->pid_file);
if (params->ctrl_interface)
global->params.ctrl_interface =
os_strdup(params->ctrl_interface);
if (params->ctrl_interface_group)
global->params.ctrl_interface_group =
os_strdup(params->ctrl_interface_group);
if (params->override_driver)
global->params.override_driver =
os_strdup(params->override_driver);
if (params->override_ctrl_interface)
global->params.override_ctrl_interface =
os_strdup(params->override_ctrl_interface);
#ifdef CONFIG_MATCH_IFACE
global->params.match_iface_count = params->match_iface_count;
if (params->match_iface_count) {
global->params.match_ifaces =
os_calloc(params->match_iface_count,
sizeof(struct wpa_interface));
os_memcpy(global->params.match_ifaces,
params->match_ifaces,
params->match_iface_count *
sizeof(struct wpa_interface));
}
#endif /* CONFIG_MATCH_IFACE */
#ifdef CONFIG_P2P
if (params->conf_p2p_dev)
global->params.conf_p2p_dev =
os_strdup(params->conf_p2p_dev);
#endif /* CONFIG_P2P */
wpa_debug_level = global->params.wpa_debug_level =
params->wpa_debug_level;
wpa_debug_show_keys = global->params.wpa_debug_show_keys =
params->wpa_debug_show_keys;
wpa_debug_timestamp = global->params.wpa_debug_timestamp =
params->wpa_debug_timestamp;
wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR);
if (eloop_init()) {
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
wpa_supplicant_deinit(global);
return NULL;
}
random_init(params->entropy_file);
global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
if (global->ctrl_iface == NULL) {
wpa_supplicant_deinit(global);
return NULL;
}
if (wpas_notify_supplicant_initialized(global)) {
wpa_supplicant_deinit(global);
return NULL;
}
for (i = 0; wpa_drivers[i]; i++)
global->drv_count++;
if (global->drv_count == 0) {
wpa_printf(MSG_ERROR, "No drivers enabled");
wpa_supplicant_deinit(global);
return NULL;
}
global->drv_priv = os_calloc(global->drv_count, sizeof(void *));
if (global->drv_priv == NULL) {
wpa_supplicant_deinit(global);
return NULL;
}
#ifdef CONFIG_WIFI_DISPLAY
if (wifi_display_init(global) < 0) {
wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display");
wpa_supplicant_deinit(global);
return NULL;
}
#endif /* CONFIG_WIFI_DISPLAY */
eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
wpas_periodic, global, NULL);
return global;
}
其中有这么一句
if (wpas_notify_supplicant_initialized(global)) {
wpa_supplicant_deinit(global);
return NULL;
}
1.2 wpas_notify_supplicant_initialized
notify.c
int wpas_notify_supplicant_initialized(struct wpa_global *global)
{
#ifdef CONFIG_DBUS
if (global->params.dbus_ctrl_interface) {
global->dbus = wpas_dbus_init(global);
if (global->dbus == NULL)
return -1;
}
#endif /* CONFIG_DBUS */
#ifdef CONFIG_HIDL
global->hidl = wpas_hidl_init(global);
if (!global->hidl)
return -1;
#endif /* CONFIG_HIDL */
return 0;
}
1.3 wpas_hidl_init
hidl.cpp
struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global)
{
struct wpas_hidl_priv *priv;
HidlManager *hidl_manager;
priv = (wpas_hidl_priv *)os_zalloc(sizeof(*priv));
if (!priv)
return NULL;
priv->global = global;
wpa_printf(MSG_DEBUG, "Initing hidl control");
configureRpcThreadpool(1, true /* callerWillJoin */);
IPCThreadState::self()->setupPolling(&priv->hidl_fd);
if (priv->hidl_fd < 0)
goto err;
wpa_printf(MSG_INFO, "Processing hidl events on FD %d", priv->hidl_fd);
// Look for read events from the hidl socket in the eloop.
if (eloop_register_read_sock(
priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0)
goto err;
hidl_manager = HidlManager::getInstance();
if (!hidl_manager)
goto err;
hidl_manager->registerHidlService(global);
// We may not need to store this hidl manager reference in the
// global data strucure because we've made it a singleton class.
priv->hidl_manager = (void *)hidl_manager;
return priv;
err:
wpas_hidl_deinit(priv);
return NULL;
}
1.4 registerHidlService
hidl_manager.cpp
int HidlManager::registerHidlService(struct wpa_global *global)
{
// Create the main hidl service object and register it.
supplicant_object_ = new Supplicant(global);
if (supplicant_object_->registerAsService() != android::NO_ERROR) {
return 1;
}
if (!supplicant_object_->ensureConfigFileExists()) {
// If config file does not exist, we cannot start supplicant.
return 1;
}
return 0;
}
1.5 ensureConfigFileExists
supplicant.cpp
bool Supplicant::ensureConfigFileExists()
{
// To support Android P Wifi framework, make sure the config file exists.
if (copyTemplateConfigFileIfNotExists(
kStaIfaceConfPath, kTemplateConfPath) != 0) {
wpa_printf(MSG_ERROR, "Conf file does not exists: %s",
kStaIfaceConfPath);
return false;
}
// P2P configuration file is not madatory but required for some devices.
if (copyTemplateConfigFileIfNotExists(
kP2pIfaceConfPath, kTemplateConfPath) != 0) {
wpa_printf(MSG_INFO, "Conf file does not exists: %s",
kP2pIfaceConfPath);
}
return true;
}