Changeset 18898


Ignore:
Timestamp:
2009-12-22T23:58:59+01:00 (8 years ago)
Author:
jow
Message:

[packages] huaweiaktbbo: add support for the E156 and E169 (#6396)

Location:
packages/utils/huaweiaktbbo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • packages/utils/huaweiaktbbo/Makefile

    r15480 r18898  
    1919  CATEGORY:=Utilities 
    2020  DEPENDS:=+libusb 
    21   TITLE:=Huawei e220 configuration tool 
     21  TITLE:=Huawei E156/E169/E220 activation tool 
    2222endef 
    2323 
  • packages/utils/huaweiaktbbo/src/huaweiAktBbo.c

    r10226 r18898  
    1 /* HUAWEI E220 3G HSDPA modem - Aktivator modemu = aktivuje ttyUSB0 tty USB1  
    2    bobovsky 11.12.2006 
    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  
     1/* HUAWEI 3G modems activator 
     2   Copyright (C) 2006 bobovsky bobovsky@kanoistika.sk  GPL 
     3   Copyright (C) 2009 Nuno Goncalves nunojpg@gmail.com GPL 
    74   This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License2. 
    85*/ 
     6 
    97#include <stdio.h> 
    108#include <stdlib.h> 
     
    1412#include <ctype.h> 
    1513#include <usb.h> 
    16 #if 0 
    17  #include <linux/usbdevice_fs.h> 
    18  #define LIBUSB_AUGMENT 
    19  #include "libusb_augment.h" 
    20 #endif 
    2114 
    2215struct usb_dev_handle *devh; 
    2316 
    2417void release_usb_device(int dummy) { 
    25     int ret; 
    26     ret = usb_release_interface(devh, 0); 
    27     if (!ret) 
    28         printf("failed to release interface: %d\n", ret); 
    29     usb_close(devh); 
    30     if (!ret) 
    31         printf("failed to close interface: %d\n", ret); 
    32     exit(1); 
     18        int ret; 
     19        ret = usb_release_interface(devh, 0); 
     20 
     21        if (!ret) 
     22                printf("failed to release interface: %d\n", ret); 
     23 
     24        usb_close(devh); 
     25 
     26        if (!ret) 
     27                printf("failed to close interface: %d\n", ret); 
     28 
     29        exit(1); 
    3330} 
    3431 
    3532void list_devices() { 
    36     struct usb_bus *bus; 
    37     for (bus = usb_get_busses(); bus; bus = bus->next) { 
     33        struct usb_bus *bus; 
     34        for (bus = usb_get_busses(); bus; bus = bus->next) { 
    3835        struct usb_device *dev; 
    39          
     36 
    4037        for (dev = bus->devices; dev; dev = dev->next) 
    41             printf("0x%04x 0x%04x\n", 
    42                    dev->descriptor.idVendor, 
    43                    dev->descriptor.idProduct); 
     38                printf("0x%04x 0x%04x\n", dev->descriptor.idVendor, dev->descriptor.idProduct); 
    4439    } 
    4540}     
    4641 
    47 struct usb_device *find_device(int vendor, int product) { 
    48     struct usb_bus *bus; 
    49      
    50     for (bus = usb_get_busses(); bus; bus = bus->next) { 
    51         struct usb_device *dev; 
    52          
    53         for (dev = bus->devices; dev; dev = dev->next) { 
    54             if (dev->descriptor.idVendor == vendor 
    55                 && dev->descriptor.idProduct == product) 
     42struct usb_device *find_device() { 
     43        struct usb_bus *bus; 
     44 
     45        for (bus = usb_get_busses(); bus; bus = bus->next) { 
     46                struct usb_device *dev; 
     47 
     48                for (dev = bus->devices; dev; dev = dev->next) { 
     49                if (dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1001 || //Huawei E169, Huawei E169G 
     50                    dev->descriptor.idVendor == 0x12d1 && dev->descriptor.idProduct == 0x1003)   //Huawei E220, Huawei E156G 
    5651                return dev; 
     52                } 
    5753        } 
    58     } 
    59     return NULL; 
     54        return NULL; 
    6055} 
    6156 
    62 void print_bytes(char *bytes, int len) { 
    63     int i; 
    64     if (len > 0) { 
    65         for (i=0; i<len; i++) { 
    66             printf("%02x ", (int)((unsigned char)bytes[i])); 
     57int main(int argc, char **argv) { 
     58        int ret, vendor, product; 
     59        struct usb_device *dev; 
     60        char buf[65535], *endptr; 
     61 
     62        usb_init(); 
     63        usb_find_busses(); 
     64        usb_find_devices(); 
     65 
     66        printf("Searching modem..."); 
     67        dev = find_device(); 
     68 
     69        if(dev == NULL){ 
     70                printf("No supported modem found\n"); 
     71                return 1; 
    6772        } 
    68         printf("\""); 
    69         for (i=0; i<len; i++) { 
    70             printf("%c", isprint(bytes[i]) ? bytes[i] : '.'); 
    71         } 
    72         printf("\""); 
    73     } 
    74 } 
    7573 
     74        printf("found supported modem!\n"); 
    7675 
    77 int main(int argc, char **argv) { 
    78     int ret, vendor, product; 
    79     struct usb_device *dev; 
    80     char buf[65535], *endptr; 
    81 #if 0 
    82     usb_urb *isourb; 
    83     struct timeval isotv; 
    84     char isobuf[32768]; 
    85 #endif 
     76        assert(dev); 
     77        devh = usb_open(dev); 
     78        assert(devh); 
    8679 
    87     usb_init(); 
    88 //    usb_set_debug(255); 
    89     usb_find_busses(); 
    90     usb_find_devices(); 
    91 /* 
    92     if (argc!=3) { 
    93         printf("usage: %s vendorID productID\n", argv[0]); 
    94         printf("ID numbers of currently attached devices:\n"); 
    95         list_devices(); 
    96         exit(1); 
    97     } 
    98     vendor = strtol(argv[1], &endptr, 16); 
    99     if (*endptr != '\0') { 
    100         printf("invalid vendor id\n"); 
    101         exit(1); 
    102     } 
    103     product = strtol(argv[2], &endptr, 16); 
    104     if (*endptr != '\0') { 
    105         printf("invalid product id\n"); 
    106         exit(1); 
    107     } 
    108 */ 
    109     printf("Hladam HUAWEI E220 a prepnem na modem - bbo 06\n"); 
    110     vendor = 0x12d1; 
    111     product = 0x1003; 
    112     dev = find_device(vendor, product); 
    113     assert(dev); 
     80        signal(SIGTERM, release_usb_device); 
    11481 
    115     devh = usb_open(dev); 
    116     assert(devh); 
    117      
    118     signal(SIGTERM, release_usb_device); 
     82        ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012); 
     83        usleep(1*1000); 
     84        ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000009); 
     85        usleep(1*1000); 
     86        ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000020); 
     87        usleep(1*1000); 
     88        ret = usb_control_msg(devh, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 00000001, 0, buf, 0, 1000); 
    11989 
    120 /* 
    121     ret = usb_get_driver_np(devh, 0, buf, sizeof(buf)); 
    122     printf("usb_get_driver_np returned %d\n", ret); 
    123     if (ret == 0) { 
    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); 
    127     } 
    128     ret = usb_claim_interface(devh, 0); 
    129     if (ret != 0) { 
    130         printf("claim failed with error %d\n", ret); 
    131                 exit(1); 
    132     } 
    133      
    134     ret = usb_set_altinterface(devh, 0); 
    135     assert(ret >= 0); 
    136 */ 
    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); 
    141 //printf("\n"); 
    142 usleep(1*1000); 
    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); 
    147 //printf("\n"); 
    148 usleep(1*1000); 
    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); 
    153 //printf("\n"); 
    154 usleep(1*1000); 
    155 /* 
    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); 
    164 usleep(50*1000); 
    165 ret = usb_set_altinterface(devh, 0); 
    166 printf("5 set alternate setting returned %d\n", ret); 
    167 usleep(62*1000); 
    168 */ 
    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); 
    171 /* 
    172         ret = usb_release_interface(devh, 0); 
    173         assert(ret == 0); 
    174 */ 
    17590        ret = usb_close(devh); 
    17691        assert(ret == 0); 
    177         printf("Prepnute-OK, Mas ttyUSB0 ttyUSB1 (cez usbserial vendor=0x12d1 product=0x1003)\n"); 
    178         printf("pozri /proc/bus/usb/devices\n"); 
     92         
     93        printf("Modem poked!\n"); 
    17994        return 0; 
    18095} 
Note: See TracChangeset for help on using the changeset viewer.