Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * The USB Monitor, inspired by Dave Harding's USBMon. |
Pete Zaitcev | da5ca00 | 2005-08-16 15:16:46 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 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 | |
| 18 | struct mon_bus { |
| 19 | struct list_head bus_link; |
| 20 | spinlock_t lock; |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 21 | struct usb_bus *u_bus; |
| 22 | |
| 23 | int text_inited; |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 24 | int bin_inited; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | struct dentry *dent_s; /* Debugging file */ |
| 26 | struct dentry *dent_t; /* Text interface file */ |
Pete Zaitcev | f1c9e30 | 2007-02-24 19:27:33 -0800 | [diff] [blame] | 27 | struct dentry *dent_u; /* Second text interface file */ |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 28 | struct device *classdev; /* Device in usbmon class */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 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 Zaitcev | 5b1c674 | 2006-06-09 20:10:10 -0700 | [diff] [blame] | 36 | unsigned int cnt_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | unsigned int cnt_text_lost; |
| 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * An instance of a process which opened a file (but can fork later) |
| 42 | */ |
| 43 | struct 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 Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 49 | void (*rnf_error)(void *data, struct urb *urb, int error); |
Alan Stern | 9347d51 | 2007-08-24 15:41:41 -0400 | [diff] [blame] | 50 | void (*rnf_complete)(void *data, struct urb *urb, int status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); |
| 54 | void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); |
| 55 | |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 56 | struct mon_bus *mon_bus_lookup(unsigned int num); |
| 57 | |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 58 | int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 59 | void mon_text_del(struct mon_bus *mbus); |
Pete Zaitcev | ce7cd137f | 2007-05-03 16:51:16 -0700 | [diff] [blame] | 60 | int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus); |
| 61 | void mon_bin_del(struct mon_bus *mbus); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 62 | |
| 63 | int __init mon_text_init(void); |
Pete Zaitcev | 21641e3 | 2007-02-20 10:37:52 -0800 | [diff] [blame] | 64 | void mon_text_exit(void); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 65 | int __init mon_bin_init(void); |
Pete Zaitcev | 21641e3 | 2007-02-20 10:37:52 -0800 | [diff] [blame] | 66 | void mon_bin_exit(void); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 67 | |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 68 | /* |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 69 | */ |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 70 | extern struct mutex mon_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 72 | extern const struct file_operations mon_fops_stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Pete Zaitcev | ecb658d | 2007-04-11 13:47:26 -0700 | [diff] [blame] | 74 | extern struct mon_bus mon_bus0; /* Only for redundant checks */ |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #endif /* __USB_MON_H */ |