Skip to content

Latest commit

 

History

History
966 lines (860 loc) · 33.8 KB

usb_moded-dbus.c

File metadata and controls

966 lines (860 loc) · 33.8 KB
 
Mar 22, 2011
Mar 22, 2011
1
/**
Aug 24, 2018
Aug 24, 2018
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
* @file usb_moded-dbus.c
*
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
* Copyright (C) 2012-2018 Jolla. All rights reserved.
*
* @author: Philippe De Swert <philippe.de-swert@nokia.com>
* @author: Philippe De Swert <phdeswer@lumi.maa>
* @author: Philippe De Swert <philippedeswert@gmail.com>
* @author: Philippe De Swert <philippe.deswert@jollamobile.com>
* @author: Vesa Halttunen <vesa.halttunen@jollamobile.com>
* @author: Slava Monich <slava.monich@jolla.com>
* @author: Martin Jones <martin.jones@jollamobile.com>
* @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
* @author: Andrew den Exter <andrew.den.exter@jolla.com>
* @author: Andrew den Exter <andrew.den.exter@jollamobile.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* 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 Lesser 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
*/
Mar 22, 2011
Mar 22, 2011
32
33
#include "usb_moded-dbus-private.h"
Sep 5, 2018
Sep 5, 2018
34
Sep 11, 2011
Sep 11, 2011
35
#include "usb_moded-config-private.h"
Sep 5, 2018
Sep 5, 2018
36
#include "usb_moded-control.h"
Sep 5, 2018
Sep 5, 2018
37
38
39
40
41
42
43
44
#include "usb_moded-log.h"
#include "usb_moded-modes.h"
#include "usb_moded-network.h"
#include <stdlib.h>
#include <string.h>
#include <dbus/dbus-glib-lowlevel.h>
Mar 22, 2011
Mar 22, 2011
45
Aug 24, 2018
Aug 24, 2018
46
47
48
49
/* ========================================================================= *
* Constants
* ========================================================================= */
Oct 18, 2016
Oct 18, 2016
50
51
52
53
#define INIT_DONE_INTERFACE "com.nokia.startup.signal"
#define INIT_DONE_SIGNAL "init_done"
#define INIT_DONE_MATCH "type='signal',interface='"INIT_DONE_INTERFACE"',member='"INIT_DONE_SIGNAL"'"
Aug 24, 2018
Aug 24, 2018
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
/* ========================================================================= *
* Prototypes
* ========================================================================= */
/* -- umdbus -- */
static void umdbus_send_config_signal (const char *section, const char *key, const char *value);
static DBusHandlerResult umdbus_msg_handler (DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data);
DBusConnection *umdbus_get_connection (void);
gboolean umdbus_init_connection (void);
gboolean umdbus_init_service (void);
static void umdbus_cleanup_service (void);
void umdbus_cleanup (void);
static int umdbus_send_signal_ex (const char *signal_type, const char *content);
int umdbus_send_state_signal (const char *state_ind);
int umdbus_send_error_signal (const char *error);
int umdbus_send_supported_modes_signal (const char *supported_modes);
int umdbus_send_available_modes_signal (const char *available_modes);
int umdbus_send_hidden_modes_signal (const char *hidden_modes);
int umdbus_send_whitelisted_modes_signal(const char *whitelist);
static void umdbus_get_name_owner_cb (DBusPendingCall *pc, void *aptr);
gboolean umdbus_get_name_owner_async (const char *name, usb_moded_get_name_owner_fn cb, DBusPendingCall **ppc);
/* ========================================================================= *
* Data
* ========================================================================= */
Sep 5, 2018
Sep 5, 2018
81
82
static DBusConnection *umdbus_connection = NULL;
static gboolean umdbus_service_name_acquired = FALSE;
Nov 7, 2016
Nov 7, 2016
83
Nov 3, 2016
Nov 3, 2016
84
/** Introspect xml format string for parents of USB_MODE_OBJECT */
Sep 5, 2018
Sep 5, 2018
85
static const char umdbus_introspect_template[] =
Nov 3, 2016
Nov 3, 2016
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node name=\"%s\">\n"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg direction=\"out\" name=\"data\" type=\"s\"/>\n"
" </method>\n"
" </interface>\n"
" <interface name=\"org.freedesktop.DBus.Peer\">\n"
" <method name=\"Ping\"/>\n"
" <method name=\"GetMachineId\">\n"
" <arg direction=\"out\" name=\"machine_uuid\" type=\"s\" />\n"
" </method>\n"
" </interface>\n"
" <node name=\"%s\"/>\n"
"</node>\n";
/** Introspect xml data for object path USB_MODE_OBJECT */
Sep 5, 2018
Sep 5, 2018
103
static const char umdbus_introspect_usbmoded[] =
Nov 3, 2016
Nov 3, 2016
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
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node name=\"" USB_MODE_OBJECT "\">\n"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg name=\"xml\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" </interface>\n"
" <interface name=\"org.freedesktop.DBus.Peer\">\n"
" <method name=\"Ping\"/>\n"
" <method name=\"GetMachineId\">\n"
" <arg direction=\"out\" name=\"machine_uuid\" type=\"s\" />\n"
" </method>\n"
" </interface>\n"
" <interface name=\"" USB_MODE_INTERFACE "\">\n"
" <method name=\"" USB_MODE_STATE_REQUEST "\">\n"
" <arg name=\"mode\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_STATE_SET "\">\n"
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"mode\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_CONFIG_SET "\">\n"
" <arg name=\"config\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"config\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_NETWORK_SET "\">\n"
" <arg name=\"key\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"value\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"key\" type=\"s\" direction=\"out\"/>\n"
" <arg name=\"value\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_NETWORK_GET "\">\n"
" <arg name=\"key\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"key\" type=\"s\" direction=\"out\"/>\n"
" <arg name=\"value\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_CONFIG_GET "\">\n"
" <arg name=\"mode\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_LIST "\">\n"
" <arg name=\"modes\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
Aug 11, 2017
Aug 11, 2017
147
148
149
150
151
" <method name=\"" USB_MODE_AVAILABLE_MODES_GET "\">\n"
" <arg name=\"modes\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"" USB_MODE_WHITELISTED_MODES_GET "\">\n"
" <arg name=\"modes\" type=\"s\" direction=\"out\"/>\n"
Aug 24, 2018
Aug 24, 2018
152
" </method>\n"
Aug 11, 2017
Aug 11, 2017
153
154
155
156
157
158
159
" <method name=\"" USB_MODE_WHITELISTED_MODES_SET "\">"
" <arg name=\"modes\" type=\"s\" direction=\"in\"/>"
" </method>"
" <method name=\"" USB_MODE_WHITELISTED_SET "\">"
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>"
" <arg name=\"whitelisted\" type=\"b\" direction=\"in\"/>"
" </method>"
Nov 3, 2016
Nov 3, 2016
160
161
162
163
164
165
166
167
168
169
" <method name=\"" USB_MODE_RESCUE_OFF "\"/>\n"
" <signal name=\"" USB_MODE_SIGNAL_NAME "\">\n"
" <arg name=\"mode\" type=\"s\"/>\n"
" </signal>\n"
" <signal name=\"" USB_MODE_ERROR_SIGNAL_NAME "\">\n"
" <arg name=\"error\" type=\"s\"/>\n"
" </signal>\n"
" <signal name=\"" USB_MODE_SUPPORTED_MODES_SIGNAL_NAME "\">\n"
" <arg name=\"modes\" type=\"s\"/>\n"
" </signal>\n"
Aug 11, 2017
Aug 11, 2017
170
171
172
173
174
175
" <signal name=\"" USB_MODE_AVAILABLE_MODES_SIGNAL_NAME "\">\n"
" <arg name=\"modes\" type=\"s\">\n"
" </signal>\n"
" <signal name=\"" USB_MODE_WHITELISTED_MODES_SIGNAL_NAME "\">\n"
" <arg name=\"modes\" type=\"s\">\n"
" </signal>\n"
Nov 3, 2016
Nov 3, 2016
176
177
178
179
180
181
182
183
" <signal name=\"" USB_MODE_CONFIG_SIGNAL_NAME "\">\n"
" <arg name=\"section\" type=\"s\"/>\n"
" <arg name=\"key\" type=\"s\"/>\n"
" <arg name=\"value\" type=\"s\"/>\n"
" </signal>\n"
" </interface>\n"
"</node>\n";
Aug 24, 2018
Aug 24, 2018
184
185
186
187
188
189
190
191
/* ========================================================================= *
* Functions
* ========================================================================= */
/**
* Issues "sig_usb_config_ind" signal.
*/
static void umdbus_send_config_signal(const char *section, const char *key, const char *value)
Mar 22, 2011
Mar 22, 2011
192
{
Sep 5, 2018
Sep 5, 2018
193
DBusMessage* msg = 0;
Aug 24, 2018
Aug 24, 2018
194
Sep 5, 2018
Sep 5, 2018
195
196
197
198
199
200
201
if( !section || !key || !value ) {
log_err("config notification with NULL %s",
!section ? "section" : !key ? "key" : value);
goto EXIT;
}
if( !umdbus_service_name_acquired ) {
Aug 24, 2018
Aug 24, 2018
202
203
log_err("config notification without service: [%s] %s=%s",
section, key, value);
Sep 5, 2018
Sep 5, 2018
204
goto EXIT;
Aug 24, 2018
Aug 24, 2018
205
}
Sep 5, 2018
Sep 5, 2018
206
207
208
209
210
if( !umdbus_connection ) {
log_err("config notification without connection: [%s] %s=%s",
section, key, value);
goto EXIT;
Aug 24, 2018
Aug 24, 2018
211
}
Sep 5, 2018
Sep 5, 2018
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
log_debug("broadcast signal %s(%s, %s, %s)\n", USB_MODE_CONFIG_SIGNAL_NAME, section, key, value);
msg = dbus_message_new_signal(USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_CONFIG_SIGNAL_NAME);
if( !msg )
goto EXIT;
dbus_message_append_args(msg, DBUS_TYPE_STRING, &section,
DBUS_TYPE_STRING, &key,
DBUS_TYPE_STRING, &value,
DBUS_TYPE_INVALID);
dbus_connection_send(umdbus_connection, msg, NULL);
EXIT:
if( msg )
dbus_message_unref(msg);
Aug 24, 2018
Aug 24, 2018
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
}
static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
DBusMessage *reply = 0;
const char *interface = dbus_message_get_interface(msg);
const char *member = dbus_message_get_member(msg);
const char *object = dbus_message_get_path(msg);
int type = dbus_message_get_type(msg);
(void)user_data;
if(!interface || !member || !object) goto EXIT;
log_debug("DBUS %s %s.%s from %s",
dbus_message_type_to_string(type),
interface, member,
dbus_message_get_sender(msg) ?: "N/A");
if( type == DBUS_MESSAGE_TYPE_SIGNAL )
{
if( !strcmp(interface, INIT_DONE_INTERFACE) && !strcmp(member, INIT_DONE_SIGNAL) ) {
/* Update the cached state value */
usbmoded_set_init_done(true);
/* Auto-disable rescue mode when bootup is finished */
Sep 5, 2018
Sep 5, 2018
255
256
if( usbmoded_get_rescue_mode() ) {
usbmoded_set_rescue_mode(false);
Aug 24, 2018
Aug 24, 2018
257
258
259
260
261
262
263
264
265
266
267
268
log_debug("init done reached - rescue mode disabled");
}
}
goto EXIT;
}
if( type == DBUS_MESSAGE_TYPE_METHOD_CALL && !strcmp(interface, USB_MODE_INTERFACE) && !strcmp(object, USB_MODE_OBJECT))
{
status = DBUS_HANDLER_RESULT_HANDLED;
if(!strcmp(member, USB_MODE_STATE_REQUEST))
{
Sep 5, 2018
Sep 5, 2018
269
const char *mode = control_get_external_mode();
Aug 24, 2018
Aug 24, 2018
270
271
272
273
274
275
276
277
/* To the outside we want to keep CHARGING and CHARGING_FALLBACK the same */
if(!strcmp(MODE_CHARGING_FALLBACK, mode))
mode = MODE_CHARGING;
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
}
else if(!strcmp(member, USB_MODE_STATE_SET))
Apr 4, 2016
Apr 4, 2016
278
{
Aug 24, 2018
Aug 24, 2018
279
280
281
282
283
284
285
286
char *use = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* check if usb is connected, since it makes no sense to change mode if it isn't */
Sep 5, 2018
Sep 5, 2018
287
if( control_get_cable_state() != CABLE_STATE_PC_CONNECTED ) {
Aug 24, 2018
Aug 24, 2018
288
289
290
291
log_warning("USB not connected, not changing mode!\n");
goto error_reply;
}
/* check if the mode exists */
Sep 5, 2018
Sep 5, 2018
292
if(common_valid_mode(use))
Aug 24, 2018
Aug 24, 2018
293
294
goto error_reply;
/* do not change mode if the mode requested is the one already set */
Sep 5, 2018
Sep 5, 2018
295
if(strcmp(use, control_get_usb_mode()) != 0)
Aug 24, 2018
Aug 24, 2018
296
{
Sep 5, 2018
Sep 5, 2018
297
control_set_usb_mode(use);
Aug 24, 2018
Aug 24, 2018
298
}
Apr 4, 2016
Apr 4, 2016
299
if((reply = dbus_message_new_method_return(msg)))
Aug 24, 2018
Aug 24, 2018
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
dbus_message_append_args (reply, DBUS_TYPE_STRING, &use, DBUS_TYPE_INVALID);
else
error_reply:
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_CONFIG_SET))
{
char *config = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting configuration */
int ret = config_set_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_SETTING_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_HIDE))
{
char *config = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting configuration */
int ret = config_set_hide_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_UNHIDE))
{
char *config = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting configuration */
int ret = config_set_unhide_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
Apr 4, 2016
Apr 4, 2016
369
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
Aug 24, 2018
Aug 24, 2018
370
371
372
373
374
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
dbus_error_free(&err);
Apr 4, 2016
Apr 4, 2016
375
}
Aug 24, 2018
Aug 24, 2018
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
else if(!strcmp(member, USB_MODE_HIDDEN_GET))
{
char *config = config_get_hidden_modes();
if(!config)
config = g_strdup("");
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
g_free(config);
}
else if(!strcmp(member, USB_MODE_NETWORK_SET))
{
char *config = 0, *setting = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting configuration */
int ret = config_set_network_setting(config, setting);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(NETWORK_ENTRY, config, setting);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID);
network_update();
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_NETWORK_GET))
{
char *config = 0;
char *setting = 0;
DBusError err = DBUS_ERROR_INIT;
if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
{
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
}
else
{
setting = config_get_network_setting(config);
if(setting)
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID);
free(setting);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
}
else if(!strcmp(member, USB_MODE_CONFIG_GET))
{
char *config = config_get_mode_setting();
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
g_free(config);
}
else if(!strcmp(member, USB_MODE_LIST))
{
Sep 5, 2018
Sep 5, 2018
442
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST);
Mar 4, 2013
Mar 4, 2013
443
Aug 24, 2018
Aug 24, 2018
444
445
446
447
448
449
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, (const char *) &mode_list, DBUS_TYPE_INVALID);
g_free(mode_list);
}
else if(!strcmp(member, USB_MODE_AVAILABLE_MODES_GET))
{
Sep 5, 2018
Sep 5, 2018
450
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST);
Aug 24, 2018
Aug 24, 2018
451
452
453
454
455
456
457
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, (const char *) &mode_list, DBUS_TYPE_INVALID);
g_free(mode_list);
}
else if(!strcmp(member, USB_MODE_RESCUE_OFF))
{
Sep 5, 2018
Sep 5, 2018
458
usbmoded_set_rescue_mode(false);
Aug 24, 2018
Aug 24, 2018
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
log_debug("Rescue mode off\n ");
reply = dbus_message_new_method_return(msg);
}
else if(!strcmp(member, USB_MODE_WHITELISTED_MODES_GET))
{
gchar *mode_list = config_get_mode_whitelist();
if(!mode_list)
mode_list = g_strdup("");
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args(reply, DBUS_TYPE_STRING, &mode_list, DBUS_TYPE_INVALID);
g_free(mode_list);
}
else if(!strcmp(member, USB_MODE_WHITELISTED_MODES_SET))
{
const char *whitelist = 0;
DBusError err = DBUS_ERROR_INIT;
if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &whitelist, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
int ret = config_set_mode_whitelist(whitelist);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_WHITELIST_KEY, whitelist);
if (SET_CONFIG_OK(ret))
{
if ((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args(reply, DBUS_TYPE_STRING, &whitelist, DBUS_TYPE_INVALID);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, whitelist);
}
dbus_error_free(&err);
}
else if (!strcmp(member, USB_MODE_WHITELISTED_SET))
{
const char *mode = 0;
dbus_bool_t enabled = FALSE;
DBusError err = DBUS_ERROR_INIT;
if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &mode, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
int ret = config_set_mode_in_whitelist(mode, enabled);
if (ret == SET_CONFIG_UPDATED)
{
char *whitelist = config_get_mode_whitelist();
if (!whitelist)
whitelist = g_strdup(MODE_UNDEFINED);
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_WHITELIST_KEY, whitelist);
g_free(whitelist);
}
if (SET_CONFIG_OK(ret))
reply = dbus_message_new_method_return(msg);
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, mode);
}
dbus_error_free(&err);
}
else
{
/*unknown methods are handled here */
reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_METHOD, member);
}
if( !reply )
{
reply = dbus_message_new_error(msg, DBUS_ERROR_FAILED, member);
}
}
else if( type == DBUS_MESSAGE_TYPE_METHOD_CALL &&
!strcmp(interface, "org.freedesktop.DBus.Introspectable") &&
!strcmp(member, "Introspect"))
{
const gchar *xml = 0;
gchar *tmp = 0;
gchar *err = 0;
size_t len = strlen(object);
const char *pos = USB_MODE_OBJECT;
if( !strncmp(object, pos, len) )
{
if( pos[len] == 0 )
{
/* Full length USB_MODE_OBJECT requested */
Sep 5, 2018
Sep 5, 2018
547
xml = umdbus_introspect_usbmoded;
Aug 24, 2018
Aug 24, 2018
548
549
550
551
552
553
554
555
556
557
}
else if( pos[len] == '/' )
{
/* Leading part of USB_MODE_OBJECT requested */
gchar *parent = 0;
gchar *child = 0;
parent = g_strndup(pos, len);
pos += len + 1;
len = strcspn(pos, "/");
child = g_strndup(pos, len);
Sep 5, 2018
Sep 5, 2018
558
xml = tmp = g_strdup_printf(umdbus_introspect_template,
Aug 24, 2018
Aug 24, 2018
559
560
561
562
563
564
565
566
567
568
569
570
parent, child);
g_free(child);
g_free(parent);
}
else if( !strcmp(object, "/") )
{
/* Root object needs to be handled separately */
const char *parent = "/";
gchar *child = 0;
pos += 1;
len = strcspn(pos, "/");
child = g_strndup(pos, len);
Sep 5, 2018
Sep 5, 2018
571
xml = tmp = g_strdup_printf(umdbus_introspect_template,
Aug 24, 2018
Aug 24, 2018
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
parent, child);
g_free(child);
}
}
if( xml )
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply,
DBUS_TYPE_STRING, &xml,
DBUS_TYPE_INVALID);
}
else
{
err = g_strdup_printf("Object '%s' does not exist", object);
reply = dbus_message_new_error(msg, DBUS_ERROR_UNKNOWN_OBJECT,
err);
}
g_free(err);
g_free(tmp);
if( reply )
{
status = DBUS_HANDLER_RESULT_HANDLED;
}
}
Mar 22, 2011
Mar 22, 2011
599
600
601
EXIT:
Aug 24, 2018
Aug 24, 2018
602
603
604
605
606
607
608
609
610
611
612
if(reply)
{
if( !dbus_message_get_no_reply(msg) )
{
if( !dbus_connection_send(connection, reply, 0) )
log_debug("Failed sending reply. Out Of Memory!\n");
}
dbus_message_unref(reply);
}
return status;
Mar 22, 2011
Mar 22, 2011
613
614
}
Aug 24, 2018
Aug 24, 2018
615
DBusConnection *umdbus_get_connection(void)
Nov 7, 2016
Nov 7, 2016
616
617
{
DBusConnection *connection = 0;
Sep 5, 2018
Sep 5, 2018
618
619
if( umdbus_connection )
connection = dbus_connection_ref(umdbus_connection);
Nov 7, 2016
Nov 7, 2016
620
else
Aug 24, 2018
Aug 24, 2018
621
log_err("something asked for connection ref while unconnected");
Nov 7, 2016
Nov 7, 2016
622
623
624
return connection;
}
Mar 22, 2011
Mar 22, 2011
625
/**
Nov 7, 2016
Nov 7, 2016
626
* Establish D-Bus SystemBus connection
Mar 22, 2011
Mar 22, 2011
627
628
629
*
* @return TRUE when everything went ok
*/
Aug 24, 2018
Aug 24, 2018
630
gboolean umdbus_init_connection(void)
Mar 22, 2011
Mar 22, 2011
631
{
Aug 24, 2018
Aug 24, 2018
632
633
gboolean status = FALSE;
DBusError error = DBUS_ERROR_INIT;
Mar 22, 2011
Mar 22, 2011
634
Aug 24, 2018
Aug 24, 2018
635
/* connect to system bus */
Sep 5, 2018
Sep 5, 2018
636
if ((umdbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == NULL)
Aug 24, 2018
Aug 24, 2018
637
638
{
log_debug("Failed to open connection to system message bus; %s\n", error.message);
Mar 22, 2011
Mar 22, 2011
639
goto EXIT;
Aug 24, 2018
Aug 24, 2018
640
}
Mar 22, 2011
Mar 22, 2011
641
Aug 24, 2018
Aug 24, 2018
642
/* Initialise message handlers */
Sep 5, 2018
Sep 5, 2018
643
if (!dbus_connection_add_filter(umdbus_connection, umdbus_msg_handler, NULL, NULL))
Aug 24, 2018
Aug 24, 2018
644
goto EXIT;
Mar 22, 2011
Mar 22, 2011
645
Aug 24, 2018
Aug 24, 2018
646
/* Listen to init-done signals */
Sep 5, 2018
Sep 5, 2018
647
dbus_bus_add_match(umdbus_connection, INIT_DONE_MATCH, 0);
Nov 7, 2016
Nov 7, 2016
648
Aug 24, 2018
Aug 24, 2018
649
650
/* Re-check flag file after adding signal listener */
usbmoded_probe_init_done();
Jun 5, 2018
Jun 5, 2018
651
Aug 24, 2018
Aug 24, 2018
652
/* Connect D-Bus to the mainloop */
Sep 5, 2018
Sep 5, 2018
653
dbus_connection_setup_with_g_main(umdbus_connection, NULL);
Nov 7, 2016
Nov 7, 2016
654
Aug 24, 2018
Aug 24, 2018
655
656
/* everything went fine */
status = TRUE;
Nov 7, 2016
Nov 7, 2016
657
658
EXIT:
Aug 24, 2018
Aug 24, 2018
659
660
dbus_error_free(&error);
return status;
Nov 7, 2016
Nov 7, 2016
661
662
663
664
665
666
667
}
/**
* Reserve "com.meego.usb_moded" D-Bus Service Name
*
* @return TRUE when everything went ok
*/
Aug 24, 2018
Aug 24, 2018
668
gboolean umdbus_init_service(void)
Nov 7, 2016
Nov 7, 2016
669
{
Aug 24, 2018
Aug 24, 2018
670
671
672
673
gboolean status = FALSE;
DBusError error = DBUS_ERROR_INIT;
int ret;
Sep 5, 2018
Sep 5, 2018
674
if( !umdbus_connection ) {
Mar 22, 2011
Mar 22, 2011
675
goto EXIT;
Aug 24, 2018
Aug 24, 2018
676
677
678
}
/* Acquire D-Bus service */
Sep 5, 2018
Sep 5, 2018
679
ret = dbus_bus_request_name(umdbus_connection, USB_MODE_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
Aug 24, 2018
Aug 24, 2018
680
681
682
683
684
685
686
687
if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
log_debug("failed claiming dbus name\n");
if( dbus_error_is_set(&error) )
log_debug("DBUS ERROR: %s, %s \n", error.name, error.message);
goto EXIT;
}
log_debug("claimed name %s", USB_MODE_SERVICE);
Sep 5, 2018
Sep 5, 2018
688
umdbus_service_name_acquired = TRUE;
Aug 24, 2018
Aug 24, 2018
689
690
/* everything went fine */
status = TRUE;
Mar 22, 2011
Mar 22, 2011
691
Dec 15, 2015
Dec 15, 2015
692
EXIT:
Aug 24, 2018
Aug 24, 2018
693
694
dbus_error_free(&error);
return status;
Mar 22, 2011
Mar 22, 2011
695
696
}
Nov 7, 2016
Nov 7, 2016
697
698
/** Release "com.meego.usb_moded" D-Bus Service Name
*/
Aug 24, 2018
Aug 24, 2018
699
static void umdbus_cleanup_service(void)
Nov 7, 2016
Nov 7, 2016
700
{
Sep 5, 2018
Sep 5, 2018
701
if( !umdbus_service_name_acquired )
Nov 7, 2016
Nov 7, 2016
702
703
goto EXIT;
Sep 5, 2018
Sep 5, 2018
704
umdbus_service_name_acquired = FALSE;
Nov 7, 2016
Nov 7, 2016
705
706
log_debug("release name %s", USB_MODE_SERVICE);
Sep 5, 2018
Sep 5, 2018
707
708
if( umdbus_connection &&
dbus_connection_get_is_connected(umdbus_connection) )
Nov 7, 2016
Nov 7, 2016
709
{
Sep 5, 2018
Sep 5, 2018
710
dbus_bus_release_name(umdbus_connection, USB_MODE_SERVICE, NULL);
Nov 7, 2016
Nov 7, 2016
711
712
713
714
715
716
}
EXIT:
return;
}
Mar 22, 2011
Mar 22, 2011
717
718
719
720
/**
* Clean up the dbus connections on exit
*
*/
Aug 24, 2018
Aug 24, 2018
721
void umdbus_cleanup(void)
Mar 22, 2011
Mar 22, 2011
722
{
Nov 7, 2016
Nov 7, 2016
723
/* clean up system bus connection */
Sep 5, 2018
Sep 5, 2018
724
if (umdbus_connection != NULL)
Nov 7, 2016
Nov 7, 2016
725
{
Aug 24, 2018
Aug 24, 2018
726
umdbus_cleanup_service();
Nov 7, 2016
Nov 7, 2016
727
Sep 5, 2018
Sep 5, 2018
728
dbus_connection_remove_filter(umdbus_connection, umdbus_msg_handler, NULL);
Nov 7, 2016
Nov 7, 2016
729
Sep 5, 2018
Sep 5, 2018
730
731
dbus_connection_unref(umdbus_connection),
umdbus_connection = NULL;
Nov 7, 2016
Nov 7, 2016
732
}
Mar 22, 2011
Mar 22, 2011
733
734
735
}
/**
Mar 18, 2014
Mar 18, 2014
736
* Helper function for sending the different signals
Mar 22, 2011
Mar 22, 2011
737
*
Mar 21, 2014
Mar 21, 2014
738
* @return 0 on success, 1 on failure
Mar 18, 2014
Mar 18, 2014
739
740
* @param signal_type the type of signal (normal, error, ...)
* @@param content string which can be mode name, error, list of modes, ...
Mar 22, 2011
Mar 22, 2011
741
*/
Aug 24, 2018
Aug 24, 2018
742
static int umdbus_send_signal_ex(const char *signal_type, const char *content)
Mar 22, 2011
Mar 22, 2011
743
{
Aug 24, 2018
Aug 24, 2018
744
745
746
int result = 1;
DBusMessage* msg = 0;
Sep 5, 2018
Sep 5, 2018
747
748
749
750
751
/* Assume NULL content equals no value / empty list, and that skipping
* signal broadcast is never preferable over sending empty string. */
if( !content )
content = "";
Aug 24, 2018
Aug 24, 2018
752
753
log_debug("broadcast signal %s(%s)\n", signal_type, content);
Sep 5, 2018
Sep 5, 2018
754
if( !umdbus_service_name_acquired )
Aug 24, 2018
Aug 24, 2018
755
756
757
758
759
{
log_err("sending signal without service: %s(%s)",
signal_type, content);
goto EXIT;
}
Sep 5, 2018
Sep 5, 2018
760
if(!umdbus_connection)
Aug 24, 2018
Aug 24, 2018
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
{
log_err("Dbus system connection broken!\n");
goto EXIT;
}
// create a signal and check for errors
msg = dbus_message_new_signal(USB_MODE_OBJECT, USB_MODE_INTERFACE, signal_type );
if (NULL == msg)
{
log_debug("Message Null\n");
goto EXIT;
}
// append arguments onto signal
if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &content, DBUS_TYPE_INVALID))
{
log_debug("Appending arguments failed. Out Of Memory!\n");
goto EXIT;
}
// send the message on the correct bus and flush the connection
Sep 5, 2018
Sep 5, 2018
781
if (!dbus_connection_send(umdbus_connection, msg, 0))
Aug 24, 2018
Aug 24, 2018
782
783
784
785
786
{
log_debug("Failed sending message. Out Of Memory!\n");
goto EXIT;
}
result = 0;
Mar 22, 2011
Mar 22, 2011
787
Dec 15, 2015
Dec 15, 2015
788
EXIT:
Aug 24, 2018
Aug 24, 2018
789
790
791
// free the message
if(msg != 0)
dbus_message_unref(msg);
Mar 22, 2011
Mar 22, 2011
792
Aug 24, 2018
Aug 24, 2018
793
return result;
Mar 22, 2011
Mar 22, 2011
794
795
}
Mar 18, 2014
Mar 18, 2014
796
797
798
/**
* Send regular usb_moded state signal
*
Mar 21, 2014
Mar 21, 2014
799
* @return 0 on success, 1 on failure
Mar 18, 2014
Mar 18, 2014
800
801
802
* @param state_ind the signal name
*
*/
Aug 24, 2018
Aug 24, 2018
803
int umdbus_send_state_signal(const char *state_ind)
Mar 22, 2011
Mar 22, 2011
804
{
Sep 5, 2018
Sep 5, 2018
805
return umdbus_send_signal_ex(USB_MODE_SIGNAL_NAME, state_ind);
Mar 18, 2014
Mar 18, 2014
806
}
Mar 22, 2011
Mar 22, 2011
807
Mar 18, 2014
Mar 18, 2014
808
809
810
/**
* Send regular usb_moded error signal
*
Mar 21, 2014
Mar 21, 2014
811
* @return 0 on success, 1 on failure
Sep 15, 2014
Sep 15, 2014
812
* @param error the error to be signalled
Mar 18, 2014
Mar 18, 2014
813
814
*
*/
Aug 24, 2018
Aug 24, 2018
815
int umdbus_send_error_signal(const char *error)
Mar 18, 2014
Mar 18, 2014
816
{
Sep 5, 2018
Sep 5, 2018
817
return umdbus_send_signal_ex(USB_MODE_ERROR_SIGNAL_NAME, error);
Mar 22, 2011
Mar 22, 2011
818
}
Mar 18, 2014
Mar 18, 2014
819
Mar 18, 2014
Mar 18, 2014
820
821
822
/**
* Send regular usb_moded mode list signal
*
Mar 21, 2014
Mar 21, 2014
823
* @return 0 on success, 1 on failure
Sep 15, 2014
Sep 15, 2014
824
* @param supported_modes list of supported modes
Mar 18, 2014
Mar 18, 2014
825
826
*
*/
Aug 24, 2018
Aug 24, 2018
827
int umdbus_send_supported_modes_signal(const char *supported_modes)
Mar 18, 2014
Mar 18, 2014
828
{
Sep 5, 2018
Sep 5, 2018
829
return umdbus_send_signal_ex(USB_MODE_SUPPORTED_MODES_SIGNAL_NAME, supported_modes);
Mar 18, 2014
Mar 18, 2014
830
}
Apr 4, 2016
Apr 4, 2016
831
Aug 11, 2017
Aug 11, 2017
832
833
834
835
836
837
838
/**
* Send regular usb_moded mode list signal
*
* @return 0 on success, 1 on failure
* @param available_modes list of available modes
*
*/
Aug 24, 2018
Aug 24, 2018
839
int umdbus_send_available_modes_signal(const char *available_modes)
Aug 11, 2017
Aug 11, 2017
840
{
Sep 5, 2018
Sep 5, 2018
841
return umdbus_send_signal_ex(USB_MODE_AVAILABLE_MODES_SIGNAL_NAME, available_modes);
Aug 11, 2017
Aug 11, 2017
842
843
}
Apr 4, 2016
Apr 4, 2016
844
845
846
847
848
849
850
/**
* Send regular usb_moded hidden mode list signal
*
* @return 0 on success, 1 on failure
* @param hidden_modes list of supported modes
*
*/
Aug 24, 2018
Aug 24, 2018
851
int umdbus_send_hidden_modes_signal(const char *hidden_modes)
Apr 4, 2016
Apr 4, 2016
852
{
Sep 5, 2018
Sep 5, 2018
853
return umdbus_send_signal_ex(USB_MODE_HIDDEN_MODES_SIGNAL_NAME, hidden_modes);
Apr 4, 2016
Apr 4, 2016
854
}
Nov 7, 2016
Nov 7, 2016
855
Aug 11, 2017
Aug 11, 2017
856
857
858
859
860
861
/**
* Send regular usb_moded whitelisted mode list signal
*
* @return 0 on success, 1 on failure
* @param whitelist list of allowed modes
*/
Aug 24, 2018
Aug 24, 2018
862
int umdbus_send_whitelisted_modes_signal(const char *whitelist)
Aug 11, 2017
Aug 11, 2017
863
{
Sep 5, 2018
Sep 5, 2018
864
return umdbus_send_signal_ex(USB_MODE_WHITELISTED_MODES_SIGNAL_NAME, whitelist);
Aug 11, 2017
Aug 11, 2017
865
866
}
Aug 24, 2018
Aug 24, 2018
867
/** Async reply handler for umdbus_get_name_owner_async()
Nov 7, 2016
Nov 7, 2016
868
869
870
871
*
* @param pc Pending call object pointer
* @param aptr Notify function to call (as a void pointer)
*/
Aug 24, 2018
Aug 24, 2018
872
static void umdbus_get_name_owner_cb(DBusPendingCall *pc, void *aptr)
Nov 7, 2016
Nov 7, 2016
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
{
usb_moded_get_name_owner_fn cb = aptr;
DBusMessage *rsp = 0;
const char *dta = 0;
DBusError err = DBUS_ERROR_INIT;
if( !(rsp = dbus_pending_call_steal_reply(pc)) ) {
log_err("did not get reply");
goto EXIT;
}
if( dbus_set_error_from_message(&err, rsp) )
{
if( strcmp(err.name, DBUS_ERROR_NAME_HAS_NO_OWNER) )
log_err("error reply: %s: %s", err.name, err.message);
goto EXIT;
}
if( !dbus_message_get_args(rsp, &err,
DBUS_TYPE_STRING, &dta,
DBUS_TYPE_INVALID) )
{
if( strcmp(err.name, DBUS_ERROR_NAME_HAS_NO_OWNER) )
Nov 7, 2016
Nov 7, 2016
897
log_err("parse error: %s: %s", err.name, err.message);
Nov 7, 2016
Nov 7, 2016
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
goto EXIT;
}
EXIT:
/* Allways call the notification function. Equate any error
* situations with "service does not have an owner". */
cb(dta ?: "");
if( rsp ) dbus_message_unref(rsp);
dbus_error_free(&err);
}
/** Helper function for making async dbus name owner queries
*
* @param name D-Bus name to query
* @param cb Function to call when async reply is received
* @param ppc Where to store pending call object, or NULL
*
* @return TRUE if method call was sent, FALSE otherwise
*/
Aug 24, 2018
Aug 24, 2018
919
gboolean umdbus_get_name_owner_async(const char *name,
Nov 7, 2016
Nov 7, 2016
920
921
922
923
924
925
926
usb_moded_get_name_owner_fn cb,
DBusPendingCall **ppc)
{
gboolean ack = FALSE;
DBusMessage *req = 0;
DBusPendingCall *pc = 0;
Sep 5, 2018
Sep 5, 2018
927
if(!umdbus_connection)
Nov 7, 2016
Nov 7, 2016
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
goto EXIT;
req = dbus_message_new_method_call(DBUS_INTERFACE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
DBUS_GET_NAME_OWNER_REQ);
if( !req ) {
log_err("could not create method call message");
goto EXIT;
}
if( !dbus_message_append_args(req,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID) ) {
log_err("could not add method call parameters");
goto EXIT;
}
Sep 5, 2018
Sep 5, 2018
946
if( !dbus_connection_send_with_reply(umdbus_connection, req, &pc, -1) )
Nov 7, 2016
Nov 7, 2016
947
948
949
950
951
goto EXIT;
if( !pc )
goto EXIT;
Aug 24, 2018
Aug 24, 2018
952
if( !dbus_pending_call_set_notify(pc, umdbus_get_name_owner_cb, cb, 0) )
Nov 7, 2016
Nov 7, 2016
953
954
955
956
957
958
959
960
961
962
963
964
965
966
goto EXIT;
ack = TRUE;
if( ppc )
*ppc = pc, pc = 0;
EXIT:
if( pc ) dbus_pending_call_unref(pc);
if( req ) dbus_message_unref(req);
return ack;
}