2011-07-13 21:40:15 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2012-10-22 16:31:20 +08:00
|
|
|
* Copyright (C) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
|
2011-07-13 21:40:15 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-07 18:46:04 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-09-03 19:11:36 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2011-07-13 21:40:15 +08:00
|
|
|
#include <bluetooth/bluetooth.h>
|
2012-02-23 04:29:51 +08:00
|
|
|
#include <glib.h>
|
2011-07-13 21:40:15 +08:00
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "adapter.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "storage.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nintendo Wii Remote devices require the bdaddr of the host as pin input for
|
|
|
|
* authentication. This plugin registers a pin-callback and forces this pin
|
|
|
|
* to be used for authentication.
|
|
|
|
*
|
|
|
|
* There are two ways to place the wiimote into discoverable mode.
|
|
|
|
* - Pressing the red-sync button on the back of the wiimote. This module
|
|
|
|
* supports pairing via this method. Auto-reconnect should be possible after
|
|
|
|
* the device was paired once.
|
|
|
|
* - Pressing the 1+2 buttons on the front of the wiimote. This module does
|
|
|
|
* not support this method since this method never enables auto-reconnect.
|
|
|
|
* Hence, pairing is not needed. Use it without pairing if you want.
|
|
|
|
* After connecting the wiimote you should immediately connect to the input
|
|
|
|
* service of the wiimote. If you don't, the wiimote will close the connection.
|
|
|
|
* The wiimote waits about 5 seconds until it turns off again.
|
|
|
|
* Auto-reconnect is only enabled when pairing with the wiimote via the red
|
|
|
|
* sync-button and then connecting to the input service. If you do not connect
|
|
|
|
* to the input service, then auto-reconnect is not enabled.
|
|
|
|
* If enabled, the wiimote connects to the host automatically when any button
|
|
|
|
* is pressed.
|
|
|
|
*/
|
|
|
|
|
2012-10-22 16:31:20 +08:00
|
|
|
static uint16_t wii_ids[][2] = {
|
2013-10-18 22:13:47 +08:00
|
|
|
{ 0x057e, 0x0306 }, /* 1st gen */
|
|
|
|
{ 0x054c, 0x0306 }, /* LEGO wiimote */
|
|
|
|
{ 0x057e, 0x0330 }, /* 2nd gen */
|
2012-10-22 16:31:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *wii_names[] = {
|
2013-10-18 22:13:47 +08:00
|
|
|
"Nintendo RVL-CNT-01", /* 1st gen */
|
|
|
|
"Nintendo RVL-CNT-01-TR", /* 2nd gen */
|
|
|
|
"Nintendo RVL-CNT-01-UC", /* Wii U Pro Controller */
|
|
|
|
"Nintendo RVL-WBC-01", /* Balance Board */
|
2012-10-22 16:31:20 +08:00
|
|
|
};
|
|
|
|
|
2011-07-13 21:40:15 +08:00
|
|
|
static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
|
2013-05-21 21:06:44 +08:00
|
|
|
char *pinbuf, bool *display,
|
|
|
|
unsigned int attempt)
|
2011-07-13 21:40:15 +08:00
|
|
|
{
|
|
|
|
uint16_t vendor, product;
|
2012-02-23 04:29:51 +08:00
|
|
|
char addr[18], name[25];
|
2012-10-22 16:31:20 +08:00
|
|
|
unsigned int i;
|
2011-07-13 21:40:15 +08:00
|
|
|
|
2013-05-09 08:37:56 +08:00
|
|
|
/* Only try the pin code once per device. If it's not correct then it's
|
|
|
|
* an unknown device. */
|
|
|
|
if (attempt > 1)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-05 16:16:58 +08:00
|
|
|
ba2str(device_get_address(device), addr);
|
2011-09-22 23:51:52 +08:00
|
|
|
|
|
|
|
vendor = btd_device_get_vendor(device);
|
|
|
|
product = btd_device_get_product(device);
|
2012-02-23 04:29:51 +08:00
|
|
|
|
|
|
|
device_get_name(device, name, sizeof(name));
|
|
|
|
name[sizeof(name) - 1] = 0;
|
|
|
|
|
2012-10-22 16:31:20 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS(wii_ids); ++i) {
|
|
|
|
if (vendor == wii_ids[i][0] && product == wii_ids[i][1])
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS(wii_names); ++i) {
|
|
|
|
if (g_str_equal(name, wii_names[i]))
|
|
|
|
goto found;
|
2011-07-13 21:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-10-22 16:31:20 +08:00
|
|
|
|
|
|
|
found:
|
|
|
|
DBG("Forcing fixed pin on detected wiimote %s", addr);
|
|
|
|
memcpy(pinbuf, adapter_get_address(adapter), 6);
|
|
|
|
return 6;
|
2011-07-13 21:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int wii_probe(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
btd_adapter_register_pin_cb(adapter, wii_pincb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wii_remove(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
btd_adapter_unregister_pin_cb(adapter, wii_pincb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct btd_adapter_driver wii_driver = {
|
|
|
|
.name = "wiimote",
|
|
|
|
.probe = wii_probe,
|
|
|
|
.remove = wii_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int wii_init(void)
|
|
|
|
{
|
|
|
|
return btd_register_adapter_driver(&wii_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wii_exit(void)
|
|
|
|
{
|
|
|
|
btd_unregister_adapter_driver(&wii_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLUETOOTH_PLUGIN_DEFINE(wiimote, VERSION,
|
|
|
|
BLUETOOTH_PLUGIN_PRIORITY_LOW, wii_init, wii_exit)
|