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);
861 WMESH_LOGE("Unable to get address !");
866 service->connected_mesh_peers =
867 g_list_prepend(service->connected_mesh_peers, peer_info);
870 g_variant_iter_free(peer);
873 int wmesh_gdbus_get_mesh_networks(wmesh_service *service)
875 GVariant *variant = NULL;
876 GError *error = NULL;
878 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
879 wmeshd_check_null_ret_error("connection", service->connection,
880 WMESHD_ERROR_INVALID_PARAMETER);
881 wmeshd_check_null_ret_error("_gproxy_connman",
882 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
884 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetMeshPeers",
886 G_DBUS_CALL_FLAGS_NONE,
889 WMESH_LOGD("Successfully requested. [GetMeshPeers]");
891 if (service->scanned_mesh_network) {
892 /* LCOV_EXCL_START */
893 g_list_free_full(service->scanned_mesh_network, _on_scan_result_destroy);
894 service->scanned_mesh_network = NULL;
898 _get_mesh_peers(service, variant);
900 /* List item is saved with reversed order for efficiency. */
901 service->scanned_mesh_network =
902 g_list_reverse(service->scanned_mesh_network);
903 /* LCOV_EXCL_START */
905 WMESH_LOGE("Failed DBus call [%s]", error->message);
907 return WMESHD_ERROR_IO_ERROR;
911 return WMESHD_ERROR_NONE;
914 int wmesh_gdbus_get_joined_mesh_network(wmesh_service *service)
916 GVariant *variant = NULL;
917 GError *error = NULL;
919 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
920 wmeshd_check_null_ret_error("connection", service->connection,
921 WMESHD_ERROR_INVALID_PARAMETER);
922 wmeshd_check_null_ret_error("_gproxy_connman",
923 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
925 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetMeshPeers",
927 G_DBUS_CALL_FLAGS_NONE,
930 WMESH_LOGD("Successfully requested. [GetMeshPeers]");
932 if (service->joined_network) {
933 /* LCOV_EXCL_START */
934 g_free(service->joined_network->mesh_id);
935 g_free(service->joined_network->bssid);
936 g_free(service->joined_network->ipv4_address);
937 g_free(service->joined_network->ipv4_netmask);
938 g_free(service->joined_network);
939 service->joined_network = NULL;
943 _get_joined_network(service, variant);
944 /* LCOV_EXCL_START */
946 WMESH_LOGE("Failed DBus call [%s]", error->message);
948 return WMESHD_ERROR_IO_ERROR;
952 return WMESHD_ERROR_NONE;
955 /* LCOV_EXCL_START */
956 int wmesh_gdbus_get_connected_peers(wmesh_service *service)
958 GVariant *variant = NULL;
959 GError *error = NULL;
961 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
962 wmeshd_check_null_ret_error("connection", service->connection,
963 WMESHD_ERROR_INVALID_PARAMETER);
964 wmeshd_check_null_ret_error("_gproxy_connman",
965 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
967 variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetConnectedMeshPeers",
969 G_DBUS_CALL_FLAGS_NONE,
972 WMESH_LOGD("Successfully requested. [GetConnectedMeshPeers]");
974 if (service->connected_mesh_peers) {
975 g_list_free_full(service->connected_mesh_peers, _on_peer_info_destroy);
976 service->connected_mesh_peers = NULL;
979 _get_connected_mesh_peers(service, variant);
981 /* List item is saved with reversed order for efficiency. */
982 service->connected_mesh_peers =
983 g_list_reverse(service->connected_mesh_peers);
985 WMESH_LOGE("Failed DBus call [%s]", error->message);
987 return WMESHD_ERROR_IO_ERROR;
990 return WMESHD_ERROR_NONE;
993 static void _get_mesh_property(GVariant *variant, wmesh_network_info_s *result)
995 GVariantIter *property = NULL;
997 GVariant *val = NULL;
1000 WMESH_LOGD("Type [%s]", g_variant_get_type_string(variant));
1002 g_variant_get(variant, "(a{sv})", &property);
1004 while (g_variant_iter_loop(property, "{sv}", &key, &val)) {
1005 if (strcasecmp(key, "Name") == 0) {
1006 const char *buf = g_variant_get_string(val, &len);
1007 result->mesh_id = g_strdup(buf);
1008 WMESH_LOGD(" Mesh ID : %s", result->mesh_id);
1009 } else if (strcasecmp(key, "BSSID") == 0) {
1010 const char *buf = g_variant_get_string(val, &len);
1011 result->bssid = g_strdup(buf);
1012 WMESH_LOGD(" BSSID : %s", result->bssid);
1013 } else if (strcasecmp(key, "State") == 0) {
1014 const char *buf = g_variant_get_string(val, &len);
1015 WMESH_LOGD(" State : %s", buf);
1017 if (g_strcmp0(buf, "idle") == 0
1018 || g_strcmp0(buf, "disconnect") == 0
1019 || g_strcmp0(buf, "failure") == 0) {
1020 result->state = WMESHD_CONNECTION_STATE_DISCONNECTED;
1021 } else if (g_strcmp0(buf, "association") == 0) {
1022 result->state = WMESHD_CONNECTION_STATE_ASSOCIATION;
1023 } else if (g_strcmp0(buf, "configuration") == 0) {
1024 result->state = WMESHD_CONNECTION_STATE_CONFIGURATION;
1025 } else if (g_strcmp0(buf, "ready") == 0 || g_strcmp0(buf, "online") == 0) {
1026 result->state = WMESHD_CONNECTION_STATE_CONNECTED;
1028 } else if (strcasecmp(key, "Security") == 0) {
1029 const char *buf = g_variant_get_string(val, &len);
1030 WMESH_LOGD(" Security : %s", buf);
1031 if (g_strcmp0("sae", buf) == 0)
1032 result->security = WMESHD_SECURITY_SAE;
1034 result->security = WMESHD_SECURITY_NONE;
1035 } else if (strcasecmp(key, "Frequency") == 0) {
1036 result->channel = __frequency_to_channel(g_variant_get_uint16(val));
1037 WMESH_LOGD(" Channel : %d", result->channel);
1038 } else if (strcasecmp(key, "Favorite") == 0) {
1039 const char *buf = g_variant_get_string(val, &len);
1040 WMESH_LOGD(" Favorite : %s", buf);
1041 } else if (strcasecmp(key, "Strength") == 0) {
1042 gint rssi = (gint)g_variant_get_byte(val);
1043 WMESH_LOGD(" RSSI : %d", rssi);
1046 g_variant_iter_free(property);
1048 /* LCOV_EXCL_STOP */
1050 static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service,
1051 const gchar* object_path, wmesh_network_info_s *result)
1053 GVariant *variant = NULL;
1054 GError *error = NULL;
1056 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1057 wmeshd_check_null_ret_error("connection", service->connection,
1058 WMESHD_ERROR_INVALID_PARAMETER);
1059 wmeshd_check_null_ret_error("result", result, WMESHD_ERROR_INVALID_PARAMETER);
1061 variant = g_dbus_connection_call_sync(service->connection,
1062 CONNMAN_SERVER_NAME,
1064 CONNMAN_INTERFACE_MESH,
1067 G_DBUS_CALL_FLAGS_NONE,
1070 WMESH_LOGD("Successfully requested. [GetProperties]");
1072 /* Get properties */
1073 _get_mesh_property(variant, result);
1074 /* LCOV_EXCL_START */
1076 LOGE("Failed DBus call [%s]", error->message);
1077 g_error_free(error);
1078 return WMESHD_ERROR_IO_ERROR;
1080 /* LCOV_EXCL_STOP */
1082 return WMESHD_ERROR_NONE;
1085 int wmesh_gdbus_create_network(wmesh_service *service, gchar *mesh_id,
1086 gint channel, wmeshd_security_type_e sec, wmeshd_pmf_type_e pmf)
1088 GVariant *variant = NULL;
1089 GError *error = NULL;
1090 GVariant *var_dict = NULL;
1091 GVariantBuilder builder;
1092 const gchar* security = (WMESHD_SECURITY_SAE == sec) ? "sae" : "none";
1094 enum nl80211_band band = (channel <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1095 gushort freq = __channel_to_frequency(channel, band);
1097 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1098 wmeshd_check_null_ret_error("connection", service->connection,
1099 WMESHD_ERROR_INVALID_PARAMETER);
1100 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1101 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1103 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
1104 g_variant_builder_open(&builder, G_VARIANT_TYPE("a{sv}"));
1106 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1107 g_variant_builder_add(&builder, "s", "Name");
1108 g_variant_builder_add(&builder, "v", g_variant_new_string(mesh_id));
1109 g_variant_builder_close(&builder); /* {sv} */
1111 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1112 g_variant_builder_add(&builder, "s", "Frequency");
1113 g_variant_builder_add(&builder, "v", g_variant_new_uint16(freq));
1114 g_variant_builder_close(&builder); /* {sv} */
1116 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1117 g_variant_builder_add(&builder, "s", "Security");
1118 g_variant_builder_add(&builder, "v", g_variant_new_string(security));
1119 g_variant_builder_close(&builder); /* {sv} */
1121 g_variant_builder_open(&builder, G_VARIANT_TYPE("{sv}"));
1122 g_variant_builder_add(&builder, "s", "Pmf");
1123 g_variant_builder_add(&builder, "v", g_variant_new_uint16(pmf));
1124 g_variant_builder_close(&builder); /* {sv} */
1126 g_variant_builder_close(&builder); /* a{sv} */
1128 var_dict = g_variant_builder_end(&builder);
1130 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
1131 g_variant_new("(sv)", "MeshCreateNetwork", var_dict),
1132 G_DBUS_CALL_FLAGS_NONE,
1134 g_variant_builder_unref(&builder);
1136 WMESH_LOGD("Successfully requested. [MeshCreateNetwork]"); /* LCOV_EXCL_LINE */
1137 /* LCOV_EXCL_START */
1139 WMESH_LOGE("Failed DBus call [%s]", error->message);
1140 g_error_free(error);
1141 return WMESHD_ERROR_IO_ERROR;
1143 /* LCOV_EXCL_STOP */
1145 return WMESHD_ERROR_NONE;
1148 /* LCOV_EXCL_START */
1149 int wmesh_gdbus_set_passphrase(wmesh_service *service, wmesh_scan_result_s *info, gchar *passphrase)
1151 int ret = WMESHD_ERROR_NONE;
1152 GVariant *variant = NULL;
1153 GVariant *var_passphrase = NULL;
1154 GError *error = NULL;
1156 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1157 wmeshd_check_null_ret_error("passphrase", passphrase, WMESHD_ERROR_INVALID_PARAMETER);
1159 var_passphrase = g_variant_new_string(passphrase);
1160 variant = g_dbus_connection_call_sync(service->connection,
1161 CONNMAN_SERVER_NAME,
1163 CONNMAN_INTERFACE_MESH,
1165 g_variant_new("(sv)", "Passphrase", var_passphrase),
1167 G_DBUS_CALL_FLAGS_NONE,
1170 WMESH_LOGD("Successfully requested. [SetProperty]");
1172 LOGE("Failed DBus call [%s]", error->message);
1173 g_error_free(error);
1174 ret = WMESHD_ERROR_IO_ERROR;
1176 g_variant_unref(var_passphrase);
1181 static void on_response_connect_network(GObject *source_object,
1182 GAsyncResult *res, gpointer user_data)
1184 int ret = WMESHD_ERROR_NONE;
1185 GError *error = NULL;
1186 GVariant *variant = NULL;
1190 variant = g_dbus_connection_call_finish(
1191 G_DBUS_CONNECTION(source_object), res, &error);
1193 WMESH_LOGD("Successfully requested. [Connect]");
1195 /* TODO: Unregister property change event */
1197 ret = WMESHD_ERROR_IO_ERROR;
1198 LOGE("Failed DBus call [%s]", error->message);
1200 if (g_strrstr(error->message, "Already exists"))
1201 ret = WMESHD_ERROR_ALREADY_REGISTERED;
1202 else if (g_strrstr(error->message, "In progress"))
1203 ret = WMESHD_ERROR_IN_PROGRESS;
1205 ret = WMESHD_ERROR_IO_ERROR;
1207 g_error_free(error);
1212 int wmesh_gdbus_connect_network(wmesh_service *service, wmesh_scan_result_s *info)
1214 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1215 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1217 g_dbus_connection_call(service->connection,
1218 CONNMAN_SERVER_NAME,
1220 CONNMAN_INTERFACE_MESH,
1223 G_DBUS_CALL_FLAGS_NONE,
1225 NULL, /* G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED */
1227 WMESH_LOGD("Successfully requested. [Connect]");
1229 return WMESHD_ERROR_NONE;
1232 int wmesh_gdbus_disconnect_network(wmesh_service *service, wmesh_scan_result_s *info)
1234 GVariant *variant = NULL;
1235 GError *error = NULL;
1237 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1238 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1240 variant = g_dbus_connection_call_sync(service->connection,
1241 CONNMAN_SERVER_NAME,
1243 CONNMAN_INTERFACE_MESH,
1246 G_DBUS_CALL_FLAGS_NONE,
1249 WMESH_LOGD("Successfully requested. [Disconnect]");
1251 LOGE("Failed DBus call [%s]", error->message);
1252 g_error_free(error);
1253 return WMESHD_ERROR_IO_ERROR;
1256 return WMESHD_ERROR_NONE;
1259 int wmesh_gdbus_remove_network(wmesh_service *service, wmesh_scan_result_s *info)
1261 GVariant *variant = NULL;
1262 GError *error = NULL;
1264 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1265 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1267 variant = g_dbus_connection_call_sync(service->connection,
1268 CONNMAN_SERVER_NAME,
1270 CONNMAN_INTERFACE_MESH,
1273 G_DBUS_CALL_FLAGS_NONE,
1276 WMESH_LOGD("Successfully requested. [Remove]");
1278 LOGE("Failed DBus call [%s]", error->message);
1279 g_error_free(error);
1280 return WMESHD_ERROR_IO_ERROR;
1283 return WMESHD_ERROR_NONE;
1287 int wmesh_gdbus_enable_ethernet_interface(wmesh_service *service, bool state)
1289 int ret = WMESHD_ERROR_NONE;
1290 GVariant *variant = NULL;
1291 GVariant *var_state = NULL;
1292 GError *error = NULL;
1293 wmesh_interface_s *info = NULL;
1295 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1296 wmeshd_check_null_ret_error("connection", service->connection,
1297 WMESHD_ERROR_INVALID_PARAMETER);
1298 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1299 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1301 info = service->interface_info;
1302 wmeshd_check_null_ret_error("info", info, WMESHD_ERROR_INVALID_PARAMETER);
1304 var_state = g_variant_new_boolean(state);
1305 variant = g_dbus_proxy_call_sync(_gproxy_connman_ethernet, "SetProperty",
1306 g_variant_new("(sv)", "Powered", var_state),
1307 G_DBUS_CALL_FLAGS_NONE,
1310 WMESH_LOGD("Successfully requested. [Powered]");
1312 ret = WMESHD_ERROR_IO_ERROR;
1313 WMESH_LOGE("Failed DBus call [%s]", error->message);
1315 /* Interface not exists (Not created yet) */
1316 if (g_strrstr(error->message, "No such device"))
1317 ret = WMESHD_ERROR_NONE;
1318 g_error_free(error);
1320 g_variant_unref(var_state);
1324 /* LCOV_EXCL_STOP */
1326 int wmesh_gdbus_set_mesh_gate(wmesh_service *service)
1328 int ret = WMESHD_ERROR_NONE;
1329 GVariant *variant = NULL;
1330 GError *error = NULL;
1331 GVariant *var_dict = NULL;
1333 wmesh_interface_s *info = NULL;
1335 wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER);
1336 wmeshd_check_null_ret_error("connection", service->connection,
1337 WMESHD_ERROR_INVALID_PARAMETER);
1338 wmeshd_check_null_ret_error("_gproxy_connman_technology",
1339 _gproxy_connman_technology, WMESHD_ERROR_IO_ERROR);
1341 info = service->interface_info;
1343 g_variant_dict_init(&dict, NULL);
1344 g_variant_dict_insert(&dict, "GateAnnounce", "b", info->gate_announce);
1345 g_variant_dict_insert(&dict, "HWMPRootMode", "q", info->hwmp_root_mode);
1346 g_variant_dict_insert(&dict, "STP", "q", info->stp);
1347 var_dict = g_variant_dict_end(&dict);
1349 variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
1350 g_variant_new("(sv)", "SetMeshGate", var_dict),
1351 G_DBUS_CALL_FLAGS_NONE,
1354 WMESH_LOGD("Successfully requested. [SetMeshGate]"); /* LCOV_EXCL_LINE */
1355 /* LCOV_EXCL_START */
1357 ret = WMESHD_ERROR_IO_ERROR;
1358 WMESH_LOGE("Failed DBus call [%s]", error->message);
1360 /* Interface not exists */
1361 if (g_strrstr(error->message, "No such device"))
1362 ret = WMESHD_ERROR_INVALID_PARAMETER;
1363 g_error_free(error);
1365 /* LCOV_EXCL_STOP */
1370 /* LCOV_EXCL_START */
1371 int wmesh_gdbus_mesh_remove_peer(wmesh_service *service, char *peer)
1373 GVariant *variant = NULL;
1374 GError *error = NULL;
1375 int ret = WMESHD_ERROR_NONE;
1377 wmeshd_check_null_ret_error("service", service,
1378 WMESHD_ERROR_INVALID_PARAMETER);
1379 wmeshd_check_null_ret_error("connection", service->connection,
1380 WMESHD_ERROR_INVALID_PARAMETER);
1381 wmeshd_check_null_ret_error("_gproxy_connman",
1382 _gproxy_connman, WMESHD_ERROR_IO_ERROR);
1384 variant = g_dbus_proxy_call_sync(_gproxy_connman, "MeshRemovePeer",
1385 g_variant_new("(s)", peer), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
1388 WMESH_LOGD("Successfully requested. [MeshRemovePeer]");
1390 ret = WMESHD_ERROR_IO_ERROR;
1391 WMESH_LOGE("Failed DBus call [%s]", error->message);
1393 /* Interface not exists */
1394 if (g_strrstr(error->message, "No such device"))
1395 ret = WMESHD_ERROR_INVALID_PARAMETER;
1396 g_error_free(error);
1401 /* LCOV_EXCL_STOP */