lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 16 Sep 2023 17:36:33 +0200
From: Stefan Schmidt <stefan@...enfreihafen.org>
To: Miquel Raynal <miquel.raynal@...tlin.com>,
 Alexander Aring <alex.aring@...il.com>, linux-wpan@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>, Jakub Kicinski
 <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
 Eric Dumazet <edumazet@...gle.com>, netdev@...r.kernel.org,
 David Girault <david.girault@...vo.com>,
 Romuald Despres <romuald.despres@...vo.com>,
 Frederic Blain <frederic.blain@...vo.com>,
 Nicolas Schodet <nico@...fr.eu.org>,
 Guilhem Imberton <guilhem.imberton@...vo.com>,
 Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH wpan-next v2 07/11] mac802154: Handle association requests
 from peers

Hello Miquel

On 01.09.23 19:04, Miquel Raynal wrote:
> Coordinators may have to handle association requests from peers which
> want to join the PAN. The logic involves:
> - Acknowledging the request (done by hardware)
> - If requested, a random short address that is free on this PAN should
>    be chosen for the device.
> - Sending an association response with the short address allocated for
>    the peer and expecting it to be ack'ed.
> 
> If anything fails during this procedure, the peer is considered not
> associated.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@...tlin.com>
> ---
>   include/net/cfg802154.h         |   7 ++
>   include/net/ieee802154_netdev.h |   6 ++
>   net/ieee802154/core.c           |   7 ++
>   net/ieee802154/pan.c            |  30 +++++++
>   net/mac802154/ieee802154_i.h    |   2 +
>   net/mac802154/rx.c              |   8 ++
>   net/mac802154/scan.c            | 147 ++++++++++++++++++++++++++++++++
>   7 files changed, 207 insertions(+)
> 
> diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> index c79ff560f400..20ccc8f5da87 100644
> --- a/include/net/cfg802154.h
> +++ b/include/net/cfg802154.h
> @@ -583,4 +583,11 @@ struct ieee802154_pan_device *
>   cfg802154_device_is_child(struct wpan_dev *wpan_dev,
>   			  struct ieee802154_addr *target);
>   
> +/**
> + * cfg802154_get_free_short_addr - Get a free address among the known devices
> + * @wpan_dev: the wpan device
> + * @return: a random short address expectedly unused on our PAN
> + */
> +__le16 cfg802154_get_free_short_addr(struct wpan_dev *wpan_dev);
> +
>   #endif /* __NET_CFG802154_H */
> diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h
> index 16194356cfe7..4de858f9929e 100644
> --- a/include/net/ieee802154_netdev.h
> +++ b/include/net/ieee802154_netdev.h
> @@ -211,6 +211,12 @@ struct ieee802154_association_req_frame {
>   	struct ieee802154_assoc_req_pl assoc_req_pl;
>   };
>   
> +struct ieee802154_association_resp_frame {
> +	struct ieee802154_hdr mhr;
> +	struct ieee802154_mac_cmd_pl mac_pl;
> +	struct ieee802154_assoc_resp_pl assoc_resp_pl;
> +};
> +
>   struct ieee802154_disassociation_notif_frame {
>   	struct ieee802154_hdr mhr;
>   	struct ieee802154_mac_cmd_pl mac_pl;
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index be958727ccdf..790965018118 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -200,11 +200,18 @@ EXPORT_SYMBOL(wpan_phy_free);
>   
>   static void cfg802154_free_peer_structures(struct wpan_dev *wpan_dev)
>   {
> +	struct ieee802154_pan_device *child, *tmp;
> +
>   	mutex_lock(&wpan_dev->association_lock);
>   
>   	kfree(wpan_dev->parent);
>   	wpan_dev->parent = NULL;
>   
> +	list_for_each_entry_safe(child, tmp, &wpan_dev->children, node) {
> +		list_del(&child->node);
> +		kfree(child);
> +	}
> +
>   	wpan_dev->association_generation++;
>   
>   	mutex_unlock(&wpan_dev->association_lock);
> diff --git a/net/ieee802154/pan.c b/net/ieee802154/pan.c
> index 477e8dad0cf0..364abb89d156 100644
> --- a/net/ieee802154/pan.c
> +++ b/net/ieee802154/pan.c
> @@ -66,3 +66,33 @@ cfg802154_device_is_child(struct wpan_dev *wpan_dev,
>   	return NULL;
>   }
>   EXPORT_SYMBOL_GPL(cfg802154_device_is_child);
> +
> +__le16 cfg802154_get_free_short_addr(struct wpan_dev *wpan_dev)
> +{
> +	struct ieee802154_pan_device *child;
> +	__le16 addr;
> +
> +	lockdep_assert_held(&wpan_dev->association_lock);
> +
> +	do {
> +		get_random_bytes(&addr, 2);
> +		if (addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST) ||
> +		    addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC))
> +			continue;
> +
> +		if (wpan_dev->short_addr == addr)
> +			continue;
> +
> +		if (wpan_dev->parent && wpan_dev->parent->short_addr == addr)
> +			continue;
> +
> +		list_for_each_entry(child, &wpan_dev->children, node)
> +			if (child->short_addr == addr)
> +				continue;
> +
> +		break;
> +	} while (1);
> +
> +	return addr;
> +}
> +EXPORT_SYMBOL_GPL(cfg802154_get_free_short_addr);
> diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
> index 92252f86c69c..432bfa87249e 100644
> --- a/net/mac802154/ieee802154_i.h
> +++ b/net/mac802154/ieee802154_i.h
> @@ -318,6 +318,8 @@ static inline bool mac802154_is_associating(struct ieee802154_local *local)
>   int mac802154_send_disassociation_notif(struct ieee802154_sub_if_data *sdata,
>   					struct ieee802154_pan_device *target,
>   					u8 reason);
> +int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
> +				      struct sk_buff *skb);
>   
>   /* interface handling */
>   int ieee802154_iface_init(void);
> diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c
> index d0e08613a36b..96040b63a4fc 100644
> --- a/net/mac802154/rx.c
> +++ b/net/mac802154/rx.c
> @@ -102,6 +102,14 @@ void mac802154_rx_mac_cmd_worker(struct work_struct *work)
>   		mac802154_process_association_resp(mac_pkt->sdata, mac_pkt->skb);
>   		break;
>   
> +	case IEEE802154_CMD_ASSOCIATION_REQ:
> +		dev_dbg(&mac_pkt->sdata->dev->dev, "processing ASSOC REQ\n");
> +		if (mac_pkt->sdata->wpan_dev.iftype != NL802154_IFTYPE_COORD)
> +			break;
> +
> +		mac802154_process_association_req(mac_pkt->sdata, mac_pkt->skb);
> +		break;
> +
>   	default:
>   		break;
>   	}
> diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
> index e2f2e1235ec6..9f55b2314fe5 100644
> --- a/net/mac802154/scan.c
> +++ b/net/mac802154/scan.c
> @@ -697,3 +697,150 @@ int mac802154_send_disassociation_notif(struct ieee802154_sub_if_data *sdata,
>   	dev_dbg(&sdata->dev->dev, "DISASSOC ACK received from %8phC\n", &teaddr);
>   	return 0;
>   }
> +
> +static int
> +mac802154_send_association_resp_locked(struct ieee802154_sub_if_data *sdata,
> +				       struct ieee802154_pan_device *target,
> +				       struct ieee802154_assoc_resp_pl *assoc_resp_pl)
> +{
> +	u64 teaddr = swab64((__force u64)target->extended_addr);
> +	struct ieee802154_association_resp_frame frame = {};
> +	struct ieee802154_local *local = sdata->local;
> +	struct wpan_dev *wpan_dev = &sdata->wpan_dev;
> +	struct sk_buff *skb;
> +	int ret;
> +
> +	frame.mhr.fc.type = IEEE802154_FC_TYPE_MAC_CMD;
> +	frame.mhr.fc.security_enabled = 0;
> +	frame.mhr.fc.frame_pending = 0;
> +	frame.mhr.fc.ack_request = 1; /* We always expect an ack here */
> +	frame.mhr.fc.intra_pan = 1;
> +	frame.mhr.fc.dest_addr_mode = IEEE802154_EXTENDED_ADDRESSING;
> +	frame.mhr.fc.version = IEEE802154_2003_STD;
> +	frame.mhr.fc.source_addr_mode = IEEE802154_EXTENDED_ADDRESSING;
> +	frame.mhr.seq = 10;

Where does the 10 come from and what is the meaning?

regards
Stefan Schmidt

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