]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | /*\r |
2 | * This file is part of the IPCop Firewall.\r | |
3 | *\r | |
4 | * IPCop is free software; you can redistribute it and/or modify\r | |
5 | * it under the terms of the GNU General Public License as published by\r | |
6 | * the Free Software Foundation; either version 2 of the License, or\r | |
7 | * (at your option) any later version.\r | |
8 | *\r | |
9 | * IPCop is distributed in the hope that it will be useful,\r | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
12 | * GNU General Public License for more details.\r | |
13 | *\r | |
14 | * You should have received a copy of the GNU General Public License\r | |
15 | * along with IPCop; if not, write to the Free Software\r | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r | |
17 | *\r | |
18 | * Copyright 2002: Mark Wormgoor <mark@wormgoor.com>\r | |
19 | * \r | |
20 | * $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $\r | |
21 | * \r | |
22 | */\r | |
23 | \r | |
24 | #include "install.h"\r | |
25 | \r | |
26 | int usbuhci = 0;\r | |
27 | int usbohci = 0;\r | |
28 | int ehcihcd = 0;\r | |
29 | \r | |
30 | int initialize_usb() {\r | |
31 | modprobe("sd_mod");\r | |
32 | modprobe("sr_mod");\r | |
33 | modprobe("usb-storage");\r | |
34 | \r | |
35 | if (ehcihcd) {\r | |
36 | rmmod("ehci-hcd");\r | |
37 | ehcihcd = 0;\r | |
38 | }\r | |
39 | if (usbohci) {\r | |
40 | rmmod("usb-ohci");\r | |
41 | usbohci = 0;\r | |
42 | }\r | |
43 | if (usbuhci) {\r | |
44 | rmmod("usb-uhci");\r | |
45 | usbuhci = 0;\r | |
46 | }\r | |
47 | \r | |
48 | if (modprobe("ehci-hcd") == 0) ehcihcd = 1;\r | |
49 | if (modprobe("usb-ohci") == 0) usbohci = 1;\r | |
50 | if (modprobe("usb-uhci") == 0) usbuhci = 1;\r | |
51 | \r | |
52 | modprobe("hid");\r | |
53 | modprobe("keybdev");\r | |
54 | return 0;\r | |
55 | }\r | |
56 | \r | |
57 | int write_usb_modules_conf() {\r | |
58 | int index = 0;\r | |
59 | FILE *handle;\r | |
60 | \r | |
61 | if (!(handle = fopen("/harddisk/etc/modules.conf", "a")))\r | |
62 | return 0;\r | |
63 | \r | |
64 | #if 0 /* we don't do this yet, because one of the drivers has a problem \r | |
65 | * with it */\r | |
66 | if (ehcihcd) {\r | |
67 | fprintf(handle,"alias usb-controller");\r | |
68 | if (index)\r | |
69 | fprintf(handle,"%d",index);\r | |
70 | fprintf(handle," ehci-hcd\n");\r | |
71 | index++;\r | |
72 | }\r | |
73 | #endif\r | |
74 | \r | |
75 | if (usbohci) {\r | |
76 | fprintf(handle,"alias usb-controller");\r | |
77 | if (index)\r | |
78 | fprintf(handle,"%d",index);\r | |
79 | fprintf(handle," usb-ohci\n");\r | |
80 | index++;\r | |
81 | }\r | |
82 | \r | |
83 | if (usbuhci) {\r | |
84 | fprintf(handle,"alias usb-controller");\r | |
85 | if (index)\r | |
86 | fprintf(handle,"%d",index);\r | |
87 | fprintf(handle," usb-uhci\n");\r | |
88 | index++;\r | |
89 | }\r | |
90 | fclose(handle);\r | |
91 | \r | |
92 | return 0;\r | |
93 | }\r | |
94 | \r | |
95 | /* checkusb().\r | |
96 | Scans the named partitions and returns true if USB-removable.\r | |
97 | a bug? in "cat /proc/partitions" with superfloppy scheme device\r | |
98 | make them appearing always with four 'false' partitions:\r | |
99 | sda and sda1 sda2 sda3 sda4.\r | |
100 | No easy way to decide if /dev/sda1 exists or not.\r | |
101 | */\r | |
102 | int checkusb(char *partition)\r | |
103 | {\r | |
104 | FILE *f = NULL;\r | |
105 | char filename[STRING_SIZE];\r | |
106 | char buffer[STRING_SIZE];\r | |
107 | char *pchar = &buffer[0];\r | |
108 | if (!(f = fopen("/proc/partitions", "r")))\r | |
109 | return 0;\r | |
110 | \r | |
111 | short int major = 0, minor = 0; \r | |
112 | while (fgets(buffer, STRING_SIZE, f)) {\r | |
113 | /* look for partition*/ \r | |
114 | if (strstr (buffer, partition)) {\r | |
115 | major = atoi (buffer);\r | |
116 | if (major != 8) break ; /* not scsi */\r | |
117 | //get minor\r | |
118 | while (*pchar != '8') pchar++;\r | |
119 | minor = atoi (++pchar);\r | |
120 | break;\r | |
121 | }\r | |
122 | }\r | |
123 | fclose(f);\r | |
124 | if (major != 8) return 0; /* nothing found */\r | |
125 | \r | |
126 | //now check for usb-storage-MINOR\r | |
127 | minor >>= 4; // get index from minor\r | |
128 | sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor);\r | |
129 | \r | |
130 | if (!(f = fopen(filename, "r")))\r | |
131 | return 0;\r | |
132 | int count = 0;\r | |
133 | while (fgets(buffer, STRING_SIZE, f)) {\r | |
134 | if (strstr(buffer,"usb-storage")) count++;\r | |
135 | if (strstr(buffer,"SCSI")) count++;\r | |
136 | if (strstr(buffer,"Attached: Yes")) count++;\r | |
137 | }\r | |
138 | fclose(f);\r | |
139 | \r | |
140 | return (count==3 ? 1 : 0);\r | |
141 | }\r |