3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011 David Herrmann <dh.herrmann@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <bluetooth/bluetooth.h>
38 * Nintendo Wii Remote devices require the bdaddr of the host as pin input for
39 * authentication. This plugin registers a pin-callback and forces this pin
40 * to be used for authentication.
42 * There are two ways to place the wiimote into discoverable mode.
43 * - Pressing the red-sync button on the back of the wiimote. This module
44 * supports pairing via this method. Auto-reconnect should be possible after
45 * the device was paired once.
46 * - Pressing the 1+2 buttons on the front of the wiimote. This module does
47 * not support this method since this method never enables auto-reconnect.
48 * Hence, pairing is not needed. Use it without pairing if you want.
49 * After connecting the wiimote you should immediately connect to the input
50 * service of the wiimote. If you don't, the wiimote will close the connection.
51 * The wiimote waits about 5 seconds until it turns off again.
52 * Auto-reconnect is only enabled when pairing with the wiimote via the red
53 * sync-button and then connecting to the input service. If you do not connect
54 * to the input service, then auto-reconnect is not enabled.
55 * If enabled, the wiimote connects to the host automatically when any button
59 static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
60 char *pinbuf, gboolean *display)
62 uint16_t vendor, product;
64 char addr[18], name[25];
66 adapter_get_address(adapter, &sba);
67 device_get_address(device, &dba, NULL);
70 vendor = btd_device_get_vendor(device);
71 product = btd_device_get_product(device);
73 device_get_name(device, name, sizeof(name));
74 name[sizeof(name) - 1] = 0;
76 if (g_str_equal(name, "Nintendo RVL-CNT-01") ||
77 (vendor == 0x057e && product == 0x0306)) {
78 DBG("Forcing fixed pin on detected wiimote %s", addr);
79 memcpy(pinbuf, &sba, 6);
86 static int wii_probe(struct btd_adapter *adapter)
88 btd_adapter_register_pin_cb(adapter, wii_pincb);
93 static void wii_remove(struct btd_adapter *adapter)
95 btd_adapter_unregister_pin_cb(adapter, wii_pincb);
98 static struct btd_adapter_driver wii_driver = {
101 .remove = wii_remove,
104 static int wii_init(void)
106 return btd_register_adapter_driver(&wii_driver);
109 static void wii_exit(void)
111 btd_unregister_adapter_driver(&wii_driver);
114 BLUETOOTH_PLUGIN_DEFINE(wiimote, VERSION,
115 BLUETOOTH_PLUGIN_PRIORITY_LOW, wii_init, wii_exit)