Skip to content

Commit

Permalink
ieee802154: Convert scan error messages to extack
Browse files Browse the repository at this point in the history
Instead of printing error messages in the kernel log, let's use extack.
When there is a netlink error returned that could be further specified
with a string, use extack as well.

Apply this logic to the very recent scan/beacon infrastructure.

Fixes: ed3557c ("ieee802154: Add support for user scanning requests")
Fixes: 9bc1145 ("ieee802154: Add support for user beaconing requests")
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230214135035.1202471-3-miquel.raynal@bootlin.com
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
  • Loading branch information
Miquel Raynal authored and Stefan Schmidt committed Feb 18, 2023
1 parent 648324c commit a0b6106
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions net/ieee802154/nl802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,15 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
u8 type;
int err;

/* Monitors are not allowed to perform scans */
if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR)
if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR) {
NL_SET_ERR_MSG(info->extack, "Monitors are not allowed to perform scans");
return -EPERM;
}

if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
return -EINVAL;
}

request = kzalloc(sizeof(*request), GFP_KERNEL);
if (!request)
Expand All @@ -1424,7 +1430,7 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
request->type = type;
break;
default:
pr_err("Unsupported scan type: %d\n", type);
NL_SET_ERR_MSG_FMT(info->extack, "Unsupported scan type: %d", type);
err = -EINVAL;
goto free_request;
}
Expand Down Expand Up @@ -1576,12 +1582,13 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info)
struct cfg802154_beacon_request *request;
int err;

/* Only coordinators can send beacons */
if (wpan_dev->iftype != NL802154_IFTYPE_COORD)
if (wpan_dev->iftype != NL802154_IFTYPE_COORD) {
NL_SET_ERR_MSG(info->extack, "Only coordinators can send beacons");
return -EOPNOTSUPP;
}

if (wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
pr_err("Device is not part of any PAN\n");
NL_SET_ERR_MSG(info->extack, "Device is not part of any PAN");
return -EPERM;
}

Expand Down

0 comments on commit a0b6106

Please sign in to comment.