1 /* $NetBSD: uirdavar.h,v 1.8 2021/09/26 15:08:29 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2001,2007 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart@augustsson.net). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 /* 32 * Protocol related definitions 33 */ 34 35 #define UIRDA_INPUT_HEADER_SIZE 1 36 /* Inbound header byte */ 37 #define UIRDA_MEDIA_BUSY 0x80 38 #define UIRDA_SPEED_MASK 0x0f 39 #define UIRDA_NO_SPEED 0x00 40 #define UIRDA_2400 0x01 41 #define UIRDA_9600 0x02 42 #define UIRDA_19200 0x03 43 #define UIRDA_38400 0x04 44 #define UIRDA_57600 0x05 45 #define UIRDA_115200 0x06 46 #define UIRDA_576000 0x07 47 #define UIRDA_1152000 0x08 48 #define UIRDA_4000000 0x09 49 50 #define UIRDA_OUTPUT_HEADER_SIZE 1 51 /* Outbound header byte */ 52 #define UIRDA_EB_NO_CHANGE 0x00 53 #define UIRDA_EB_48 0x10 54 #define UIRDA_EB_24 0x20 55 #define UIRDA_EB_12 0x30 56 #define UIRDA_EB_6 0x40 57 #define UIRDA_EB_3 0x50 58 #define UIRDA_EB_2 0x60 59 #define UIRDA_EB_1 0x70 60 #define UIRDA_EB_0 0x80 61 /* Speeds as above */ 62 63 #define UIRDA_WR_TIMEOUT 200 64 65 typedef struct { 66 uByte bLength; 67 uByte bDescriptorType; 68 #define UDESC_IRDA 0x21 69 uWord bcdSpecRevision; 70 uByte bmDataSize; 71 #define UI_DS_2048 0x20 72 #define UI_DS_1024 0x10 73 #define UI_DS_512 0x08 74 #define UI_DS_256 0x04 75 #define UI_DS_128 0x02 76 #define UI_DS_64 0x01 77 uByte bmWindowSize; 78 #define UI_WS_7 0x40 79 #define UI_WS_6 0x20 80 #define UI_WS_5 0x10 81 #define UI_WS_4 0x08 82 #define UI_WS_3 0x04 83 #define UI_WS_2 0x02 84 #define UI_WS_1 0x01 85 uByte bmMinTurnaroundTime; 86 #define UI_TA_0 0x80 87 #define UI_TA_10 0x40 88 #define UI_TA_50 0x20 89 #define UI_TA_100 0x10 90 #define UI_TA_500 0x08 91 #define UI_TA_1000 0x04 92 #define UI_TA_5000 0x02 93 #define UI_TA_10000 0x01 94 uWord wBaudRate; 95 #define UI_BR_4000000 0x0100 96 #define UI_BR_1152000 0x0080 97 #define UI_BR_576000 0x0040 98 #define UI_BR_115200 0x0020 99 #define UI_BR_57600 0x0010 100 #define UI_BR_38400 0x0008 101 #define UI_BR_19200 0x0004 102 #define UI_BR_9600 0x0002 103 #define UI_BR_2400 0x0001 104 uByte bmAdditionalBOFs; 105 #define UI_EB_0 0x80 106 #define UI_EB_1 0x40 107 #define UI_EB_2 0x20 108 #define UI_EB_3 0x10 109 #define UI_EB_6 0x08 110 #define UI_EB_12 0x04 111 #define UI_EB_24 0x02 112 #define UI_EB_48 0x01 113 uByte bIrdaSniff; 114 uByte bMaxUnicastList; 115 } UPACKED usb_irda_descriptor_t; 116 #define USB_IRDA_DESCRIPTOR_SIZE 12 117 118 119 struct uirda_softc { 120 device_t sc_dev; 121 struct usbd_device *sc_udev; 122 struct usbd_interface *sc_iface; 123 124 kmutex_t sc_rd_buf_lk; 125 uint8_t *sc_rd_buf; 126 int sc_rd_addr; 127 struct usbd_pipe *sc_rd_pipe; 128 struct usbd_xfer *sc_rd_xfer; 129 struct selinfo sc_rd_sel; 130 u_int sc_rd_count; 131 u_char sc_rd_err; 132 133 kmutex_t sc_wr_buf_lk; 134 uint8_t *sc_wr_buf; 135 int sc_wr_addr; 136 struct usbd_xfer *sc_wr_xfer; 137 struct usbd_pipe *sc_wr_pipe; 138 int sc_wr_hdr; 139 140 device_t sc_child; 141 struct irda_params sc_params; 142 usb_irda_descriptor_t sc_irdadesc; 143 144 int sc_refcnt; 145 char sc_dying; 146 uint8_t sc_hdszi; /* set to value if != 1 needed */ 147 148 int (*sc_loadfw)(struct uirda_softc *); 149 struct irframe_methods *sc_irm; 150 }; 151 152 usbd_status usbd_get_class_desc(struct usbd_device *, int, int, int, void *); 153 154 int uirda_open(void *, int, int, struct lwp *); 155 int uirda_close(void *, int, int, struct lwp *); 156 int uirda_read(void *, struct uio *, int); 157 int uirda_write(void *, struct uio *, int); 158 int uirda_set_params(void *, struct irda_params *); 159 int uirda_get_speeds(void *, int *); 160 int uirda_get_turnarounds(void *, int *); 161 int uirda_poll(void *, int, struct lwp *); 162 int uirda_kqfilter(void *, struct knote *); 163