interface: add support for extended addr while iface add
Alexander Aring
maintainerPATCH 1/2 interface: add support for extended addr while iface add
This patch adds support for given extended addr while adding a new interface.
Signed-off-by Alexander Aring <[email protected]>
--- src/interface.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-)
src/interface.c +58 -2
@@ -66,6 +66,56 @@ static int get_if_type(int *argc, char ***argv, enum nl802154_iftype *type,return 2 ; } +#define EUI64_ALEN 8 + +static int extendedaddr_a2n (unsigned char *mac_addr,char *arg) +{ +int i; + +for (i =0 ; i <EUI64_ALEN ; i++) { +int temp; +char *cp =strchr (arg,':' ); +if (cp) { + *cp =0 ; + cp++; + } +if (sscanf (arg,"%x" , &temp) !=1 ) +return -1 ; +if (temp <0 || temp >255 ) +return -1 ; + + mac_addr[EUI64_ALEN -1 - i] = temp; +if (!cp) +break ; + arg = cp; + } +if (i <EUI64_ALEN -1 ) +return -1 ; + +return 0 ; +} + +/* return 0 if ok, internal error otherwise */ +static int get_eui64 (int *argc,char ***argv,void *eui64) +{ +int ret; + +if (*argc <1 ) +return 0 ; + + ret =extendedaddr_a2n (eui64, (*argv)[0 ]); +if (ret) { +fprintf (stderr,"invalid extended address\n" ); +return 2 ; + } + + + *argc -=1 ; + *argv +=1 ; + +return 0 ; +} + static int handle_interface_add(struct nl802154_state *state, struct nl_cb *cb, struct nl_msg *msg,
@@ -74,6 +124,7 @@ static int handle_interface_add(struct nl802154_state *state, {char *name;enum nl802154_iftype type; +uint64_t eui64 =0 ;int tpset;if (argc <1 )
@@ -87,22 +138,27 @@ static int handle_interface_add(struct nl802154_state *state,if (tpset)return tpset; + tpset =get_eui64 (&argc, &argv, &eui64); +if (tpset) +return tpset; +if (argc)return 1 ;NLA_PUT_STRING (msg,NL802154_ATTR_IFNAME , name);NLA_PUT_U32 (msg,NL802154_ATTR_IFTYPE , type); +NLA_PUT_U64 (msg,NL802154_ATTR_EXTENDED_ADDR , eui64);return 0 ; nla_put_failure:return -ENOBUFS ; } -COMMAND (interface, add,"<name> type <type>" , +COMMAND (interface, add,"<name> type <type> [extended address <hex as 00:11:..>]" ,NL802154_CMD_NEW_INTERFACE ,0 ,CIB_PHY , handle_interface_add,"Add a new virtual interface with the given configuration.\n" IFACE_TYPES "\n\n" ); -COMMAND (interface, add,"<name> type <type>" , +COMMAND (interface, add,"<name> type <type> [extended address <hex as 00:11:..>]" ,NL802154_CMD_NEW_INTERFACE ,0 ,CIB_NETDEV , handle_interface_add,NULL ); static int handle_interface_del(struct nl802154_state *state,
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 2/2 interface: mac: fix byteorder issues
The kernel except and delivers little endian byteorder. This patch fix the current handling with byteorder.
Signed-off-by Alexander Aring <[email protected]>
--- src/interface.c | 12 ++++++------ src/mac.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-)
src/interface.c +6 -6
@@ -201,15 +201,15 @@ static int print_iface_handler(struct nl_msg *msg, void *arg)if (tb_msg[NL802154_ATTR_WPAN_DEV ])printf ("%s\twpan_dev 0x%llx\n" , indent, (unsigned long long )nla_get_u64 (tb_msg[NL802154_ATTR_WPAN_DEV ])); -/* TODO byteorder? */ if (tb_msg[NL802154_ATTR_EXTENDED_ADDR ]) -printf ("%s\textended_addr 0x%016llx\n" , indent,nla_get_u64 (tb_msg[NL802154_ATTR_EXTENDED_ADDR ])); -/* TODO byteorder? */ +printf ("%s\textended_addr 0x%016llx\n" , indent, +le64toh (nla_get_u64 (tb_msg[NL802154_ATTR_EXTENDED_ADDR ])));if (tb_msg[NL802154_ATTR_SHORT_ADDR ]) -printf ("%s\tshort_addr 0x%04x\n" , indent,nla_get_u16 (tb_msg[NL802154_ATTR_SHORT_ADDR ])); -/* TODO byteorder? */ +printf ("%s\tshort_addr 0x%04x\n" , indent, +le16toh (nla_get_u16 (tb_msg[NL802154_ATTR_SHORT_ADDR ])));if (tb_msg[NL802154_ATTR_PAN_ID ]) -printf ("%s\tpan_id 0x%04x\n" , indent,nla_get_u16 (tb_msg[NL802154_ATTR_PAN_ID ])); +printf ("%s\tpan_id 0x%04x\n" , indent, +le16toh (nla_get_u16 (tb_msg[NL802154_ATTR_PAN_ID ])));if (tb_msg[NL802154_ATTR_IFTYPE ])printf ("%s\ttype %s\n" , indent,iftype_name (nla_get_u32 (tb_msg[NL802154_ATTR_IFTYPE ])));if (!wpan_phy && tb_msg[NL802154_ATTR_WPAN_PHY ])
src/mac.c +2 -2
@@ -30,7 +30,7 @@ static int handle_pan_id_set(struct nl802154_state *state,if (*end !='\0' )return 1 ; -NLA_PUT_U16 (msg,NL802154_ATTR_PAN_ID , pan_id); +NLA_PUT_U16 (msg,NL802154_ATTR_PAN_ID ,htole16 (pan_id));return 0 ;
@@ -57,7 +57,7 @@ static int handle_short_addr_set(struct nl802154_state *state,if (*end !='\0' )return 1 ; -NLA_PUT_U16 (msg,NL802154_ATTR_SHORT_ADDR , short_addr); +NLA_PUT_U16 (msg,NL802154_ATTR_SHORT_ADDR ,htole16 (short_addr));return 0 ;
Signature · 1 line
2.1.3