diff --git a/hostapd/main.c b/hostapd/main.c index d5a0fd775..99c137dd3 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -257,10 +257,22 @@ static int hostapd_driver_init(struct hostapd_iface *iface) os_memset(¶ms, 0, sizeof(params)); for (i = 0; wpa_drivers[i]; i++) { - if (wpa_drivers[i] == hapd->driver) { - params.global_priv = global.drv_priv[i]; - break; + if (wpa_drivers[i] != hapd->driver) + continue; + + if (global.drv_priv[i] == NULL && + wpa_drivers[i]->global_init) { + global.drv_priv[i] = wpa_drivers[i]->global_init(); + if (global.drv_priv[i] == NULL) { + wpa_printf(MSG_ERROR, "Failed to initialize " + "driver '%s'", + wpa_drivers[i]->name); + return -1; + } } + + params.global_priv = global.drv_priv[i]; + break; } params.bssid = b; params.ifname = hapd->conf->iface; @@ -425,16 +437,6 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces, global.drv_priv = os_zalloc(global.drv_count * sizeof(void *)); if (global.drv_priv == NULL) return -1; - for (i = 0; wpa_drivers[i]; i++) { - if (!wpa_drivers[i]->global_init) - continue; - global.drv_priv[i] = wpa_drivers[i]->global_init(); - if (global.drv_priv[i] == NULL) { - wpa_printf(MSG_ERROR, "Failed to initialize driver " - "'%s'", wpa_drivers[i]->name); - return -1; - } - } return 0; } diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 62a82bd26..e49b0a5c2 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -1867,6 +1867,26 @@ struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s) } +static int select_driver(struct wpa_supplicant *wpa_s, int i) +{ + struct wpa_global *global = wpa_s->global; + + if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) { + global->drv_priv[i] = wpa_drivers[i]->global_init(); + if (global->drv_priv[i] == NULL) { + wpa_printf(MSG_ERROR, "Failed to initialize driver " + "'%s'", wpa_drivers[i]->name); + return -1; + } + } + + wpa_s->driver = wpa_drivers[i]; + wpa_s->global_drv_priv = global->drv_priv[i]; + + return 0; +} + + static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, const char *name) { @@ -1885,9 +1905,7 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, if (name == NULL) { /* default to first driver in the list */ - wpa_s->driver = wpa_drivers[0]; - wpa_s->global_drv_priv = wpa_s->global->drv_priv[0]; - return 0; + return select_driver(wpa_s, 0); } do { @@ -1900,12 +1918,8 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, for (i = 0; wpa_drivers[i]; i++) { if (os_strlen(wpa_drivers[i]->name) == len && os_strncmp(driver, wpa_drivers[i]->name, len) == - 0) { - wpa_s->driver = wpa_drivers[i]; - wpa_s->global_drv_priv = - wpa_s->global->drv_priv[i]; - return 0; - } + 0) + return select_driver(wpa_s, i); } driver = pos + 1; @@ -2625,17 +2639,6 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params) wpa_supplicant_deinit(global); return NULL; } - for (i = 0; wpa_drivers[i]; i++) { - if (!wpa_drivers[i]->global_init) - continue; - global->drv_priv[i] = wpa_drivers[i]->global_init(); - if (global->drv_priv[i] == NULL) { - wpa_printf(MSG_ERROR, "Failed to initialize driver " - "'%s'", wpa_drivers[i]->name); - wpa_supplicant_deinit(global); - return NULL; - } - } return global; }