18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * The USB Monitor, inspired by Dave Harding's USBMon. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __USB_MON_H 98c2ecf20Sopenharmony_ci#define __USB_MON_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/list.h> 128c2ecf20Sopenharmony_ci#include <linux/slab.h> 138c2ecf20Sopenharmony_ci#include <linux/kref.h> 148c2ecf20Sopenharmony_ci/* #include <linux/usb.h> */ /* We use struct pointers only in this header */ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define TAG "usbmon" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct mon_bus { 198c2ecf20Sopenharmony_ci struct list_head bus_link; 208c2ecf20Sopenharmony_ci spinlock_t lock; 218c2ecf20Sopenharmony_ci struct usb_bus *u_bus; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci int text_inited; 248c2ecf20Sopenharmony_ci int bin_inited; 258c2ecf20Sopenharmony_ci struct dentry *dent_s; /* Debugging file */ 268c2ecf20Sopenharmony_ci struct dentry *dent_t; /* Text interface file */ 278c2ecf20Sopenharmony_ci struct dentry *dent_u; /* Second text interface file */ 288c2ecf20Sopenharmony_ci struct device *classdev; /* Device in usbmon class */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci /* Ref */ 318c2ecf20Sopenharmony_ci int nreaders; /* Under mon_lock AND mbus->lock */ 328c2ecf20Sopenharmony_ci struct list_head r_list; /* Chain of readers (usually one) */ 338c2ecf20Sopenharmony_ci struct kref ref; /* Under mon_lock */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* Stats */ 368c2ecf20Sopenharmony_ci unsigned int cnt_events; 378c2ecf20Sopenharmony_ci unsigned int cnt_text_lost; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* 418c2ecf20Sopenharmony_ci * An instance of a process which opened a file (but can fork later) 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_cistruct mon_reader { 448c2ecf20Sopenharmony_ci struct list_head r_link; 458c2ecf20Sopenharmony_ci struct mon_bus *m_bus; 468c2ecf20Sopenharmony_ci void *r_data; /* Use container_of instead? */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci void (*rnf_submit)(void *data, struct urb *urb); 498c2ecf20Sopenharmony_ci void (*rnf_error)(void *data, struct urb *urb, int error); 508c2ecf20Sopenharmony_ci void (*rnf_complete)(void *data, struct urb *urb, int status); 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_civoid mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); 548c2ecf20Sopenharmony_civoid mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct mon_bus *mon_bus_lookup(unsigned int num); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciint /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus); 598c2ecf20Sopenharmony_civoid mon_text_del(struct mon_bus *mbus); 608c2ecf20Sopenharmony_ciint /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus); 618c2ecf20Sopenharmony_civoid mon_bin_del(struct mon_bus *mbus); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciint __init mon_text_init(void); 648c2ecf20Sopenharmony_civoid mon_text_exit(void); 658c2ecf20Sopenharmony_ciint __init mon_bin_init(void); 668c2ecf20Sopenharmony_civoid mon_bin_exit(void); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_ciextern struct mutex mon_lock; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciextern const struct file_operations mon_fops_stat; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciextern struct mon_bus mon_bus0; /* Only for redundant checks */ 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#endif /* __USB_MON_H */ 77