2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "wmesh-log.h"
18 #include "wmesh-util.h"
19 #include "wmesh-gdbus.h"
20 #include "wmesh-request.h"
22 #include <linux/nl80211.h>
24 static GDBusProxy *_gproxy_connman = NULL;
25 static GDBusProxy *_gproxy_connman_mesh = NULL;
26 static GDBusProxy *_gproxy_connman_technology = NULL;
27 static GDBusProxy *_gproxy_connman_ethernet = NULL;
29 static int _wmeshd_close_gdbus_call(wmesh_service *service);
30 static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service,
31 const gchar* object_path, wmesh_network_info_s *result);
34 static int __channel_to_frequency(int channel, enum nl80211_band band)
40 case NL80211_BAND_2GHZ:
43 else if (channel < 14)
44 return 2407 + channel * 5;
46 case NL80211_BAND_5GHZ:
47 if (channel >= 182 && channel <= 196)
48 return 4000 + channel * 5;
50 return 5000 + channel * 5;
60 static int __frequency_to_channel(int freq)
65 return (freq - 2407) / 5;
66 else if (freq >= 4910 && freq <= 4980)
67 return (freq - 4000) / 5;
68 else if (freq <= 45000)
69 return (freq - 5000) / 5;
70 else if (freq >= 58320 && freq <= 64800)
71 return (freq - 56160) / 2160;
76 static GDBusProxy *_proxy_get_connman(wmesh_service *service)
78 GDBusProxy *proxy = NULL;
79 wmeshd_check_null_ret_error("service", service, NULL);
81 if (NULL == _gproxy_connman) {
82 proxy = g_dbus_proxy_new_sync(service->connection,
83 G_DBUS_PROXY_FLAGS_NONE, NULL,
86 CONNMAN_INTERFACE_MANAGER,
89 proxy = _gproxy_connman; //LCOV_EXCL_LINE
94 static GDBusProxy *_proxy_get_connman_mesh(wmesh_service *service)
96 GDBusProxy *proxy = NULL;
97 wmeshd_check_null_ret_error("service", service, NULL);
99 if (NULL == _gproxy_connman_mesh) {
100 proxy = g_dbus_proxy_new_sync(service->connection,
101 G_DBUS_PROXY_FLAGS_NONE, NULL,
103 CONNMAN_OBJECT_PATH_MESH,
104 CONNMAN_INTERFACE_MESH,
107 proxy = _gproxy_connman_mesh; //LCOV_EXCL_LINE
112 static GDBusProxy *_proxy_get_connman_ethernet(wmesh_service *service)
114 GDBusProxy *proxy = NULL;
115 wmeshd_check_null_ret_error("service", service, NULL);
117 if (NULL == _gproxy_connman_ethernet) {
118 proxy = g_dbus_proxy_new_sync(service->connection,
119 G_DBUS_PROXY_FLAGS_NONE, NULL,
120 CONNMAN_SERVER_NAME, /* Name */
121 "/net/connman/technology/ethernet", /* Object Path */
122 CONNMAN_INTERFACE_TECH, /* interface Name */
125 proxy = _gproxy_connman_ethernet; //LCOV_EXCL_LINE
130 static GDBusProxy *_proxy_get_connman_technology(wmesh_service *service)
132 GDBusProxy *proxy = NULL;
133 wmeshd_check_null_ret_error("service", service, NULL);
135 if (NULL == _gproxy_connman_technology) {
136 proxy = g_dbus_proxy_new_sync(service->connection,
137 G_DBUS_PROXY_FLAGS_NONE, NULL,
139 CONNMAN_OBJECT_PATH_TECH_MESH,
140 CONNMAN_INTERFACE_TECH,
143 proxy = _gproxy_connman_technology; //LCOV_EXCL_LINE
148 /* LCOV_EXCL_START */
149 static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
152 GDBusProxy *proxy = G_DBUS_PROXY(object);
153 gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
154 wmesh_service *service = (wmesh_service*)user_data;
158 if (NULL == name_owner) {
159 WMESH_LOGE("name_owner is not exists !");
160 _wmeshd_close_gdbus_call(service);
167 static int _wmeshd_create_gdbus_call(wmesh_service *service)
170 GError *error = NULL;
173 return WMESHD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
175 if (NULL != service->connection)
176 return WMESHD_ERROR_ALREADY_REGISTERED; //LCOV_EXCL_LINE
178 service->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
179 if (service->connection == NULL) {
180 /* LCOV_EXCL_START */
182 WMESH_LOGE("Failed to connect to the D-BUS daemon [%s]", error->message);
185 return WMESHD_ERROR_IO_ERROR;
189 id = g_signal_connect(service->connection, "notify::g-name-owner",
190 G_CALLBACK(_dbus_name_owner_notify), service);
192 /* LCOV_EXCL_START */
193 WMESH_LOGE("g_signal_connect() Fail");
194 g_object_unref(service->connection);
195 service->connection = NULL;
196 return WMESHD_ERROR_IO_ERROR;
200 return WMESHD_ERROR_NONE;
203 static int _wmeshd_close_gdbus_call(wmesh_service *service)
205 /* CHECK: is connection ref count required? */
206 g_object_unref(service->connection);
207 service->connection = NULL;
209 return WMESHD_ERROR_NONE;
212 /* LCOV_EXCL_START */
213 static void _wmeshd_signal_handler(GDBusConnection *connection,
214 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
215 const gchar *signal_name, GVariant *parameters, gpointer user_data)
217 wmesh_service *service = (wmesh_service*)user_data;
218 wmesh_network_info_s network_info = { 0, };
219 int ret = WMESHD_ERROR_NONE;
221 wmeshd_check_null_ret("user_data", user_data);
223 NOTUSED(sender_name);
224 NOTUSED(interface_name);
226 WMESH_LOGD("signal received = %s", signal_name);
227 if (0 == g_strcmp0(signal_name, "ScanDone")) {
228 /* TODO: Handle event */
229 wmesh_notify_scan_done();
230 } else if (0 == g_strcmp0(signal_name, "PropertyChanged")) {
231 const gchar* var = NULL;
233 GVariant *variant = NULL;
234 wmeshd_connection_state_e state = WMESHD_CONNECTION_STATE_DISCONNECTED;
236 if (NULL == parameters) {
237 WMESH_LOGE("Unexpected parameter");
241 g_variant_get(parameters, "(sv)", &key, &variant);
242 if (NULL == variant) {
243 WMESH_LOGE("Invalid variant");
248 var = g_variant_get_string(variant, NULL);
249 WMESH_LOGD(" %s [%s]", key, var);
250 WMESH_LOGD(" %s", object_path);
252 ret = _wmesh_gdbus_get_mesh_network_property(service, object_path, &network_info);
253 if (WMESHD_ERROR_NONE != ret)
254 WMESH_LOGE("Cannot get valid network property !"); //LCOV_EXCL_LINE
256 if (g_strcmp0("association", var) == 0) {
257 /* Joined mesh network */
258 state = WMESHD_CONNECTION_STATE_ASSOCIATION;
259 } else if (g_strcmp0("configuration", var) == 0) {
260 /* Trying to get IP address */
261 state = WMESHD_CONNECTION_STATE_CONFIGURATION;
262 } else if (g_strcmp0("ready", var) == 0 || g_strcmp0("online", var) == 0) {
263 /* IP address is obtained */
264 state = WMESHD_CONNECTION_STATE_CONNECTED;
265 } else if (g_strcmp0("disconnect", var) == 0 || g_strcmp0("failure", var) == 0) {
266 state = WMESHD_CONNECTION_STATE_DISCONNECTED;
268 WMESH_LOGE(" Unhandled state !");
269 g_free(network_info.mesh_id);
270 g_free(network_info.bssid);
274 wmesh_notify_connection_state(network_info.mesh_id, network_info.bssid,
275 network_info.channel, network_info.security, state);
277 g_free(network_info.mesh_id);
278 g_free(network_info.bssid);
283 static void _wmeshd_subscribe_event(wmesh_service *service)
287 wmeshd_check_null_ret("service", service);
289 id = g_dbus_connection_signal_subscribe(
290 (GDBusConnection *)service->connection,
291 CONNMAN_SERVER_NAME, CONNMAN_INTERFACE_MANAGER,
292 "ScanDone", "/", NULL,
293 G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL);
295 /* LCOV_EXCL_START */
296 WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno);
300 service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id));
301 WMESH_LOGD("[Signal subscribe] : ScanDone (%d)", id);
303 /* To monitor mesh profiles */
304 id = g_dbus_connection_signal_subscribe(
305 (GDBusConnection *)service->connection,
307 CONNMAN_INTERFACE_MESH,
311 G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL);
313 /* LCOV_EXCL_START */
314 WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno);
318 service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id));
319 WMESH_LOGD("[Signal subscribe] : PropertyChanged (%d)", id);
321 /* End of subscription */
324 static void _on_unsubscribe_ids(gpointer data, gpointer user_data)
326 unsigned int id = GPOINTER_TO_UINT(data);
327 wmesh_service *service = (wmesh_service*)user_data;
329 WMESH_LOGD("[Signal unsubscribe] : %d", id);
330 g_dbus_connection_signal_unsubscribe(
331 (GDBusConnection *)service->connection, id);
334 static void _wmeshd_unsubscribe_event(wmesh_service *service)
336 wmeshd_check_null_ret("service", service);
338 g_list_foreach(service->dbus_sub_ids, _on_unsubscribe_ids, service);
340 g_list_free(service->dbus_sub_ids);
341 service->dbus_sub_ids = NULL;
344 int wmeshd_dbus_start(wmesh_service *service)
348 rv = _wmeshd_create_gdbus_call(service);
349 if (WMESHD_ERROR_NONE != rv)
350 return rv; /* LCOV_EXCL_LINE */
352 service->ca = g_cancellable_new();
354 /* Create all required proxies here */
355 _gproxy_connman = _proxy_get_connman(service);
356 wmeshd_check_null_ret_error("_gproxy_connman", _gproxy_connman,
357 WMESHD_ERROR_IO_ERROR);
358 g_dbus_proxy_set_default_timeout(
359 G_DBUS_PROXY(_gproxy_connman), WMESH_DBUS_PROXY_TIMEOUT);
361 _gproxy_connman_mesh = _proxy_get_connman_mesh(service);
362 wmeshd_check_null_ret_error("_gproxy_connman_mesh", _gproxy_connman_mesh,
363 WMESHD_ERROR_IO_ERROR);
364 g_dbus_proxy_set_default_timeout(
365 G_DBUS_PROXY(_gproxy_connman_mesh), WMESH_DBUS_PROXY_TIMEOUT);
367 _gproxy_connman_technology = _proxy_get_connman_technology(service);
368 wmeshd_check_null_ret_error("_gproxy_connman_technology", _gproxy_connman_technology,
369 WMESHD_ERROR_IO_ERROR);
370 g_dbus_proxy_set_default_timeout(
371 G_DBUS_PROXY(_gproxy_connman_technology), WMESH_DBUS_PROXY_TIMEOUT);
373 _gproxy_connman_ethernet = _proxy_get_connman_ethernet(service);
374 wmeshd_check_null_ret_error("_gproxy_connman_ethernet", _gproxy_connman_ethernet,
375 WMESHD_ERROR_IO_ERROR);
376 g_dbus_proxy_set_default_timeout(
377 G_DBUS_PROXY(_gproxy_connman_ethernet), WMESH_DBUS_PROXY_TIMEOUT);
379 /* Subscribe events */
380 _wmeshd_subscribe_event(service);
382 return WMESHD_ERROR_NONE;
385 int wmeshd_dbus_stop(wmesh_service *service)
390 return WMESHD_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
392 /* Unsubscribe events */
393 _wmeshd_unsubscribe_event(service);
395 /* Unref all proxies here */
396 if (_gproxy_connman) {
397 g_object_unref(_gproxy_connman);
398 _gproxy_connman = NULL;
400 if (_gproxy_connman_mesh) {
401 g_object_unref(_gproxy_connman_mesh);
402 _gproxy_connman_mesh = NULL;
404 if (_gproxy_connman_technology) {
405 g_object_unref(_gproxy_connman_technology);
406 _gproxy_connman_technology = NULL;
409 g_cancellable_cancel(service->ca);
410 g_object_unref(service->ca);
413 rv = _wmeshd_close_gdbus_call(service);
417 int wmesh_gdbus_create_mesh_interface(wmesh_service *service)
419 int ret = WMESHD_ERROR_NONE;
420 GVariant *variant = NULL;
421 GError *error = NULL;
422 GVariant *var_dict = NULL;
424 wmesh_interface_s *info = NULL;
426 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
427 wmeshd_check_null_ret_error("connection", service->connection,
428 WMESHD_ERROR_INVALID_PARAMETER);
429 wmeshd_check_null_ret_error("_gproxy_connman_technology",
430 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
432 info = service->interface_info;
434 g_variant_dict_init(&dict, NULL);
435 g_variant_dict_insert(&dict, "Ifname", "s", info->mesh_interface);
436 g_variant_dict_insert(&dict, "ParentIfname", "s", info->base_interface);
437 g_variant_dict_insert(&dict, "BridgeIfname", "s", info->bridge_interface);
438 var_dict = g_variant_dict_end(&dict);
440 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
441 g_variant_new("(sv)", "MeshInterfaceAdd", var_dict),
442 G_DBUS_CALL_FLAGS_NONE,
445 WMESH_LOGD("Successfully requested. [MeshInterfaceAdd]");
446 /* LCOV_EXCL_START */
448 ret = WMESHD_ERROR_IO_ERROR;
449 WMESH_LOGE("Failed DBus call [%s]", error->message);
451 /* Interface not exists */
452 if (g_strrstr(error->message, "No such device"))
453 ret = WMESHD_ERROR_INVALID_PARAMETER;
460 int wmesh_gdbus_remove_mesh_interface(wmesh_service *service)
462 int ret = WMESHD_ERROR_NONE;
463 GVariant *variant = NULL;
464 GError *error = NULL;
465 GVariant *var_dict = NULL;
467 wmesh_interface_s *info = NULL;
469 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
470 wmeshd_check_null_ret_error("connection", service->connection,
471 WMESHD_ERROR_INVALID_PARAMETER);
472 wmeshd_check_null_ret_error("_gproxy_connman_technology",
473 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
475 info = service->interface_info;
477 g_variant_dict_init(&dict, NULL);
478 g_variant_dict_insert(&dict, "Ifname", "s", info->mesh_interface);
479 var_dict = g_variant_dict_end(&dict);
481 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
482 g_variant_new("(sv)", "MeshInterfaceRemove", var_dict),
483 G_DBUS_CALL_FLAGS_NONE,
486 WMESH_LOGD("Successfully requested. [MeshInterfaceRemove]");
487 /* LCOV_EXCL_START */
489 ret = WMESHD_ERROR_IO_ERROR;
490 WMESH_LOGE("Failed DBus call [%s]", error->message);
492 /* Interface not exists (Not created yet) */
493 if (g_strrstr(error->message, "No such device"))
494 ret = WMESHD_ERROR_NONE;
502 int wmesh_gdbus_mesh_scan(wmesh_service *service)
504 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
505 wmeshd_check_null_ret_error("connection", service->connection,
506 WMESHD_ERROR_INVALID_PARAMETER);
507 wmeshd_check_null_ret_error("_gproxy_connman_technology",
508 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
510 g_dbus_proxy_call(_gproxy_connman_technology, "Scan",
512 G_DBUS_CALL_FLAGS_NONE,
513 -1, NULL, NULL, NULL);
515 WMESH_LOGD("Successfully requested. [Scan]");
517 return WMESHD_ERROR_NONE;
520 int wmesh_gdbus_mesh_specific_scan(wmesh_service *service, gchar *mesh_id, gint channel)
522 GVariant *variant = NULL;
523 GError *error = NULL;
524 GVariant *var_dict = NULL;
527 enum nl80211_band band = (channel <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
528 gushort freq = __channel_to_frequency(channel, band);
530 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
531 wmeshd_check_null_ret_error("connection", service->connection,
532 WMESHD_ERROR_INVALID_PARAMETER);
533 wmeshd_check_null_ret_error("_gproxy_connman_technology",
534 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
536 g_variant_dict_init(&dict, NULL);
537 g_variant_dict_insert(&dict, "Name", "s", mesh_id);
538 g_variant_dict_insert(&dict, "Frequency", "q", freq);
539 var_dict = g_variant_dict_end(&dict);
541 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
542 g_variant_new("(sv)", "MeshSpecificScan", var_dict),
543 G_DBUS_CALL_FLAGS_NONE,
546 WMESH_LOGD("Successfully requested. [MeshSpecificScan]"); /* LCOV_EXCL_LINE */
547 /* LCOV_EXCL_START */
549 WMESH_LOGE("Failed DBus call [%s]", error->message);
551 return WMESHD_ERROR_IO_ERROR;
555 return WMESHD_ERROR_NONE;
558 int wmesh_gdbus_mesh_cancel_scan(wmesh_service *service)
560 int ret = WMESHD_ERROR_NONE;
561 GVariant *variant = NULL;
562 GError *error = NULL;
563 GVariant *var_dict = NULL;
566 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
567 wmeshd_check_null_ret_error("connection", service->connection,
568 WMESHD_ERROR_INVALID_PARAMETER);
569 wmeshd_check_null_ret_error("_gproxy_connman_technology",
570 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
572 g_variant_dict_init(&dict, NULL);
573 var_dict = g_variant_dict_end(&dict);
575 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
576 g_variant_new("(sv)", "AbortScan", var_dict),
577 G_DBUS_CALL_FLAGS_NONE,
580 WMESH_LOGD("Successfully requested. [AbortScan]"); /* LCOV_EXCL_LINE */
581 /* LCOV_EXCL_START */
583 ret = WMESHD_ERROR_IO_ERROR;
584 WMESH_LOGE("Failed DBus call [%s]", error->message);
586 /* Scan is not in progress */
587 if (g_strrstr(error->message, "Already exists"))
588 ret = WMESHD_ERROR_NONE;
592 /* LCOV_EXCL_START */
597 /* LCOV_EXCL_START */
598 static void _on_scan_result_destroy(gpointer data)
600 wmesh_scan_result_s *scan_item = (wmesh_scan_result_s *)data;
603 g_free(scan_item->mesh_id);
604 g_free(scan_item->bssid);
605 g_free(scan_item->object_path);
610 static void _on_peer_info_destroy(gpointer data)
612 wmesh_peer_info_s *peer = (wmesh_peer_info_s *)data;
615 g_free(peer->address);
620 static void _get_joined_network(wmesh_service *service, GVariant *variant)
622 GVariantIter *peer = NULL;
623 GVariantIter *property = NULL;
624 GVariantIter *iter = NULL;
626 gchar *sub_key = NULL;
627 GVariant *val = NULL;
628 GVariant *sub_val = NULL;
631 const gchar* obj_path = NULL;
632 const gchar* buf = NULL;
634 g_variant_get(variant, "(a(oa{sv}))", &peer);
635 /* LCOV_EXCL_START */
636 while ((child = g_variant_iter_next_value(peer))) {
637 wmesh_network_info_s *joined_info = NULL;
638 gboolean valid_state = TRUE;
640 g_variant_get(child, "(oa{sv})", &obj_path, &property);
641 WMESH_LOGD(" Object: [%s]", obj_path);
642 g_variant_unref(child);
643 if (NULL == obj_path) {
644 WMESH_LOGE("Null object");
648 /* Create an information structure for joined network */
649 joined_info = g_try_new0(wmesh_network_info_s, 1);
650 if (NULL == joined_info) {
651 WMESH_LOGE("Failed to allocate !");
655 while (g_variant_iter_loop(property, "{sv}", &key, &val)) {
656 if (strcasecmp(key, "Name") == 0) {
657 buf = g_variant_get_string(val, &len);
658 joined_info->mesh_id = g_strdup(buf);
659 } else if (strcasecmp(key, "BSSID") == 0) {
660 buf = g_variant_get_string(val, &len);
661 joined_info->bssid = g_strdup(buf);
662 } else if (strcasecmp(key, "State") == 0) {
663 buf = g_variant_get_string(val, &len);
664 WMESH_LOGD(" State : %s", buf);
666 /* Skip ignorable state */
667 if (g_strcmp0(buf, "idle") == 0
668 || g_strcmp0(buf, "disconnect") == 0
669 || g_strcmp0(buf, "failure") == 0) {
672 } else if (g_strcmp0(buf, "association") == 0) {
673 joined_info->state = WMESHD_CONNECTION_STATE_ASSOCIATION;
674 } else if (g_strcmp0(buf, "configuration") == 0) {
675 joined_info->state = WMESHD_CONNECTION_STATE_CONFIGURATION;
676 } else if (g_strcmp0(buf, "ready") == 0 || g_strcmp0(buf, "online") == 0) {
677 joined_info->state = WMESHD_CONNECTION_STATE_CONNECTED;
679 } else if (strcasecmp(key, "Security") == 0) {
680 buf = g_variant_get_string(val, &len);
681 if (g_strcmp0("sae", buf) == 0)
682 joined_info->security = WMESHD_SECURITY_SAE;
684 joined_info->security = WMESHD_SECURITY_NONE;
685 } else if (strcasecmp(key, "Pmf") == 0) {
686 joined_info->pmf = g_variant_get_uint16(val);
687 } else if (strcasecmp(key, "Frequency") == 0) {
688 joined_info->channel = __frequency_to_channel(g_variant_get_uint16(val));
689 } else if (strcasecmp(key, "IPv4") == 0) {
690 g_variant_get(val, "a{sv}", &iter);
691 while (g_variant_iter_loop(iter, "{sv}", &sub_key, &sub_val)) {
693 if (strcasecmp(sub_key, "Method") == 0) {
694 buf = g_variant_get_string(sub_val, &len);
695 WMESH_LOGD("Method %s", buf);
697 if (strcasecmp(buf, "dhcp") == 0)
698 joined_info->ipv4_type =
699 WMESHD_IP_CONFIG_TYPE_DYNAMIC;
700 else if (strcasecmp(buf, "manual") == 0)
701 joined_info->ipv4_type =
702 WMESHD_IP_CONFIG_TYPE_STATIC;
704 joined_info->ipv4_type =
705 WMESHD_IP_CONFIG_TYPE_UNKNOWN;
706 } else if (strcasecmp(sub_key, "Address") == 0) {
707 buf = g_variant_get_string(sub_val, &len);
708 WMESH_LOGD("Address %s", buf);
709 joined_info->ipv4_address = g_strdup(buf);
710 } else if (strcasecmp(sub_key, "Netmask") == 0) {
711 buf = g_variant_get_string(sub_val, &len);
712 WMESH_LOGD("Netmask %s", buf);
713 joined_info->ipv4_netmask = g_strdup(buf);
716 g_variant_iter_free(iter);
720 /* Skip ignorable state */
721 if (FALSE == valid_state) {
722 g_free(joined_info->mesh_id);
723 g_free(joined_info->bssid);
724 g_free(joined_info->ipv4_address);
725 g_free(joined_info->ipv4_netmask);
730 WMESH_LOGD(" Mesh ID : %s", joined_info->mesh_id);
731 WMESH_LOGD(" BSSID : %s", joined_info->bssid);
732 WMESH_LOGD(" Channel : %d", joined_info->channel);
733 WMESH_LOGD(" Security : %s",
734 (WMESHD_SECURITY_SAE == joined_info->security) ? "SAE" : "NONE");
735 service->joined_network = joined_info;
737 g_variant_iter_free(property);
739 /* If found, stop loop iteration */
743 g_variant_iter_free(peer);
747 static void _get_mesh_peers(wmesh_service *service, GVariant *variant)
749 GVariantIter *peer = NULL;
750 GVariantIter *property = NULL;
752 GVariant *val = NULL;
755 const gchar* obj_path = NULL;
757 g_variant_get(variant, "(a(oa{sv}))", &peer);
758 /* LCOV_EXCL_START */
759 while ((child = g_variant_iter_next_value(peer))) {
760 wmesh_scan_result_s *scan_info = NULL;
762 scan_info = g_try_new0(wmesh_scan_result_s, 1);
763 if (NULL == scan_info) {
764 WMESH_LOGE("Failed to allocate !");
765 g_variant_unref(child);
769 g_variant_get(child, "(oa{sv})", &obj_path, &property);
770 if (NULL == obj_path) {
771 WMESH_LOGE("Null object");
772 g_variant_unref(child);
776 g_variant_unref(child);
778 WMESH_LOGD(" Obj path : [%s]", obj_path);
779 scan_info->object_path = g_strdup(obj_path);
781 while (g_variant_iter_loop(property, "{sv}", &key, &val)) {
782 if (strcasecmp(key, "Name") == 0) {
783 const char *buf = g_variant_get_string(val, &len);
784 scan_info->mesh_id = g_strdup(buf);
785 WMESH_LOGD(" Mesh ID : %s", scan_info->mesh_id);
786 } else if (strcasecmp(key, "BSSID") == 0) {
787 const char *buf = g_variant_get_string(val, &len);
788 scan_info->bssid = g_strdup(buf);
789 WMESH_LOGD(" BSSID : %s", scan_info->bssid);
790 } else if (strcasecmp(key, "State") == 0) {
791 const char *buf = g_variant_get_string(val, &len);
792 WMESH_LOGD(" State : %s", buf);
794 if (g_strcmp0(buf, "idle") == 0
795 || g_strcmp0(buf, "disconnect") == 0
796 || g_strcmp0(buf, "failure") == 0) {
797 scan_info->state = WMESHD_CONNECTION_STATE_DISCONNECTED;
798 } else if (g_strcmp0(buf, "association") == 0) {
799 scan_info->state = WMESHD_CONNECTION_STATE_ASSOCIATION;
800 } else if (g_strcmp0(buf, "configuration") == 0) {
801 scan_info->state = WMESHD_CONNECTION_STATE_CONFIGURATION;
802 } else if (g_strcmp0(buf, "ready") == 0 || g_strcmp0(buf, "online") == 0) {
803 scan_info->state = WMESHD_CONNECTION_STATE_CONNECTED;
805 } else if (strcasecmp(key, "Security") == 0) {
806 const char *buf = g_variant_get_string(val, &len);
807 WMESH_LOGD(" Security : %s", buf);
808 if (g_strcmp0("sae", buf) == 0)
809 scan_info->security = WMESHD_SECURITY_SAE;
811 scan_info->security = WMESHD_SECURITY_NONE;
812 } else if (strcasecmp(key, "Frequency") == 0) {
813 scan_info->channel = __frequency_to_channel(g_variant_get_uint16(val));
814 WMESH_LOGD(" Channel : %d", scan_info->channel);
815 } else if (strcasecmp(key, "Favorite") == 0) {
816 const char *buf = g_variant_get_string(val, &len);
817 WMESH_LOGD(" Favorite : %s", buf);
818 } else if (strcasecmp(key, "Strength") == 0) {
819 scan_info->rssi = (gint)g_variant_get_byte(val);
820 WMESH_LOGD(" RSSI : %d", scan_info->rssi);
824 service->scanned_mesh_network =
825 g_list_prepend(service->scanned_mesh_network, scan_info);
827 g_variant_iter_free(property);
830 g_variant_iter_free(peer);
833 static void _get_connected_mesh_peers(wmesh_service *service, GVariant *variant)
835 GVariantIter *peer = NULL;
836 GVariant *val = NULL;
839 GVariant *dict = NULL;
841 g_variant_get(variant, "(a(a{sv}))", &peer);
842 while ((child = g_variant_iter_next_value(peer))) {
843 /* LCOV_EXCL_START */
844 wmesh_peer_info_s *peer_info = NULL;
846 peer_info = g_try_new0(wmesh_peer_info_s, 1);
847 if (NULL == peer_info) {
848 WMESH_LOGE("Failed to allocate !");
852 /* a{sv} <- (a{sv}) */
853 dict = g_variant_get_child_value(child, 0);
854 val = g_variant_lookup_value(dict, "PeerAddress", NULL);
856 const char *buf = g_variant_get_string(val, &len);
857 peer_info->address = g_strdup(buf);
858 WMESH_LOGD(" Address : %s", peer_info->address);
859 g_variant_unref(val);
860 g_variant_unref(dict);
862 WMESH_LOGE("Unable to get address !");
864 g_variant_unref(dict);
868 service->connected_mesh_peers =
869 g_list_prepend(service->connected_mesh_peers, peer_info);
872 g_variant_iter_free(peer);
875 int wmesh_gdbus_get_mesh_networks(wmesh_service *service)
877 GVariant *variant = NULL;
878 GError *error = NULL;
880 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
881 wmeshd_check_null_ret_error("connection", service->connection,
882 WMESHD_ERROR_INVALID_PARAMETER);
883 wmeshd_check_null_ret_error("_gproxy_connman",
884 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
886 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetMeshPeers",
888 G_DBUS_CALL_FLAGS_NONE,
891 WMESH_LOGD("Successfully requested. [GetMeshPeers]");
893 if (service->scanned_mesh_network) {
894 /* LCOV_EXCL_START */
895 g_list_free_full(service->scanned_mesh_network, _on_scan_result_destroy);
896 service->scanned_mesh_network = NULL;
900 _get_mesh_peers(service, variant);
902 /* List item is saved with reversed order for efficiency. */
903 service->scanned_mesh_network =
904 g_list_reverse(service->scanned_mesh_network);
905 /* LCOV_EXCL_START */
907 WMESH_LOGE("Failed DBus call [%s]", error->message);
909 return WMESHD_ERROR_IO_ERROR;
913 return WMESHD_ERROR_NONE;
916 int wmesh_gdbus_get_joined_mesh_network(wmesh_service *service)
918 GVariant *variant = NULL;
919 GError *error = NULL;
921 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
922 wmeshd_check_null_ret_error("connection", service->connection,
923 WMESHD_ERROR_INVALID_PARAMETER);
924 wmeshd_check_null_ret_error("_gproxy_connman",
925 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
927 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetMeshPeers",
929 G_DBUS_CALL_FLAGS_NONE,
932 WMESH_LOGD("Successfully requested. [GetMeshPeers]");
934 if (service->joined_network) {
935 /* LCOV_EXCL_START */
936 g_free(service->joined_network->mesh_id);
937 g_free(service->joined_network->bssid);
938 g_free(service->joined_network->ipv4_address);
939 g_free(service->joined_network->ipv4_netmask);
940 g_free(service->joined_network);
941 service->joined_network = NULL;
945 _get_joined_network(service, variant);
946 /* LCOV_EXCL_START */
948 WMESH_LOGE("Failed DBus call [%s]", error->message);
950 return WMESHD_ERROR_IO_ERROR;
954 return WMESHD_ERROR_NONE;
957 /* LCOV_EXCL_START */
958 int wmesh_gdbus_get_connected_peers(wmesh_service *service)
960 GVariant *variant = NULL;
961 GError *error = NULL;
963 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
964 wmeshd_check_null_ret_error("connection", service->connection,
965 WMESHD_ERROR_INVALID_PARAMETER);
966 wmeshd_check_null_ret_error("_gproxy_connman",
967 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
969 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetConnectedMeshPeers",
971 G_DBUS_CALL_FLAGS_NONE,
974 WMESH_LOGD("Successfully requested. [GetConnectedMeshPeers]");
976 if (service->connected_mesh_peers) {
977 g_list_free_full(service->connected_mesh_peers, _on_peer_info_destroy);
978 service->connected_mesh_peers = NULL;
981 _get_connected_mesh_peers(service, variant);
983 /* List item is saved with reversed order for efficiency. */
984 service->connected_mesh_peers =
985 g_list_reverse(service->connected_mesh_peers);
987 WMESH_LOGE("Failed DBus call [%s]", error->message);
989 return WMESHD_ERROR_IO_ERROR;
992 return WMESHD_ERROR_NONE;
995 static void _get_mesh_property(GVariant *variant, wmesh_network_info_s *result)
997 GVariantIter *property = NULL;
999 GVariant *val = NULL;
1002 WMESH_LOGD("Type [%s]", g_variant_get_type_string(variant));
1004 g_variant_get(variant, "(a{sv})", &property);
1006 while (g_variant_iter_loop(property, "{sv}", &key, &val)) {
1007 if (strcasecmp(key, "Name") == 0) {
1008 const char *buf = g_variant_get_string(val, &len);
1009 result->mesh_id = g_strdup(buf);
1010 WMESH_LOGD(" Mesh ID : %s", result->mesh_id);
1011 } else if (strcasecmp(key, "BSSID") == 0) {
1012 const char *buf = g_variant_get_string(val, &len);
1013 result->bssid = g_strdup(buf);
1014 WMESH_LOGD(" BSSID : %s", result->bssid);
1015 } else if (strcasecmp(key, "State") == 0) {
1016 const char *buf = g_variant_get_string(val, &len);
1017 WMESH_LOGD(" State : %s", buf);
1019 if (g_strcmp0(buf, "idle") == 0
1020 || g_strcmp0(buf, "disconnect") == 0
1021 || g_strcmp0(buf, "failure") == 0) {
1022 result->state = WMESHD_CONNECTION_STATE_DISCONNECTED;
1023 } else if (g_strcmp0(buf, "association") == 0) {
1024 result->state = WMESHD_CONNECTION_STATE_ASSOCIATION;
1025 } else if (g_strcmp0(buf, "configuration") == 0) {
1026 result->state = WMESHD_CONNECTION_STATE_CONFIGURATION;
1027 } else if (g_strcmp0(buf, "ready") == 0 || g_strcmp0(buf, "online") == 0) {
1028 result->state = WMESHD_CONNECTION_STATE_CONNECTED;
1030 } else if (strcasecmp(key, "Security") == 0) {
1031 const char *buf = g_variant_get_string(val, &len);
1032 WMESH_LOGD(" Security : %s", buf);
1033 if (g_strcmp0("sae", buf) == 0)
1034 result->security = WMESHD_SECURITY_SAE;
1036 result->security = WMESHD_SECURITY_NONE;
1037 } else if (strcasecmp(key, "Frequency") == 0) {
1038 result->channel = __frequency_to_channel(g_variant_get_uint16(val));
1039 WMESH_LOGD(" Channel : %d", result->channel);
1040 } else if (strcasecmp(key, "Favorite") == 0) {
1041 const char *buf = g_variant_get_string(val, &len);
1042 WMESH_LOGD(" Favorite : %s", buf);
1043 } else if (strcasecmp(key, "Strength") == 0) {
1044 gint rssi = (gint)g_variant_get_byte(val);
1045 WMESH_LOGD(" RSSI : %d", rssi);
1048 g_variant_iter_free(property);
1050 /* LCOV_EXCL_STOP */
1052 static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service,
1053 const gchar* object_path, wmesh_network_info_s *result)
1055 GVariant *variant = NULL;
1056 GError *error = NULL;
1058 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1059 wmeshd_check_null_ret_error("connection", service->connection,
1060 WMESHD_ERROR_INVALID_PARAMETER);
1061 wmeshd_check_null_ret_error("result", result, WMESHD_ERROR_INVALID_PARAMETER);
1063 variant = g_dbus_connection_call_sync(service->connection,
1064 CONNMAN_SERVER_NAME,
1066 CONNMAN_INTERFACE_MESH,
1069 G_DBUS_CALL_FLAGS_NONE,
1072 WMESH_LOGD("Successfully requested. [GetProperties]");
1074 /* Get properties */
1075 _get_mesh_property(variant, result);
1076 /* LCOV_EXCL_START */
1078 LOGE("Failed DBus call [%s]", error->message);
1079 g_error_free(error);
1080 return WMESHD_ERROR_IO_ERROR;
1082 /* LCOV_EXCL_STOP */
1084 return WMESHD_ERROR_NONE;
1087 int wmesh_gdbus_create_network(wmesh_service *service, gchar *mesh_id,
1088 gint channel, wmeshd_security_type_e sec, wmeshd_pmf_type_e pmf)
1090 GVariant *variant = NULL;
1091 GError *error = NULL;
1092 GVariant *var_dict = NULL;
1093 GVariantBuilder builder;
1094 const gchar* security = (WMESHD_SECURITY_SAE == sec) ? "sae" : "none";
1096 enum nl80211_band band = (channel <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1097 gushort freq = __channel_to_frequency(channel, band);
1099 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1100 wmeshd_check_null_ret_error("connection", service->connection,
1101 WMESHD_ERROR_INVALID_PARAMETER);
1102 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1103 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1105 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
1106 g_variant_builder_open(&builder, G_VARIANT_TYPE("a{sv}"));
1108 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1109 g_variant_builder_add(&builder, "s", "Name");
1110 g_variant_builder_add(&builder, "v", g_variant_new_string(mesh_id));
1111 g_variant_builder_close(&builder); /* {sv} */
1113 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1114 g_variant_builder_add(&builder, "s", "Frequency");
1115 g_variant_builder_add(&builder, "v", g_variant_new_uint16(freq));
1116 g_variant_builder_close(&builder); /* {sv} */
1118 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1119 g_variant_builder_add(&builder, "s", "Security");
1120 g_variant_builder_add(&builder, "v", g_variant_new_string(security));
1121 g_variant_builder_close(&builder); /* {sv} */
1123 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1124 g_variant_builder_add(&builder, "s", "Pmf");
1125 g_variant_builder_add(&builder, "v", g_variant_new_uint16(pmf));
1126 g_variant_builder_close(&builder); /* {sv} */
1128 g_variant_builder_close(&builder); /* a{sv} */
1130 var_dict = g_variant_builder_end(&builder);
1132 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
1133 g_variant_new("(sv)", "MeshCreateNetwork", var_dict),
1134 G_DBUS_CALL_FLAGS_NONE,
1136 g_variant_builder_unref(&builder);
1138 WMESH_LOGD("Successfully requested. [MeshCreateNetwork]"); /* LCOV_EXCL_LINE */
1139 /* LCOV_EXCL_START */
1141 WMESH_LOGE("Failed DBus call [%s]", error->message);
1142 g_error_free(error);
1143 return WMESHD_ERROR_IO_ERROR;
1145 /* LCOV_EXCL_STOP */
1147 return WMESHD_ERROR_NONE;
1150 /* LCOV_EXCL_START */
1151 int wmesh_gdbus_set_passphrase(wmesh_service *service, wmesh_scan_result_s *info, gchar *passphrase)
1153 int ret = WMESHD_ERROR_NONE;
1154 GVariant *variant = NULL;
1155 GVariant *var_passphrase = NULL;
1156 GError *error = NULL;
1158 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1159 wmeshd_check_null_ret_error("passphrase", passphrase, WMESHD_ERROR_INVALID_PARAMETER);
1161 var_passphrase = g_variant_new_string(passphrase);
1162 variant = g_dbus_connection_call_sync(service->connection,
1163 CONNMAN_SERVER_NAME,
1165 CONNMAN_INTERFACE_MESH,
1167 g_variant_new("(sv)", "Passphrase", var_passphrase),
1169 G_DBUS_CALL_FLAGS_NONE,
1172 WMESH_LOGD("Successfully requested. [SetProperty]");
1174 LOGE("Failed DBus call [%s]", error->message);
1175 g_error_free(error);
1176 ret = WMESHD_ERROR_IO_ERROR;
1178 g_variant_unref(var_passphrase);
1183 static void on_response_connect_network(GObject *source_object,
1184 GAsyncResult *res, gpointer user_data)
1186 int ret = WMESHD_ERROR_NONE;
1187 GError *error = NULL;
1188 GVariant *variant = NULL;
1192 variant = g_dbus_connection_call_finish(
1193 G_DBUS_CONNECTION(source_object), res, &error);
1195 WMESH_LOGD("Successfully requested. [Connect]");
1197 /* TODO: Unregister property change event */
1199 ret = WMESHD_ERROR_IO_ERROR;
1200 LOGE("Failed DBus call [%s]", error->message);
1202 if (g_strrstr(error->message, "Already exists"))
1203 ret = WMESHD_ERROR_ALREADY_REGISTERED;
1204 else if (g_strrstr(error->message, "In progress"))
1205 ret = WMESHD_ERROR_IN_PROGRESS;
1207 ret = WMESHD_ERROR_IO_ERROR;
1209 g_error_free(error);
1214 int wmesh_gdbus_connect_network(wmesh_service *service, wmesh_scan_result_s *info)
1216 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1217 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1219 g_dbus_connection_call(service->connection,
1220 CONNMAN_SERVER_NAME,
1222 CONNMAN_INTERFACE_MESH,
1225 G_DBUS_CALL_FLAGS_NONE,
1227 NULL, /* G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED */
1229 WMESH_LOGD("Successfully requested. [Connect]");
1231 return WMESHD_ERROR_NONE;
1234 int wmesh_gdbus_disconnect_network(wmesh_service *service, wmesh_scan_result_s *info)
1236 GVariant *variant = NULL;
1237 GError *error = NULL;
1239 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1240 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1242 variant = g_dbus_connection_call_sync(service->connection,
1243 CONNMAN_SERVER_NAME,
1245 CONNMAN_INTERFACE_MESH,
1248 G_DBUS_CALL_FLAGS_NONE,
1251 WMESH_LOGD("Successfully requested. [Disconnect]");
1253 LOGE("Failed DBus call [%s]", error->message);
1254 g_error_free(error);
1255 return WMESHD_ERROR_IO_ERROR;
1258 return WMESHD_ERROR_NONE;
1261 int wmesh_gdbus_remove_network(wmesh_service *service, wmesh_scan_result_s *info)
1263 GVariant *variant = NULL;
1264 GError *error = NULL;
1266 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1267 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1269 variant = g_dbus_connection_call_sync(service->connection,
1270 CONNMAN_SERVER_NAME,
1272 CONNMAN_INTERFACE_MESH,
1275 G_DBUS_CALL_FLAGS_NONE,
1278 WMESH_LOGD("Successfully requested. [Remove]");
1280 LOGE("Failed DBus call [%s]", error->message);
1281 g_error_free(error);
1282 return WMESHD_ERROR_IO_ERROR;
1285 return WMESHD_ERROR_NONE;
1289 int wmesh_gdbus_enable_ethernet_interface(wmesh_service *service, bool state)
1291 int ret = WMESHD_ERROR_NONE;
1292 GVariant *variant = NULL;
1293 GVariant *var_state = NULL;
1294 GError *error = NULL;
1295 wmesh_interface_s *info = NULL;
1297 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1298 wmeshd_check_null_ret_error("connection", service->connection,
1299 WMESHD_ERROR_INVALID_PARAMETER);
1300 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1301 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1303 info = service->interface_info;
1304 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1306 var_state = g_variant_new_boolean(state);
1307 variant = g_dbus_proxy_call_sync(_gproxy_connman_ethernet, "SetProperty",
1308 g_variant_new("(sv)", "Powered", var_state),
1309 G_DBUS_CALL_FLAGS_NONE,
1312 WMESH_LOGD("Successfully requested. [Powered]");
1314 ret = WMESHD_ERROR_IO_ERROR;
1315 WMESH_LOGE("Failed DBus call [%s]", error->message);
1317 /* Interface not exists (Not created yet) */
1318 if (g_strrstr(error->message, "No such device"))
1319 ret = WMESHD_ERROR_NONE;
1320 g_error_free(error);
1322 g_variant_unref(var_state);
1326 /* LCOV_EXCL_STOP */
1328 int wmesh_gdbus_set_mesh_gate(wmesh_service *service)
1330 int ret = WMESHD_ERROR_NONE;
1331 GVariant *variant = NULL;
1332 GError *error = NULL;
1333 GVariant *var_dict = NULL;
1335 wmesh_interface_s *info = NULL;
1337 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1338 wmeshd_check_null_ret_error("connection", service->connection,
1339 WMESHD_ERROR_INVALID_PARAMETER);
1340 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1341 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1343 info = service->interface_info;
1345 g_variant_dict_init(&dict, NULL);
1346 g_variant_dict_insert(&dict, "GateAnnounce", "b", info->gate_announce);
1347 g_variant_dict_insert(&dict, "HWMPRootMode", "q", info->hwmp_root_mode);
1348 g_variant_dict_insert(&dict, "STP", "q", info->stp);
1349 var_dict = g_variant_dict_end(&dict);
1351 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
1352 g_variant_new("(sv)", "SetMeshGate", var_dict),
1353 G_DBUS_CALL_FLAGS_NONE,
1356 WMESH_LOGD("Successfully requested. [SetMeshGate]"); /* LCOV_EXCL_LINE */
1357 /* LCOV_EXCL_START */
1359 ret = WMESHD_ERROR_IO_ERROR;
1360 WMESH_LOGE("Failed DBus call [%s]", error->message);
1362 /* Interface not exists */
1363 if (g_strrstr(error->message, "No such device"))
1364 ret = WMESHD_ERROR_INVALID_PARAMETER;
1365 g_error_free(error);
1367 /* LCOV_EXCL_STOP */
1372 /* LCOV_EXCL_START */
1373 int wmesh_gdbus_mesh_remove_peer(wmesh_service *service, char *peer)
1375 GVariant *variant = NULL;
1376 GError *error = NULL;
1377 int ret = WMESHD_ERROR_NONE;
1379 wmeshd_check_null_ret_error("service", service,
1380 WMESHD_ERROR_INVALID_PARAMETER);
1381 wmeshd_check_null_ret_error("connection", service->connection,
1382 WMESHD_ERROR_INVALID_PARAMETER);
1383 wmeshd_check_null_ret_error("_gproxy_connman",
1384 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
1386 variant = g_dbus_proxy_call_sync(_gproxy_connman, "MeshRemovePeer",
1387 g_variant_new("(s)", peer), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
1390 WMESH_LOGD("Successfully requested. [MeshRemovePeer]");
1392 ret = WMESHD_ERROR_IO_ERROR;
1393 WMESH_LOGE("Failed DBus call [%s]", error->message);
1395 /* Interface not exists */
1396 if (g_strrstr(error->message, "No such device"))
1397 ret = WMESHD_ERROR_INVALID_PARAMETER;
1398 g_error_free(error);
1403 /* LCOV_EXCL_STOP */