From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Alexander Aring <alex.aring@gmail.com>,
Stefan Schmidt <stefan@datenfreihafen.org>,
linux-wpan@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>,
netdev@vger.kernel.org, David Girault <david.girault@qorvo.com>,
Romuald Despres <romuald.despres@qorvo.com>,
Frederic Blain <frederic.blain@qorvo.com>,
Nicolas Schodet <nico@ni.fr.eu.org>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH wpan-next 03/20] net: ieee802154: Handle coordinators discovery
Date: Fri, 1 Jul 2022 16:30:35 +0200 [thread overview]
Message-ID: <20220701143052.1267509-4-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20220701143052.1267509-1-miquel.raynal@bootlin.com>
Let's introduce helpers for giving the MAC layer a generic interface for
advertising discovered coordinators/PANs upon beacon reception. This
support requires the MAC layers to:
- Allocate a coordinator/PAN descriptor and fill it.
- Register this structure, giving the generic ieee802154 layer the
necessary information about the coordinator/PAN the beacon originates
from.
- To flush all the allocated structures once the scan is done.
The generic layer keeps a temporary list of the discovered coordinators
to avoid spamming the user with identical information. So only new
discoveries are forwarded to the user through netlink messages (already
implemented).
Co-developed-by: David Girault <david.girault@qorvo.com>
Signed-off-by: David Girault <david.girault@qorvo.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
include/net/cfg802154.h | 11 ++++
net/ieee802154/Makefile | 2 +-
net/ieee802154/core.c | 2 +
net/ieee802154/nl802154.c | 2 +
net/ieee802154/pan.c | 112 ++++++++++++++++++++++++++++++++++++++
5 files changed, 128 insertions(+), 1 deletion(-)
create mode 100644 net/ieee802154/pan.c
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 1f1b275dcabd..895948b433de 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -398,6 +398,10 @@ struct wpan_dev {
/* fallback for acknowledgment bit setting */
bool ackreq;
+
+ /* Coordinators management during scans */
+ spinlock_t coord_list_lock;
+ struct list_head coord_list;
};
#define to_phy(_dev) container_of(_dev, struct wpan_phy, dev)
@@ -446,4 +450,11 @@ static inline const char *wpan_phy_name(struct wpan_phy *phy)
void ieee802154_configure_durations(struct wpan_phy *phy);
+struct ieee802154_coord_desc *
+cfg802154_alloc_coordinator(struct ieee802154_addr *coord);
+void cfg802154_record_coordinator(struct wpan_phy *wpan_phy,
+ struct wpan_dev *wpan_dev,
+ struct ieee802154_coord_desc *desc);
+void cfg802154_flush_known_coordinators(struct wpan_dev *wpan_dev);
+
#endif /* __NET_CFG802154_H */
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index f05b7bdae2aa..6b7c66de730d 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -4,7 +4,7 @@ obj-$(CONFIG_IEEE802154_SOCKET) += ieee802154_socket.o
obj-y += 6lowpan/
ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \
- header_ops.o sysfs.o nl802154.o trace.o
+ header_ops.o sysfs.o nl802154.o pan.o trace.o
ieee802154_socket-y := socket.o
CFLAGS_trace.o := -I$(src)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 57546e07e06a..091eb467fde6 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -276,6 +276,8 @@ static int cfg802154_netdev_notifier_call(struct notifier_block *nb,
wpan_dev->identifier = ++rdev->wpan_dev_id;
list_add_rcu(&wpan_dev->list, &rdev->wpan_dev_list);
rdev->devlist_generation++;
+ spin_lock_init(&wpan_dev->coord_list_lock);
+ INIT_LIST_HEAD(&wpan_dev->coord_list);
wpan_dev->netdev = dev;
break;
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 7c0aec10ef7f..8598767c0c0a 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -1368,6 +1368,8 @@ int nl802154_advertise_new_coordinator(struct wpan_phy *wpan_phy,
struct sk_buff *msg;
int ret;
+ lockdep_assert(&wpan_dev->coord_list_lock);
+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
if (!msg)
return -ENOMEM;
diff --git a/net/ieee802154/pan.c b/net/ieee802154/pan.c
new file mode 100644
index 000000000000..134a13ff0a87
--- /dev/null
+++ b/net/ieee802154/pan.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * IEEE 802.15.4 PAN management
+ *
+ * Copyright (C) Qorvo, 2021
+ * Authors:
+ * - David Girault <david.girault@qorvo.com>
+ * - Miquel Raynal <miquel.raynal@bootlin.com>
+ */
+
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+
+#include <net/cfg802154.h>
+#include <net/af_ieee802154.h>
+
+#include "ieee802154.h"
+#include "../ieee802154/nl802154.h"
+
+struct ieee802154_coord_desc *
+cfg802154_alloc_coordinator(struct ieee802154_addr *coord)
+{
+ struct ieee802154_coord_desc *desc;
+
+ desc = kzalloc(sizeof(*desc), GFP_ATOMIC);
+ if (!desc)
+ return ERR_PTR(-ENOMEM);
+
+ desc->addr = kzalloc(sizeof(*coord), GFP_ATOMIC);
+ if (!desc->addr) {
+ kfree(desc);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ memcpy(desc->addr, coord, sizeof(*coord));
+
+ return desc;
+}
+EXPORT_SYMBOL_GPL(cfg802154_alloc_coordinator);
+
+static void cfg802154_free_coordinator_desc(struct ieee802154_coord_desc *desc)
+{
+ kfree(desc->addr);
+ kfree(desc);
+}
+
+static bool
+cfg802154_is_same_coordinator(struct ieee802154_coord_desc *a,
+ struct ieee802154_coord_desc *b)
+{
+ if (a->addr->pan_id != b->addr->pan_id)
+ return false;
+
+ if (a->addr->mode != b->addr->mode)
+ return false;
+
+ if (a->addr->mode == IEEE802154_ADDR_SHORT &&
+ a->addr->short_addr == b->addr->short_addr)
+ return true;
+ else if (a->addr->mode == IEEE802154_ADDR_LONG &&
+ a->addr->extended_addr == b->addr->extended_addr)
+ return true;
+
+ return false;
+}
+
+static bool
+cfg802154_coordinator_is_known(struct wpan_dev *wpan_dev,
+ struct ieee802154_coord_desc *desc)
+{
+ struct ieee802154_coord_desc *item;
+
+ list_for_each_entry(item, &wpan_dev->coord_list, node)
+ if (cfg802154_is_same_coordinator(item, desc))
+ return true;
+
+ return false;
+}
+
+void cfg802154_record_coordinator(struct wpan_phy *wpan_phy,
+ struct wpan_dev *wpan_dev,
+ struct ieee802154_coord_desc *desc)
+{
+ spin_lock_bh(&wpan_dev->coord_list_lock);
+
+ if (cfg802154_coordinator_is_known(wpan_dev, desc)) {
+ cfg802154_free_coordinator_desc(desc);
+ } else {
+ list_add_tail(&desc->node, &wpan_dev->coord_list);
+ nl802154_advertise_new_coordinator(wpan_phy, wpan_dev, desc);
+ }
+
+ spin_unlock_bh(&wpan_dev->coord_list_lock);
+}
+EXPORT_SYMBOL_GPL(cfg802154_record_coordinator);
+
+void cfg802154_flush_known_coordinators(struct wpan_dev *wpan_dev)
+{
+ struct ieee802154_coord_desc *desc, *tmp;
+
+ spin_lock_bh(&wpan_dev->coord_list_lock);
+
+ list_for_each_entry_safe(desc, tmp, &wpan_dev->coord_list, node) {
+ list_del(&desc->node);
+ cfg802154_free_coordinator_desc(desc);
+ }
+
+ spin_unlock_bh(&wpan_dev->coord_list_lock);
+}
+EXPORT_SYMBOL_GPL(cfg802154_flush_known_coordinators);
--
2.34.1
next prev parent reply other threads:[~2022-07-01 14:35 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-01 14:30 [PATCH wpan-next 00/20] net: ieee802154: Support scanning/beaconing Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 01/20] net: mac802154: Allow the creation of coordinator interfaces Miquel Raynal
2022-07-06 1:51 ` Alexander Aring
2022-08-19 17:11 ` Miquel Raynal
2022-08-23 12:33 ` Alexander Aring
2022-08-23 16:29 ` Miquel Raynal
2022-08-23 21:44 ` Alexander Aring
2022-08-24 7:35 ` Miquel Raynal
2022-08-24 21:43 ` Alexander Aring
2022-08-25 8:40 ` Miquel Raynal
2022-08-26 0:51 ` Alexander Aring
2022-08-26 1:35 ` Alexander Aring
2022-08-26 8:08 ` Miquel Raynal
2022-08-29 2:31 ` Alexander Aring
2022-08-29 8:05 ` Miquel Raynal
2022-08-26 7:30 ` Miquel Raynal
2022-08-24 10:20 ` Miquel Raynal
2022-08-24 12:43 ` Alexander Aring
2022-08-24 13:26 ` Miquel Raynal
2022-08-24 21:53 ` Alexander Aring
2022-08-25 1:02 ` Alexander Aring
2022-08-25 8:46 ` Miquel Raynal
2022-08-25 12:58 ` Miquel Raynal
2022-08-26 1:05 ` Alexander Aring
2022-08-26 7:54 ` Miquel Raynal
2022-08-29 2:52 ` Alexander Aring
2022-08-29 8:02 ` Miquel Raynal
2022-08-30 2:23 ` Alexander Aring
2022-08-31 15:39 ` Miquel Raynal
2022-09-01 0:09 ` Miquel Raynal
2022-09-01 13:09 ` Miquel Raynal
2022-09-02 2:38 ` Alexander Aring
2022-09-03 0:08 ` Miquel Raynal
2022-09-03 14:20 ` Alexander Aring
2022-09-03 14:31 ` Alexander Aring
2022-09-03 16:05 ` Miquel Raynal
2022-09-03 18:21 ` Alexander Aring
2022-09-03 18:29 ` Alexander Aring
2022-09-03 19:07 ` Alexander Aring
2022-09-03 19:10 ` Alexander Aring
2022-09-03 19:40 ` Alexander Aring
2022-09-05 3:16 ` Miquel Raynal
2022-09-05 22:35 ` Alexander Aring
2022-09-02 2:23 ` Alexander Aring
2022-09-02 2:39 ` Alexander Aring
2022-09-02 2:09 ` Alexander Aring
2022-07-01 14:30 ` [PATCH wpan-next 02/20] net: ieee802154: Advertize coordinators discovery Miquel Raynal
2022-07-01 14:30 ` Miquel Raynal [this message]
2022-07-01 14:30 ` [PATCH wpan-next 04/20] net: ieee802154: Trace the registration of new PANs Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 05/20] net: ieee802154: Define frame types Miquel Raynal
2022-07-11 2:06 ` Alexander Aring
2022-08-19 17:13 ` Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 06/20] net: ieee802154: Add support for user scanning requests Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 07/20] net: ieee802154: Define a beacon frame header Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 08/20] net: mac802154: Prepare forcing specific symbol duration Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 09/20] net: mac802154: Introduce a global device lock Miquel Raynal
2022-07-04 1:12 ` Alexander Aring
2022-08-19 17:06 ` Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 10/20] net: mac802154: Handle passive scanning Miquel Raynal
2022-07-15 3:33 ` Alexander Aring
2022-07-15 3:42 ` Alexander Aring
2022-08-19 17:22 ` Miquel Raynal
2022-08-01 23:42 ` Alexander Aring
2022-08-01 23:54 ` Alexander Aring
2022-07-01 14:30 ` [PATCH wpan-next 11/20] net: ieee802154: Add support for user beaconing requests Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 12/20] net: mac802154: Handle basic beaconing Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 13/20] net: ieee802154: Add support for user active scan requests Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 14/20] net: mac802154: Handle active scanning Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 15/20] net: ieee802154: Add support for allowing to answer BEACON_REQ Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 16/20] net: mac802154: Handle received BEACON_REQ Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 17/20] net: ieee802154: Handle limited devices with only datagram support Miquel Raynal
2022-07-15 3:16 ` Alexander Aring
2022-08-19 17:13 ` Miquel Raynal
2022-08-23 12:43 ` Alexander Aring
2022-07-01 14:30 ` [PATCH wpan-next 18/20] ieee802154: ca8210: Flag the driver as being limited Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 19/20] ieee802154: hwsim: Do not check the rtnl Miquel Raynal
2022-07-06 1:23 ` Alexander Aring
2022-08-01 23:58 ` Alexander Aring
2022-08-19 17:09 ` Miquel Raynal
2022-08-25 22:41 ` Miquel Raynal
2022-07-01 14:30 ` [PATCH wpan-next 20/20] ieee802154: hwsim: Allow devices to be coordinators Miquel Raynal
2022-07-11 2:01 ` Alexander Aring
2022-08-19 17:12 ` Miquel Raynal
2022-07-04 1:17 ` [PATCH wpan-next 00/20] net: ieee802154: Support scanning/beaconing Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220701143052.1267509-4-miquel.raynal@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=david.girault@qorvo.com \
--cc=edumazet@google.com \
--cc=frederic.blain@qorvo.com \
--cc=kuba@kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nico@ni.fr.eu.org \
--cc=pabeni@redhat.com \
--cc=romuald.despres@qorvo.com \
--cc=stefan@datenfreihafen.org \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).