1 /* HUAWEI E220 3G HSDPA modem - Aktivator modemu = aktivuje ttyUSB0 tty USB1
3 dalej sa uz pouzije usbserial a usb-storage
4 cc huaweiAktBbo.c -lusb (resp -I. -L.)
5 armeb-linux-gcc huaweiAktBbo.c -L. -I. -lusb
6 Copyright (C) 2006 bobovsky bobovsky@kanoistika.sk GPL
7 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License2.
17 #include <linux/usbdevice_fs.h>
18 #define LIBUSB_AUGMENT
19 #include "libusb_augment.h"
22 struct usb_dev_handle
*devh
;
24 void release_usb_device(int dummy
) {
26 ret
= usb_release_interface(devh
, 0);
28 printf("failed to release interface: %d\n", ret
);
31 printf("failed to close interface: %d\n", ret
);
37 for (bus
= usb_get_busses(); bus
; bus
= bus
->next
) {
38 struct usb_device
*dev
;
40 for (dev
= bus
->devices
; dev
; dev
= dev
->next
)
41 printf("0x%04x 0x%04x\n",
42 dev
->descriptor
.idVendor
,
43 dev
->descriptor
.idProduct
);
47 struct usb_device
*find_device(int vendor
, int product
) {
50 for (bus
= usb_get_busses(); bus
; bus
= bus
->next
) {
51 struct usb_device
*dev
;
53 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
54 if (dev
->descriptor
.idVendor
== vendor
55 && dev
->descriptor
.idProduct
== product
)
62 void print_bytes(char *bytes
, int len
) {
65 for (i
=0; i
<len
; i
++) {
66 printf("%02x ", (int)((unsigned char)bytes
[i
]));
69 for (i
=0; i
<len
; i
++) {
70 printf("%c", isprint(bytes
[i
]) ? bytes
[i
] : '.');
77 int main(int argc
, char **argv
) {
78 int ret
, vendor
, product
;
79 struct usb_device
*dev
;
80 char buf
[65535], *endptr
;
88 // usb_set_debug(255);
93 printf("usage: %s vendorID productID\n", argv[0]);
94 printf("ID numbers of currently attached devices:\n");
98 vendor = strtol(argv[1], &endptr, 16);
99 if (*endptr != '\0') {
100 printf("invalid vendor id\n");
103 product = strtol(argv[2], &endptr, 16);
104 if (*endptr != '\0') {
105 printf("invalid product id\n");
109 printf("Hladam HUAWEI E220 a prepnem na modem - bbo 06\n");
112 dev
= find_device(vendor
, product
);
115 devh
= usb_open(dev
);
118 signal(SIGTERM
, release_usb_device
);
121 ret = usb_get_driver_np(devh, 0, buf, sizeof(buf));
122 printf("usb_get_driver_np returned %d\n", ret);
124 printf("interface 0 already claimed by driver \"%s\", attempting to detach it\n", buf);
125 ret = usb_detach_kernel_driver_np(devh, 0);
126 printf("usb_detach_kernel_driver_np returned %d\n", ret);
128 ret = usb_claim_interface(devh, 0);
130 printf("claim failed with error %d\n", ret);
134 ret = usb_set_altinterface(devh, 0);
137 // BBO typ 1 = DEVICE
138 ret
= usb_get_descriptor(devh
, 0x0000001, 0x0000000, buf
, 0x0000012);
139 //printf("1 get descriptor returned %d, bytes: ", ret);
140 //print_bytes(buf, ret);
143 // BBO typ 2 = CONFIGURATION
144 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000009);
145 //printf("2 get descriptor returned %d, bytes: ", ret);
146 //print_bytes(buf, ret);
149 // BBO typ 2 = CONFIGURATION
150 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000020);
151 //printf("3 get descriptor returned %d, bytes: ", ret);
152 //print_bytes(buf, ret);
156 ret = usb_release_interface(devh, 0);
157 if (ret != 0) printf("failed to release interface before set_configuration: %d\n", ret);
158 ret = usb_set_configuration(devh, 0x0000001);
159 printf("4 set configuration returned %d\n", ret);
160 ret = usb_claim_interface(devh, 0);
161 if (ret != 0) printf("claim after set_configuration failed with error %d\n", ret);
162 ret = usb_set_altinterface(devh, 0);
163 printf("4 set alternate setting returned %d\n", ret);
165 ret = usb_set_altinterface(devh, 0);
166 printf("5 set alternate setting returned %d\n", ret);
169 ret
= usb_control_msg(devh
, USB_TYPE_STANDARD
+ USB_RECIP_DEVICE
, USB_REQ_SET_FEATURE
, 00000001, 0, buf
, 0, 1000);
170 printf("4 set feature request returned %d\n", ret
);
172 ret = usb_release_interface(devh, 0);
175 ret
= usb_close(devh
);
177 printf("Prepnute-OK, Mas ttyUSB0 ttyUSB1 (cez usbserial vendor=0x12d1 product=0x1003)\n");
178 printf("pozri /proc/bus/usb/devices\n");