usbugly.c 848 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "usb.h"
  4. void
  5. main(int argc, char *argv[])
  6. {
  7. Usbconfig *confs;
  8. int nconfs;
  9. int fd, epdata, epctl;
  10. int i;
  11. confs = nil;
  12. epdata = -1;
  13. epctl = -1;
  14. fd = open(argv[1], ORDWR);
  15. nconfs = usbconfread(fd, &confs);
  16. for(i = 0; i < nconfs; i++){
  17. if(usbconfprint(1, confs+i) == -1){
  18. fprint(2, "usbprint fail!\n");
  19. goto fail;
  20. }
  21. }
  22. epdata = usbopen(fd, confs, 0, &epctl);
  23. if(epdata == -1){
  24. fprint(2, "usbopen fail!\n");
  25. goto fail;
  26. }
  27. for(i = 0; i < 128; i++){
  28. char buf[8];
  29. int j, n;
  30. n = read(epdata, buf, sizeof buf);
  31. for(j = 0; j < n; j++)
  32. print("0x%02x%s", buf[j], j == n-1 ? "\n" : ", ");
  33. }
  34. fail:
  35. if(confs != nil)
  36. free(confs);
  37. close(fd);
  38. if(epdata != -1)
  39. close(epdata);
  40. if(epctl != -1)
  41. close(epctl);
  42. print("sizeof(confs[0]) = %d\n", sizeof confs[0]);
  43. exits(nil);
  44. }