From patchwork Wed Apr 8 13:31:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 459276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F0F2814009B for ; Wed, 8 Apr 2015 23:36:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=mork.no header.i=@mork.no header.b=QnrMJkqZ; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8781628C74B; Wed, 8 Apr 2015 15:32:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 7FF8C28BFAD; Wed, 8 Apr 2015 15:30:54 +0200 (CEST) X-policyd-weight: using cached result; rate:hard: -7.6 X-policyd-weight: using cached result; rate:hard: -7.6 Received: from canardo.mork.no (canardo.mork.no [148.122.252.1]) by arrakis.dune.hu (Postfix) with ESMTPS; Wed, 8 Apr 2015 15:30:46 +0200 (CEST) Received: from nemi.mork.no (ip6-localhost [IPv6:::1]) by canardo.mork.no (8.14.4/8.14.4) with ESMTP id t38DVUBd022136 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 8 Apr 2015 15:31:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=a; t=1428499891; bh=IdTeWWH6RHDfKQigycUuwbDP6ipT/5qtw/G0+LvG6ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QnrMJkqZ7PP/1lWDGioxKOXtudLZ7bvgJ5CxV+ZUU/JxNlGGsXxniJbqmUPcKUPZE x2eVkctaUDkoIY3guQC51pL/Ne/8fsvhC2RWkyW7j97EdExQDiejcJwx+nhMMt4jG2 Bf59Nkn7OjFa9N1qDmWMEtn5TGIBeq7G63elWqSbFM7xBJn7NkS9sX9mQ9BcgKtJtS J845jyo4kNByyAnXbIF8cw9/CVRjQNnupEyxSy5qJonQ9Igxp84s7q++iWudYTE1Nk wECHKOBNtBETb5BphtH3nrbxIlye8MMWsqI/glIHq/viEmjn7P5vc1BkJKtyxZMZ+F kC8wrEN+pb16g== Received: from bjorn by nemi.mork.no with local (Exim 4.84) (envelope-from ) id 1Yfq4o-00008a-OK; Wed, 08 Apr 2015 15:31:30 +0200 From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= To: John Crispin Date: Wed, 8 Apr 2015 15:31:23 +0200 Message-Id: <1428499884-465-7-git-send-email-bjorn@mork.no> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428499884-465-1-git-send-email-bjorn@mork.no> References: <87d23g42o4.fsf@nemi.mork.no> <1428499884-465-1-git-send-email-bjorn@mork.no> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (canardo.mork.no [IPv6:::1]); Wed, 08 Apr 2015 15:31:31 +0200 (CEST) X-Virus-Scanned: clamav-milter 0.98.5 at canardo X-Virus-Status: Clean Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH v2 6/7] support IPv6 configuration X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Bjørn Mork --- 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