annotate src/bluetooth/agent.c @ 3052:95b34f46a231

Comment out MPEG2/MPEG4 determination using the variable id. It is not used anywhere. Code analysis run, unique ID 6nYoHM.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 19:06:20 +0100
parents 223822ba79f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2839
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
1 /*
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
2 * Audacious Bluetooth headset suport plugin
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
3 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
4 * Copyright (c) 2008 Paula Stanciu <paula.stanciu@gmail.com>
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
6 * Copyright (C) 2006-2007 Bastien Nocera <hadess@hadess.net>
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
7 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
8 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
9 * This program is free software; you can redistribute it and/or modify
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
10 * it under the terms of the GNU General Public License as published by
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
12 * (at your option) any later version.
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
13 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
14 * This program is distributed in the hope that it will be useful,
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
17 * GNU General Public License for more details.
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
18 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
19 * You should have received a copy of the GNU General Public License
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
20 * along with this program; if not, write to the Free Software
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
22 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
23 */
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
24
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
25 #include <glib/gprintf.h>
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
26 #include "bluetooth.h"
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
27 #include "agent.h"
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
28 #include "gui.h"
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
29
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
30 #define PASSKEY_AGENT_PATH "/org/bluez/passkey_agent"
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
31 #define AUTH_AGENT_PATH "/org/bluez/auth_agent"
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
32
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
33 static GtkWidget *agent_window = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
34 static GtkWidget *window_box = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
35 static GtkWidget *top_box = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
36 static GtkWidget *middle_box = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
37 static GtkWidget *bottom_box = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
38 static GtkWidget *pair_label = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
39 static GtkWidget *device_label = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
40 static GtkWidget *passkey_entry = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
41 static GtkWidget *ok_button = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
42 static GtkWidget *cancel_button = NULL;
2871
455e6e37feae removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2867
diff changeset
43 static const char* passkey;
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
44 static GList *adapter_list = NULL;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
45 DBusGProxy *pair_obj = NULL;
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
46
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
47 static DBusGConnection *connection;
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
48
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
49 struct adapter_data {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
50 char *path;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
51 int attached;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
52 char *old_mode;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
53 };
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
54
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
55 void ok_button_call()
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
56 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
57 passkey = gtk_entry_get_text(GTK_ENTRY(passkey_entry));
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
58 printf("Key entered : %s\n",passkey);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
59 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
60
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
61 void cancel_button_call()
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
62 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
63 gtk_widget_destroy (agent_window);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
64 agent_window = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
65 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
66
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
67 void gui_agent()
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
68 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
69 if (!agent_window)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
70 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
71 agent_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
72 g_signal_connect (agent_window, "destroy",G_CALLBACK (gtk_widget_destroyed), &agent_window);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
73 window_box = gtk_vbox_new(FALSE,2);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
74 top_box = gtk_vbox_new(FALSE,2);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
75 middle_box = gtk_hbox_new(FALSE,2);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
76 bottom_box = gtk_hbox_new(FALSE,2);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
77
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
78 gtk_container_add(GTK_CONTAINER(agent_window),window_box);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
79 gtk_container_add(GTK_CONTAINER(window_box),top_box);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
80 gtk_container_set_border_width (GTK_CONTAINER(middle_box), 20);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
81 gtk_container_add(GTK_CONTAINER(window_box),middle_box);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
82 gtk_container_add(GTK_CONTAINER(window_box),bottom_box);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
83
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
84 pair_label = gtk_label_new_with_mnemonic("Enter passkey for pairing");
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
85 device_label = gtk_label_new_with_mnemonic(((DeviceData*)(selected_dev->data))->name);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
86
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
87 gtk_container_add(GTK_CONTAINER(top_box),pair_label);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
88 gtk_container_add(GTK_CONTAINER(top_box),device_label);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
89
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
90 passkey_entry = gtk_entry_new();
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
91 gtk_container_add(GTK_CONTAINER(middle_box),passkey_entry);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
92
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
93 ok_button = gtk_button_new_with_mnemonic("OK");
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
94 cancel_button = gtk_button_new_with_mnemonic("Cancel");
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
95 gtk_container_add(GTK_CONTAINER(bottom_box),ok_button);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
96 g_signal_connect(ok_button,"clicked",G_CALLBACK(ok_button_call),NULL);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
97
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
98 gtk_container_add(GTK_CONTAINER(bottom_box),cancel_button);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
99 g_signal_connect(cancel_button,"clicked",G_CALLBACK (cancel_button_call),NULL);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
100
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
101
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
102 gtk_window_set_title(GTK_WINDOW(agent_window),"Pairing passkey request");
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
103 if (!GTK_WIDGET_VISIBLE (agent_window))
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
104 gtk_widget_show_all (agent_window);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
105 else
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
106 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
107 gtk_widget_destroy (agent_window);
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
108 agent_window = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
109 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
110
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
111 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
112
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
113
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
114 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
115 static DBusGConnection *connection;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
116
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
117 static int volatile registered_passkey = 0;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
118 static int volatile registered_auth = 0;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
119
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
120 static gboolean auto_authorize = FALSE;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
121
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
122 typedef enum {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
123 AGENT_ERROR_REJECT
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
124 } AgentError;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
125
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
126 #define AGENT_ERROR (agent_error_quark())
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
127
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
128 #define AGENT_ERROR_TYPE (agent_error_get_type())
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
129
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
130 static GQuark agent_error_quark(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
131 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
132 static GQuark quark = 0;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
133 if (!quark)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
134 quark = g_quark_from_static_string("agent");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
135
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
136 return quark;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
137 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
138
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
139 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
140
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
141 static GType agent_error_get_type(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
142 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
143 static GType etype = 0;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
144 if (etype == 0) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
145 static const GEnumValue values[] = {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
146 ENUM_ENTRY(AGENT_ERROR_REJECT, "Rejected"),
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
147 { 0, 0, 0 }
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
148 };
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
149
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
150 etype = g_enum_register_static("agent", values);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
151 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
152
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
153 return etype;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
154 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
155
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
156 static GList *input_list = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
157
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
158 struct input_data {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
159 char *path;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
160 char *address;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
161 char *service;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
162 char *uuid;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
163 DBusGMethodInvocation *context;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
164 };
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
165
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
166 static gint input_compare(gconstpointer a, gconstpointer b)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
167 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
168 struct input_data *a_data = (struct input_data *) a;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
169 struct input_data *b_data = (struct input_data *) b;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
170
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
171 return g_ascii_strcasecmp(a_data->address, b_data->address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
172 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
173
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
174 static void input_free(struct input_data *input)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
175 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
176
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
177 input_list = g_list_remove(input_list, input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
178
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
179 g_free(input->uuid);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
180 g_free(input->service);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
181 g_free(input->address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
182 g_free(input->path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
183 g_free(input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
184
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
185 // if (g_list_length(input_list) == 0)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
186 // disable_blinking();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
187 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
188
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
189 static void passkey_callback(gint response, gpointer user_data)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
190 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
191 struct input_data *input = user_data;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
192
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
193 if (response == GTK_RESPONSE_ACCEPT) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
194 const char *passkey;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
195 /*!!!!!!!!! hardcoded passkey !!!!!!!!!!!!! to modify*/
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
196 passkey ="0000";
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
197 dbus_g_method_return(input->context, passkey);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
198 } else {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
199 GError *error;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
200 error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
201 "Pairing request rejected");
2867
dc22e3d2e56e fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
202 printf("passkey error\n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
203 dbus_g_method_return_error(input->context, error);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
204 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
205
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
206 input_free(input);
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
207 printf("return\n");
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
208 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
209
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
210
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
211 static void passkey_dialog(const char *path, const char *address,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
212 const gchar *device, DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
213 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
214 struct input_data *input;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
215
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
216 input = g_try_malloc0(sizeof(*input));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
217 if (!input)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
218 return;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
219
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
220 input->path = g_strdup(path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
221 input->address = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
222
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
223 input->context = context;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
224
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
225 passkey_callback(GTK_RESPONSE_ACCEPT,input);
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
226
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
227
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
228 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
229
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
230 static void confirm_dialog(const char *path, const char *address,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
231 const char *value, const gchar *device,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
232 DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
233 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
234 printf("confirm dialog \n");
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
235 struct input_data *input;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
236
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
237 input = g_try_malloc0(sizeof(*input));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
238 if (!input)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
239 return;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
240
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
241 input->path = g_strdup(path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
242 input->address = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
243
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
244 input->context = context;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
245 // g_signal_connect(G_OBJECT(dialog), "response",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
246 // G_CALLBACK(confirm_callback), input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
247
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
248 //enable_blinking();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
249 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
250
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
251 static void auth_dialog(const char *path, const char *address,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
252 const char *service, const char *uuid, const gchar *device,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
253 const gchar *profile, DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
254 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
255 struct input_data *input;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
256
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
257 input = g_try_malloc0(sizeof(*input));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
258 if (!input)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
259 return;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
260
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
261 input->path = g_strdup(path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
262 input->address = g_strdup(address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
263 input->service = g_strdup(service);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
264 input->uuid = g_strdup(uuid);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
265
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
266 input->context = context;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
267
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
268
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
269 /* translators: Whether to grant access to a particular service
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
270 * to the device mentioned */
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
271
2867
dc22e3d2e56e fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
272 /* g_signal_connect(G_OBJECT(dialog), "response",
dc22e3d2e56e fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
273 G_CALLBACK(auth_callback), input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
274
2867
dc22e3d2e56e fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
275 enable_blinking();
dc22e3d2e56e fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
276 */
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
277 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
278
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
279 typedef struct {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
280 GObject parent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
281 } PasskeyAgent;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
282
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
283 typedef struct {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
284 GObjectClass parent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
285 } PasskeyAgentClass;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
286
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
287 static GObjectClass *passkey_agent_parent;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
288
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
289 G_DEFINE_TYPE(PasskeyAgent, passkey_agent, G_TYPE_OBJECT)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
290
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
291 #define PASSKEY_AGENT_OBJECT_TYPE (passkey_agent_get_type())
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
292
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
293 #define PASSKEY_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
294 PASSKEY_AGENT_OBJECT_TYPE, PasskeyAgent))
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
295
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
296 static void passkey_agent_finalize(GObject *obj)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
297 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
298 passkey_agent_parent->finalize(obj);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
299 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
300
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
301 static void passkey_agent_init(PasskeyAgent *obj)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
302 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
303 g_printf("passkeyagent init\n");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
304 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
305
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
306 static void passkey_agent_class_init(PasskeyAgentClass *klass)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
307 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
308 GObjectClass *gobject_class;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
309
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
310 passkey_agent_parent = g_type_class_peek_parent(klass);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
311
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
312 gobject_class = G_OBJECT_CLASS(klass);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
313 gobject_class->finalize = passkey_agent_finalize;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
314 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
315
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
316 static PasskeyAgent *passkey_agent_new(const char *path)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
317 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
318 PasskeyAgent *agent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
319
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
320 agent = g_object_new(PASSKEY_AGENT_OBJECT_TYPE, NULL);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
321
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
322 dbus_g_connection_register_g_object(connection, path, G_OBJECT(agent));
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
323 g_printf("new passkey agent \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
324 return agent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
325 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
326 static gboolean passkey_agent_request(PasskeyAgent *agent,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
327 const char *path, const char *address,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
328 DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
329 {
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
330 printf("passkey_agent request\n");
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
331 DBusGProxy *object;
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
332 const char *adapter = NULL, *name = NULL;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
333 gchar *device, *line;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
334
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
335 object = dbus_g_proxy_new_for_name(connection, "org.bluez",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
336 path, "org.bluez.Adapter");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
337
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
338 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
339 G_TYPE_STRING, &adapter, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
340
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
341 dbus_g_proxy_call(object, "GetRemoteName", NULL,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
342 G_TYPE_STRING, address, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
343 G_TYPE_STRING, &name, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
344
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
345 if (name) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
346 if (g_strrstr(name, address))
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
347 device = g_strdup(name);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
348 else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
349 device = g_strdup_printf("%s (%s)", name, address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
350 } else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
351 device = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
352
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
353 passkey_dialog(path, address, device, context);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
354 /* translators: this is a popup telling you a particular device
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
355 * has asked for pairing */
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
356 line = g_strdup_printf(_("Pairing request for '%s'"), device);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
357 g_free(device);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
358
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
359 /*show_notification(adapter ? adapter : _("Bluetooth device"),
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
360 line, _("Enter passkey"), 0,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
361 G_CALLBACK(notification_closed));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
362 */
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
363 g_free(line);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
364
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
365 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
366 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
367
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
368 static gboolean passkey_agent_confirm(PasskeyAgent *agent,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
369 const char *path, const char *address,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
370 const char *value, DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
371 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
372 printf("passkey agent confirm \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
373 DBusGProxy *object;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
374 const char *adapter = NULL, *name = NULL;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
375 gchar *device, *line;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
376
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
377 object = dbus_g_proxy_new_for_name(connection, "org.bluez",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
378 path, "org.bluez.Adapter");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
379
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
380 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
381 G_TYPE_STRING, &adapter, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
382
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
383 dbus_g_proxy_call(object, "GetRemoteName", NULL,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
384 G_TYPE_STRING, address, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
385 G_TYPE_STRING, &name, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
386
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
387 if (name) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
388 if (g_strrstr(name, address))
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
389 device = g_strdup(name);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
390 else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
391 device = g_strdup_printf("%s (%s)", name, address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
392 } else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
393 device = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
394
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
395 confirm_dialog(path, address, value, device, context);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
396
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
397 line = g_strdup_printf(_("Pairing request for '%s'"), device);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
398 g_free(device);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
399
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
400 /*show_notification(adapter ? adapter : _("Bluetooth device"),
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
401 line, _("Confirm pairing"), 0,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
402 G_CALLBACK(notification_closed));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
403 */
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
404 g_free (line);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
405
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
406 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
407 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
408
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
409 static gboolean passkey_agent_cancel(PasskeyAgent *agent,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
410 const char *path, const char *address, GError **error)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
411 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
412 printf("passkey agent cancel \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
413 GList *list;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
414 GError *result;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
415 struct input_data *input;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
416
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
417 input = g_try_malloc0(sizeof(*input));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
418 if (!input)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
419 return FALSE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
420
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
421 input->path = g_strdup(path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
422 input->address = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
423
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
424 list = g_list_find_custom(input_list, input, input_compare);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
425
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
426 g_free(input->address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
427 g_free(input->path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
428 g_free(input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
429
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
430 if (!list || !list->data)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
431 return FALSE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
432
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
433 input = list->data;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
434
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
435 //close_notification();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
436
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
437 result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
438 "Agent callback canceled");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
439
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
440 dbus_g_method_return_error(input->context, result);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
441
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
442 input_free(input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
443
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
444 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
445 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
446
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
447 static gboolean passkey_agent_release(PasskeyAgent *agent, GError **error)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
448 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
449 printf("pass agent release \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
450 registered_passkey = 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
451
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
452 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
453 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
454
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
455 #include "passkey-agent-glue.h"
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
456
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
457 typedef struct {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
458 GObject parent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
459 } AuthAgent;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
460
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
461 typedef struct {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
462 GObjectClass parent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
463 } AuthAgentClass;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
464
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
465 static GObjectClass *auth_agent_parent;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
466
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
467 G_DEFINE_TYPE(AuthAgent, auth_agent, G_TYPE_OBJECT)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
468
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
469 #define AUTH_AGENT_OBJECT_TYPE (auth_agent_get_type())
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
470
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
471 #define AUTH_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
472 AUTH_AGENT_OBJECT_TYPE, AuthAgent))
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
473
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
474 static void auth_agent_finalize(GObject *obj)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
475 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
476 auth_agent_parent->finalize(obj);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
477 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
478
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
479 static void auth_agent_init(AuthAgent *obj)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
480 {
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
481 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
482
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
483 static void auth_agent_class_init(AuthAgentClass *klass)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
484 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
485 GObjectClass *gobject_class;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
486
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
487 auth_agent_parent = g_type_class_peek_parent(klass);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
488
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
489 gobject_class = G_OBJECT_CLASS(klass);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
490 gobject_class->finalize = auth_agent_finalize;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
491 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
492
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
493 static AuthAgent *auth_agent_new(const char *path)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
494 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
495 AuthAgent *agent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
496
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
497 agent = g_object_new(AUTH_AGENT_OBJECT_TYPE, NULL);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
498
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
499 dbus_g_connection_register_g_object(connection, path, G_OBJECT(agent));
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
500
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
501 return agent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
502 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
503
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
504 static gboolean auth_agent_authorize(PasskeyAgent *agent,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
505 const char *path, const char *address, const char *service,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
506 const char *uuid, DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
507 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
508 printf("auth agent authorize \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
509 DBusGProxy *object;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
510 const char *adapter = NULL, *name = NULL;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
511 gchar *device, *profile, *line;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
512
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
513 if (auto_authorize == TRUE) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
514 dbus_g_method_return(context);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
515 return TRUE;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
516 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
517
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
518 object = dbus_g_proxy_new_for_name(connection, "org.bluez",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
519 path, "org.bluez.Adapter");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
520
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
521 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
522 G_TYPE_STRING, &adapter, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
523
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
524 dbus_g_proxy_call(object, "GetRemoteName", NULL,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
525 G_TYPE_STRING, address, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
526 G_TYPE_STRING, &name, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
527
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
528 object = dbus_g_proxy_new_for_name(connection, "org.bluez",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
529 service, "org.bluez.Service");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
530
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
531 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
532 G_TYPE_STRING, &profile, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
533
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
534 if (name) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
535 if (g_strrstr(name, address))
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
536 device = g_strdup(name);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
537 else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
538 device = g_strdup_printf("%s (%s)", name, address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
539 } else
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
540 device = g_strdup(address);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
541
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
542 auth_dialog(path, address, service, uuid, device, profile, context);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
543
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
544 line = g_strdup_printf(_("Authorization request for %s"), device);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
545 g_free(device);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
546
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
547 /*show_notification(adapter ? adapter : _("Bluetooth device"),
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
548 line, _("Check authorization"), 0,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
549 G_CALLBACK(notification_closed));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
550 */
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
551 g_free(line);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
552
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
553 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
554 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
555
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
556 static gboolean auth_agent_cancel(PasskeyAgent *agent,
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
557 const char *path, const char *address, const char *service,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
558 const char *uuid, DBusGMethodInvocation *context)
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
559 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
560 GList *list;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
561 GError *result;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
562 struct input_data *input;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
563
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
564 input = g_try_malloc0(sizeof(*input));
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
565 if (!input)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
566 return FALSE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
567
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
568 input->path = g_strdup(path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
569 input->address = g_strdup(address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
570 input->service = g_strdup(service);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
571 input->uuid = g_strdup(uuid);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
572
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
573 list = g_list_find_custom(input_list, input, input_compare);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
574
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
575 g_free(input->uuid);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
576 g_free(input->service);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
577 g_free(input->address);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
578 g_free(input->path);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
579 g_free(input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
580
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
581 if (!list || !list->data)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
582 return FALSE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
583
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
584 input = list->data;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
585
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
586 //close_notification();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
587
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
588 result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
589 "Agent callback canceled");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
590
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
591 dbus_g_method_return_error(input->context, result);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
592
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
593 input_free(input);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
594
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
595 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
596 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
597
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
598 static gboolean auth_agent_release(PasskeyAgent *agent, GError **error)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
599 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
600 registered_auth = 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
601
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
602 return TRUE;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
603 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
604
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
605 #include "auth-agent-glue.h"
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
606
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
607 int register_agents(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
608 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
609 DBusGProxy *object;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
610 GError *error = NULL;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
611
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
612 if (registered_passkey && registered_auth)
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
613 return 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
614
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
615 object = dbus_g_proxy_new_for_name(connection, "org.bluez",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
616 "/org/bluez", "org.bluez.Security");
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
617
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
618 if (!registered_passkey) {
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
619
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
620 dbus_g_proxy_call(object, "RegisterDefaultPasskeyAgent",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
621 &error, G_TYPE_STRING, PASSKEY_AGENT_PATH,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
622 G_TYPE_INVALID, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
623
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
624 if (error != NULL) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
625 g_error_free(error);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
626 return -1;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
627 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
628
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
629 registered_passkey = 1;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
630 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
631
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
632 if (!registered_auth) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
633 dbus_g_proxy_call(object, "RegisterDefaultAuthorizationAgent",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
634 &error, G_TYPE_STRING, AUTH_AGENT_PATH,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
635 G_TYPE_INVALID, G_TYPE_INVALID);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
636
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
637 if (error != NULL) {
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
638 g_error_free(error);
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
639 return -1;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
640 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
641
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
642 registered_auth = 1;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
643 }
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
644
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
645 return 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
646 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
647
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
648 void unregister_agents(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
649 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
650 registered_passkey = 0;
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
651 registered_auth = 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
652 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
653
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
654 int setup_agents(DBusGConnection *conn)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
655 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
656 printf("setup agents\n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
657 void *agent;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
658
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
659 connection = dbus_g_connection_ref(conn);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
660
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
661 dbus_g_object_type_install_info(PASSKEY_AGENT_OBJECT_TYPE,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
662 &dbus_glib_passkey_agent_object_info);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
663
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
664 dbus_g_object_type_install_info(AUTH_AGENT_OBJECT_TYPE,
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
665 &dbus_glib_auth_agent_object_info);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
666
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
667 dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error",
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
668 AGENT_ERROR_TYPE);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
669
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
670 agent = passkey_agent_new(PASSKEY_AGENT_PATH);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
671
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
672 agent = auth_agent_new(AUTH_AGENT_PATH);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
673
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
674 return 0;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
675 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
676
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
677 void cleanup_agents(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
678 {
2884
4128ae5633e4 disable play button while pairing - some cleanups
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2882
diff changeset
679 printf("clean up agents \n");
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
680 unregister_agents();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
681
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
682 dbus_g_connection_unref(connection);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
683 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
684
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
685 void show_agents(void)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
686 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
687 printf("show_agents\n");
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
688 //close_notification();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
689
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
690 // g_list_foreach(input_list, show_dialog, NULL);
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
691
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
692 // disable_blinking();
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
693 }
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
694
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
695 void set_auto_authorize(gboolean value)
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
696 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
697 auto_authorize = value;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
698 }
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
699
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
700 static void bonding_created(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
701 const char *address, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
702 {
2896
35773e919dba removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2884
diff changeset
703
2882
15754379dbd5 fixed the remove bonding bug and made it thread safe
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2871
diff changeset
704
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
705 const char *adapter = NULL, *name = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
706 gchar *device, *text;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
707
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
708 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
709 G_TYPE_STRING, &adapter, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
710
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
711 dbus_g_proxy_call(object, "GetRemoteName", NULL,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
712 G_TYPE_STRING, address, G_TYPE_INVALID,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
713 G_TYPE_STRING, &name, G_TYPE_INVALID);
2916
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
714 mcs_handle_t *cfgfile = aud_cfg_db_open();
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
715 aud_cfg_db_set_string(cfgfile,"BLUETOOTH_PLUGIN","bonded", address);
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
716 aud_cfg_db_close(cfgfile);
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
717
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
718 if (name) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
719 if (g_strrstr(name, address))
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
720 device = g_strdup(name);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
721 else
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
722 device = g_strdup_printf("%s (%s)", name, address);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
723 } else
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
724 device = g_strdup(address);
2896
35773e919dba removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2884
diff changeset
725 bonded_dev = g_strdup_printf(address);
35773e919dba removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2884
diff changeset
726
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
727
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
728 text = g_strdup_printf(_("Created bonding with %s"), device);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
729 bonding_finish = 1;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
730 g_free(device);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
731
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
732 g_printf("%s\n",text);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
733 g_free(text);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
734 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
735
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
736 static void bonding_removed(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
737 const char *address, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
738 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
739 const char *adapter = NULL, *name = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
740 gchar *device, *text;
2916
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
741 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
742 G_TYPE_STRING, &adapter, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
743
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
744 dbus_g_proxy_call(object, "GetRemoteName", NULL,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
745 G_TYPE_STRING, address, G_TYPE_INVALID,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
746 G_TYPE_STRING, &name, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
747
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
748 if (name) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
749 if (g_strrstr(name, address))
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
750 device = g_strdup(name);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
751 else
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
752 device = g_strdup_printf("%s (%s)", name, address);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
753 } else
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
754 device = g_strdup(address);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
755
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
756 text = g_strdup_printf(_("Removed bonding with %s"), device);
2916
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
757 mcs_handle_t *cfgfile = aud_cfg_db_open();
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
758 aud_cfg_db_set_string(cfgfile,"BLUETOOTH_PLUGIN","bonded","no");
223822ba79f2 writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2896
diff changeset
759 aud_cfg_db_close(cfgfile);
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
760
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
761 g_free(device);
2896
35773e919dba removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2884
diff changeset
762 printf("bonding removed\n");
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
763
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
764 // show_notification(adapter ? adapter : _("Bluetooth device"),
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
765 // text, NULL, 6000, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
766
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
767 g_free(text);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
768 bonding_finish =0;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
769 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
770
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
771
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
772 static void trust_added(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
773 const char *address, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
774 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
775 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
776
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
777 static void trust_removed(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
778 const char *address, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
779 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
780 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
781
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
782 static void set_new_mode(struct adapter_data *adapter, const char *mode)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
783 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
784 g_free(adapter->old_mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
785
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
786 adapter->old_mode = g_strdup(mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
787 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
788
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
789 static void mode_changed(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
790 const char *mode, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
791 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
792 struct adapter_data *adapter = (struct adapter_data *) user_data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
793 const char *adapter_name = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
794 const char *text;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
795
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
796 if (g_str_equal(mode, "off") == TRUE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
797 set_new_mode(adapter, mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
798 return;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
799 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
800 if (g_str_equal(adapter->old_mode, "off")
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
801 && g_str_equal(mode, "connectable")) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
802 set_new_mode(adapter, mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
803 return;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
804 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
805
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
806
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
807 if (g_str_equal(mode, "off") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
808 text = N_("Device has been switched off");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
809 } else if (g_str_equal(mode, "connectable") != FALSE
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
810 && g_str_equal(adapter->old_mode, "discoverable") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
811 text = N_("Device has been made non-discoverable");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
812 } else if (g_str_equal(mode, "connectable") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
813 text = N_("Device has been made connectable");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
814 } else if (g_str_equal (mode, "discoverable") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
815 text = N_("Device has been made discoverable");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
816 } else if (g_str_equal(mode, "limited") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
817 text = N_("Device has been made limited discoverable");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
818 } else if (g_str_equal(mode, "pairing") != FALSE) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
819 text = N_("Device has been switched into pairing mode");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
820 } else {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
821 set_new_mode(adapter, mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
822 return;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
823 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
824
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
825 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
826 G_TYPE_STRING, &adapter_name, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
827
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
828 /*show_notification(adapter_name ? adapter_name : _("Bluetooth device"),
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
829 _(text), NULL, 3000, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
830 */
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
831
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
832 set_new_mode(adapter, mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
833 }
2871
455e6e37feae removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2867
diff changeset
834 /*
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
835 static void adapter_free(gpointer data, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
836 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
837 struct adapter_data *adapter = data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
838
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
839 adapter_list = g_list_remove(adapter_list, adapter);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
840
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
841 g_free(adapter->path);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
842 g_free(adapter->old_mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
843 g_free(adapter);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
844 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
845
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
846 static void adapter_disable(gpointer data, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
847 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
848 struct adapter_data *adapter = data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
849
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
850 adapter->attached = 0;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
851 }
2871
455e6e37feae removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2867
diff changeset
852 */
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
853
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
854 static gint adapter_compare(gconstpointer a, gconstpointer b)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
855 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
856 const struct adapter_data *adapter = a;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
857 const char *path = b;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
858
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
859 return g_ascii_strcasecmp(adapter->path, path);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
860 }
2871
455e6e37feae removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2867
diff changeset
861 /*
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
862 static void adapter_count(gpointer data, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
863 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
864 struct adapter_data *adapter = data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
865 int *count = user_data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
866
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
867 if (adapter->attached)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
868 (*count)++;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
869 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
870
2871
455e6e37feae removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2867
diff changeset
871 */
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
872
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
873
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
874 void add_bonding(){
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
875 DBusGProxy *object;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
876
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
877 object = dbus_g_proxy_new_for_name(bus, "org.bluez",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
878 "/org/bluez/passkey", "org.bluez.Adapter");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
879
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
880 dbus_g_proxy_add_signal(object, "BondingCreated",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
881 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
882
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
883 dbus_g_proxy_connect_signal(object, "BondingCreated",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
884 G_CALLBACK(bonding_created), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
885
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
886 dbus_g_proxy_add_signal(object, "BondingRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
887 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
888
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
889 dbus_g_proxy_connect_signal(object, "BondingRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
890 G_CALLBACK(bonding_removed), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
891 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
892 static void add_adapter(const char *path)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
893 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
894 GList *list;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
895 DBusGProxy *object;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
896 struct adapter_data *adapter;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
897 const char *old_mode;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
898
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
899 list = g_list_find_custom(adapter_list, path, adapter_compare);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
900 if (list && list->data) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
901 struct adapter_data *adapter = list->data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
902
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
903 adapter->attached = 1;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
904 return;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
905 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
906
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
907 adapter = g_try_malloc0(sizeof(*adapter));
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
908 if (!adapter)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
909 return;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
910
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
911 adapter->path = g_strdup(path);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
912 adapter->attached = 1;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
913
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
914 adapter_list = g_list_append(adapter_list, adapter);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
915
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
916
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
917 object = dbus_g_proxy_new_for_name(bus, "org.bluez",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
918 path, "org.bluez.Adapter");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
919
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
920 dbus_g_proxy_add_signal(object, "ModeChanged",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
921 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
922
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
923 dbus_g_proxy_connect_signal(object, "ModeChanged",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
924 G_CALLBACK(mode_changed), adapter, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
925
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
926 dbus_g_proxy_add_signal(object, "BondingCreated",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
927 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
928
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
929 dbus_g_proxy_connect_signal(object, "BondingCreated",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
930 G_CALLBACK(bonding_created), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
931
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
932 dbus_g_proxy_add_signal(object, "BondingRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
933 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
934
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
935 dbus_g_proxy_connect_signal(object, "BondingRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
936 G_CALLBACK(bonding_removed), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
937
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
938 dbus_g_proxy_add_signal(object, "TrustAdded",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
939 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
940
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
941 dbus_g_proxy_connect_signal(object, "TrustAdded",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
942 G_CALLBACK(trust_added), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
943
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
944 dbus_g_proxy_add_signal(object, "TrustRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
945 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
946
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
947 dbus_g_proxy_connect_signal(object, "TrustRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
948 G_CALLBACK(trust_removed), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
949
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
950 old_mode = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
951 dbus_g_proxy_call(object, "GetMode", NULL,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
952 G_TYPE_INVALID, G_TYPE_STRING,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
953 &old_mode, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
954 if (old_mode != NULL)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
955 set_new_mode(adapter, old_mode);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
956 register_agents();
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
957 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
958
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
959 static void adapter_added(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
960 const char *path, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
961 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
962 printf("adapter added\n");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
963 register_agents();
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
964
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
965 add_adapter(path);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
966 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
967
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
968 static void adapter_removed(DBusGProxy *object,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
969 const char *path, gpointer user_data)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
970 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
971 GList *list;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
972
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
973 list = g_list_find_custom(adapter_list, path, adapter_compare);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
974 if (list && list->data) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
975 struct adapter_data *adapter = list->data;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
976
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
977 adapter->attached = 0;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
978 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
979
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
980 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
981
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
982
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
983 static int setup_manager(void)
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
984 {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
985 DBusGProxy *object;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
986 GError *error = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
987 const gchar **array = NULL;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
988
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
989 object = dbus_g_proxy_new_for_name(bus, "org.bluez",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
990 "/org/bluez", "org.bluez.Manager");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
991
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
992 dbus_g_proxy_add_signal(object, "AdapterAdded",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
993 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
994
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
995 dbus_g_proxy_connect_signal(object, "AdapterAdded",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
996 G_CALLBACK(adapter_added), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
997
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
998 dbus_g_proxy_add_signal(object, "AdapterRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
999 G_TYPE_STRING, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1000
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1001 dbus_g_proxy_connect_signal(object, "AdapterRemoved",
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1002 G_CALLBACK(adapter_removed), NULL, NULL);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1003
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1004 dbus_g_proxy_call(object, "ListAdapters", &error,
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1005 G_TYPE_INVALID, G_TYPE_STRV, &array, G_TYPE_INVALID);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1006
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1007 if (error == NULL) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1008 while (*array) {
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1009 printf("add adapter\n");
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1010 add_adapter(*array);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1011 array++;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1012 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1013 } else
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1014 g_error_free(error);
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1015
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1016 return 0;
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1017 }
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1018
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1019
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
1020 void run_agents()
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
1021 {
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
1022 bonding_finish =0;
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
1023 setup_agents(bus);
2846
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1024 //to add the bounding signals
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1025 // register_agents();
3d7f01edb388 updated pairing agent - added bonding signals
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2845
diff changeset
1026 setup_manager();
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
1027
2840
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
1028 }
50507763fd31 working basic pairing / bounding
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2839
diff changeset
1029