Skip to content

Commit a5a9dcf

Browse files
AyalaBkrjmberg-intel
authored andcommitted
cfg80211: allow the user space to change current NAN configuration
Some NAN configuration paramaters may change during the operation of the NAN device. For example, a user may want to update master preference value when the device gets plugged/unplugged to the power. Add API that allows to do so. Signed-off-by: Andrei Otcheretianski <[email protected]> Signed-off-by: Emmanuel Grumbach <[email protected]> Signed-off-by: Luca Coelho <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent a442b76 commit a5a9dcf

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

include/net/cfg80211.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,18 @@ struct cfg80211_nan_conf {
23262326
u8 dual;
23272327
};
23282328

2329+
/**
2330+
* enum cfg80211_nan_conf_changes - indicates changed fields in NAN
2331+
* configuration
2332+
*
2333+
* @CFG80211_NAN_CONF_CHANGED_PREF: master preference
2334+
* @CFG80211_NAN_CONF_CHANGED_DUAL: dual band operation
2335+
*/
2336+
enum cfg80211_nan_conf_changes {
2337+
CFG80211_NAN_CONF_CHANGED_PREF = BIT(0),
2338+
CFG80211_NAN_CONF_CHANGED_DUAL = BIT(1),
2339+
};
2340+
23292341
/**
23302342
* struct cfg80211_nan_func_filter - a NAN function Rx / Tx filter
23312343
*
@@ -2691,6 +2703,9 @@ struct cfg80211_nan_func {
26912703
* On success the driver should assign an instance_id in the
26922704
* provided @nan_func.
26932705
* @del_nan_func: Delete a NAN function.
2706+
* @nan_change_conf: changes NAN configuration. The changed parameters must
2707+
* be specified in @changes (using &enum cfg80211_nan_conf_changes);
2708+
* All other parameters must be ignored.
26942709
*/
26952710
struct cfg80211_ops {
26962711
int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2963,6 +2978,10 @@ struct cfg80211_ops {
29632978
struct cfg80211_nan_func *nan_func);
29642979
void (*del_nan_func)(struct wiphy *wiphy, struct wireless_dev *wdev,
29652980
u64 cookie);
2981+
int (*nan_change_conf)(struct wiphy *wiphy,
2982+
struct wireless_dev *wdev,
2983+
struct cfg80211_nan_conf *conf,
2984+
u32 changes);
29662985
};
29672986

29682987
/*

include/uapi/linux/nl80211.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@
862862
* the response to this command.
863863
* Look at %NL80211_ATTR_SOCKET_OWNER as well.
864864
* @NL80211_CMD_DEL_NAN_FUNCTION: Delete a NAN function by cookie.
865+
* @NL80211_CMD_CHANGE_NAN_CONFIG: Change current NAN configuration. NAN
866+
* must be operational (%NL80211_CMD_START_NAN was executed).
867+
* It must contain at least one of the following attributes:
868+
* %NL80211_ATTR_NAN_MASTER_PREF, %NL80211_ATTR_NAN_DUAL.
865869
*
866870
* @NL80211_CMD_MAX: highest used command number
867871
* @__NL80211_CMD_AFTER_LAST: internal use
@@ -1055,6 +1059,7 @@ enum nl80211_commands {
10551059
NL80211_CMD_STOP_NAN,
10561060
NL80211_CMD_ADD_NAN_FUNCTION,
10571061
NL80211_CMD_DEL_NAN_FUNCTION,
1062+
NL80211_CMD_CHANGE_NAN_CONFIG,
10581063

10591064
/* add new commands above here */
10601065

