2 * Network Configuration Module
4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file implements wifi direct dbus utility functions.
23 * @file wifi-direct-dbus.c
24 * @author Nishant Chaprana (n.chaprana@samsung.com)
29 #include "wifi-direct-iface.h"
30 #include "wifi-direct-dbus.h"
31 #include "wifi-direct-log.h"
32 #include <wifi-direct.h>
33 #include "wifi-direct-ipc.h"
34 #include "wifi-direct-manager.h"
36 /* introspection xml to register interfaces */
37 const gchar wfd_manager_introspection_xml[] = {
38 "<node name='/net/wifidirect'>"
39 "<interface name='net.wifidirect'>"
40 "<method name='Activate'>"
41 "<arg type='i' name='error_code' direction='out'/>"
43 "<method name='AddClient'>"
44 "<arg type='i' name='result' direction='out'/>"
46 "<method name='Deactivate'>"
47 "<arg type='i' name='error_code' direction='out'/>"
49 "<method name='StartDiscovery'>"
50 "<arg type='a{sv}' name='parameters' direction='in'/>"
51 "<arg type='i' name='error_code' direction='out'/>"
53 "<method name='StopDiscovery'>"
54 "<arg type='i' name='error_code' direction='out'/>"
56 "<method name='GetDiscoveredPeers'>"
57 "<arg type='i' name='error_code' direction='out'/>"
58 "<arg type='aa{sv}' name='peer_details_list' direction='out'/>"
60 "<method name='Connect'>"
61 "<arg type='s' name='mac_address' direction='in'/>"
62 "<arg type='i' name='error_code' direction='out'/>"
64 "<method name='Disconnect'>"
65 "<arg type='s' name='mac_address' direction='in'/>"
66 "<arg type='i' name='error_code' direction='out'/>"
68 "<method name='CancelConnection'>"
69 "<arg type='s' name='mac_address' direction='in'/>"
70 "<arg type='i' name='error_code' direction='out'/>"
72 "<method name='AcceptConnection'>"
73 "<arg type='s' name='mac_address' direction='in'/>"
74 "<arg type='i' name='error_code' direction='out'/>"
76 "<method name='RejectConnection'>"
77 "<arg type='s' name='mac_address' direction='in'/>"
78 "<arg type='i' name='error_code' direction='out'/>"
80 "<method name='DisconnectAll'>"
81 "<arg type='i' name='error_code' direction='out'/>"
83 "<method name='GetConnectedPeers'>"
84 "<arg type='i' name='error_code' direction='out'/>"
85 "<arg type='aa{sv}' name='peer_details_list' direction='out'/>"
87 "<method name='GetConnectingPeer'>"
88 "<arg type='i' name='error_code' direction='out'/>"
89 "<arg type='a{sv}' name='peer_details' direction='out'/>"
91 "<method name='IsDiscoverable'>"
92 "<arg type='b' name='result' direction='out'/>"
94 "<method name='IsListeningOnly'>"
95 "<arg type='b' name='result' direction='out'/>"
97 "<method name='GetPeerInfo'>"
98 "<arg type='s' name='mac_address' direction='in'/>"
99 "<arg type='i' name='error_code' direction='out'/>"
100 "<arg type='a{sv}' name='peer_details' direction='out'/>"
102 "<method name='GetPeerVsie'>"
103 "<arg type='s' name='peer_mac_addr' direction='in'/>"
104 "<arg type='i' name='error_code' direction='out'/>"
105 "<arg type='s' name='vsie' direction='out'/>"
107 "<method name='GetState'>"
108 "<arg type='i' name='error_code' direction='out'/>"
109 "<arg type='i' name='state' direction='out'/>"
111 "<signal name='Activation'>"
112 "<arg type='i' name='error_code'/>"
114 "<signal name='Deactivation'>"
115 "<arg type='i' name='error_code'/>"
117 "<signal name='Connection'>"
118 "<arg type='i' name='error_code'/>"
119 "<arg type='i' name='connection_state'/>"
120 "<arg type='s' name='peer_mac_address'/>"
122 "<signal name='Disconnection'>"
123 "<arg type='i' name='error_code'/>"
124 "<arg type='i' name='connection_state'/>"
125 "<arg type='s' name='peer_mac_address'/>"
127 "<signal name='ListenStarted'>"
129 "<signal name='DiscoveryStarted'>"
131 "<signal name='DiscoveryFinished'>"
133 "<signal name='PeerFound'>"
134 "<arg type='s' name='peer_mac_address'/>"
136 "<signal name='PeerLost'>"
137 "<arg type='s' name='peer_mac_address'/>"
139 "<signal name='PeerIPAssigned'>"
140 "<arg type='s' name='peer_mac_address'/>"
141 "<arg type='s' name='assigned_ip_address'/>"
144 "<interface name='net.wifidirect.group'>"
145 "<method name='CreateGroup'>"
146 "<arg type='a{sv}' name='parameters' direction='in'/>"
147 "<arg type='i' name='error_code' direction='out'/>"
149 "<method name='DestroyGroup'>"
150 "<arg type='i' name='error_code' direction='out'/>"
152 "<method name='IsGroupOwner'>"
153 "<arg type='b' name='result' direction='out'/>"
155 "<method name='IsAutoGroup'>"
156 "<arg type='b' name='result' direction='out'/>"
158 "<method name='ActivatePushButton'>"
159 "<arg type='i' name='error_code' direction='out'/>"
161 "<method name='GetPersistentGroups'>"
162 "<arg type='i' name='error_code' direction='out'/>"
163 "<arg type='aa{sv}' name='result' direction='out'/>"
165 "<method name='RemovePersistentGroup'>"
166 "<arg type='s' name='mac_address' direction='in'/>"
167 "<arg type='s' name='ssid' direction='in'/>"
168 "<arg type='i' name='error_code' direction='out'/>"
170 "<method name='SetPassphrase'>"
171 "<arg type='s' name='passphrase' direction='in'/>"
172 "<arg type='i' name='error_code' direction='out'/>"
174 "<method name='GetPassphrase'>"
175 "<arg type='i' name='error_code' direction='out'/>"
176 "<arg type='s' name='passphrase' direction='out'/>"
178 "<method name='SetPersistentGroupEnabled'>"
179 "<arg type='b' name='enable' direction='in'/>"
180 "<arg type='i' name='error_code' direction='out'/>"
182 "<method name='IsPersistentGroupEnabled'>"
183 "<arg type='b' name='result' direction='out'/>"
185 "<method name='RemovePersistentDevice'>"
186 "<arg type='s' name='mac_address' direction='in'/>"
187 "<arg type='i' name='error_code' direction='out'/>"
189 "<method name='RemoveAllPersistentDevice'>"
190 "<arg type='i' name='error_code' direction='out'/>"
192 "<signal name='Created'>"
194 "<signal name='Destroyed'>"
197 "<interface name='net.wifidirect.config'>"
198 "<method name='GetDeviceName'>"
199 "<arg type='i' name='error_code' direction='out'/>"
200 "<arg type='s' name='device_name' direction='out'/>"
202 "<method name='SetDeviceName'>"
203 "<arg type='s' name='device_name' direction='in'/>"
204 "<arg type='i' name='error_code' direction='out'/>"
206 "<method name='SetWpsPin'>"
207 "<arg type='s' name='wps_pin' direction='in'/>"
208 "<arg type='i' name='error_code' direction='out'/>"
210 "<method name='GetWpsPin'>"
211 "<arg type='i' name='error_code' direction='out'/>"
212 "<arg type='s' name='wps_pin' direction='out'/>"
214 "<method name='GenerateWpsPin'>"
215 "<arg type='i' name='error_code' direction='out'/>"
216 "<arg type='s' name='wps_pin' direction='out'/>"
218 "<method name='GetSupportedWpsMode'>"
219 "<arg type='i' name='error_code' direction='out'/>"
220 "<arg type='i' name='config_methods' direction='out'/>"
222 "<method name='GetReqWpsMode'>"
223 "<arg type='i' name='error_code' direction='out'/>"
224 "<arg type='i' name='req_wps_mode' direction='out'/>"
226 "<method name='SetReqWpsMode'>"
227 "<arg type='i' name='req_wps_mode' direction='in'/>"
228 "<arg type='i' name='error_code' direction='out'/>"
230 "<method name='GetLocalWpsMode'>"
231 "<arg type='i' name='error_code' direction='out'/>"
232 "<arg type='i' name='local_wps_mode' direction='out'/>"
234 "<method name='GetIPAddress'>"
235 "<arg type='i' name='error_code' direction='out'/>"
236 "<arg type='s' name='local_ip_address' direction='out'/>"
238 "<method name='GetMacAddress'>"
239 "<arg type='i' name='error_code' direction='out'/>"
240 "<arg type='s' name='local_mac_address' direction='out'/>"
242 "<method name='GetGoIntent'>"
243 "<arg type='i' name='error_code' direction='out'/>"
244 "<arg type='i' name='go_intent' direction='out'/>"
246 "<method name='SetGoIntent'>"
247 "<arg type='i' name='go_intent' direction='in'/>"
248 "<arg type='i' name='error_code' direction='out'/>"
250 "<method name='SetGoIntentPerType'>"
251 "<arg type='i' name='type' direction='in'/>"
252 "<arg type='i' name='go_intent' direction='in'/>"
253 "<arg type='i' name='error_code' direction='out'/>"
255 "<method name='GetGoIntentPerType'>"
256 "<arg type='i' name='type' direction='in'/>"
257 "<arg type='i' name='error_code' direction='out'/>"
258 "<arg type='i' name='go_intent' direction='out'/>"
260 "<method name='GetMaxClient'>"
261 "<arg type='i' name='error_code' direction='out'/>"
262 "<arg type='i' name='max_client' direction='out'/>"
264 "<method name='SetMaxClient'>"
265 "<arg type='i' name='max_client' direction='in'/>"
266 "<arg type='i' name='error_code' direction='out'/>"
268 "<method name='SetAutoConnectionMode'>"
269 "<arg type='b' name='auto_connection_mode' direction='in'/>"
270 "<arg type='i' name='error_code' direction='out'/>"
272 "<method name='IsAutoConnectionMode'>"
273 "<arg type='i' name='error_code' direction='out'/>"
274 "<arg type='b' name='result' direction='out'/>"
276 "<method name='GetOperatingChannel'>"
277 "<arg type='i' name='error_code' direction='out'/>"
278 "<arg type='i' name='operating_channel' direction='out'/>"
280 "<method name='SetAutoConnectionPeer'>"
281 "<arg type='s' name='peer_mac_address' direction='in'/>"
282 "<arg type='i' name='error_code' direction='out'/>"
284 "<method name='GetConnectingPeer'>"
285 "<arg type='i' name='error_code' direction='out'/>"
286 "<arg type='s' name='local_mac_address' direction='out'/>"
288 "<method name='GetInterfaceName'>"
289 "<arg type='i' name='error_code' direction='out'/>"
290 "<arg type='s' name='ifname' direction='out'/>"
292 "<method name='GetSubnetMask'>"
293 "<arg type='i' name='error_code' direction='out'/>"
294 "<arg type='s' name='subnet_mask' direction='out'/>"
296 "<method name='GetGateway'>"
297 "<arg type='i' name='error_code' direction='out'/>"
298 "<arg type='s' name='gateway_address' direction='out'/>"
300 "<method name='GetSessionTimer'>"
301 "<arg type='i' name='error_code' direction='out'/>"
302 "<arg type='i' name='session_timer' direction='out'/>"
304 "<method name='SetSessionTimer'>"
305 "<arg type='i' name='session_timer' direction='in'/>"
306 "<arg type='i' name='error_code' direction='out'/>"
308 "<method name='SetAutoGroupRemoval'>"
309 "<arg type='b' name='enable' direction='in'/>"
310 "<arg type='i' name='error_code' direction='out'/>"
312 "<method name='GetPrimaryDevType'>"
313 "<arg type='i' name='pri_dev_type' direction='out'/>"
314 "<arg type='i' name='error_code' direction='out'/>"
316 "<method name='GetSecondaryDevType'>"
317 "<arg type='i' name='sec_dev_type' direction='out'/>"
318 "<arg type='i' name='error_code' direction='out'/>"
320 "<method name='GetPeerRssi'>"
321 "<arg type='s' name='peer_mac_addr' direction='in'/>"
322 "<arg type='i' name='error_code' direction='out'/>"
323 "<arg type='i' name='rssi' direction='out'/>"
325 "<method name='AddVsie'>"
326 "<arg type='i' name='frame_id' direction='in'/>"
327 "<arg type='s' name='vsie' direction='in'/>"
328 "<arg type='i' name='error_code' direction='out'/>"
330 "<method name='GetVsie'>"
331 "<arg type='i' name='frame_id' direction='in'/>"
332 "<arg type='i' name='error_code' direction='out'/>"
333 "<arg type='s' name='vsie' direction='out'/>"
335 "<method name='RemoveVsie'>"
336 "<arg type='i' name='frame_id' direction='in'/>"
337 "<arg type='s' name='vsie' direction='in'/>"
338 "<arg type='i' name='error_code' direction='out'/>"
340 "<method name='GetWpsConfigMethod'>"
341 "<arg type='i' name='error_code' direction='out'/>"
342 "<arg type='i' name='req_wps_mode' direction='out'/>"
344 "<method name='SetWpsConfigMethod'>"
345 "<arg type='i' name='req_wps_mode' direction='in'/>"
346 "<arg type='i' name='error_code' direction='out'/>"
349 "<interface name='net.wifidirect.service'>"
350 "<method name='StartDiscovery'>"
351 "<arg type='i' name='service_type' direction='in'/>"
352 "<arg type='s' name='mac_addr' direction='in'/>"
353 "<arg type='i' name='error_code' direction='out'/>"
355 "<method name='StopDiscovery'>"
356 "<arg type='i' name='service_type' direction='in'/>"
357 "<arg type='s' name='mac_addr' direction='in'/>"
358 "<arg type='i' name='error_code' direction='out'/>"
360 "<method name='Register'>"
361 "<arg type='i' name='service_type' direction='in'/>"
362 "<arg type='s' name='info_string' direction='in'/>"
363 "<arg type='i' name='error_code' direction='out'/>"
364 "<arg type='i' name='service_id' direction='out'/>"
366 "<method name='Deregister'>"
367 "<arg type='i' name='service_id' direction='in'/>"
368 "<arg type='i' name='error_code' direction='out'/>"
370 "<signal name='DiscoveryStarted'>"
372 "<signal name='DiscoveryFound'>"
373 "<arg type='i' name='service_type'/>"
374 "<arg type='s' name='response_data'/>"
375 "<arg type='s' name='peer_mac_address'/>"
377 "<signal name='DiscoveryFinished'>"
380 "<interface name='net.wifidirect.display'>"
381 "<method name='Init'>"
382 "<arg type='i' name='error_code' direction='out'/>"
384 "<method name='Deinit'>"
385 "<arg type='i' name='error_code' direction='out'/>"
387 "<method name='SetConfig'>"
388 "<arg type='i' name='type' direction='in'/>"
389 "<arg type='i' name='port' direction='in'/>"
390 "<arg type='i' name='hdcp' direction='in'/>"
391 "<arg type='i' name='error_code' direction='out'/>"
393 "<method name='SetAvailiability'>"
394 "<arg type='i' name='availability' direction='in'/>"
395 "<arg type='i' name='error_code' direction='out'/>"
397 "<method name='GetConfig'>"
398 "<arg type='i' name='error_code' direction='out'/>"
399 "<arg type='i' name='type' direction='out'/>"
400 "<arg type='i' name='port' direction='out'/>"
401 "<arg type='i' name='hdcp' direction='out'/>"
403 "<method name='GetAvailiability'>"
404 "<arg type='i' name='error_code' direction='out'/>"
405 "<arg type='i' name='availability' direction='out'/>"
407 "<method name='GetPeerType'>"
408 "<arg type='s' name='peer_mac_addr' direction='in'/>"
409 "<arg type='i' name='error_code' direction='out'/>"
410 "<arg type='i' name='result' direction='out'/>"
412 "<method name='GetPeerAvailability'>"
413 "<arg type='s' name='peer_mac_addr' direction='in'/>"
414 "<arg type='i' name='error_code' direction='out'/>"
415 "<arg type='i' name='result' direction='out'/>"
417 "<method name='GetPeerHdcp'>"
418 "<arg type='s' name='peer_mac_addr' direction='in'/>"
419 "<arg type='i' name='error_code' direction='out'/>"
420 "<arg type='i' name='result' direction='out'/>"
422 "<method name='GetPeerPort'>"
423 "<arg type='s' name='peer_mac_addr' direction='in'/>"
424 "<arg type='i' name='error_code' direction='out'/>"
425 "<arg type='i' name='result' direction='out'/>"
427 "<method name='GetPeerThroughput'>"
428 "<arg type='s' name='peer_mac_addr' direction='in'/>"
429 "<arg type='i' name='error_code' direction='out'/>"
430 "<arg type='i' name='result' direction='out'/>"
433 "<interface name='net.wifidirect.asp'>"
434 "<method name='AdvertiseService'>"
435 "<arg type='a{sv}' name='parameters' direction='in'/>"
436 "<arg type='i' name='result' direction='out'/>"
438 "<method name='CancelAdvertiseService'>"
439 "<arg type='u' name='adv_id' direction='in'/>"
440 "<arg type='i' name='result' direction='out'/>"
442 "<method name='SeekService'>"
443 "<arg type='a{sv}' name='parameters' direction='in'/>"
444 "<arg type='i' name='result' direction='out'/>"
446 "<method name='CancelSeekService'>"
447 "<arg type='t' name='search_id' direction='in'/>"
448 "<arg type='i' name='result' direction='out'/>"
450 "<method name='ConnectSession'>"
451 "<arg type='a{sv}' name='parameters' direction='in'/>"
452 "<arg type='i' name='result' direction='out'/>"
454 "<method name='ConfirmSession'>"
455 "<arg type='a{sv}' name='parameters' direction='in'/>"
456 "<arg type='i' name='result' direction='out'/>"
458 "<signal name='SearchResult'>"
459 "<arg type='a{sv}' name='parameters'/>"
461 "<signal name='SessionRequest'>"
462 "<arg type='a{sv}' name='parameters'/>"
464 "<signal name='SessionConfigRequest'>"
465 "<arg type='a{sv}' name='parameters'/>"
467 "<signal name='ConnectStatus'>"
468 "<arg type='a{sv}' name='parameters'/>"
470 "<signal name='SessionStatus'>"
471 "<arg type='a{sv}' name='parameters'/>"
473 "<signal name='SessionPeerIPAssigned'>"
474 "<arg type='a{sv}' name='parameters'/>"
480 static GDBusConnection *g_connection = NULL;
481 static guint g_owner_id = 0; /* Name Owner ID */
483 static int nameowner_changed_sub_id = 0;
485 static void wfd_manager_dbus_register_nameowner_signal(void);
487 static GDBusConnection *__dbus_get_gdbus_conn(void)
492 static void wfd_manger_dbus_manage_iface_handler(
493 GDBusConnection *connection,
495 const gchar *object_path,
496 const gchar *interface_name,
497 const gchar *method_name,
498 GVariant *parameters,
499 GDBusMethodInvocation *invocation,
502 if (!g_strcmp0(method_name, "AddClient"))
503 wfd_manager_add_active_client(sender);
506 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
507 DBUS_DEBUG_VARIANT(parameters);
509 wfd_manager_iface_manage_handler(method_name, parameters, invocation);
514 static void wfd_manger_dbus_group_iface_handler(
515 GDBusConnection *connection,
517 const gchar *object_path,
518 const gchar *interface_name,
519 const gchar *method_name,
520 GVariant *parameters,
521 GDBusMethodInvocation *invocation,
525 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
526 DBUS_DEBUG_VARIANT(parameters);
528 wfd_manager_iface_group_handler(method_name, parameters, invocation);
532 static void wfd_manger_dbus_config_iface_handler(
533 GDBusConnection *connection,
535 const gchar *object_path,
536 const gchar *interface_name,
537 const gchar *method_name,
538 GVariant *parameters,
539 GDBusMethodInvocation *invocation,
543 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
544 DBUS_DEBUG_VARIANT(parameters);
546 wfd_manager_iface_config_handler(method_name, parameters, invocation);
550 static void wfd_manger_dbus_service_iface_handler(
551 GDBusConnection *connection,
553 const gchar *object_path,
554 const gchar *interface_name,
555 const gchar *method_name,
556 GVariant *parameters,
557 GDBusMethodInvocation *invocation,
561 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
562 DBUS_DEBUG_VARIANT(parameters);
564 wfd_manager_iface_service_handler(method_name, parameters, invocation);
568 static void wfd_manger_dbus_display_iface_handler(
569 GDBusConnection *connection,
571 const gchar *object_path,
572 const gchar *interface_name,
573 const gchar *method_name,
574 GVariant *parameters,
575 GDBusMethodInvocation *invocation,
579 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
580 DBUS_DEBUG_VARIANT(parameters);
582 wfd_manager_iface_display_handler(method_name, parameters, invocation);
586 static void wfd_manger_dbus_asp_iface_handler(
587 GDBusConnection *connection,
589 const gchar *object_path,
590 const gchar *interface_name,
591 const gchar *method_name,
592 GVariant *parameters,
593 GDBusMethodInvocation *invocation,
597 WDS_LOGD("interface : [%s], method : [%s]", interface_name, method_name);
598 DBUS_DEBUG_VARIANT(parameters);
600 wfd_manager_iface_asp_handler(method_name, parameters, invocation);
604 /* GDBus method handler */
606 static const GDBusInterfaceVTable wfd_manager_dbus_manage_iface_vtable = {
607 wfd_manger_dbus_manage_iface_handler, NULL, NULL};
609 static const GDBusInterfaceVTable wfd_manager_dbus_group_iface_vtable = {
610 wfd_manger_dbus_group_iface_handler, NULL, NULL};
612 static const GDBusInterfaceVTable wfd_manager_dbus_config_iface_vtable = {
613 wfd_manger_dbus_config_iface_handler, NULL, NULL};
615 static const GDBusInterfaceVTable wfd_manager_dbus_service_iface_vtable = {
616 wfd_manger_dbus_service_iface_handler, NULL, NULL};
618 static const GDBusInterfaceVTable wfd_manager_dbus_display_iface_vtable = {
619 wfd_manger_dbus_display_iface_handler, NULL, NULL};
621 static const GDBusInterfaceVTable wfd_manager_dbus_asp_iface_vtable = {
622 wfd_manger_dbus_asp_iface_handler, NULL, NULL};
627 const gchar *iface_name;
628 const GDBusInterfaceVTable *vtbl;
629 } wfd_manager_iface_map[] = {
632 WFD_MANAGER_MANAGE_INTERFACE,
633 &wfd_manager_dbus_manage_iface_vtable
637 WFD_MANAGER_GROUP_INTERFACE,
638 &wfd_manager_dbus_group_iface_vtable
642 WFD_MANAGER_CONFIG_INTERFACE,
643 &wfd_manager_dbus_config_iface_vtable
647 WFD_MANAGER_SERVICE_INTERFACE,
648 &wfd_manager_dbus_service_iface_vtable
652 WFD_MANAGER_DISPLAY_INTERFACE,
653 &wfd_manager_dbus_display_iface_vtable
657 WFD_MANAGER_ASP_INTERFACE,
658 &wfd_manager_dbus_asp_iface_vtable
667 static guint wfd_manager_dbus_iface_register(const gchar* iface_name,
668 const gchar* iface_path,
669 GDBusNodeInfo *node_info,
670 const GDBusInterfaceVTable *interface_vtable)
672 GDBusInterfaceInfo *interface_info = NULL;
673 GError *Error = NULL;
675 GDBusConnection *connection = NULL;
677 connection = __dbus_get_gdbus_conn();
678 if (connection == NULL) {
679 WDS_LOGE("Dbus connection not yet initiated");
683 if (!iface_name || !iface_path || !node_info || !interface_vtable) {
684 WDS_LOGE("Invalid Parameters");
688 /* Register interface */
689 interface_info = g_dbus_node_info_lookup_interface(node_info, iface_name);
690 if (interface_info == NULL) {
691 WDS_LOGE("Failed to get interface info");
692 g_dbus_node_info_unref(node_info);
696 reg_id = g_dbus_connection_register_object(connection, iface_path,
697 interface_info, interface_vtable,
700 WDS_LOGE("Failed to register: %s", Error->message);
701 g_clear_error(&Error);
702 g_dbus_node_info_unref(node_info);
706 WDS_LOGD("Interface Registration ID [%d], Interface Name [%s]", reg_id, iface_name);
711 static gboolean wfd_manager_dbus_register(void)
713 GDBusNodeInfo *node_info = NULL;
714 GError *Error = NULL;
717 wfd_error_register();
719 node_info = g_dbus_node_info_new_for_xml(wfd_manager_introspection_xml, &Error);
720 if (node_info == NULL) {
721 WDS_LOGE("Failed to get node info, Error: %s", Error->message);
722 g_clear_error(&Error);
726 while (wfd_manager_iface_map[count].iface_name != NULL) {
727 wfd_manager_iface_map[count].reg_id =
728 wfd_manager_dbus_iface_register(wfd_manager_iface_map[count].iface_name,
731 wfd_manager_iface_map[count].vtbl);
733 WDS_LOGD("Registered Interface [%d, %s]",
734 wfd_manager_iface_map[count].reg_id,
735 wfd_manager_iface_map[count].iface_name);
740 g_dbus_node_info_unref(node_info);
744 static void nameowner_signal_handler(GDBusConnection *connection,
745 const gchar *sender_name,
746 const gchar *object_path,
747 const gchar *interface_name,
748 const gchar *signal_name,
749 GVariant *parameters,
756 g_variant_get(parameters, "(&s&s&s)", &name, &old, &new);
757 wfd_manager_remove_active_client(name, old, new);
760 static void wfd_manager_dbus_register_nameowner_signal(void)
762 GDBusConnection *connection = __dbus_get_gdbus_conn();
764 if (connection == NULL) {
765 WDS_LOGE("Failed to get GDbus Connection");
769 nameowner_changed_sub_id = g_dbus_connection_signal_subscribe(
776 G_DBUS_SIGNAL_FLAGS_NONE,
777 nameowner_signal_handler,
781 WDS_LOGD("Subscribed successfully for NameOwnerChanged signals");
784 static void __on_bus_acquired(GDBusConnection *connection,
788 WDS_LOGD("on_bus_acquired: %s", name);
789 wfd_manager_dbus_register_nameowner_signal();
790 wfd_manager_dbus_register();
793 static void __on_name_acquired(GDBusConnection *connection,
797 WDS_LOGD("on_name_acquired: %s", name);
800 static void __on_name_lost(GDBusConnection *connection,
804 WDS_LOGD("on_name_lost: %s", name);
807 void wfd_manager_dbus_unregister_nameowner_signal(void)
809 GDBusConnection *connection = NULL;
811 wfd_manager_free_active_client_list();
813 connection = __dbus_get_gdbus_conn();
815 WDS_LOGE("Already unregistered. Nothing to be done");
819 g_dbus_connection_signal_unsubscribe(connection,
820 nameowner_changed_sub_id);
822 WDS_LOGD("Unsubscribed successfully for NameOwnerChanged signals");
825 gboolean wfd_manager_dbus_iface_unregister(guint reg_id)
827 GDBusConnection *connection = NULL;
829 connection = __dbus_get_gdbus_conn();
830 if (connection == NULL) {
831 WDS_LOGE("Dbus connection not yet initiated");
836 if (g_dbus_connection_unregister_object(connection, reg_id) == FALSE)
837 WDS_LOGE("Failed to unregister iface object");
842 void wfd_manager_dbus_unregister(void)
846 wfd_error_deregister();
848 while (wfd_manager_iface_map[count].iface_name != NULL) {
849 wfd_manager_dbus_iface_unregister(wfd_manager_iface_map[count].reg_id);
854 gboolean wfd_manager_dbus_init(void)
856 GError *Error = NULL;
858 if (g_connection != NULL) {
859 WDS_LOGE("Conenciton already present");
863 g_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &Error);
864 if (g_connection == NULL) {
865 WDS_LOGE("Failed to get connection, Error[%s]", Error->message);
870 g_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
872 G_BUS_NAME_OWNER_FLAGS_NONE,
878 if (g_owner_id == 0) {
879 WDS_LOGE("Failed to get bus name");
882 WDS_LOGD("DBus Owner id is [%d]", g_owner_id);
887 void wfd_manager_dbus_deinit(void)
889 if (g_connection == NULL || g_owner_id == 0)
892 g_object_unref(g_connection);
893 g_bus_unown_name(g_owner_id);
896 gboolean wfd_manager_dbus_emit_signal(const gchar *interface_name,
897 const gchar *signal_name,
898 GVariant *parameters)
901 GError *error = NULL;
902 GDBusConnection *connection;
904 connection = __dbus_get_gdbus_conn();
905 if (connection == NULL) {
906 WDS_LOGE("GDBusconnection is NULL");
910 DBUS_DEBUG_VARIANT(parameters);
912 rv = g_dbus_connection_emit_signal(connection,
920 WDS_LOGE("Failed to get node info, Error: %s", error->message);
923 WDS_LOGD("[%s] signal sent on [%s] interface", signal_name, interface_name);
929 void wfd_manager_dbus_return_err(int ret, GDBusMethodInvocation *invocation)
932 gchar* dbus_error_name = NULL;
937 wfd_error_set_gerror(ret, &err);
938 dbus_error_name = g_dbus_error_encode_gerror(err);
939 WDS_LOGD("g_dbus_method_invocation_return_gerror with [%s]", dbus_error_name);
940 g_free(dbus_error_name);
941 g_dbus_method_invocation_return_gerror(invocation, err);
946 void wfd_manager_dbus_reply_error_none(GDBusMethodInvocation *invocation)
951 g_dbus_method_invocation_return_value(invocation,
952 g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE));
957 void wfd_manager_dbus_reply_params(GDBusMethodInvocation *invocation, GVariant *parameters)
962 g_dbus_method_invocation_return_value(invocation, parameters);
967 GVariant* wfd_manager_dbus_pack_ay(const unsigned char *src, int size)
969 GVariantBuilder *builder = NULL;
970 GVariant *iter = NULL;
974 WDS_LOGE("Invalid parameter");//LCOV_EXCL_LINE
978 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
980 for (i = 0; i < size; i++)
981 g_variant_builder_add(builder, "y", src[i]);
983 iter = g_variant_new("ay", builder);
985 g_variant_builder_unref(builder);