root/src/router/libutils/lib3g.c

Revision 12432, 6.0 kB (checked in by BrainSlayer, 5 months ago)

hso support

Line 
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <shutils.h>
4 #include <bcmnvram.h>
5
6 static int scanFor(int Vendor, int Product)
7 {
8 #ifdef ARCH_broadcom
9         char grepstr[128];
10         sprintf(grepstr, "grep Vendor=%x ProdID=%x /tmp/usb/devices|wc -l",
11                 Vendor, Product);
12         FILE *check = popen(grepstr, "rb");
13         if (check) {
14                 int count = 0;
15                 fscanf(check, "%d", &count);
16                 fclose(check);
17                 if (count > 0) {
18                         eval("umount /tmp/usb");
19                         return 1;
20                 }
21         }
22         return 0;
23 #else
24         int count = 1;
25         while (1) {
26                 char sysfs[64];
27                 sprintf(sysfs, "/sys/bus/usb/devices/%d-0:1.0/bInterfaceNumber",
28                         count);
29                 FILE *probe = fopen(sysfs, "rb");
30                 if (!probe)
31                         return 0;
32                 fclose(probe);
33                 sprintf(sysfs, "/sys/bus/usb/devices/%d-1/idProduct", count);
34                 FILE *modem = fopen(sysfs, "rb");
35                 if (!modem) {
36                         count++;
37                         continue;
38                 }
39                 int idProduct;
40                 int idVendor;
41                 fscanf(modem, "%X", &idProduct);
42                 fclose(modem);
43                 sprintf(sysfs, "/sys/bus/usb/devices/%d-1/idVendor", count);
44                 modem = fopen(sysfs, "rb");
45                 if (!modem) {
46                         count++;
47                         continue;
48                 }
49                 fscanf(modem, "%X", &idVendor);
50                 fclose(modem);
51                 if (idVendor == Vendor && idProduct == Product)
52                         return 1;
53                 count++;
54         }
55 #endif
56 }
57
58 void checkreset(char *tty)
59 {
60 #ifdef HAVE_CAMBRIA
61         eval("comgt", "-d", tty, "-s", "/etc/comgt/reset.comgt");
62         FILE *check = NULL;
63         int count = 0;
64         sleep(1);
65         while (!(check = fopen(tty, "rb")) && count < 10) {
66                 sleep(1);
67                 count++;
68         }
69         if (check)
70                 fclose(check);
71         else
72                 fprintf(stderr, "reset error\n");
73         fprintf(stderr, "wakeup card\n");
74         eval("comgt", "-d", tty, "-s", "/etc/comgt/wakeup.comgt");
75         sleep(5);               //give extra delay for registering
76 #endif
77 }
78
79 char *get3GControlDevice(void)
80 {
81 #ifdef ARCH_broadcom
82         mkdir("/tmp/usb");
83         eval("mount", "-t", "usbfs", "usb", "/tmp/usb");
84 //insmod("sierra");  //further investigation required (compass problem)
85 #endif
86
87         char *ttsdevice = "/dev/usb/tts/0";
88 #ifdef HAVE_CAMBRIA
89         eval("gpio", "enable", "26");
90         eval("gpio", "disable", "27");
91         if (nvram_match("wan_select", "1")) {
92                 eval("gpio", "enable", "26");
93                 eval("gpio", "disable", "27");
94         }
95         if (nvram_match("wan_select", "2")) {
96                 eval("gpio", "disable", "26");
97                 eval("gpio", "enable", "27");
98         }
99         if (nvram_match("wan_select", "3")) {
100                 eval("gpio", "enable", "26");
101                 eval("gpio", "enable", "27");
102         }
103 #endif
104         nvram_set("3gdata", "/dev/usb/tts/0");
105         if (scanFor(0x1199, 0x6880)) {
106                 //sierra wireless
107                 fprintf(stderr, "Sierra Wireless Compass 885 deteted\n");
108                 insmod("usbserial");
109                 insmod("sierra");
110                 nvram_set("3gdata", "/dev/usb/tts/4");
111                 return "/dev/usb/tts/3";
112         }
113         if (scanFor(0x1199, 0x6890)) {
114                 //sierra wireless
115                 fprintf(stderr, "Sierra Wireless Compass 888 deteted\n");
116                 insmod("usbserial");
117                 insmod("sierra");
118                 nvram_set("3gdata", "/dev/usb/tts/4");
119                 return "/dev/usb/tts/3";
120         }
121         if (scanFor(0x1199, 0x683C)) {
122                 //sierra wireless
123                 fprintf(stderr, "Sierra Wireless MC8790\n");
124                 nvram_set("3gdata", "/dev/usb/tts/4");
125                 insmod("usbserial");
126                 insmod("sierra");
127                 checkreset("/dev/usb/tts/3");
128                 return "/dev/usb/tts/3";
129         }
130         if (scanFor(0x1199, 0x683D)) {
131                 //sierra wireless
132                 fprintf(stderr, "Sierra Wireless MC8790\n");
133                 nvram_set("3gdata", "/dev/usb/tts/4");
134                 insmod("usbserial");
135                 insmod("sierra");
136                 checkreset("/dev/usb/tts/3");
137                 return "/dev/usb/tts/3";
138         }
139         if (scanFor(0x1199, 0x683E)) {
140                 //sierra wireless
141                 fprintf(stderr, "Sierra Wireless MC8790\n");
142                 nvram_set("3gdata", "/dev/usb/tts/4");
143                 insmod("usbserial");
144                 insmod("sierra");
145                 checkreset("/dev/usb/tts/3");
146                 return "/dev/usb/tts/3";
147         }
148         if (scanFor(0x12d1, 0x1003)) {
149                 //huawei
150                 fprintf(stderr, "HUAWEI/Option E172 detected\n");
151         insmod("usbserial");
152         insmod("option");
153                 return "/dev/usb/tts/0";
154         }
155         if (scanFor(0x0af0, 0x7011)) {
156                 //huawei
157                 fprintf(stderr, "HUAWEI/Option E301 HSUPA detected\n");
158         insmod("usbserial");
159         insmod("option");
160                 return "/dev/usb/tts/0";
161         }
162         if (scanFor(0x12d1, 0x1001)) {
163                 //huawei
164                 fprintf(stderr, "HUAWEI/Option E600 detected\n");
165         insmod("usbserial");
166         insmod("option");
167                 return "/dev/usb/tts/0";
168         }
169         if (scanFor(0x12d1, 0x1003)) {
170                 //huawei
171                 fprintf(stderr, "HUAWEI/Option EC270 detected\n");
172         insmod("usbserial");
173         insmod("option");
174                 return "/dev/usb/tts/0";
175         }
176         if (scanFor(0x12d1, 0x1412)) {
177                 //huawei
178                 fprintf(stderr, "HUAWEI/Option EC168 detected\n");
179         insmod("usbserial");
180         insmod("option");
181                 return "/dev/usb/tts/0";
182         }
183         if (scanFor(0x12d1, 0x1412)) {
184                 //huawei
185                 fprintf(stderr, "HUAWEI/Option EC168 detected\n");
186         insmod("usbserial");
187         insmod("option");
188                 return "/dev/usb/tts/0";
189         }
190
191         if (scanFor(0x1e0e, 0x9000)) {
192                 //huawei
193                 fprintf(stderr, "QUALCOMM ICON 210 detected\n");
194                 nvram_set("3gdata", "/dev/usb/tts/2");
195         insmod("usbserial");
196         insmod("option");
197                 return "/dev/usb/tts/2";
198         }
199
200         if (scanFor(0x1e0e, 0xf000)) {
201                 //huawei
202         fprintf(stderr, "QUALCOMM ICON 210 detected\n");
203         FILE *out = fopen("/tmp/usb_modeswitch.conf","wb");
204         fprintf(out,"DefaultVendor=0x1e0e\n");
205         fprintf(out,"DefaultProduct=0xf000\n");
206         fprintf(out,"TargetVendor=0x1e0e\n");
207         fprintf(out,"TargetProduct=0x9000\n");
208         fprintf(out,"MessageContent=\"555342431234567800000000000006bd000000020000000000000000000000\"\n");
209         fprintf(out,"ResponseEndpoint=0x01\n");
210         fclose(out);
211         system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
212         sleep(2);
213         insmod("usbserial");
214         insmod("option");
215         nvram_set("3gdata", "/dev/usb/tts/2");
216             return "/dev/usb/tts/2";
217         }
218
219         if (scanFor(0x0af0, 0x6971)) {
220                 //huawei
221         fprintf(stderr, "QUALCOMM ICON 225 detected\n");
222         system("ozerocdoff -wi 0x6971");
223         sleep(10);
224         system("insmod hso");
225         FILE *out=fopen("/tmp/conninfo.ini","wb");
226         fprintf(out,"APN=%s\n",nvram_safe_get("wan_apn"));
227         fprintf(out,"USER=%s\n",nvram_safe_get("ppp_username"));
228         fprintf(out,"PASS=%s\n",nvram_safe_get("ppp_passwd"));
229         fprintf(out,"PIN=%s\n",nvram_safe_get("wan_pin"));
230         fclose(out);
231         nvram_set("3gdata", "hso");
232         system("/etc/hso/hso_connect.sh restart");
233         return "hso";
234         }
235
236         if (scanFor(0x1199, 0x6832)) {
237                 //sierra wireless mc 8780
238                 fprintf(stderr,
239                         "Sierra Wireless MC 8780 detected\nreset card\n");
240                 checkreset("/dev/usb/tts/2");
241                 return "/dev/usb/tts/2";
242         }
243         insmod("usbserial");
244         insmod("sierra");
245         insmod("option");
246         return ttsdevice;
247 }
Note: See TracBrowser for help on using the browser.