mirror of
https://github.com/torvalds/linux.git
synced 2024-12-23 19:31:53 +00:00
ieee802154: Add support for user disassociation requests
A device may decide at some point to disassociate from a PAN, let's introduce a netlink command for this purpose. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Stefan Schmidt <stefan@datenfreihafen.org> Acked-by: Alexander Aring <aahringo@redhat.com> Link: https://lore.kernel.org/linux-wpan/20230927181214.129346-6-miquel.raynal@bootlin.com
This commit is contained in:
parent
fefd19807f
commit
7b18313e84
@ -81,6 +81,9 @@ struct cfg802154_ops {
|
||||
int (*associate)(struct wpan_phy *wpan_phy,
|
||||
struct wpan_dev *wpan_dev,
|
||||
struct ieee802154_addr *coord);
|
||||
int (*disassociate)(struct wpan_phy *wpan_phy,
|
||||
struct wpan_dev *wpan_dev,
|
||||
struct ieee802154_addr *target);
|
||||
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
|
||||
void (*get_llsec_table)(struct wpan_phy *wpan_phy,
|
||||
struct wpan_dev *wpan_dev,
|
||||
|
@ -177,6 +177,11 @@ enum ieee802154_association_status {
|
||||
IEEE802154_FAST_ASSOCIATION_SUCCESSFUL = 0x80,
|
||||
};
|
||||
|
||||
enum ieee802154_disassociation_reason {
|
||||
IEEE802154_COORD_WISHES_DEVICE_TO_LEAVE = 0x1,
|
||||
IEEE802154_DEVICE_WISHES_TO_LEAVE = 0x2,
|
||||
};
|
||||
|
||||
struct ieee802154_hdr {
|
||||
struct ieee802154_hdr_fc fc;
|
||||
u8 seq;
|
||||
@ -206,6 +211,12 @@ struct ieee802154_association_req_frame {
|
||||
struct ieee802154_assoc_req_pl assoc_req_pl;
|
||||
};
|
||||
|
||||
struct ieee802154_disassociation_notif_frame {
|
||||
struct ieee802154_hdr mhr;
|
||||
struct ieee802154_mac_cmd_pl mac_pl;
|
||||
u8 disassoc_pl;
|
||||
};
|
||||
|
||||
/* pushes hdr onto the skb. fields of hdr->fc that can be calculated from
|
||||
* the contents of hdr will be, and the actual value of those bits in
|
||||
* hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
|
||||
|
@ -79,6 +79,7 @@ enum nl802154_commands {
|
||||
NL802154_CMD_SEND_BEACONS,
|
||||
NL802154_CMD_STOP_BEACONS,
|
||||
NL802154_CMD_ASSOCIATE,
|
||||
NL802154_CMD_DISASSOCIATE,
|
||||
|
||||
/* add new commands above here */
|
||||
|
||||
|
@ -1663,6 +1663,39 @@ static int nl802154_associate(struct sk_buff *skb, struct genl_info *info)
|
||||
return err;
|
||||
}
|
||||
|
||||
static int nl802154_disassociate(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct cfg802154_registered_device *rdev = info->user_ptr[0];
|
||||
struct net_device *dev = info->user_ptr[1];
|
||||
struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
|
||||
struct wpan_phy *wpan_phy = &rdev->wpan_phy;
|
||||
struct ieee802154_addr target;
|
||||
|
||||
if (wpan_phy->flags & WPAN_PHY_FLAG_DATAGRAMS_ONLY) {
|
||||
NL_SET_ERR_MSG(info->extack, "PHY only supports datagrams");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
target.pan_id = wpan_dev->pan_id;
|
||||
|
||||
if (info->attrs[NL802154_ATTR_EXTENDED_ADDR]) {
|
||||
target.mode = IEEE802154_ADDR_LONG;
|
||||
target.extended_addr = nla_get_le64(info->attrs[NL802154_ATTR_EXTENDED_ADDR]);
|
||||
} else if (info->attrs[NL802154_ATTR_SHORT_ADDR]) {
|
||||
target.mode = IEEE802154_ADDR_SHORT;
|
||||
target.short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
|
||||
} else {
|
||||
NL_SET_ERR_MSG(info->extack, "Device address is missing");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&wpan_dev->association_lock);
|
||||
rdev_disassociate(rdev, wpan_dev, &target);
|
||||
mutex_unlock(&wpan_dev->association_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#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 },
|
||||
@ -2792,6 +2825,14 @@ static const struct genl_ops nl802154_ops[] = {
|
||||
NL802154_FLAG_CHECK_NETDEV_UP |
|
||||
NL802154_FLAG_NEED_RTNL,
|
||||
},
|
||||
{
|
||||
.cmd = NL802154_CMD_DISASSOCIATE,
|
||||
.doit = nl802154_disassociate,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
.internal_flags = NL802154_FLAG_NEED_NETDEV |
|
||||
NL802154_FLAG_CHECK_NETDEV_UP |
|
||||
NL802154_FLAG_NEED_RTNL,
|
||||
},
|
||||
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
|
||||
{
|
||||
.cmd = NL802154_CMD_SET_SEC_PARAMS,
|
||||
|
@ -280,6 +280,21 @@ static inline int rdev_associate(struct cfg802154_registered_device *rdev,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int rdev_disassociate(struct cfg802154_registered_device *rdev,
|
||||
struct wpan_dev *wpan_dev,
|
||||
struct ieee802154_addr *target)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!rdev->ops->disassociate)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
trace_802154_rdev_disassociate(&rdev->wpan_phy, wpan_dev, target);
|
||||
ret = rdev->ops->disassociate(&rdev->wpan_phy, wpan_dev, target);
|
||||
trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
|
||||
/* TODO this is already a nl802154, so move into ieee802154 */
|
||||
static inline void
|
||||
|
@ -375,6 +375,25 @@ TRACE_EVENT(802154_rdev_associate,
|
||||
WPAN_PHY_PR_ARG, WPAN_DEV_PR_ARG, __entry->addr)
|
||||
);
|
||||
|
||||
TRACE_EVENT(802154_rdev_disassociate,
|
||||
TP_PROTO(struct wpan_phy *wpan_phy,
|
||||
struct wpan_dev *wpan_dev,
|
||||
struct ieee802154_addr *target),
|
||||
TP_ARGS(wpan_phy, wpan_dev, target),
|
||||
TP_STRUCT__entry(
|
||||
WPAN_PHY_ENTRY
|
||||
WPAN_DEV_ENTRY
|
||||
__field(__le64, addr)
|
||||
),
|
||||
TP_fast_assign(
|
||||
WPAN_PHY_ASSIGN;
|
||||
WPAN_DEV_ASSIGN;
|
||||
__entry->addr = target->extended_addr;
|
||||
),
|
||||
TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT ", disassociating with: 0x%llx",
|
||||
WPAN_PHY_PR_ARG, WPAN_DEV_PR_ARG, __entry->addr)
|
||||
);
|
||||
|
||||
TRACE_EVENT(802154_rdev_return_int,
|
||||
TP_PROTO(struct wpan_phy *wpan_phy, int ret),
|
||||
TP_ARGS(wpan_phy, ret),
|
||||
|
Loading…
Reference in New Issue
Block a user