]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/boot/nusbrc
nusbrc: detect "keyboardio model 01", appears as multifuction device with IAD csp...
[plan9front.git] / sys / src / 9 / boot / nusbrc
1 #!/bin/rc
2 if(! bind -a '#u' /dev)
3         exit
4
5 mkdir -p -m 700 '#σc/usb'
6 mkdir -p -m 700 '#σc/usbnet'
7
8 if(! nusb/usbd)
9         exit
10
11 @{
12         rfork ne
13         fn attach {
14                 id=$1
15                 if(~ $#* 5 && ! test -e /env/nousbhname)
16                         id=$1:$5
17                 switch($2$3){
18                 case 0b957720 0b95772a 0db0a877 13b10018 15577720 20013c05 07d13c05 05ac1402
19                         nusb/ether -t a88772 $etherargs $id
20                 case 0b951780 14eaab11 17370039 0411006e 050d5055
21                         nusb/ether -t a88178 $etherargs $id
22                 case 2001abc1
23                         nusb/ether -t aue $etherargs $id
24                 case 0bda8150
25                         nusb/ether -t url $etherargs $id
26                 case 18d14ee3 0bb40003 10046344
27                         nusb/ether -t rndis $etherargs $id
28                 case 12092301 # keyboardio model 01 (IAD)
29                         nusb/kb $id
30                 # prevent attachment to nusb/kb for:
31                 case 054c0268 # sony dualshock 3 (ps3) controller
32                 case *
33                         switch($4){
34                         case *03
35                                 nusb/kb $id
36                         case *02
37                                 # CDC ethernet
38                                 nusb/ether $etherargs $id
39                         case *08
40                                 if(nusb/disk $id) @{
41                                         rfork ne
42                                         cd '#σ/usb'
43                                         devs=sdU^($1 $5)
44                                         for(dev in $devs $devs.*) if(test -d $dev) {
45                                                 diskparts $dev
46                                                 for(part in $dev/dos* $dev/9fat* $dev/data) if(test -r $part && ~ `{fstype $part} dos) {
47                                                         mkdir -m 0700 '#σc/'^$dev || exit
48                                                         {dossrv -s -f $part &} <[0=1] |
49                                                                 echo 0 >'#σc/'^$dev/dos
50                                                         exit
51                                                 }
52                                         }
53                                 }
54                         case *
55                                 # Raspberry Pi ethernet will always appear as /net/etherU0
56                                 if(~ $2 0424){
57                                         if(~ $3 7800)
58                                                 nusb/ether -t lan78xx $etherargs $1:0
59                                         if not
60                                                 nusb/ether -t smsc $etherargs $1:0
61                                 }
62                         }
63                 }
64         }
65         fn detach {
66                 devs='#σc/sdU'^($1 $5)
67                 rm -rf '#σc/usb/'^$1.* '#σc/usbnet/'^$1.* $devs $devs.* 
68         }
69         rc < '#σ/usb/usbevent' &
70 }
71
72 # usbd removes this file once all devices have been enumerated
73 while(test -e /env/usbbusy)
74         sleep 1
75
76 bind -a '#σ/usb' /dev
77 bind -a '#σ/usbnet' /net