| 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("usbserial"); |
|---|
| 85 |
//insmod("sierra"); //further investigation required (compass problem) |
|---|
| 86 |
insmod("option"); |
|---|
| 87 |
insmod("ipw"); |
|---|
| 88 |
insmod("pl2303"); |
|---|
| 89 |
#endif |
|---|
| 90 |
|
|---|
| 91 |
char *ttsdevice = "/dev/usb/tts/0"; |
|---|
| 92 |
#ifdef HAVE_CAMBRIA |
|---|
| 93 |
eval("gpio", "enable", "26"); |
|---|
| 94 |
eval("gpio", "disable", "27"); |
|---|
| 95 |
if (nvram_match("wan_select", "1")) { |
|---|
| 96 |
eval("gpio", "enable", "26"); |
|---|
| 97 |
eval("gpio", "disable", "27"); |
|---|
| 98 |
} |
|---|
| 99 |
if (nvram_match("wan_select", "2")) { |
|---|
| 100 |
eval("gpio", "disable", "26"); |
|---|
| 101 |
eval("gpio", "enable", "27"); |
|---|
| 102 |
} |
|---|
| 103 |
if (nvram_match("wan_select", "3")) { |
|---|
| 104 |
eval("gpio", "enable", "26"); |
|---|
| 105 |
eval("gpio", "enable", "27"); |
|---|
| 106 |
} |
|---|
| 107 |
#endif |
|---|
| 108 |
nvram_set("3gdata", "/dev/usb/tts/0"); |
|---|
| 109 |
if (scanFor(0x1199, 0x6880)) { |
|---|
| 110 |
//sierra wireless |
|---|
| 111 |
fprintf(stderr, "Sierra Wireless Compass 885 deteted\n"); |
|---|
| 112 |
nvram_set("3gdata", "/dev/usb/tts/4"); |
|---|
| 113 |
return "/dev/usb/tts/3"; |
|---|
| 114 |
} |
|---|
| 115 |
if (scanFor(0x1199, 0x6890)) { |
|---|
| 116 |
//sierra wireless |
|---|
| 117 |
fprintf(stderr, "Sierra Wireless Compass 888 deteted\n"); |
|---|
| 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 |
checkreset("/dev/usb/tts/3"); |
|---|
| 126 |
return "/dev/usb/tts/3"; |
|---|
| 127 |
} |
|---|
| 128 |
if (scanFor(0x1199, 0x683D)) { |
|---|
| 129 |
//sierra wireless |
|---|
| 130 |
fprintf(stderr, "Sierra Wireless MC8790\n"); |
|---|
| 131 |
nvram_set("3gdata", "/dev/usb/tts/4"); |
|---|
| 132 |
checkreset("/dev/usb/tts/3"); |
|---|
| 133 |
return "/dev/usb/tts/3"; |
|---|
| 134 |
} |
|---|
| 135 |
if (scanFor(0x1199, 0x683E)) { |
|---|
| 136 |
//sierra wireless |
|---|
| 137 |
fprintf(stderr, "Sierra Wireless MC8790\n"); |
|---|
| 138 |
nvram_set("3gdata", "/dev/usb/tts/4"); |
|---|
| 139 |
checkreset("/dev/usb/tts/3"); |
|---|
| 140 |
return "/dev/usb/tts/3"; |
|---|
| 141 |
} |
|---|
| 142 |
if (scanFor(0x12d1, 0x1003)) { |
|---|
| 143 |
//huawei |
|---|
| 144 |
fprintf(stderr, "HUAWEI/Option E172 detected\n"); |
|---|
| 145 |
insmod("option"); |
|---|
| 146 |
return "/dev/usb/tts/0"; |
|---|
| 147 |
} |
|---|
| 148 |
if (scanFor(0x0af0, 0x7011)) { |
|---|
| 149 |
//huawei |
|---|
| 150 |
fprintf(stderr, "HUAWEI/Option E301 HSUPA detected\n"); |
|---|
| 151 |
insmod("option"); |
|---|
| 152 |
return "/dev/usb/tts/0"; |
|---|
| 153 |
} |
|---|
| 154 |
if (scanFor(0x12d1, 0x1001)) { |
|---|
| 155 |
//huawei |
|---|
| 156 |
fprintf(stderr, "HUAWEI/Option E600 detected\n"); |
|---|
| 157 |
insmod("option"); |
|---|
| 158 |
return "/dev/usb/tts/0"; |
|---|
| 159 |
} |
|---|
| 160 |
if (scanFor(0x12d1, 0x1003)) { |
|---|
| 161 |
//huawei |
|---|
| 162 |
fprintf(stderr, "HUAWEI/Option EC270 detected\n"); |
|---|
| 163 |
insmod("option"); |
|---|
| 164 |
return "/dev/usb/tts/0"; |
|---|
| 165 |
} |
|---|
| 166 |
if (scanFor(0x12d1, 0x1412)) { |
|---|
| 167 |
//huawei |
|---|
| 168 |
fprintf(stderr, "HUAWEI/Option EC168 detected\n"); |
|---|
| 169 |
insmod("option"); |
|---|
| 170 |
return "/dev/usb/tts/0"; |
|---|
| 171 |
} |
|---|
| 172 |
if (scanFor(0x12d1, 0x1412)) { |
|---|
| 173 |
//huawei |
|---|
| 174 |
fprintf(stderr, "HUAWEI/Option EC168 detected\n"); |
|---|
| 175 |
insmod("option"); |
|---|
| 176 |
return "/dev/usb/tts/0"; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if (scanFor(0x1e0e, 0x9000)) { |
|---|
| 180 |
//huawei |
|---|
| 181 |
fprintf(stderr, "QUALCOMM ICON 210 detected\n"); |
|---|
| 182 |
nvram_set("3gdata", "/dev/usb/tts/2"); |
|---|
| 183 |
insmod("option"); |
|---|
| 184 |
return "/dev/usb/tts/2"; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
if (scanFor(0x1e0e, 0xf000)) { |
|---|
| 188 |
//huawei |
|---|
| 189 |
fprintf(stderr, "QUALCOMM ICON 210 detected\n"); |
|---|
| 190 |
FILE *out = fopen("/tmp/usb_modeswitch.conf","wb"); |
|---|
| 191 |
fprintf(out,"DefaultVendor=0x1e0e\n"); |
|---|
| 192 |
fprintf(out,"DefaultProduct=0xf000\n"); |
|---|
| 193 |
fprintf(out,"TargetVendor=0x1e0e\n"); |
|---|
| 194 |
fprintf(out,"TargetProduct=0x9000\n"); |
|---|
| 195 |
fprintf(out,"MessageContent=\"555342431234567800000000000006bd000000020000000000000000000000\"\n"); |
|---|
| 196 |
fprintf(out,"ResponseEndpoint=0x01\n"); |
|---|
| 197 |
fclose(out); |
|---|
| 198 |
system("usb_modeswitch -c /tmp/usb_modeswitch.conf"); |
|---|
| 199 |
sleep(2); |
|---|
| 200 |
insmod("option"); |
|---|
| 201 |
nvram_set("3gdata", "/dev/usb/tts/2"); |
|---|
| 202 |
return "/dev/usb/tts/2"; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
if (scanFor(0x0af0, 0x6971)) { |
|---|
| 206 |
//huawei |
|---|
| 207 |
fprintf(stderr, "QUALCOMM ICON 225 detected\n"); |
|---|
| 208 |
/* FILE *out = fopen("/tmp/usb_modeswitch.conf","wb"); |
|---|
| 209 |
fprintf(out,"DefaultVendor=0x0af0\n"); |
|---|
| 210 |
fprintf(out,"DefaultProduct=0x6971\n"); |
|---|
| 211 |
fprintf(out,"TargetClass=0xff\n"); |
|---|
| 212 |
fprintf(out,"MessageContent=\"55534243785634120100000080000601000000000000000000000000000000\"\n"); |
|---|
| 213 |
fclose(out); |
|---|
| 214 |
system("usb_modeswitch -c /tmp/usb_modeswitch.conf");*/ |
|---|
| 215 |
system("ozerocdoff -wi 0x6971"); |
|---|
| 216 |
sleep(5); |
|---|
| 217 |
system("insmod hso"); |
|---|
| 218 |
nvram_set("3gdata", "/dev/usb/tts/2"); |
|---|
| 219 |
return "/dev/usb/tts/2"; |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
if (scanFor(0x1199, 0x6832)) { |
|---|
| 225 |
//sierra wireless mc 8780 |
|---|
| 226 |
fprintf(stderr, |
|---|
| 227 |
"Sierra Wireless MC 8780 detected\nreset card\n"); |
|---|
| 228 |
checkreset("/dev/usb/tts/2"); |
|---|
| 229 |
return "/dev/usb/tts/2"; |
|---|
| 230 |
} |
|---|
| 231 |
insmod("option"); |
|---|
| 232 |
return ttsdevice; |
|---|
| 233 |
} |
|---|