summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/connman/connman-gnome/0004-Handle-WiFi-authentication-using-an-agent.patch
blob: 98230525b6a803aa8ec91098e7490dcfa162971d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
From c742b40860851f1659e801d0a652f854f6783bd1 Mon Sep 17 00:00:00 2001
Message-Id: <c742b40860851f1659e801d0a652f854f6783bd1.1334369310.git.paul.eggleton@linux.intel.com>
In-Reply-To: <cover.1334369310.git.paul.eggleton@linux.intel.com>
References: <cover.1334369310.git.paul.eggleton@linux.intel.com>
From: Paul Eggleton <paul.eggleton@linux.intel.com>
Date: Sat, 14 Apr 2012 02:32:43 +0100
Subject: [PATCH 4/6] Handle WiFi authentication using an agent

Register an agent within the applet which shows an appropriate dialog
when credentials are requested upon connecting to a secured wireless
network.

Thanks to Julien Massot for providing the underlying agent library code.

Upstream-Status: Submitted

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 applet/Makefile.am       |    3 +-
 applet/agent.c           |  209 +++++++++++++++++++++++
 applet/agent.h           |   29 +++
 applet/main.c            |    3 +
 common/Makefile.am       |   13 +-
 common/connman-agent.c   |  426 ++++++++++++++++++++++++++++++++++++++++++++++
 common/connman-agent.h   |   77 +++++++++
 common/connman-agent.xml |   26 +++
 common/marshal.list      |    2 +
 9 files changed, 783 insertions(+), 5 deletions(-)
 create mode 100644 applet/agent.c
 create mode 100644 applet/agent.h
 create mode 100644 common/connman-agent.c
 create mode 100644 common/connman-agent.h
 create mode 100644 common/connman-agent.xml

diff --git a/applet/Makefile.am b/applet/Makefile.am
index fe582ef..2e7c157 100644
--- a/applet/Makefile.am
+++ b/applet/Makefile.am
@@ -2,7 +2,8 @@
 bin_PROGRAMS = connman-applet
 
 connman_applet_SOURCES = main.c \
-	properties.h properties.c status.h status.c
+	properties.h properties.c status.h \
+	status.c agent.h agent.c
 
 connman_applet_LDADD = $(top_builddir)/common/libcommon.a \
 					@GTK_LIBS@ @DBUS_LIBS@
