summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteffen Ritter <steffen.ritter@stz-bt.de>2010-11-04 14:23:32 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2010-11-04 14:42:59 +0100
commit1ca0c45409a3f0bd1c75b9201aca07644e11597b (patch)
tree98f2ace253a2e1b3ac0a272a8b24fc6e61333a03
parentcb78e74dce8c998fe4075d998def392f03a25876 (diff)
added huawei control utility
Signed-off-by: Steffen Ritter <steffen.ritter@stz-bt.de>
-rw-r--r--package/huawei/Makefile33
-rw-r--r--package/huawei/src/huawei.c95
2 files changed, 128 insertions, 0 deletions
diff --git a/package/huawei/Makefile b/package/huawei/Makefile
new file mode 100644
index 000000000..603500a88
--- /dev/null
+++ b/package/huawei/Makefile
@@ -0,0 +1,33 @@
+# This file is part of the OpenADK project. OpenADK is copyrighted
+# material, please see the LICENCE file in the top-level directory.
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:= huawei
+PKG_VERSION:= 0.1
+PKG_RELEASE:= 1
+PKG_DESCR:= huawei modem control
+PKG_SECTION:= utils
+PKG_DEPENDS:= libusb
+PKG_BUILDDEP+= libusb
+
+NO_DISTFILES:= 1
+
+
+include $(TOPDIR)/mk/package.mk
+
+$(eval $(call PKG_template,HUAWEI,$(PKG_NAME),$(PKG_VERSION)-${PKG_RELEASE},${PKG_DEPENDS},${PKG_DESCR},${PKG_SECTION}))
+
+CONFIG_STYLE:= manual
+BUILD_STYLE:= manual
+INSTALL_STYLE:= manual
+
+do-build:
+ ${TARGET_CC} -Wall ${TCPPFLAGS} ${TCFLAGS} \
+ -o ${WRKBUILD}/huawei ${WRKBUILD}/huawei.c -lusb
+
+do-install:
+ ${INSTALL_DIR} ${IDIR_HUAWEI}/sbin
+ ${INSTALL_BIN} ${WRKBUILD}/huawei ${IDIR_HUAWEI}/sbin
+
+include ${TOPDIR}/mk/pkg-bottom.mk
diff --git a/package/huawei/src/huawei.c b/package/huawei/src/huawei.c
new file mode 100644
index 000000000..09c905085
--- /dev/null
+++ b/package/huawei/src/huawei.c
@@ -0,0 +1,95 @@
+/* HUAWEI 3G modems activator
+ Copyright (C) 2006 bobovsky bobovsky@kanoistika.sk GPL
+ Copyright (C) 2009 Nuno Goncalves nunojpg@gmail.com GPL
+ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License2.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <signal.h>
+#include <ctype.h>
+#include <usb.h>
+
+struct usb_dev_handle *devh;
+
+void release_usb_device(int dummy) {
+ int ret;
+ ret = usb_release_interface(devh, 0);
+
+ if (!ret)
+ printf("failed to release interface: %d\n", ret);
+
+ usb_close(devh);
+
+ if (!ret)
+ printf("failed to close interface: %d\n", ret);
+
+ exit(1);
+}
+
+void list_devices() {
+ struct usb_bus *bus;
+ for (bus = usb_get_busses(); bus; bus = bus->next) {
+ struct usb_device *dev;
+
+ for (dev = bus->devices; dev; dev = dev->next)
+ printf("0x%04x 0x%04x\n", dev->descriptor.idVendor, dev->descriptor.idProduct);
+ }
+}
+
+struct usb_device *find_device() {
+ struct usb_bus *bus;
+
+ for (bus = usb_get_busses(); bus; bus = bus->next) {
+ struct usb_device *dev;
+
+ for (dev = bus->devices; dev; dev = dev->next) {
+ if (dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1001 || //Huawei E169, Huawei E169G
+ dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1003) //Huawei E220, Huawei E156G
+ return dev;
+ }
+ }
+ return NULL;
+}
+
+int main(int argc, char **argv) {
+ int ret, vendor, product;
+ struct usb_device *dev;
+ char buf[65535], *endptr;
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+
+ printf("Searching modem...");
+ dev = find_device();
+
+ if(dev == NULL){
+ printf("No supported modem found\n");
+ return 1;
+ }
+
+ printf("found supported modem!\n");
+
+ assert(dev);
+ devh = usb_open(dev);
+ assert(devh);
+
+ signal(SIGTERM, release_usb_device);
+
+ ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);
+ usleep(1*1000);
+ ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000009);
+ usleep(1*1000);
+ ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000020);
+ usleep(1*1000);
+ ret = usb_control_msg(devh, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 00000001, 0, buf, 0, 1000);
+
+ ret = usb_close(devh);
+ assert(ret == 0);
+
+ printf("Modem poked!\n");
+ return 0;
+}