/
usb.c
5564 lines (4766 loc) · 140 KB
/
usb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
USB Support
*/
#include <rc.h>
#ifdef RTCONFIG_PERMISSION_MANAGEMENT
#include <PMS_DBAPIs.h>
#endif
#ifdef RTCONFIG_USB
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <proto/ethernet.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/mount.h>
#include <mntent.h>
#include <dirent.h>
#include <sys/file.h>
#include <sys/swap.h>
#include <sys/vfs.h>
#include <sys/stat.h>
#include <rc_event.h>
#include <shared.h>
#include <disk_io_tools.h>
#include <disk_share.h>
#include <disk_initial.h>
char *usb_dev_file = "/proc/bus/usb/devices";
#define ERR_DISK_FS_RDONLY "1"
#define ERR_DISK_SCSI_KILL "10"
#define USB_CLS_PER_INTERFACE 0 /* for DeviceClass */
#define USB_CLS_AUDIO 1
#define USB_CLS_COMM 2
#define USB_CLS_HID 3
#define USB_CLS_PHYSICAL 5
#define USB_CLS_STILL_IMAGE 6
#define USB_CLS_PRINTER 7
#define USB_CLS_MASS_STORAGE 8
#define USB_CLS_HUB 9
#define USB_CLS_CDC_DATA 0x0a
#define USB_CLS_CSCID 0x0b /* chip+ smart card */
#define USB_CLS_CONTENT_SEC 0x0d /* content security */
#define USB_CLS_VIDEO 0x0e
#define USB_CLS_WIRELESS_CONTROLLER 0xe0
#define USB_CLS_MISC 0xef
#define USB_CLS_APP_SPEC 0xfe
#define USB_CLS_VENDOR_SPEC 0xff
#define USB_CLS_3GDEV 0x35
#define OP_MOUNT 1
#define OP_UMOUNT 2
#define OP_SETNVRAM 3
char *find_sddev_by_mountpoint(char *mountpoint);
/* Adjust bdflush parameters.
* Do this here, because Tomato doesn't have the sysctl command.
* With these values, a disk block should be written to disk within 2 seconds.
*/
#ifdef LINUX26
void tune_bdflush(void)
{
f_write_string("/proc/sys/vm/dirty_writeback_centisecs", "200", 0, 0);
#ifndef RTCONFIG_BCMARM
f_write_string("/proc/sys/vm/dirty_expire_centisecs", "200", 0, 0);
#else
printf("no tune_bdflush\n");
#endif
}
#else
#include <sys/kdaemon.h>
#define SET_PARM(n) (n * 2 | 1)
void tune_bdflush(void)
{
bdflush(SET_PARM(5), 100);
bdflush(SET_PARM(6), 100);
bdflush(SET_PARM(8), 0);
}
#endif // LINUX26
#define NFS_EXPORT "/etc/exports"
#ifdef RTCONFIG_USB_PRINTER
void
start_lpd()
{
pid_t pid;
char *lpd_argv[] = { "lpd", NULL, NULL };
if(getpid()!=1) {
notify_rc("start_lpd");
return;
}
#ifdef RTAC68U
if (!hw_usb_cap())
return;
#endif
if (!pids("lpd"))
{
unlink("/var/run/lpdparent.pid");
if (is_routing_enabled())
lpd_argv[1] = nvram_safe_get("lan_ifname");
//return xstart("lpd");
_eval(lpd_argv, NULL, 0, &pid);
}
}
void
stop_lpd()
{
if(getpid()!=1) {
notify_rc("stop_lpd");
return;
}
if (pids("lpd"))
{
killall_tk("lpd");
unlink("/var/run/lpdparent.pid");
}
}
void
start_u2ec()
{
pid_t pid;
char *u2ec_argv[] = { "u2ec", NULL };
if(getpid()!=1) {
notify_rc("start_u2ec");
return;
}
#ifdef RTAC68U
if (!hw_usb_cap())
return;
#endif
if (!pids("u2ec"))
{
unlink("/var/run/u2ec.pid");
_eval(u2ec_argv, NULL, 0, &pid);
nvram_set("apps_u2ec_ex", "1");
}
}
void
stop_u2ec()
{
#if defined(RTCONFIG_QCA)
nvram_commit();
#endif
if(getpid()!=1) {
notify_rc("stop_u2ec");
return;
}
if (pids("u2ec")){
killall_tk("u2ec");
unlink("/var/run/u2ec.pid");
}
}
#endif
FILE* fopen_or_warn(const char *path, const char *mode)
{
FILE *fp = fopen(path, mode);
if (!fp)
{
dbg("hotplug USB: No such file or directory: %s\n", path);
errno = 0;
return NULL;
}
return fp;
}
#ifdef DLM
int
test_user(char *target, char *pattern)
{
char s[384];
char p[32];
char *start;
char *pp;
strcpy(s, target);
strcpy(p, pattern);
start = s;
while ((pp=strchr(start, ';')) != NULL)
{
*pp='\0';
if (! strcmp(start, p))
return 1;
start=pp+1;
}
return 0;
}
int
fill_smbpasswd_input_file(const char *passwd)
{
FILE *fp;
unlink("/tmp/smbpasswd");
fp = fopen("/tmp/smbpasswd", "w");
if (fp && passwd)
{
fprintf(fp,"%s\n", passwd);
fprintf(fp,"%s\n", passwd);
fclose(fp);
return 1;
}
else
return 0;
}
#endif
void add_usb_host_module(void)
{
#if defined(HND_ROUTER)
tweak_usb_affinity(1);
#endif
#if defined(RTCONFIG_USB_XHCI)
#if defined(RTN65U) || defined(RTCONFIG_QCA) || defined(RTAC85U)
char *u3_param = "u3intf=0";
#endif
#endif
char param[32];
int i;
#ifdef RTAC68U
if (!hw_usb_cap())
return;
#endif
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(3,2,0)
modprobe(USBCOMMON_MOD);
#endif
modprobe(USBCORE_MOD);
#if defined(RTCONFIG_USB_XHCI)
#if defined(RTN65U) || defined(RTCONFIG_QCA) || defined(RTAC85U)
if (nvram_get_int("usb_usb3") == 1)
u3_param = "u3intf=1";
#if !defined(RTCONFIG_SOC_IPQ40XX)
modprobe(USB30_MOD, u3_param);
#endif
#if defined(RTCONFIG_SOC_IPQ8064)
modprobe("udc-core");
modprobe("dwc3-ipq");
#endif
#elif defined(RTCONFIG_XHCIMODE)
modprobe(USB30_MOD);
#elif defined(RTCONFIG_LANTIQ)
modprobe(USB30_MOD);
#elif defined(RTCONFIG_ALPINE)
modprobe(USB30_MOD);
#else
if (nvram_get_int("usb_usb3") == 1) {
modprobe(USB30_MOD);
#ifdef HND_ROUTER
modprobe("xhci-plat-hcd");
#endif
}
#endif
#endif // RTCONFIG_USB_XHCI
/* if enabled, force USB2 before USB1.1 */
if (nvram_get_int("usb_usb2") == 1) {
#if defined(RTN56UB1) || defined(RTN56UB2) || defined(RTAC1200GA1) || defined(RTAC1200GU)
modprobe(USB20_MOD);
#else
i = nvram_get_int("usb_irq_thresh");
if ((i < 0) || (i > 6))
i = 0;
sprintf(param, "log2_irq_thresh=%d", i);
modprobe(USB20_MOD, param);
#ifdef HND_ROUTER
modprobe("ehci-platform");
#endif
#endif
}
#ifndef RTCONFIG_LANTIQ
// BlueCave: ehci will handle USB 2.0 & 1.x.
if (nvram_get_int("usb_uhci") == 1) {
modprobe(USBUHCI_MOD);
}
if (nvram_get_int("usb_ohci") == 1) {
modprobe(USBOHCI_MOD);
#ifdef HND_ROUTER
modprobe("ohci-platform");
#endif
}
#endif
#if defined(RTCONFIG_SOC_IPQ40XX)
modprobe(USB_PHY1);
modprobe(USB_PHY2);
modprobe(USB_DWC3_IPQ);
modprobe(USB_DWC3);
#if defined(RTCONFIG_USB_XHCI)
modprobe(USB30_MOD, u3_param);
/* workaround for some USB dongle */
modprobe_r(USB_DWC3_IPQ);
modprobe(USB_DWC3_IPQ);
#endif
#endif
#ifdef HND_ROUTER
if(!nvram_get_int("usb_usb3")){
modprobe(USB30_MOD);
modprobe("xhci-plat-hcd");
}
modprobe("bcm_usb");
if(!nvram_get_int("usb_usb3")){
modprobe_r("xhci-plat-hcd");
modprobe_r(USB30_MOD);
}
#endif
}
#ifdef RTCONFIG_USB_MODEM
static int usb_modem_modules_loaded = 0;
void add_usb_modem_modules(void)
{
if (usb_modem_modules_loaded)
return;
usb_modem_modules_loaded = 1;
#ifdef RTAC68U
if (!hw_usb_cap())
return;
#endif
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe("mii"); // for usbnet.
#endif
modprobe("usbnet");
#ifdef RTCONFIG_INTERNAL_GOBI
if(nvram_get_int("usb_gobi"))
modprobe("gobi");
#endif
modprobe("cdc-acm");
#if !defined(RTCONFIG_INTERNAL_GOBI) || defined(RTCONFIG_USB_MULTIMODEM)
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe("libphy");
#endif
modprobe("asix");
modprobe("ax88179_178a");
modprobe("cdc_ether");
modprobe("rndis_host");
modprobe("cdc_ncm");
modprobe("cdc_wdm");
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe("huawei_cdc_ncm"); // depend on cdc_ncm, cdc_wdm.
#endif
if(nvram_get_int("usb_qmi"))
modprobe("qmi_wwan");
modprobe("cdc_mbim");
#endif
}
void remove_usb_modem_modules(void)
{
#ifdef RTCONFIG_USB_BECEEM
modprobe_r("drxvi314");
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
killall_tk("gobi");
modprobe_r("gobi");
#endif
#if !defined(RTCONFIG_INTERNAL_GOBI) || defined(RTCONFIG_USB_MULTIMODEM)
modprobe_r("cdc_mbim");
modprobe_r("qmi_wwan");
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe_r("huawei_cdc_ncm");
#endif
modprobe_r("cdc_wdm");
modprobe_r("cdc_ncm");
modprobe_r("rndis_host");
modprobe_r("cdc_ether");
modprobe_r("ax88179_178a");
modprobe_r("asix");
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe_r("libphy");
#endif
modprobe_r("option");
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36)
modprobe_r("usb_wwan");
#endif
modprobe_r("usbserial");
#endif
modprobe_r("cdc-acm");
modprobe_r("usbnet");
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(4,1,0)
modprobe_r("mii"); // for usbnet.
#endif
modprobe_r("sr_mod");
modprobe_r("cdrom");
usb_modem_modules_loaded = 0;
}
#ifdef RTCONFIG_INTERNAL_GOBI
#if defined(RTCONFIG_JFFS2) || defined(RTCONFIG_BRCM_NAND_JFFS2) || defined(RTCONFIG_UBIFS)
int modem_data_update(int sim_order){
int modem_unit, wan_unit;
char tmp[100], prefix[32];
char *modem_dev;
unsigned long long rx_old, tx_old;
unsigned long long rx_reset, tx_reset;
unsigned long long rx_new, tx_new;
unsigned long long rx_now, tx_now;
char path[256];
printf("Updating %dth net traffic:\n", sim_order);
for(modem_unit = MODEM_UNIT_FIRST; modem_unit < MODEM_UNIT_MAX; ++modem_unit){
usb_modem_prefix(modem_unit, prefix, sizeof(prefix));
modem_dev = nvram_safe_get(strcat_r(prefix, "act_dev", tmp));
wan_unit = get_wan_unit(modem_dev);
if(wan_unit == -1)
continue;
rx_old = strtoull(nvram_safe_get("modem_bytes_rx"), NULL, 10);
tx_old = strtoull(nvram_safe_get("modem_bytes_tx"), NULL, 10);
printf("rx_old=%llu\n"
"tx_old=%llu\n",
rx_old, tx_old);
rx_reset = strtoull(nvram_safe_get("modem_bytes_rx_reset"), NULL, 10);
if(rx_reset < 0)
rx_reset = 0;
tx_reset = strtoull(nvram_safe_get("modem_bytes_tx_reset"), NULL, 10);
if(tx_reset < 0)
tx_reset = 0;
printf("rx_reset=%llu\n"
"tx_reset=%llu\n",
rx_reset, tx_reset);
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/rx_bytes", modem_dev);
f_read_string(path, tmp, sizeof(tmp));
if(strlen(tmp) > 0)
tmp[strlen(tmp)-1] = '\0';
rx_new = strtoull(tmp, NULL, 10);
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/tx_bytes", modem_dev);
f_read_string(path, tmp, sizeof(tmp));
if(strlen(tmp) > 0)
tmp[strlen(tmp)-1] = '\0';
tx_new = strtoull(tmp, NULL, 10);
printf("rx_new=%llu\n"
"tx_new=%llu\n",
rx_new, tx_new);
rx_now = rx_new+rx_old;
if(rx_now >= rx_reset)
rx_now -= rx_reset;
tx_now = tx_new+tx_old;
if(tx_now >= tx_reset)
tx_now -= tx_reset;
printf("rx_now=%llu\n"
"tx_now=%llu\n",
rx_now, tx_now);
snprintf(tmp, sizeof(tmp), "%llu", rx_now);
nvram_set("modem_bytes_rx", tmp);
snprintf(tmp, sizeof(tmp), "%llu", tx_now);
nvram_set("modem_bytes_tx", tmp);
snprintf(tmp, sizeof(tmp), "%llu", rx_new);
nvram_set("modem_bytes_rx_reset", tmp);
snprintf(tmp, sizeof(tmp), "%llu", tx_new);
nvram_set("modem_bytes_tx_reset", tmp);
}
return 0;
}
int modem_data_reset(int sim_order){
int modem_unit, wan_unit;
char tmp[100], prefix[32];
char *modem_dev;
char rx_new[32], tx_new[32];
char path[256];
time_t now;
char timebuf[32];
printf("Reseting %dth net traffic:\n", sim_order);
for(modem_unit = MODEM_UNIT_FIRST; modem_unit < MODEM_UNIT_MAX; ++modem_unit){
usb_modem_prefix(modem_unit, prefix, sizeof(prefix));
modem_dev = nvram_safe_get(strcat_r(prefix, "act_dev", tmp));
wan_unit = get_wan_unit(modem_dev);
if(wan_unit == -1)
continue;
time(&now);
snprintf(timebuf, sizeof(timebuf), "%d", (int)now);
snprintf(path, sizeof(path), "/jffs/sim/%d/modem_bytes_data_start", sim_order);
f_write_string(path, timebuf, 0, 0);
nvram_set("modem_bytes_data_start", timebuf);
snprintf(path, sizeof(path), "/jffs/sim/%d/modem_bytes_rx", sim_order);
f_write_string(path, "0", 0, 0);
nvram_set("modem_bytes_rx", "0");
snprintf(path, sizeof(path), "/jffs/sim/%d/modem_bytes_tx", sim_order);
f_write_string(path, "0", 0, 0);
nvram_set("modem_bytes_tx", "0");
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/rx_bytes", modem_dev);
f_read_string(path, rx_new, sizeof(rx_new));
if(strlen(rx_new) > 0)
rx_new[strlen(rx_new)-1] = '\0';
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/tx_bytes", modem_dev);
f_read_string(path, tx_new, sizeof(tx_new));
if(strlen(rx_new) > 0)
tx_new[strlen(tx_new)-1] = '\0';
printf("rx_new=%s\n"
"tx_new=%s\n",
rx_new, tx_new);
nvram_set("modem_bytes_rx_reset", rx_new);
nvram_set("modem_bytes_tx_reset", tx_new);
}
return 0;
}
int modem_data_save(int sim_order){
char *rx_now = nvram_safe_get("modem_bytes_rx");
char *tx_now = nvram_safe_get("modem_bytes_tx");
char path[256];
printf("Saving %dth net traffic:\n"
"rx_now=%s\n"
"tx_now=%s\n",
sim_order, rx_now, tx_now);
snprintf(path, sizeof(path), "/jffs/sim/%d/modem_bytes_rx", sim_order);
f_write_string(path, rx_now, 0, 0);
snprintf(path, sizeof(path), "/jffs/sim/%d/modem_bytes_tx", sim_order);
f_write_string(path, tx_now, 0, 0);
return 0;
}
int modem_data_usage(){
printf("\nUsage: modem_data [OPTION]...\n\n"
"Options:\n"
"\t\t -o \t Set the SIM's order. 1 ~ 9\n"
"\t\t -u \t Update the net traffic\n"
"\t\t -r \t Reset the net traffic\n"
"\t\t -s \t Save the net traffic\n"
"\t\t -h \t Display this help\n");
return 0;
}
int modem_data_main(int argc, char *argv[]){
int c;
int sim_order = 1;
if(argc == 1){
modem_data_usage();
return 0;
}
while((c = getopt(argc, argv, "o:ursh")) != -1){
switch(c){
case 'o':
sim_order = strtod(optarg, NULL);
if(sim_order < 1 || sim_order > 9)
sim_order = 1;
printf("modem data: sim_order=%d.\n", sim_order);
break;
case 'u':
printf("modem data: Updating the %dth net traffic...\n", sim_order);
modem_data_update(sim_order);
break;
case 'r':
printf("modem data: Reseting the %dth net traffic...\n", sim_order);
modem_data_reset(sim_order);
break;
case 's':
printf("modem data: Saving the %dth net traffic...\n", sim_order);
modem_data_save(sim_order);
break;
case 'h':
modem_data_usage();
break;
default:
printf("Invalid parameters: '%c'", c);
modem_data_usage();
break;
}
}
return 0;
}
#endif
#endif // RTCONFIG_INTERNAL_GOBI
#endif // RTCONFIG_USB_MODEM
void start_usb(int orig)
{
char param[32];
int i;
_dprintf("%s\n", __func__);
#ifdef RTAC68U
if (!hw_usb_cap())
return;
#endif
#if defined(RTCONFIG_SOC_IPQ40XX)
_dprintf("insmod dakota usb module....\n");
modprobe(USB_PHY1);
modprobe(USB_PHY2);
modprobe(USB_DWC3_IPQ);
modprobe(USB_DWC3);
#endif
tune_bdflush();
if (nvram_get_int("usb_enable")) {
if(orig)
add_usb_host_module();
#ifdef RTCONFIG_USB_MODEM
if(orig)
add_usb_modem_modules();
#endif
/* mount usb device filesystem */
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(3,2,0)
mount("debugfs", "/sys/kernel/debug", "debugfs", MS_MGC_VAL, NULL);
#if defined(RTCONFIG_RALINK) && defined(LINUX30)
mount(USBFS, "/proc/bus/usb", USBFS, MS_MGC_VAL, NULL);
#endif
#else
mount(USBFS, "/proc/bus/usb", USBFS, MS_MGC_VAL, NULL);
#endif
#ifdef LINUX26
if ((i = nvram_get_int("led_usb_gpio")) != 255) {
modprobe("ledtrig-usbdev");
modprobe("leds-usb");
sprintf(param, "%d", i);
f_write_string("/sys/class/leds/usb-led/gpio_pin", param, 0, 0);
f_write_string("/sys/class/leds/usb-led/device_name", "1-1", 0, 0);
}
/* big enough for minidlna to minitor all media files? */
f_write_string("/proc/sys/fs/inotify/max_user_watches", "100000", 0, 0);
#endif
#if defined(RTCONFIG_SAMBASRV) || defined(RTCONFIG_FTP)
if (nvram_get_int("usb_storage")) {
/* insert scsi and storage modules before usb drivers */
modprobe(SCSI_MOD);
#ifdef LINUX26
modprobe(SCSI_WAIT_MOD);
#endif
modprobe(SD_MOD);
modprobe(SG_MOD);
modprobe(USBSTORAGE_MOD);
if (nvram_get_int("usb_fs_ext3")) {
#ifdef LINUX26
modprobe("mbcache"); // used by ext2/ext3
#endif
/* insert ext3 first so that lazy mount tries ext4 before ext2 */
modprobe("jbd");
modprobe("ext3");
#if defined(RTCONFIG_BCMARM) || defined(RTCONFIG_EXT4FS)
modprobe("ext4");
#endif
modprobe("ext2");
}
if (nvram_get_int("usb_fs_fat")) {
#ifdef RTCONFIG_OPENPLUS_TFAT
if(nvram_match("usb_fatfs_mod", "tuxera"))
modprobe("tfat");
else{
modprobe("fat");
modprobe("vfat");
}
#elif defined(RTCONFIG_TFAT)
modprobe("tfat");
#else
modprobe("fat");
modprobe("vfat");
#endif
}
#ifdef RTCONFIG_NTFS
if(nvram_get_int("usb_fs_ntfs")){
#ifdef RTCONFIG_TUXERA_NTFS
#if defined(RTCONFIG_OPENPLUSTUXERA_NTFS)
if(nvram_match("usb_ntfs_mod", "tuxera"))
#endif
modprobe("tntfs");
#elif defined(RTCONFIG_PARAGON_NTFS)
#if defined(RTCONFIG_OPENPLUSPARAGON_NTFS)
if(nvram_match("usb_ntfs_mod", "paragon"))
#endif
#ifdef RTCONFIG_UFSD_DEBUG
modprobe("ufsd_debug");
#else
modprobe("ufsd");
#endif
#endif
}
#endif
#ifdef RTCONFIG_HFS
if(nvram_get_int("usb_fs_hfs")){
#ifdef RTCONFIG_TUXERA_HFS
#if defined(RTCONFIG_OPENPLUSTUXERA_HFS)
if(nvram_invmatch("usb_hfs_mod", "tuxera")){
modprobe("hfs");
modprobe("hfsplus");
}
else
#endif
modprobe("thfsplus");
#elif defined(RTCONFIG_PARAGON_HFS)
#if defined(RTCONFIG_OPENPLUSPARAGON_HFS)
if(nvram_invmatch("usb_hfs_mod", "paragon")){
modprobe("hfs");
modprobe("hfsplus");
}
else
#endif
#ifdef RTCONFIG_UFSD_DEBUG
modprobe("ufsd_debug");
#else
modprobe("ufsd");
#endif
#else
modprobe("hfs");
modprobe("hfsplus");
#endif
}
#endif
}
#endif
#ifdef RTCONFIG_USB_PRINTER
if (nvram_get_int("usb_printer")) {
symlink("/dev/usb", "/dev/printers");
modprobe(USBPRINTER_MOD);
}
#endif
#if defined(RTCONFIG_BT_CONN)
modprobe("btusb");
modprobe("ath3k");
#if defined(MAPAC1300) || defined(MAPAC2200) || defined(VZWAC1300)
if (nvram_match("x_Setting", "0"))
system("/usr/bin/btchk.sh &"); /* workaround script */
#endif
#endif /* RTCONFIG_BT_CONN */
#ifdef HND_ROUTER
modprobe("btusbdrv");
#endif
}
}
#ifdef RTCONFIG_SOC_IPQ40XX
void remove_dakota_usb_modules(void)
{
modprobe_r(USB_DWC3);
modprobe_r(USB_DWC3_IPQ);
modprobe_r(USB_PHY2);
modprobe_r(USB_PHY1);
}
#endif
#ifdef RTCONFIG_USB_PRINTER
void remove_usb_prn_module(void)
{
modprobe_r(USBPRINTER_MOD);
}
#endif
void remove_usb_storage_module(void)
{
#if defined(RTCONFIG_SAMBASRV) || defined(RTCONFIG_FTP)
modprobe_r("ext2");
modprobe_r("ext3");
modprobe_r("jbd");
#if defined(RTCONFIG_BCMARM) || defined(RTCONFIG_EXT4FS)
modprobe_r("ext4");
modprobe_r("jbd2");
#endif
#ifdef LINUX26
modprobe_r("mbcache");
#endif
#ifdef RTCONFIG_OPENPLUS_TFAT
if(nvram_match("usb_fatfs_mod", "tuxera"))
modprobe_r("tfat");
else{
modprobe_r("vfat");
modprobe_r("fat");
}
#elif defined(RTCONFIG_TFAT)
modprobe_r("tfat");
#else
modprobe_r("vfat");
modprobe_r("fat");
#endif
#ifdef RTCONFIG_NTFS
#ifdef RTCONFIG_TUXERA_NTFS
#if defined(RTCONFIG_OPENPLUSTUXERA_NTFS)
if(nvram_match("usb_ntfs_mod", "tuxera"))
#endif
modprobe_r("tntfs");
#elif defined(RTCONFIG_PARAGON_NTFS)
#if defined(RTCONFIG_OPENPLUSPARAGON_NTFS)
if(nvram_match("usb_ntfs_mod", "paragon"))
#endif
{
#ifdef RTCONFIG_UFSD_DEBUG
modprobe_r("ufsd_debug");
modprobe_r("jnl_debug");
#else
modprobe_r("ufsd");
modprobe_r("jnl");
#endif
}
#endif
#endif
#ifdef RTCONFIG_HFS
#ifdef RTCONFIG_TUXERA_HFS
#if defined(RTCONFIG_OPENPLUSTUXERA_HFS)
if(nvram_match("usb_hfs_mod", "tuxera"))
#endif
modprobe_r("thfsplus");
#elif defined(RTCONFIG_PARAGON_HFS)
#if defined(RTCONFIG_OPENPLUSPARAGON_HFS)
if(nvram_match("usb_hfs_mod", "paragon"))
#endif
{
#ifdef RTCONFIG_UFSD_DEBUG
modprobe_r("ufsd_debug");
modprobe_r("jnl_debug");
#else
modprobe_r("ufsd");
modprobe_r("jnl");
#endif
}
#endif
#endif
modprobe_r("fuse");
sleep(1);
#ifdef RTCONFIG_SAMBASRV
modprobe_r("nls_cp437");
modprobe_r("nls_cp850");
modprobe_r("nls_cp852");
modprobe_r("nls_cp866");
#ifdef LINUX26
modprobe_r("nls_cp932");
modprobe_r("nls_cp936");
modprobe_r("nls_cp949");
modprobe_r("nls_cp950");
#endif
#endif
modprobe_r(USBSTORAGE_MOD);
modprobe_r(SG_MOD);
modprobe_r(SD_MOD);
#ifdef LINUX26
modprobe_r(SCSI_WAIT_MOD);
#endif
modprobe_r(SCSI_MOD);
#endif
}
void remove_usb_led_module(void)
{
#ifdef LINUX26
modprobe_r("leds-usb");
modprobe_r("ledtrig-usbdev");
#endif
}
void remove_usb_host_module(void)
{
#ifndef HND_ROUTER
modprobe_r(USBOHCI_MOD);
modprobe_r(USBUHCI_MOD);
modprobe_r(USB20_MOD);
#if defined(RTCONFIG_BT_CONN)
modprobe_r("ath3k");
modprobe_r("btusb");
#endif
#if defined(RTCONFIG_USB_XHCI)
#if defined(RTCONFIG_SOC_IPQ8064)
modprobe_r("dwc3-ipq");
modprobe_r("udc-core");
#endif
modprobe_r(USB30_MOD);
#endif
#else // HND_ROUTER
tweak_usb_affinity(0);
#endif
#if defined(RTCONFIG_BLINK_LED)
/* If both bled and USB Bus traffic statistics are enabled,
* don't remove USB core and USB common kernel module.
*/
if (!((nvram_get_int("led_usb_gpio") | nvram_get_int("led_usb3_gpio")) & GPIO_BLINK_LED))
#endif
{
modprobe_r(USBCORE_MOD);
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(3,2,0)
modprobe_r(USBCOMMON_MOD);
#endif
}
}
void remove_usb_module(void)
{
#ifdef RTCONFIG_USB_MODEM
remove_usb_modem_modules();
#endif
#ifdef RTCONFIG_USB_PRINTER
remove_usb_prn_module();
#endif
#if defined(RTCONFIG_SAMBASRV) || defined(RTCONFIG_FTP)
remove_usb_storage_module();
#endif
remove_usb_led_module();
remove_usb_host_module();
#ifdef RTCONFIG_SOC_IPQ40XX
remove_dakota_usb_modules();
#endif
}
// mode 0: stop all USB programs, mode 1: stop the programs from USB hotplug.
void stop_usb_program(int mode)
{
#ifdef RTCONFIG_USB_MODEM
#ifdef RTCONFIG_USB_BECEEM
killall("wimaxd", SIGTERM);
killall("wimaxd", SIGUSR1);
if(!g_reboot)
sleep(1);
#endif
#endif
#if defined(RTCONFIG_APP_PREINSTALLED) || defined(RTCONFIG_APP_NETINSTALLED)
#if defined(RTCONFIG_APP_PREINSTALLED) && defined(RTCONFIG_CLOUDSYNC)
if(pids("inotify") || pids("asuswebstorage") || pids("webdav_client") || pids("dropbox_client") || pids("ftpclient") || pids("sambaclient") || pids("usbclient") || pids("google_client")){
_dprintf("%s: stop_cloudsync.\n", __func__);
stop_cloudsync(-1);
}
#endif
stop_app();
#endif
stop_nas_services(0);
if(mode)
return;