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