huawei.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* HUAWEI 3G modems activator
  2. Copyright (C) 2006 bobovsky bobovsky@kanoistika.sk GPL
  3. Copyright (C) 2009 Nuno Goncalves nunojpg@gmail.com GPL
  4. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License2.
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. #include <signal.h>
  11. #include <ctype.h>
  12. #include <usb.h>
  13. struct usb_dev_handle *devh;
  14. void release_usb_device(int dummy) {
  15. int ret;
  16. ret = usb_release_interface(devh, 0);
  17. if (!ret)
  18. printf("failed to release interface: %d\n", ret);
  19. usb_close(devh);
  20. if (!ret)
  21. printf("failed to close interface: %d\n", ret);
  22. exit(1);
  23. }
  24. void list_devices() {
  25. struct usb_bus *bus;
  26. for (bus = usb_get_busses(); bus; bus = bus->next) {
  27. struct usb_device *dev;
  28. for (dev = bus->devices; dev; dev = dev->next)
  29. printf("0x%04x 0x%04x\n", dev->descriptor.idVendor, dev->descriptor.idProduct);
  30. }
  31. }
  32. struct usb_device *find_device() {
  33. struct usb_bus *bus;
  34. for (bus = usb_get_busses(); bus; bus = bus->next) {
  35. struct usb_device *dev;
  36. for (dev = bus->devices; dev; dev = dev->next) {
  37. if (dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1001 || //Huawei E169, Huawei E169G
  38. dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1003) //Huawei E220, Huawei E156G
  39. return dev;
  40. }
  41. }
  42. return NULL;
  43. }
  44. int main(int argc, char **argv) {
  45. int ret, vendor, product;
  46. struct usb_device *dev;
  47. char buf[65535], *endptr;
  48. usb_init();
  49. usb_find_busses();
  50. usb_find_devices();
  51. printf("Searching modem...");
  52. dev = find_device();
  53. if(dev == NULL){
  54. printf("No supported modem found\n");
  55. return 1;
  56. }
  57. printf("found supported modem!\n");
  58. assert(dev);
  59. devh = usb_open(dev);
  60. assert(devh);
  61. signal(SIGTERM, release_usb_device);
  62. ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);
  63. usleep(1*1000);
  64. ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000009);
  65. usleep(1*1000);
  66. ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000020);
  67. usleep(1*1000);
  68. ret = usb_control_msg(devh, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 00000001, 0, buf, 0, 1000);
  69. ret = usb_close(devh);
  70. assert(ret == 0);
  71. printf("Modem poked!\n");
  72. return 0;
  73. }