1 /* 2 * Copyright (c) 2007-2008 by Michael Lotz 3 * Heavily based on the original usb_serial driver which is: 4 * 5 * Copyright (c) 2003 by Siarzhuk Zharski <imker@gmx.li> 6 * Distributed under the terms of the MIT License. 7 */ 8 #ifndef _USB_SERIAL_DRIVER_H_ 9 #define _USB_SERIAL_DRIVER_H_ 10 11 #include <OS.h> 12 #include <KernelExport.h> 13 #include <Drivers.h> 14 15 #include "BeOSCompatibility.h" 16 #include "kernel_cpp.h" 17 #include "Tracing.h" 18 #include "USB3.h" 19 20 extern "C" { 21 #include <ttylayer.h> 22 } 23 24 #define DRIVER_NAME "usb_serial" // driver name for debug output 25 #define DEVICES_COUNT 20 // max simultaneously open devices 26 27 /* Some usefull helper defines ... */ 28 #define SIZEOF(array) (sizeof(array) / sizeof(array[0])) /* size of array */ 29 /* This one rounds the size to integral count of segs (segments) */ 30 #define ROUNDUP(size, seg) (((size) + (seg) - 1) & ~((seg) - 1)) 31 /* Default device buffer size */ 32 #define DEF_BUFFER_SIZE 0x200 33 34 /* line coding defines ... Come from CDC USB specs? */ 35 #define LC_STOP_BIT_1 0 36 #define LC_STOP_BIT_2 2 37 38 #define LC_PARITY_NONE 0 39 #define LC_PARITY_ODD 1 40 #define LC_PARITY_EVEN 2 41 42 /* struct that represents line coding */ 43 typedef struct usb_serial_line_coding_s { 44 uint32 speed; 45 uint8 stopbits; 46 uint8 parity; 47 uint8 databits; 48 } usb_serial_line_coding; 49 50 /* control line states */ 51 #define CLS_LINE_DTR 0x0001 52 #define CLS_LINE_RTS 0x0002 53 54 /* attributes etc ...*/ 55 #ifndef USB_EP_ADDR_DIR_IN 56 #define USB_EP_ADDR_DIR_IN 0x80 57 #define USB_EP_ADDR_DIR_OUT 0x00 58 #endif 59 60 #ifndef USB_EP_ATTR_CONTROL 61 #define USB_EP_ATTR_CONTROL 0x00 62 #define USB_EP_ATTR_ISOCHRONOUS 0x01 63 #define USB_EP_ATTR_BULK 0x02 64 #define USB_EP_ATTR_INTERRUPT 0x03 65 #endif 66 67 /* USB class - communication devices */ 68 #define USB_DEV_CLASS_COMM 0x02 69 #define USB_INT_CLASS_CDC 0x02 70 #define USB_INT_SUBCLASS_ACM 0x02 71 #define USB_INT_CLASS_CDC_DATA 0x0a 72 #define USB_INT_SUBCLASS_DATA 0x00 73 74 // communication device subtypes 75 #define FUNCTIONAL_SUBTYPE_UNION 0x06 76 77 extern usb_module_info *gUSBModule; 78 extern tty_module_info *gTTYModule; 79 extern struct ddomain gSerialDomain; 80 81 extern "C" { 82 status_t usb_serial_device_added(usb_device device, void **cookie); 83 status_t usb_serial_device_removed(void *cookie); 84 85 status_t init_hardware(); 86 void uninit_driver(); 87 88 bool usb_serial_service(struct tty *ptty, struct ddrover *ddr, uint flags); 89 90 status_t usb_serial_open(const char *name, uint32 flags, void **cookie); 91 status_t usb_serial_read(void *cookie, off_t position, void *buffer, size_t *numBytes); 92 status_t usb_serial_write(void *cookie, off_t position, const void *buffer, size_t *numBytes); 93 status_t usb_serial_control(void *cookie, uint32 op, void *arg, size_t length); 94 status_t usb_serial_select(void *cookie, uint8 event, uint32 ref, selectsync *sync); 95 status_t usb_serial_deselect(void *coookie, uint8 event, selectsync *sync); 96 status_t usb_serial_close(void *cookie); 97 status_t usb_serial_free(void *cookie); 98 99 const char **publish_devices(); 100 device_hooks *find_device(const char *name); 101 } 102 103 #endif //_USB_SERIAL_DRIVER_H_ 104