[gnome-bluetooth] wizard: Use host address to create the wiimote pin



commit a42beda039770b04a5b2567df0d82652c1a53717
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Dec 5 13:58:54 2009 +0000

    wizard: Use host address to create the wiimote pin
    
    Note that we only support pairing through the "Sync" button,
    not through the 1/2 buttons.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=603845

 wizard/main.c                |   63 ++++++++++++++++++++++++++++++++++++++++++
 wizard/pin-code-database.xml |    7 ++++
 2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/wizard/main.c b/wizard/main.c
index de079d8..637c489 100644
--- a/wizard/main.c
+++ b/wizard/main.c
@@ -679,6 +679,62 @@ set_user_pincode (GtkWidget *button)
 	}
 }
 
+static char *
+get_default_adapter_address (void)
+{
+	BluetoothClient *client;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	gboolean cont;
+
+	client = bluetooth_client_new ();
+	model = bluetooth_client_get_adapter_model (client);
+	cont = gtk_tree_model_get_iter_first(model, &iter);
+
+	while (cont == TRUE) {
+		char *address;
+		gboolean is_default;
+
+		gtk_tree_model_get (model, &iter,
+				    BLUETOOTH_COLUMN_ADDRESS, &address,
+				    BLUETOOTH_COLUMN_DEFAULT, &is_default, -1);
+
+		if (is_default == TRUE) {
+			g_object_unref (model);
+			g_object_unref (client);
+			return address;
+		}
+
+		g_free (address);
+
+		cont = gtk_tree_model_iter_next (model, &iter);
+	}
+
+	g_object_unref (model);
+	g_object_unref (client);
+
+	return NULL;
+}
+
+static char *
+pin_from_adapter (const char *bdaddr)
+{
+	char **items;
+	GString *s;
+	char *ret;
+	int i;
+
+	items = g_strsplit (bdaddr, ":", -1);
+	g_assert (g_strv_length (items) == 6);
+	s = g_string_new ("$");
+	for (i = 5; i >= 0; i--)
+		g_string_append (s, items[i]);
+	g_strfreev (items);
+	ret = g_string_free (s, FALSE);
+
+	return ret;
+}
+
 void
 select_device_changed (BluetoothChooser *selector,
 		       const char *address,
@@ -731,6 +787,13 @@ select_device_changed (BluetoothChooser *selector,
 				pincode = g_strndup(target_pincode, max_digits);
 			else
 				pincode = g_strdup(target_pincode);
+		} else if (g_str_equal (pincode, "WII")) {
+			char *default_adapter;
+
+			g_free (pincode);
+			default_adapter = get_default_adapter_address ();
+			pincode = pin_from_adapter (default_adapter);
+			g_free (default_adapter);
 		} else if (target_ssp == FALSE) {
 			automatic_pincode = TRUE;
 		}
diff --git a/wizard/pin-code-database.xml b/wizard/pin-code-database.xml
index cf57909..b9d886f 100644
--- a/wizard/pin-code-database.xml
+++ b/wizard/pin-code-database.xml
@@ -27,6 +27,10 @@
   connected to and marked as trusted. This is for devices such as mice
   and joypads where there is no encryption
 
+  The special "WII" pin means that the device will use the host's Bluetooth
+  address to compute the pin code as explained at:
+  http://wiibrew.org/wiki/Wiimote#Sync_Button
+
   If a device can use a random PIN but is limited in the number of digits that
   can be entered, then set the "pin" attribute should be set to "max:X" where X
   is the maximum number of digits, for example max:4 for 4 digits.
@@ -71,6 +75,9 @@
 	<!-- Lenovo Ideacenter remote -->
 	<device oui="00:08:1B:" name="lenovo_RC" pin="0000"/>
 
+	<!-- Wiimote -->
+	<device name="Nintendo RVL-CNT-01" pin="WII"/>
+
 <!-- GPS devices -->
 	<device oui="00:0D:B5:" name="TomTom Wireless GPS MkII" pin="0000"/>
 	<device oui="00:0D:B5:" name="GPS-GW-005" pin="0000"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]