From patchwork Sun Mar 5 17:06:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Moc X-Patchwork-Id: 735462 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vbq9R5Phzz9s83 for ; Mon, 6 Mar 2017 04:07:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="j3tYkdAb"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version: Message-ID:To:From:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: References:List-Owner; bh=3iv+8GdZHjadUO9qowjQDgWZGJ+4G39DTWp0lrIBzFY=; b=j3t YkdAb5rhw4xScdxPLWgPDyKpSiBipAVcxoUea/k75PL/q5CrbdO8LxwL0MYt+8u1010U3mMXKbAzD 7dyPB+U1N/zGITQ3kARYNhWG0FbCwgkExcWP+BNcUOzVW4uFukKXgbM83AKBrXA9w86TkmHq9tafg rTZreONxkKRvFzzc1PgSfKuc4iMeB0/JL+4clGDipE0moIUi3I9AKc6r0vT2QbwS7FK+eDJvbKCVL l+e5redgm21u5JtCwZV/ctjIibrHAyul535zbUxriDbeXX+xfIZtfa+fj908YoaCci3TymSvK6JzW 4/lzAsq9eHmT/ITAoOqplGsAs/iNYvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ckZd3-0003bK-QZ; Sun, 05 Mar 2017 17:07:29 +0000 Received: from [2a02:768:2100:966:250:fcff:feb6:91f7] (helo=moc6.cz) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckZcd-0003ZW-7u for lede-dev@lists.infradead.org; Sun, 05 Mar 2017 17:07:05 +0000 Received: by moc6.cz (Postfix, from userid 1025) id 5821423225DD; Sun, 5 Mar 2017 18:06:41 +0100 (CET) Date: Sun, 5 Mar 2017 18:06:41 +0100 From: Filip Moc To: lede-dev@lists.infradead.org Message-ID: <20170305170641.GA29987@moc6.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170305170320.GA29725@moc6.cz> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170305_090703_653664_6599047F X-CRM114-Status: GOOD ( 11.20 ) X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Subject: [LEDE-DEV] [PATCH v3 2/2] Move enablemodem from ramips to new package adb-enablemodem and make it used also by TL-MR6400 X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Filip Moc --- Notes: This moves enablemodem from ramips to new package adb-enablemodem. New adb-enablemodem uses modem's id rather than main board's name so it could possibly work even on different boards without need to change anything. Fixes: - Problem when modem is not responding causing adb to wait indefinitely and blocking boot process. - Asterisk path expansion. - Possible race condition when there are more devices attached. New features: - Logging - Stopping httpd v2->v3: - Less insane code for closing filedescriptors package/network/utils/adb-enablemodem/Makefile | 26 +++++++++ .../utils/adb-enablemodem/files/adb-enablemodem | 64 ++++++++++++++++++++++ target/linux/ar71xx/image/tp-link.mk | 2 +- .../linux/ramips/base-files/etc/init.d/enablemodem | 17 ------ target/linux/ramips/image/mt7620.mk | 2 +- 5 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 package/network/utils/adb-enablemodem/Makefile create mode 100644 package/network/utils/adb-enablemodem/files/adb-enablemodem delete mode 100755 target/linux/ramips/base-files/etc/init.d/enablemodem diff --git a/package/network/utils/adb-enablemodem/Makefile b/package/network/utils/adb-enablemodem/Makefile new file mode 100644 index 0000000..3ffc64a --- /dev/null +++ b/package/network/utils/adb-enablemodem/Makefile @@ -0,0 +1,26 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=adb-enablemodem +PKG_VERSION:=2017-03-05 +PKG_RELEASE:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/adb-enablemodem + SECTION:=net + CATEGORY:=Network + SUBMENU:=WWAN + TITLE:=Enable modem via adb + DEPENDS:=+adb +endef + +define Build/Compile + true +endef + +define Package/adb-enablemodem/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/adb-enablemodem $(1)/etc/init.d/adb-enablemodem +endef + +$(eval $(call BuildPackage,adb-enablemodem)) diff --git a/package/network/utils/adb-enablemodem/files/adb-enablemodem b/package/network/utils/adb-enablemodem/files/adb-enablemodem new file mode 100644 index 0000000..ddfc681 --- /dev/null +++ b/package/network/utils/adb-enablemodem/files/adb-enablemodem @@ -0,0 +1,64 @@ +#!/bin/sh /etc/rc.common + +START=99 + +adb_exec() { + adb -s "$serial" shell "( $1 ) >/dev/null 2>&1"'; printf "\nEXIT_CODE: %i\n" $?' | head -c 64 | grep -qx 'EXIT_CODE: 0\r\?' +} + +enablemodem_do() { + logger -t adb-enablemodem 'INFO: waiting for device' + adb wait-for-device + serial="$(adb get-serialno)" + + vendor_id="$(adb -s "$serial" shell 'uci get product.usb.vid' | head -c 16 | tr -d '\r\n')" + product_id="$(adb -s "$serial" shell 'uci get product.usb.pid' | head -c 16 | tr -d '\r\n')" + + case "$vendor_id:$product_id" in + "0x2357:0x000D") # TP-LINK LTE MODULE + case "$1" in + start) + if adb_exec ' + chmod +x /WEBSERVER/www/cgi-bin/* + fds="$(ls /proc/$$/fd | grep -v "^[012]$")" + for fd in $fds; do + eval "exec $fd>&-" + done + start-stop-daemon -x httpd -S -- -h /WEBSERVER/www/ + '; then + logger -t adb-enablemodem 'INFO: httpd on modem started' + else + logger -t adb-enablemodem 'ERROR: failed to start httpd on modem' + fi + option_newid='/sys/bus/usb-serial/drivers/option1/new_id' + if [ -e "$option_newid" ]; then + printf '%s %s' "$vendor_id" "$product_id" > "$option_newid" + fi + ;; + stop) + if adb_exec 'start-stop-daemon -x httpd -K'; then + logger -t adb-enablemodem 'INFO: httpd on modem stopped' + else + logger -t adb-enablemodem 'ERROR: failed to stop httpd on modem' + fi + ;; + esac + ;; + *) + logger -t adb-enablemodem "ERROR: unknown device $vendor_id:$product_id" + ;; + esac +} + +start() { + ( enablemodem_do start ) & +} + +stop() { + ( enablemodem_do stop ) & +} + +restart() { + ( enablemodem_do stop; enablemodem_do start ) & +} + diff --git a/target/linux/ar71xx/image/tp-link.mk b/target/linux/ar71xx/image/tp-link.mk index 2a0b06a..a8b39a0 100644 --- a/target/linux/ar71xx/image/tp-link.mk +++ b/target/linux/ar71xx/image/tp-link.mk @@ -455,7 +455,7 @@ TARGET_DEVICES += tl-mr3020-v1 tl-mr3040-v1 tl-mr3040-v2 tl-mr3220-v1 tl-mr3220- define Device/tl-mr6400-v1 $(Device/tplink-8mlzma) DEVICE_TITLE := TP-LINK TL-MR6400 v1 - DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-net kmod-usb-net-rndis kmod-usb-serial kmod-usb-serial-option adb + DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-net kmod-usb-net-rndis kmod-usb-serial kmod-usb-serial-option adb-enablemodem BOARDNAME := TL-MR6400 DEVICE_PROFILE := TLMR6400 TPLINK_HWID := 0x64000001 diff --git a/target/linux/ramips/base-files/etc/init.d/enablemodem b/target/linux/ramips/base-files/etc/init.d/enablemodem deleted file mode 100755 index ba54cc4..0000000 --- a/target/linux/ramips/base-files/etc/init.d/enablemodem +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=99 - -start() { - . /lib/ramips.sh - - local board=$(ramips_board_name) - if [ $board = "mr200" ]; then - adb wait-for-device - adb shell chmod +x /WEBSERVER/www/cgi-bin/* - adb shell httpd -h /WEBSERVER/www/ & - echo "2357 000d" > /sys/bus/usb-serial/drivers/option1/new_id - sleep 2 - adb kill-server - fi -} diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk index 9a2941c..b9d6e98 100644 --- a/target/linux/ramips/image/mt7620.mk +++ b/target/linux/ramips/image/mt7620.mk @@ -46,7 +46,7 @@ define Device/ArcherMR200 KERNEL := $(KERNEL_DTB) KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-header ArcherMR200 -c IMAGE/sysupgrade.bin := append-kernel | tplink-header ArcherMR200 -j | append-metadata - DEVICE_PACKAGES := kmod-usb2 kmod-usb-net kmod-usb-net-rndis kmod-usb-serial kmod-usb-serial-option adb + DEVICE_PACKAGES := kmod-usb2 kmod-usb-net kmod-usb-net-rndis kmod-usb-serial kmod-usb-serial-option adb-enablemodem DEVICE_TITLE := TP-Link ArcherMR200 endef TARGET_DEVICES += ArcherMR200