Add NL80211_CMD_NAN_NDP_INITIATE to let userspace initiate a NAN Data Path session when NDP management is offloaded to the device. Validate that the initiator NDI exists locally, pass key material by pointer, and apply the NAN security requirements to cipher suite, PMK, PMKID, and GTK. Let the initiator provide transport port and protocol information for its service in the NDPE Service Info TLV. It can also request a preferred NDL channel or require that the device include it. The device chooses the bandwidth and reports setup failure if it cannot use a forced channel. Let the driver assign the NDP ID and return it in the command reply. Clear the request skb after handling it because it may contain PMK data. Trace the non-secret request parameters without recording PMK or PMKID bytes. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 66 +++++++++ include/uapi/linux/nl80211.h | 110 +++++++++++++++ net/wireless/nl80211.c | 263 +++++++++++++++++++++++++++++++++++ net/wireless/rdev-ops.h | 16 +++ net/wireless/trace.h | 94 +++++++++++++ 5 files changed, 549 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 60152bc5aa9a..eb753c83722e 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -4341,6 +4341,60 @@ struct cfg80211_nan_peer_sched { struct cfg80211_nan_peer_map maps[CFG80211_NAN_MAX_PEER_MAPS]; }; +/** + * struct cfg80211_nan_ndp_initiate - NAN NDP initiate parameters + * + * @peer_nmi: peer NMI address + * @publish_id: publisher's service instance ID + * @service_id: NAN service ID (%NL80211_NAN_FUNC_SERVICE_ID_LEN bytes) + * @init_ndi: initiator NDI MAC address. The corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist. + * @ssi: service-specific info (may be NULL) + * @ssi_len: length of @ssi + * @cipher_suite: NAN cipher suite ID, 0 for open NDP + * @pmk: ND-PMK used to derive the PTK; NULL if absent. Its length depends on + * the cipher suite and is given by @pmk_len. Requires non-zero + * @cipher_suite and %NL80211_EXT_FEATURE_SECURE_NAN. + * @pmk_len: length of @pmk in bytes + * @pmkid: PMKID (16 octets) to include in the NDP Request, or NULL if absent + * @gtk_required: if true, GTK protection is required for group-addressed data + * frames + * @gtk_cipher: GTK cipher suite ID, valid when @gtk_required is true + * @ipv6_intf_id: IPv6 link-local interface identifier, or NULL if absent + * @ndp_id: output NDP ID assigned by the driver on success (1-255) + * @transport_info: if true, convey @transport_port and @transport_protocol to + * the peer in the NDPE Service Info TLV (Generic Service Protocol). These + * values are not conveyed if the peer does not support NDPE. + * @transport_port: transport port to convey when @transport_info is true + * @transport_protocol: IANA protocol number to convey when @transport_info is + * true + * @chan: preferred channel for the NDL, or NULL when the device chooses the + * channels + * @chan_forced: if true, @chan must be included in the NDL; valid only when + * @chan is non-NULL + */ +struct cfg80211_nan_ndp_initiate { + const u8 *peer_nmi; + u8 publish_id; + u8 service_id[NL80211_NAN_FUNC_SERVICE_ID_LEN]; + const u8 *init_ndi; + const u8 *ssi; + u8 ssi_len; + u32 cipher_suite; + const u8 *pmk; + u8 pmk_len; + const u8 *pmkid; + bool gtk_required; + u32 gtk_cipher; + const u8 *ipv6_intf_id; + u8 ndp_id; + bool transport_info; + u16 transport_port; + u8 transport_protocol; + struct ieee80211_channel *chan; + bool chan_forced; +}; + /** * enum cfg80211_nan_conf_changes - indicates changed fields in NAN * configuration @@ -5322,6 +5376,15 @@ struct mgmt_frame_regs { * supported when %WIPHY_NAN_FLAGS_OFFLOAD_NDP is set; the device manages * channel evacuation. * + * @nan_ndp_initiate: Initiate a NAN Data Path session as the initiator. + * Only valid if the driver has set %WIPHY_NAN_FLAGS_OFFLOAD_NDP. + * The driver must set params->ndp_id to the assigned NDP ID (1-255) on + * success. Each accepted setup attempt completes asynchronously with one + * status notification, including on failure or timeout. If the parameters + * specify a channel, drivers advertising NDP offload must honor it as a + * channel preference. If the channel is forced and cannot be included in the + * NDL, the driver must fail the request. + * * @set_multicast_to_unicast: configure multicast to unicast conversion for BSS * * @get_txq_stats: Get TXQ stats for interface or phy. If wdev is %NULL, this @@ -5729,6 +5792,9 @@ struct cfg80211_ops { int (*nan_set_non_evac_channels)(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_nan_non_evac_channels *channels); + int (*nan_ndp_initiate)(struct wiphy *wiphy, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params); int (*set_multicast_to_unicast)(struct wiphy *wiphy, struct net_device *dev, const bool enabled); diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 3406e37df5c4..d6b601556248 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1484,6 +1484,26 @@ * and multiple can be nested in %NL80211_ATTR_MLO_LINKS but then the * update isn't atomic if any failures happen. * Only supported with %NL80211_EXT_FEATURE_UPDATE_BEACON. + * + * @NL80211_CMD_NAN_NDP_INITIATE: Initiate NAN Data Path (NDP) setup + * as the initiator. Requires %NL80211_NAN_CAPA_OFFLOAD_NDP, + * %NL80211_ATTR_MAC (peer NMI), and %NL80211_ATTR_NAN_NDP. The NDI + * interface specified in %NL80211_NAN_NDP_ATTR_INIT_NDI must already + * exist as a %NL80211_IFTYPE_NAN_DATA interface. For a locally + * initiated NDP, the driver assigns the NDP ID and returns it in the + * %NL80211_ATTR_NAN_NDP reply. + * %NL80211_NAN_NDP_ATTR_TRANSPORT_PORT and + * %NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL may be supplied together to + * include transport information in the NDPE Service Info TLV. + * Without %NL80211_NAN_NDP_ATTR_CHANNEL_FREQ, the device chooses the + * channels of the NDL. A supplied channel frequency is a preference unless + * %NL80211_NAN_NDP_ATTR_CHANNEL_FORCED is also present; the device may then + * use other channels. With %NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, the device + * must include the requested channel in the NDL or fail setup, reporting the + * failure with %NL80211_CMD_NAN_NDP_STATUS. The device chooses the bandwidth. + * Each accepted setup attempt completes asynchronously with exactly one + * %NL80211_CMD_NAN_NDP_STATUS notification, including on failure or timeout. + * * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */ @@ -1766,6 +1786,8 @@ enum nl80211_commands { NL80211_CMD_UPDATE_BEACON, + NL80211_CMD_NAN_NDP_INITIATE, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -3260,6 +3282,9 @@ enum nl80211_commands { * @NL80211_ATTR_ASSOC_PROTECTED_TWT: Enable protected TWT for the association, * requires protected TWT support (flag attribute) * + * @NL80211_ATTR_NAN_NDP: nested attribute carrying NAN Data Path parameters. + * See &enum nl80211_nan_ndp_attributes. + * * @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use @@ -3867,6 +3892,8 @@ enum nl80211_attrs { NL80211_ATTR_ASSOC_PROTECTED_TWT, + NL80211_ATTR_NAN_NDP, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, @@ -8024,6 +8051,89 @@ enum nl80211_nan_conf_attributes { NL80211_NAN_CONF_ATTR_MAX = NUM_NL80211_NAN_CONF_ATTR - 1, }; +#define NL80211_NAN_NDP_IPV6_INTF_ID_LEN 8 + +/** + * enum nl80211_nan_ndp_attributes - NAN Data Path attributes + * + * Nested attributes used within %NL80211_ATTR_NAN_NDP for NDP setup commands + * and events. + * + * @__NL80211_NAN_NDP_ATTR_INVALID: Invalid. + * @NL80211_NAN_NDP_ATTR_ID: u8 NDP ID (1-255), assigned by the NDP initiator. + * For locally initiated NDPs the driver assigns it and returns it in the + * %NL80211_CMD_NAN_NDP_INITIATE reply; do not include it in that request. + * @NL80211_NAN_NDP_ATTR_PUBLISH_ID: u8 publisher's service instance ID, used + * to match the NDP to a service. + * @NL80211_NAN_NDP_ATTR_SERVICE_ID: binary NAN service ID derived from the + * service name, %NL80211_NAN_FUNC_SERVICE_ID_LEN bytes. + * @NL80211_NAN_NDP_ATTR_INIT_NDI: ETH_ALEN-byte initiator NDI MAC address. + * For locally initiated NDPs, the corresponding + * %NL80211_IFTYPE_NAN_DATA interface must exist. + * @NL80211_NAN_NDP_ATTR_RESP_NDI: ETH_ALEN-byte responder NDI MAC address. + * @NL80211_NAN_NDP_ATTR_SSI: binary. Service-specific info carried in + * the NDP setup frames. + * @NL80211_NAN_NDP_ATTR_CIPHER_SUITE: u32 NAN cipher suite ID; 0 for open NDP. + * See the Wi-Fi Aware Specification for values. + * @NL80211_NAN_NDP_ATTR_PMK: binary ND-PMK used to derive the PTK; its length + * depends on the cipher suite. Requires non-zero + * @NL80211_NAN_NDP_ATTR_CIPHER_SUITE and %NL80211_EXT_FEATURE_SECURE_NAN. + * @NL80211_NAN_NDP_ATTR_PMKID: 16-octet PMKID. In + * %NL80211_CMD_NAN_NDP_INITIATE requests it identifies the PMK and is + * included in the SCIA of the NDP Request. In a peer-request notification, + * it carries the PMKID received in the peer's SCIA for cached-PMK lookup. + * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED: flag indicating that GTK protection is + * required for group-addressed data frames. Requires + * @NL80211_NAN_NDP_ATTR_GTK_CIPHER; IGTK and BIGTK are not covered. + * @NL80211_NAN_NDP_ATTR_GTK_CIPHER: u32 GTK cipher suite ID. Required if + * @NL80211_NAN_NDP_ATTR_GTK_REQUIRED is set. + * @NL80211_NAN_NDP_ATTR_IPV6_INTF_ID: binary IPv6 link-local interface + * identifier, %NL80211_NAN_NDP_IPV6_INTF_ID_LEN bytes. The driver conveys it + * in the NDPE attribute and selects NDP or NDPE based on peer capabilities. + * @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT: u16 transport port. Must be supplied + * with @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL. The driver carries the pair + * in the NDPE Service Info TLV (Generic Service Protocol). If the peer does + * not support NDPE, the values are not conveyed. + * @NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL: u8 IANA protocol number. Must be + * supplied with @NL80211_NAN_NDP_ATTR_TRANSPORT_PORT. + * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ: optional u32 channel frequency in MHz. + * Valid only with %NL80211_CMD_NAN_NDP_INITIATE. When supplied without + * @NL80211_NAN_NDP_ATTR_CHANNEL_FORCED it is a preference, and the device + * may use other channels for the NDL. Without this attribute, the device + * chooses the NDL channels. The device chooses the channel bandwidth. + * @NL80211_NAN_NDP_ATTR_CHANNEL_FORCED: optional flag valid only with + * %NL80211_CMD_NAN_NDP_INITIATE and + * @NL80211_NAN_NDP_ATTR_CHANNEL_FREQ. The requested channel must be included + * in the NDL. If it cannot be used, for example because it is incompatible + * with peer availability, setup fails. + * @__NL80211_NAN_NDP_ATTR_LAST: Internal. + * @NL80211_NAN_NDP_ATTR_MAX: Highest NDP attribute. + */ +enum nl80211_nan_ndp_attributes { + __NL80211_NAN_NDP_ATTR_INVALID, + + NL80211_NAN_NDP_ATTR_ID, + NL80211_NAN_NDP_ATTR_PUBLISH_ID, + NL80211_NAN_NDP_ATTR_SERVICE_ID, + NL80211_NAN_NDP_ATTR_INIT_NDI, + NL80211_NAN_NDP_ATTR_RESP_NDI, + NL80211_NAN_NDP_ATTR_SSI, + NL80211_NAN_NDP_ATTR_CIPHER_SUITE, + NL80211_NAN_NDP_ATTR_PMK, + NL80211_NAN_NDP_ATTR_PMKID, + NL80211_NAN_NDP_ATTR_GTK_REQUIRED, + NL80211_NAN_NDP_ATTR_GTK_CIPHER, + NL80211_NAN_NDP_ATTR_IPV6_INTF_ID, + NL80211_NAN_NDP_ATTR_TRANSPORT_PORT, + NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL, + NL80211_NAN_NDP_ATTR_CHANNEL_FREQ, + NL80211_NAN_NDP_ATTR_CHANNEL_FORCED, + + /* keep last */ + __NL80211_NAN_NDP_ATTR_LAST, + NL80211_NAN_NDP_ATTR_MAX = __NL80211_NAN_NDP_ATTR_LAST - 1, +}; + /** * enum nl80211_external_auth_action - Action to perform with external * authentication request. Used by NL80211_ATTR_EXTERNAL_AUTH_ACTION. diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 4bcb62a0172f..fb1190a60748 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -800,6 +800,34 @@ nl80211_nan_peer_map_policy[NL80211_NAN_PEER_MAP_ATTR_MAX + 1] = { NLA_POLICY_EXACT_LEN(CFG80211_NAN_SCHED_NUM_TIME_SLOTS), }; +static const struct nla_policy +nl80211_nan_ndp_policy[NL80211_NAN_NDP_ATTR_MAX + 1] = { + [NL80211_NAN_NDP_ATTR_ID] = NLA_POLICY_RANGE(NLA_U8, 1, 255), + [NL80211_NAN_NDP_ATTR_PUBLISH_ID] = { .type = NLA_U8 }, + [NL80211_NAN_NDP_ATTR_SERVICE_ID] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_FUNC_SERVICE_ID_LEN), + [NL80211_NAN_NDP_ATTR_INIT_NDI] = NLA_POLICY_EXACT_LEN(ETH_ALEN), + [NL80211_NAN_NDP_ATTR_RESP_NDI] = NLA_POLICY_EXACT_LEN(ETH_ALEN), + [NL80211_NAN_NDP_ATTR_SSI] = { + .type = NLA_BINARY, + .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN + }, + [NL80211_NAN_NDP_ATTR_CIPHER_SUITE] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_PMK] = + NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_nan_pmk, + WLAN_PMK_LEN_SUITE_B_192), + [NL80211_NAN_NDP_ATTR_PMKID] = + NLA_POLICY_EXACT_LEN(WLAN_PMKID_LEN), + [NL80211_NAN_NDP_ATTR_GTK_REQUIRED] = { .type = NLA_FLAG }, + [NL80211_NAN_NDP_ATTR_GTK_CIPHER] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_IPV6_INTF_ID] = + NLA_POLICY_EXACT_LEN(NL80211_NAN_NDP_IPV6_INTF_ID_LEN), + [NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] = { .type = NLA_U16 }, + [NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL] = { .type = NLA_U8 }, + [NL80211_NAN_NDP_ATTR_CHANNEL_FREQ] = { .type = NLA_U32 }, + [NL80211_NAN_NDP_ATTR_CHANNEL_FORCED] = { .type = NLA_FLAG }, +}; + static const struct nla_policy nl80211_nan_conf_policy[NL80211_NAN_CONF_ATTR_MAX + 1] = { [NL80211_NAN_CONF_CLUSTER_ID] = @@ -1226,6 +1254,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { [NL80211_ATTR_NAN_MAX_CHAN_SWITCH_TIME] = { .type = NLA_U16 }, [NL80211_ATTR_NAN_PEER_MAPS] = NLA_POLICY_NESTED_ARRAY(nl80211_nan_peer_map_policy), + [NL80211_ATTR_NAN_NDP] = NLA_POLICY_NESTED(nl80211_nan_ndp_policy), [NL80211_ATTR_NPCA_PRIMARY_FREQ] = { .type = NLA_U32 }, [NL80211_ATTR_NPCA_PUNCT_BITMAP] = NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range), @@ -18495,6 +18524,233 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb, return rdev_nan_set_peer_sched(rdev, wdev, &sched); } +static bool nl80211_nan_ndi_exists(struct cfg80211_registered_device *rdev, + const u8 *addr) +{ + struct wireless_dev *wdev; + + lockdep_assert_wiphy(&rdev->wiphy); + + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { + if (wdev->iftype == NL80211_IFTYPE_NAN_DATA && + ether_addr_equal(wdev_address(wdev), addr)) + return true; + } + + return false; +} + +static int nl80211_nan_ndp_initiate(struct sk_buff *skb, + struct genl_info *info) +{ + struct cfg80211_registered_device *rdev = info->user_ptr[0]; + struct wireless_dev *wdev = info->user_ptr[1]; + struct nlattr *tb[NL80211_NAN_NDP_ATTR_MAX + 1], *ndp_attr; + struct cfg80211_nan_ndp_initiate params = {}; + struct sk_buff *msg; + void *hdr; + bool secure_nan; + int err; + + if (wdev->iftype != NL80211_IFTYPE_NAN) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires NAN interface"); + return -EOPNOTSUPP; + } + + if (!(rdev->wiphy.nan_capa.flags & WIPHY_NAN_FLAGS_OFFLOAD_NDP)) { + NL_SET_ERR_MSG(info->extack, + "NAN NDP offload not supported by driver"); + return -EOPNOTSUPP; + } + + if (!info->attrs[NL80211_ATTR_MAC] || + !info->attrs[NL80211_ATTR_NAN_NDP]) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires peer NMI and NDP params"); + return -EINVAL; + } + + err = nla_parse_nested(tb, NL80211_NAN_NDP_ATTR_MAX, + info->attrs[NL80211_ATTR_NAN_NDP], + nl80211_nan_ndp_policy, + info->extack); + if (err) + return err; + + if (!!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT] != + !!tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]) { + NL_SET_ERR_MSG(info->extack, + "Transport port and protocol must be supplied together"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED] && + !tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED], + "CHANNEL_FORCED requires CHANNEL_FREQ"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_ID]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_ID], + "NDP ID is assigned by the driver"); + return -EINVAL; + } + + if (!tb[NL80211_NAN_NDP_ATTR_INIT_NDI] || + !tb[NL80211_NAN_NDP_ATTR_PUBLISH_ID] || + !tb[NL80211_NAN_NDP_ATTR_SERVICE_ID]) { + NL_SET_ERR_MSG(info->extack, + "NDP initiate requires INIT_NDI, PUBLISH_ID and SERVICE_ID"); + return -EINVAL; + } + + if (!nl80211_nan_ndi_exists(rdev, + nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_INIT_NDI], + "INIT_NDI must identify an existing NAN Data interface"); + return -ENODEV; + } + + params.peer_nmi = nla_data(info->attrs[NL80211_ATTR_MAC]); + params.init_ndi = nla_data(tb[NL80211_NAN_NDP_ATTR_INIT_NDI]); + params.publish_id = nla_get_u8(tb[NL80211_NAN_NDP_ATTR_PUBLISH_ID]); + memcpy(params.service_id, + nla_data(tb[NL80211_NAN_NDP_ATTR_SERVICE_ID]), + NL80211_NAN_FUNC_SERVICE_ID_LEN); + if (tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]) { + params.transport_info = true; + params.transport_port = + nla_get_u16(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PORT]); + params.transport_protocol = + nla_get_u8(tb[NL80211_NAN_NDP_ATTR_TRANSPORT_PROTOCOL]); + } + + if (tb[NL80211_NAN_NDP_ATTR_SSI]) { + params.ssi = nla_data(tb[NL80211_NAN_NDP_ATTR_SSI]); + params.ssi_len = nla_len(tb[NL80211_NAN_NDP_ATTR_SSI]); + } + + if (tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]) + params.cipher_suite = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE]); + + secure_nan = wiphy_ext_feature_isset(&rdev->wiphy, + NL80211_EXT_FEATURE_SECURE_NAN); + if (params.cipher_suite && !secure_nan) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CIPHER_SUITE], + "NDP cipher suite requires SECURE_NAN"); + return -EOPNOTSUPP; + } + + if (tb[NL80211_NAN_NDP_ATTR_PMK] || + tb[NL80211_NAN_NDP_ATTR_PMKID] || + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!secure_nan || !params.cipher_suite) { + NL_SET_ERR_MSG(info->extack, + "PMK, PMKID, and GTK require SECURE_NAN and a non-zero cipher suite"); + return -EINVAL; + } + } + + if (tb[NL80211_NAN_NDP_ATTR_PMK]) { + params.pmk = nla_data(tb[NL80211_NAN_NDP_ATTR_PMK]); + params.pmk_len = nla_len(tb[NL80211_NAN_NDP_ATTR_PMK]); + } + + if (tb[NL80211_NAN_NDP_ATTR_PMKID]) + params.pmkid = nla_data(tb[NL80211_NAN_NDP_ATTR_PMKID]); + + if (tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED]) { + if (!tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_REQUIRED], + "GTK_CIPHER is required when GTK_REQUIRED is set"); + return -EINVAL; + } + + params.gtk_required = true; + params.gtk_cipher = + nla_get_u32(tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]); + } else if (tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER]) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_GTK_CIPHER], + "GTK_CIPHER requires GTK_REQUIRED"); + return -EINVAL; + } + + if (tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]) + params.ipv6_intf_id = + nla_data(tb[NL80211_NAN_NDP_ATTR_IPV6_INTF_ID]); + + if (tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]) { + u32 freq = nla_get_u32(tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ]); + + params.chan = ieee80211_get_channel(&rdev->wiphy, freq); + if (!params.chan) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel frequency is not supported"); + return -EINVAL; + } + if (params.chan->flags & IEEE80211_CHAN_DISABLED) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel is disabled"); + return -EINVAL; + } + if (!(rdev->wiphy.nan_supported_bands & + BIT(params.chan->band))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NL80211_NAN_NDP_ATTR_CHANNEL_FREQ], + "Channel band is not supported for NAN"); + return -EOPNOTSUPP; + } + params.chan_forced = + !!tb[NL80211_NAN_NDP_ATTR_CHANNEL_FORCED]; + } + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, + NL80211_CMD_NAN_NDP_INITIATE); + if (!hdr) { + nlmsg_free(msg); + return -ENOMEM; + } + + err = rdev_nan_ndp_initiate(rdev, wdev, ¶ms); + if (err) { + nlmsg_free(msg); + return err; + } + + if (WARN_ON_ONCE(!params.ndp_id)) { + nlmsg_free(msg); + return -EINVAL; + } + + ndp_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_NDP); + if (!ndp_attr || + nla_put_u8(msg, NL80211_NAN_NDP_ATTR_ID, params.ndp_id)) + goto nla_put_failure; + + nla_nest_end(msg, ndp_attr); + genlmsg_end(msg, hdr); + return genlmsg_reply(msg, info); + +nla_put_failure: + nlmsg_free(msg); + return -ENOBUFS; +} + static bool nl80211_nan_is_sched_empty(struct cfg80211_nan_local_sched *sched) { if (!sched->n_channels) @@ -21656,6 +21912,13 @@ static const struct genl_small_ops nl80211_small_ops[] = { .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | NL80211_FLAG_NO_WIPHY_MTX), }, + { + .cmd = NL80211_CMD_NAN_NDP_INITIATE, + .doit = nl80211_nan_ndp_initiate, + .flags = GENL_ADMIN_PERM, + .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | + NL80211_FLAG_CLEAR_SKB), + }, }; static struct genl_family nl80211_fam __ro_after_init = { diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h index 7b8440c1f697..df8ec338e59d 100644 --- a/net/wireless/rdev-ops.h +++ b/net/wireless/rdev-ops.h @@ -1189,6 +1189,22 @@ static inline void rdev_stop_pd(struct cfg80211_registered_device *rdev, trace_rdev_return_void(&rdev->wiphy); } +static inline int +rdev_nan_ndp_initiate(struct cfg80211_registered_device *rdev, + struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params) +{ + int ret; + + if (!rdev->ops->nan_ndp_initiate) + return -EOPNOTSUPP; + + trace_rdev_nan_ndp_initiate(&rdev->wiphy, wdev, params); + ret = rdev->ops->nan_ndp_initiate(&rdev->wiphy, wdev, params); + trace_rdev_return_int(&rdev->wiphy, ret); + return ret; +} + static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev, struct net_device *dev, struct cfg80211_acl_data *params) diff --git a/net/wireless/trace.h b/net/wireless/trace.h index 31000ffebe43..131fb5657004 100644 --- a/net/wireless/trace.h +++ b/net/wireless/trace.h @@ -2552,6 +2552,100 @@ TRACE_EVENT(rdev_nan_set_non_evac_channels, __entry->n_channels, sizeof(u32))) ); +#define RDEV_NAN_NDP_INITIATE_FMT_1 \ + ", peer: %pM, init_ndi: %pM, publish_id: %u, " +#define RDEV_NAN_NDP_INITIATE_FMT_2 \ + "service_id: %s, ssi_len: %u, ssi: %s, " +#define RDEV_NAN_NDP_INITIATE_FMT_3 \ + "cipher_suite: %u, pmk_len: %u, pmkid_present: %d, " +#define RDEV_NAN_NDP_INITIATE_FMT_4 \ + "gtk_required: %d, gtk_cipher: %u, ipv6_intf_id_present: %d, " +#define RDEV_NAN_NDP_INITIATE_FMT_5 \ + "ipv6_intf_id: %s, channel_freq: %u, channel_forced: %d" +TRACE_EVENT(rdev_nan_ndp_initiate, + TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev, + struct cfg80211_nan_ndp_initiate *params), + TP_ARGS(wiphy, wdev, params), + TP_STRUCT__entry( + WIPHY_ENTRY + WDEV_ENTRY + __array(u8, peer_nmi, ETH_ALEN) + __array(u8, init_ndi, ETH_ALEN) + __field(u8, publish_id) + __array(u8, service_id, NL80211_NAN_FUNC_SERVICE_ID_LEN) + __field(u8, ssi_len) + __dynamic_array(u8, ssi, params->ssi_len) + __field(u32, cipher_suite) + __field(u8, pmk_len) + __field(bool, pmkid_present) + __field(bool, gtk_required) + __field(u32, gtk_cipher) + __field(bool, transport_info) + __field(u16, transport_port) + __field(u8, transport_protocol) + __field(bool, ipv6_intf_id_present) + __array(u8, ipv6_intf_id, NL80211_NAN_NDP_IPV6_INTF_ID_LEN) + __field(u32, channel_freq) + __field(bool, channel_forced) + ), + TP_fast_assign( + WIPHY_ASSIGN; + WDEV_ASSIGN; + memcpy(__entry->peer_nmi, params->peer_nmi, ETH_ALEN); + memcpy(__entry->init_ndi, params->init_ndi, ETH_ALEN); + __entry->publish_id = params->publish_id; + memcpy(__entry->service_id, params->service_id, + NL80211_NAN_FUNC_SERVICE_ID_LEN); + __entry->ssi_len = params->ssi_len; + if (params->ssi_len) + memcpy(__get_dynamic_array(ssi), params->ssi, + params->ssi_len); + __entry->cipher_suite = params->cipher_suite; + __entry->pmk_len = params->pmk ? params->pmk_len : 0; + __entry->pmkid_present = !!params->pmkid; + __entry->gtk_required = params->gtk_required; + __entry->gtk_cipher = params->gtk_cipher; + __entry->transport_info = params->transport_info; + __entry->transport_port = params->transport_port; + __entry->transport_protocol = params->transport_protocol; + __entry->ipv6_intf_id_present = !!params->ipv6_intf_id; + if (params->ipv6_intf_id) + memcpy(__entry->ipv6_intf_id, params->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + else + memset(__entry->ipv6_intf_id, 0, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN); + __entry->channel_freq = params->chan ? + params->chan->center_freq : 0; + __entry->channel_forced = params->chan_forced; + ), + TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT + RDEV_NAN_NDP_INITIATE_FMT_1 RDEV_NAN_NDP_INITIATE_FMT_2 + RDEV_NAN_NDP_INITIATE_FMT_3 RDEV_NAN_NDP_INITIATE_FMT_4 + RDEV_NAN_NDP_INITIATE_FMT_5 + ", transport_info: %d, transport_port: %u, transport_protocol: %u", + WIPHY_PR_ARG, WDEV_PR_ARG, __entry->peer_nmi, __entry->init_ndi, + __entry->publish_id, + __print_array(__entry->service_id, + NL80211_NAN_FUNC_SERVICE_ID_LEN, sizeof(u8)), + __entry->ssi_len, + __print_array(__get_dynamic_array(ssi), __entry->ssi_len, + sizeof(u8)), + __entry->cipher_suite, __entry->pmk_len, + __entry->pmkid_present, __entry->gtk_required, + __entry->gtk_cipher, __entry->ipv6_intf_id_present, + __print_array(__entry->ipv6_intf_id, + NL80211_NAN_NDP_IPV6_INTF_ID_LEN, sizeof(u8)), + __entry->channel_freq, __entry->channel_forced, + __entry->transport_info, __entry->transport_port, + __entry->transport_protocol) +); +#undef RDEV_NAN_NDP_INITIATE_FMT_1 +#undef RDEV_NAN_NDP_INITIATE_FMT_2 +#undef RDEV_NAN_NDP_INITIATE_FMT_3 +#undef RDEV_NAN_NDP_INITIATE_FMT_4 +#undef RDEV_NAN_NDP_INITIATE_FMT_5 + TRACE_EVENT(rdev_set_mac_acl, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_acl_data *params), -- 2.34.1