11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The USB Monitor, inspired by Dave Harding's USBMon.
3da5ca008933b3b28303ba44d0be3372fbac7748bPete Zaitcev *
4da5ca008933b3b28303ba44d0be3372fbac7748bPete Zaitcev * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __USB_MON_H
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __USB_MON_H
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/list.h>
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h>
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kref.h>
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* #include <linux/usb.h> */	/* We use struct pointers only in this header */
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define TAG "usbmon"
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mon_bus {
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head bus_link;
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	spinlock_t lock;
206f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev	struct usb_bus *u_bus;
216f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev
226f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev	int text_inited;
23ce7cd137fced114d49178b73d468b82096a107fbPete Zaitcev	int bin_inited;
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct dentry *dent_s;		/* Debugging file */
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct dentry *dent_t;		/* Text interface file */
26f1c9e30b5e4cdd8aae5f0ea87004b1b61ec41881Pete Zaitcev	struct dentry *dent_u;		/* Second text interface file */
27ce7cd137fced114d49178b73d468b82096a107fbPete Zaitcev	struct device *classdev;	/* Device in usbmon class */
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Ref */
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int nreaders;			/* Under mon_lock AND mbus->lock */
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head r_list;	/* Chain of readers (usually one) */
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct kref ref;		/* Under mon_lock */
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Stats */
355b1c674d223eef6c6494be8be91e9e3a3054817ePete Zaitcev	unsigned int cnt_events;
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned int cnt_text_lost;
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * An instance of a process which opened a file (but can fork later)
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct mon_reader {
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct list_head r_link;
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct mon_bus *m_bus;
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void *r_data;		/* Use container_of instead? */
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	void (*rnf_submit)(void *data, struct urb *urb);
4812e72feab5d9a23107f245b0f241a2484cbb5a4ePete Zaitcev	void (*rnf_error)(void *data, struct urb *urb, int error);
499347d51c52afcf1a77d2104f162cf8a085624c83Alan Stern	void (*rnf_complete)(void *data, struct urb *urb, int status);
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
556f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcevstruct mon_bus *mon_bus_lookup(unsigned int num);
566f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev
57ce7cd137fced114d49178b73d468b82096a107fbPete Zaitcevint /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus);
586f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcevvoid mon_text_del(struct mon_bus *mbus);
59ce7cd137fced114d49178b73d468b82096a107fbPete Zaitcevint /*bool*/ mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus);
60ce7cd137fced114d49178b73d468b82096a107fbPete Zaitcevvoid mon_bin_del(struct mon_bus *mbus);
616f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev
626f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcevint __init mon_text_init(void);
6321641e3fb1c2e53b3a0acf68e6f62f1f82f61445Pete Zaitcevvoid mon_text_exit(void);
646f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcevint __init mon_bin_init(void);
6521641e3fb1c2e53b3a0acf68e6f62f1f82f61445Pete Zaitcevvoid mon_bin_exit(void);
666f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev
670256839619d9b1e933cafc83e7f0deaad4216465Pete Zaitcev/*
686f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9Pete Zaitcev */
694186ecf8ad16dd05759a09594de6a87e48759ba6Arjan van de Venextern struct mutex mon_lock;
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
71066202dd48cf3296b6cc22b5fcf89aef33fa0efcLuiz Fernando N. Capitulinoextern const struct file_operations mon_fops_stat;
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
73ecb658d387dc09f344b3d755e8674076072032c7Pete Zaitcevextern struct mon_bus mon_bus0;		/* Only for redundant checks */
74ecb658d387dc09f344b3d755e8674076072032c7Pete Zaitcev
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* __USB_MON_H */
76