@@ -1910,12 +1915,14 @@ enum nl80211_commands {
19101915
* used to pull the stored data for mesh peer in power save state.
19111916
*
19121917
* @NL80211_ATTR_NAN_MASTER_PREF: the master preference to be used by
1913-
* %NL80211_CMD_START_NAN. Its type is u8 and it can't be 0.
1918+
* %NL80211_CMD_START_NAN and optionally with
1919+
* %NL80211_CMD_CHANGE_NAN_CONFIG. Its type is u8 and it can't be 0.
19141920
* Also, values 1 and 255 are reserved for certification purposes and
19151921
* should not be used during a normal device operation.
19161922
* @NL80211_ATTR_NAN_DUAL: NAN dual band operation config (see
19171923
* &enum nl80211_nan_dual_band_conf). This attribute is used with
1918-
* %NL80211_CMD_START_NAN.
1924+
* %NL80211_CMD_START_NAN and optionally with
1925+
* %NL80211_CMD_CHANGE_NAN_CONFIG.
19191926
* @NL80211_ATTR_NAN_FUNC: a function that can be added to NAN. See
19201927
* &enum nl80211_nan_func_attributes for description of this nested
19211928
* attribute.

net/wireless/nl80211.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10919,6 +10919,40 @@ static int nl80211_nan_del_func(struct sk_buff *skb,
1091910919
return 0;
1092010920
}
1092110921

10922+
static int nl80211_nan_change_config(struct sk_buff *skb,
10923+
struct genl_info *info)
10924+
{
10925+
struct cfg80211_registered_device *rdev = info->user_ptr[0];
10926+
struct wireless_dev *wdev = info->user_ptr[1];
10927+
struct cfg80211_nan_conf conf = {};
10928+
u32 changed = 0;
10929+
10930+
if (wdev->iftype != NL80211_IFTYPE_NAN)
10931+
return -EOPNOTSUPP;
10932+
10933+
if (!wdev->nan_started)
10934+
return -ENOTCONN;
10935+
10936+
if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
10937+
conf.master_pref =
10938+
nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10939+
if (conf.master_pref <= 1 || conf.master_pref == 255)
10940+
return -EINVAL;
10941+
10942+
changed |= CFG80211_NAN_CONF_CHANGED_PREF;
10943+
}
10944+
10945+
if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
10946+
conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10947+
changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
10948+
}
10949+
10950+
if (!changed)
10951+
return -EINVAL;
10952+
10953+
return rdev_nan_change_conf(rdev, wdev, &conf, changed);
10954+
}
10955+
1092210956
static int nl80211_get_protocol_features(struct sk_buff *skb,
1092310957
struct genl_info *info)
1092410958
{
@@ -12292,6 +12326,14 @@ static const struct genl_ops nl80211_ops[] = {
1229212326
.internal_flags = NL80211_FLAG_NEED_WDEV_UP |
1229312327
NL80211_FLAG_NEED_RTNL,
1229412328
},
12329+
{
12330+
.cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12331+
.doit = nl80211_nan_change_config,
12332+
.policy = nl80211_policy,
12333+
.flags = GENL_ADMIN_PERM,
12334+
.internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12335+
NL80211_FLAG_NEED_RTNL,
12336+
},
1229512337
{
1229612338
.cmd = NL80211_CMD_SET_MCAST_RATE,
1229712339
.doit = nl80211_set_mcast_rate,

net/wireless/rdev-ops.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,23 @@ static inline void rdev_del_nan_func(struct cfg80211_registered_device *rdev,
928928
trace_rdev_return_void(&rdev->wiphy);
929929
}
930930

931+
static inline int
932+
rdev_nan_change_conf(struct cfg80211_registered_device *rdev,
933+
struct wireless_dev *wdev,
934+
struct cfg80211_nan_conf *conf, u32 changes)
935+
{
936+
int ret;
937+
938+
trace_rdev_nan_change_conf(&rdev->wiphy, wdev, conf, changes);
939+
if (rdev->ops->nan_change_conf)
940+
ret = rdev->ops->nan_change_conf(&rdev->wiphy, wdev, conf,
941+
changes);
942+
else
943+
ret = -ENOTSUPP;
944+
trace_rdev_return_int(&rdev->wiphy, ret);
945+
return ret;
946+
}
947+
931948
static inline int rdev_set_mac_acl(struct cfg80211_registered_device *rdev,
932949
struct net_device *dev,
933950
struct cfg80211_acl_data *params)

net/wireless/trace.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,30 @@ TRACE_EVENT(rdev_start_nan,
19111911
__entry->dual)
19121912
);
19131913

1914+
TRACE_EVENT(rdev_nan_change_conf,
1915+
TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev,
1916+
struct cfg80211_nan_conf *conf, u32 changes),
1917+
TP_ARGS(wiphy, wdev, conf, changes),
1918+
TP_STRUCT__entry(
1919+
WIPHY_ENTRY
1920+
WDEV_ENTRY
1921+
__field(u8, master_pref)
1922+
__field(u8, dual);
1923+
__field(u32, changes);
1924+
),
1925+
TP_fast_assign(
1926+
WIPHY_ASSIGN;
1927+
WDEV_ASSIGN;
1928+
__entry->master_pref = conf->master_pref;
1929+
__entry->dual = conf->dual;
1930+
__entry->changes = changes;
1931+
),
1932+
TP_printk(WIPHY_PR_FMT ", " WDEV_PR_FMT
1933+
", master preference: %u, dual: %d, changes: %x",
1934+
WIPHY_PR_ARG, WDEV_PR_ARG, __entry->master_pref,
1935+
__entry->dual, __entry->changes)
1936+
);
1937+
19141938
DEFINE_EVENT(wiphy_wdev_evt, rdev_stop_nan,
19151939
TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
19161940
TP_ARGS(wiphy, wdev)

0 commit comments

Comments
 (0)