1 /* 2 * usb/ether - usb ethernet adapter. 3 * BUG: This should use /dev/etherfile to 4 * use the kernel ether device code. 5 */ 6 #include <u.h> 7 #include <libc.h> 8 #include <fcall.h> 9 #include <thread.h> 10 #include "usb.h" 11 #include "usbfs.h" 12 #include "ether.h" 13 14 enum 15 { 16 Arglen = 80, 17 }; 18 19 static void 20 usage(void) 21 { 22 fprint(2, "usage: %s [-a addr] [-Dd] [-N nb] [-m mnt] [-s srv] [dev...]\n", argv0); 23 threadexitsall("usage"); 24 } 25 26 /* 27 * Ether devices may be weird. 28 * Be optimistic and try to use any communication 29 * device or one of the `vendor specific class' devices 30 * that we know are ethernets. 31 */ 32 static int 33 matchether(char *info, void*) 34 { 35 Cinfo *ip; 36 char buf[50]; 37 38 /* 39 * I have an ether reporting comms.0.0 40 */ 41 if(strstr(info, "comms") != nil) 42 return 0; 43 for(ip = cinfo; ip->vid != 0; ip++){ 44 snprint(buf, sizeof(buf), "vid %#06x did %#06x", ip->vid, ip->did); 45 if(strstr(info, buf) != nil) 46 return 0; 47 } 48 return -1; 49 } 50 51 void 52 threadmain(int argc, char **argv) 53 { 54 char args[Arglen]; 55 char *as, *ae, *srv, *mnt; 56 57 srv = nil; 58 mnt = "/net"; 59 60 quotefmtinstall(); 61 ae = args+sizeof(args); 62 as = seprint(args, ae, "ether"); 63 ARGBEGIN{ 64 case 'a': 65 as = seprint(as, ae, " -a %s", EARGF(usage())); 66 break; 67 case 'D': 68 usbfsdebug++; 69 break; 70 case 'd': 71 usbdebug++; 72 as = seprint(as, ae, " -d"); 73 break; 74 case 'N': 75 as = seprint(as, ae, " -N %s", EARGF(usage())); 76 break; 77 case 'm': 78 mnt = EARGF(usage()); 79 break; 80 case 's': 81 srv = EARGF(usage()); 82 break; 83 default: 84 usage(); 85 }ARGEND 86 87 rfork(RFNOTEG); 88 threadsetgrp(threadid()); 89 fmtinstall('U', Ufmt); 90 usbfsinit(srv, mnt, &usbdirfs, MAFTER|MCREATE); 91 startdevs(args, argv, argc, matchether, nil, ethermain); 92 threadexits(nil); 93 } 94