[OpenWrt-Devel] [PATCH v2] Add support for QMI-based mobile broadband modems

2014-05-26 Thread Matti Laakso
Many of the 4G/LTE and 3G modems utilize the QMI-protocol to control the
modem. At the moment there is no support for them in OpenWrt. This
patch adds support for them in the form of a netifd script and a
control utility. Tested with Huawei E398 and ZTE MF820D (which requires
a delay of ~30 s before responding to QMI commands). I put myself up as
the maintainer, feel free to change this if you desire.

Changes to RFC version:
- Patch split into two
- Improved netifd script
- Minor fixes to uqmi command line help
- Fixed autoconnect in uqmi
- Fixed printing service versions in uqmi

v2:
- Uses subprotocols instead of including entire dhcp.sh, therefore
removed netifd patch
- Makes while loops less nasty by looping on expected conditions only,
avoids infinite loops in unexpected conditions

Signed-off-by: Matti Laakso malaa...@elisanet.fi
---

diff --git a/package/network/utils/uqmi/Makefile 
b/package/network/utils/uqmi/Makefile
new file mode 100644
index 000..c66de85
--- /dev/null
+++ b/package/network/utils/uqmi/Makefile
@@ -0,0 +1,48 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=uqmi
+PKG_VERSION:=2013-06-23
+PKG_RELEASE=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=git://nbd.name/uqmi.git
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=35201737484008ac802649cbe9fb5f7ab38a4ad2
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
+PKG_MAINTAINER:=Matti Laakso malaa...@elisanet.fi
+# PKG_MIRROR_MD5SUM:=
+# CMAKE_INSTALL:=1
+
+PKG_LICENSE:=GPLv2
+PKG_LICENSE_FILES:=
+
+PKG_BUILD_PARALLEL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/uqmi
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:=+libubox +libblobmsg-json
+  TITLE:=Control utility for mobile broadband modems
+endef
+
+define Package/uqmi/description
+  uqmi is a command line tool for controlling mobile broadband modems using 
+  the QMI-protocol.
+endef
+
+TARGET_CFLAGS += \
+   -I$(STAGING_DIR)/usr/include
+
+CMAKE_OPTIONS += \
+   -DDEBUG=1
+
+define Package/uqmi/install
+   $(INSTALL_DIR) $(1)/sbin
+   $(INSTALL_BIN) $(PKG_BUILD_DIR)/uqmi $(1)/sbin/
+   $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,uqmi))
diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh 
b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
new file mode 100755
index 000..971adeb
--- /dev/null
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -0,0 +1,137 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto $@
+
+proto_qmi_init_config() {
+   proto_config_add_string device:device
+   proto_config_add_string apn
+   proto_config_add_string auth
+   proto_config_add_string username
+   proto_config_add_string password
+   proto_config_add_string pincode
+   proto_config_add_string delay
+   proto_config_add_string modes
+}
+
+proto_qmi_setup() {
+   local interface=$1
+   
+   local device apn auth username password pincode delay modes cid pdh
+   json_get_vars device apn auth username password pincode delay modes
+
+   [ -n $device ] || {
+   logger -p daemon.err -t qmi[$$] No control device specified
+   proto_notify_error $interface NO_DEVICE
+   proto_block_restart $interface
+   return 1
+   }
+   [ -c $device ] || {
+   logger -p daemon.err -t qmi[$$] The specified control device 
does not exist
+   proto_notify_error $interface NO_DEVICE
+   proto_block_restart $interface
+   return 1
+   }
+   
+   [ -n $delay ]  sleep $delay
+   
+   while uqmi -s -d $device --get-pin-status | grep 'UIM 
uninitialized'  /dev/null; do
+   sleep 1;
+   done
+   
+   [ -n $pincode ]  {
+   uqmi -s -d $device --verify-pin1 $pincode || {
+   logger -p daemon.err -t qmi[$$] Unable to verify PIN
+   proto_notify_error $interface PIN_FAILED
+   proto_block_restart $interface
+   return 1
+   }
+   }
+   
+   [ -n $apn ] || {
+   logger -p daemon.err -t qmi[$$] No APN specified
+   proto_notify_error $interface NO_APN
+   proto_block_restart $interface
+   return 1
+   }
+   
+   logger -p daemon.info -t qmi[$$] Waiting for network registration
+   while uqmi -s -d $device --get-serving-system | grep 'searching'  
/dev/null; do
+   sleep 5;
+   done
+   
+   [ -n $modes ]  uqmi -s -d $device --set-network-modes $modes
+   
+   logger -p daemon.info -t qmi[$$] Starting network $apn
+   cid=`uqmi -s -d $device --get-client-id wds`
+   [ $? -ne 0 ]  {
+   logger -p daemon.err -t qmi[$$] Unable to obtain client ID
+   proto_notify_error $interface NO_CID
+   

Re: [OpenWrt-Devel] [PATCH v2] Add support for QMI-based mobile broadband modems

2014-05-26 Thread Felix Fietkau
On 2014-05-26 21:49, Matti Laakso wrote:
 Many of the 4G/LTE and 3G modems utilize the QMI-protocol to control the
 modem. At the moment there is no support for them in OpenWrt. This
 patch adds support for them in the form of a netifd script and a
 control utility. Tested with Huawei E398 and ZTE MF820D (which requires
 a delay of ~30 s before responding to QMI commands). I put myself up as
 the maintainer, feel free to change this if you desire.
 
 Changes to RFC version:
 - Patch split into two
 - Improved netifd script
 - Minor fixes to uqmi command line help
 - Fixed autoconnect in uqmi
 - Fixed printing service versions in uqmi
 
 v2:
 - Uses subprotocols instead of including entire dhcp.sh, therefore
 removed netifd patch
 - Makes while loops less nasty by looping on expected conditions only,
 avoids infinite loops in unexpected conditions
 
 Signed-off-by: Matti Laakso malaa...@elisanet.fi
Thanks for doing this, looks good.
Please submit the uqmi changes as a separate series against my git tree,
instead of adding them as patches to the OpenWrt package.

- Felix
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel