????Linux USB???????????????
???????ν????OS?????豸??????д???о????????????????????????????????????????????????????ο????????????????????????????????????????????????????????Linux???????????????????????Linux??USB?????????????????????????????????????????????????????????????д????
??????????Linux???豸????????????????——??????????????driver???????Щ????ó???????????e??????壬??????????e???????????????????????????????????????????????????????????е???????????????Linux???????c????д?????????????????????????????????????????????????OO????????????Щ?????????????????????????????????????????????????????????mouse_dev??struct??????????????keyboard_dev??struct??dev for device??????????????豸??????????????????????????Linux???????е????usb-skeleton????usb??????????????????????????豸???????usb-skel??
????struct usb_skel {
????struct usb_device *      udev;                 /* the usb device for this device */
????struct usb_interface *   interface;            /* the interface for this device */
????struct semaphore       limit_sem;         /* limiting the number of writes in progress */
????unsigned char *         bulk_in_buffer;     /* the buffer to receive data */
????size_t         bulk_in_size;                  /* the size of the receive buffer */
????__u8          bulk_in_endpointAddr;        /* the address of the bulk in endpoint */
????__u8          bulk_out_endpointAddr;      /* the address of the bulk out endpoint */
????struct kref   kref;
????};
????????????ò??????????ЩUSB??Э??淶????USB??????????豸????????????????????????豸????????淶??????????????????????????????????????????Linux?????????????????????????????????USB????????????飬?????USB??bus???????????????Linux??????????????????????????????????????????????????????USB??bus??????????????·?????????е?????????????????USB????????????????????????usb_core????ɡ???USB?豸???USB????????????usb_core?????豸???Щ?????????????????ID??????ID?????????豸?????class??subclass??protocol?????????????????????????????豸?????渴???????????ù?????????????????鶴??——usb???豸???????????????????usb_core??????????????????????????
???????????????????????usb?豸??????????(configuration)?????????????????ж?????(interface)???????????ж??????(setting?????и???)???????????????ж??????????end point????USB????????????????????У???????????????佨????????????????????????Щ????????????
?????????control??
?????????????豸??????豸???????????????????豸????????
?????ж??interrupt??
??????USB????????豸????????????ж????????????????????????????????????????????USB?豸??????豸????????????????????
??????????bulk??
?????????????????????????????????????????????????????????????????????
?????????isochronous??
?????????????????????????????????????????????????????????????????
????Linux????struct usb_host_endpoint??????USB??????usb_host_endpoint?а??????struct usb_endpoint_descriptor???壬???а???????????????豸????????????????Щ?????????
????bEndpointAddress??b for byte??
????8λ??????????????????????????????????????????????????????????USB_DIR_OUT??USB_DIR_IN???????
????bmAttributes
????????????????USB_ENDPOINT_XFERTYPE_MASK????????????USB_ENDPOINT_XFER_ISOC?????????USB_ENDPOINT_XFER_BULK????????????USB_ENDPOINT_XFER_INT???ж????
????wMaxPacketSize
?????????δ?????????????????BULK???????????????????????????

????bInterval
?????????????ж?????????????????????????????λ??
???????????????USB?豸???????????????????????????????USB?????????????????????????????????????????????????????????????????????????豸??????????????????????????????????????????????????????????????????????????豸??????????????????????ACL??EVENT????????????????SCO??·?????????????????????????Linux?????????struct usb_interface??????????????y????б?????????Σ?
????struct usb_host_interface *altsetting???????usb_interface??
???????????????????????????????????????????е???????????????????????饗??????????ж????????????usb_host_interface???????????struct usb_host_endpoint??????????á?????Щ???????????????
????unsigned num_altstting
????????????????????altsetting????????????????
????struct usb_host_interface *cur_altsetting
???????????????????altsetting?????е??????
????int minor
???????????y???USB???????????USB???豸?????USB core???????豸?????????????usb_register_dev??????Ч??
????????????????struct usb_host_config??????????????????????????????????????USB?豸???????struct usb_device?????????????????????????????????????????????????????????????????????????????塣


????Linux USB????????????????
???????????USB?Щ?淶????????????????????Linux????????????????Linux???豸???????????????hotplug??USB?豸???????????????飬???????????????????д???Linux????鰱????????????helloworld?????
????#include <linux/init.h>
????#include <linux/module.h>
????MODULE_LICENSE(“GPL”);
????static int hello_init(void)
????{
????printk(KERN_ALERT “Hello World!/n”);
????return 0;
????}
????static int hello_exit(void)
????{
????printk(KERN_ALERT “GOODBYE!/n”);
????}
????module_init(hello_init);
????module_exit(hello_exit);
?????????????????????????д?????飬MODULE_LICENSE??????????????????????????£???GPL????BSD???????????????????????????????????????????module_init??module_exit???????????????????????????????????????????????????????????hello_init?????????????hello_exit??
???????????????????????????????????????е?makefile??????????Makefile????д???
????ifneq ($(KERNELRELEASE)??)
????obj-m:= hello.o#usb-dongle.o
????else
????KDIR:= /usr/src/linux-headers-$(shell uname -r)
????BDIR:= $(shell pwd)
????default:
????$(MAKE) -C $(KDIR) M=$(PWD) modules
????.PHONY: clean
????clean:
????make -C $(KDIR) M=$(BDIR) clean
????endif
??????????insmod??rmmod?????????????ж???????????root????????????У???????????su????sudo??Ubuntu??????????е??