| File: | dev/usb/uvisor.c |
| Warning: | line 327, column 17 Assigned value is garbage or undefined |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* $OpenBSD: uvisor.c,v 1.53 2022/04/09 20:07:44 naddy Exp $ */ | |||
| 2 | /* $NetBSD: uvisor.c,v 1.21 2003/08/03 21:59:26 nathanw Exp $ */ | |||
| 3 | ||||
| 4 | /* | |||
| 5 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | |||
| 6 | * All rights reserved. | |||
| 7 | * | |||
| 8 | * This code is derived from software contributed to The NetBSD Foundation | |||
| 9 | * by Lennart Augustsson (lennart@augustsson.net) at | |||
| 10 | * Carlstedt Research & Technology. | |||
| 11 | * | |||
| 12 | * Redistribution and use in source and binary forms, with or without | |||
| 13 | * modification, are permitted provided that the following conditions | |||
| 14 | * are met: | |||
| 15 | * 1. Redistributions of source code must retain the above copyright | |||
| 16 | * notice, this list of conditions and the following disclaimer. | |||
| 17 | * 2. Redistributions in binary form must reproduce the above copyright | |||
| 18 | * notice, this list of conditions and the following disclaimer in the | |||
| 19 | * documentation and/or other materials provided with the distribution. | |||
| 20 | * | |||
| 21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |||
| 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |||
| 23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |||
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |||
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |||
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |||
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |||
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |||
| 31 | * POSSIBILITY OF SUCH DAMAGE. | |||
| 32 | */ | |||
| 33 | ||||
| 34 | /* | |||
| 35 | * Handspring Visor (Palmpilot compatible PDA) driver | |||
| 36 | */ | |||
| 37 | ||||
| 38 | #include <sys/param.h> | |||
| 39 | #include <sys/systm.h> | |||
| 40 | #include <sys/kernel.h> | |||
| 41 | #include <sys/device.h> | |||
| 42 | #include <sys/conf.h> | |||
| 43 | #include <sys/tty.h> | |||
| 44 | ||||
| 45 | #include <dev/usb/usb.h> | |||
| 46 | ||||
| 47 | #include <dev/usb/usbdi.h> | |||
| 48 | #include <dev/usb/usbdi_util.h> | |||
| 49 | #include <dev/usb/usbdevs.h> | |||
| 50 | ||||
| 51 | #include <dev/usb/ucomvar.h> | |||
| 52 | ||||
| 53 | #ifdef UVISOR_DEBUG | |||
| 54 | #define DPRINTF(x) if (uvisordebug) printf x | |||
| 55 | #define DPRINTFN(n,x) if (uvisordebug>(n)) printf x | |||
| 56 | int uvisordebug = 0; | |||
| 57 | #else | |||
| 58 | #define DPRINTF(x) | |||
| 59 | #define DPRINTFN(n,x) | |||
| 60 | #endif | |||
| 61 | ||||
| 62 | #define UVISOR_IFACE_INDEX0 0 | |||
| 63 | ||||
| 64 | /* From the Linux driver */ | |||
| 65 | /* | |||
| 66 | * UVISOR_REQUEST_BYTES_AVAILABLE asks the visor for the number of bytes that | |||
| 67 | * are available to be transferred to the host for the specified endpoint. | |||
| 68 | * Currently this is not used, and always returns 0x0001 | |||
| 69 | */ | |||
| 70 | #define UVISOR_REQUEST_BYTES_AVAILABLE0x01 0x01 | |||
| 71 | ||||
| 72 | /* | |||
| 73 | * UVISOR_CLOSE_NOTIFICATION is set to the device to notify it that the host | |||
| 74 | * is now closing the pipe. An empty packet is sent in response. | |||
| 75 | */ | |||
| 76 | #define UVISOR_CLOSE_NOTIFICATION0x02 0x02 | |||
| 77 | ||||
| 78 | /* | |||
| 79 | * UVISOR_GET_CONNECTION_INFORMATION is sent by the host during enumeration to | |||
| 80 | * get the endpoints used by the connection. | |||
| 81 | */ | |||
| 82 | #define UVISOR_GET_CONNECTION_INFORMATION0x03 0x03 | |||
| 83 | ||||
| 84 | ||||
| 85 | /* | |||
| 86 | * UVISOR_GET_CONNECTION_INFORMATION returns data in the following format | |||
| 87 | */ | |||
| 88 | #define UVISOR_MAX_CONN8 8 | |||
| 89 | struct uvisor_connection_info { | |||
| 90 | uWord num_ports; | |||
| 91 | struct { | |||
| 92 | uByte port_function_id; | |||
| 93 | uByte port; | |||
| 94 | } connections[UVISOR_MAX_CONN8]; | |||
| 95 | }; | |||
| 96 | #define UVISOR_CONNECTION_INFO_SIZE18 18 | |||
| 97 | ||||
| 98 | /* struct uvisor_connection_info.connection[x].port_function_id defines: */ | |||
| 99 | #define UVISOR_FUNCTION_GENERIC0x00 0x00 | |||
| 100 | #define UVISOR_FUNCTION_DEBUGGER0x01 0x01 | |||
| 101 | #define UVISOR_FUNCTION_HOTSYNC0x02 0x02 | |||
| 102 | #define UVISOR_FUNCTION_CONSOLE0x03 0x03 | |||
| 103 | #define UVISOR_FUNCTION_REMOTE_FILE_SYS0x04 0x04 | |||
| 104 | ||||
| 105 | /* | |||
| 106 | * Unknown PalmOS stuff. | |||
| 107 | */ | |||
| 108 | #define UVISOR_GET_PALM_INFORMATION0x04 0x04 | |||
| 109 | #define UVISOR_GET_PALM_INFORMATION_LEN0x44 0x44 | |||
| 110 | ||||
| 111 | struct uvisor_palm_connection_info { | |||
| 112 | uByte num_ports; | |||
| 113 | uByte endpoint_numbers_different; | |||
| 114 | uWord reserved1; | |||
| 115 | struct { | |||
| 116 | uDWord port_function_id; | |||
| 117 | uByte port; | |||
| 118 | uByte end_point_info; | |||
| 119 | uWord reserved; | |||
| 120 | } connections[UVISOR_MAX_CONN8]; | |||
| 121 | }; | |||
| 122 | ||||
| 123 | #define UVISORIBUFSIZE64 64 | |||
| 124 | #define UVISOROBUFSIZE1024 1024 | |||
| 125 | ||||
| 126 | struct uvisor_softc { | |||
| 127 | struct device sc_dev; /* base device */ | |||
| 128 | struct usbd_device *sc_udev; /* device */ | |||
| 129 | struct usbd_interface *sc_iface; /* interface */ | |||
| 130 | /* | |||
| 131 | * added sc_vendor for later interrogation in failed initialisations | |||
| 132 | */ | |||
| 133 | int sc_vendor; /* USB device vendor */ | |||
| 134 | ||||
| 135 | struct device *sc_subdevs[UVISOR_MAX_CONN8]; | |||
| 136 | int sc_numcon; | |||
| 137 | ||||
| 138 | u_int16_t sc_flags; | |||
| 139 | }; | |||
| 140 | ||||
| 141 | usbd_status uvisor_init(struct uvisor_softc *, | |||
| 142 | struct uvisor_connection_info *, | |||
| 143 | struct uvisor_palm_connection_info *); | |||
| 144 | ||||
| 145 | void uvisor_close(void *, int); | |||
| 146 | ||||
| 147 | ||||
| 148 | const struct ucom_methods uvisor_methods = { | |||
| 149 | NULL((void *)0), | |||
| 150 | NULL((void *)0), | |||
| 151 | NULL((void *)0), | |||
| 152 | NULL((void *)0), | |||
| 153 | NULL((void *)0), | |||
| 154 | uvisor_close, | |||
| 155 | NULL((void *)0), | |||
| 156 | NULL((void *)0), | |||
| 157 | }; | |||
| 158 | ||||
| 159 | struct uvisor_type { | |||
| 160 | struct usb_devno uv_dev; | |||
| 161 | u_int16_t uv_flags; | |||
| 162 | #define PALM40x0001 0x0001 | |||
| 163 | #define VISOR0x0002 0x0002 | |||
| 164 | #define NOFRE0x0004 0x0004 | |||
| 165 | #define CLIE4(0x0002|0x0004) (VISOR0x0002|NOFRE0x0004) | |||
| 166 | }; | |||
| 167 | static const struct uvisor_type uvisor_devs[] = { | |||
| 168 | {{ USB_VENDOR_ACEECA0x4766, USB_PRODUCT_ACEECA_MEZ10000x0001 }, PALM40x0001 }, | |||
| 169 | {{ USB_VENDOR_FOSSIL0x0e67, USB_PRODUCT_FOSSIL_WRISTPDA0x0002 }, PALM40x0001 }, | |||
| 170 | {{ USB_VENDOR_GARMIN0x091e, USB_PRODUCT_GARMIN_IQUE36000x0004 }, PALM40x0001 }, | |||
| 171 | {{ USB_VENDOR_HANDSPRING0x082d, USB_PRODUCT_HANDSPRING_VISOR0x0100 }, VISOR0x0002 }, | |||
| 172 | {{ USB_VENDOR_HANDSPRING0x082d, USB_PRODUCT_HANDSPRING_TREO0x0200 }, PALM40x0001 }, | |||
| 173 | {{ USB_VENDOR_HANDSPRING0x082d, USB_PRODUCT_HANDSPRING_TREO6000x0300 }, VISOR0x0002 }, | |||
| 174 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_M5000x0001 }, PALM40x0001 }, | |||
| 175 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_M5050x0002 }, PALM40x0001 }, | |||
| 176 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_M5150x0003 }, PALM40x0001 }, | |||
| 177 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_I7050x0020 }, PALM40x0001 }, | |||
| 178 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_M1250x0040 }, PALM40x0001 }, | |||
| 179 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_M1300x0050 }, PALM40x0001 }, | |||
| 180 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_TUNGSTEN_Z0x0031 }, PALM40x0001 }, | |||
| 181 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_TUNGSTEN_T0x0060 }, PALM40x0001 }, | |||
| 182 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_ZIRE0x0070 }, PALM40x0001 }, | |||
| 183 | {{ USB_VENDOR_PALM0x0830, USB_PRODUCT_PALM_ZIRE_310x0061 }, PALM40x0001 }, | |||
| 184 | {{ USB_VENDOR_SONY0x054c, USB_PRODUCT_SONY_CLIE_400x0066 }, PALM40x0001 }, | |||
| 185 | {{ USB_VENDOR_SONY0x054c, USB_PRODUCT_SONY_CLIE_410x009a }, PALM40x0001 }, | |||
| 186 | {{ USB_VENDOR_SONY0x054c, USB_PRODUCT_SONY_CLIE_S3600x0095 }, PALM40x0001 }, | |||
| 187 | {{ USB_VENDOR_SONY0x054c, USB_PRODUCT_SONY_CLIE_NX600x00da }, PALM40x0001 }, | |||
| 188 | {{ USB_VENDOR_SONY0x054c, USB_PRODUCT_SONY_CLIE_TJ250x0169 }, PALM40x0001 }, | |||
| 189 | /* {{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/ | |||
| 190 | {{ USB_VENDOR_TAPWAVE0x12ef, USB_PRODUCT_TAPWAVE_ZODIAC0x0100 }, PALM40x0001 }, | |||
| 191 | }; | |||
| 192 | #define uvisor_lookup(v, p)((struct uvisor_type *)usbd_match_device((const struct usb_devno *)(uvisor_devs), sizeof (uvisor_devs) / sizeof ((uvisor_devs )[0]), sizeof ((uvisor_devs)[0]), (v), (p))) ((struct uvisor_type *)usb_lookup(uvisor_devs, v, p)usbd_match_device((const struct usb_devno *)(uvisor_devs), sizeof (uvisor_devs) / sizeof ((uvisor_devs)[0]), sizeof ((uvisor_devs )[0]), (v), (p))) | |||
| 193 | ||||
| 194 | int uvisor_match(struct device *, void *, void *); | |||
| 195 | void uvisor_attach(struct device *, struct device *, void *); | |||
| 196 | int uvisor_detach(struct device *, int); | |||
| 197 | ||||
| 198 | struct cfdriver uvisor_cd = { | |||
| 199 | NULL((void *)0), "uvisor", DV_DULL | |||
| 200 | }; | |||
| 201 | ||||
| 202 | const struct cfattach uvisor_ca = { | |||
| 203 | sizeof(struct uvisor_softc), uvisor_match, uvisor_attach, uvisor_detach | |||
| 204 | }; | |||
| 205 | ||||
| 206 | int | |||
| 207 | uvisor_match(struct device *parent, void *match, void *aux) | |||
| 208 | { | |||
| 209 | struct usb_attach_arg *uaa = aux; | |||
| 210 | ||||
| 211 | if (uaa->iface == NULL((void *)0)) | |||
| 212 | return (UMATCH_NONE0); | |||
| 213 | ||||
| 214 | DPRINTFN(20,("uvisor: vendor=0x%x, product=0x%x\n", | |||
| 215 | uaa->vendor, uaa->product)); | |||
| 216 | ||||
| 217 | return (uvisor_lookup(uaa->vendor, uaa->product)((struct uvisor_type *)usbd_match_device((const struct usb_devno *)(uvisor_devs), sizeof (uvisor_devs) / sizeof ((uvisor_devs )[0]), sizeof ((uvisor_devs)[0]), (uaa->vendor), (uaa-> product))) != NULL((void *)0) ? | |||
| 218 | UMATCH_VENDOR_PRODUCT13 : UMATCH_NONE0); | |||
| 219 | } | |||
| 220 | ||||
| 221 | void | |||
| 222 | uvisor_attach(struct device *parent, struct device *self, void *aux) | |||
| 223 | { | |||
| 224 | struct uvisor_softc *sc = (struct uvisor_softc *)self; | |||
| 225 | struct usb_attach_arg *uaa = aux; | |||
| 226 | struct usbd_device *dev = uaa->device; | |||
| 227 | struct usbd_interface *iface; | |||
| 228 | usb_interface_descriptor_t *id; | |||
| 229 | struct uvisor_connection_info coninfo; | |||
| 230 | struct uvisor_palm_connection_info palmconinfo; | |||
| 231 | usb_endpoint_descriptor_t *ed; | |||
| 232 | int i, j, hasin, hasout, port; | |||
| 233 | usbd_status err; | |||
| 234 | struct ucom_attach_args uca; | |||
| 235 | ||||
| 236 | DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc)); | |||
| 237 | ||||
| 238 | err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX0, &iface); | |||
| 239 | if (err) { | |||
| ||||
| 240 | printf(": failed to get interface, err=%s\n", | |||
| 241 | usbd_errstr(err)); | |||
| 242 | goto bad; | |||
| 243 | } | |||
| 244 | ||||
| 245 | sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)((struct uvisor_type *)usbd_match_device((const struct usb_devno *)(uvisor_devs), sizeof (uvisor_devs) / sizeof ((uvisor_devs )[0]), sizeof ((uvisor_devs)[0]), (uaa->vendor), (uaa-> product)))->uv_flags; | |||
| 246 | sc->sc_vendor = uaa->vendor; | |||
| 247 | ||||
| 248 | if ((sc->sc_flags & (VISOR0x0002 | PALM40x0001)) == 0) { | |||
| 249 | printf("%s: device is neither visor nor palm\n", | |||
| 250 | sc->sc_dev.dv_xname); | |||
| 251 | goto bad; | |||
| 252 | } | |||
| 253 | ||||
| 254 | id = usbd_get_interface_descriptor(iface); | |||
| 255 | ||||
| 256 | sc->sc_udev = dev; | |||
| 257 | sc->sc_iface = iface; | |||
| 258 | ||||
| 259 | uca.ibufsize = UVISORIBUFSIZE64; | |||
| 260 | uca.obufsize = UVISOROBUFSIZE1024; | |||
| 261 | uca.ibufsizepad = UVISORIBUFSIZE64; | |||
| 262 | uca.opkthdrlen = 0; | |||
| 263 | uca.device = dev; | |||
| 264 | uca.iface = iface; | |||
| 265 | uca.methods = &uvisor_methods; | |||
| 266 | uca.arg = sc; | |||
| 267 | ||||
| 268 | err = uvisor_init(sc, &coninfo, &palmconinfo); | |||
| 269 | if (err
| |||
| 270 | printf("%s: init failed, %s\n", sc->sc_dev.dv_xname, | |||
| 271 | usbd_errstr(err)); | |||
| 272 | goto bad; | |||
| 273 | } | |||
| 274 | ||||
| 275 | if (sc->sc_flags & VISOR0x0002) { | |||
| 276 | sc->sc_numcon = UGETW(coninfo.num_ports)(*(u_int16_t *)(coninfo.num_ports)); | |||
| 277 | if (sc->sc_numcon > UVISOR_MAX_CONN8) | |||
| 278 | sc->sc_numcon = UVISOR_MAX_CONN8; | |||
| 279 | ||||
| 280 | /* Attach a ucom for each connection. */ | |||
| 281 | for (i = 0; i < sc->sc_numcon; ++i) { | |||
| 282 | switch (coninfo.connections[i].port_function_id) { | |||
| 283 | case UVISOR_FUNCTION_GENERIC0x00: | |||
| 284 | uca.info = "Generic"; | |||
| 285 | break; | |||
| 286 | case UVISOR_FUNCTION_DEBUGGER0x01: | |||
| 287 | uca.info = "Debugger"; | |||
| 288 | break; | |||
| 289 | case UVISOR_FUNCTION_HOTSYNC0x02: | |||
| 290 | uca.info = "HotSync"; | |||
| 291 | break; | |||
| 292 | case UVISOR_FUNCTION_REMOTE_FILE_SYS0x04: | |||
| 293 | uca.info = "Remote File System"; | |||
| 294 | break; | |||
| 295 | default: | |||
| 296 | uca.info = "unknown"; | |||
| 297 | break; | |||
| 298 | } | |||
| 299 | port = coninfo.connections[i].port; | |||
| 300 | uca.portno = port; | |||
| 301 | uca.bulkin = port | UE_DIR_IN0x80; | |||
| 302 | uca.bulkout = port | UE_DIR_OUT0x00; | |||
| 303 | /* Verify that endpoints exist. */ | |||
| 304 | hasin = 0; | |||
| 305 | hasout = 0; | |||
| 306 | for (j = 0; j < id->bNumEndpoints; j++) { | |||
| 307 | ed = usbd_interface2endpoint_descriptor(iface, j); | |||
| 308 | if (ed == NULL((void *)0)) | |||
| 309 | break; | |||
| 310 | if (UE_GET_ADDR(ed->bEndpointAddress)((ed->bEndpointAddress) & 0x0f) == port && | |||
| 311 | UE_GET_XFERTYPE(ed->bmAttributes)((ed->bmAttributes) & 0x03) == UE_BULK0x02) { | |||
| 312 | if (UE_GET_DIR(ed->bEndpointAddress)((ed->bEndpointAddress) & 0x80) | |||
| 313 | == UE_DIR_IN0x80) | |||
| 314 | hasin++; | |||
| 315 | else | |||
| 316 | hasout++; | |||
| 317 | } | |||
| 318 | } | |||
| 319 | if (hasin == 1 && hasout == 1) | |||
| 320 | sc->sc_subdevs[i] = config_found_sm(self, &uca, | |||
| 321 | ucomprint, ucomsubmatch); | |||
| 322 | else | |||
| 323 | printf("%s: no proper endpoints for port %d (%d,%d)\n", | |||
| 324 | sc->sc_dev.dv_xname, port, hasin, hasout); | |||
| 325 | } | |||
| 326 | } else { | |||
| 327 | sc->sc_numcon = palmconinfo.num_ports; | |||
| ||||
| 328 | if (sc->sc_numcon > UVISOR_MAX_CONN8) | |||
| 329 | sc->sc_numcon = UVISOR_MAX_CONN8; | |||
| 330 | ||||
| 331 | /* Attach a ucom for each connection. */ | |||
| 332 | for (i = 0; i < sc->sc_numcon; ++i) { | |||
| 333 | /* | |||
| 334 | * XXX this should copy out 4-char string from the | |||
| 335 | * XXX port_function_id, but where would the string go? | |||
| 336 | * XXX uca.info is a const char *, not an array. | |||
| 337 | */ | |||
| 338 | uca.info = "sync"; | |||
| 339 | uca.portno = i; | |||
| 340 | if (palmconinfo.endpoint_numbers_different) { | |||
| 341 | port = palmconinfo.connections[i].end_point_info; | |||
| 342 | uca.bulkin = (port >> 4) | UE_DIR_IN0x80; | |||
| 343 | uca.bulkout = (port & 0xf) | UE_DIR_OUT0x00; | |||
| 344 | } else { | |||
| 345 | port = palmconinfo.connections[i].port; | |||
| 346 | uca.bulkin = port | UE_DIR_IN0x80; | |||
| 347 | uca.bulkout = port | UE_DIR_OUT0x00; | |||
| 348 | } | |||
| 349 | sc->sc_subdevs[i] = config_found_sm(self, &uca, | |||
| 350 | ucomprint, ucomsubmatch); | |||
| 351 | } | |||
| 352 | } | |||
| 353 | ||||
| 354 | return; | |||
| 355 | ||||
| 356 | bad: | |||
| 357 | DPRINTF(("uvisor_attach: ATTACH ERROR\n")); | |||
| 358 | usbd_deactivate(sc->sc_udev); | |||
| 359 | } | |||
| 360 | ||||
| 361 | int | |||
| 362 | uvisor_detach(struct device *self, int flags) | |||
| 363 | { | |||
| 364 | struct uvisor_softc *sc = (struct uvisor_softc *)self; | |||
| 365 | int rv = 0; | |||
| 366 | int i; | |||
| 367 | ||||
| 368 | DPRINTF(("uvisor_detach: sc=%p flags=%d\n", sc, flags)); | |||
| 369 | for (i = 0; i < sc->sc_numcon; i++) { | |||
| 370 | if (sc->sc_subdevs[i] != NULL((void *)0)) { | |||
| 371 | rv |= config_detach(sc->sc_subdevs[i], flags); | |||
| 372 | sc->sc_subdevs[i] = NULL((void *)0); | |||
| 373 | } | |||
| 374 | } | |||
| 375 | ||||
| 376 | return (rv); | |||
| 377 | } | |||
| 378 | ||||
| 379 | usbd_status | |||
| 380 | uvisor_init(struct uvisor_softc *sc, struct uvisor_connection_info *ci, | |||
| 381 | struct uvisor_palm_connection_info *cpi) | |||
| 382 | { | |||
| 383 | usbd_status err = 0; | |||
| 384 | usb_device_request_t req; | |||
| 385 | int actlen; | |||
| 386 | uWord avail; | |||
| 387 | ||||
| 388 | if (sc->sc_flags & PALM40x0001) { | |||
| 389 | DPRINTF(("uvisor_init: getting Palm connection info\n")); | |||
| 390 | req.bmRequestType = UT_READ_VENDOR_ENDPOINT(0x80 | 0x40 | 0x02); | |||
| 391 | req.bRequest = UVISOR_GET_PALM_INFORMATION0x04; | |||
| 392 | USETW(req.wValue, 0)(*(u_int16_t *)(req.wValue) = (0)); | |||
| 393 | USETW(req.wIndex, 0)(*(u_int16_t *)(req.wIndex) = (0)); | |||
| 394 | USETW(req.wLength, UVISOR_GET_PALM_INFORMATION_LEN)(*(u_int16_t *)(req.wLength) = (0x44)); | |||
| 395 | err = usbd_do_request_flags(sc->sc_udev, &req, cpi, | |||
| 396 | USBD_SHORT_XFER_OK0x04, &actlen, USBD_DEFAULT_TIMEOUT5000); | |||
| 397 | if (err == USBD_STALLED && sc->sc_vendor == USB_VENDOR_SONY0x054c) { | |||
| 398 | /* some sony clie devices stall on palm4 requests, | |||
| 399 | * switch them over to using visor. dont do free space | |||
| 400 | * checks on them since they dont like them either. | |||
| 401 | */ | |||
| 402 | DPRINTF(("switching role for CLIE probe\n")); | |||
| 403 | sc->sc_flags = CLIE4(0x0002|0x0004); | |||
| 404 | err = 0; | |||
| 405 | } | |||
| 406 | if (err) | |||
| 407 | return (err); | |||
| 408 | } | |||
| 409 | ||||
| 410 | if (sc->sc_flags & VISOR0x0002) { | |||
| 411 | DPRINTF(("uvisor_init: getting Visor connection info\n")); | |||
| 412 | req.bmRequestType = UT_READ_VENDOR_ENDPOINT(0x80 | 0x40 | 0x02); | |||
| 413 | req.bRequest = UVISOR_GET_CONNECTION_INFORMATION0x03; | |||
| 414 | USETW(req.wValue, 0)(*(u_int16_t *)(req.wValue) = (0)); | |||
| 415 | USETW(req.wIndex, 0)(*(u_int16_t *)(req.wIndex) = (0)); | |||
| 416 | USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE)(*(u_int16_t *)(req.wLength) = (18)); | |||
| 417 | err = usbd_do_request_flags(sc->sc_udev, &req, ci, | |||
| 418 | USBD_SHORT_XFER_OK0x04, &actlen, USBD_DEFAULT_TIMEOUT5000); | |||
| 419 | if (err) | |||
| 420 | return (err); | |||
| 421 | } | |||
| 422 | ||||
| 423 | if (sc->sc_flags & NOFRE0x0004) | |||
| 424 | return (err); | |||
| 425 | ||||
| 426 | DPRINTF(("uvisor_init: getting available bytes\n")); | |||
| 427 | req.bmRequestType = UT_READ_VENDOR_ENDPOINT(0x80 | 0x40 | 0x02); | |||
| 428 | req.bRequest = UVISOR_REQUEST_BYTES_AVAILABLE0x01; | |||
| 429 | USETW(req.wValue, 0)(*(u_int16_t *)(req.wValue) = (0)); | |||
| 430 | USETW(req.wIndex, 5)(*(u_int16_t *)(req.wIndex) = (5)); | |||
| 431 | USETW(req.wLength, sizeof avail)(*(u_int16_t *)(req.wLength) = (sizeof avail)); | |||
| 432 | err = usbd_do_request(sc->sc_udev, &req, &avail); | |||
| 433 | if (err) | |||
| 434 | return (err); | |||
| 435 | DPRINTF(("uvisor_init: avail=%d\n", UGETW(avail))); | |||
| 436 | DPRINTF(("uvisor_init: done\n")); | |||
| 437 | return (err); | |||
| 438 | } | |||
| 439 | ||||
| 440 | void | |||
| 441 | uvisor_close(void *addr, int portno) | |||
| 442 | { | |||
| 443 | struct uvisor_softc *sc = addr; | |||
| 444 | usb_device_request_t req; | |||
| 445 | struct uvisor_connection_info coninfo; /* XXX ? */ | |||
| 446 | int actlen; | |||
| 447 | ||||
| 448 | if (usbd_is_dying(sc->sc_udev)) | |||
| 449 | return; | |||
| 450 | ||||
| 451 | req.bmRequestType = UT_READ_VENDOR_ENDPOINT(0x80 | 0x40 | 0x02); /* XXX read? */ | |||
| 452 | req.bRequest = UVISOR_CLOSE_NOTIFICATION0x02; | |||
| 453 | USETW(req.wValue, 0)(*(u_int16_t *)(req.wValue) = (0)); | |||
| 454 | USETW(req.wIndex, 0)(*(u_int16_t *)(req.wIndex) = (0)); | |||
| 455 | USETW(req.wLength, UVISOR_CONNECTION_INFO_SIZE)(*(u_int16_t *)(req.wLength) = (18)); | |||
| 456 | (void)usbd_do_request_flags(sc->sc_udev, &req, &coninfo, | |||
| 457 | USBD_SHORT_XFER_OK0x04, &actlen, USBD_DEFAULT_TIMEOUT5000); | |||
| 458 | } |