Merge tag 'ieee802154-for-net-next-2022-12-05' of git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan-next

Stefan Schmidt says:

====================
ieee802154-next 2022-12-05

Miquel continued his work towards full scanning support. For this,
we now allow the creation of dedicated coordinator interfaces
to allow a PAN coordinator to serve in the network and set
the needed address filters with the hardware.

On top of this we have the first part to allow scanning for available
15.4 networks. A new netlink scan group, within the existing nl802154
API, was added.

In addition Miquel fixed two issues that have been introduced in the former
patches to free an skb correctly and clarifying an expression in the stack.

From David Girault we got tracing support when registering new PANs.

* tag 'ieee802154-for-net-next-2022-12-05' of git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan-next:
  mac802154: Trace the registration of new PANs
  ieee802154: Advertize coordinators discovery
  mac802154: Allow the creation of coordinator interfaces
  mac802154: Clarify an expression
  mac802154: Move an skb free within the rx path
====================

Link: https://lore.kernel.org/r/20221205131909.1871790-1-stefan@datenfreihafen.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2022-12-07 17:33:26 -08:00
commit cfbf877a33
8 changed files with 211 additions and 21 deletions

View File

@ -260,6 +260,24 @@ struct ieee802154_addr {
};
};
/**
* struct ieee802154_coord_desc - Coordinator descriptor
* @addr: PAN ID and coordinator address
* @page: page this coordinator is using
* @channel: channel this coordinator is using
* @superframe_spec: SuperFrame specification as received
* @link_quality: link quality indicator at which the beacon was received
* @gts_permit: the coordinator accepts GTS requests
*/
struct ieee802154_coord_desc {
struct ieee802154_addr addr;
u8 page;
u8 channel;
u16 superframe_spec;
u8 link_quality;
bool gts_permit;
};
struct ieee802154_llsec_key_id {
u8 mode;
u8 id;

View File

@ -72,6 +72,8 @@ enum nl802154_commands {
NL802154_CMD_NEW_SEC_LEVEL,
NL802154_CMD_DEL_SEC_LEVEL,
NL802154_CMD_SCAN_EVENT,
/* add new commands above here */
/* used to define NL802154_CMD_MAX below */
@ -131,6 +133,8 @@ enum nl802154_attrs {
NL802154_ATTR_PID,
NL802154_ATTR_NETNS_FD,
NL802154_ATTR_COORDINATOR,
/* add attributes here, update the policy in nl802154.c */
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
@ -216,6 +220,45 @@ enum nl802154_wpan_phy_capability_attr {
NL802154_CAP_ATTR_MAX = __NL802154_CAP_ATTR_AFTER_LAST - 1
};
/**
* enum nl802154_coord - Netlink attributes for a coord
*
* @__NL802154_COORD_INVALID: invalid
* @NL802154_COORD_PANID: PANID of the coordinator (2 bytes)
* @NL802154_COORD_ADDR: coordinator address, (8 bytes or 2 bytes)
* @NL802154_COORD_CHANNEL: channel number, related to @NL802154_COORD_PAGE (u8)
* @NL802154_COORD_PAGE: channel page, related to @NL802154_COORD_CHANNEL (u8)
* @NL802154_COORD_PREAMBLE_CODE: Preamble code used when the beacon was received,
* this is PHY dependent and optional (u8)
* @NL802154_COORD_MEAN_PRF: Mean PRF used when the beacon was received,
* this is PHY dependent and optional (u8)
* @NL802154_COORD_SUPERFRAME_SPEC: superframe specification of the PAN (u16)
* @NL802154_COORD_LINK_QUALITY: signal quality of beacon in unspecified units,
* scaled to 0..255 (u8)
* @NL802154_COORD_GTS_PERMIT: set to true if GTS is permitted on this PAN
* @NL802154_COORD_PAYLOAD_DATA: binary data containing the raw data from the
* frame payload, (only if beacon or probe response had data)
* @NL802154_COORD_PAD: attribute used for padding for 64-bit alignment
* @NL802154_COORD_MAX: highest coordinator attribute
*/
enum nl802154_coord {
__NL802154_COORD_INVALID,
NL802154_COORD_PANID,
NL802154_COORD_ADDR,
NL802154_COORD_CHANNEL,
NL802154_COORD_PAGE,
NL802154_COORD_PREAMBLE_CODE,
NL802154_COORD_MEAN_PRF,
NL802154_COORD_SUPERFRAME_SPEC,
NL802154_COORD_LINK_QUALITY,
NL802154_COORD_GTS_PERMIT,
NL802154_COORD_PAYLOAD_DATA,
NL802154_COORD_PAD,
/* keep last */
NL802154_COORD_MAX,
};
/**
* enum nl802154_cca_modes - cca modes
*

View File

@ -26,10 +26,12 @@ static struct genl_family nl802154_fam;
/* multicast groups */
enum nl802154_multicast_groups {
NL802154_MCGRP_CONFIG,
NL802154_MCGRP_SCAN,
};
static const struct genl_multicast_group nl802154_mcgrps[] = {
[NL802154_MCGRP_CONFIG] = { .name = "config", },
[NL802154_MCGRP_SCAN] = { .name = "scan", },
};
/* returns ERR_PTR values */
@ -216,6 +218,9 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
[NL802154_ATTR_PID] = { .type = NLA_U32 },
[NL802154_ATTR_NETNS_FD] = { .type = NLA_U32 },
[NL802154_ATTR_COORDINATOR] = { .type = NLA_NESTED },
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
[NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
[NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
@ -1281,6 +1286,104 @@ static int nl802154_wpan_phy_netns(struct sk_buff *skb, struct genl_info *info)
return err;
}
static int nl802154_prep_scan_event_msg(struct sk_buff *msg,
struct cfg802154_registered_device *rdev,
struct wpan_dev *wpan_dev,
u32 portid, u32 seq, int flags, u8 cmd,
struct ieee802154_coord_desc *desc)
{
struct nlattr *nla;
void *hdr;
hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
if (!hdr)
return -ENOBUFS;
if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx))
goto nla_put_failure;
if (wpan_dev->netdev &&
nla_put_u32(msg, NL802154_ATTR_IFINDEX, wpan_dev->netdev->ifindex))
goto nla_put_failure;
if (nla_put_u64_64bit(msg, NL802154_ATTR_WPAN_DEV,
wpan_dev_id(wpan_dev), NL802154_ATTR_PAD))
goto nla_put_failure;
nla = nla_nest_start_noflag(msg, NL802154_ATTR_COORDINATOR);
if (!nla)
goto nla_put_failure;
if (nla_put(msg, NL802154_COORD_PANID, IEEE802154_PAN_ID_LEN,
&desc->addr.pan_id))
goto nla_put_failure;
if (desc->addr.mode == IEEE802154_ADDR_SHORT) {
if (nla_put(msg, NL802154_COORD_ADDR,
IEEE802154_SHORT_ADDR_LEN,
&desc->addr.short_addr))
goto nla_put_failure;
} else {
if (nla_put(msg, NL802154_COORD_ADDR,
IEEE802154_EXTENDED_ADDR_LEN,
&desc->addr.extended_addr))
goto nla_put_failure;
}
if (nla_put_u8(msg, NL802154_COORD_CHANNEL, desc->channel))
goto nla_put_failure;
if (nla_put_u8(msg, NL802154_COORD_PAGE, desc->page))
goto nla_put_failure;
if (nla_put_u16(msg, NL802154_COORD_SUPERFRAME_SPEC,
desc->superframe_spec))
goto nla_put_failure;
if (nla_put_u8(msg, NL802154_COORD_LINK_QUALITY, desc->link_quality))
goto nla_put_failure;
if (desc->gts_permit && nla_put_flag(msg, NL802154_COORD_GTS_PERMIT))
goto nla_put_failure;
/* TODO: NL802154_COORD_PAYLOAD_DATA if any */
nla_nest_end(msg, nla);
genlmsg_end(msg, hdr);
return 0;
nla_put_failure:
genlmsg_cancel(msg, hdr);
return -EMSGSIZE;
}
int nl802154_scan_event(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
struct ieee802154_coord_desc *desc)
{
struct cfg802154_registered_device *rdev = wpan_phy_to_rdev(wpan_phy);
struct sk_buff *msg;
int ret;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
if (!msg)
return -ENOMEM;
ret = nl802154_prep_scan_event_msg(msg, rdev, wpan_dev, 0, 0, 0,
NL802154_CMD_SCAN_EVENT,
desc);
if (ret < 0) {
nlmsg_free(msg);
return ret;
}
return genlmsg_multicast_netns(&nl802154_fam, wpan_phy_net(wpan_phy),
msg, 0, NL802154_MCGRP_SCAN, GFP_ATOMIC);
}
EXPORT_SYMBOL_GPL(nl802154_scan_event);
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
[NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },

View File

@ -4,5 +4,7 @@
int nl802154_init(void);
void nl802154_exit(void);
int nl802154_scan_event(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
struct ieee802154_coord_desc *desc);
#endif /* __IEEE802154_NL802154_H */

View File

@ -254,7 +254,6 @@ ieee802154_check_concurrent_iface(struct ieee802154_sub_if_data *sdata,
enum nl802154_iftype iftype)
{
struct ieee802154_local *local = sdata->local;
struct wpan_dev *wpan_dev = &sdata->wpan_dev;
struct ieee802154_sub_if_data *nsdata;
/* we hold the RTNL here so can safely walk the list */
@ -262,13 +261,13 @@ ieee802154_check_concurrent_iface(struct ieee802154_sub_if_data *sdata,
if (nsdata != sdata && ieee802154_sdata_running(nsdata)) {
int ret;
/* TODO currently we don't support multiple node types
* we need to run skb_clone at rx path. Check if there
* exist really an use case if we need to support
* multiple node types at the same time.
/* TODO currently we don't support multiple node/coord
* types we need to run skb_clone at rx path. Check if
* there exist really an use case if we need to support
* multiple node/coord types at the same time.
*/
if (wpan_dev->iftype == NL802154_IFTYPE_NODE &&
nsdata->wpan_dev.iftype == NL802154_IFTYPE_NODE)
if (sdata->wpan_dev.iftype != NL802154_IFTYPE_MONITOR &&
nsdata->wpan_dev.iftype != NL802154_IFTYPE_MONITOR)
return -EBUSY;
/* check all phy mac sublayer settings are the same.
@ -565,6 +564,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
wpan_dev->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
switch (type) {
case NL802154_IFTYPE_COORD:
case NL802154_IFTYPE_NODE:
ieee802154_be64_to_le64(&wpan_dev->extended_addr,
sdata->dev->dev_addr);
@ -624,6 +624,7 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
ieee802154_le64_to_be64(ndev->perm_addr,
&local->hw.phy->perm_extended_addr);
switch (type) {
case NL802154_IFTYPE_COORD:
case NL802154_IFTYPE_NODE:
ndev->type = ARPHRD_IEEE802154;
if (ieee802154_is_valid_extended_unicast_addr(extended_addr)) {

View File

@ -107,7 +107,7 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
phy->supported.lbt = NL802154_SUPPORTED_BOOL_FALSE;
/* always supported */
phy->supported.iftypes = BIT(NL802154_IFTYPE_NODE);
phy->supported.iftypes = BIT(NL802154_IFTYPE_NODE) | BIT(NL802154_IFTYPE_COORD);
return &local->hw;
}

View File

@ -208,6 +208,7 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local,
int ret;
struct ieee802154_sub_if_data *sdata;
struct ieee802154_hdr hdr;
struct sk_buff *skb2;
ret = ieee802154_parse_frame_start(skb, &hdr);
if (ret) {
@ -217,7 +218,7 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local,
}
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
if (sdata->wpan_dev.iftype != NL802154_IFTYPE_NODE)
if (sdata->wpan_dev.iftype == NL802154_IFTYPE_MONITOR)
continue;
if (!ieee802154_sdata_running(sdata))
@ -230,12 +231,12 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local,
sdata->required_filtering == IEEE802154_FILTERING_4_FRAME_FIELDS)
continue;
ieee802154_subif_frame(sdata, skb, &hdr);
skb = NULL;
break;
skb2 = skb_clone(skb, GFP_ATOMIC);
if (skb2) {
skb2->dev = sdata->dev;
ieee802154_subif_frame(sdata, skb2, &hdr);
}
}
kfree_skb(skb);
}
static void
@ -274,7 +275,7 @@ void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb)
WARN_ON_ONCE(softirq_count() == 0);
if (local->suspended)
goto drop;
goto free_skb;
/* TODO: When a transceiver omits the checksum here, we
* add an own calculated one. This is currently an ugly
@ -292,20 +293,17 @@ void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb)
/* Level 1 filtering: Check the FCS by software when relevant */
if (local->hw.phy->filtering == IEEE802154_FILTERING_NONE) {
crc = crc_ccitt(0, skb->data, skb->len);
if (crc) {
rcu_read_unlock();
if (crc)
goto drop;
}
}
/* remove crc */
skb_trim(skb, skb->len - 2);
__ieee802154_rx_handle_packet(local, skb);
rcu_read_unlock();
return;
drop:
rcu_read_unlock();
free_skb:
kfree_skb(skb);
}

View File

@ -264,6 +264,31 @@ TRACE_EVENT(802154_drv_set_promiscuous_mode,
BOOL_TO_STR(__entry->on))
);
TRACE_EVENT(802154_new_scan_event,
TP_PROTO(struct ieee802154_coord_desc *desc),
TP_ARGS(desc),
TP_STRUCT__entry(
__field(__le16, pan_id)
__field(__le64, addr)
__field(u8, channel)
__field(u8, page)
),
TP_fast_assign(
__entry->page = desc->page;
__entry->channel = desc->channel;
__entry->pan_id = desc->addr.pan_id;
__entry->addr = desc->addr.extended_addr;
),
TP_printk("panid: %u, coord_addr: 0x%llx, page: %u, channel: %u",
__le16_to_cpu(__entry->pan_id), __le64_to_cpu(__entry->addr),
__entry->page, __entry->channel)
);
DEFINE_EVENT(802154_new_scan_event, 802154_scan_event,
TP_PROTO(struct ieee802154_coord_desc *desc),
TP_ARGS(desc)
);
#endif /* !__MAC802154_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
#undef TRACE_INCLUDE_PATH