[PATCH] wpa_s: p2p: rework creation order of P2P Device interface
Arend van Spriel
arend
Thu May 16 13:27:48 PDT 2013
Create the P2P Device in main interface creation loop when
the added interface flags support and P2P supplicant is not
yet initialized avoiding recursion of add_interface.
Signed-hostap: Arend van Spriel <arend at broadcom.com>
---
Hi Jouni,
One more patch to clean up P2P device creation and restore
function interfaces of driver_init and update_mac_addr.
Regards,
Arend
---
wpa_supplicant/events.c | 4 ++--
wpa_supplicant/main.c | 15 +++++++++++++--
wpa_supplicant/p2p_supplicant.h | 1 +
wpa_supplicant/wpa_supplicant.c | 30 ++++++++++++++++--------------
wpa_supplicant/wpa_supplicant_i.h | 6 ++++--
5 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 6728fd3..463c8e6 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -2168,7 +2168,7 @@ wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
break;
wpa_s->interface_removed = 0;
wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
- if (wpa_supplicant_driver_init(wpa_s, 1) < 0) {
+ if (wpa_supplicant_driver_init(wpa_s) < 0) {
wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
"driver after interface was added");
}
@@ -2909,7 +2909,7 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
case EVENT_INTERFACE_ENABLED:
wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
- wpa_supplicant_update_mac_addr(wpa_s, 1);
+ wpa_supplicant_update_mac_addr(wpa_s);
#ifdef CONFIG_AP
if (!wpa_s->ap_iface) {
wpa_supplicant_set_state(wpa_s,
diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c
index f45c1b7..8eb93e5 100644
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -14,6 +14,7 @@
#include "common.h"
#include "wpa_supplicant_i.h"
#include "driver_i.h"
+#include "p2p_supplicant.h"
extern struct wpa_driver_ops *wpa_drivers[];
@@ -262,7 +263,7 @@ int main(int argc, char *argv[])
if (iface == NULL)
goto out;
ifaces = iface;
- iface = &ifaces[iface_count - 1];
+ iface = &ifaces[iface_count - 1];
os_memset(iface, 0, sizeof(*iface));
break;
default:
@@ -284,6 +285,8 @@ int main(int argc, char *argv[])
}
for (i = 0; exitcode == 0 && i < iface_count; i++) {
+ struct wpa_supplicant *wpa_s;
+
if ((ifaces[i].confname == NULL &&
ifaces[i].ctrl_interface == NULL) ||
ifaces[i].ifname == NULL) {
@@ -294,8 +297,16 @@ int main(int argc, char *argv[])
exitcode = -1;
break;
}
- if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
+ wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]);
+ if (wpa_s == NULL) {
exitcode = -1;
+ break;
+ }
+ if (wpa_s->global->p2p == NULL &&
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
+ if (wpas_p2p_add_p2pdev_interface(wpa_s) < 0)
+ exitcode = -1;
+ }
}
if (exitcode == 0)
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 2157cae..a7fadc0 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -14,6 +14,7 @@ struct p2p_go_neg_results;
enum p2p_send_action_result;
struct p2p_peer_info;
struct p2p_channels;
+struct wps_event_fail;
int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s);
void wpas_p2p_deinit(struct wpa_supplicant *wpa_s);
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 170d613..6a0b236 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -2316,14 +2316,14 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
}
-int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s, int l2_needed)
+int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
{
if (wpa_s->driver->send_eapol) {
const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
if (addr)
os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
- } else if (l2_needed && !(wpa_s->drv_flags &
- WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) {
+ } else if (!wpa_s->p2p_mgmt &&
+ !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) {
l2_packet_deinit(wpa_s->l2);
wpa_s->l2 = l2_packet_init(wpa_s->ifname,
wpa_drv_get_mac_addr(wpa_s),
@@ -2374,18 +2374,17 @@ static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr,
/**
* wpa_supplicant_driver_init - Initialize driver interface parameters
* @wpa_s: Pointer to wpa_supplicant data
- * @l2_needed: need call l2_packet_init() for this interface
* Returns: 0 on success, -1 on failure
*
* This function is called to initialize driver interface parameters.
* wpa_drv_init() must have been called before this function to initialize the
* driver interface.
*/
-int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s, int l2_needed)
+int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
{
static int interface_count = 0;
- if (wpa_supplicant_update_mac_addr(wpa_s, l2_needed) < 0)
+ if (wpa_supplicant_update_mac_addr(wpa_s) < 0)
return -1;
wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR,
@@ -2955,7 +2954,16 @@ next_driver:
if (wpa_s->max_remain_on_chan == 0)
wpa_s->max_remain_on_chan = 1000;
- if (wpa_supplicant_driver_init(wpa_s, !iface->p2p_mgmt) < 0)
+ /* only take p2p_mgmt parameters when P2P Device is supported.
+ * doing it here as it determines whether l2_packet_init()
+ * will be done during wpa_supplicant_driver_init().
+ */
+ if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
+ wpa_s->p2p_mgmt = iface->p2p_mgmt;
+ else
+ iface->p2p_mgmt = 1;
+
+ if (wpa_supplicant_driver_init(wpa_s) < 0)
return -1;
#ifdef CONFIG_TDLS
@@ -2997,13 +3005,7 @@ next_driver:
}
#ifdef CONFIG_P2P
- if (iface->p2p_mgmt == 0 && wpa_s->global->p2p == NULL &&
- (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
- if (wpas_p2p_add_p2pdev_interface(wpa_s) < 0) {
- wpa_msg(wpa_s, MSG_ERROR, "Failed to create P2P Device");
- return -1;
- }
- } else if (wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
+ if (iface->p2p_mgmt && wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
return -1;
}
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index eac9b8f..de5fcd9 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -568,6 +568,8 @@ struct wpa_supplicant {
unsigned int roc_waiting_drv_freq;
int action_tx_wait_time;
+ int p2p_mgmt;
+
#ifdef CONFIG_P2P
struct p2p_go_neg_results *go_params;
int create_p2p_iface;
@@ -715,8 +717,8 @@ int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
const char * wpa_supplicant_state_txt(enum wpa_states state);
-int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s, int l2_needed);
-int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s, int l2_needed);
+int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s);
+int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);
int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss, struct wpa_ssid *ssid,
u8 *wpa_ie, size_t *wpa_ie_len);
--
1.7.10.4
More information about the Hostap
mailing list