diff mbox

[08/20] driver: nl80211: handle creation of P2P device interface

Message ID 1368710915-32176-9-git-send-email-arend@broadcom.com
State Changes Requested
Headers show

Commit Message

Arend van Spriel May 16, 2013, 1:28 p.m. UTC
Add specific handler for creating the P2P device to store the
wdev_id as this type of interface does not have an interface
index.

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

Comments

Peer, Ilan May 19, 2013, 6:15 p.m. UTC | #1
> -----Original Message-----
> From: hostap-bounces@lists.shmoo.com [mailto:hostap-
> bounces@lists.shmoo.com] On Behalf Of Arend van Spriel
> Sent: Thursday, May 16, 2013 16:28
> To: Jouni Malinen
> Cc: hostap@lists.shmoo.com
> Subject: [PATCH 08/20] driver: nl80211: handle creation of P2P device interface
> 
> Add specific handler for creating the P2P device to store the wdev_id as this
> type of interface does not have an interface index.
> 
> Signed-hostap: Arend van Spriel <arend@broadcom.com>
> ---
>  src/drivers/driver_nl80211.c |   57
> ++++++++++++++++++++++++++++++++++++------
>  1 file changed, 50 insertions(+), 7 deletions(-)
> 
> diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index
> f185f71..92b8882 100644
> --- a/src/drivers/driver_nl80211.c
> +++ b/src/drivers/driver_nl80211.c
> @@ -4592,10 +4592,15 @@ static int wpa_driver_nl80211_set_key(const char
> *ifname, struct i802_bss *bss,
>  				      const u8 *key, size_t key_len)  {
>  	struct wpa_driver_nl80211_data *drv = bss->drv;
> -	int ifindex = if_nametoindex(ifname);
> +	int ifindex;
>  	struct nl_msg *msg;
>  	int ret;
> 
> +	/* ignore for P2P Device */
> +	if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
> +		return 0;
> +
> +	ifindex = if_nametoindex(ifname);
>  	wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d
> "
>  		   "set_tx=%d seq_len=%lu key_len=%lu",
>  		   __func__, ifindex, alg, addr, key_idx, set_tx, @@ -8584,6
> +8589,24 @@ static int nl80211_p2p_interface_addr(struct
> wpa_driver_nl80211_data *drv,
> 
>  #endif /* CONFIG_P2P */
> 
> +static int nl80211_create_p2p_dev_handler(struct nl_msg *msg, void
> +*arg) {

Can't we simply have this for all the interfaces types? Is there something wrong we having to keep wdev in all cases?

> +	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
> +	struct nlattr *tb[NL80211_ATTR_MAX + 1];
> +	struct i802_bss *p2p_dev = arg;
> +
> +	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
> +			genlmsg_attrlen(gnlh, 0), NULL);
> +	if (tb[NL80211_ATTR_WDEV])
> +		p2p_dev->wdev_id =
> +			nla_get_u64(tb[NL80211_ATTR_WDEV]);
> +
> +	if (tb[NL80211_ATTR_MAC])
> +		os_memcpy(p2p_dev->addr,
> +			  nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN);
> +
> +	return NL_SKIP;
> +}
> 
>  static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type
> type,
>  				     const char *ifname, const u8 *addr, @@ -
> 8591,7 +8614,9 @@ static int wpa_driver_nl80211_if_add(void *priv, enum
> wpa_driver_if_type type,
>  				     char *force_ifname, u8 *if_addr,
>  				     const char *bridge)
>  {
> +	enum nl80211_iftype nlmode;
>  	struct i802_bss *bss = priv;
> +	struct i802_bss *p2pdev;
>  	struct wpa_driver_nl80211_data *drv = bss->drv;
>  	int ifidx;
>  #ifdef HOSTAPD
> @@ -8606,14 +8631,32 @@ static int wpa_driver_nl80211_if_add(void *priv,
> enum wpa_driver_if_type type,
> 
>  	if (addr)
>  		os_memcpy(if_addr, addr, ETH_ALEN);
> -	ifidx = nl80211_create_iface(drv, ifname,
> -				     wpa_driver_nl80211_if_type(type), addr,
> -				     0, NULL, NULL);
> -	if (ifidx < 0) {
> +	nlmode = wpa_driver_nl80211_if_type(type);
> +	if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
> +		p2pdev = os_zalloc(sizeof(*p2pdev));
> +		if (!p2pdev)
> +			return -1;
> +		*p2pdev = *bss;
> +		os_strncpy(p2pdev->ifname, ifname, IFNAMSIZ);
> +		ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
> +					     0,
> nl80211_create_p2p_dev_handler,
> +					     p2pdev);
> +		if (p2pdev->wdev_id == -1 || ifidx != 0 ||
> +		    is_zero_ether_addr((const u8 *)&p2pdev->addr)) {
> +			wpa_printf(MSG_ERROR, "nl80211: Failed to create a
> p2p device"
> +					" interface %s", ifname);
> +			os_free(p2pdev);
> +			return -1;
> +		}
> +	} else {
> +		ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
> +					     0, NULL, NULL);
> +		if (ifidx < 0) {
>  #ifdef HOSTAPD
> -		os_free(new_bss);
> +			os_free(new_bss);
>  #endif /* HOSTAPD */
> -		return -1;
> +			return -1;
> +		}
>  	}
> 
>  	if (!addr &&
> --
> 1.7.10.4
> 
> 
> _______________________________________________
> HostAP mailing list
> HostAP@lists.shmoo.com
> http://lists.shmoo.com/mailman/listinfo/hostap
diff mbox

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index f185f71..92b8882 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -4592,10 +4592,15 @@  static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
 				      const u8 *key, size_t key_len)
 {
 	struct wpa_driver_nl80211_data *drv = bss->drv;
-	int ifindex = if_nametoindex(ifname);
+	int ifindex;
 	struct nl_msg *msg;
 	int ret;
 
+	/* ignore for P2P Device */
+	if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
+		return 0;
+
+	ifindex = if_nametoindex(ifname);
 	wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
 		   "set_tx=%d seq_len=%lu key_len=%lu",
 		   __func__, ifindex, alg, addr, key_idx, set_tx,
@@ -8584,6 +8589,24 @@  static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv,
 
 #endif /* CONFIG_P2P */
 
+static int nl80211_create_p2p_dev_handler(struct nl_msg *msg, void *arg)
+{
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	struct nlattr *tb[NL80211_ATTR_MAX + 1];
+	struct i802_bss *p2p_dev = arg;
+
+	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+			genlmsg_attrlen(gnlh, 0), NULL);
+	if (tb[NL80211_ATTR_WDEV])
+		p2p_dev->wdev_id =
+			nla_get_u64(tb[NL80211_ATTR_WDEV]);
+
+	if (tb[NL80211_ATTR_MAC])
+		os_memcpy(p2p_dev->addr,
+			  nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN);
+
+	return NL_SKIP;
+}
 
 static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
 				     const char *ifname, const u8 *addr,
@@ -8591,7 +8614,9 @@  static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
 				     char *force_ifname, u8 *if_addr,
 				     const char *bridge)
 {
+	enum nl80211_iftype nlmode;
 	struct i802_bss *bss = priv;
+	struct i802_bss *p2pdev;
 	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ifidx;
 #ifdef HOSTAPD
@@ -8606,14 +8631,32 @@  static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
 
 	if (addr)
 		os_memcpy(if_addr, addr, ETH_ALEN);
-	ifidx = nl80211_create_iface(drv, ifname,
-				     wpa_driver_nl80211_if_type(type), addr,
-				     0, NULL, NULL);
-	if (ifidx < 0) {
+	nlmode = wpa_driver_nl80211_if_type(type);
+	if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
+		p2pdev = os_zalloc(sizeof(*p2pdev));
+		if (!p2pdev)
+			return -1;
+		*p2pdev = *bss;
+		os_strncpy(p2pdev->ifname, ifname, IFNAMSIZ);
+		ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
+					     0, nl80211_create_p2p_dev_handler,
+					     p2pdev);
+		if (p2pdev->wdev_id == -1 || ifidx != 0 ||
+		    is_zero_ether_addr((const u8 *)&p2pdev->addr)) {
+			wpa_printf(MSG_ERROR, "nl80211: Failed to create a p2p device"
+					" interface %s", ifname);
+			os_free(p2pdev);
+			return -1;
+		}
+	} else {
+		ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
+					     0, NULL, NULL);
+		if (ifidx < 0) {
 #ifdef HOSTAPD
-		os_free(new_bss);
+			os_free(new_bss);
 #endif /* HOSTAPD */
-		return -1;
+			return -1;
+		}
 	}
 
 	if (!addr &&