hid2hci.c revision 4b6769f61206e90850aff8a30e8e93fbfcc18673
/*
* hid2hci : switch the radio on devices that support
* it from HID to HCI and back
*
* Copyright (C) 2003-2009 Marcel Holtmann <marcel@holtmann.org>
* Copyright (C) 2008-2009 Mario Limonciello <mario_limonciello@dell.com>
* Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <usb.h>
#include "libudev.h"
#include "libudev-private.h"
enum mode {
HCI = 0,
HID = 1,
};
{
int err;
if (err == 0) {
err = -1;
} else {
err = 0;
}
return err;
}
{
struct hiddev_report_info rinfo;
struct hiddev_usage_ref uref;
unsigned int i;
int err;
for (i = 0; i < size; i++) {
uref.field_index = 0;
uref.usage_index = i;
if (err < 0)
return err;
}
return err;
}
static int hid_switch_logitech(const char *filename)
{
int fd;
int err = -1;
if (fd < 0)
return err;
if (err < 0)
goto out;
if (err < 0)
goto out;
if (err < 0)
goto out;
out:
return err;
}
{
int err;
switch (mode) {
case HCI:
break;
case HID:
break;
}
/* Don't need to check return, as might not be in use */
if (usb_claim_interface(dev, 0) < 0)
return -EIO;
if (err == 0) {
err = -1;
} else {
err = 0;
}
return err;
}
/*
* The braindead libusb needs to scan and open all devices, just to
* to find the device we already have. This needs to be fixed in libusb
* or it will be ripped out and we carry our own code.
*/
{
const char *str;
int busnum;
int devnum;
return NULL;
return NULL;
usb_init();
struct usb_device *dev;
continue;
return dev;
}
}
return NULL;
}
{
struct usb_device *dev;
struct udev_device *udev_parent;
char str[UTIL_NAME_SIZE];
struct udev_enumerate *enumerate;
struct udev_list_entry *entry;
if (sibling_intf == NULL) {
return NULL;
}
/* find matching sibling of the current usb_device, they share the same hub */
if (udev_parent == NULL)
return NULL;
return NULL;
/* match all childs of the parent */
/* match the specified interface */
struct udev_device *udev_device;
if (udev_device != NULL) {
/* get the usb_device of the usb_interface we matched */
if (udev_parent == NULL)
continue;
/* only look at the first matching device */
break;
}
}
return handle;
}
{
if (error)
else
printf("hid2hci - Bluetooth HID to HCI mode switching utility\n\n");
printf("Usage: hid2hci [options]\n"
" --mode= mode to switch to [hid|hci] (default hci)\n"
" --devpath= sys device path\n"
" --method= method to use to switch [csr|logitech-hid|dell]\n"
" --find-sibling-intf= find the sibling device with 00:00:00 (class:subclass:prot)\n"
" --help\n\n");
}
{
{ }
};
enum method {
} method = METHOD_UNDEF;
char syspath[UTIL_PATH_SIZE];
const char *sibling_intf = NULL;
int err = -1;
int rc = 1;
for (;;) {
int option;
if (option == -1)
break;
switch (option) {
case 'm':
} else {
usage("error: undefined radio mode\n");
exit(1);
}
break;
case 'p':
break;
case 'M':
method = METHOD_CSR;
} else {
usage("error: undefined switching method\n");
exit(1);
}
break;
case 'I':
break;
case 'h':
default:
exit(1);
}
}
usage("error: --devpath= and --method= must be defined\n");
exit(1);
}
goto exit;
goto exit;
}
switch (method) {
case METHOD_CSR:
case METHOD_DELL: {
struct udev_device *dev;
struct usb_dev_handle *handle;
const char *type;
/* get the parent usb_device if needed */
goto exit;
}
}
goto exit;
}
break;
}
case METHOD_LOGITECH_HID: {
const char *device;
goto exit;
}
break;
}
default:
break;
}
if (err < 0)
exit:
return rc;
}