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

Last change on this file since 15995 was 15995, checked in by BrainSlayer, 2 years ago

support some nokia devices

File size: 25.8 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        eval("comgt", "-d", tty, "-s", "/etc/comgt/reset.comgt");
95        FILE *check = NULL;
96        int count = 0;
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        eval("comgt", "-d", tty, "-s", "/etc/comgt/wakeup.comgt");
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 55534243123456780600000080000601000000000000000000000000000000");
204        system
205            ("usb_modeswitch -v 0x12d1 -p 0x1031 -M 55534243123456780600000080010a11060000000000000000000000000000");
206        system
207            ("usb_modeswitch -v 0x12d1 -p 0x1446 -M 55534243123456780000000000000011060000000000000000000000000000");
208        system
209            ("usb_modeswitch -v 0x12d1 -p 0x14ad -M 55534243123456780000000000000011060000000000000000000000000000");
210        system
211            ("usb_modeswitch -v 0x12d1 -p 0x14c6 -M 55534243123456780000000000000011060000000000000000000000000000");
212        system
213            ("usb_modeswitch -v 0x12d1 -p 0x1520 -M 55534243123456780000000000000011060000000000000000000000000000");
214        system
215            ("usb_modeswitch -v 0x12d1 -p 0x1521 -M 55534243123456780000000000000011060000000000000000000000000000");
216        system
217            ("usb_modeswitch -v 0x12d1 -p 0x1523 -M 55534243123456780000000000000011060000000000000000000000000000");
218        system
219            ("usb_modeswitch -v 0x12d1 -p 0x1557 -M 55534243123456780000000000000011060000000000000000000000000000");
220        sleep(2);
221}
222
223static void modeswitch_icon210(int needreset, char *controldev)
224{
225        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
226        fprintf(out, "DefaultVendor=0x1e0e\n");
227        fprintf(out, "DefaultProduct=0xf000\n");
228        fprintf(out, "TargetVendor=0x1e0e\n");
229        fprintf(out, "TargetProductList=\"9200,9000\"\n");
230        fprintf(out,
231                "MessageContent=\"555342431234567800000000000006bd000000020000000000000000000000\"\n");
232        fprintf(out, "NeedResponse=1\n");
233        fclose(out);
234        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
235        sleep(2);
236}
237
238static void modeswitch_nokia(int needreset, char *controldev)
239{
240        FILE *out = fopen("/tmp/usb_modeswitch.conf", "wb");
241        fprintf(out, "DefaultVendor=0x0421\n");
242        fprintf(out, "DefaultProduct=0x060c\n");
243        fprintf(out, "TargetVendor=0x0421\n");
244        fprintf(out, "TargetProduct=0x060e\n");
245        fprintf(out, "CheckSuccess=20\n");
246        fprintf(out,
247                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
248        fclose(out);
249        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
250        out = fopen("/tmp/usb_modeswitch.conf", "wb");
251        fprintf(out, "DefaultVendor=0x0421\n");
252        fprintf(out, "DefaultProduct=0x0610\n");
253        fprintf(out, "TargetVendor=0x0421\n");
254        fprintf(out, "TargetProduct=0x0612\n");
255        fprintf(out, "CheckSuccess=20\n");
256        fprintf(out,
257                "MessageContent=\"5553424312345678000000000000061b000000020000000000000000000000\"\n");
258        fclose(out);
259        system("usb_modeswitch -c /tmp/usb_modeswitch.conf");
260        sleep(2);
261}
262
263static void hsoinit_icon225(int needreset, char *controldev)
264{
265        system("ozerocdoff -wi 0x6971");
266        sleep(10);
267        system("insmod hso");
268        FILE *out = fopen("/tmp/conninfo.ini", "wb");
269        fprintf(out, "APN=%s\n", nvram_safe_get("wan_apn"));
270        fprintf(out, "USER=%s\n", nvram_safe_get("ppp_username"));
271        fprintf(out, "PASS=%s\n", nvram_safe_get("ppp_passwd"));
272        fprintf(out, "PIN=%s\n", nvram_safe_get("wan_pin"));
273        fclose(out);
274        nvram_set("3gdata", "hso");
275        system("/etc/hso/hso_connect.sh restart");
276}
277
278struct DEVICES {
279        int vendor;
280        int product;
281        char *driver;
282        char *controldevice;
283        char *datadevice;
284        int modeswitch;
285        void (*customsetup) (int needreset, char *controldev);
286        char *name;
287};
288
289static struct DEVICES devicelist[] = {
290//sierra wireless cards
291        {0x1199, 0x0fff, "sierra", "3", "4", 1, &modeswitch_sierra, "Sierra Device CDROM Mode"},        //
292        {0x1199, 0x0017, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
293        {0x1199, 0x0018, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
294        {0x1199, 0x0019, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC595U Modem Mode"},     //
295        {0x1199, 0x0020, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
296        {0x1199, 0x0021, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC597E Modem Mode"},     //
297        {0x1199, 0x0022, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
298        {0x1199, 0x0024, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC5727 CDMA Modem Mode"},        //
299        {0x1199, 0x0026, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
300        {0x1199, 0x0027, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
301        {0x1199, 0x0028, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
302        {0x1199, 0x0029, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
303        {0x1199, 0x0112, "sierra", "3", "4", 1, NULL, "Sierra Wireless CDMA 1xEVDO PC Card, Aircard 580 Modem Mode"},   //
304        {0x1199, 0x0120, "sierra", "3", "4", 1, NULL, "Sierra Wireless AC595U Modem Mode"},     //
305        {0x1199, 0x0218, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC5720 Wireless Modem"}, //
306        {0x1199, 0x0220, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
307        {0x1199, 0x0224, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
308        {0x1199, 0x6802, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
309        {0x1199, 0x6803, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8765 Modem Mode"},     //
310        {0x1199, 0x6804, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
311        {0x1199, 0x6805, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8765 Modem Mode"},     //
312        {0x1199, 0x6808, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
313        {0x1199, 0x6809, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8755 Modem Mode"},     //
314        {0x1199, 0x6812, "sierra", "0", "2", 1, &reset_mc, "Sierra Wireless MC8775V"},  //
315        {0x1199, 0x6813, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
316        {0x1199, 0x6815, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
317        {0x1199, 0x6816, "sierra", "0", "2", 1, NULL, "Sierra Wireless MC8775 Modem Mode"},     //
318        {0x1199, 0x6820, "sierra", "0", "2", 1, NULL, "Sierra Wireless AC875 Modem Mode"},      //
319        {0x1199, 0x6821, "sierra", "2", "0", 1, NULL, "Sierra Wireless AC875U Modem Mode"},     //
320        {0x1199, 0x6822, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
321        {0x1199, 0x6832, "sierra", "2", "0", 1, &reset_mc, "Sierra Wireless MC8780 Modem Mode"},        //
322        {0x1199, 0x6833, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8781 Modem Mode"},     //
323        {0x1199, 0x6834, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
324        {0x1199, 0x6835, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
325        {0x1199, 0x6838, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
326        {0x1199, 0x6839, "sierra", "3", "4", 1, NULL, "Sierra Wireless Modem Mode"},    //
327        {0x1199, 0x683a, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8785 Modem Mode"},     //
328        {0x1199, 0x683b, "sierra", "3", "4", 1, NULL, "Sierra Wireless MC8785 Composite Modem Mode"},   //
329        {0x1199, 0x683c, "sierra", "3", "4", 1, &reset_mc, "Sierra Wireless MC8790"},   //
330        {0x1199, 0x683d, "sierra", "3", "4", 1, &reset_mc, "Sierra Wireless MC8791 Composite"}, //
331        {0x1199, 0x683e, "sierra", "3", "4", 1, &reset_mc, "Sierra Wireless MC8790"},   //
332        {0x1199, 0x6850, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 880 Modem Mode"},        //
333        {0x1199, 0x6851, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 881 Modem Mode"},        //
334        {0x1199, 0x6852, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 880E Modem Mode"},       //
335        {0x1199, 0x6853, "sierra", "2", "0", 1, NULL, "Sierra Wireless AirCard 881E Modem Mode"},       //
336        {0x1199, 0x6855, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
337        {0x1199, 0x6856, "sierra", "2", "0", 1, NULL, "Sierra Wireless ATT USB Connect 881 Modem Mode"},        //
338        {0x1199, 0x6859, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
339        {0x1199, 0x685a, "sierra", "2", "0", 1, NULL, "Sierra Wireless Modem Mode"},    //
340        {0x1199, 0x6880, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 885"},   //
341        {0x1199, 0x6890, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 888"},   //
342        {0x1199, 0x6893, "sierra", "3", "3", 1, NULL, "Sierra Wireless Compass 889"},   //
343//      {0x1199, 0x68a3, "sierra", "3", "4", 1, NULL, "Sierra Wireless Compass 889"},   //alternate variant
344        {0x1199, 0x68a3, "sierra", "2", "2", 1, &reset_mc, "Sierra Wireless MC8700/Compass Direct IP"}, //
345//option/huawei
346        {0x12d1, 0x1001, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E600/E620 or generic"},      //
347        {0x12d1, 0x1003, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E172/EC27/E220/E230/E270 HSDPA/HSUPA Model"},        //
348        {0x12d1, 0x1009, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option U120"},      //
349        {0x12d1, 0x101e, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI U7510 / U7517"},    //
350        {0x12d1, 0x1031, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI U8110 (Android smartphone)"},       //
351        {0x12d1, 0x1035, "option", "0", "0", 2, NULL, "HUAWEI U8110 (Android smartphone)"},     //
352        {0x12d1, 0x1414, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E180"},      //
353        {0x12d1, 0x1406, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
354        {0x12d1, 0x140b, "option", "0", "0", 2, NULL, "HUAWEI/Option EC1260 Wireless Data Modem HSD USB Card"}, //
355        {0x12d1, 0x140c, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
356        {0x12d1, 0x1412, "option", "0", "0", 2, NULL, "HUAWEI/Option EC168"},   //
357        {0x12d1, 0x141b, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
358        {0x12d1, 0x14ac, "option", "0", "0", 2, NULL, "HUAWEI/Option newer modems"},    //
359        {0x12d1, 0x14ae, "option", "0", "0", 2, NULL, "Vodafone (Huawei) K3806"},       //
360        {0x12d1, 0x1446, "option", "0", "0", 2, &modeswitch_huawei, "HUAWEI/Option E1552 HSPA Modem"},  //
361        {0x12d1, 0x14ad, "option", "0", "0", 2, &modeswitch_huawei, "Vodafone (Huawei) K3806"}, //
362        {0x12d1, 0x14c1, "option", "0", "0", 2, &modeswitch_huawei, "Vodafone (Huawei) K4605"}, //
363        {0x12d1, 0x14c6, "option", "0", "0", 2, NULL, "Vodafone (Huawei) K4605"},       //
364        {0x12d1, 0x1520, "option", "0", "0", 2, &modeswitch_huawei, "Huawei K3765"},    //
365        {0x12d1, 0x1465, "option", "0", "0", 2, NULL, "Huawei K3765"},  //
366        {0x12d1, 0x1521, "option", "0", "0", 2, &modeswitch_huawei, "Huawei K4505"},    //
367        {0x12d1, 0x1464, "option", "0", "0", 2, NULL, "Huawei K4505"},  //
368        {0x12d1, 0x1521, "option", "0", "0", 2, &modeswitch_huawei, "Huawei R201"},     //
369        {0x12d1, 0x1491, "option", "0", "0", 2, NULL, "Huawei R201"},   //
370        {0x12d1, 0x1557, "option", "0", "0", 2, &modeswitch_huawei, "Huawei E173"},     //
371        {0x12d1, 0x14a5, "option", "0", "0", 2, NULL, "Huawei E173"},   //
372
373        {0x0af0, 0x7011, "option", "0", "0", 2, NULL, "HUAWEI/Option E301 HSUPA"},      //
374
375        {0x1410, 0x5010, "option", "0", "0", 2, &modeswitch_usb760, "Novatel CDROM Mode"},      //
376        {0x1410, 0x5020, "option", "0", "0", 2, &modeswitch_usb760, "Novatel MC990D CDROM Mode"},       //
377        {0x1410, 0x5030, "option", "0", "0", 2, &modeswitch_usb760, "Novatel USB760 CDROM Mode"},       //
378        {0x1410, 0x5031, "option", "0", "0", 2, &modeswitch_usb760, "Novatel USB760 3G CDROM Mode"},    //
379        {0x1410, 0x5041, "option", "0", "0", 2, &modeswitch_usb760, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 CDROM Mode"},       //
380        {0x1410, 0x4100, "option", "0", "0", 2, NULL, "Novatel U727 Modem Mode"},       //
381        {0x1410, 0x4400, "option", "0", "0", 2, NULL, "Novatel Ovation MC930D/MC950D Modem Mode"},      //
382
383        {0x1410, 0x7001, "option", "0", "0", 2, NULL, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 Modem Mode"},     //
384        {0x1410, 0x7003, "option", "0", "0", 2, NULL, "Novatel Generic MiFi 2352 / Vodafone MiFi 2352 Modem Mode"},     //
385
386        {0x1410, 0x6000, "option", "0", "0", 2, NULL, "Novatel USB760 Modem Mode"},     //
387        {0x1410, 0x6002, "option", "0", "0", 2, NULL, "Novatel USB760 3G Modem Mode"},  //
388//qualcomm
389        {0x1e0e, 0x9000, "option", "2", "2", 3, NULL, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU Modem Mode"},        //
390        {0x1e0e, 0x9200, "option", "2", "2", 3, NULL, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU Modem Mode"},        //
391        {0x1e0e, 0xf000, "option", "2", "2", 3, &modeswitch_icon210, "Option iCON 210, PROLiNK PHS100, Hyundai MB-810, A-Link 3GU CDROM Mode"}, //
392        {0x0af0, 0x6971, NULL, "hso", "hso", 0, &hsoinit_icon225, "Qualcomm ICON 225"}, //
393//ericsson
394        {0x0bdb, 0x1900, "option", "4", "4", 0, NULL, "Ericsson F3507g"},       //
395        {0x0bdb, 0x1902, "option", "4", "4", 0, NULL, "Ericsson F3507g"},       //
396//ONDA
397        {0x19d2, 0x2000, "option", "1", "1", 2, &modeswitch_onda, "ONDA/ZTE (cdrom mode)"},     //
398        {0x19d2, 0x0001, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
399        {0x19d2, 0x0002, "option", "1", "3", 2, NULL, "ZTE ET502HS/MT505UP/MF632"},     //
400        {0x19d2, 0x0003, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MU351 (cdrom mode)"},   //
401        {0x19d2, 0x0015, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
402        {0x19d2, 0x0016, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
403        {0x19d2, 0x0017, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
404        {0x19d2, 0x0022, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K2525 (modem mode)"},     //
405        {0x19d2, 0x0026, "option", "1", "3", 2, &modeswitch_onda2, "ZTE AC581 (cdrom mode)"},   //
406        {0x19d2, 0x0031, "option", "1", "2", 2, NULL, "ZTE MF110/MF112/MF626 (Variant) (modem mode)"},  //tested on MF626
407        {0x19d2, 0x0037, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
408        {0x19d2, 0x0040, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K2525 (cdrom mode)"},        //
409        {0x19d2, 0x0052, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
410        {0x19d2, 0x0053, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF110 (Variant) (modem mode)"}, //
411        {0x19d2, 0x0055, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
412        {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
413        {0x19d2, 0x0064, "option", "1", "3", 2, NULL, "ZTE MF627 AU (modem mode)"},     //
414        {0x19d2, 0x0083, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF110 (Variant) (cdrom mode)"}, //
415        {0x19d2, 0x0094, "option", "1", "3", 2, NULL, "ZTE AC581 (modem mode)"},        //
416        {0x19d2, 0x0101, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K4505-Z (cdrom mode)"},      //
417        {0x19d2, 0x0103, "option", "1", "3", 2, &modeswitch_onda2, "ZTE MF112 (cdrom mode)"},   //
418        {0x19d2, 0x0104, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K4505-Z (modem mode)"},   //
419        {0x19d2, 0x0108, "option", "1", "3", 2, NULL, "ONDA MT505UP/ZTE (modem mode)"}, //
420        {0x19d2, 0x0115, "option", "1", "3", 2, &modeswitch_onda2, "ONDA MT505UP/ZTE (modem mode)"},    //
421        {0x19d2, 0x0116, "option", "1", "3", 2, NULL, "ZTE MF651 (cdrom mode)"},        //
422        {0x19d2, 0x0117, "option", "1", "2", 2, NULL, "ZTE MF112 (modem mode)"},        // tested, works
423        {0x19d2, 0x0128, "option", "1", "3", 2, NULL, "ZTE MF651 (modem mode)"},        //
424        {0x19d2, 0x0124, "option", "1", "3", 2, NULL, "ZTE MF110 (Variant) (modem mode)"},      //
425        {0x19d2, 0x1001, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3805-Z (cdrom mode)"},      //
426        {0x19d2, 0x1003, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3805-Z (modem mode)"},   //
427        {0x19d2, 0x1007, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3570-Z (cdrom mode)"},      //
428        {0x19d2, 0x1008, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3570-Z (modem mode)"},   //
429        {0x19d2, 0x1009, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3571-Z (cdrom mode)"},      //
430        {0x19d2, 0x1010, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3571-Z (modem mode)"},   //
431        {0x19d2, 0x1013, "option", "1", "3", 2, &modeswitch_onda2, "Vodafone (ZTE) K3806-Z (cdrom mode)"},      //
432        {0x19d2, 0x1015, "option", "1", "3", 2, NULL, "Vodafone (ZTE) K3806-Z (modem mode)"},   //
433        {0x19d2, 0xfff5, "option", "1", "3", 2, &modeswitch_onda2, "ZTE generic (cdrom mode)"}, //
434        {0x19d2, 0xfff6, "option", "1", "3", 2, &modeswitch_onda2, "ZTE generic (cdrom mode)"}, //
435        {0x19d2, 0xfff1, "option", "1", "3", 2, NULL, "ZTE generic (modem mode)"},      //
436        {0x19d2, 0xffff, "option", "1", "3", 2, NULL, "ZTE generic (modem mode)"},      //
437        {0x0421, 0x060c, "option", "0", "0", 2, &modeswitch_nokia, "Nokia CS-10 (cdrom mode)"}, //
438        {0x0421, 0x060e, "option", "0", "0", 2, NULL, "Nokia CS-10 (modem mode)"},      //
439        {0x0421, 0x0610, "option", "0", "0", 2, &modeswitch_nokia, "Nokia CS-15 (cdrom mode)"}, //
440        {0x0421, 0x0612, "option", "0", "0", 2, NULL, "Nokia CS-15 (modem mode)"},      //
441
442        {0xffff, 0xffff, NULL, NULL, NULL, 0, NULL, NULL}       //
443};
444
445char *get3GControlDevice(void)
446{
447#if defined(ARCH_broadcom) && !defined(HAVE_BCMMODERN)
448        mkdir("/tmp/usb");
449        eval("mount", "-t", "usbfs", "usb", "/tmp/usb");
450//insmod("sierra");  //further investigation required (compass problem)
451#endif
452        int needreset = 1;
453        char *ttsdevice = "/dev/usb/tts/0";
454#ifdef HAVE_CAMBRIA
455        int gpio1 = atoi(nvram_safe_get("gpio26"));
456        int gpio2 = atoi(nvram_safe_get("gpio27"));
457        int select = atoi(nvram_safe_get("wan_select"));
458        switch (select) {
459        case 1:
460                if (gpio1 == 1 || gpio2 == 0)
461                        needreset = 0;
462                else {
463                        gpio1 = 1;
464                        gpio2 = 0;
465                }
466                break;
467        case 2:
468                if (gpio1 == 0 || gpio2 == 1)
469                        needreset = 0;
470                else {
471                        gpio1 = 0;
472                        gpio2 = 1;
473                }
474                break;
475        case 3:
476                if (gpio1 == 1 || gpio2 == 1)
477                        needreset = 0;
478                else {
479                        gpio1 = 1;
480                        gpio2 = 1;
481                }
482                break;
483        default:
484                if (gpio1 == 0 && gpio2 == 0) {
485                        gpio1 = 1;
486                        gpio2 = 0;
487                } else
488                        needreset = 0;
489                break;
490        }
491        if (gpio1) {
492                nvram_set("gpio26", "1");
493                set_gpio(26, 1);
494        } else {
495                nvram_set("gpio26", "0");
496                set_gpio(26, 0);
497        }
498        if (gpio2) {
499                nvram_set("gpio27", "1");
500                set_gpio(27, 1);
501        } else {
502                nvram_set("gpio27", "0");
503                set_gpio(27, 0);
504        }
505#endif
506        nvram_unset("3gnmvariant");
507        nvram_set("3gdata", "/dev/usb/tts/0");
508
509        int devicecount = 0;
510        while (devicelist[devicecount].vendor != 0xffff) {
511                if (scanFor
512                    (devicelist[devicecount].vendor,
513                     devicelist[devicecount].product)) {
514                        fprintf(stderr, "%s detected\n",
515                                devicelist[devicecount].name);
516                        if (devicelist[devicecount].driver) {
517                                insmod("usbserial");
518                                insmod(devicelist[devicecount].driver);
519                        }
520                        if (devicelist[devicecount].datadevice) {
521                                static char data[32];
522                                if (!strcmp
523                                    (devicelist[devicecount].datadevice, "hso"))
524                                        sprintf(data, "hso");
525                                else {
526                                        if (devicelist[devicecount].vendor ==
527                                            0x0421)
528                                                sprintf(data, "/dev/ttyACM%s",
529                                                        devicelist
530                                                        [devicecount].datadevice);
531                                        else
532                                                sprintf(data, "/dev/usb/tts/%s",
533                                                        devicelist
534                                                        [devicecount].datadevice);
535
536                                }
537                                nvram_set("3gdata", data);
538                        }
539                        if (devicelist[devicecount].modeswitch) {
540                                char variant[32];
541                                sprintf(variant, "%d",
542                                        devicelist[devicecount].modeswitch);
543                                nvram_set("3gnmvariant", variant);
544                        }
545                        //start custom setup, if defined
546                        if (devicelist[devicecount].customsetup)
547                                devicelist[devicecount].customsetup(needreset,
548                                                                    devicelist
549                                                                    [devicecount].
550                                                                    controldevice);
551                        static char control[32];
552                        if (!strcmp
553                            (devicelist[devicecount].controldevice, "hso"))
554                                sprintf(control, "hso");
555                        else {
556                                if (devicelist[devicecount].vendor == 0x0421)
557                                        sprintf(control, "/dev/ttyACM%s",
558                                                devicelist[devicecount].
559                                                controldevice);
560                                else
561                                        sprintf(control, "/dev/usb/tts/%s",
562                                                devicelist[devicecount].
563                                                controldevice);
564                        }
565                        return control;
566                }
567                devicecount++;
568        }
569        //not found, use generic implementation (tts0, all drivers)
570        insmod("cdc_acm");
571        insmod("usbserial");
572        insmod("sierra");
573        insmod("option");
574        return ttsdevice;
575}
576
577/*
578//future
579typedef struct {
580char *devicename;
581int vendorid;
582int productid;
583char *drivers;
584char *3gdata;
585char *controldevice;
586int iconswitch;
587}3GDEVICE;
588*/
Note: See TracBrowser for help on using the repository browser.