usb_mon.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * The USB Monitor, inspired by Dave Harding's USBMon.
  4. *
  5. * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
  6. */
  7. #ifndef __USB_MON_H
  8. #define __USB_MON_H
  9. #include <linux/list.h>
  10. #include <linux/slab.h>
  11. #include <linux/kref.h>
  12. /* #include <linux/usb.h> */ /* We use struct pointers only in this header */
  13. #define TAG "usbmon"
  14. struct mon_bus {
  15. struct list_head bus_link;
  16. spinlock_t lock;
  17. struct usb_bus *u_bus;
  18. int text_inited;
  19. int bin_inited;
  20. struct dentry *dent_s; /* Debugging file */
  21. struct dentry *dent_t; /* Text interface file */
  22. struct dentry *dent_u; /* Second text interface file */
  23. struct device *classdev; /* Device in usbmon class */
  24. /* Ref */
  25. int nreaders; /* Under mon_lock AND mbus->lock */
  26. struct list_head r_list; /* Chain of readers (usually one) */
  27. struct kref ref; /* Under mon_lock */
  28. /* Stats */
  29. unsigned int cnt_events;
  30. unsigned int cnt_text_lost;
  31. };
  32. /*
  33. * An instance of a process which opened a file (but can fork later)
  34. */
  35. struct mon_reader {
  36. struct list_head r_link;
  37. struct mon_bus *m_bus;
  38. void *r_data; /* Use container_of instead? */
  39. void (*rnf_submit)(void *data, struct urb *urb);
  40. void (*rnf_error)(void *data, struct urb *urb, int error);
  41. void (*rnf_complete)(void *data, struct urb *urb, int status);
  42. };
  43. void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
  44. void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
  45. struct mon_bus *mon_bus_lookup(unsigned int num);
  46. int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
  47. void mon_text_del(struct mon_bus *mbus);
  48. int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
  49. void mon_bin_del(struct mon_bus *mbus);
  50. int __init mon_text_init(void);
  51. void mon_text_exit(void);
  52. int __init mon_bin_init(void);
  53. void mon_bin_exit(void);
  54. /*
  55. */
  56. extern struct mutex mon_lock;
  57. extern const struct file_operations mon_fops_stat;
  58. extern struct mon_bus mon_bus0; /* Only for redundant checks */
  59. #endif /* __USB_MON_H */