Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * The USB Monitor, inspired by Dave Harding's USBMon.
0004  *
0005  * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
0006  */
0007 
0008 #ifndef __USB_MON_H
0009 #define __USB_MON_H
0010 
0011 #include <linux/list.h>
0012 #include <linux/slab.h>
0013 #include <linux/kref.h>
0014 /* #include <linux/usb.h> */    /* We use struct pointers only in this header */
0015 
0016 #define TAG "usbmon"
0017 
0018 struct mon_bus {
0019     struct list_head bus_link;
0020     spinlock_t lock;
0021     struct usb_bus *u_bus;
0022 
0023     int text_inited;
0024     int bin_inited;
0025     struct dentry *dent_s;      /* Debugging file */
0026     struct dentry *dent_t;      /* Text interface file */
0027     struct dentry *dent_u;      /* Second text interface file */
0028     struct device *classdev;    /* Device in usbmon class */
0029 
0030     /* Ref */
0031     int nreaders;           /* Under mon_lock AND mbus->lock */
0032     struct list_head r_list;    /* Chain of readers (usually one) */
0033     struct kref ref;        /* Under mon_lock */
0034 
0035     /* Stats */
0036     unsigned int cnt_events;
0037     unsigned int cnt_text_lost;
0038 };
0039 
0040 /*
0041  * An instance of a process which opened a file (but can fork later)
0042  */
0043 struct mon_reader {
0044     struct list_head r_link;
0045     struct mon_bus *m_bus;
0046     void *r_data;       /* Use container_of instead? */
0047 
0048     void (*rnf_submit)(void *data, struct urb *urb);
0049     void (*rnf_error)(void *data, struct urb *urb, int error);
0050     void (*rnf_complete)(void *data, struct urb *urb, int status);
0051 };
0052 
0053 void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
0054 void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
0055 
0056 struct mon_bus *mon_bus_lookup(unsigned int num);
0057 
0058 int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
0059 void mon_text_del(struct mon_bus *mbus);
0060 int /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
0061 void mon_bin_del(struct mon_bus *mbus);
0062 
0063 int __init mon_text_init(void);
0064 void mon_text_exit(void);
0065 int __init mon_bin_init(void);
0066 void mon_bin_exit(void);
0067 
0068 /*
0069  */
0070 extern struct mutex mon_lock;
0071 
0072 extern const struct file_operations mon_fops_stat;
0073 
0074 extern struct mon_bus mon_bus0;     /* Only for redundant checks */
0075 
0076 #endif /* __USB_MON_H */