diff --git a/applet/agent.c b/applet/agent.c
new file mode 100644
index 0000000..b12d337
--- /dev/null
+++ b/applet/agent.c
@@ -0,0 +1,209 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Agent implementation based on code from bluez-gnome
+ *
+ *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
+ *  Copyright (C) 2012  Intel Corporation
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <dbus/dbus-glib.h>
+
+#include <connman-agent.h>
+
+#include "agent.h"
+
+struct input_data {
+	gboolean numeric;
+	gpointer request_data;
+	GtkWidget *dialog;
+	GHashTable *entries;
+};
+
+static struct input_data *input_data_inst = NULL;
+
+static void input_free(struct input_data *input)
+{
+	gtk_widget_destroy(input->dialog);
+
+	g_hash_table_destroy(input->entries);
+	
+	if( input_data_inst == input )
+		input_data_inst = NULL;
+	
+	g_free(input);
+}
+
+static void request_input_callback(GtkWidget *dialog,
+				gint response, gpointer user_data)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	GValue *retvalue = NULL;
+	const gchar *text;
+	struct input_data *input = user_data;
+
+	if (response == GTK_RESPONSE_OK) {
+		GHashTable *reply = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+		g_hash_table_iter_init (&iter, input->entries);
+		while (g_hash_table_iter_next (&iter, &key, &value)) {
+			text = gtk_entry_get_text((GtkEntry *)value);
+			if(strlen(text)) {
+				retvalue = g_slice_new0(GValue);
+				g_value_init(retvalue, G_TYPE_STRING);
+				g_value_set_string(retvalue, text);
+				g_hash_table_insert(reply, g_strdup(key), retvalue);
+			}
+		}
+		
+		connman_agent_request_input_set_reply(input->request_data, reply);
+	} else {
+		connman_agent_request_input_abort(input->request_data);
+	}
+
+	input_free(input);
+}
+
+static void show_dialog(gpointer data, gpointer user_data)
+{
+	struct input_data *input = data;
+
+	gtk_widget_show_all(input->dialog);
+
+	gtk_window_present(GTK_WINDOW(input->dialog));
+}
+
+static void request_input_dialog(GHashTable *request,
+						gpointer request_data)
+{
+	GtkWidget *dialog;
+	GtkWidget *label;
+	GtkWidget *table;
+	GtkWidget *entry;
+	struct input_data *input;
+	GHashTableIter iter;
+	gpointer key, value;
+	int elems, i;
+
+	input = g_try_malloc0(sizeof(*input));
+	if (!input)
+		return;
+
+	input->request_data = request_data;
+
+	input->entries = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+	dialog = gtk_dialog_new();
+	gtk_window_set_title(GTK_WINDOW(dialog), _("Connection Manager"));
+	gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
+	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
+	gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
+	gtk_window_set_urgency_hint(GTK_WINDOW(dialog), TRUE);
+	gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
+	input->dialog = dialog;
+
+	gtk_dialog_add_button(GTK_DIALOG(dialog),
+					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	gtk_dialog_add_button(GTK_DIALOG(dialog),
+					GTK_STOCK_OK, GTK_RESPONSE_OK);
+
+	elems = g_hash_table_size(request);
+	table = gtk_table_new(elems+1, 2, FALSE);
+	gtk_table_set_row_spacings(GTK_TABLE(table), 4);
+	gtk_table_set_col_spacings(GTK_TABLE(table), 20);
+	gtk_container_set_border_width(GTK_CONTAINER(table), 12);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
+
+	label = gtk_label_new(_("Please provide some network information:"));
+	gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+	gtk_table_attach(GTK_TABLE(table), label, 0, 2, 0, 1,
+				GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
+
+	g_hash_table_iter_init (&iter, request);
+	i=1;
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		label = gtk_label_new((const char *)key);
+		gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+		gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, i+1,
+					GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
+
+		entry = gtk_entry_new();
+		gtk_entry_set_max_length(GTK_ENTRY(entry), 64);
+		gtk_entry_set_width_chars(GTK_ENTRY(entry), 16);
+		gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
+		gtk_table_attach(GTK_TABLE(table), entry, 1, 2, i, i+1,
+					GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
+		g_hash_table_insert(input->entries, g_strdup(key), entry);
+
+		i++;
+	}
+	
+	input_data_inst = input;
+	
+	g_signal_connect(G_OBJECT(dialog), "response",
+				G_CALLBACK(request_input_callback), input);
+
+	show_dialog(input, NULL);
+}
+
+static void request_input(const char *service_id, 
+                              GHashTable *request, gpointer request_data, gpointer user_data)
+{
+	request_input_dialog(request, request_data);
+}
+
+static gboolean cancel_request(DBusGMethodInvocation *context,
+							gpointer user_data)
+{
+	if( input_data_inst ) {
+		connman_agent_request_input_abort(input_data_inst->request_data);
+
+		input_free(input_data_inst);
+	}
+
+	return TRUE;
+}
+
+int setup_agents(void)
+{
+	ConnmanAgent *agent = connman_agent_new();
+	connman_agent_setup(agent, "/org/gnome/connman/applet");
+
+	connman_agent_set_request_input_func(agent, request_input, agent);
+	connman_agent_set_cancel_func(agent, cancel_request, agent);
+
+	connman_agent_register(agent);
+
+	return 0;
+}
+
+void cleanup_agents(void)
+{
+}
diff --git a/applet/agent.h b/applet/agent.h
new file mode 100644
index 0000000..d85676b
--- /dev/null
+++ b/applet/agent.h
@@ -0,0 +1,29 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Agent implementation based on code from bluez-gnome
+ *
+ *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
+ *  Copyright (C) 2012  Intel Corporation
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+int setup_agents(void);
+void cleanup_agents(void);
diff --git a/applet/main.c b/applet/main.c
index 68a77b1..d06ce60 100644
--- a/applet/main.c
+++ b/applet/main.c
@@ -32,6 +32,7 @@
 
 #include "properties.h"
 #include "status.h"
+#include "agent.h"
 
 static gboolean global_ready = FALSE;
 static gint global_strength = -1;
@@ -132,6 +133,7 @@ static void manager_init(DBusGConnection *connection)
 					"/", "net.connman.Manager");
 
 	properties_create(manager, manager_property_changed, NULL);
+	setup_agents();
 }
 
 static void manager_cleanup(void)
