From patchwork Thu Feb 18 17:12:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Randolf X-Patchwork-Id: 584815 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 50670140773 for ; Fri, 19 Feb 2016 04:12:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=einfach.org header.i=@einfach.org header.b=IuX5+T+Z; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 1313028C689; Thu, 18 Feb 2016 18:12:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 5B12628C685 for ; Thu, 18 Feb 2016 18:12:41 +0100 (CET) X-policyd-weight: using cached result; rate: -7.6 Received: from postler.einfach.org (postler.einfach.org [5.9.2.179]) by arrakis.dune.hu (Postfix) with ESMTP for ; Thu, 18 Feb 2016 18:12:41 +0100 (CET) Received: from localhost.localdomain (unknown [188.85.43.69]) by postler.einfach.org (Postfix) with ESMTPA id 8E1F561A; Thu, 18 Feb 2016 17:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=einfach.org; s=mail; t=1455815562; bh=f8Lra2ggsQH443cejjtGowky7xtq/GEReXVwITJVUBA=; h=From:To:Cc:Subject:Date; b=IuX5+T+ZImHZFH6LG5HKW/g90HLpgHwTZulG+dvtNAuc/EciFEVBeY2ECfHWTj55N W3k3cQJMDzHBBX125Kk4G36lKd1VGnRkp5cmFV0puSz5C7nx0+3mvGD+/jelSMHRHx LwBJos+V33bBpTTc6p7ikOvjpB5bzu9Ynic1bT+U= From: Bruno Randolf To: openwrt-devel@lists.openwrt.org Date: Thu, 18 Feb 2016 17:12:25 +0000 Message-Id: <1455815546-17544-1-git-send-email-br1@einfach.org> X-Mailer: git-send-email 1.9.1 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (postler.einfach.org [0.0.0.0]); Thu, 18 Feb 2016 17:12:42 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.98.7 at bced1da0f74a X-Virus-Status: Clean Cc: Bruno Randolf , steven@midlink.org Subject: [OpenWrt-Devel] [PATCH 1/2] wwan: Add support for CDC (Huawei 'HiLink') Modems 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: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Huawei HiLink ("h" model names) modems just provide a CDC Ethernet interface where we have to run DHCP to get an IP address (usually in the 192.168.8.0 range). While this may be bad design in general it's sometimes necessary to support these modems. This adds autodetection and handling of these to wwan. Tested with Huawei E3030h-1. Signed-off-by: Bruno Randolf --- package/network/utils/wwan/Makefile | 3 +- package/network/utils/wwan/files/hilink.sh | 56 ++++++++++++++++++++++++++++++ package/network/utils/wwan/files/wwan.sh | 9 ++++- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 package/network/utils/wwan/files/hilink.sh diff --git a/package/network/utils/wwan/Makefile b/package/network/utils/wwan/Makefile index 8d388dc..1917d1c 100644 --- a/package/network/utils/wwan/Makefile +++ b/package/network/utils/wwan/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=wwan PKG_VERSION:=2014-07-17 -PKG_RELEASE=1 +PKG_RELEASE=3 PKG_LICENSE:=GPL-2.0 PKG_LICENSE_FILES:= @@ -24,6 +24,7 @@ endef define Package/wwan/install $(INSTALL_DIR) $(1)/lib/netifd/proto/ $(CP) ./files/wwan.sh $(1)/lib/netifd/proto/ + $(CP) ./files/hilink.sh $(1)/lib/netifd/proto/ $(INSTALL_DIR) $(1)/etc/hotplug.d/usb $(INSTALL_BIN) ./files/wwan.usb $(1)/etc/hotplug.d/usb/00_wwan.sh $(INSTALL_DIR) $(1)/etc/hotplug.d/usbmisc diff --git a/package/network/utils/wwan/files/hilink.sh b/package/network/utils/wwan/files/hilink.sh new file mode 100644 index 0000000..229e1a4 --- /dev/null +++ b/package/network/utils/wwan/files/hilink.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +[ -n "$INCLUDE_ONLY" ] || { + . /lib/functions.sh + . ../netifd-proto.sh + init_proto "$@" +} + +proto_hilink_init_config() { + available=1 + no_device=1 + proto_config_add_boolean defaultroute + proto_config_add_boolean peerdns + proto_config_add_int metric +} + +proto_hilink_setup() { + local interface="$1" + local ifname="$ctl_device" + local defaultroute peerdns metric + + json_get_vars defaultroute peerdns metric + + [ -n "$ifname" ] || { + proto_notify_error "$interface" NO_IFNAME + proto_set_available "$interface" 0 + return 1 + } + + logger -p daemon.info -t "hilink[$$]" "Starting DHCP on $ifname" + proto_init_update "$ifname" 1 + proto_send_update "$interface" + + json_init + json_add_string name "${interface}_4" + json_add_string ifname "@$interface" + json_add_string proto "dhcp" + [ -n "$defaultroute" ] && json_add_boolean defaultroute "$defaultroute" + [ -n "$peerdns" ] && json_add_boolean peerdns "$peerdns" + [ -n "$metric" ] && json_add_int metric "$metric" + json_close_object + ubus call network add_dynamic "$(json_dump)" + + return 0 +} + +proto_hilink_teardown() { + local interface="$1" + + proto_init_update "*" 0 + proto_send_update "$interface" +} + +[ -n "$INCLUDE_ONLY" ] || { + add_protocol hilink +} diff --git a/package/network/utils/wwan/files/wwan.sh b/package/network/utils/wwan/files/wwan.sh index 6b33600..3d80aba 100755 --- a/package/network/utils/wwan/files/wwan.sh +++ b/package/network/utils/wwan/files/wwan.sh @@ -14,12 +14,14 @@ proto_qmi_setup() { echo "wwan[$$] qmi proto is missing"; } proto_ncm_setup() { echo "wwan[$$] ncm proto is missing"; } proto_3g_setup() { echo "wwan[$$] 3g proto is missing"; } proto_directip_setup() { echo "wwan[$$] directip proto is missing"; } +proto_hilink_setup() { echo "wwan[$$] hilink proto is missing"; } [ -f ./mbim.sh ] && . ./mbim.sh [ -f ./ncm.sh ] && . ./ncm.sh [ -f ./qmi.sh ] && . ./qmi.sh [ -f ./3g.sh ] && { . ./ppp.sh; . ./3g.sh; } [ -f ./directip.sh ] && . ./directip.sh +[ -f ./hilink.sh ] && . ./hilink.sh proto_wwan_init_config() { available=1 @@ -66,7 +68,7 @@ proto_wwan_setup() { } } - [ -z "$ctl_device" ] && for net in $(ls /sys/class/net/ | grep wwan); do + [ -z "$ctl_device" ] && for net in $(ls /sys/class/net/ | grep -E "wwan|eth"); do [ -z "$ctl_device" ] || continue driver=$(grep DRIVER /sys/class/net/$net/device/uevent | cut -d= -f2) case "$driver" in @@ -76,6 +78,9 @@ proto_wwan_setup() { sierra_net|*cdc_ncm) ctl_device=/dev/$(cd /sys/class/net/$net/; find ../../../ -name ttyUSB* |xargs basename | head -n1) ;; + cdc_ether) + ctl_device=$net + ;; *) continue;; esac echo "wwan[$$]" "Using proto:$proto device:$ctl_device iface:$net desc:$desc" @@ -98,6 +103,7 @@ proto_wwan_setup() { sierra_net) proto_directip_setup $@ ;; comgt) proto_3g_setup $@ ;; *cdc_ncm) proto_ncm_setup $@ ;; + cdc_ether) proto_hilink_setup $@ ;; esac } @@ -113,6 +119,7 @@ proto_wwan_teardown() { sierra_net) proto_mbim_teardown $@ ;; comgt) proto_3g_teardown $@ ;; *cdc_ncm) proto_ncm_teardown $@ ;; + cdc_ether) proto_hilink_teardown $@ ;; esac }