service: Fix Domains property
[framework/connectivity/connman.git] / src / agent.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <gdbus.h>
31
32 #include "connman.h"
33
34 static DBusConnection *connection = NULL;
35 static guint agent_watch = 0;
36 static gchar *agent_path = NULL;
37 static gchar *agent_sender = NULL;
38
39 static void agent_free(void)
40 {
41         agent_watch = 0;
42
43         g_free(agent_sender);
44         agent_sender = NULL;
45
46         g_free(agent_path);
47         agent_path = NULL;
48 }
49
50 static void agent_disconnect(DBusConnection *connection, void *data)
51 {
52         DBG("data %p", data);
53
54         agent_free();
55 }
56
57 int __connman_agent_register(const char *sender, const char *path)
58 {
59         DBG("sender %s path %s", sender, path);
60
61         if (agent_path != NULL)
62                 return -EEXIST;
63
64         agent_sender = g_strdup(sender);
65         agent_path = g_strdup(path);
66
67         agent_watch = g_dbus_add_disconnect_watch(connection, sender,
68                                                 agent_disconnect, NULL, NULL);
69
70         return 0;
71 }
72
73 int __connman_agent_unregister(const char *sender, const char *path)
74 {
75         DBG("sender %s path %s", sender, path);
76
77         if (agent_path == NULL)
78                 return -ESRCH;
79
80         if (agent_watch > 0)
81                 g_dbus_remove_watch(connection, agent_watch);
82
83         agent_free();
84
85         return 0;
86 }
87
88 static connman_bool_t check_reply_has_dict(DBusMessage *reply)
89 {
90         const char *signature = DBUS_TYPE_ARRAY_AS_STRING
91                 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
92                 DBUS_TYPE_STRING_AS_STRING
93                 DBUS_TYPE_VARIANT_AS_STRING
94                 DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
95
96         if (dbus_message_has_signature(reply, signature) == TRUE)
97                 return TRUE;
98
99         connman_warn("Reply %s to %s from %s has wrong signature %s",
100                         signature,
101                         dbus_message_get_interface(reply),
102                         dbus_message_get_sender(reply),
103                         dbus_message_get_signature(reply));
104
105         return FALSE;
106 }
107
108 struct request_input_reply {
109         struct connman_service *service;
110         authentication_cb_t callback;
111         void *user_data;
112 };
113
114 static void request_input_passphrase_reply(DBusPendingCall *call, void *user_data)
115 {
116         struct request_input_reply *passphrase_reply = user_data;
117         connman_bool_t values_received = FALSE;
118         connman_bool_t wps = FALSE;
119         const char *error = NULL;
120         char *identity = NULL;
121         char *passphrase = NULL;
122         char *wpspin = NULL;
123         char *key;
124         char *name = NULL;
125         int name_len = 0;
126         DBusMessageIter iter, dict;
127         DBusMessage *reply = dbus_pending_call_steal_reply(call);
128
129         if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
130                 error = dbus_message_get_error_name(reply);
131                 goto done;
132         }
133
134         if (check_reply_has_dict(reply) == FALSE)
135                 goto done;
136
137         values_received = TRUE;
138
139         dbus_message_iter_init(reply, &iter);
140         dbus_message_iter_recurse(&iter, &dict);
141         while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
142                 DBusMessageIter entry, value;
143
144                 dbus_message_iter_recurse(&dict, &entry);
145                 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
146                         break;
147
148                 dbus_message_iter_get_basic(&entry, &key);
149
150                 if (g_str_equal(key, "Identity")) {
151                         dbus_message_iter_next(&entry);
152                         if (dbus_message_iter_get_arg_type(&entry)
153                                                         != DBUS_TYPE_VARIANT)
154                                 break;
155                         dbus_message_iter_recurse(&entry, &value);
156                         dbus_message_iter_get_basic(&value, &identity);
157
158                 } else if (g_str_equal(key, "Passphrase")) {
159                         dbus_message_iter_next(&entry);
160                         if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
161                                 break;
162                         dbus_message_iter_recurse(&entry, &value);
163                         dbus_message_iter_get_basic(&value, &passphrase);
164
165                 } else if (g_str_equal(key, "WPS")) {
166                         wps = TRUE;
167
168                         dbus_message_iter_next(&entry);
169                         if (dbus_message_iter_get_arg_type(&entry)
170                                                         != DBUS_TYPE_VARIANT)
171                                 break;
172                         dbus_message_iter_recurse(&entry, &value);
173                         dbus_message_iter_get_basic(&value, &wpspin);
174                         break;
175                 } else if (g_str_equal(key, "Name")) {
176                         dbus_message_iter_next(&entry);
177                         if (dbus_message_iter_get_arg_type(&entry)
178                                                         != DBUS_TYPE_VARIANT)
179                                 break;
180                         dbus_message_iter_recurse(&entry, &value);
181                         dbus_message_iter_get_basic(&value, &name);
182                         name_len = strlen(name);
183                 } else if (g_str_equal(key, "SSID")) {
184                         dbus_message_iter_next(&entry);
185                         if (dbus_message_iter_get_arg_type(&entry)
186                                                         != DBUS_TYPE_VARIANT)
187                                 break;
188                         dbus_message_iter_recurse(&entry, &value);
189                         if (dbus_message_iter_get_arg_type(&value)
190                                                         != DBUS_TYPE_VARIANT)
191                                 break;
192                         if (dbus_message_iter_get_element_type(&value)
193                                                         != DBUS_TYPE_VARIANT)
194                                 break;
195                         dbus_message_iter_get_fixed_array(&value, &name,
196                                                         &name_len);
197                 }
198                 dbus_message_iter_next(&dict);
199         }
200
201 done:
202         passphrase_reply->callback(passphrase_reply->service, values_received,
203                                 name, name_len,
204                                 identity, passphrase,
205                                 wps, wpspin, error,
206                                 passphrase_reply->user_data);
207         connman_service_unref(passphrase_reply->service);
208         dbus_message_unref(reply);
209         dbus_pending_call_unref(call);
210         g_free(passphrase_reply);
211 }
212
213 static void request_input_append_alternates(DBusMessageIter *iter,
214                                                         void *user_data)
215 {
216         const char *str = user_data;
217         char **alternates, **alternative;
218
219         if (str == NULL)
220                 return;
221
222         alternates = g_strsplit(str, ",", 0);
223         if (alternates == NULL)
224                 return;
225
226         for (alternative = alternates; *alternative != NULL; alternative++)
227                 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
228                                                                 alternative);
229
230         g_strfreev(alternates);
231 }
232
233 static void request_input_append_identity(DBusMessageIter *iter,
234                                                         void *user_data)
235 {
236         char *str = "string";
237
238         connman_dbus_dict_append_basic(iter, "Type",
239                                 DBUS_TYPE_STRING, &str);
240         str = "mandatory";
241         connman_dbus_dict_append_basic(iter, "Requirement",
242                                 DBUS_TYPE_STRING, &str);
243 }
244
245 static void request_input_append_passphrase(DBusMessageIter *iter,
246                                                         void *user_data)
247 {
248         struct connman_service *service = user_data;
249         char *value;
250         const char *phase2;
251
252         switch (__connman_service_get_security(service)) {
253         case CONNMAN_SERVICE_SECURITY_WEP:
254                 value = "wep";
255                 break;
256         case CONNMAN_SERVICE_SECURITY_PSK:
257                 value = "psk";
258                 break;
259         case CONNMAN_SERVICE_SECURITY_8021X:
260                 phase2 = __connman_service_get_phase2(service);
261
262                 if (phase2 != NULL && (
263                                 g_str_has_suffix(phase2, "GTC") == TRUE ||
264                                 g_str_has_suffix(phase2, "OTP") == TRUE))
265                         value = "response";
266                 else
267                         value = "passphrase";
268
269                 break;
270         default:
271                 value = "string";
272                 break;
273         }
274         connman_dbus_dict_append_basic(iter, "Type",
275                                 DBUS_TYPE_STRING, &value);
276         value = "mandatory";
277         connman_dbus_dict_append_basic(iter, "Requirement",
278                                 DBUS_TYPE_STRING, &value);
279
280         if (__connman_service_wps_enabled(service) == TRUE) {
281                 connman_dbus_dict_append_array(iter, "Alternates",
282                                         DBUS_TYPE_STRING,
283                                         request_input_append_alternates,
284                                         "WPS");
285         }
286 }
287
288 static void request_input_append_wps(DBusMessageIter *iter, void *user_data)
289 {
290         const char *str = "wpspin";
291
292         connman_dbus_dict_append_basic(iter, "Type",
293                                 DBUS_TYPE_STRING, &str);
294         str = "alternate";
295         connman_dbus_dict_append_basic(iter, "Requirement",
296                                 DBUS_TYPE_STRING, &str);
297 }
298
299 static void request_input_append_name(DBusMessageIter *iter, void *user_data)
300 {
301         const char *str = "string";
302
303         connman_dbus_dict_append_basic(iter, "Type",
304                                 DBUS_TYPE_STRING, &str);
305         str = "mandatory";
306         connman_dbus_dict_append_basic(iter, "Requirement",
307                                 DBUS_TYPE_STRING, &str);
308         connman_dbus_dict_append_array(iter, "Alternates",
309                                 DBUS_TYPE_STRING,
310                                 request_input_append_alternates,
311                                 "SSID");
312 }
313
314 static void request_input_append_ssid(DBusMessageIter *iter, void *user_data)
315 {
316         const char *str = "ssid";
317
318         connman_dbus_dict_append_basic(iter, "Type",
319                                 DBUS_TYPE_STRING, &str);
320         str = "alternate";
321         connman_dbus_dict_append_basic(iter, "Requirement",
322                                 DBUS_TYPE_STRING, &str);
323 }
324
325 static void request_input_append_password(DBusMessageIter *iter,
326                                                         void *user_data)
327 {
328         char *str = "passphrase";
329
330         connman_dbus_dict_append_basic(iter, "Type",
331                                 DBUS_TYPE_STRING, &str);
332         str = "mandatory";
333         connman_dbus_dict_append_basic(iter, "Requirement",
334                                 DBUS_TYPE_STRING, &str);
335 }
336
337 static void request_input_login_reply(DBusPendingCall *call, void *user_data)
338 {
339         struct request_input_reply *username_password_reply = user_data;
340         const char *error = NULL;
341         connman_bool_t values_received = FALSE;
342         char *username = NULL;
343         char *password = NULL;
344         char *key;
345         DBusMessageIter iter, dict;
346         DBusMessage *reply = dbus_pending_call_steal_reply(call);
347
348         if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
349                 error = dbus_message_get_error_name(reply);
350                 goto done;
351         }
352
353         if (check_reply_has_dict(reply) == FALSE)
354                 goto done;
355
356         values_received = TRUE;
357
358         dbus_message_iter_init(reply, &iter);
359         dbus_message_iter_recurse(&iter, &dict);
360         while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
361                 DBusMessageIter entry, value;
362
363                 dbus_message_iter_recurse(&dict, &entry);
364                 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
365                         break;
366
367                 dbus_message_iter_get_basic(&entry, &key);
368
369                 if (g_str_equal(key, "Username")) {
370                         dbus_message_iter_next(&entry);
371                         if (dbus_message_iter_get_arg_type(&entry)
372                                                         != DBUS_TYPE_VARIANT)
373                                 break;
374                         dbus_message_iter_recurse(&entry, &value);
375                         dbus_message_iter_get_basic(&value, &username);
376
377                 } else if (g_str_equal(key, "Password")) {
378                         dbus_message_iter_next(&entry);
379                         if (dbus_message_iter_get_arg_type(&entry) !=
380                                                         DBUS_TYPE_VARIANT)
381                                 break;
382                         dbus_message_iter_recurse(&entry, &value);
383                         dbus_message_iter_get_basic(&value, &password);
384                 }
385
386                 dbus_message_iter_next(&dict);
387         }
388
389 done:
390         username_password_reply->callback(username_password_reply->service,
391                                         values_received, NULL, 0,
392                                         username, password,
393                                         FALSE, NULL, error,
394                                         username_password_reply->user_data);
395         connman_service_unref(username_password_reply->service);
396         dbus_message_unref(reply);
397         g_free(username_password_reply);
398 }
399
400 int __connman_agent_request_passphrase_input(struct connman_service *service,
401                                 authentication_cb_t callback, void *user_data)
402 {
403         DBusMessage *message;
404         const char *path;
405         DBusMessageIter iter;
406         DBusMessageIter dict;
407         DBusPendingCall *call;
408         struct request_input_reply *passphrase_reply;
409
410         if (service == NULL || agent_path == NULL || callback == NULL)
411                 return -ESRCH;
412
413         message = dbus_message_new_method_call(agent_sender, agent_path,
414                                         CONNMAN_AGENT_INTERFACE,
415                                         "RequestInput");
416         if (message == NULL)
417                 return -ENOMEM;
418
419         dbus_message_iter_init_append(message, &iter);
420
421         path = __connman_service_get_path(service);
422         dbus_message_iter_append_basic(&iter,
423                                 DBUS_TYPE_OBJECT_PATH, &path);
424
425         connman_dbus_dict_open(&iter, &dict);
426
427         if (__connman_service_is_hidden(service)) {
428                 connman_dbus_dict_append_dict(&dict, "Name",
429                                         request_input_append_name, NULL);
430                 connman_dbus_dict_append_dict(&dict, "SSID",
431                                         request_input_append_ssid, NULL);
432         }
433
434         if (__connman_service_get_security(service) ==
435                         CONNMAN_SERVICE_SECURITY_8021X) {
436                 connman_dbus_dict_append_dict(&dict, "Identity",
437                                         request_input_append_identity, service);
438         }
439
440         if (__connman_service_get_security(service) !=
441                         CONNMAN_SERVICE_SECURITY_NONE) {
442                 connman_dbus_dict_append_dict(&dict, "Passphrase",
443                                         request_input_append_passphrase, service);
444         }
445
446         if (__connman_service_wps_enabled(service) == TRUE) {
447             connman_dbus_dict_append_dict(&dict, "WPS",
448                                 request_input_append_wps, NULL);
449         }
450
451         connman_dbus_dict_close(&iter, &dict);
452
453         passphrase_reply = g_try_new0(struct request_input_reply, 1);
454         if (passphrase_reply == NULL) {
455                 dbus_message_unref(message);
456                 return -ENOMEM;
457         }
458
459         if (dbus_connection_send_with_reply(connection, message,
460                                                 &call, -1) == FALSE) {
461                 dbus_message_unref(message);
462                 g_free(passphrase_reply);
463                 return -ESRCH;
464         }
465
466         if (call == NULL) {
467                 dbus_message_unref(message);
468                 g_free(passphrase_reply);
469                 return -ESRCH;
470         }
471
472         passphrase_reply->service = connman_service_ref(service);
473         passphrase_reply->callback = callback;
474         passphrase_reply->user_data = user_data;
475
476         dbus_pending_call_set_notify(call, request_input_passphrase_reply,
477                                 passphrase_reply, NULL);
478
479         dbus_message_unref(message);
480
481         return -EIO;
482 }
483
484 int __connman_agent_request_login_input(struct connman_service *service,
485                                 authentication_cb_t callback, void *user_data)
486 {
487         DBusMessage *message;
488         const char *path;
489         DBusMessageIter iter;
490         DBusMessageIter dict;
491         DBusPendingCall *call;
492         struct request_input_reply *username_password_reply;
493
494         if (service == NULL || agent_path == NULL || callback == NULL)
495                 return -ESRCH;
496
497         message = dbus_message_new_method_call(agent_sender, agent_path,
498                                         CONNMAN_AGENT_INTERFACE,
499                                         "RequestInput");
500         if (message == NULL)
501                 return -ENOMEM;
502
503         dbus_message_iter_init_append(message, &iter);
504
505         path = __connman_service_get_path(service);
506         dbus_message_iter_append_basic(&iter,
507                                 DBUS_TYPE_OBJECT_PATH, &path);
508
509         connman_dbus_dict_open(&iter, &dict);
510
511         connman_dbus_dict_append_dict(&dict, "Username",
512                                 request_input_append_identity, service);
513
514         connman_dbus_dict_append_dict(&dict, "Password",
515                                 request_input_append_password, service);
516
517         connman_dbus_dict_close(&iter, &dict);
518
519         username_password_reply = g_try_new0(struct request_input_reply, 1);
520         if (username_password_reply == NULL) {
521                 dbus_message_unref(message);
522                 return -ENOMEM;
523         }
524
525         if (dbus_connection_send_with_reply(connection, message,
526                                                         &call, -1) == FALSE) {
527                 dbus_message_unref(message);
528                 g_free(username_password_reply);
529                 return -ESRCH;
530         }
531
532         if (call == NULL) {
533                 dbus_message_unref(message);
534                 g_free(username_password_reply);
535                 return -ESRCH;
536         }
537
538         username_password_reply->service = connman_service_ref(service);
539         username_password_reply->callback = callback;
540         username_password_reply->user_data = user_data;
541
542         dbus_pending_call_set_notify(call, request_input_login_reply,
543                                                 username_password_reply, NULL);
544
545         dbus_message_unref(message);
546
547         return -EIO;
548 }
549
550 struct request_browser_reply_data {
551         struct connman_service *service;
552         browser_authentication_cb_t callback;
553         void *user_data;
554 };
555
556 static void request_browser_reply(DBusPendingCall *call, void *user_data)
557 {
558         struct request_browser_reply_data *browser_reply_data = user_data;
559         DBusMessage *reply = dbus_pending_call_steal_reply(call);
560         connman_bool_t result = FALSE;
561         const char *error = NULL;
562
563         if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
564                 error = dbus_message_get_error_name(reply);
565                 goto done;
566         }
567
568         result = TRUE;
569
570 done:
571         browser_reply_data->callback(browser_reply_data->service, result,
572                                         error, browser_reply_data->user_data);
573         connman_service_unref(browser_reply_data->service);
574         dbus_message_unref(reply);
575         g_free(browser_reply_data);
576 }
577
578 int __connman_agent_request_browser(struct connman_service *service,
579                                 browser_authentication_cb_t callback,
580                                 const char *url, void *user_data)
581 {
582         struct request_browser_reply_data *browser_reply_data;
583         DBusPendingCall *call;
584         DBusMessage *message;
585         DBusMessageIter iter;
586         const char *path;
587
588         if (service == NULL || agent_path == NULL || callback == NULL)
589                 return -ESRCH;
590
591         if (url == NULL)
592                 url = "";
593
594         message = dbus_message_new_method_call(agent_sender, agent_path,
595                                         CONNMAN_AGENT_INTERFACE,
596                                         "RequestBrowser");
597         if (message == NULL)
598                 return -ENOMEM;
599
600         dbus_message_iter_init_append(message, &iter);
601
602         path = __connman_service_get_path(service);
603         dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
604
605         dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &url);
606
607         browser_reply_data = g_try_new0(struct request_browser_reply_data, 1);
608         if (browser_reply_data == NULL) {
609                 dbus_message_unref(message);
610                 return -ENOMEM;
611         }
612
613         if (dbus_connection_send_with_reply(connection, message,
614                                                         &call, -1) == FALSE) {
615                 dbus_message_unref(message);
616                 g_free(browser_reply_data);
617                 return -ESRCH;
618         }
619
620         if (call == NULL) {
621                 dbus_message_unref(message);
622                 g_free(browser_reply_data);
623                 return -ESRCH;
624         }
625
626         browser_reply_data->service = connman_service_ref(service);
627         browser_reply_data->callback = callback;
628         browser_reply_data->user_data = user_data;
629
630         dbus_pending_call_set_notify(call, request_browser_reply,
631                                                 browser_reply_data, NULL);
632
633         dbus_message_unref(message);
634
635         return -EIO;
636 }
637
638 struct report_error_data {
639         struct connman_service *service;
640         report_error_cb_t callback;
641         void *user_data;
642 };
643
644 static void report_error_reply(DBusPendingCall *call, void *user_data)
645 {
646         struct report_error_data *report_error = user_data;
647         DBusMessage *reply = dbus_pending_call_steal_reply(call);
648         gboolean retry = FALSE;
649         const char *dbus_err;
650
651         if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
652                 dbus_err = dbus_message_get_error_name(reply);
653                 if (dbus_err != NULL &&
654                         strcmp(dbus_err,
655                                 CONNMAN_AGENT_INTERFACE ".Error.Retry") == 0)
656                         retry = TRUE;
657         }
658
659         report_error->callback(report_error->service, retry,
660                         report_error->user_data);
661         connman_service_unref(report_error->service);
662         g_free(report_error);
663         dbus_message_unref(reply);
664         dbus_pending_call_unref(call);
665 }
666
667 int __connman_agent_report_error(struct connman_service *service,
668                                 const char *error,
669                                 report_error_cb_t callback, void *user_data)
670 {
671         DBusMessage *message;
672         DBusMessageIter iter;
673         const char *path;
674         struct report_error_data *report_error;
675         DBusPendingCall *call;
676
677         if (service == NULL || agent_path == NULL || error == NULL ||
678                 callback == NULL)
679                 return -ESRCH;
680
681         message = dbus_message_new_method_call(agent_sender, agent_path,
682                                         CONNMAN_AGENT_INTERFACE,
683                                         "ReportError");
684         if (message == NULL)
685                 return -ENOMEM;
686
687         dbus_message_iter_init_append(message, &iter);
688
689         path = __connman_service_get_path(service);
690         dbus_message_iter_append_basic(&iter,
691                                 DBUS_TYPE_OBJECT_PATH, &path);
692         dbus_message_iter_append_basic(&iter,
693                                 DBUS_TYPE_STRING, &error);
694
695         report_error = g_try_new0(struct report_error_data, 1);
696         if (report_error == NULL) {
697                 dbus_message_unref(message);
698                 return -ENOMEM;
699         }
700
701         if (dbus_connection_send_with_reply(connection, message,
702                                                 &call, -1) == FALSE) {
703                 dbus_message_unref(message);
704                 g_free(report_error);
705                 return -ESRCH;
706         }
707
708         if (call == NULL) {
709                 dbus_message_unref(message);
710                 g_free(report_error);
711                 return -ESRCH;
712         }
713
714         report_error->service = connman_service_ref(service);
715         report_error->callback = callback;
716         report_error->user_data = user_data;
717         dbus_pending_call_set_notify(call, report_error_reply,
718                                 report_error, NULL);
719         dbus_message_unref(message);
720
721         return -EIO;
722 }
723
724 int __connman_agent_init(void)
725 {
726         DBG("");
727
728         connection = connman_dbus_get_connection();
729         if (connection == NULL)
730                 return -1;
731
732         return 0;
733 }
734
735 void __connman_agent_cleanup(void)
736 {
737         DBusMessage *message;
738
739         DBG("");
740
741         if (connection == NULL)
742                 return;
743
744         if (agent_watch > 0)
745                 g_dbus_remove_watch(connection, agent_watch);
746
747         if (agent_path == NULL)
748                 return;
749
750         message = dbus_message_new_method_call(agent_sender, agent_path,
751                                         CONNMAN_AGENT_INTERFACE, "Release");
752         if (message == NULL)
753                 return;
754
755         dbus_message_set_no_reply(message, TRUE);
756
757         g_dbus_send_message(connection, message);
758
759         agent_free();
760
761         dbus_connection_unref(connection);
762 }