[OpenWrt-Devel] [PATCH v2 6/7] support IPv6 configuration
Bjørn Mork
bjorn at mork.no
Wed Apr 8 09:31:23 EDT 2015
Signed-off-by: Bjørn Mork <bjorn at mork.no>
---
cli.c | 32 ++++++++++++++++++++++++--------
mbim-msg.c | 10 ++++++++++
mbim-msg.h | 1 +
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/cli.c b/cli.c
index c43b4f3..d1f3e88 100644
--- a/cli.c
+++ b/cli.c
@@ -216,7 +216,7 @@ static int
mbim_config_response(void *buffer, int len)
{
struct mbim_basic_connect_ip_configuration_r *ip = (struct mbim_basic_connect_ip_configuration_r *) buffer;
- char ipv4[16];
+ char out[40];
int i;
uint32_t offset;
@@ -228,22 +228,38 @@ mbim_config_response(void *buffer, int len)
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
for (i = 0; i < le32toh(ip->ipv4addresscount); i++) {
offset = le32toh(ip->ipv4address) + (i * 4);
- mbim_get_ipv4(buffer, ipv4, 4 + offset);
- printf(" ipv4address: %s/%d\n", ipv4, mbim_get_int(buffer, offset));
+ mbim_get_ipv4(buffer, out, 4 + offset);
+ printf(" ipv4address: %s/%d\n", out, mbim_get_int(buffer, offset));
}
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
- mbim_get_ipv4(buffer, ipv4, ip->ipv4gateway);
- printf(" ipv4gateway: %s\n", ipv4);
+ mbim_get_ipv4(buffer, out, le32toh(ip->ipv4gateway));
+ printf(" ipv4gateway: %s\n", out);
}
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
printf(" ipv4mtu: %d\n", le32toh(ip->ipv4mtu));
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
for (i = 0; i < le32toh(ip->ipv4dnsservercount); i++) {
- mbim_get_ipv4(buffer, ipv4, ip->ipv4dnsserver + (i * 4));
- printf(" ipv4dnsserver: %s\n", ipv4);
+ mbim_get_ipv4(buffer, out, le32toh(ip->ipv4dnsserver) + (i * 4));
+ printf(" ipv4dnsserver: %s\n", out);
}
- printf(" ipv6configurationavailable: %04X\n", le32toh(ip->ipv6configurationavailable));
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
+ for (i = 0; i < le32toh(ip->ipv6addresscount); i++) {
+ offset = le32toh(ip->ipv6address) + (i * 16);
+ mbim_get_ipv6(buffer, out, 4 + offset);
+ printf(" ipv6address: %s/%d\n", out, mbim_get_int(buffer, offset));
+ }
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
+ mbim_get_ipv6(buffer, out, le32toh(ip->ipv6gateway));
+ printf(" ipv6gateway: %s\n", out);
+ }
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
+ printf(" ipv6mtu: %d\n", le32toh(ip->ipv6mtu));
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
+ for (i = 0; i < le32toh(ip->ipv6dnsservercount); i++) {
+ mbim_get_ipv6(buffer, out, le32toh(ip->ipv6dnsserver) + (i * 16));
+ printf(" ipv6dnsserver: %s\n", out);
+ }
return 0;
}
diff --git a/mbim-msg.c b/mbim-msg.c
index 7199e85..ad5a2d5 100644
--- a/mbim-msg.c
+++ b/mbim-msg.c
@@ -97,6 +97,16 @@ mbim_get_ipv4(void *buffer, char *out, uint32_t offset)
snprintf(out, 16, "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
}
+void
+mbim_get_ipv6(void *buffer, char *out, uint32_t offset)
+{
+ uint8_t *b = buffer + offset;
+
+ snprintf(out, 40, "%x:%x:%x:%x:%x:%x:%x:%x", b[0] << 8 | b[1],
+ b[2] << 8 | b[3], b[4] << 8 | b[5], b[6] << 8 | b[7],
+ b[8] << 8 | b[9], b[10] << 8 | b[11], b[12] << 8 | b[13],
+ b[14] << 8 | b[15]);
+}
uint32_t
mbim_get_int(void *buffer, uint32_t offset)
diff --git a/mbim-msg.h b/mbim-msg.h
index 25415a5..2957abb 100644
--- a/mbim-msg.h
+++ b/mbim-msg.h
@@ -94,6 +94,7 @@ int mbim_send_command_msg(void);
int mbim_add_payload(uint8_t len);
int mbim_encode_string(struct mbim_string *str, char *in);
void mbim_get_ipv4(void *buffer, char *out, uint32_t offset);
+void mbim_get_ipv6(void *buffer, char *out, uint32_t offset);
uint32_t mbim_get_int(void *buffer, uint32_t offset);
#endif
--
2.1.4
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list