From 6f93acdf013f34fd4899c61118311260af0ea3ab Mon Sep 17 00:00:00 2001 From: saerome kim Date: Fri, 3 Mar 2017 21:20:10 +0900 Subject: [PATCH] Apply changed Dbus methods Signed-off-by: saerome kim --- include/mesh.h | 87 +++++++++++++--- include/mesh_dbus.h | 6 +- include/mesh_private.h | 54 ++++++++++ src/mesh.c | 14 ++- src/mesh_dbus.c | 226 +++++++++++++++++++++++++++++++++++++++-- test/mesh_device.c | 2 +- 6 files changed, 353 insertions(+), 36 deletions(-) mode change 100644 => 100755 include/mesh.h mode change 100644 => 100755 include/mesh_dbus.h mode change 100644 => 100755 include/mesh_private.h mode change 100644 => 100755 src/mesh.c mode change 100644 => 100755 src/mesh_dbus.c mode change 100644 => 100755 test/mesh_device.c diff --git a/include/mesh.h b/include/mesh.h old mode 100644 new mode 100755 index f237e88..c065f8e --- a/include/mesh.h +++ b/include/mesh.h @@ -50,17 +50,17 @@ typedef void *mesh_h; * @since_tizen 4.0 */ typedef enum { - MESH_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + MESH_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ MESH_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - MESH_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ - MESH_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + MESH_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ + MESH_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ MESH_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED, /**< Address family not supported */ - MESH_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Now in progress */ - MESH_ERROR_OPERATION_FAILED = TIZEN_ERROR_MESH|0x01, /**< Operation failed */ - MESH_ERROR_OPERATION_ABORTED = TIZEN_ERROR_MESH|0x02, /**< Operation is aborted */ - MESH_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission Denied */ - MESH_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< DBus error */ - MESH_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not Supported */ + MESH_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Now in progress */ + MESH_ERROR_OPERATION_FAILED = TIZEN_ERROR_MESH|0x01, /**< Operation failed */ + MESH_ERROR_OPERATION_ABORTED = TIZEN_ERROR_MESH|0x02, /**< Operation is aborted */ + MESH_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission Denied */ + MESH_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< DBus error */ + MESH_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not Supported */ } mesh_error_e; /** @@ -90,8 +90,8 @@ typedef enum { * @since_tizen 4.0 */ typedef enum { - MESH_STATE_DEACTIVATED = 0, /**< Mesh network is Deactivated */ - MESH_STATE_ACTIVATED = 1, /**< Mesh network is activated */ + MESH_STATE_DEACTIVATED = 0, /**< Mesh network is Deactivated */ + MESH_STATE_ACTIVATED = 1, /**< Mesh network is activated */ } mesh_state_e; /** @@ -103,6 +103,25 @@ typedef enum { * @{ */ + +/** + * @brief The mesh network profile handle. + * @since_tizen 4.0 +*/ +typedef void* mesh_network_h; + +/** + * @brief The mesh station information handle. + * @since_tizen 4.0 +*/ +typedef void* mesh_station_info_h; + +/** + * @brief The mesh path information handle. + * @since_tizen 4.0 +*/ +typedef void* mesh_path_info_h; + /** * @brief Initializes Mesh network. * @since_tizen 4.0 @@ -167,7 +186,6 @@ typedef void (*mesh_event_cb)(mesh_event_e event_type, void* param); * if mesh service is no longer needed. * * @param[in] handle The mesh handle - * @param[in] interface The interface name of mesh network * @param[in] event_handler The event handler * * @return 0 on success, otherwise a negative error value. @@ -181,7 +199,7 @@ typedef void (*mesh_event_cb)(mesh_event_e event_type, void* param); * @see mesh_disable() * */ -int mesh_enable(mesh_h handle, const char* interface, mesh_event_cb event_handler); +int mesh_enable(mesh_h handle, mesh_event_cb event_handler); /** * @brief disable the mesh service. @@ -271,6 +289,43 @@ int mesh_specific_scan(mesh_h handle, const char* ssid, int channel); */ int mesh_cancel_scan(mesh_h handle); +/** + * @brief + * @details This function can receive scan results from mesh network. + * + * @since_tizen 4.0 + * + * @param[out] network mesh bss information handle + * @param[out] user_data user data pointer + * + * @pre The callback must be registered with mesh_enable() + * + * @see mesh_foreach_found_mesh_netwrok() + */ +typedef void (*mesh_found_mesh_netwrok_cb)(mesh_network_h network, void* user_data); + +/** + * @brief + * @details + * + * @since_tizen 4.0 + * + * @param[in] handle The mesh handle + * @param[in] cb callback function pointer to inform bss information + * @param[in] user_data user data pointer + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #MESH_ERROR_NONE Successful + * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see mesh_scan() + * @see mesh_found_mesh_netwrok_cb() + * + */ +int mesh_foreach_found_mesh_netwrok(mesh_h handle, mesh_found_mesh_netwrok_cb cb, void *user_data); + /** * @brief Get information of all connected stations. * @details Get information about all stations present in the currently connected mesh network. @@ -278,6 +333,7 @@ int mesh_cancel_scan(mesh_h handle); * @since_tizen 4.0 * * @param[in] handle The mesh handle + * @param[out] station The mesh station information handle * * * @return 0 on success, otherwise a negative error value. @@ -289,7 +345,7 @@ int mesh_cancel_scan(mesh_h handle); * @see mesh_deinitialize() * */ -int mesh_get_station_info(mesh_h handle); +int mesh_get_station_info(mesh_h handle, mesh_station_info_h station); /** * @brief Get information of all mesh paths. @@ -298,6 +354,7 @@ int mesh_get_station_info(mesh_h handle); * @since_tizen 4.0 * * @param[in] handle The mesh handle + * @param[out] path The mesh path information handle * * * @return 0 on success, otherwise a negative error value. @@ -309,7 +366,7 @@ int mesh_get_station_info(mesh_h handle); * @see mesh_deinitialize() * */ -int mesh_get_mpath_info(mesh_h handle); +int mesh_get_path_info(mesh_h handle, mesh_path_info_h path); /** * @brief Join into specific mesh network. diff --git a/include/mesh_dbus.h b/include/mesh_dbus.h old mode 100644 new mode 100755 index 70d4fc3..3ad7e52 --- a/include/mesh_dbus.h +++ b/include/mesh_dbus.h @@ -33,13 +33,13 @@ extern "C" { int _mesh_dbus_start(mesh_h m); int _mesh_dbus_stop(mesh_h m); -int _mesh_enable(mesh_h handle, const char* interface, mesh_event_cb event_handler); +int _mesh_enable(mesh_h handle, mesh_event_cb event_handler); int _mesh_disable(mesh_h handle); int _mesh_scan(mesh_h handle); int _mesh_specific_scan(mesh_h handle, const char* ssid, int channel); int _mesh_cancel_scan(mesh_h handle); -int _mesh_get_station_info(mesh_h handle); -int _mesh_get_mpath_info(mesh_h handle); +int _mesh_get_station_info(mesh_h handle, void *station); +int _mesh_get_path_info(mesh_h handle, void *mpath_data); int _mesh_join(mesh_h handle, const char* ssid); int _mesh_is_joined(mesh_h handle, int is_joined); int _mesh_disjoin(mesh_h handle); diff --git a/include/mesh_private.h b/include/mesh_private.h old mode 100644 new mode 100755 index 1822506..695fa7a --- a/include/mesh_private.h +++ b/include/mesh_private.h @@ -82,6 +82,60 @@ struct mesh_handle { #endif } mesh_handle_s; +struct mesh_found_network_s { + char *meshid; /**< meshid */ + char *bssid; /**< bssid */ + int channel; /**< channel */ + int rssi; /**< rssi */ + int data_rate; /**< data rate */ +}; + +struct mesh_station_info_s { + char *station; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */ + guint inactive_time; /**< inactive time ex) 1685 ms */ + guint rx_bytes; /**< rx bytes ex) 34174 */ + guint rx_packets; /**< rx packet ex) 1181 */ + guint tx_bytes; /**< tx bytes ex) 6877 */ + guint tx_packets; /**< tx packets ex) 76 */ + guint tx_retries; /**< tx retries ex) 0 */ + guint tx_failed; /**< tx failed ex) 0 */ + guint beacon_loss; /**< beacon loss count ex) 0 */ + int signal; /**< -64 dBm */ + int signal_avg; /**< -63 dBm */ + guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */ + guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */ + guint mesh_llid; /**< mesh_llid ex) 51731 */ + guint mesh_plid; /**< mesh plid ex) 35432 */ + char *mesh_plink; /**< mesh plink ex) ESTAB */ + char *mesh_local_PS_mode; /**< mesh local power save mode ex) ACTIVE */ + char *mesh_peer_PS_mode; /**< mesh peer power save mode ex) ACTIVE */ + char *mesh_non_peer_PS_mode; /**< mesh non-peer power save mode ex) ACTIVE */ + bool authorized; /**< autorized ex) yes */ + bool authenticated; /**< authenticated ex) yes */ + bool associated; /**< associated ex) yes */ + char *preamble; /**< preamble ex) long */ + bool WMM_WME; /**< WMM/WME supported ex) yes */ + bool MFP; /**< MFP ex) no */ + bool TDLS_peer; /**< TDLS peer ex) no */ + guint DTIM_period; /**< DTIM period ex) 0 */ + guint beacon_interval; /**< beacon interbal ex) 1000 */ + guint short_slot_time; /**< short slot time supported ex) yes */ + guint connected_time; /**< connected time : ex) 256 seconds */ +}; + +struct mesh_mpath_dump_s { + char *dest_addr; /**< destination address */ + char *next_hop; /**< next hop address */ + char *iface; /**< network interface for mesh */ + int sn; /**< sequence number */ + int metric; /**< metric */ + int qlen; /**< driver queue length */ + int exptime; /**< expire time */ + int dtim; /**< DTIM interval */ + int dret; /**< dret */ + int flags; /**< flags */ +}; + const char* _mesh_internal_error_to_string(mesh_internal_err_e err); #endif /* __CAPI_MESH_PRIVATE_H__ */ diff --git a/src/mesh.c b/src/mesh.c old mode 100644 new mode 100755 index c5f89be..24c94c5 --- a/src/mesh.c +++ b/src/mesh.c @@ -72,16 +72,14 @@ EXPORT_API int mesh_deinitialize(mesh_h mesh) return MESH_ERROR_NONE; } -EXPORT_API int mesh_enable(mesh_h handle, const char* interface, - mesh_event_cb event_handler) +EXPORT_API int mesh_enable(mesh_h handle, mesh_event_cb event_handler) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - RETV_IF(NULL == interface, MESH_ERROR_INVALID_PARAMETER); RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_enable(handle, interface, event_handler); + rv = _mesh_enable(handle, event_handler); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } @@ -150,14 +148,14 @@ EXPORT_API int mesh_cancel_scan(mesh_h handle) return MESH_ERROR_NONE; } -EXPORT_API int mesh_get_station_info(mesh_h handle) +EXPORT_API int mesh_get_station_info(mesh_h handle, mesh_station_info_h station) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_get_station_info(handle); + rv = _mesh_get_station_info(handle, station); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } @@ -165,14 +163,14 @@ EXPORT_API int mesh_get_station_info(mesh_h handle) return MESH_ERROR_NONE; } -EXPORT_API int mesh_get_mpath_info(mesh_h handle) +EXPORT_API int mesh_get_path_info(mesh_h handle, mesh_path_info_h path) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_get_station_info(handle); + rv = _mesh_get_path_info(handle, path); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } diff --git a/src/mesh_dbus.c b/src/mesh_dbus.c old mode 100644 new mode 100755 index ea01a38..3da6a0a --- a/src/mesh_dbus.c +++ b/src/mesh_dbus.c @@ -142,7 +142,62 @@ int _mesh_dbus_stop(mesh_h handle) return rv; } -int _mesh_enable(mesh_h handle, const char* interface, mesh_event_cb event_handler) +struct mesh_network_list_s { + int count; + GList *list; +}; +struct mesh_network_list_s g_networks; + +static void _mesh_free_network(gpointer data) +{ + struct mesh_found_network_s *network = data; + g_free(network->meshid); + g_free(network->bssid); + g_free(network); + network = NULL; +} + +static void _mesh_append_network(gpointer data) +{ + g_networks.list = g_list_append(g_networks.list, data); + g_networks.count++; +} + +static void _mesh_remove_networks() +{ + g_list_free_full(g_networks.list, _mesh_free_network); + g_networks.count = 0; +} + +struct mesh_mpath_list_s { + int count; + GList *list; +}; +struct mesh_mpath_list_s g_mpath; + +static void _mesh_free_mpath(gpointer data) +{ + struct mesh_mpath_dump_s *mpath = data; + g_free(mpath->dest_addr); + g_free(mpath->next_hop); + g_free(mpath->iface); + g_free(mpath); + mpath = NULL; +} + +static void _mesh_add_mpath(gpointer data) +{ + g_mpath.list = g_list_append(g_mpath.list, data); + g_mpath.count++; +} + +static void _mesh_remove_mpath() +{ + g_list_free_full(g_mpath.list, _mesh_free_mpath); + g_mpath.count = 0; +} + +int _mesh_enable(mesh_h handle, mesh_event_cb event_handler) { GVariant *variant = NULL; unsigned int result; @@ -153,7 +208,7 @@ int _mesh_enable(mesh_h handle, const char* interface, mesh_event_cb event_handl RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "enable", - g_variant_new("(s)", interface), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); @@ -177,6 +232,9 @@ int _mesh_disable(mesh_h handle) GError *error = NULL; struct mesh_handle *h = handle; + _mesh_remove_networks(); + _mesh_remove_mpath(); + RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); @@ -279,13 +337,103 @@ int _mesh_cancel_scan(mesh_h handle) return MESH_ITNL_ERR_NONE; } -int _mesh_get_station_info(mesh_h handle) +int _mesh_foreach_found_mesh_netwrok(mesh_h handle, + mesh_found_mesh_netwrok_cb cb, void *user_data) +{ + GVariant *variant = NULL; + unsigned int result; + GError *error = NULL; + struct mesh_handle *h = handle; + + GVariant *params = NULL; + GVariant *inner_params = NULL; + GVariantIter iter, inner_iter; + + gchar *key; + GVariant *val; + gsize len = 0; + + _mesh_remove_networks(); + + RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_found_mesh_networks", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + /* handle station list here */ + g_variant_get(variant, "(a(a{sv})u)", ¶ms, &result); + + g_variant_iter_init(&iter, params); + while (g_variant_iter_loop(&iter, "(a{sv})", &inner_params)) { + + struct mesh_found_network_s *network_info = + g_malloc0(sizeof(struct mesh_found_network_s)); + + g_variant_iter_init(&inner_iter, inner_params); + while (g_variant_iter_loop(&inner_iter, "{sv}", &key, &val)) { + if (strcasecmp(key, "meshid") == 0) { + network_info->meshid = g_variant_dup_string(val, &len); + LOGE("meshid=%s", network_info->meshid); + } + else if (strcasecmp(key, "bssid") == 0) { + network_info->bssid = g_variant_dup_string(val, &len); + LOGE("bssid = %s", network_info->bssid); + } + else if (strcasecmp(key, "channel") == 0) { + network_info->channel = g_variant_get_int32(val); + LOGE("channel = %d", network_info->channel); + } + else if (strcasecmp(key, "rssi") == 0) { + network_info->rssi = g_variant_get_int32(val); + LOGE("rssi = %d", network_info->rssi); + } + else if (strcasecmp(key, "data_rate") == 0) { + network_info->data_rate = g_variant_get_int32(val); + LOGE("data_rate = %d", network_info->data_rate); + /* Last element */ + _mesh_append_network(network_info); + if (cb) cb(network_info, user_data); + } + } + g_variant_unref(inner_params); + } + g_variant_unref(params); + + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return MESH_ITNL_ERR_IO_ERROR; + } + + return MESH_ITNL_ERR_NONE; +} + +struct mesh_station_info_s g_station; + +int _mesh_get_station_info(mesh_h handle, void *station) { GVariant *variant = NULL; -// unsigned int result; + unsigned int result; GError *error = NULL; struct mesh_handle *h = handle; + GVariant *params = NULL; + GVariant *inner_params = NULL; + GVariantIter iter, inner_iter; + + gchar *key; + GVariant *val; + gsize len = 0; + + if (g_station.station) { + g_free(g_station.station); + } + memset(&g_station, 0, sizeof(g_station)); + RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); @@ -295,8 +443,31 @@ int _mesh_get_station_info(mesh_h handle) -1, NULL, &error); if (variant) { - //g_variant_get(variant, "(a(a{sv})", &result); + g_variant_get(variant, "(a(a{sv})u)", ¶ms, &result); + /* TODO: handle station list here */ + g_variant_iter_init(&iter, params); + while (g_variant_iter_loop(&iter, "(a{sv})", &inner_params)) { + + g_variant_iter_init(&inner_iter, inner_params); + while (g_variant_iter_loop(&inner_iter, "{sv}", &key, &val)) { + if (strcasecmp(key, "station") == 0) { + g_station.station = g_variant_dup_string(val, &len); + LOGE("station= %s", g_station.station); + } + else if (strcasecmp(key, "inactive_time") == 0) { + g_station.inactive_time = g_variant_get_uint32(val); + LOGE("inactive_time= %s", g_station.inactive_time); + } + else if (strcasecmp(key, "rx_bytes") == 0) { + g_station.rx_bytes = g_variant_get_uint32(val); + LOGE("rx_bytes= %s", g_station.rx_bytes); + } + } + g_variant_unref(inner_params); + } + g_variant_unref(params); + } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); @@ -304,15 +475,24 @@ int _mesh_get_station_info(mesh_h handle) } return MESH_ITNL_ERR_NONE; + } -int _mesh_get_mpath_info(mesh_h handle) +int _mesh_get_path_info(mesh_h handle, void* mpath_data) { GVariant *variant = NULL; -// unsigned int result; + unsigned int result; GError *error = NULL; struct mesh_handle *h = handle; + GVariant *params = NULL; + GVariant *inner_params = NULL; + GVariantIter iter, inner_iter; + + gchar *key; + GVariant *val; + gsize len = 0; + RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); @@ -322,8 +502,36 @@ int _mesh_get_mpath_info(mesh_h handle) -1, NULL, &error); if (variant) { - //g_variant_get(variant, "(a(a{sv})", &result); - /* TODO: handle mpath list here */ + g_variant_get(variant, "(a(a{sv})u)", ¶ms, &result); + + /* handle station list here */ + _mesh_remove_mpath(); + + g_variant_iter_init(&iter, params); + while (g_variant_iter_loop(&iter, "(a{sv})", &inner_params)) { + struct mesh_mpath_dump_s *mpath = g_malloc0(sizeof(struct mesh_mpath_dump_s)); + g_variant_iter_init(&inner_iter, inner_params); + while (g_variant_iter_loop(&inner_iter, "{sv}", &key, &val)) { + if (strcasecmp(key, "dest_addr") == 0) { + mpath->dest_addr = g_variant_dup_string(val, &len); + LOGE("dest_addr= %s", mpath->dest_addr); + } + else if (strcasecmp(key, "next_hop") == 0) { + mpath->next_hop = g_variant_dup_string(val, &len); + LOGE("next_hop= %s", mpath->next_hop); + } + else if (strcasecmp(key, "iface") == 0) { + mpath->iface = g_variant_dup_string(val, &len); + LOGE("iface= %s", mpath->iface); + } + + _mesh_add_mpath((gpointer)mpath); + } + g_variant_unref(inner_params); + } + + g_variant_unref(params); + } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); diff --git a/test/mesh_device.c b/test/mesh_device.c old mode 100644 new mode 100755 index 5196672..a6e2c0f --- a/test/mesh_device.c +++ b/test/mesh_device.c @@ -67,7 +67,7 @@ static int run_mesh_enable(MManager *mm, struct menu_data *menu) int ret; msg("enable"); - ret = mesh_enable(mesh, data_mesh_interface, event_cb); + ret = mesh_enable(mesh, event_cb); if (ret != 0) { msg("Failed to enable mesh network: [%s(0x%X)]", mesh_error_to_string(ret), ret); -- 2.34.1