summaryrefslogtreecommitdiff
path: root/package/huawei/src/huawei.c
blob: 09c90508544e97359855862e5e44713f9ed94491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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;
}