-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheciadsl-doctor.in
executable file
·624 lines (538 loc) · 16.7 KB
/
eciadsl-doctor.in
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
#!/bin/bash
# Author: Benoit PAPILLAULT <[email protected]>
# Creation: 01/02/2002
# Licence: GPL
# 02/02/2002: added the permission check for check-hdlc & check-hdlc-bug
# 07/02/2002: added check on the pppd output. added the CVS Id.
# CVS $Id: eciadsl-doctor.in,v 1.3 2007/04/03 20:17:19 flashcode Exp $
# Tag $Name: $
# 16/02/2002 Benoit PAPILLAULT
# Check for an existing pppd and display its version
# 26/02/2002 Benoit PAPILLAULT
# Added the 'nopersist' flag for diagnostic purpose.
# 22/04/2004 FlashCode <[email protected]>
# Renamed script: eci-doctor.sh -> eciadsl-doctor
# <CONFIG>
ETC_DIR="@sysconfdir@"
CONF_DIR="@sysconfdir@/eciadsl"
BIN_DIR="@bindir@"
PPPD_DIR="@sysconfdir@/ppp"
VERSION="@PACKAGE_VERSION@"
# </CONFIG>
# define the usb devices path for Suse 9.1
DEVICES=/proc/bus/usb/devices
DEVICES_SUSE=/proc/bus/usb/devices_please-use-sysfs-instead
if [ "$1" == "--version" -o "$1" == "-v" ]; then
echo "$VERSION"
exit 0
fi
# cd to the directory where the 'doctor' is.
cd `dirname $0`
PATH=/bin:/sbin:/usr/bin:/usr/sbin
if [ `id -u` -ne 0 ]; then
echo "You need to be root (type su)" ;
exit -1;
fi
# display the kernel version
echo "You are using linux kernel version `uname -r`"
# note the size in lines of /var/log/messages
line=`wc -l /var/log/messages | awk '{print $1}'`
function fatal () {
tail -n +$line /var/log/messages > /tmp/msg.log
# check for "usb-uhci.c: ENXIO 80000380, flags 0, urb c7f401c0, burb c6469140"
grep 'usb-uhci.c: ENXIO' /tmp/msg.log
# check for "usb-uhci.c: interrupt, status 29, frame# 956"
grep 'usb-uhci.c: interrupt' /tmp/msg.log
# check for "usb_control/bulk_msg: timeout"
grep 'usb_control/bulk_msg' /tmp/msg.log
# check for "usb-uhci.c: Host controller halted, trying to restart"
grep 'usb-uhci.c: Host controller halted' /tmp/msg.log
# check for "usb-uhci.c: process_transfer: fixed toggle"
grep 'usb-uhci.c: process_transfer' /tmp/msg.log
# check for "usb-uhci.c: iso_find_start: gap in seamless isochronous scheduling"
grep 'usb-uhci.c: iso_find_start' /tmp/msg.log
rm /tmp/msg.log
exit -1;
}
# use only DEVICES throughout the rest of this script
if [ ! -f "${DEVICES}" ] && [ -f "${DEVICES_SUSE}" ]; then
echo "Warning: using ${DEVICES_SUSE}"
DEVICES="${DEVICES_SUSE}"
fi
# use the proper USB modules name according to the running kernel version
case `uname -r` in
2.4.*)
UHCI=usb-uhci
UHCI_BIS=uhci
OHCI=usb-ohci
KERNEL_TYPE=2.4
;;
2.5.* | 2.6.*)
UHCI=uhci-hcd
UHCI_BIS=
OHCI=ohci-hcd
KERNEL_TYPE=2.6
;;
*)
KERNEL_TYPE=unknown
;;
esac
if [ "${KERNEL_TYPE}" = "unknown" ]; then
echo "unable to detect kernel type"
exit
fi
if [ ! -d /proc/bus/usb ]; then
echo "Support for USB is missing... trying to load" ;
modprobe usbcore
sleep 1
if [ ! -d /proc/bus/usb ]; then
echo "Support for USB: failed to load" ;
fatal;
else
echo "Support for USB is now OK" ;
fi
else
echo "Support for USB is OK" ;
fi
# mount usbdevfs is this is not the case
# warning: on 2.6 kernels, there is no /proc/bus/usb/devices file even
# if usbfs is mounted!
# check if there is a mounted filesystem which is either of type
# "usbfs" or "usbdevfs".
if ! awk '{print $3}' /proc/mounts | egrep -q "usbfs|usbdevfs"; then
echo "Preliminary USB device filesystem is missing... trying to mount" ;
mount -t usbdevfs usbdevfs /proc/bus/usb
if ! awk '{print $3}' /proc/mounts | egrep -q "usbfs|usbdevfs"; then
echo "Preliminary USB device filesystem: failed to load" ;
fatal ;
else
echo "Preliminary USB device filesystem is now OK" ;
fi
else
echo "Preliminary USB device filesystem is OK" ;
fi
# check for the dabusb module
lsmod | grep "^dabusb" > /dev/null
if [ $? -eq 0 ]; then
echo "dabusb module is loaded: trying to unload!" ;
modprobe -r dabusb
sleep 1
lsmod | grep "^dabusb" > /dev/null
if [ $? -eq 0 ]; then
echo "dabusb module cannot be unloaded, verify if it is busy";
fatal;
else
echo "dabusb module unloaded: OK";
fi
else
echo "dabusb module is not loaded: OK";
fi
# usage: check_usb_support OHCI
# return 0 if OHCI is properly handled by the running kernel
# OHCI can be replaced by UHCI or EHCI
check_usb_support() {
# echo "check_usb_support $@"
USB_C="$1"
case "${KERNEL_TYPE}" in
2.4)
grep "^S: Product=" "${DEVICES}" | grep -q "${USB_C}"
;;
2.6)
case "${USB_C}" in
UHCI) DRIVER="uhci_hcd";;
OHCI) DRIVER="ohci_hcd";;
EHCI) DRIVER="ehci_hcd";;
esac
[ -d "/sys/bus/pci/drivers/${DRIVER}" ]
;;
esac
}
need_usb_support_proc_pci() {
# echo "need_usb_support_proc_pci $@"
USB_C="$1"
case "${USB_C}" in
UHCI) KW="I/O";;
OHCI) KW="memory";;
EHCI) echo "EHCI cannot be detected using /proc/pci"; return 1;
esac
grep -A 3 "USB Controller" /proc/pci | grep -q "${KW}"
}
need_usb_support_lspci() {
# echo "need_usb_support_lspci $@"
USB_C="$1"
lspci -v | grep "USB Controller" | grep -q "${USB_C}"
}
need_usb_support_sys() {
# echo "need_usb_support_sys $@"
USB_C="$1"
case "${USB_C}" in
UHCI) CLASS="0x0c0300";;
OHCI) CLASS="0x0c0310";;
EHCI) CLASS="0x0c0320";;
esac
grep -q "${CLASS}" /sys/bus/pci/devices/*/class
}
# usage: need_usb_support OHCI
# return 0 if OHCI is needed on the running machine
# OHCI can be replaced by UHCI or EHCI
need_usb_support() {
USB_C="$1"
if [ -d /sys/bus/pci ]; then
need_usb_support_sys "$@"
elif [ -f /proc/pci ]; then
need_usb_support_proc_pci "$@"
elif which lspci > /dev/null 2>&1; then
need_usb_support_lspci "$@"
else
echo "cannot check if ${USB_C} is needed"
fi
}
# check for OHCI. We try to loaded OHCI module only if there are OHCI
# controllers that are not handled by the running kernel.
# - if modem is detected in /proc/bus/usb/devices, we are done
# - check if OHCI support is active (using /proc/bus/usb/devices on 2.4
# and /sys/bus/pci/drivers/*_hcd on 2.6)
# - if yes, we are done
# - if no, check if we need OHCI support (using /sys/bus/pci/devices/*/class
# or lspci or /proc/pci [we might detect EHCI as OHCI... but since there is
# always an OCHI controller along EHCI, it is OK)
# - if no, we are done
# - if yes, try to load OHCI module
# - check if OHCI support is active
# - if yes, we are done
# - if no, we failed.
# - redo the same with UHCI
# - do not mess with EHCI since it's only for USB 2.0 devices and all our
# modems are USB 1.1
uhci=0
if check_usb_support UHCI; then
echo "UHCI support is OK"
uhci=1
else
if need_usb_support UHCI; then
echo "UHCI support is missing... trying to load"
modprobe "${UHCI}"
if [ -n "${UHCI_BIS}" ]; then
modprobe "${UHCI_BIS}"
fi
sleep 2
if check_usb_support UHCI; then
echo "UHCI support is now OK"
uhci=1
else
echo "UHCI support failed to load"
fi
else
echo "UHCI support is not needed"
fi
fi
ohci=0
if check_usb_support OHCI; then
echo "OHCI support is OK"
ohci=1
else
if need_usb_support OHCI; then
echo "OHCI support is missing... trying to load"
modprobe "${OHCI}"
sleep 2
if check_usb_support OHCI; then
echo "OHCI support is now OK"
ohci=1
else
echo "OHCI support failed to load"
fi
else
echo "OHCI support is not needed"
fi
fi
if [ "$uhci" -eq 0 -a "$ohci" -eq 0 ]; then
echo "I found no USB controller" ;
fatal;
fi
# check for the presense of /dev/ppp
if [ ! -c /dev/ppp ]; then
echo "/dev/ppp is missing... trying to create" ;
mknod /dev/ppp c 108 0
if [ ! -c /dev/ppp ]; then
echo "/dev/ppp: failed to create" ;
fatal;
fi
fi
# check some property of /dev/ppp
set `ls -la /dev/ppp`
if [ $3 != "root" ]; then
echo "/dev/ppp should be owned by root... trying to change" ;
chown root /dev/ppp
set `ls -la /dev/ppp`
if [ $3 != "root" ]; then
echo "/dev/ppp: failed to change owner to root" ;
fatal;
fi
fi
if [ $5 != "108," ]; then
echo "/dev/ppp has a bad major number... trying to change" ;
rm /dev/ppp
mknod /dev/ppp c 108 0
set `ls -la /dev/ppp`
if [ $5 != "108," ]; then
echo "/dev/ppp: failed to change major number" ;
fatal;
fi
fi
if [ $6 != "0" ]; then
echo "/dev/ppp has a bad minor number... trying to change" ;
rm /dev/ppp
mknod /dev/ppp c 108 0
set `ls -la /dev/ppp`
if [ $6 != "0" ]; then
echo "/dev/ppp: failed to change minor number" ;
fatal;
fi
fi
echo "/dev/ppp is OK" ;
# check for the HDLC support
"$BIN_DIR/eciadsl-check-hdlc"
if [ $? -ne 0 ]; then
echo "HDLC support is missing... trying to load" ;
modprobe n_hdlc ;
./eciadsl-check-hdlc ;
if [ $? -ne 0 ]; then
echo "HDLC support: failed to load" ;
cat <<EOF
You should check your kernel config with: cd /usr/src/linux ; make
menuconfig and look under Character devices for Non-standard serial
port support and HDLC line discipline support
EOF
fatal;
fi
# here, HDLC support is OK, but maybe some alias are missing
modprobe -r n_hdlc ;
./eciadsl-check-hdlc ;
if [ $? -ne 0 ]; then
echo "HDLC support: alias is missing... trying to add" ;
echo "alias tty-ldisc-13 n_hdlc" >> "$ETC_DIR/modules.conf" ;
depmod -a ;
# checking again
./eciadsl-check-hdlc ;
if [ $? -ne 0 ]; then
echo "HDLC support: adding alias does not work" ;
fatal;
else
echo "HDLC support is OK" ;
fi
else
echo "HDLC support is OK" ;
fi
else
echo "HDLC support is OK" ;
fi
# check for the HDLC bug
"$BIN_DIR/eciadsl-check-hdlc-bug" > /dev/null 2>&1
if [ $? -ne 0 ]; then
cat <<EOF
HDLC support is buggy, you should apply the HDLC patch to your kernel
source. See the howto in the doc directory or on
http://eciadsl.flashtux.org/ in the Documentation section for
further instructions.
EOF
else
echo "HDLC support is OK (no bug)" ;
fi
if [ -s "$CONF_DIR/eciadsl.conf" ]; then
vid1=`grep -E "^[ \t]*VID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -d " \t"`
pid1=`grep -E "^[ \t]*PID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -d " \t"`
vid2=`grep -E "^[ \t]*VID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -d " \t"`
pid2=`grep -E "^[ \t]*PID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -d " \t"`
firmware_options=`grep -E "^[ \t]*FIRMWARE_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -s "\t" " "`
synch_options=`grep -E "^[ \t]*SYNCH_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -n 1 | cut -f 2 -d '=' | tr -s "\t" " "`
else
echo -e "\ncouldn't find $CONF_DIR/eciadsl.conf, default config assumed"
fi
test -z "$vid1" && vid1="0547"
test -z "$pid1" && pid1="2131"
test -z "$vid2" && vid2="0915"
test -z "$pid2" && pid2="8000"
# check for the EZUSB chip
ezusb=0
grep "^P: Vendor=$vid1 ProdID=$pid1" "${DEVICES}" > /dev/null
if [ $? -eq 0 ]; then
ezusb=1 ;
echo "Loading EZ-USB firmware... ";
$BIN_DIR/eciadsl-firmware $firmware_options
if [ $? -ne 0 ] ; then
echo "Failed to load EZ-USB firmware" ;
fatal ;
fi ;
echo "Loading the GlobeSpan firmware..." ;
$BIN_DIR/eciadsl-synch $synch_options
if [ $? -ne 0 ] ; then
echo "Failed to load GlobeSpan firmware" ;
fatal ;
fi ;
fi
# check for the $PPPD_DIR/peers/adsl file (if the user is using another name,
# he knows what he's doing and does not need this script).
if [ ! -f $PPPD_DIR/peers/adsl ]; then
echo "No $PPPD_DIR/peers/adsl: did you install the ECI driver?" ;
fatal;
fi
# Note: user option (either in $PPPD_DIR/peers/adsl or $PPPD_DIR/chap-secrets)
# can be :
# user TheUser
# user "TheUser"
# user 'TheUser'
# check for an existing user param. The actual user param may be
# within "" or not.
user=`grep "^user" $PPPD_DIR/peers/adsl | awk '{print $2}'`
if [ "$user" = "" ]; then
echo "Option 'user' if missing from $PPPD_DIR/peers/adsl: Fatal" ;
fatal ;
fi
# remove "" and '' from $user if needed.
n=`echo $user | cut -d'"' -f2` ;
if [ "$n" != "" ]; then
user=$n;
fi
n=`echo $user | cut -d'"' -f2`;
if [ "$n" != "" ]; then
user=$n;
fi
# check that the user param is the same is $PPPD_DIR/peers/adsl and
# $PPPD_DIR/chap-secrets
grep "^$user[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
if [ $? -ne 0 ]; then
grep "^'$user'[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
if [ $? -ne 0 ]; then
grep "^\"$user\"[ \t]*" $PPPD_DIR/chap-secrets > /dev/null
if [ $? -ne 0 ]; then
echo "$PPPD_DIR/chap-secrets: no password for $user" ;
echo "Give me the password for $user:"
read pwd
echo "$user * $pwd *" >> $PPPD_DIR/chap-secrets
fi
fi
else
echo "$PPPD_DIR/chap-secrets is OK" ;
fi
# check for the Globespan chip
grep "^P: Vendor=$vid2 ProdID=$pid2" "${DEVICES}" > /dev/null
if [ $? -ne 0 ]; then
echo "I cannot find your ADSL modem: Fatal"
fatal;
fi
# check for an existing pppd
x=`which pppd`
if [ "$x" = "" ]; then
echo "No pppd is intalled: Fatal" ;
exit -1;
fi
# check the pppd version
ppp_version=`pppd --version 2>&1 | cut -d" " -f 3` ;
msg="";
if [ "$ppp_version" != "2.4.0" -a "$ppp_version" != "2.4.1" ]; then
msg=" (untested)" ;
fi
echo "You are using pppd version $ppp_version$msg" ;
# check for an existing $PPPD_DIR/options file
if [ -f $PPPD_DIR/options ]; then
echo "You have an $PPPD_DIR/options file. Options in this file may conflict with" ;
echo "options from $PPPD_DIR/peers/adsl. We suggest to remove this file or make a";
echo "backup copy." ;
grep "^nodetach" $PPPD_DIR/options > /dev/null
if [ $? -eq 0 ]; then
echo "Removing 'nodetach' option from $PPPD_DIR/options..." ;
grep -v "^nodetach" $PPPD_DIR/options > /tmp/options
mv /tmp/options $PPPD_DIR/options
fi
fi
# check for an existing PPP connection (select the first one if several)
PPP=`ifconfig | grep "^ppp" | head -n 1 | awk '{print $1}'`
if [ "$PPP" = "" ]; then
echo "No existing PPP connection... trying to make one (please wait)" ;
nice --20 pppd call adsl updetach | tee /tmp/ppp.log
# check if we succeed in making a new PPP connection
PPP=`ifconfig | grep "^ppp" | head -n 1 | awk '{print $1}'`
if [ "$PPP" = "" ]; then
# check for usermode driver crash
grep "Modem hangup" /tmp/ppp.log > /dev/null
if [ $? -eq 0 ]; then
echo "PPP: very bad ... usermode driver just crashed" ;
rm /tmp/ppp.log
fatal;
fi
# check for no response from PPP
grep 'LCP: timeout sending Config-Requests' /tmp/ppp.log > /dev/null
if [ $? -eq 0 ]; then
echo "PPP connection failed: check your vci & vpi parameters in $PPPD_DIR/peers/adsl and check for USB errors in /var/log/messages" ;
rm /tmp/ppp.log
fatal;
fi
# check for invalid password
grep 'CHAP authentication failed' /tmp/ppp.log > /dev/null
if [ $? -eq 0 ]; then
echo "CHAP authentication failed: check your user in $PPPD_DIR/peers/adsl and the matching password in $PPPD_DIR/chap-secrets" ;
rm /tmp/ppp.log
fatal;
fi
# check for "sent [LCP ConfRej id=0xa5 <auth chap MD5>]"
grep 'sent \[LCP ConfRej' /tmp/ppp.log | grep '<auth chap MD5>' > /dev/null
if [ $? -eq 0 ]; then
echo "Password for user $user is missing in $PPPD_DIR/chap-secrets";
rm /tmp/ppp.log
fatal;
fi
echo "Cannot make a PPP connection: Fatal" ;
rm /tmp/ppp.log
fatal;
else
rm /tmp/ppp.log
echo "PPP connection is OK" ;
fi
else
echo "PPP connection is OK" ;
fi
# check for the default route over pppN
route -n | grep "^0.0.0.0" | grep $PPP > /dev/null
if [ $? -ne 0 ]; then
echo "No default route over $PPP... trying to add" ;
route add default dev $PPP
route -n | grep "^0.0.0.0" | grep $PPP > /dev/null
if [ $? -ne 0 ]; then
echo "No default over $PPP: failed" ;
fatal;
else
echo "Default route over $PPP is OK" ;
fi
else
echo "Default route over $PPP is OK" ;
fi
# check for the default route not over ethN
route -n | grep "^0.0.0.0" | grep -v $PPP > /dev/null
if [ $? -eq 0 ]; then
echo "You have default route(s) not over $PPP... trying to delete" ;
other=`route -n | grep "^0.0.0.0" | grep -v $PPP | awk '{print $8}'`;
for itf in $other;
do
echo "Deleting default route over $itf" ;
route del default dev $itf ;
done
route -n | grep "^0.0.0.0" | grep -v $PPP > /dev/null
if [ $? -eq 0 ]; then
echo "Deleting default route not over $PPP: failed" ;
fatal;
fi
fi
# check if ICMP packets are sent & received (is it usefull?)
#ping -c 10 yahoo.fr > /dev/null
#if [ $? -eq 0 ]; then
# echo "ICMP traffic is OK" ;
#else
# echo "ICMP traffic does not work" ;
#fi
# check for /var/log or /tmp partitions full (TODO)
# check for "rcvd [LCP TermReq id=0xa8]" (TODO)
# check for $ETC_DIR/resolv.conf validity (TODO)
# check for an already running pppd & eciadsl-pppoeci, while no ppp0 (TODO)
# check for $PPPD_DIR/pap-secrets too (TODO)
# check for either pap-secrets or chap-secrets, how? (TODO)
echo "Everything is OK"