Mercurial > audlegacy-plugins
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 |
rev | line source |
---|---|
2839 | 1 /* |
2 * Audacious Bluetooth headset suport plugin | |
3 * | |
4 * Copyright (c) 2008 Paula Stanciu <paula.stanciu@gmail.com> | |
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> | |
6 * Copyright (C) 2006-2007 Bastien Nocera <hadess@hadess.net> | |
7 * | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
22 * | |
23 */ | |
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 | 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 | 132 static GQuark quark = 0; |
133 if (!quark) | |
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 | 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 | 143 static GType etype = 0; |
144 if (etype == 0) { | |
145 static const GEnumValue values[] = { | |
146 ENUM_ENTRY(AGENT_ERROR_REJECT, "Rejected"), | |
147 { 0, 0, 0 } | |
148 }; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
149 |
2841 | 150 etype = g_enum_register_static("agent", values); |
151 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
152 |
2841 | 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 | 159 char *path; |
160 char *address; | |
161 char *service; | |
162 char *uuid; | |
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 | 168 struct input_data *a_data = (struct input_data *) a; |
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 | 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 | 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 | 179 g_free(input->uuid); |
180 g_free(input->service); | |
181 g_free(input->address); | |
182 g_free(input->path); | |
183 g_free(input); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
184 |
2841 | 185 // if (g_list_length(input_list) == 0) |
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 | 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 | 193 if (response == GTK_RESPONSE_ACCEPT) { |
194 const char *passkey; | |
195 /*!!!!!!!!! hardcoded passkey !!!!!!!!!!!!! to modify*/ | |
196 passkey ="0000"; | |
197 dbus_g_method_return(input->context, passkey); | |
198 } else { | |
199 GError *error; | |
200 error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, | |
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 | 203 dbus_g_method_return_error(input->context, error); |
204 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
205 |
2841 | 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 | 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 | 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 | 216 input = g_try_malloc0(sizeof(*input)); |
217 if (!input) | |
218 return; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
219 |
2841 | 220 input->path = g_strdup(path); |
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 | 223 input->context = context; |
224 | |
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 | 231 const char *value, const gchar *device, |
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 | 237 input = g_try_malloc0(sizeof(*input)); |
238 if (!input) | |
239 return; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
240 |
2841 | 241 input->path = g_strdup(path); |
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 | 244 input->context = context; |
245 // g_signal_connect(G_OBJECT(dialog), "response", | |
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 | 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 | 252 const char *service, const char *uuid, const gchar *device, |
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 | 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 | 257 input = g_try_malloc0(sizeof(*input)); |
258 if (!input) | |
259 return; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
260 |
2841 | 261 input->path = g_strdup(path); |
262 input->address = g_strdup(address); | |
263 input->service = g_strdup(service); | |
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 | 266 input->context = context; |
267 | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
268 |
2841 | 269 /* translators: Whether to grant access to a particular service |
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 | 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 | 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 | 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 | 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 | 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 | 308 GObjectClass *gobject_class; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
309 |
2841 | 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 | 312 gobject_class = G_OBJECT_CLASS(klass); |
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 | 318 PasskeyAgent *agent; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
319 |
2841 | 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 | 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 | 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 | 327 const char *path, const char *address, |
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 | 332 const char *adapter = NULL, *name = NULL; |
333 gchar *device, *line; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
334 |
2841 | 335 object = dbus_g_proxy_new_for_name(connection, "org.bluez", |
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 | 338 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID, |
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 | 341 dbus_g_proxy_call(object, "GetRemoteName", NULL, |
342 G_TYPE_STRING, address, G_TYPE_INVALID, | |
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 | 345 if (name) { |
346 if (g_strrstr(name, address)) | |
347 device = g_strdup(name); | |
348 else | |
349 device = g_strdup_printf("%s (%s)", name, address); | |
350 } else | |
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 | 353 passkey_dialog(path, address, device, context); |
354 /* translators: this is a popup telling you a particular device | |
355 * has asked for pairing */ | |
356 line = g_strdup_printf(_("Pairing request for '%s'"), device); | |
357 g_free(device); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
358 |
2841 | 359 /*show_notification(adapter ? adapter : _("Bluetooth device"), |
360 line, _("Enter passkey"), 0, | |
361 G_CALLBACK(notification_closed)); | |
362 */ | |
363 g_free(line); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
364 |
2841 | 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 | 369 const char *path, const char *address, |
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 | 373 DBusGProxy *object; |
374 const char *adapter = NULL, *name = NULL; | |
375 gchar *device, *line; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
376 |
2841 | 377 object = dbus_g_proxy_new_for_name(connection, "org.bluez", |
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 | 380 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID, |
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 | 383 dbus_g_proxy_call(object, "GetRemoteName", NULL, |
384 G_TYPE_STRING, address, G_TYPE_INVALID, | |
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 | 387 if (name) { |
388 if (g_strrstr(name, address)) | |
389 device = g_strdup(name); | |
390 else | |
391 device = g_strdup_printf("%s (%s)", name, address); | |
392 } else | |
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 | 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 | 397 line = g_strdup_printf(_("Pairing request for '%s'"), device); |
398 g_free(device); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
399 |
2841 | 400 /*show_notification(adapter ? adapter : _("Bluetooth device"), |
401 line, _("Confirm pairing"), 0, | |
402 G_CALLBACK(notification_closed)); | |
403 */ | |
404 g_free (line); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
405 |
2841 | 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 | 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 | 413 GList *list; |
414 GError *result; | |
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 | 417 input = g_try_malloc0(sizeof(*input)); |
418 if (!input) | |
419 return FALSE; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
420 |
2841 | 421 input->path = g_strdup(path); |
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 | 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 | 426 g_free(input->address); |
427 g_free(input->path); | |
428 g_free(input); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
429 |
2841 | 430 if (!list || !list->data) |
431 return FALSE; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
432 |
2841 | 433 input = list->data; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
434 |
2841 | 435 //close_notification(); |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
436 |
2841 | 437 result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, |
438 "Agent callback canceled"); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
439 |
2841 | 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 | 442 input_free(input); |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
443 |
2841 | 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 | 450 registered_passkey = 0; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
451 |
2841 | 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 | 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 | 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 | 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 | 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 | 485 GObjectClass *gobject_class; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
486 |
2841 | 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 | 489 gobject_class = G_OBJECT_CLASS(klass); |
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 | 495 AuthAgent *agent; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
496 |
2841 | 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 | 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 | 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 | 505 const char *path, const char *address, const char *service, |
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 | 509 DBusGProxy *object; |
510 const char *adapter = NULL, *name = NULL; | |
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 | 513 if (auto_authorize == TRUE) { |
514 dbus_g_method_return(context); | |
515 return TRUE; | |
516 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
517 |
2841 | 518 object = dbus_g_proxy_new_for_name(connection, "org.bluez", |
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 | 521 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID, |
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 | 524 dbus_g_proxy_call(object, "GetRemoteName", NULL, |
525 G_TYPE_STRING, address, G_TYPE_INVALID, | |
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 | 528 object = dbus_g_proxy_new_for_name(connection, "org.bluez", |
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 | 531 dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID, |
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 | 534 if (name) { |
535 if (g_strrstr(name, address)) | |
536 device = g_strdup(name); | |
537 else | |
538 device = g_strdup_printf("%s (%s)", name, address); | |
539 } else | |
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 | 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 | 544 line = g_strdup_printf(_("Authorization request for %s"), device); |
545 g_free(device); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
546 |
2841 | 547 /*show_notification(adapter ? adapter : _("Bluetooth device"), |
548 line, _("Check authorization"), 0, | |
549 G_CALLBACK(notification_closed)); | |
550 */ | |
551 g_free(line); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
552 |
2841 | 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 | 557 const char *path, const char *address, const char *service, |
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 | 560 GList *list; |
561 GError *result; | |
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 | 564 input = g_try_malloc0(sizeof(*input)); |
565 if (!input) | |
566 return FALSE; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
567 |
2841 | 568 input->path = g_strdup(path); |
569 input->address = g_strdup(address); | |
570 input->service = g_strdup(service); | |
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 | 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 | 575 g_free(input->uuid); |
576 g_free(input->service); | |
577 g_free(input->address); | |
578 g_free(input->path); | |
579 g_free(input); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
580 |
2841 | 581 if (!list || !list->data) |
582 return FALSE; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
583 |
2841 | 584 input = list->data; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
585 |
2841 | 586 //close_notification(); |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
587 |
2841 | 588 result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, |
589 "Agent callback canceled"); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
590 |
2841 | 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 | 593 input_free(input); |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
594 |
2841 | 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 | 600 registered_auth = 0; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
601 |
2841 | 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 | 609 DBusGProxy *object; |
610 GError *error = NULL; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
611 |
2841 | 612 if (registered_passkey && registered_auth) |
613 return 0; | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
614 |
2841 | 615 object = dbus_g_proxy_new_for_name(connection, "org.bluez", |
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 | 618 if (!registered_passkey) { |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
619 |
2841 | 620 dbus_g_proxy_call(object, "RegisterDefaultPasskeyAgent", |
621 &error, G_TYPE_STRING, PASSKEY_AGENT_PATH, | |
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 | 624 if (error != NULL) { |
625 g_error_free(error); | |
626 return -1; | |
627 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
628 |
2841 | 629 registered_passkey = 1; |
630 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
631 |
2841 | 632 if (!registered_auth) { |
633 dbus_g_proxy_call(object, "RegisterDefaultAuthorizationAgent", | |
634 &error, G_TYPE_STRING, AUTH_AGENT_PATH, | |
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 | 637 if (error != NULL) { |
638 g_error_free(error); | |
639 return -1; | |
640 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
641 |
2841 | 642 registered_auth = 1; |
643 } | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
644 |
2841 | 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 | 650 registered_passkey = 0; |
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 | 657 void *agent; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
658 |
2841 | 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 | 661 dbus_g_object_type_install_info(PASSKEY_AGENT_OBJECT_TYPE, |
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 | 664 dbus_g_object_type_install_info(AUTH_AGENT_OBJECT_TYPE, |
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 | 667 dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error", |
668 AGENT_ERROR_TYPE); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
669 |
2841 | 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 | 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 | 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 | 680 unregister_agents(); |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
681 |
2841 | 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 | 687 printf("show_agents\n"); |
688 //close_notification(); | |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff
changeset
|
689 |
2841 | 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 | 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 | 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 | 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 |