iw: add set sar_specs command
PATCH 1/1 iw: add set sar_specs command
From: Zong-Zhe Yang <[email protected]>
Add set sar_specs command
usage: iw <phy> set sar_specs <sar type> <range index:sar power>* e.g.
iw phy0 set sar_specs 0 0:100 1:90 2:80...
where sar type should correspond to wiphy's sar_capa, and range index should be valid in wiphy's sar_capa.
For now, kernel sar type supports only 0 (NL80211_SAR_TYPE_POWER) which means that the sar power limitation is specified in 0.25dBm unit.
Cc Carl Huang <[email protected]>
Signed-off-by Zong-Zhe Yang <[email protected]>
Signed-off-by Ping-Ke Shih <[email protected]>
--- sar.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 sar.c
sar.c new file +71 -0
@@ -0,0 +1,71 @@ +#include <errno.h> +#include <string.h> + +#include <netlink/genl/genl.h> +#include <netlink/msg.h> +#include <netlink/attr.h> + +#include "nl80211.h" +#include "iw.h" + +static int set_sar_specs (struct nl80211_state *state, +struct nl_msg *msg, +int argc,char **argv, +enum id_input id) +{ +struct nlattr *nl_sar, *nl_specs, *nl_sub; +enum nl80211_sar_type type; +__u32 idx; +__s32 pwr; +char *tmp; +int count, i; + +if (argc <=1 ) +return -EINVAL ; + + type =atoi (argv[0 ]); + + nl_sar =nla_nest_start (msg,NL80211_ATTR_SAR_SPEC ); +if (!nl_sar) + goto nla_put_failure; + +NLA_PUT_U32 (msg,NL80211_SAR_ATTR_TYPE , type); + + nl_specs =nla_nest_start (msg,NL80211_SAR_ATTR_SPECS ); +if (!nl_specs) + goto nla_put_failure; + +for (i =1 ; i < argc; i++) { + tmp =strchr (argv[i],':' ); +if (!tmp) +return -EINVAL ; + +if (tmp !=strrchr (argv[i],':' )) +return -EINVAL ; + + count =sscanf (argv[i],"%u:%d" , &idx, &pwr); +if (count !=2 ) +return -EINVAL ; + + nl_sub =nla_nest_start (msg, i -1 ); +if (!nl_sub) + goto nla_put_failure; + +NLA_PUT_U32 (msg,NL80211_SAR_ATTR_SPECS_RANGE_INDEX , idx); +NLA_PUT_S32 (msg,NL80211_SAR_ATTR_SPECS_POWER , pwr); + +nla_nest_end (msg, nl_sub); + } + +nla_nest_end (msg, nl_specs); +nla_nest_end (msg, nl_sar); + +return 0 ; + + nla_put_failure: +return -ENOBUFS ; +} + +COMMAND (set, sar_specs,"<sar type> <range index:sar power>*" , +NL80211_CMD_SET_SAR_SPECS ,0 ,CIB_PHY , set_sar_specs, +"Set SAR specs corresponding to SAR capa of wiphy." );
Signature · 1 line
2.25.1