@@ -148,6 +150,7 @@ static void name_owner_changed(DBusGProxy *proxy, const char *name,
 	if (*new != '\0') {
 		status_offline();
 		properties_enable(manager);
+		setup_agents();
 	} else {
 		properties_disable(manager);
 		status_unavailable();
diff --git a/common/Makefile.am b/common/Makefile.am
index ef1267a..5bfff19 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -3,19 +3,21 @@ noinst_LIBRARIES = libcommon.a
 
 libcommon_a_SOURCES = connman-dbus.c connman-dbus.h connman-dbus-glue.h \
 				connman-client.h connman-client.c \
-							instance.h instance.c
+							instance.h instance.c \
+				connman-agent.h connman-agent.c
 
 BUILT_SOURCES = marshal.h marshal.c \
 			connman-dbus-glue.h \
-				instance-glue.h
+				instance-glue.h \
+				connman-agent-glue.h
 
-nodist_libcommon_a_SOURCES = connman-dbus-glue.h instance-glue.h
+nodist_libcommon_a_SOURCES = connman-dbus-glue.h instance-glue.h connman-agent-glue.h
 
 CLEANFILES = $(BUILT_SOURCES)
 
 AM_CFLAGS = @DBUS_CFLAGS@ @GTK_CFLAGS@
 
-EXTRA_DIST = marshal.list instance.xml connman-dbus.xml
+EXTRA_DIST = marshal.list instance.xml connman-dbus.xml connman-agent.xml
 
 MAINTAINERCLEANFILES = Makefile.in
 
@@ -30,3 +32,6 @@ instance-glue.h: instance.xml
 
 connman-dbus-glue.h: connman-dbus.xml
 	$(DBUS_BINDING_TOOL) --prefix=connman --mode=glib-client --output=$@ $<
+
+connman-agent-glue.h: connman-agent.xml
+	$(DBUS_BINDING_TOOL) --prefix=connman_agent --mode=glib-server --output=$@ $<
diff --git a/common/connman-agent.c b/common/connman-agent.c
new file mode 100644
index 0000000..769bf27
--- /dev/null
+++ b/common/connman-agent.c
@@ -0,0 +1,426 @@
+/*
+ *  Connection Manager Agent implementation
+ * 
+ *  Author(s):
+ *  - Julien MASSOT <jmassot@aldebaran-robotics.com>
+ *  - Paul Eggleton <paul.eggleton@linux.intel.com>
+ *
+ *  Copyright (C) 2012 Aldebaran Robotics
+ *  Copyright (C) 2012 Intel Corporation
+ * 
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License version 2.1 as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <stdio.h>
+
+#include "connman-agent.h"
+#include "connman-dbus.h"
+
+#define CONNMAN_AGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+  CONNMAN_TYPE_AGENT, ConnmanAgentPrivate))
+
+typedef enum {
+  AGENT_ERROR_REJECT,
+  AGENT_ERROR_RETRY
+} AgentError;
+
+#define AGENT_ERROR (agent_error_quark())
+
+#define AGENT_ERROR_TYPE (agent_error_get_type())
+
+static GQuark agent_error_quark(void)
+{
+	static GQuark quark = 0;
+	if (!quark)
+		quark = g_quark_from_static_string("Agent");
+
+	return quark;
+}
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+static GType agent_error_get_type(void)
+{
+	static GType etype = 0;
+	if (etype == 0) {
+		static const GEnumValue values[] = {
+			ENUM_ENTRY(AGENT_ERROR_REJECT, "Rejected"),
+			ENUM_ENTRY(AGENT_ERROR_RETRY, "Retry"),
+			{ 0, 0, 0 }
+		};
+
+		etype = g_enum_register_static("Agent", values);
+	}
+
+	return etype;
+}
+
+typedef struct _ConnmanAgentPrivate ConnmanAgentPrivate;
+
+typedef struct _PendingRequest PendingRequest;
+
+struct _PendingRequest {
+	DBusGMethodInvocation *context;
+	ConnmanAgent *agent;
+};
+
+struct _ConnmanAgentPrivate {
+	gchar *busname;
+	gchar *path;
+	DBusGConnection *connection;
+	DBusGProxy *connman_proxy;
+
+	ConnmanAgentRequestInputFunc input_func;
+	gpointer input_data;
+
+	ConnmanAgentCancelFunc cancel_func;
+	gpointer cancel_data;
+
+	ConnmanAgentReleaseFunc release_func;
+	gpointer release_data;
+
+	ConnmanAgentDebugFunc debug_func;
+	gpointer debug_data;
+
+};
+
+G_DEFINE_TYPE(ConnmanAgent, connman_agent, G_TYPE_OBJECT)
+
+static inline void debug(ConnmanAgent *agent, const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	if (priv->debug_func == NULL)
+		return;
+
+	va_start(ap, format);
+
+	if (vsnprintf(str, sizeof(str), format, ap) > 0)
+		priv->debug_func(str, priv->debug_data);
+
+	va_end(ap);
+}
+
+gboolean connman_agent_request_input_set_reply(gpointer request_data, GHashTable *reply)
+{
+	PendingRequest *pendingrequest = request_data;
+
+	if (request_data == NULL)
+		return FALSE;
+
+	dbus_g_method_return(pendingrequest->context, reply);
+
+	g_free(pendingrequest);
+
+	return FALSE;
+}
+
+gboolean connman_agent_request_input_abort(gpointer request_data)
+{
+	PendingRequest *pendingrequest = request_data;
+	GError *result;
+	if (request_data == NULL)
+		return FALSE;
+
+	result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+	                     "Input request rejected");
+	dbus_g_method_return_error(pendingrequest->context, result);
+	g_clear_error(&result);
+	g_free(pendingrequest);
+
+	return FALSE;
+}
+
+static gboolean connman_agent_request_input_cb(const GHashTable *reply, gpointer user_data)
+{
+
+	PendingRequest *pendingrequest = user_data;
+
+	dbus_g_method_return(pendingrequest->context, reply);
+
+	g_free(pendingrequest);
+	return FALSE;
+}
+
+gboolean connman_agent_report_error(ConnmanAgent *agent,
+                                    const char *path, const char *error,
+                                    DBusGMethodInvocation *context)
+{
+	GError *result;
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	debug(agent, "connection %s, reports an error: %s", path, error);
+	result = g_error_new(AGENT_ERROR, AGENT_ERROR_RETRY,
+	                     "Retry");
+	dbus_g_method_return_error(context, result);
+	g_clear_error(&result);
+
+	return FALSE;
+}
+
+gboolean connman_agent_request_input(ConnmanAgent *agent,
+                                     const char *path, GHashTable *fields,
+                                     DBusGMethodInvocation *context)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	const char *sender = dbus_g_method_get_sender(context);
+	char *name = NULL, *type = NULL;
+	char **id = NULL;
+	PendingRequest *pendingrequest = NULL;
+
+	debug(agent, "request %s, sender %s", path, sender);
+
+	if (fields == NULL)
+		return FALSE;
+
+	if (priv->input_func != NULL) {
+		id = g_strsplit(path, "/net/connman/service/", 2);
+		if (g_strv_length(id) == 2) {
+			pendingrequest = g_try_new0(PendingRequest, 1);
+			pendingrequest->context = context;
+			pendingrequest->agent   = agent;
+			priv->input_func(id[1], fields, pendingrequest, priv->input_data);
+		}
+		g_strfreev(id);
+	}
+
+	return FALSE;
+}
+
+gboolean connman_agent_cancel(ConnmanAgent *agent,
+                              DBusGMethodInvocation *context)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	const char *sender = dbus_g_method_get_sender(context);
+	gboolean result = FALSE;
+
+	debug(agent, "Request Canceled %s", sender);
+
+	if (g_str_equal(sender, priv->busname) == FALSE)
+		return FALSE;
+
+	if (priv->cancel_func)
+		result = priv->cancel_func(context, priv->cancel_data);
+
+	return result;
+}
+
+gboolean connman_agent_release(ConnmanAgent *agent,
+                               DBusGMethodInvocation *context)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	const char *sender = dbus_g_method_get_sender(context);
+
+	debug(agent, "agent %p sender %s", agent, sender);
+
+	if (g_str_equal(sender, priv->busname) == FALSE)
+		return FALSE;
+
+	dbus_g_method_return(context);
+
+	return TRUE;
+}
+
+#include "connman-agent-glue.h"
+
+static void connman_agent_init(ConnmanAgent *agent)
+{
+  debug(agent, "agent %p", agent);
+}
+
+static void connman_agent_finalize(GObject *agent)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	if (priv->connman_proxy != NULL) {
+		g_object_unref(priv->connman_proxy);
+	}
+
+	g_free(priv->path);
+	g_free(priv->busname);
+	dbus_g_connection_unref(priv->connection);
+
+	G_OBJECT_CLASS(connman_agent_parent_class)->finalize(agent);
+}
+
+static void connman_agent_class_init(ConnmanAgentClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *) klass;
+
+	g_type_class_add_private(klass, sizeof(ConnmanAgentPrivate));
+
+	object_class->finalize = connman_agent_finalize;
+
+	dbus_g_object_type_install_info(CONNMAN_TYPE_AGENT,
+	                                &dbus_glib_connman_agent_object_info);
+}
+
+ConnmanAgent *connman_agent_new(void)
+{
+	ConnmanAgent *agent;
+	g_type_init();
+
+	agent = CONNMAN_AGENT(g_object_new(CONNMAN_TYPE_AGENT, NULL));
+
+	return agent;
+}
+
+gboolean connman_agent_setup(ConnmanAgent *agent, const char *path)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	DBusGProxy *proxy;
+	GObject *object;
+	GError *error = NULL;
+
+	debug(agent, "agent_setup %p", agent);
+
+	if (priv->path != NULL)
+		return FALSE;
+
+	priv->path = g_strdup(path);
+	priv->connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+	if (error != NULL) {
+		g_printerr("Connecting to system bus failed: %s\n",
+		           error->message);
+		g_error_free(error);
+		return FALSE;
+	}
+
+	proxy = dbus_g_proxy_new_for_name_owner(priv->connection, CONNMAN_SERVICE,
+	                                        CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, NULL);
+
+	g_free(priv->busname);
+
+	if (proxy != NULL) {
+		priv->busname = g_strdup(dbus_g_proxy_get_bus_name(proxy));
+		g_object_unref(proxy);
+	} else
+		priv->busname = NULL;
+
+	object = dbus_g_connection_lookup_g_object(priv->connection, priv->path);
+	if (object != NULL)
+		g_object_unref(object);
+
+	return TRUE;
+}
+
+
+gboolean connman_agent_register(ConnmanAgent *agent)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	DBusGProxy *proxy;
+	GObject *object;
+	GError *error = NULL;
+	gchar *path;
+
+	debug(agent, "register agent %p", agent);
+
+	if (priv->connman_proxy != NULL)
+		return FALSE;
+
+	priv->connman_proxy = dbus_g_proxy_new_for_name_owner(priv->connection, CONNMAN_SERVICE,
+	                                                      CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, NULL);
+
+	g_free(priv->busname);
+
+	priv->busname = g_strdup(dbus_g_proxy_get_bus_name(priv->connman_proxy));
+
+	object = dbus_g_connection_lookup_g_object(priv->connection, priv->path);
+	if (object != NULL)
+		g_object_unref(object);
+
+	dbus_g_connection_register_g_object(priv->connection,
+	                                    priv->path, G_OBJECT(agent));
+
+	dbus_g_proxy_call(priv->connman_proxy, "RegisterAgent", &error,
+	                  DBUS_TYPE_G_OBJECT_PATH, priv->path,
+	                  G_TYPE_INVALID, G_TYPE_INVALID);
+
+	if (error != NULL) {
+		g_printerr("Agent registration failed: %s\n",
+		           error->message);
+		g_error_free(error);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+gboolean connman_agent_unregister(ConnmanAgent *agent)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+	GError *error = NULL;
+
+	debug(agent, "unregister agent %p", agent);
+
+	if (priv->connman_proxy == NULL)
+		return FALSE;
+
+	dbus_g_proxy_call(priv->connman_proxy, "UnregisterAgent", &error,
+	                  DBUS_TYPE_G_OBJECT_PATH, priv->path,
+	                  G_TYPE_INVALID, G_TYPE_INVALID);
+
+	if (error != NULL) {
+		g_printerr("Agent unregistration failed: %s\n",
+		           error->message);
+		g_error_free(error);
+	}
+
+	g_object_unref(priv->connman_proxy);
+	priv->connman_proxy = NULL;
+
+	g_free(priv->path);
+	priv->path = NULL;
+
+	return TRUE;
+}
+
+void connman_agent_set_request_input_func(ConnmanAgent *agent,
+                                          ConnmanAgentRequestInputFunc func, gpointer data)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	priv->input_func = func;
+	priv->input_data = data;
+}
+
+void connman_agent_set_cancel_func(ConnmanAgent *agent,
+                                   ConnmanAgentCancelFunc func, gpointer data)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	priv->cancel_func = func;
+	priv->cancel_data = data;
+}
+
+void connman_agent_set_release_func(ConnmanAgent *agent,
+                                    ConnmanAgentReleaseFunc func, gpointer data)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	priv->release_func = func;
+	priv->release_data = data;
+}
+
+void connman_agent_set_debug_func(ConnmanAgent *agent, ConnmanAgentDebugFunc func, gpointer data)
+{
+	ConnmanAgentPrivate *priv = CONNMAN_AGENT_GET_PRIVATE(agent);
+
+	priv->debug_func = func;
+	priv->debug_data = data;
+}
diff --git a/common/connman-agent.h b/common/connman-agent.h
new file mode 100644
index 0000000..0a1aa92
--- /dev/null
+++ b/common/connman-agent.h
@@ -0,0 +1,77 @@
+/*
+ *  Connection Manager Agent implementation
+ * 
+ *  Author(s):
+ *  - Julien MASSOT <jmassot@aldebaran-robotics.com>
+ *  - Paul Eggleton <paul.eggleton@linux.intel.com>
+ *
+ *  Copyright (C) 2012 Aldebaran Robotics
+ *  Copyright (C) 2012 Intel Corporation
+ * 
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License version 2.1 as published by the Free Software Foundation.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef   	CONNMAN_AGENT_H_
+# define   	CONNMAN_AGENT_H_
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define CONNMAN_TYPE_AGENT (connman_agent_get_type())
+#define CONNMAN_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+                                        CONNMAN_TYPE_AGENT, ConnmanAgent))
+#define CONNMAN_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
+                                        CONNMAN_TYPE_AGENT, ConnmanAgentClass))
+#define CONNMAN_IS_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+                                                        CONNMAN_TYPE_AGENT))
+#define CONNMAN_IS_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \
+                                                        CONNMAN_TYPE_AGENT))
+#define CONNMAN_GET_AGENT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \
+                                        CONNMAN_TYPE_AGENT, ConnmanAgentClass))
+
+typedef struct _ConnmanAgent ConnmanAgent;
+typedef struct _ConnmanAgentClass ConnmanAgentClass;
+
+struct _ConnmanAgent {
+	GObject parent;
+};
+
+struct _ConnmanAgentClass {
+	GObjectClass parent_class;
+};
+
+GType connman_agent_get_type(void);
+
+ConnmanAgent *connman_agent_new(void);
+
+gboolean connman_agent_setup(ConnmanAgent *agent, const char *path);
+
+gboolean connman_agent_register(ConnmanAgent *agent);
+gboolean connman_agent_unregister(ConnmanAgent *agent);
+gboolean connman_agent_request_input_set_reply(gpointer request_data, GHashTable *reply);
+gboolean connman_agent_request_input_abort(gpointer request_data);
+
+typedef void (*ConnmanAgentRequestInputFunc) (const char *service_id, GHashTable *request, gpointer request_data, gpointer user_data);
+typedef gboolean (*ConnmanAgentCancelFunc) (DBusGMethodInvocation *context, gpointer data);
+typedef gboolean (*ConnmanAgentReleaseFunc) (DBusGMethodInvocation *context, gpointer data);
+typedef void (*ConnmanAgentDebugFunc) (const char *str, gpointer user_data);
+
+void connman_agent_set_request_input_func(ConnmanAgent *agent, ConnmanAgentRequestInputFunc func, gpointer data);
+void connman_agent_set_cancel_func(ConnmanAgent *agent, ConnmanAgentCancelFunc func, gpointer data);
+void connman_agent_set_debug_func(ConnmanAgent *agent, ConnmanAgentDebugFunc func, gpointer data);
+
+G_END_DECLS
+#endif 	    /* !CONNMAN_AGENT_H_ */
diff --git a/common/connman-agent.xml b/common/connman-agent.xml
new file mode 100644
index 0000000..ed9ee8b
--- /dev/null
+++ b/common/connman-agent.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/net/connman/Agent">
+  <interface name="net.connman.Agent">
+    <method name="ReportError">
+       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+       <arg type="o" direction="in"/>
+       <arg type="s" direction="in"/>
+    </method>
+
+    <method name="RequestInput">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="o" direction="in"/>
+      <arg type="a{sv}" direction="in"/>
+      <arg type="a{sv}" direction="out"/>
+    </method>
+
+    <method name="Cancel">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+    </method>
+
+    <method name="Release">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+   </method>
+  </interface>
+</node>
diff --git a/common/marshal.list b/common/marshal.list
index 8b174d0..3c6317b 100644
--- a/common/marshal.list
+++ b/common/marshal.list
@@ -1,3 +1,5 @@
 VOID:STRING,BOXED
+VOID:OBJECT,BOXED
+VOID:OBJECT
 VOID:BOXED
 VOID:STRING
-- 
1.7.5.4