/* $Id: hid2hci.c,v 1.1 2006/11/29 14:40:01 fun Exp $ */ /* * Copyright (c) 2006 FUKAUMI Naoki. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { struct usb_device_info udi; struct usb_ctl_request ucr; int ugen_fd; if (argc != 2) { printf("usage: %s device\n", argv[0]); return 0; } ugen_fd = open(argv[1], O_WRONLY, 0); if (ugen_fd == -1) err(1, "%s", argv[1]); if (ioctl(ugen_fd, USB_GET_DEVICEINFO, &udi) == -1) { close(ugen_fd); err(1, "USB_GET_DEVICEINFO"); } switch (udi.udi_vendorNo) { case 0x0458: /* KYE Systems */ case 0x05ac: /* Apple Computer */ case 0x0a12: /* Cambridge Silicon Radio */ if (udi.udi_productNo == 0x1000) break; /* FALLTHROUGH */ default: close(ugen_fd); printf("unknown device: %s(0x%04x), %s(0x%04x)\n", udi.udi_vendor, udi.udi_vendorNo, udi.udi_product, udi.udi_productNo); return 0; /* NOTREACHED */ } memset(&ucr, 0, sizeof(ucr)); ucr.ucr_request.bmRequestType = UT_WRITE_VENDOR_DEVICE; USETW(ucr.ucr_request.wValue, 0); /* 0: HID2HCI, 1: HCI2HID */ if (ioctl(ugen_fd, USB_DO_REQUEST, &ucr) == -1) { close(ugen_fd); err(1, "USB_DO_REQUEST"); } close(ugen_fd); return 0; }