Commit a442b761 authored by Ayala Beker's avatar Ayala Beker Committed by Johannes Berg

cfg80211: add add_nan_func / del_nan_func

A NAN function can be either publish, subscribe or follow
up. Make all the necessary verifications and just pass the
request to the driver.
Allow the user space application that starts NAN to
forbid any other socket to add or remove functions.
Signed-off-by: default avatarAndrei Otcheretianski <andrei.otcheretianski@intel.com>
Signed-off-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: default avatarAyala Beker <ayala.beker@intel.com>
Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 708d50ed
...@@ -2326,6 +2326,73 @@ struct cfg80211_nan_conf { ...@@ -2326,6 +2326,73 @@ struct cfg80211_nan_conf {
u8 dual; u8 dual;
}; };
/**
* struct cfg80211_nan_func_filter - a NAN function Rx / Tx filter
*
* @filter: the content of the filter
* @len: the length of the filter
*/
struct cfg80211_nan_func_filter {
const u8 *filter;
u8 len;
};
/**
* struct cfg80211_nan_func - a NAN function
*
* @type: &enum nl80211_nan_function_type
* @service_id: the service ID of the function
* @publish_type: &nl80211_nan_publish_type
* @close_range: if true, the range should be limited. Threshold is
* implementation specific.
* @publish_bcast: if true, the solicited publish should be broadcasted
* @subscribe_active: if true, the subscribe is active
* @followup_id: the instance ID for follow up
* @followup_reqid: the requestor instance ID for follow up
* @followup_dest: MAC address of the recipient of the follow up
* @ttl: time to live counter in DW.
* @serv_spec_info: Service Specific Info
* @serv_spec_info_len: Service Specific Info length
* @srf_include: if true, SRF is inclusive
* @srf_bf: Bloom Filter
* @srf_bf_len: Bloom Filter length
* @srf_bf_idx: Bloom Filter index
* @srf_macs: SRF MAC addresses
* @srf_num_macs: number of MAC addresses in SRF
* @rx_filters: rx filters that are matched with corresponding peer's tx_filter
* @tx_filters: filters that should be transmitted in the SDF.
* @num_rx_filters: length of &rx_filters.
* @num_tx_filters: length of &tx_filters.
* @instance_id: driver allocated id of the function.
* @cookie: unique NAN function identifier.
*/
struct cfg80211_nan_func {
enum nl80211_nan_function_type type;
u8 service_id[NL80211_NAN_FUNC_SERVICE_ID_LEN];
u8 publish_type;
bool close_range;
bool publish_bcast;
bool subscribe_active;
u8 followup_id;
u8 followup_reqid;
struct mac_address followup_dest;
u32 ttl;
const u8 *serv_spec_info;
u8 serv_spec_info_len;
bool srf_include;
const u8 *srf_bf;
u8 srf_bf_len;
u8 srf_bf_idx;
struct mac_address *srf_macs;
int srf_num_macs;
struct cfg80211_nan_func_filter *rx_filters;
struct cfg80211_nan_func_filter *tx_filters;
u8 num_tx_filters;
u8 num_rx_filters;
u8 instance_id;
u64 cookie;
};
/** /**
* struct cfg80211_ops - backend description for wireless configuration * struct cfg80211_ops - backend description for wireless configuration
* *
...@@ -2616,6 +2683,14 @@ struct cfg80211_nan_conf { ...@@ -2616,6 +2683,14 @@ struct cfg80211_nan_conf {
* peers must be on the base channel when the call completes. * peers must be on the base channel when the call completes.
* @start_nan: Start the NAN interface. * @start_nan: Start the NAN interface.
* @stop_nan: Stop the NAN interface. * @stop_nan: Stop the NAN interface.
* @add_nan_func: Add a NAN function. Returns negative value on failure.
* On success @nan_func ownership is transferred to the driver and
* it may access it outside of the scope of this function. The driver
* should free the @nan_func when no longer needed by calling
* cfg80211_free_nan_func().
* On success the driver should assign an instance_id in the
* provided @nan_func.
* @del_nan_func: Delete a NAN function.
*/ */
struct cfg80211_ops { struct cfg80211_ops {
int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow); int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
...@@ -2884,6 +2959,10 @@ struct cfg80211_ops { ...@@ -2884,6 +2959,10 @@ struct cfg80211_ops {
int (*start_nan)(struct wiphy *wiphy, struct wireless_dev *wdev, int (*start_nan)(struct wiphy *wiphy, struct wireless_dev *wdev,
struct cfg80211_nan_conf *conf); struct cfg80211_nan_conf *conf);
void (*stop_nan)(struct wiphy *wiphy, struct wireless_dev *wdev); void (*stop_nan)(struct wiphy *wiphy, struct wireless_dev *wdev);
int (*add_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev,
struct cfg80211_nan_func *nan_func);
void (*del_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev,
u64 cookie);
}; };
/* /*
...@@ -3335,6 +3414,8 @@ struct wiphy_iftype_ext_capab { ...@@ -3335,6 +3414,8 @@ struct wiphy_iftype_ext_capab {
* @bss_select_support: bitmask indicating the BSS selection criteria supported * @bss_select_support: bitmask indicating the BSS selection criteria supported
* by the driver in the .connect() callback. The bit position maps to the * by the driver in the .connect() callback. The bit position maps to the
* attribute indices defined in &enum nl80211_bss_select_attr. * attribute indices defined in &enum nl80211_bss_select_attr.
*
* @cookie_counter: unique generic cookie counter, used to identify objects.
*/ */
struct wiphy { struct wiphy {
/* assign these fields before you register the wiphy */ /* assign these fields before you register the wiphy */
...@@ -3464,6 +3545,8 @@ struct wiphy { ...@@ -3464,6 +3545,8 @@ struct wiphy {
u32 bss_select_support; u32 bss_select_support;
u64 cookie_counter;
char priv[0] __aligned(NETDEV_ALIGN); char priv[0] __aligned(NETDEV_ALIGN);
}; };
...@@ -5584,6 +5667,14 @@ wiphy_ext_feature_isset(struct wiphy *wiphy, ...@@ -5584,6 +5667,14 @@ wiphy_ext_feature_isset(struct wiphy *wiphy,
return (ft_byte & BIT(ftidx % 8)) != 0; return (ft_byte & BIT(ftidx % 8)) != 0;
} }
/**
* cfg80211_free_nan_func - free NAN function
* @f: NAN function that should be freed
*
* Frees all the NAN function and all it's allocated members.
*/
void cfg80211_free_nan_func(struct cfg80211_nan_func *f);
/* ethtool helper */ /* ethtool helper */
void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info); void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
......
...@@ -847,6 +847,21 @@ ...@@ -847,6 +847,21 @@
* After this command NAN functions can be added. * After this command NAN functions can be added.
* @NL80211_CMD_STOP_NAN: Stop the NAN operation, identified by * @NL80211_CMD_STOP_NAN: Stop the NAN operation, identified by
* its %NL80211_ATTR_WDEV interface. * its %NL80211_ATTR_WDEV interface.
* @NL80211_CMD_ADD_NAN_FUNCTION: Add a NAN function. The function is defined
* with %NL80211_ATTR_NAN_FUNC nested attribute. When called, this
* operation returns the strictly positive and unique instance id
* (%NL80211_ATTR_NAN_FUNC_INST_ID) and a cookie (%NL80211_ATTR_COOKIE)
* of the function upon success.
* Since instance ID's can be re-used, this cookie is the right
* way to identify the function. This will avoid races when a termination
* event is handled by the user space after it has already added a new
* function that got the same instance id from the kernel as the one
* which just terminated.
* This cookie may be used in NAN events even before the command
* returns, so userspace shouldn't process NAN events until it processes
* the response to this command.
* Look at %NL80211_ATTR_SOCKET_OWNER as well.
* @NL80211_CMD_DEL_NAN_FUNCTION: Delete a NAN function by cookie.
* *
* @NL80211_CMD_MAX: highest used command number * @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use * @__NL80211_CMD_AFTER_LAST: internal use
...@@ -1038,6 +1053,8 @@ enum nl80211_commands { ...@@ -1038,6 +1053,8 @@ enum nl80211_commands {
NL80211_CMD_START_NAN, NL80211_CMD_START_NAN,
NL80211_CMD_STOP_NAN, NL80211_CMD_STOP_NAN,
NL80211_CMD_ADD_NAN_FUNCTION,
NL80211_CMD_DEL_NAN_FUNCTION,
/* add new commands above here */ /* add new commands above here */
...@@ -1899,6 +1916,9 @@ enum nl80211_commands { ...@@ -1899,6 +1916,9 @@ enum nl80211_commands {
* @NL80211_ATTR_NAN_DUAL: NAN dual band operation config (see * @NL80211_ATTR_NAN_DUAL: NAN dual band operation config (see
* &enum nl80211_nan_dual_band_conf). This attribute is used with * &enum nl80211_nan_dual_band_conf). This attribute is used with
* %NL80211_CMD_START_NAN. * %NL80211_CMD_START_NAN.
* @NL80211_ATTR_NAN_FUNC: a function that can be added to NAN. See
* &enum nl80211_nan_func_attributes for description of this nested
* attribute.
* *
* @NUM_NL80211_ATTR: total number of nl80211_attrs available * @NUM_NL80211_ATTR: total number of nl80211_attrs available
* @NL80211_ATTR_MAX: highest attribute number currently defined * @NL80211_ATTR_MAX: highest attribute number currently defined
...@@ -2296,6 +2316,7 @@ enum nl80211_attrs { ...@@ -2296,6 +2316,7 @@ enum nl80211_attrs {
NL80211_ATTR_NAN_MASTER_PREF, NL80211_ATTR_NAN_MASTER_PREF,
NL80211_ATTR_NAN_DUAL, NL80211_ATTR_NAN_DUAL,
NL80211_ATTR_NAN_FUNC,
/* add attributes here, update the policy in nl80211.c */ /* add attributes here, update the policy in nl80211.c */
...@@ -4917,4 +4938,133 @@ enum nl80211_nan_dual_band_conf { ...@@ -4917,4 +4938,133 @@ enum nl80211_nan_dual_band_conf {
NL80211_NAN_BAND_5GHZ = 1 << 2, NL80211_NAN_BAND_5GHZ = 1 << 2,
}; };
/**
* enum nl80211_nan_function_type - NAN function type
*
* Defines the function type of a NAN function
*
* @NL80211_NAN_FUNC_PUBLISH: function is publish
* @NL80211_NAN_FUNC_SUBSCRIBE: function is subscribe
* @NL80211_NAN_FUNC_FOLLOW_UP: function is follow-up
*/
enum nl80211_nan_function_type {
NL80211_NAN_FUNC_PUBLISH,
NL80211_NAN_FUNC_SUBSCRIBE,
NL80211_NAN_FUNC_FOLLOW_UP,
/* keep last */
__NL80211_NAN_FUNC_TYPE_AFTER_LAST,
NL80211_NAN_FUNC_MAX_TYPE = __NL80211_NAN_FUNC_TYPE_AFTER_LAST - 1,
};
/**
* enum nl80211_nan_publish_type - NAN publish tx type
*
* Defines how to send publish Service Discovery Frames
*
* @NL80211_NAN_SOLICITED_PUBLISH: publish function is solicited
* @NL80211_NAN_UNSOLICITED_PUBLISH: publish function is unsolicited
*/
enum nl80211_nan_publish_type {
NL80211_NAN_SOLICITED_PUBLISH = 1 << 0,
NL80211_NAN_UNSOLICITED_PUBLISH = 1 << 1,
};
#define NL80211_NAN_FUNC_SERVICE_ID_LEN 6
#define NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN 0xff
#define NL80211_NAN_FUNC_SRF_MAX_LEN 0xff
/**
* enum nl80211_nan_func_attributes - NAN function attributes
* @__NL80211_NAN_FUNC_INVALID: invalid
* @NL80211_NAN_FUNC_TYPE: &enum nl80211_nan_function_type (u8).
* @NL80211_NAN_FUNC_SERVICE_ID: 6 bytes of the service ID hash as
* specified in NAN spec. This is a binary attribute.
* @NL80211_NAN_FUNC_PUBLISH_TYPE: relevant if the function's type is
* publish. Defines the transmission type for the publish Service Discovery
* Frame, see &enum nl80211_nan_publish_type. Its type is u8.
* @NL80211_NAN_FUNC_PUBLISH_BCAST: relevant if the function is a solicited
* publish. Should the solicited publish Service Discovery Frame be sent to
* the NAN Broadcast address. This is a flag.
* @NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE: relevant if the function's type is
* subscribe. Is the subscribe active. This is a flag.
* @NL80211_NAN_FUNC_FOLLOW_UP_ID: relevant if the function's type is follow up.
* The instance ID for the follow up Service Discovery Frame. This is u8.
* @NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID: relevant if the function's type
* is follow up. This is a u8.
* The requestor instance ID for the follow up Service Discovery Frame.
* @NL80211_NAN_FUNC_FOLLOW_UP_DEST: the MAC address of the recipient of the
* follow up Service Discovery Frame. This is a binary attribute.
* @NL80211_NAN_FUNC_CLOSE_RANGE: is this function limited for devices in a
* close range. The range itself (RSSI) is defined by the device.
* This is a flag.
* @NL80211_NAN_FUNC_TTL: strictly positive number of DWs this function should
* stay active. If not present infinite TTL is assumed. This is a u32.
* @NL80211_NAN_FUNC_SERVICE_INFO: array of bytes describing the service
* specific info. This is a binary attribute.
* @NL80211_NAN_FUNC_SRF: Service Receive Filter. This is a nested attribute.
* See &enum nl80211_nan_srf_attributes.
* @NL80211_NAN_FUNC_RX_MATCH_FILTER: Receive Matching filter. This is a nested
* attribute. It is a list of binary values.
* @NL80211_NAN_FUNC_TX_MATCH_FILTER: Transmit Matching filter. This is a
* nested attribute. It is a list of binary values.
* @NL80211_NAN_FUNC_INSTANCE_ID: The instance ID of the function.
* Its type is u8 and it cannot be 0.
* @NL80211_NAN_FUNC_TERM_REASON: NAN function termination reason.
* See &enum nl80211_nan_func_term_reason.
*
* @NUM_NL80211_NAN_FUNC_ATTR: internal
* @NL80211_NAN_FUNC_ATTR_MAX: highest NAN function attribute
*/
enum nl80211_nan_func_attributes {
__NL80211_NAN_FUNC_INVALID,
NL80211_NAN_FUNC_TYPE,
NL80211_NAN_FUNC_SERVICE_ID,
NL80211_NAN_FUNC_PUBLISH_TYPE,
NL80211_NAN_FUNC_PUBLISH_BCAST,
NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE,
NL80211_NAN_FUNC_FOLLOW_UP_ID,
NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID,
NL80211_NAN_FUNC_FOLLOW_UP_DEST,
NL80211_NAN_FUNC_CLOSE_RANGE,
NL80211_NAN_FUNC_TTL,
NL80211_NAN_FUNC_SERVICE_INFO,
NL80211_NAN_FUNC_SRF,
NL80211_NAN_FUNC_RX_MATCH_FILTER,
NL80211_NAN_FUNC_TX_MATCH_FILTER,
NL80211_NAN_FUNC_INSTANCE_ID,
NL80211_NAN_FUNC_TERM_REASON,
/* keep last */
NUM_NL80211_NAN_FUNC_ATTR,
NL80211_NAN_FUNC_ATTR_MAX = NUM_NL80211_NAN_FUNC_ATTR - 1
};
/**
* enum nl80211_nan_srf_attributes - NAN Service Response filter attributes
* @__NL80211_NAN_SRF_INVALID: invalid
* @NL80211_NAN_SRF_INCLUDE: present if the include bit of the SRF set.
* This is a flag.
* @NL80211_NAN_SRF_BF: Bloom Filter. Present if and only if
* &NL80211_NAN_SRF_MAC_ADDRS isn't present. This attribute is binary.
* @NL80211_NAN_SRF_BF_IDX: index of the Bloom Filter. Mandatory if
* &NL80211_NAN_SRF_BF is present. This is a u8.
* @NL80211_NAN_SRF_MAC_ADDRS: list of MAC addresses for the SRF. Present if
* and only if &NL80211_NAN_SRF_BF isn't present. This is a nested
* attribute. Each nested attribute is a MAC address.
* @NUM_NL80211_NAN_SRF_ATTR: internal
* @NL80211_NAN_SRF_ATTR_MAX: highest NAN SRF attribute
*/
enum nl80211_nan_srf_attributes {
__NL80211_NAN_SRF_INVALID,
NL80211_NAN_SRF_INCLUDE,
NL80211_NAN_SRF_BF,
NL80211_NAN_SRF_BF_IDX,
NL80211_NAN_SRF_MAC_ADDRS,
/* keep last */
NUM_NL80211_NAN_SRF_ATTR,
NL80211_NAN_SRF_ATTR_MAX = NUM_NL80211_NAN_SRF_ATTR - 1,
};
#endif /* __LINUX_NL80211_H */ #endif /* __LINUX_NL80211_H */
...@@ -605,7 +605,8 @@ int wiphy_register(struct wiphy *wiphy) ...@@ -605,7 +605,8 @@ int wiphy_register(struct wiphy *wiphy)
return -EINVAL; return -EINVAL;
if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN)) && if (WARN_ON((wiphy->interface_modes & BIT(NL80211_IFTYPE_NAN)) &&
(!rdev->ops->start_nan || !rdev->ops->stop_nan))) (!rdev->ops->start_nan || !rdev->ops->stop_nan ||
!rdev->ops->add_nan_func || !rdev->ops->del_nan_func)))
return -EINVAL; return -EINVAL;
/* /*
......
This diff is collapsed.
...@@ -907,6 +907,27 @@ static inline void rdev_stop_nan(struct cfg80211_registered_device *rdev, ...@@ -907,6 +907,27 @@ static inline void rdev_stop_nan(struct cfg80211_registered_device *rdev,
trace_rdev_return_void(&rdev->wiphy); trace_rdev_return_void(&rdev->wiphy);
} }
static inline int
rdev_add_nan_func(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev,
struct cfg80211_nan_func *nan_func)
{
int ret;
trace_rdev_add_nan_func(&rdev->wiphy, wdev, nan_func);
ret = rdev->ops->add_nan_func(&rdev->wiphy, wdev, nan_func);
trace_rdev_return_int(&rdev->wiphy, ret);
return ret;
}
static inline void rdev_del_nan_func(struct cfg80211_registered_device *rdev,
struct wireless_dev *wdev, u64 cookie)
{
trace_rdev_del_nan_func(&rdev->wiphy, wdev, cookie);
rdev->ops->del_nan_func(&rdev->wiphy, wdev, cookie);
trace_rdev_return_void(&rdev->wiphy);
}
static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev, static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev,
struct net_device *dev, struct net_device *dev,
struct cfg80211_acl_data *params) struct cfg80211_acl_data *params)
......
...@@ -1916,6 +1916,45 @@ DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan, ...@@ -1916,6 +1916,45 @@ DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan,
TP_ARGS(wiphy, wdev) TP_ARGS(wiphy, wdev)
); );
TRACE_EVENT(rdev_add_nan_func,
TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev,
const struct cfg80211_nan_func *func),
TP_ARGS(wiphy, wdev, func),
TP_STRUCT__entry(
WIPHY_ENTRY
WDEV_ENTRY
__field(u8, func_type)
__field(u64, cookie)
),
TP_fast_assign(
WIPHY_ASSIGN;
WDEV_ASSIGN;
__entry->func_type = func->type;
__entry->cookie = func->cookie
),
TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", type=%u, cookie=%llu",
WIPHY_PR_ARG, WDEV_PR_ARG, __entry->func_type,
__entry->cookie)
);
TRACE_EVENT(rdev_del_nan_func,
TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev,
u64 cookie),
TP_ARGS(wiphy, wdev, cookie),
TP_STRUCT__entry(
WIPHY_ENTRY
WDEV_ENTRY
__field(u64, cookie)
),
TP_fast_assign(
WIPHY_ASSIGN;
WDEV_ASSIGN;
__entry->cookie = cookie;
),
TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT ", cookie=%llu",
WIPHY_PR_ARG, WDEV_PR_ARG, __entry->cookie)
);
TRACE_EVENT(rdev_set_mac_acl, TRACE_EVENT(rdev_set_mac_acl,
TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
struct cfg80211_acl_data *params), struct cfg80211_acl_data *params),
......
...@@ -1762,6 +1762,28 @@ int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr, ...@@ -1762,6 +1762,28 @@ int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr,
} }
EXPORT_SYMBOL(cfg80211_get_station); EXPORT_SYMBOL(cfg80211_get_station);
void cfg80211_free_nan_func(struct cfg80211_nan_func *f)
{
int i;
if (!f)
return;
kfree(f->serv_spec_info);
kfree(f->srf_bf);
kfree(f->srf_macs);
for (i = 0; i < f->num_rx_filters; i++)
kfree(f->rx_filters[i].filter);
for (i = 0; i < f->num_tx_filters; i++)
kfree(f->tx_filters[i].filter);
kfree(f->rx_filters);
kfree(f->tx_filters);
kfree(f);
}
EXPORT_SYMBOL(cfg80211_free_nan_func);
/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
/* Ethernet-II snap header (RFC1042 for most EtherTypes) */ /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
const unsigned char rfc1042_header[] __aligned(2) = const unsigned char rfc1042_header[] __aligned(2) =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment