Allow userspace to inspect every attribute in a received Service Discovery Frame when the NAN Discovery Engine is offloaded. Such frames can contain SDEA, NPBA, CSIA, SCIA, DCEA, and extended SSI. Report the complete received management frame, including the 802.11 header, in NL80211_ATTR_FRAME, along with its frequency and RSSI when available. This lets userspace parse attributes without requiring a separate nl80211 attribute for each. Document that the peer Service Info may contain the SSI from the SDA or the SDEA. Signed-off-by: Shivani Baranwal --- include/net/cfg80211.h | 21 +++++++++++++++++++-- include/uapi/linux/nl80211.h | 8 +++++++- net/wireless/nl80211.c | 13 +++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 11d5650c23c5..285aa6991efa 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -10584,8 +10584,20 @@ void cfg80211_free_nan_func(struct cfg80211_nan_func *f); * @inst_id: the local instance id * @peer_inst_id: the instance id of the peer's function * @addr: the MAC address of the peer - * @info_len: the length of the &info - * @info: the Service Specific Info from the peer (if any) + * @info_len: the length of @info + * @info: SSI from the peer, i.e. the Service Info of the Service Descriptor + * attribute (SDA) or the Service Info of the Service Descriptor Extension + * attribute (SDEA; extended SSI), whichever the peer used. + * @frame: complete management frame containing the received NAN SDF, + * including the 802.11 header (optional). It is reported as received and, + * for protected frames, after decryption, as with received frames reported + * with %NL80211_CMD_FRAME. This lets userspace distinguish protected + * (Protected Dual of Public Action) and unprotected frames. + * @frame_len: length of @frame + * @freq: frequency in MHz on which @frame was received, or 0 if unknown + * @rssi: received signal strength in dBm at the time of the match. + * Only valid when @rssi_valid is true. + * @rssi_valid: if true, @rssi contains a valid RSSI measurement. * @cookie: unique identifier of the corresponding function */ struct cfg80211_nan_match_params { @@ -10595,6 +10607,11 @@ struct cfg80211_nan_match_params { const u8 *addr; u8 info_len; const u8 *info; + const u8 *frame; + size_t frame_len; + u32 freq; + s32 rssi; + bool rssi_valid; u64 cookie; }; diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index 4037a0f78ef6..38dd596b54c2 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -1127,7 +1127,13 @@ * only a subset was changed. * @NL80211_CMD_NAN_MATCH: Notification sent when a match is reported. * This will contain a %NL80211_ATTR_NAN_MATCH nested attribute and - * %NL80211_ATTR_COOKIE. + * %NL80211_ATTR_COOKIE. It may also contain %NL80211_ATTR_FRAME, + * %NL80211_ATTR_WIPHY_FREQ, and %NL80211_ATTR_RX_SIGNAL_DBM so userspace + * can parse any attribute in the received SDF. The frame is the complete + * received management frame, including the 802.11 header. It is reported as + * received and, for protected frames, after decryption, as with received + * frames reported with %NL80211_CMD_FRAME. This lets userspace distinguish + * protected (Protected Dual of Public Action) and unprotected frames. * * @NL80211_CMD_UPDATE_CONNECT_PARAMS: Update one or more connect parameters * for subsequent roaming cases if the driver or firmware uses internal diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 1331fe716985..44d512675065 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -17850,7 +17850,10 @@ void cfg80211_nan_match(struct wireless_dev *wdev, if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) return; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); + if (WARN_ON_ONCE(match->frame_len && !match->frame)) + return; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE + match->frame_len, gfp); if (!msg) return; @@ -17869,7 +17872,13 @@ void cfg80211_nan_match(struct wireless_dev *wdev, if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, NL80211_ATTR_PAD) || - nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) + nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr) || + (match->frame && match->frame_len && + nla_put(msg, NL80211_ATTR_FRAME, match->frame_len, match->frame)) || + (match->freq && + nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, match->freq)) || + (match->rssi_valid && + nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, match->rssi))) goto nla_put_failure; match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); -- 2.34.1