support IPv6 configuration
authorBjørn Mork <bjorn@mork.no>
Wed, 8 Apr 2015 13:31:23 +0000 (15:31 +0200)
committerJohn Crispin <blogic@openwrt.org>
Fri, 3 Apr 2015 08:33:36 +0000 (10:33 +0200)
Signed-off-by: Bjørn Mork <bjorn@mork.no>
cli.c
mbim-msg.c
mbim-msg.h

diff --git a/cli.c b/cli.c
index c43b4f3ed180506ba9a7e12ce18d38a7d366c782..d1f3e88dc5ccbdadd6b46035113f605c2991503c 100644 (file)
--- 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;
 }
index 7199e85148bce0fcf090bb051bdb6698631d886f..ad5a2d5dcd9adcc026e8dd3347916c2895d0b93f 100644 (file)
@@ -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)
index 25415a5b2813487f50b531ccd9b14fae136aea70..2957abb46d1bcaa3a3431ce23e1cce54a6bf1d3b 100644 (file)
@@ -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