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