Patchwork [12/20] driver: nl80211: remove P2P Device interface upon .deinit()

login
register
mail settings
Submitter Arend van Spriel
Date May 16, 2013, 1:28 p.m.
Message ID <1368710915-32176-13-git-send-email-arend@broadcom.com>
Download mbox | patch
Permalink /patch/244313/
State Changes Requested
Headers show

Comments

Arend van Spriel - May 16, 2013, 1:28 p.m.
The .deinit() closes netlink for P2P Device. Before doing that
remove the P2P Device interface that was created by wpa_s.

Signed-hostap: Arend van Spriel <arend@broadcom.com>
---
 src/drivers/driver_nl80211.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index afdb098..a8d288f 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -3735,25 +3735,51 @@  static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
 	wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
 }
 
-static int nl80211_start_p2pdev(struct i802_bss *bss)
+static void nl80211_del_p2pdev(struct i802_bss *bss)
 {
 	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
-	int ret = -1;
+	int ret;
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		return;
 
-	wpa_printf(MSG_DEBUG, "nl80211: start p2p device %s (%" PRIx64 ")",
-		   bss->ifname, bss->wdev_id);
+	nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE);
+	NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
+
+	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
+	msg = NULL;
+
+	wpa_printf(MSG_DEBUG, "nl80211: delete p2p device %s (%" PRIx64 "): %s",
+		   bss->ifname, bss->wdev_id, strerror(ret));
+nla_put_failure:
+	nlmsg_free(msg);
+	return;
+}
+
+static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
+{
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+	struct nl_msg *msg;
+	int ret = -1;
 
 	msg = nlmsg_alloc();
 	if (!msg)
 		return -1;
 
-	nl80211_cmd(drv, msg, 0, NL80211_CMD_START_P2P_DEVICE);
+	if (start)
+		nl80211_cmd(drv, msg, 0, NL80211_CMD_START_P2P_DEVICE);
+	else
+		nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_P2P_DEVICE);
 	NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
 
 	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
 	msg = NULL;
 
+	wpa_printf(MSG_DEBUG, "nl80211: %s p2p device %s (%" PRIx64 "): %s",
+		   start ? "start" : "stop", bss->ifname, bss->wdev_id,
+		   strerror(ret));
 nla_put_failure:
 	nlmsg_free(msg);
 	return ret;
@@ -3819,7 +3845,7 @@  wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
 		return -1;
 
 	if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
-		int ret = nl80211_start_p2pdev(bss);
+		int ret = nl80211_set_p2pdev(bss, 1);
 		if (ret < 0)
 			wpa_printf(MSG_ERROR, "nl80211: could not start P2P device");
 		return ret;
@@ -3942,7 +3968,8 @@  static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
 	(void)i802_set_iface_flags(bss, 0);
 	wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION);
 	nl80211_mgmt_unsubscribe(bss, "deinit");
-
+	if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE)
+		nl80211_del_p2pdev(bss);
 	nl_cb_put(drv->nl_cb);
 
 	nl80211_destroy_bss(&drv->first_bss);