ether.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * usb/ether - usb ethernet adapter.
  11. * BUG: This should use /dev/etherfile to
  12. * use the kernel ether device code.
  13. */
  14. #include <u.h>
  15. #include <libc.h>
  16. #include <fcall.h>
  17. #include <thread.h>
  18. #include <usb/usb.h>
  19. #include <usb/usbfs.h>
  20. #include <usb/ether.h>
  21. enum
  22. {
  23. Arglen = 80,
  24. };
  25. static void
  26. usage(void)
  27. {
  28. fprint(2, "usage: %s [-a addr] [-Dd] [-N nb] [-m mnt] [-s srv] [dev...]\n", argv0);
  29. threadexitsall("usage");
  30. }
  31. /*
  32. * Ether devices may be weird.
  33. * Be optimistic and try to use any communication
  34. * device or one of the `vendor specific class' devices
  35. * that we know are ethernets.
  36. */
  37. static int
  38. matchether(char *info, void*_)
  39. {
  40. Cinfo *ip;
  41. char buf[50];
  42. /*
  43. * I have an ether reporting comms.0.0
  44. */
  45. if(strstr(info, "comms") != nil)
  46. return 0;
  47. for(ip = cinfo; ip->vid != 0; ip++){
  48. snprint(buf, sizeof(buf), "vid %#06x did %#06x", ip->vid, ip->did);
  49. if(strstr(info, buf) != nil)
  50. return 0;
  51. }
  52. return -1;
  53. }
  54. void
  55. threadmain(int argc, char **argv)
  56. {
  57. char args[Arglen];
  58. char *as, *ae, *srv, *mnt;
  59. srv = nil;
  60. mnt = "/net";
  61. quotefmtinstall();
  62. ae = args+sizeof(args);
  63. as = seprint(args, ae, "ether");
  64. ARGBEGIN{
  65. case 'a':
  66. as = seprint(as, ae, " -a %s", EARGF(usage()));
  67. break;
  68. case 'D':
  69. usbfsdebug++;
  70. break;
  71. case 'd':
  72. usbdebug++;
  73. as = seprint(as, ae, " -d");
  74. break;
  75. case 'N':
  76. as = seprint(as, ae, " -N %s", EARGF(usage()));
  77. break;
  78. case 'm':
  79. mnt = EARGF(usage());
  80. break;
  81. case 's':
  82. srv = EARGF(usage());
  83. break;
  84. default:
  85. usage();
  86. }ARGEND
  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. }