linux-wpan.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH wpan-tools 1/2] interface: add support for extended addr while iface add
@ 2014-11-16 20:05 Alexander Aring
  2014-11-16 20:05 ` [PATCH wpan-tools 2/2] interface: mac: fix byteorder issues Alexander Aring
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Aring @ 2014-11-16 20:05 UTC (permalink / raw)
  To: linux-wpan; +Cc: Alexander Aring

This patch adds support for given extended addr while adding a new interface.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 src/interface.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/src/interface.c b/src/interface.c
index 40c18ef..0ac9c5a 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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,
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH wpan-tools 2/2] interface: mac: fix byteorder issues
  2014-11-16 20:05 [PATCH wpan-tools 1/2] interface: add support for extended addr while iface add Alexander Aring
@ 2014-11-16 20:05 ` Alexander Aring
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Aring @ 2014-11-16 20:05 UTC (permalink / raw)
  To: linux-wpan; +Cc: Alexander Aring

The kernel except and delivers little endian byteorder. This patch fix
the current handling with byteorder.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 src/interface.c | 12 ++++++------
 src/mac.c       |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/interface.c b/src/interface.c
index 0ac9c5a..095753b 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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])
diff --git a/src/mac.c b/src/mac.c
index 3f2dfc8..703d09f 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -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;
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-16 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-16 20:05 [PATCH wpan-tools 1/2] interface: add support for extended addr while iface add Alexander Aring
2014-11-16 20:05 ` [PATCH wpan-tools 2/2] interface: mac: fix byteorder issues Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).