treewide: change transmit power to mbm
Alexander Aring
maintainerPATCH v2 1/2 treewide: change transmit power to mbm
This patch changes the transmit power nl802154 setting variable to handle as a mbm values instead dbm.
Signed-off-by Alexander Aring <[email protected]>
--- src/info.c | 2 +- src/iwpan.h | 5 +++++ src/nl_extras.h | 5 +++++ src/phy.c | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-)
src/info.c +1 -1
@@ -83,7 +83,7 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) }if (tb_msg[NL802154_ATTR_TX_POWER ]) -printf ("tx_power: %d\n" ,nla_get_s8 (tb_msg[NL802154_ATTR_TX_POWER ])); +printf ("tx_power: %.2g\n" ,MBM_TO_DBM (nla_get_s32 (tb_msg[NL802154_ATTR_TX_POWER ])));return 0 ; }
src/iwpan.h +5 -0
@@ -107,6 +107,11 @@ struct cmd {#define DECLARE_SECTION (_name) \ extern struct cmd __section ## _ ## _name; +#define DBM_TO_MBM (gain) \ + ((int)(((float)gain) * 100)) +#define MBM_TO_DBM (gain) \ + ((float)(gain) / 100) +int handle_cmd (struct nl802154_state *state,enum id_input idby,int argc,char **argv);
src/nl_extras.h +5 -0
@@ -28,6 +28,11 @@ static inline int8_t nla_get_s8(struct nlattr *nla)#define NLA_PUT_S32 (n, attrtype, value) \ NLA_PUT_TYPE(n, int32_t, attrtype, value) +static inline int32_t nla_get_s32 (struct nlattr *nla) +{ +return *(int32_t *)nla_data (nla); +} +#endif /* NLA_S32 */ #ifndef NLA_S64
src/phy.c +2 -2
@@ -64,7 +64,7 @@ static int handle_tx_power_set(struct nl802154_state *state,if (*end !='\0' )return 1 ; -NLA_PUT_S8 (msg,NL802154_ATTR_TX_POWER , dbm); +NLA_PUT_S32 (msg,NL802154_ATTR_TX_POWER ,DBM_TO_MBM (dbm));return 0 ;
@@ -132,7 +132,7 @@ static int handle_cca_ed_level(struct nl802154_state *state,if (*end !='\0' )return 1 ; -NLA_PUT_S32 (msg,NL802154_ATTR_CCA_ED_LEVEL , level); +NLA_PUT_S32 (msg,NL802154_ATTR_CCA_ED_LEVEL ,DBM_TO_MBM (level));return 0 ;
Signature · 1 line
2.3.7
Alexander Aring
maintainerPATCH v2 2/2 info: add support for phy capability dump
This patch adds support for dumping phy capabilities by running iwpan list, which printout something like:
capabilities:
iftypes: node,monitor
channels:
page 0: 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
tx_powers: 3,2.8,2.3,1.8,1.3,0.7,0,-1,-2,-3,-4,-5,-7,-9,-12,-17
cca_ed_levels: -91,-89,-87,-85,-83,-81,-79,-77,-75,-73,-71,-69,-67,-65,-63,-61
cca_modes: 1,2,3
cca_opts: 0(cca_mode: 3),1(cca_mode: 3)
min_be: 0,1,2,3,4,5,6,7,8
max_be: 3,4,5,6,7,8
csma_backoffs: 0,1,2,3,4,5
frame_retries: -1,0,1,2,3,4,5,6,7
lbt: falseSigned-off-by Alexander Aring <[email protected]>
--- src/info.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/iwpan.h | 2 + src/nl802154.h | 79 ++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 1 deletion(-)
src/info.c +175 -1
@@ -12,11 +12,22 @@#include "nl_extras.h" #include "iwpan.h" +static void print_minmax_handler (int min,int max) +{ +int i; + +for (i = min; i <= max; i++) +printf ("%d," , i); + +/* TODO */ +printf ("\b \n" ); +} +static int print_phy_handler (struct nl_msg *msg,void *arg) {struct nlattr *tb_msg[NL802154_ATTR_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -int rem_page, i; +int rem_page, i, ret;int64_t phy_id =-1 ;bool print_name = true;struct nlattr *nl_page;
@@ -33,6 +44,7 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)if (print_name && tb_msg[NL802154_ATTR_WPAN_PHY_NAME ])printf ("wpan_phy %s\n" ,nla_get_string (tb_msg[NL802154_ATTR_WPAN_PHY_NAME ])); +/* TODO remove this handling it's deprecated */ if (tb_msg[NL802154_ATTR_CHANNELS_SUPPORTED ]) {unsigned char page =0 ;unsigned long channel;
@@ -85,6 +97,168 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)if (tb_msg[NL802154_ATTR_TX_POWER ])printf ("tx_power: %.2g\n" ,MBM_TO_DBM (nla_get_s32 (tb_msg[NL802154_ATTR_TX_POWER ]))); +if (tb_msg[NL802154_ATTR_WPAN_PHY_CAPS ]) { +struct nlattr *tb_caps[NL802154_CAP_ATTR_MAX +1 ]; +/* TODO fix netlink lib that we can use NLA_S32 here +* see function validate_nla line if (pt->type > NLA_TYPE_MAX) */ +static struct nla_policy caps_policy[NL802154_CAP_ATTR_MAX +1 ] = { + [NL802154_CAP_ATTR_CHANNELS ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_TX_POWERS ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_CCA_ED_LEVELS ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_CCA_MODES ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_CCA_OPTS ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_MIN_MINBE ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MAX_MINBE ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MIN_MAXBE ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MAX_MAXBE ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MIN_FRAME_RETRIES ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_MAX_FRAME_RETRIES ] = { .type =NLA_U8 }, + [NL802154_CAP_ATTR_IFTYPES ] = { .type =NLA_NESTED }, + [NL802154_CAP_ATTR_LBT ] = { .type =NLA_U32 }, + }; + +printf ("capabilities:\n" ); + + ret =nla_parse_nested (tb_caps,NL802154_CAP_ATTR_MAX , + tb_msg[NL802154_ATTR_WPAN_PHY_CAPS ], + caps_policy); +if (ret) { +printf ("failed to parse caps\n" ); +return -EIO ; + } + +if (tb_caps[NL802154_CAP_ATTR_IFTYPES ]) { +struct nlattr *nl_iftypes; +int rem_iftypes; +printf ("\tiftypes: " ); +nla_for_each_nested (nl_iftypes, + tb_caps[NL802154_CAP_ATTR_IFTYPES ], + rem_iftypes) +printf ("%s," ,iftype_name (nla_type (nl_iftypes))); +/* TODO */ +printf ("\b \n" ); + } + +if (tb_msg[NL802154_CAP_ATTR_CHANNELS ]) { +int rem_pages; +struct nlattr *nl_pages; +printf ("\tchannels:\n" ); +nla_for_each_nested (nl_pages, tb_caps[NL802154_CAP_ATTR_CHANNELS ], + rem_pages) { +int rem_channels; +struct nlattr *nl_channels; +printf ("\t\tpage %d: " ,nla_type (nl_pages)); +nla_for_each_nested (nl_channels, nl_pages, rem_channels) +printf ("%d," ,nla_type (nl_channels)); +/* TODO hack use sprintf here */ +printf ("\b \b\n" ); + } + } + +if (tb_caps[NL802154_CAP_ATTR_TX_POWERS ]) { +int rem_pwrs; +struct nlattr *nl_pwrs; + +printf ("\ttx_powers: " ); +nla_for_each_nested (nl_pwrs, tb_caps[NL802154_CAP_ATTR_TX_POWERS ], rem_pwrs) +printf ("%.2g," ,MBM_TO_DBM (nla_get_s32 (nl_pwrs))); +/* TODO */ +printf ("\b \n" ); + } + +if (tb_caps[NL802154_CAP_ATTR_CCA_ED_LEVELS ]) { +int rem_levels; +struct nlattr *nl_levels; + +printf ("\tcca_ed_levels: " ); +nla_for_each_nested (nl_levels, tb_caps[NL802154_CAP_ATTR_CCA_ED_LEVELS ], rem_levels) +printf ("%.2g," ,MBM_TO_DBM (nla_get_s32 (nl_levels))); +/* TODO */ +printf ("\b \n" ); + } + +if (tb_caps[NL802154_CAP_ATTR_CCA_MODES ]) { +struct nlattr *nl_cca_modes; +int rem_cca_modes; +printf ("\tcca_modes: " ); +nla_for_each_nested (nl_cca_modes, + tb_caps[NL802154_CAP_ATTR_CCA_MODES ], + rem_cca_modes) +printf ("%d," ,nla_type (nl_cca_modes)); +/* TODO */ +printf ("\b \n" ); + } + +if (tb_caps[NL802154_CAP_ATTR_CCA_OPTS ]) { +struct nlattr *nl_cca_opts; +int rem_cca_opts; + +printf ("\tcca_opts: " ); +nla_for_each_nested (nl_cca_opts, + tb_caps[NL802154_CAP_ATTR_CCA_OPTS ], + rem_cca_opts) { +printf ("%d" ,nla_type (nl_cca_opts)); +switch (nla_type (nl_cca_opts)) { +case NL802154_CCA_OPT_ENERGY_CARRIER_AND : +case NL802154_CCA_OPT_ENERGY_CARRIER_OR : +printf ("(cca_mode: 3)," ); +break ; +default : +printf ("unkown\n" ); +break ; + } + } +/* TODO */ +printf ("\b \n" ); + } + +if (tb_caps[NL802154_CAP_ATTR_MIN_MINBE ] && + tb_caps[NL802154_CAP_ATTR_MAX_MINBE ] && + tb_caps[NL802154_CAP_ATTR_MIN_MAXBE ] && + tb_caps[NL802154_CAP_ATTR_MAX_MAXBE ]) { +printf ("\tmin_be: " ); +print_minmax_handler (nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MIN_MINBE ]), +nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MAX_MINBE ])); +printf ("\tmax_be: " ); +print_minmax_handler (nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MIN_MAXBE ]), +nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MAX_MAXBE ])); + } + +if (tb_caps[NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS ] && + tb_caps[NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS ]) { +printf ("\tcsma_backoffs: " ); +print_minmax_handler (nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS ]), +nla_get_u8 (tb_caps[NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS ])); + } + +if (tb_caps[NL802154_CAP_ATTR_MIN_FRAME_RETRIES ] && + tb_caps[NL802154_CAP_ATTR_MAX_FRAME_RETRIES ]) { +printf ("\tframe_retries: " ); +print_minmax_handler (nla_get_s8 (tb_caps[NL802154_CAP_ATTR_MIN_FRAME_RETRIES ]), +nla_get_s8 (tb_caps[NL802154_CAP_ATTR_MAX_FRAME_RETRIES ])); + } + +if (tb_caps[NL802154_CAP_ATTR_LBT ]) { +printf ("\tlbt: " ); +switch (nla_get_u32 (tb_caps[NL802154_CAP_ATTR_LBT ])) { +case NL802154_SUPPORTED_BOOL_FALSE : +printf ("false\n" ); +break ; +case NL802154_SUPPORTED_BOOL_TRUE : +printf ("true\n" ); +break ; +case NL802154_SUPPORTED_BOOL_BOTH : +printf ("false,true\n" ); +break ; +default : +printf ("unkown\n" ); +break ; + } + } + } +return 0 ; }
src/iwpan.h +2 -0
@@ -118,4 +118,6 @@ int handle_cmd(struct nl802154_state *state, enum id_input idby,DECLARE_SECTION (set);DECLARE_SECTION (get); +const char *iftype_name (enum nl802154_iftype iftype); +#endif /* __IWPAN_H */
src/nl802154.h +79 -0
95 lines not on this page · raw message
Signature · 1 line
2.3.7