blob: aa64efaba36634405367ca342d212183aa038e44 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * The USB Monitor, inspired by Dave Harding's USBMon.
Pete Zaitcevda5ca002005-08-16 15:16:46 -07004 *
5 * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#ifndef __USB_MON_H
9#define __USB_MON_H
10
11#include <linux/list.h>
12#include <linux/slab.h>
13#include <linux/kref.h>
14/* #include <linux/usb.h> */ /* We use struct pointers only in this header */
15
16#define TAG "usbmon"
17
18struct mon_bus {
19 struct list_head bus_link;
20 spinlock_t lock;
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080021 struct usb_bus *u_bus;
22
23 int text_inited;
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070024 int bin_inited;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 struct dentry *dent_s; /* Debugging file */
26 struct dentry *dent_t; /* Text interface file */
Pete Zaitcevf1c9e302007-02-24 19:27:33 -080027 struct dentry *dent_u; /* Second text interface file */
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070028 struct device *classdev; /* Device in usbmon class */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30 /* Ref */
31 int nreaders; /* Under mon_lock AND mbus->lock */
32 struct list_head r_list; /* Chain of readers (usually one) */
33 struct kref ref; /* Under mon_lock */
34
35 /* Stats */
Pete Zaitcev5b1c6742006-06-09 20:10:10 -070036 unsigned int cnt_events;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 unsigned int cnt_text_lost;
38};
39
40/*
41 * An instance of a process which opened a file (but can fork later)
42 */
43struct mon_reader {
44 struct list_head r_link;
45 struct mon_bus *m_bus;
46 void *r_data; /* Use container_of instead? */
47
48 void (*rnf_submit)(void *data, struct urb *urb);
Pete Zaitcev12e72fe2006-06-09 22:03:32 -070049 void (*rnf_error)(void *data, struct urb *urb, int error);
Alan Stern9347d512007-08-24 15:41:41 -040050 void (*rnf_complete)(void *data, struct urb *urb, int status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
53void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
54void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
55
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080056struct mon_bus *mon_bus_lookup(unsigned int num);
57
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070058int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080059void mon_text_del(struct mon_bus *mbus);
Pete Zaitcevce7cd137f2007-05-03 16:51:16 -070060int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
61void mon_bin_del(struct mon_bus *mbus);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080062
63int __init mon_text_init(void);
Pete Zaitcev21641e32007-02-20 10:37:52 -080064void mon_text_exit(void);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080065int __init mon_bin_init(void);
Pete Zaitcev21641e32007-02-20 10:37:52 -080066void mon_bin_exit(void);
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080067
Pete Zaitcev02568392005-08-15 16:53:57 -070068/*
Pete Zaitcev6f23ee12006-12-30 22:43:10 -080069 */
Arjan van de Ven4186ecf2006-01-11 15:55:29 +010070extern struct mutex mon_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -030072extern const struct file_operations mon_fops_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Pete Zaitcevecb658d2007-04-11 13:47:26 -070074extern struct mon_bus mon_bus0; /* Only for redundant checks */
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif /* __USB_MON_H */