source: src/router/libutils/lib3g.c @ 18016

Last change on this file since 18016 was 18016, checked in by BrainSlayer, 17 months ago

already switched

File size: 29.9 KB
Line 
1/*
2 * lib3g.c
3 *
4 * Copyright (C) 2009 Sebastian Gottschall <gottschall@dd-wrt.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 *
20 * $Id:
21 * this module detects various special 3G/CDMA USB Devices which is required to handle them correct, since some devices
22 * are using non standard tty interfaces. everything which is not handled here in this list, is supported by the default tty handling which means dialin on tty0
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <shutils.h>
28#include <bcmnvram.h>
29
30static int scanFor(int Vendor, int Product)
31{
32#if defined(ARCH_broadcom) && !defined(HAVE_BCMMODERN)
33        char grepstr[128];
34        sprintf(grepstr, "grep Vendor=%x ProdID=%x /tmp/usb/devices|wc -l",
35                Vendor, Product);
36        FILE *check = popen(grepstr, "rb");
37        if (check) {
38                int count = 0;
39                fscanf(check, "%d", &count);
40                fclose(check);
41                if (count > 0) {
42                        eval("umount /tmp/usb");
43                        return 1;
44                }
45        }
46        return 0;
47#else
48        int count = 1;
49        int hub = 1;
50        while (hub < 5) {
51                char sysfs[64];
52                sprintf(sysfs, "/sys/bus/usb/devices/%d-0:1.0/bInterfaceNumber",
53                        count);
54                FILE *probe = fopen(sysfs, "rb");
55                if (!probe) {
56                        count = 1;
57                        hub++;
58                        continue;
59                }
60                fclose(probe);
61
62                sprintf(sysfs, "/sys/bus/usb/devices/%d-%d/idProduct", count,
63                        hub);
64                FILE *modem = fopen(sysfs, "rb");
65                if (!modem) {
66                        count++;
67                        continue;
68                }
69                int idProduct;
70                int idVendor;
71                fscanf(modem, "%X", &idProduct);
72                fclose(modem);
73                sprintf(sysfs, "/sys/bus/usb/devices/%d-%d/idVendor", count,
74                        hub);
75                modem = fopen(sysfs, "rb");
76                if (!modem) {
77                        count++;
78                        continue;
79                }
80                fscanf(modem, "%X", &idVendor);
81                fclose(modem);
82                if (idVendor == Vendor && idProduct == Product)
83                        return 1;
84
85                count++;
86        }
87        return 0;
88#endif
89}
90
91void checkreset(char *tty)
92{
93#ifdef HAVE_CAMBRIA
94        FILE *check = NULL;
95        int count = 0;
96        sysprintf("comgt -d /dev/usb/tts/%s -s /etc/comgt/reset.comgt\n", tty);
97        sleep(1);
98        while (!(check = fopen(tty, "rb")) && count < 10) {
99                sleep(1);
100                count++;
101        }
102        if (check)
103                fclose(check);
104        else
105                fprintf(stderr, "reset error\n");
106        fprintf(stderr, "wakeup card\n");
107        sysprintf("comgt -d /dev/usb/tts/%s -s /etc/comgt/wakeup.comgt\n", tty);
108        sleep(5);               //give extra delay for registering
109#endif
110}
111
112static void reset_mc(int needreset, char *controldev)
113{
114        if (needreset)
115                checkreset(controldev);
116}
117
118static void modeswitch_usb760(int needreset, char *controldev)
119{
120        system
121            ("usb_modeswitch -v 0x1410 -p 0x5010 -M 5553424312345678000000000000061b000000020000000000000000000000");
122        system
123            ("usb_modeswitch -v 0x1410 -p 0x5020 -M 5553424312345678000000000000061b000000020000000000000000000000");
124        system
125            ("usb_modeswitch -v 0x1410 -p 0x5030 -M 5553424312345678000000000000061b000000020000000000000000000000");
126        system
127            ("usb_modeswitch -v 0x1410 -p 0x5031 -M 5553424312345678000000000000061b000000020000000000000000000000");
128        system
129            ("usb_modeswitch -v 0x1410 -p 0x5041 -M 5553424312345678000000000000061b000000020000000000000000000000");
130        sleep(2);
131}
132
133static void modeswitch_onda(int needreset, char *controldev)
134{
135        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
136
137        fprintf(out, "DefaultVendor=0x19d2\n"
138                "DefaultProduct=0x2000\n"
139                "TargetVendor=0x19d2\n"
140                "TargetProductList=\"0001,0002,0015,0016,0017,0031,0037,0052,0055,0063,0064,0108,0128\"\n"
141                "MessageContent=\"5553424312345678000000000000061e000000000000000000000000000000\"\n"
142                "MessageContent2=\"5553424312345679000000000000061b000000020000000000000000000000\"\n"
143                "MessageContent3=\"55534243123456702000000080000c85010101180101010101000000000000\"\n"
144                "NeedResponse=1\n" "CheckSuccess=20\n");
145        fclose(out);
146        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
147        sleep(2);
148}
149
150static void modeswitch_onda2(int needreset, char *controldev)
151{
152        system
153            ("usb_modeswitch -v 0x19d2 -p 0x0003 -M 5553424312345678000000000000061e000000000000000000000000000000 -2 5553424312345679000000000000061b000000020000000000000000000000");
154        system
155            ("usb_modeswitch -v 0x19d2 -p 0x0026 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
156        system
157            ("usb_modeswitch -v 0x19d2 -p 0x0040 -n -M 5553424312345678000000000000061e000000000000000000000000000000 -2 5553424312345679000000000000061b000000020000000000000000000000");
158        system
159            ("usb_modeswitch -v 0x19d2 -p 0x0053 -n -M 5553424312345678000000000000061e000000000000000000000000000000 -2 5553424312345679000000000000061b000000020000000000000000000000");
160        system
161            ("usb_modeswitch -v 0x19d2 -p 0x0083 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
162        system
163            ("usb_modeswitch -v 0x19d2 -p 0x0101 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
164        system
165            ("usb_modeswitch -v 0x19d2 -p 0x0103 -n -M 5553424312345678000000000000061e000000000000000000000000000000 -2 5553424312345679000000000000061b000000020000000000000000000000");
166        system
167            ("usb_modeswitch -v 0x19d2 -p 0x0115 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
168        system
169            ("usb_modeswitch -v 0x19d2 -p 0x1001 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
170        system
171            ("usb_modeswitch -v 0x19d2 -p 0x1007 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
172        system
173            ("usb_modeswitch -v 0x19d2 -p 0x1009 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
174        system
175            ("usb_modeswitch -v 0x19d2 -p 0x1013 -n -M 5553424312345678000000000000061b000000020000000000000000000000");
176        system
177            ("usb_modeswitch -v 0x19d2 -p 0xfff5 -M 5553424312345678c00000008000069f030000000000000000000000000000");
178        system
179            ("usb_modeswitch -v 0x19d2 -p 0xfff6 -M 5553424312345678c00000008000069f030000000000000000000000000000");
180        sleep(2);
181}
182
183static void modeswitch_sierra(int needreset, char *controldev)
184{
185        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
186
187        fprintf(out, "DefaultVendor=0x1199\n"
188                "DefaultProduct=0x0fff\n"
189                "TargetVendor=0x1199\n"
190                "TargetProductList=\"0017,0018,0019,0020,0021,0022,0024,0026,0027,0028,0029,0112,0120,0218,0220,0224,6802,6803,6804,6805,6808,6809,6812,6813,6815,6816,6820,6821,6822,6832,6833,6834,6835,6838,6839,683a,683b,683c,683d,683e,6850,6851,6852,6853,6855,6856,6859,685a\"\n"
191                "SierraMode=1\n" "CheckSuccess=10\n");
192        fclose(out);
193        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
194        sleep(2);
195}
196
197static void modeswitch_huawei(int needreset, char *controldev)
198{
199        system("usb_modeswitch -v 0x12d1 -p 0x1001 -H");
200        system("usb_modeswitch -v 0x12d1 -p 0x1003 -H");
201        system("usb_modeswitch -v 0x12d1 -p 0x1414 -H");
202        system
203            ("usb_modeswitch -v 0x12d1 -p 0x101e -M 55534243123456780000000000000011062000000100000000000000000000");
204        system
205            ("usb_modeswitch -v 0x12d1 -p 0x1031 -M 55534243123456780600000080010a11060000000000000000000000000000");
206        system
207            ("usb_modeswitch -v 0x12d1 -p 0x1446 -M 55534243123456780000000000000011062000000100000000000000000000");
208        system
209            ("usb_modeswitch -v 0x12d1 -p 0x14ad -M 55534243123456780000000000000011062000000100000000000000000000");
210        system
211            ("usb_modeswitch -v 0x12d1 -p 0x14c1 -M 55534243123456780000000000000011062000000100000000000000000000");
212        system
213            ("usb_modeswitch -v 0x12d1 -p 0x14c6 -M 55534243123456780000000000000011062000000100000000000000000000");
214        system
215            ("usb_modeswitch -v 0x12d1 -p 0x1520 -M 55534243123456780000000000000011062000000100000000000000000000");
216        system
217            ("usb_modeswitch -v 0x12d1 -p 0x1521 -M 55534243123456780000000000000011062000000100000000000000000000");
218        system
219            ("usb_modeswitch -v 0x12d1 -p 0x1523 -M 55534243123456780000000000000011062000000100000000000000000000");
220        system
221            ("usb_modeswitch -v 0x12d1 -p 0x1553 -M 55534243123456780000000000000011062000000100000000000000000000");
222        system
223            ("usb_modeswitch -v 0x12d1 -p 0x1557 -M 55534243123456780000000000000011062000000100000000000000000000");
224        system
225            ("usb_modeswitch -v 0x12d1 -p 0x1c0b -M 55534243123456780000000000000011062000000100000000000000000000");
226        system
227            ("usb_modeswitch -v 0x12d1 -p 0x1c24 -M 55534243123456780000000000000011060000000100000000000000000000");
228        sleep(2);
229}
230
231static void modeswitch_icon210(int needreset, char *controldev)
232{
233        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
234        fprintf(out, "DefaultVendor=0x1e0e\n");
235        fprintf(out, "DefaultProduct=0xf000\n");
236        fprintf(out, "TargetVendor=0x1e0e\n");
237        fprintf(out, "TargetProductList=\"9200,9000\"\n");
238        fprintf(out,
239                "MessageContent=\"555342431234567800000000000006bd000000020000000000000000000000\"\n");
240        fprintf(out, "NeedResponse=1\n");
241        fclose(out);
242        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
243        sleep(2);
244}
245
246static void modeswitch_nokia(int needreset, char *controldev)
247{
248        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
249        fprintf(out, "DefaultVendor=0x0421\n");
250        fprintf(out, "DefaultProduct=0x060c\n");
251        fprintf(out, "TargetVendor=0x0421\n");
252        fprintf(out, "TargetProduct=0x060e\n");
253        fprintf(out, "CheckSuccess=20\n");
254        fprintf(out,
255                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
256        fclose(out);
257        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
258
259        out = fopen("/tmp/usb_modeswitch.conf", "wb");
260        fprintf(out, "DefaultVendor=0x0421\n");
261        fprintf(out, "DefaultProduct=0x0610\n");
262        fprintf(out, "TargetVendor=0x0421\n");
263        fprintf(out, "TargetProduct=0x0612\n");
264        fprintf(out, "CheckSuccess=20\n");
265        fprintf(out,
266                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
267        fclose(out);
268        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
269
270        out = fopen("/tmp/usb_modeswitch.conf", "wb");
271        fprintf(out, "DefaultVendor=0x0421\n");
272        fprintf(out, "DefaultProduct=0x0622\n");
273        fprintf(out, "TargetVendor=0x0421\n");
274        fprintf(out, "TargetProduct=0x0623\n");
275        fprintf(out, "CheckSuccess=20\n");
276        fprintf(out,
277                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
278        fclose(out);
279        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
280
281        out = fopen("/tmp/usb_modeswitch.conf", "wb");
282        fprintf(out, "DefaultVendor=0x0421\n");
283        fprintf(out, "DefaultProduct=0x0627\n");
284        fprintf(out, "TargetVendor=0x0421\n");
285        fprintf(out, "TargetProduct=0x0612\n");
286        fprintf(out, "CheckSuccess=20\n");
287        fprintf(out,
288                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
289        fclose(out);
290        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
291
292        sleep(2);
293}
294
295static void hsoinit(int needreset, char *controldev)
296{
297        system("insmod hso");
298        FILE *out = fopen("/tmp/conninfo.ini", "wb");
299        fprintf(out, "APN=%s\n", nvram_safe_get("wan_apn"));
300        fprintf(out, "USER=%s\n", nvram_safe_get("ppp_username"));
301        fprintf(out, "PASS=%s\n", nvram_safe_get("ppp_passwd"));
302        fprintf(out, "PIN=%s\n", nvram_safe_get("wan_pin"));
303        fclose(out);
304        nvram_set("3gdata", "hso");
305        system("/etc/hso/hso_connect.sh restart");
306}
307
308static void hsoinit_icon225(int needreset, char *controldev)
309{
310        system("ozerocdoff -wi 0x6971");
311        sleep(10);
312        hsoinit(needreset, controldev);
313}
314
315static void hsoinit_icon505(int needreset, char *controldev)
316{
317        system("ozerocdoff -wi 0xd055");
318        sleep(10);
319        hsoinit(needreset, controldev);
320}
321
322static void modeswitch_4g_xsstick(int needreset, char *controldev)
323{
324        FILE *out;
325
326        out = fopen("/tmp/usb_modeswitch.conf", "wb");
327        fprintf(out, "DefaultVendor=0x1c9e\n");
328        fprintf(out, "DefaultProduct=0xf000\n");
329        fprintf(out, "TargetVendor=0x1c9e\n");
330        fprintf(out, "TargetProduct=0x9603\n");
331        fprintf(out, "CheckSuccess=20\n");
332        fprintf(out,
333                "MessageContent=\"55534243123456788000000080000606f50402527000000000000000000000\"\n");
334        fclose(out);
335        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
336
337        sleep(2);
338}
339
340struct DEVICES {
341        int vendor;
342        int product;
343        char *driver;
344        char *controldevice;
345        char *datadevice;
346        int modeswitch;
347        void (*customsetup) (int needreset, char *controldev);
348        char *name;
349};
350
351#define ACM 0x10
352#define GENERIC 0x20
353static struct DEVICES devicelist[] = {
354//sierra wireless cards
355        {0x1199, 0x0fff, "sierra", "3", "4", 1, &modeswitch_sierra, "Sierra Device CDROM Mode"},        //
356        {0x1199, 0x0017, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
357        {0x1199, 0x0018, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
358        {0x1199, 0x0019, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC595U Modem Mode"},     //
359        {0x1199, 0x0020, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
360        {0x1199, 0x0021, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC597E Modem Mode"},     //
361        {0x1199, 0x0022, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
362        {0x1199, 0x0024, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC5727 CDMA Modem Mode"},        //
363        {0x1199, 0x0026, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
364        {0x1199, 0x0027, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
365        {0x1199, 0x0028, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
366        {0x1199, 0x0029, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
367        {0x1199, 0x0112, "sierra", "3", "4", 1, NULL, "Sierra Wireless CDMA 1xEVDO PC Card, Aircard 580 Modem Mode"},   //
368        {0x1199, 0x0120, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC595U Modem Mode"},     //
369        {0x1199, 0x0218, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC5720 Wireless Modem"}, //
370        {0x1199, 0x0220, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
371        {0x1199, 0x0224, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
372        {0x1199, 0x6802, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
373        {0x1199, 0x6803, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8765 Modem Mode"},     //
374        {0x1199, 0x6804, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
375        {0x1199, 0x6805, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8765 Modem Mode"},     //
376        {0x1199, 0x6808, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
377        {0x1199, 0x6809, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
378        {0x1199, 0x6812, "sierra", "0", "2", 1, &reset_mc, "Sierra Wireless MC8775V"},  //
379        {0x1199, 0x6813, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
380        {0x1199, 0x6815, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
381        {0x1199, 0x6816, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
382        {0x1199, 0x6820, "sierra", "0", "2", 1, NULL, "Sierra Wireless AC875 Modem Mode"},      //
383        {0x1199, 0x6821, "sierra", "2", "0", 1, NULL, "Sierra Wireless AC875U Modem Mode"},     //
384        {0x1199, 0x6822, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
385        {0x1199, 0x6832, "sierra", "2", "0", 1, &reset_mc, "Sierra Wireless MC8780 Modem Mode"},        //
386        {0x1199, 0x6833, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8781 Modem Mode"},     //
387        {0x1199, 0x6834, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
388        {0x1199, 0x6835, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
389        {0x1199, 0x6838, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
390        {0x1199, 0x6839, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
391        {0x1199, 0x683a, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8785 Modem Mode"},     //
392        {0x1199, 0x683b, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8785 Composite Modem Mode"},   //
393        {0x1199, 0x683c, "sierra", "3", "3", 1, &reset_mc, "Sierra Wireless MC8790"},   //
394        {0x1199, 0x683d, "sierra", "3", "3", 1, &reset_mc, "Sierra Wireless MC8791 Composite"}, //
395        {0x1199, 0x683e, "sierra", "3", "3", 1, &reset_mc, "Sierra Wireless MC8790"},   //
396        {0x1199, 0x6850, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 880 Modem Mode"},        //
397        {0x1199, 0x6851, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 881 Modem Mode"},        //
398        {0x1199, 0x6852, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 880E Modem Mode"},       //
399        {0x1199, 0x6853, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 881E Modem Mode"},       //
400        {0x1199, 0x6855, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
401        {0x1199, 0x6856, "sierra", "2", "0", 1, NULL, "Sierra Wireless ATT USB Connect 881 Modem Mode"},        //
402        {0x1199, 0x6859, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
403        {0x1199, 0x685a, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
404        {0x1199, 0x6880, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 885"},   //
405        {0x1199, 0x6890, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 888"},   //
406        {0x1199, 0x6893, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 889"},   //
407//      {0x1199, 0x68a3, "sierra", "3", "4", 1, NULL, "Sierra Wireless Compass 889"},   //alternate variant
408        {0x1199, 0x68a3, "sierra", "2", "2", 1, &reset_mc, "Sierra Wireless MC8700/Compass Direct IP"}, //
409//option/huawei
410        {0x12d1, 0x1001, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E600/E620 or generic"},      //
411        {0x12d1, 0x1003, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E172/EC27/E220/E230/E270 HSDPA/HSUPA Model"},        //
412        {0x12d1, 0x1009, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option U120"},      //
413        {0x12d1, 0x101e, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI U7510 / U7517"},    //
414        {0x12d1, 0x1031, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI U8110 (Android smartphone)"},       //
415        {0x12d1, 0x1035, "option", "0", "0", 2, NULL, "HUAWEI U8110 (Android smartphone)"},     //
416        {0x12d1, 0x1414, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E180"},      //
417        {0x12d1, 0x1406, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
418        {0x12d1, 0x140b, "option", "0", "0", 2, NULL, "HUAWEI/Option EC1260 Wireless Data Modem HSD USB Card"}, //
419        {0x12d1, 0x140c, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
420        {0x12d1, 0x1412, "option", "0", "0", 2, NULL, "HUAWEI/Option EC168"},   //
421        {0x12d1, 0x141b, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
422        {0x12d1, 0x1433, "option", "0", "0", 2, NULL, "HUAWEI/Option E1756C"},  //
423        {0x12d1, 0x14ac, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
424        {0x12d1, 0x14ae, "option", "0", "0", 2, NULL, "Vodafone (Huawei) K3806"},       //
425        {0x12d1, 0x1446, "option", "2", "2", 2, &modeswitch_huawei, "HUAWEI/Option E1552 HSPA Modem"},  //
426        {0x12d1, 0x14ad, "option", "0", "0", 2, &modeswitch_huawei, "Vodafone (Huawei) K3806"}, //
427        {0x12d1, 0x14c1, "option", "0", "0", 2, &modeswitch_huawei, "Vodafone (Huawei) K4605"}, //
428        {0x12d1, 0x14d1, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI E-182E"},   //
429        {0x12d1, 0x14c6, "option", "0", "0", 2, NULL, "Vodafone (Huawei) K4605"},       //
430        {0x12d1, 0x1506, "option", "2", "2", 2 | GENERIC, NULL, "Huawei E367"}, //
431        {0x12d1, 0x1520, "option", "0", "0", 2, &modeswitch_huawei, "Huawei K3765"},    //
432        {0x12d1, 0x1465, "option", "0", "0", 2, NULL, "Huawei K3765"},  //
433        {0x12d1, 0x1521, "option", "0", "0", 2, &modeswitch_huawei, "Huawei K4505"},    //
434        {0x12d1, 0x1464, "option", "0", "0", 2, NULL, "Huawei K4505"},  //
435        {0x12d1, 0x1521, "option", "0", "0", 2, &modeswitch_huawei, "Huawei R201"},     //
436        {0x12d1, 0x1491, "option", "0", "0", 2, NULL, "Huawei R201"},   //
437        {0x12d1, 0x1553, "option", "0", "0", 2, &modeswitch_huawei, "Huawei E1553"},    //
438        {0x12d1, 0x1557, "option", "0", "0", 2, &modeswitch_huawei, "Huawei E173"},     //
439        {0x12d1, 0x14a5, "option", "0", "0", 2, NULL, "Huawei E173"},   //
440        {0x12d1, 0x1c0b, "option", "0", "0", 2, &modeswitch_huawei, "Huawei E173s CDROM Mode"}, //
441        {0x12d1, 0x1c05, "option", "0", "0", 2, NULL, "Huawei E173s Modem Mode"},       //
442        {0x12d1, 0x1c08, "option", "0", "0", 2, NULL, "Huawei E173s Modem Mode"},       //
443        {0x12d1, 0x1c23, "option", "2", "2", 2, NULL, "Huawei E173 Modem Mode"},        //
444        {0x12d1, 0x1c24, "option", "2", "2", 2, &modeswitch_huawei, "Huawei E173 CDROM Mode"},  //
445
446        {0x0af0, 0x7011, "option", "0", "0", 2, NULL, "HUAWEI/Option E301 HSUPA"},      //
447
448        {0x1410, 0x5010, "option", "0", "0", 2, &modeswitch_usb760, "Novatel CDROM Mode"},      //
449        {0x1410, 0x5020, "option", "0", "0", 2, &modeswitch_usb760, "Novatel MC990D CDROM Mode"},       //
450        {0x1410, 0x5030, "option", "0", "0", 2, &modeswitch_usb760, "Novatel USB760 CDROM Mode"},       //
451        {0x1410, 0x5031, "option", "0", "0", 2, &modeswitch_usb760, "Novatel USB760 3G CDROM Mode"},    //
452        {0x1410, 0x5041, "option", "0", "0", 2, &modeswitch_usb760, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 CDROM Mode"},       //
453        {0x1410, 0x4100, "option", "0", "0", 2, NULL, "Novatel U727 Modem Mode"},       //
454        {0x1410, 0x4400, "option", "0", "0", 2, NULL, "Novatel Ovation MC930D/MC950D Modem Mode"},      //
455
456        {0x1410, 0x7001, "option", "0", "0", 2, NULL, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 Modem Mode"},     //
457        {0x1410, 0x7003, "option", "0", "0", 2, NULL, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 Modem Mode"},     //
458
459        {0x1410, 0x6000, "option", "0", "0", 2, NULL, "Novatel USB760 Modem Mode"},     //
460        {0x1410, 0x6002, "option", "0", "0", 2, NULL, "Novatel USB760 3G Modem Mode"},  //
461//qualcomm
462        {0x1e0e, 0x9000, "option", "2", "2", 3, NULL, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU Modem Mode"},        //
463        {0x1e0e, 0x9200, "option", "2", "2", 3, NULL, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU Modem Mode"},        //
464        {0x1e0e, 0xf000, "option", "2", "2", 3, &modeswitch_icon210, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU CDROM Mode"}, //
465        {0x0af0, 0x6971, NULL, "hso", "hso", 0, &hsoinit_icon225, "Qualcomm ICON 225"}, //
466        {0x0af0, 0xd055, NULL, "hso", "hso", 0, &hsoinit_icon505, "Qualcomm ICON 505"}, //
467//ericsson
468        {0x0bdb, 0x1900, "option", "4", "4", 0, NULL, "Ericsson F3507g"},       //
469        {0x0bdb, 0x1902, "option", "4", "4", 0, NULL, "Ericsson F3507g"},       //
470//ONDA
471        {0x19d2, 0x2000, "option", "1", "1", 2, &modeswitch_onda, "ONDA/ZTE (cdrom mode)"},     //
472        {0x19d2, 0x0001, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
473        {0x19d2, 0x0002, "option", "1", "3", 2, NULL, "ZTE ET502HS/MT505UP/MF632"},     //
474        {0x19d2, 0x0003, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MU351 (cdrom mode)"},   //
475        {0x19d2, 0x0015, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
476        {0x19d2, 0x0016, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
477        {0x19d2, 0x0017, "option", "1", "1", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
478        {0x19d2, 0x0022, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K2525 (modem mode)"},     //
479        {0x19d2, 0x0026, "option", "1", "3", 2, &modeswitch_onda2, "ZTE AC581 (cdrom mode)"},   //
480        {0x19d2, 0x0031, "option", "1", "2", 2, NULL, "ZTE MF110/MF112/MF626 (Variant) (modem mode)"},  //tested on MF626
481        {0x19d2, 0x0037, "option", "2", "2", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
482        {0x19d2, 0x0040, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K2525 (cdrom mode)"},        //
483        {0x19d2, 0x0052, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
484        {0x19d2, 0x0053, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF110 (Variant) (modem mode)"}, //
485        {0x19d2, 0x0055, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
486        {0x19d2, 0x0063, "option", "1", "3", 2, NULL, "Vodafone K3565-Z HSDPA (modem mode)"},   // tested, working. i hope the other ZDA devices are working in the same way
487        {0x19d2, 0x0064, "option", "1", "3", 2, NULL, "ZTE MF627 AU (modem mode)"},     //
488        {0x19d2, 0x0083, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF110 (Variant) (cdrom mode)"}, //
489        {0x19d2, 0x0094, "option", "1", "3", 2, NULL, "ZTE AC581 (modem mode)"},        //
490        {0x19d2, 0x0101, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K4505-Z (cdrom mode)"},      //
491        {0x19d2, 0x0103, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF112 (cdrom mode)"},   //
492        {0x19d2, 0x0104, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K4505-Z (modem mode)"},   //
493        {0x19d2, 0x0108, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
494        {0x19d2, 0x0115, "option", "1", "3", 2, &modeswitch_onda2, "ONDA MT505UP/ZTE (modem mode)"},    //
495        {0x19d2, 0x0116, "option", "1", "3", 2, NULL, "ZTE MF651 (cdrom mode)"},        //
496        {0x19d2, 0x0117, "option", "1", "2", 2, NULL, "ZTE MF112 (modem mode)"},        // tested, works
497        {0x19d2, 0x0128, "option", "1", "3", 2, NULL, "ZTE MF651 (modem mode)"},        //
498        {0x19d2, 0x0124, "option", "1", "3", 2, NULL, "ZTE MF110 (Variant) (modem mode)"},      //
499        {0x19d2, 0x1001, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3805-Z (cdrom mode)"},      //
500        {0x19d2, 0x1003, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3805-Z (modem mode)"},   //
501        {0x19d2, 0x1007, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3570-Z (cdrom mode)"},      //
502        {0x19d2, 0x1008, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3570-Z (modem mode)"},   //
503        {0x19d2, 0x1009, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3571-Z (cdrom mode)"},      //
504        {0x19d2, 0x1010, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3571-Z (modem mode)"},   //
505        {0x19d2, 0x1013, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3806-Z (cdrom mode)"},      //
506        {0x19d2, 0x1015, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3806-Z (modem mode)"},   //
507        {0x19d2, 0xfff5, "option", "1", "3", 2, &modeswitch_onda2, "ZTE generic (cdrom mode)"}, //
508        {0x19d2, 0xfff6, "option", "1", "3", 2, &modeswitch_onda2, "ZTE generic (cdrom mode)"}, //
509        {0x19d2, 0xfff1, "option", "1", "3", 2, NULL, "ZTE generic (modem mode)"},      //
510        {0x19d2, 0xffff, "option", "1", "3", 2, NULL, "ZTE generic (modem mode)"},      //
511        {0x0421, 0x060c, "option", "0", "0", 2 | ACM, &modeswitch_nokia, "Nokia CS-10 (cdrom mode)"},   //
512        {0x0421, 0x060e, "option", "0", "0", 2 | ACM, NULL, "Nokia CS-10 (modem mode)"},        //
513        {0x0421, 0x0610, "option", "0", "0", 2 | ACM, &modeswitch_nokia, "Nokia CS-15 (cdrom mode)"},   //
514        {0x0421, 0x0612, "option", "0", "0", 2 | ACM, NULL, "Nokia CS-15/CS-18 (modem mode)"},  //
515        {0x0421, 0x0622, "option", "0", "0", 2 | ACM, &modeswitch_nokia, "Nokia CS-17 (cdrom mode)"},   //
516        {0x0421, 0x0623, "option", "0", "0", 2 | ACM, NULL, "Nokia CS-17 (modem mode)"},        //
517        {0x0421, 0x0627, "option", "0", "0", 2 | ACM, &modeswitch_nokia, "Nokia CS-18 (cdrom mode)"},   //
518        {0x106c, 0x3718, "option", "0", "0", 2 | ACM, NULL, "PANTECH UML290 4G Modem"}, //
519        {0x1c9e, 0xf000, "option", "2", "2", 2, &modeswitch_4g_xsstick, "4G Systems XS Stick W14 (cdrom mode)"},        //
520        {0x1c9e, 0x9603, "option", "2", "2", 2, NULL, "4G Systems XS Stick W14"},       //
521        {0xffff, 0xffff, NULL, NULL, NULL, 0, NULL, NULL}       //
522};
523
524char *get3GControlDevice(void)
525{
526#if defined(ARCH_broadcom) && !defined(HAVE_BCMMODERN)
527        mkdir("/tmp/usb");
528        eval("mount", "-t", "usbfs", "usb", "/tmp/usb");
529//insmod("sierra");  //further investigation required (compass problem)
530#endif
531        int needreset = 1;
532        char *ttsdevice = "/dev/usb/tts/0";
533#ifdef HAVE_CAMBRIA
534        int gpio1, gpio2;
535        int select = atoi(nvram_safe_get("wan_select"));
536        switch (select) {
537        case 1:
538                gpio1 = 1;
539                gpio2 = 0;
540                break;
541        case 2:
542                gpio1 = 0;
543                gpio2 = 1;
544                break;
545        case 3:
546                gpio1 = 1;
547                gpio2 = 1;
548                break;
549        default:
550                gpio1 = 1;
551                gpio2 = 0;
552                break;
553        }
554
555        if (gpio1 == atoi(nvram_safe_get("gpio26"))
556            && gpio2 == atoi(nvram_safe_get("gpio27")))
557                needreset = 0;
558
559        if (gpio1) {
560                nvram_set("gpio26", "1");
561                set_gpio(26, 1);
562        } else {
563                nvram_set("gpio26", "0");
564                set_gpio(26, 0);
565        }
566        if (gpio2) {
567                nvram_set("gpio27", "1");
568                set_gpio(27, 1);
569        } else {
570                nvram_set("gpio27", "0");
571                set_gpio(27, 0);
572        }
573#endif
574        nvram_unset("3gnmvariant");
575        nvram_set("3gdata", "/dev/usb/tts/0");
576
577        int devicecount = 0;
578        while (devicelist[devicecount].vendor != 0xffff) {
579                if (scanFor
580                    (devicelist[devicecount].vendor,
581                     devicelist[devicecount].product)) {
582                        fprintf(stderr, "%s detected\n",
583                                devicelist[devicecount].name);
584                        if (devicelist[devicecount].driver) {
585                                insmod("usbserial");
586                                insmod("usb_wwan");
587                                insmod(devicelist[devicecount].driver);
588                        }
589                        if (devicelist[devicecount].datadevice) {
590                                static char data[32];
591                                if (!strcmp
592                                    (devicelist[devicecount].datadevice, "hso"))
593                                        sprintf(data, "hso");
594                                else {
595                                        if ((devicelist[devicecount].modeswitch
596                                             & ACM)) {
597                                                insmod("cdc-acm");
598                                                sprintf(data, "/dev/ttyACM%s",
599                                                        devicelist
600                                                        [devicecount].
601                                                        datadevice);
602                                        } else
603                                            if ((devicelist
604                                                 [devicecount].modeswitch &
605                                                 GENERIC)) {
606                                                sysprintf
607                                                    ("insmod usbserial vendor=0x%04X product=0x%04X",
608                                                     devicelist
609                                                     [devicecount].vendor,
610                                                     devicelist
611                                                     [devicecount].product);
612                                                sprintf(data, "/dev/usb/tts/%s",
613                                                        devicelist[devicecount].
614                                                        datadevice);
615                                        } else
616                                                sprintf(data, "/dev/usb/tts/%s",
617                                                        devicelist
618                                                        [devicecount].
619                                                        datadevice);
620
621                                }
622                                nvram_set("3gdata", data);
623                        }
624                        if (devicelist[devicecount].modeswitch & 0xf) {
625                                char variant[32];
626                                sprintf(variant, "%d",
627                                        devicelist[devicecount].modeswitch &
628                                        0xf);
629                                nvram_set("3gnmvariant", variant);
630                        }
631                        //start custom setup, if defined
632                        if (devicelist[devicecount].customsetup) {
633                                fprintf(stderr, "customsetup\n");
634                                devicelist[devicecount].customsetup(needreset,
635                                                                    devicelist
636                                                                    [devicecount].controldevice);
637                        }
638                        static char control[32];
639                        if (!strcmp
640                            (devicelist[devicecount].controldevice, "hso"))
641                                sprintf(control, "hso");
642                        else {
643                                if ((devicelist[devicecount].modeswitch & ACM)) {
644                                        insmod("cdc-acm");
645                                        sprintf(control, "/dev/ttyACM%s",
646                                                devicelist
647                                                [devicecount].controldevice);
648                                } else
649                                    if ((devicelist[devicecount].modeswitch &
650                                         GENERIC)) {
651                                        sysprintf
652                                            ("insmod usbserial vendor=0x%04X product=0x%04X",
653                                             devicelist[devicecount].vendor,
654                                             devicelist[devicecount].product);
655                                        sprintf(control, "/dev/usb/tts/%s",
656                                                devicelist
657                                                [devicecount].controldevice);
658                                } else
659                                        sprintf(control, "/dev/usb/tts/%s",
660                                                devicelist
661                                                [devicecount].controldevice);
662                        }
663                        return control;
664                }
665                devicecount++;
666        }
667        //not found, use generic implementation (tts0, all drivers)
668        insmod("cdc-acm");
669        insmod("usbserial");
670        insmod("usb_wwan");
671        insmod("sierra");
672        insmod("option");
673        return ttsdevice;
674}
675
676/*
677//future
678typedef struct {
679char *devicename;
680int vendorid;
681int productid;
682char *drivers;
683char *3gdata;
684char *controldevice;
685int iconswitch;
686}3GDEVICE;
687*/
Note: See TracBrowser for help on using the repository browser.