Move enablemodem from ramips to new package adb-enablemodem and make it used also...
authorFilip Moc <lede@moc6.cz>
Thu, 25 May 2017 19:55:32 +0000 (21:55 +0200)
committerJohn Crispin <john@phrozen.org>
Sat, 27 May 2017 05:54:40 +0000 (07:54 +0200)
Signed-off-by: Filip Moc <lede@moc6.cz>
package/network/utils/adb-enablemodem/Makefile [new file with mode: 0644]
package/network/utils/adb-enablemodem/files/adb-enablemodem [new file with mode: 0644]
target/linux/ar71xx/image/tp-link.mk
target/linux/ramips/base-files/etc/init.d/enablemodem [deleted file]
target/linux/ramips/image/mt7620.mk

diff --git a/package/network/utils/adb-enablemodem/Makefile b/package/network/utils/adb-enablemodem/Makefile
new file mode 100644 (file)
index 0000000..3ffc64a
--- /dev/null
@@ -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 (file)
index 0000000..ddfc681
--- /dev/null
@@ -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 ) &
+}
+
index f27ceec3e9ef2fddc022a16c6c4e6038f7135d3e..95bde34383f4ff693e6d361b6e797d028f334262 100644 (file)
@@ -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 (executable)
index ba54cc4..0000000
+++ /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
-}
index 73f91cfedd3827329b8e94f2db166ca7a857e6d4..e0f563e1b00b05f38ae1c0660db32797a00d8d90 100644 (file)
@@ -58,7 +58,7 @@ define Device/ArcherMR200
   KERNEL := $(KERNEL_DTB)
   KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-header ArcherMR200 -c
   IMAGE/sysupgrade.bin := append-kernel | tplink-header ArcherMR200 -j -s | 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