From: saerome.kim Date: Tue, 4 Jul 2017 12:17:59 +0000 (+0900) Subject: Change package name to capi-network-wifi-mesh X-Git-Tag: submit/tizen/20170828.225740~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3068dd95439f6daf95e2a126101206c98ee00777;p=platform%2Fcore%2Fapi%2Fwifi-mesh.git Change package name to capi-network-wifi-mesh Signed-off-by: saerome.kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a9eb25d..7de7068 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(fw_name "capi-network-mesh") +SET(fw_name "capi-network-wifi-mesh") PROJECT(${fw_name}) @@ -48,8 +48,7 @@ INSTALL(TARGETS ${fw_name} DESTINATION ${LIB}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/network FILES_MATCHING - PATTERN "mesh_*.h" EXCLUDE - PATTERN "service_*.h" EXCLUDE + PATTERN "wifi-mesh_*.h" EXCLUDE PATTERN "${INC_DIR}/*.h" ) diff --git a/capi-network-mesh.pc.in b/capi-network-mesh.pc.in deleted file mode 100644 index 2b4a65f..0000000 --- a/capi-network-mesh.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -# Package Information for pkg-config - -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix}/bin -libdir=@LIB_INSTALL_DIR@ -includedir=${prefix}/include/network - -Name: @PC_NAME@ -Description: @PACKAGE_DESCRIPTION@ -Version: @FULLVER@ -Requires: @PC_REQUIRED@ -Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} diff --git a/capi-network-wifi-mesh.pc.in b/capi-network-wifi-mesh.pc.in new file mode 100644 index 0000000..2b4a65f --- /dev/null +++ b/capi-network-wifi-mesh.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix}/bin +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include/network + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @FULLVER@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/doc/wifi-mesh-doc.h b/doc/wifi-mesh-doc.h new file mode 100644 index 0000000..3905feb --- /dev/null +++ b/doc/wifi-mesh-doc.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __TIZEN_NETWORK_WIFI_MESH_DOC_H__ +#define __TIZEN_NETWORK_WIFI_MESH_DOC_H__ + +/** + * @ingroup CAPI_NETWORK_FRAMEWORK + * @defgroup CAPI_NETWORK_WIFI_MESH_MODULE Wi-Fi Mesh + * @brief This provides APIs to manage Wi-Fi Mesh. + * + * @section CAPI_NETWORK_WIFI_MESH_MODULE_HEADER Header + * \#include + * + * @section CAPI_NETWORK_WIFI_MESH_MODULE_OVERVIEW Overview + * This set of functions is used to manage the settings of Wi-Fi Mesh network. + * In addition, this set provides functions to connect and disconnect remote devices using Wi-Fi Mesh. + * + * @subsection CAPI_NETWORK_WIFI_MESH_MODULE_REFERENCE Wi-Fi Mesh Reference + * - https://standards.ieee.org/findstds/standard/802.11s-2011.html/ + * - http://linuxwireless.org/en/developers/Documentation/ieee80211/802.11s/ + * + * @section CAPI_NETWORK_WIFI_MESH_MODULE_FEATURE Related Features + * These APIs are related with the following features:\n + * - http://tizen.org/feature/network.mesh\n + * - http://tizen.org/feature/network.mesh.admin\n + * + * It is recommended to design applications with regard to features, for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on using features in your application can be found in the Feature List. + * + */ + +#endif __TIZEN_NETWORK_WIFI_MESH_DOC_H__ + diff --git a/include/mesh-internal.h b/include/mesh-internal.h deleted file mode 100644 index d92b201..0000000 --- a/include/mesh-internal.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __TIZEN_MESH_INTERNAL_H__ -#define __TIZEN_MESH_INTERNAL_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file mesh-internal.h - */ - -/** - * @brief The HWMP type for mesh_hwmp_root_mode_e - * - * @since_tizen 4.0 - */ -typedef enum { - MESH_HWMP_ROOT_REACTIVE_MODE = 0, /**< Disable Proative Mode */ - MESH_HWMP_ROOT_SIMPLE_PROACTIVE_MODE = 2, /**< Enable the Proactive PREQ with no PREP */ - MESH_HWMP_ROOT_FORCED_PROACTIVE_MODE = 3, /**< Enable the Proactive PREQ with PREP. - Once you do this, all the nodes in your mesh will proactively create paths to your gate. - Mesh nodes will send to gate(s) all traffic to those destinations that could not be resolved in the mesh. */ - MESH_HWMP_ROOT_PROACTIVE_WITH_RANN_MODE = 4, /**< If we use HWMP_ROOTMODE as 4, every 5 sec, - our DUT sends action_frame with root announce. */ -} mesh_hwmp_root_mode_e; - -/** - * @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_mpath_info_h; - -/** - * @brief Gets the maximum data rate. - * @details This function is to get the maximum data rate - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] data_rate The maximum data rate. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_data_rate() - * - */ -int mesh_network_get_data_rate(mesh_network_h network, int *data_rate); - -/** - * @brief Sets the maximum data rate. - * @details This function is to set the maximum data rate - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] data_rate The maximum data rate. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_data_rate() - * - */ -int mesh_network_set_data_rate(mesh_network_h network, int data_rate); - -/** - * @brief Cancel scanning for the mesh network. - * @details Stop scanning process of mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * - * @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_specific_scan() - * @see mesh_scan() - * - */ -int mesh_cancel_scan(mesh_h handle); - -/** - * @brief Sets gate options - * @details This function sets mesh gate options. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] gate_announce Enable / Disable Gate Announce to peers - * @param[in] hwmp_root_mode HWMP (Hybrid Wireless Mesh Protocol) Root Mode \n - * #MESH_HWMP_ROOT_REACTIVE_MODE \n - * #MESH_HWMP_ROOT_SIMPLE_PROACTIVE_MODE \n - * #MESH_HWMP_ROOT_FORCED_PROACTIVE_MODE \n - * #MESH_HWMP_ROOT_PROACTIVE_WITH_RANN_MODE \n - * @param[in] stp Enable / Disable Gate Announce to peers - * - * - * @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_unset_gate() - * - */ -int mesh_set_gate(mesh_h handle, int gate_announce, int hwmp_root_mode, bool stp); - -/** - * @brief Unsets gate options - * @details This function unsets mesh gate options. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * - * @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_set_gate() - * - */ -int mesh_unset_gate(mesh_h handle); - -/** - * @brief Called after mesh_get_stations_info() - * @details This function can receive joined station information from mesh network. - * - * @since_tizen 4.0 - * - * @param[out] station mesh station information handle - * @param[out] user_data user data pointer - * - * @pre The callback must be registered with mesh_foreach_found_mesh_network() - * - * @see mesh_foreach_found_mesh_network() - */ -typedef void (*mesh_found_station_cb)(mesh_station_info_h station, void* user_data); - -/** - * @brief Get information of all connected stations. - * @details Get information about all stations present in the currently connected mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] cb The callback function to receive station information - * @param[in] user_data User data - * - * - * @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_get_path_info() - * - */ -int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data); - -/** - * @brief Called after mesh_get_stations_info() - * @details This function can receive joined station information from mesh network. - * - * @since_tizen 4.0 - * - * @param[out] path mesh path information handle - * @param[out] user_data user data pointer - * - * @pre The callback must be registered with mesh_foreach_found_mesh_network() - * - * @see mesh_foreach_found_mesh_network() - */ -typedef void (*mesh_found_mpath_cb)(mesh_mpath_info_h path, void* user_data); - -/** - * @brief Get information of all mesh paths. - * @details Get information about all mesh paths present in the currently connected mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] cb The callback function to receive mesh path information - * @param[in] user_data User data - * - * - * @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_get_stations_info() - * - */ -int mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data); - -/** - * @brief Sets network device interface name. - * @details This function provides the ability to manually select interfaces for advanced users. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] mesh An interface name for mesh network - * @param[in] gate An interface name for external network - * @param[in] softap An interface name for internal softap - * - * - * @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 - * - */ -int mesh_set_interfaces(mesh_h handle, - const char *mesh, const char* gate, const char *softap); - -#ifdef __cplusplus -} -#endif - -#endif /* __TIZEN_MESH_INTERNAL_H__ */ diff --git a/include/mesh.h b/include/mesh.h deleted file mode 100644 index fb6895f..0000000 --- a/include/mesh.h +++ /dev/null @@ -1,1009 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __TIZEN_MESH_H__ -#define __TIZEN_MESH_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file mesh.h - */ - -/** -* @addtogroup CAPI_NETWORK_MESH_MODULE -* @{ -*/ - -/** - * @brief The mesh handle. - * @since_tizen 4.0 -*/ -typedef void *mesh_h; - -/*********************************************************************** - TEMP -***********************************************************************/ -#ifndef TIZEN_ERROR_MESH -#define TIZEN_ERROR_MESH -0x02F60000 -#endif - -/** - * @brief Enumeration for the Mesh error type. - * @since_tizen 4.0 - */ -typedef enum { - 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_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ - MESH_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ - MESH_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */ - MESH_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ - 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_OPERATION_FAILED = TIZEN_ERROR_MESH | 0x01, /**< Operation failed */ - MESH_ERROR_OPERATION_ABORTED = TIZEN_ERROR_MESH | 0x02, /**< Operation is aborted */ - MESH_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_MESH | 0x03, /**< Mesh Already Initialized */ -} mesh_error_e; - -/** -* @} -*/ - -/** -* @addtogroup CAPI_NETWORK_MESH_MONITOR_MODULE -* @{ -*/ - -/** - * @brief The maximum length of mesh id - * - * @since_tizen 4.0 - */ -#define MAX_MESHID_LEN 32 - -/** - * @brief The maximum length of BSSID - * - * @since_tizen 4.0 - */ -#define MAX_BSSID_LEN 18 - -/** - * @brief The maximum length of passphrase - * - * @since_tizen 4.0 - */ -#define MAX_PASSPHRASE_LEN (64+1) - -/** - * @brief Enumeration for the security type of the Mesh network. - * @since_tizen 4.0 - */ -typedef enum { - MESH_SECURITY_NONE = 0, /**< Open network */ - MESH_SECURITY_SAE, /**< Simultaneous Authentication of Equals */ -} mesh_security_type_e; - -/** - * @brief Enumeration for the connection state of the Mesh network. - * @since_tizen 4.0 - */ -typedef enum { - MESH_CONNECTION_STATE_DISCONNECTED = 0, /**< Mesh network is disconnected */ - MESH_CONNECTION_STATE_ASSOCIATION, /**< Service is trying to establish low-level network connection to the mesh network. */ - MESH_CONNECTION_STATE_CONFIGURATION, /**< Service is trying to retrieve/configure IP settings. */ - MESH_CONNECTION_STATE_CONNECTED /**< Mesh network is connected */ -} mesh_connection_state_e; - -/** - * @brief The events for mesh_event_cb - * - * @since_tizen 4.0 - */ -typedef enum { - MESH_EVENT_ENABLED = 0x00, /**< This event is received after enabling mesh network */ - MESH_EVENT_SCAN_DONE = 0x01, /**< This event comes after scanning operation completed */ - MESH_EVENT_CONNECTION_STATE = 0x02, /**< This event takes place when mesh network connection state is changed */ - MESH_EVENT_STATION_JOIN = 0x03, /**< This event takes place when new station joined */ - MESH_EVENT_STATION_LEFT = 0x04, /**< This event takes place when existing station left */ -} mesh_event_e; - -/** - * @brief The structure type for the MESH_EVENT_ENABLED callback data. - * @details The result of creating or joining mesh network. - * - * @since_tizen 4.0 - */ -typedef struct { - int result; /**< The result of creating or joining mesh network */ -} mesh_mesh_enabled_event_s; - -/** - * @brief The structure type for the MESH_EVENT_STATION_JOIN or MESH_EVENT_STATION_LEFT callback data. - * @details Result of join or left event of other station. - * - * @since_tizen 4.0 - */ -typedef struct { - char bssid[MAX_BSSID_LEN]; /**< The BSSID of the station that generated the event */ -} mesh_other_station_event_s; - -/** - * @brief The structure type for the MESH_EVENT_CONNECTION_STATE callback data. - * @details The state of mesh network connection. - * - * @since_tizen 4.0 - */ -typedef struct { - char mesh_id[MAX_MESHID_LEN]; /**< The Mesh ID of the network that generated the event */ - char bssid[MAX_BSSID_LEN]; /**< The BSSID of the network that generated the event */ - int channel; /**< The channel of the network that generated the event */ - mesh_security_type_e security; /**< The security type of network */ - mesh_connection_state_e state; /**< The state of mesh network connection. */ -} mesh_connection_state_event_s; - -/** - * @brief The structure type for response data of mesh_event_cb. - * @details This function can receive events from the devices in the network. - * ex) join, re-join, leave and attribute change report - * - * @since_tizen 4.0 - */ -typedef struct { - union { - mesh_mesh_enabled_event_s *mesh_enable; /**< The result of enabling mesh system service. */ - mesh_other_station_event_s *sta_info; /**< This event comes from other stations. */ - mesh_connection_state_event_s *connection_state; /**< The state of mesh network connection. */ - } data; -} mesh_event_data_s; - -/** -* @} -*/ - -/** -* @addtogroup CAPI_NETWORK_MESH_MODULE -* @{ -*/ - - -/** - * @brief The mesh network profile handle. - * @since_tizen 4.0 -*/ -typedef void* mesh_network_h; - -/** - * @brief The mesh network peer handle. - * @since_tizen 4.0 -*/ -typedef void* mesh_peer_h; - -/** - * @brief Creates network handle for network information. - * @details This function is to allocate new mesh network information - * - * @since_tizen 4.0 - * - * @param[out] network The mesh network information handle, we will allocate mesh - * network information structure internally. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_OUT_OF_MEMORY Memory error - * - * @see mesh_network_clone() - * @see mesh_network_new_with() - * @see mesh_network_destroy() - * - */ -int mesh_network_new(mesh_network_h* network); - -/** - * @brief Clones network handle for network information. - * @details This function is to clone mesh network information - * - * @since_tizen 4.0 - * - * @param[out] dst The target mesh network information handle, we will allocate mesh - * network information structure internally. - * @param[in] src The source mesh network information handle. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_OUT_OF_MEMORY Memory error - * - * @see mesh_network_new() - * @see mesh_network_new_with() - * @see mesh_network_destroy() - * - */ -int mesh_network_clone(mesh_network_h* dst, mesh_network_h src); - -/** - * @brief Creates network handle with parameters for network information. - * @details This function is to allocate new mesh network information - * - * @since_tizen 4.0 - * - * @param[out] network The mesh network information handle, we will allocate mesh - * network information structure internally. - * @param[in] meshid The Mesh Network ID - * @param[in] bssid The Basic Service Set ID - * @param[in] channel The operating channel number - * @param[in] rssi The Received Signal Strength Indicator - * @param[in] security The security type for network - * @param[in] passphrase The passphrase for network connection - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_OUT_OF_MEMORY Memory error - * - * @see mesh_network_clone() - * @see mesh_network_new_with() - * @see mesh_network_destroy() - * - */ -int mesh_network_new_with(mesh_network_h* network, const char *meshid, - const char *bssid, int channel, int rssi, mesh_security_type_e security, - const char *passphrase); - -/** - * @brief Destroys network handle for network information. - * @details This function is to destroy mesh network information - * - * @since_tizen 4.0 - * - * @param[in] network The target mesh network information handle. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_OUT_OF_MEMORY Memory error - * - * @see mesh_network_new() - * @see mesh_network_new_with() - * @see mesh_network_clone() - * @see mesh_network_destroy() - * - */ -int mesh_network_destroy(mesh_network_h network); - -/** - * @brief Gets network mesh network id. - * @details This function is to return mesh network id - * @remark The returned string should be freed when no longer needed. - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] meshid The mesh network id. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_meshid() - * - */ -int mesh_network_get_meshid(mesh_network_h network, char **meshid); - -/** - * @brief Sets network mesh network id. - * @details This function is to set mesh network id - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] meshid The mesh network id. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_meshid() - * - */ -int mesh_network_set_meshid(mesh_network_h network, const char *meshid); - -/** - * @brief Gets BSSID. - * @details This function is to get basic service set id - * @remark The returned string should be freed when no longer needed. - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] bssid The basic service set id. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_bssid() - * - */ -int mesh_network_get_bssid(mesh_network_h network, char **bssid); - -/** - * @brief Sets BSSID. - * @details This function is to set basic service set id - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] bssid The basic service set id. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_bssid() - * - */ -int mesh_network_set_bssid(mesh_network_h network, const char *bssid); - -/** - * @brief Gets channel. - * @details This function is to get channel - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] channel The operating channel number. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_channel() - * - */ -int mesh_network_get_channel(mesh_network_h network, int *channel); - -/** - * @brief Sets channel. - * @details This function is to get channel - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] channel The operating channel number. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_channel() - * - */ -int mesh_network_set_channel(mesh_network_h network, int channel); - -/** - * @brief Gets RSSI. - * @details This function is to get rssi - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] rssi The received signal strength indicator. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_rssi() - * - */ -int mesh_network_get_rssi(mesh_network_h network, int *rssi); - -/** - * @brief Sets RSSI. - * @details This function is to set rssi - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] rssi The received signal strength indicator. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_rssi() - * - */ -int mesh_network_set_rssi(mesh_network_h network, int rssi); - -/** - * @brief Gets the security type. - * @details This function is to get the security type. - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] security The security type for network. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_set_security() - * - */ -int mesh_network_get_security(mesh_network_h network, mesh_security_type_e *security); - -/** - * @brief Sets the security type. - * @details This function is to set the security type. - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] security The security type for network. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_security() - * - */ -int mesh_network_set_security(mesh_network_h network, mesh_security_type_e security); - -/** - * @brief Sets the passphrase for network connection. - * @details This function is to set the passphrase. - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[in] passphrase The passphrase for network connection. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mesh_network_get_security() - * @see mesh_network_set_security() - */ -int mesh_network_set_passphrase(mesh_network_h network, const char* passphrase); - -/** - * @brief Gets the connection state. - * @details This function is to get the connection state - * - * @since_tizen 4.0 - * - * @param[in] network The mesh network information handle. - * @param[out] state The maximum data rate. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - */ -int mesh_network_get_connection_state(mesh_network_h network, mesh_connection_state_e *state); - -/** - * @brief Gets address from mesh peer. - * @details This function is to return mesh network id - * @remark The returned string should be freed when no longer needed. - * - * @since_tizen 4.0 - * - * @param[in] peer The mesh peer information handle. - * @param[out] address The address of mesh peer. - * - * @return 0 on success, otherwise a negative error value. - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * - */ -int mesh_peer_get_address(mesh_peer_h peer, char **address); - -/** - * @brief Initializes Mesh network. - * @since_tizen 4.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/network.get - * @remarks You must release @a handle using mesh_deinitialize(). - * @param[out] handle The mesh handle - * @return @c 0 on success, otherwise negative error value - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_ALREADY_INITIALIZED Already initialized - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_INVALID_OPERATION Invalid operation - * @retval #MESH_ERROR_OPERATION_FAILED Operation failed - * @retval #MESH_ERROR_PERMISSION_DENIED Permission Denied - * @retval #MESH_ERROR_OUT_OF_MEMORY Out of memory - * @retval #MESH_ERROR_NOT_SUPPORTED Not supported - */ -int mesh_initialize(mesh_h *handle); - -/** - * @brief Deinitializes Mesh network. - * @since_tizen 4.0 - * @param[in] handle The mesh handle - * @return 0 on success, otherwise negative error value - * @retval #MESH_ERROR_NONE Successful - * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MESH_ERROR_INVALID_OPERATION Invalid operation - * @retval #MESH_ERROR_OPERATION_FAILED Operation failed - * @retval #MESH_ERROR_NOT_SUPPORTED Not supported - */ -int mesh_deinitialize(mesh_h handle); - -/** - * @brief Specifies the type of function passed to mesh_enable() - * @details This function can receive events from mesh network. - * ex) enabled state, scan result - * - * @since_tizen 4.0 - * - * @remarks You can receive below events. - * @see #MESH_EVENT_ENABLED - * @see #MESH_EVENT_SCAN_DONE - * @see #MESH_EVENT_STATION_JOIN - * @see #MESH_EVENT_STATION_LEFT - * - * @param[out] event_type The event identification - * @param[out] event parameter data pointer - * - * @pre The callback must be registered with mesh_enable() - * - * @see mesh_set_event_cb() - */ -typedef void (*mesh_event_cb)(mesh_event_e event_type, mesh_event_data_s* event); - -/** - * @brief Sets event handler for the mesh network service. - * @details Sets event handler to get events from the mesh network service. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] event_handler The event handler - * - * @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 - * @retval #MESH_ERROR_NOT_SUPPORTED Not supported - * - * @see mesh_initialize() - * @see mesh_deinitialize() - * - */ -int mesh_set_event_cb(mesh_h handle, mesh_event_cb event_handler); - -/** - * @brief Enable the mesh service. - * @details All this function to start mesh service - * - * @since_tizen 4.0 - * - * @remarks You must free all resources of the mesh by calling mesh_deinitialize() - * if mesh service is no longer needed. - * - * @param[in] handle The mesh handle - * - * @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_initialize() - * @see mesh_deinitialize() - * @see mesh_event_cb() - * @see mesh_disable() - * - */ -int mesh_enable(mesh_h handle); - -/** - * @brief disable the mesh service. - * @details all this function to stop mesh service - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * @remarks You must free all resources of the mesh by calling mesh_deinitialize() - * if mesh service is no longer needed. - * - * - * @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_initialize() - * @see mesh_deinitialize() - * @see mesh_enable() - * - */ -int mesh_disable(mesh_h handle); - -/** - * @brief Scan the mesh network. - * @details Scan all mesh network to get network state. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * - * @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_specific_scan() - * @see mesh_cancel_scan() - * - */ -int mesh_scan(mesh_h handle); - -/** - * @brief Scan for the specific mesh network. - * @details Scan specific SSID and channel to get network state. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] ssid Specific SSID to scan - * @param[in] channel The channel number to scan - * - * - * @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_cancel_scan() - * - */ -int mesh_specific_scan(mesh_h handle, const char* ssid, int channel); - -/** - * @brief Called after mesh_foreach_found_mesh_network() - * @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_foreach_found_mesh_network() - * - * @see mesh_foreach_found_mesh_network() - */ -typedef void (*mesh_found_mesh_network_cb)(mesh_network_h network, void* user_data); - -/** - * @brief Gets found mesh network bss information - * @details This function returns network information found through mesh_found_mesh_network_cb. - * - * @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_network_cb() - * - */ -int mesh_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_network_cb cb, void *user_data); - -/** - * @brief Called after mesh_foreach_connected_peers() - * @details This function can receive connected peers on mesh network. - * - * @since_tizen 4.0 - * - * @param[out] network The mesh peer information handle - * @param[out] user_data user data pointer - * - * @pre The callback must be registered with mesh_foreach_connected_peers() - * - * @see mesh_foreach_connected_peers() - */ -typedef void (*mesh_connected_peer_cb)(mesh_peer_h peer, void* user_data); - -/** - * @brief Gets found mesh network peer information - * @details This function returns network information found through mesh_connected_peer_cb. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] cb callback function pointer to inform peer 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_find_peers() - * @see mesh_connected_peer_cb() - * - */ -int mesh_foreach_connected_peers(mesh_h handle, - mesh_connected_peer_cb cb, void *user_data); - -/** - * @brief Enables the mesh network. - * @details This function is to join or create mesh network using saved mesh network configuration - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * @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_disable_mesh() - * - */ -int mesh_enable_mesh(mesh_h handle); - -/** - * @brief Disables the mesh network. - * @details This function is to disjoin or destroy current mesh network - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * @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_enable_mesh() - * - */ -int mesh_disable_mesh(mesh_h handle); - -/** - * @brief Get the mesh connection state. - * @details Check if current device is joined mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[out] is_joined The state of mesh network connection. - * - * - * @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_enable_mesh() - * @see mesh_found_mesh_network_cb() - * - */ -int mesh_is_joined(mesh_h handle, bool* is_joined); - -/** - * @brief Gets current joined mesh network information. - * @details Return current joined mesh network information.. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[out] network Mesh bss information handle - * - * - * @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_enable_mesh() - * - */ -int mesh_get_joined_network(mesh_h handle, mesh_network_h* network); - -/** - * @brief Sets softap options - * @details This function sets softap options. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] ssid The SSID - * @param[in] key The pre-shared key - * @param[in] channel The operating channel number - * @param[in] visibility The broadcast option (1:Broadcast SSID, 2:Hidden) - * @param[in] max_stations The maximum allowable number of stations (default:10) - * @param[in] security Security option (1:WPA1, 2:WPA2) - * - * - * @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_enable_softap() - * @see mesh_disable_softap() - * - */ -int mesh_set_softap(mesh_h handle, const char* ssid, const char* key, - int channel, bool visibility, int max_stations, int security); - -/** - * @brief Enables softap - * @details This function enables softap. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * - * @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_set_softap() - * @see mesh_disable_softap() - * - */ -int mesh_enable_softap(mesh_h handle); - -/** - * @brief Disable softap - * @details This function disables softap. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * - * - * @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_set_softap() - * @see mesh_enable_softap() - * - */ -int mesh_disable_softap(mesh_h handle); - -/** - * @brief Creates new mesh network configuration - * @details This function creates new mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] network Mesh bss information handle - * - * - * @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_connect_mesh_network() - * @see mesh_disconnect_mesh_network() - * @see mesh_forget_mesh_network() - * - */ -int mesh_create_mesh_network(mesh_h handle, mesh_network_h network); - -/** - * @brief Connects existing mesh network - * @details This function makes a connection to existing mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] network Mesh bss information handle - * - * - * @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_create_mesh_network() - * @see mesh_disconnect_mesh_network() - * @see mesh_forget_mesh_network() - * - */ -int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network); - -/** - * @brief Disconnects existing mesh network - * @details This function disconnects with existing mesh network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] network Mesh bss information handle - * - * - * @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_create_mesh_network() - * @see mesh_forget_mesh_network() - * - */ -int mesh_disconnect_mesh_network(mesh_h handle, mesh_network_h network); - -/** - * @brief Forgets existing mesh network - * @details This function removes the information of connected network. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] network Mesh bss information handle - * - * - * @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_create_mesh_network() - * @see mesh_connect_mesh_network() - * @see mesh_disconnect_mesh_network() - * - */ -int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network); - - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIZEN_MESH_H__ */ diff --git a/include/mesh_dbus.h b/include/mesh_dbus.h deleted file mode 100644 index 0618678..0000000 --- a/include/mesh_dbus.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MESH_DBUS_H__ -#define __MESH_DBUS_H__ - -#include "mesh.h" -#include "mesh-internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MESH_SERVER_NAME "net.mesh" -#define MESH_OBJECT_PATH "/net/mesh" -#define MESH_SERVICE_INTERFACE "net.mesh" - -#define MESH_MANAGER_NAME "net.mesh.manager" -#define MESH_MANAGER_OBJ_PATH "/net/mesh/manager" -#define MESH_MANAGER_INTERFACE "net.mesh.manager" - -#define MESH_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */ - -int _mesh_dbus_start(mesh_h m); -int _mesh_dbus_stop(mesh_h m); - -int _mesh_set_event_cb(mesh_h handle, mesh_event_cb event_handler); -int _mesh_enable(mesh_h handle); -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_scan_result(mesh_h handle); -int _mesh_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_network_cb cb, void *user_data); -int _mesh_find_peers(mesh_h handle); -int _mesh_foreach_connected_peers(mesh_h handle, - mesh_connected_peer_cb cb, void *user_data); -int _mesh_enable_mesh(mesh_h handle); -int _mesh_disable_mesh(mesh_h handle); -int _mesh_is_joined(mesh_h handle, bool* is_joined); -int _mesh_get_joined_mesh_network(mesh_h handle, mesh_network_h* _network); -int _mesh_set_gate(mesh_h handle, bool gate_announce, int hwmp_root_mode, bool stp); -int _mesh_unset_gate(mesh_h handle); -int _mesh_set_softap(mesh_h handle, const char* ssid, const char* key, const char* mode, - int channel, int visibility, int max_stations, int security); -int _mesh_enable_softap(mesh_h handle); -int _mesh_disable_softap(mesh_h handle); -int _mesh_create_network(mesh_h handle, mesh_network_h _network); -int _mesh_connect_network(mesh_h handle, mesh_network_h _network); -int _mesh_disconnect_network(mesh_h handle, mesh_network_h _network); -int _mesh_forget_network(mesh_h handle, mesh_network_h _network); -int _mesh_set_interface(mesh_h handle, const char *mesh, const char *gate, const char *softap); -int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data); -int _mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data); -int _mesh_set_interfaces(mesh_h handle, const char *mesh, const char *gate, const char *softap); - -#ifdef __cplusplus -} -#endif - -#endif /** __MESH_DBUS_H__ */ diff --git a/include/mesh_log.h b/include/mesh_log.h deleted file mode 100644 index 2093faa..0000000 --- a/include/mesh_log.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CAPI_MESH_LOG_H__ -#define __CAPI_MESH_LOG_H__ - -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_MESH" - -#define RET_IF(expr) \ - do { \ - if (expr) { \ - LOGE("(%s)", #expr); \ - return; \ - } \ - } while (0) - -#define RETV_IF(expr, val) \ - do {\ - if (expr) { \ - LOGE("(%s)", #expr); \ - return (val); \ - } \ - } while (0) - -#define RETM_IF(expr, fmt, arg...) \ - do {\ - if (expr) { \ - LOGE(fmt, ##arg); \ - return; \ - } \ - } while (0) - -#define RETVM_IF(expr, val, fmt, arg...) \ - do {\ - if (expr) { \ - LOGE(fmt, ##arg); \ - return (val); \ - } \ - } while (0) - -#define ERR_IF(expr) \ - do { \ - if (expr) { \ - LOGE("(%s)", #expr); \ - } \ - } while (0) - -#define WARN_IF(expr, fmt, arg...) \ - do { \ - if (expr) { \ - LOGW(fmt, ##arg); \ - } \ - } while (0) - -#endif /* __CAPI_MESH_LOG_H__ */ diff --git a/include/mesh_private.h b/include/mesh_private.h deleted file mode 100644 index 63a22ab..0000000 --- a/include/mesh_private.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CAPI_MESH_PRIVATE_H__ -#define __CAPI_MESH_PRIVATE_H__ - -#include -#include -#include -#include - -#include "mesh.h" - -#define MESH_FEATURE "http://tizen.org/feature/network.mesh" - -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return MESH_ERROR_INVALID_PARAMETER; \ - } - -#if 0 -#define CHECK_FEATURE_SUPPORTED(feature_name) { \ - bool mesh_supported = FALSE; \ - if (!system_info_get_platform_bool(feature_name, &mesh_supported)) { \ - if (mesh_supported == FALSE) { \ - LOGE("mesh feature is disabled"); \ - return MESH_ERROR_NOT_SUPPORTED; \ - } \ - } else { \ - LOGE("Error - Feature getting from System Info"); \ - return MESH_ERROR_OPERATION_FAILED; \ - } \ -} -#else -#define CHECK_FEATURE_SUPPORTED(feature_name) { \ - LOGE("[Feature] Should be check !"); \ - } -#endif - -typedef struct mesh_handle { - gpointer dbus_connection; - GCancellable *ca; - GList *dbus_sub_ids; - mesh_event_cb event_handler; -/* TODO: Below members are related with event callback - * Need to be considered - */ -#if 0 - char *path; - GHashTable *evt_list; - - GHashTable *cache_property; - guint prop_callback_evt_id; -#endif -} mesh_handle_s; - -struct mesh_peer_s { - char address[MAX_BSSID_LEN]; /**< Peer address */ -}; - -struct mesh_network_s { - char meshid[MAX_MESHID_LEN]; /**< Mesh ID */ - char bssid[MAX_BSSID_LEN]; /**< BSSID */ - int channel; /**< Channel */ - int rssi; /**< RSSI */ - int data_rate; /**< Data rate */ - mesh_security_type_e security; /**< Security type */ - char passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase */ - mesh_connection_state_e state; /**< Connection state */ -}; - -struct mesh_station_info_s { - gchar bssid[MAX_BSSID_LEN]; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */ - guint inactive_time; /**< inactive time ex) 1685 ms */ - guint64 rx_bytes; /**< rx bytes ex) 34174 */ - guint rx_packets; /**< rx packet ex) 1181 */ - guint64 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 */ - guint64 beacon_rx; /**< beacon rx ex) 0 */ - guint64 rx_drop_misc; /**< rx drop misc ex) 0 */ - gint signal; /**< Signal ex) -64 dBm */ - gint signal_avg; /**< Average Signal ex) -63 dBm */ - guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */ - guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */ - gushort mesh_llid; /**< mesh_llid ex) 51731 */ - gushort mesh_plid; /**< mesh plid ex) 35432 */ - guchar mesh_plink; /**< mesh plink ex) ESTAB */ - guint local_ps_mode; /**< mesh local power save mode ex) ACTIVE */ - guint peer_ps_mode; /**< mesh peer power save mode ex) ACTIVE */ - guint non_peer_ps_mode; /**< mesh non-peer power save mode ex) ACTIVE */ - gboolean authorized; /**< authorized ex) yes */ - gboolean authenticated; /**< authenticated ex) yes */ - gboolean associated; /**< associated ex) yes */ - gboolean preamble; /**< preamble ex) long */ - gboolean wmm_wme; /**< WMM/WME supported ex) yes */ - gboolean mfp; /**< MFP ex) no */ - gboolean tdls_peer; /**< TDLS peer ex) no */ - guchar dtim_period; /**< DTIM period ex) 0 */ - gushort beacon_interval; /**< beacon interval ex) 1000 */ - gboolean cts_protection; /**< CTS protection */ - gboolean short_preamble; /**< short preamble */ - gboolean short_slot_time; /**< short slot time supported ex) yes */ - guint connected_time; /**< connected time : ex) 256 seconds */ -}; - -struct mesh_mpath_dump_s { - gchar dest_addr[MAX_BSSID_LEN]; /**< destination address */ - gchar next_hop[MAX_BSSID_LEN]; /**< next hop address */ - gchar iface[IFNAMSIZ]; /**< network interface for mesh */ - guint sn; /**< sequence number */ - guint metric; /**< metric */ - guint qlen; /**< driver queue length */ - guint exptime; /**< expire time */ - guint discovery_timeout; /**< Discovery timeout */ - guchar discovery_retries; /**< Discovery retries */ - guchar flags; /**< Flags */ -}; - -#define NOTUSED(var) (var = var) - -#endif /* __CAPI_MESH_PRIVATE_H__ */ diff --git a/include/service_error.h b/include/service_error.h deleted file mode 100644 index 53b4036..0000000 --- a/include/service_error.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MESH_SERVICE_ERROR_H__ -#define __MESH_SERVICE_ERROR_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - SERVICE_ERROR_NONE = 0, /**< Successful */ - SERVICE_ERROR_IO_ERROR, /**< I/O error */ - SERVICE_ERROR_NO_DATA, /**< Data not exists */ - SERVICE_ERROR_OUT_OF_MEMORY, /**< out of memory */ - SERVICE_ERROR_OPERATION_FAILED, /**< operation failed */ - SERVICE_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - SERVICE_ERROR_ALREADY_REGISTERED, /**< Request already registered */ - SERVICE_ERROR_IN_PROGRESS /**< operation is in progress */ -} service_error_e; - -#ifdef __cplusplus -} -#endif - -#endif /** __MESH_SERVICE_ERROR_H__ */ diff --git a/include/wifi-mesh-internal.h b/include/wifi-mesh-internal.h new file mode 100644 index 0000000..816a838 --- /dev/null +++ b/include/wifi-mesh-internal.h @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_WIFI_MESH_INTERNAL_H__ +#define __TIZEN_WIFI_MESH_INTERNAL_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file mesh-internal.h + */ + +/** + * @brief The HWMP type for mesh_hwmp_root_mode_e + * + * @since_tizen 4.0 + */ +typedef enum { + MESH_HWMP_ROOT_REACTIVE_MODE = 0, /**< Disable Proative Mode */ + MESH_HWMP_ROOT_SIMPLE_PROACTIVE_MODE = 2, /**< Enable the Proactive PREQ with no PREP */ + MESH_HWMP_ROOT_FORCED_PROACTIVE_MODE = 3, /**< Enable the Proactive PREQ with PREP. + Once you do this, all the nodes in your mesh will proactively create paths to your gate. + Mesh nodes will send to gate(s) all traffic to those destinations that could not be resolved in the mesh. */ + MESH_HWMP_ROOT_PROACTIVE_WITH_RANN_MODE = 4, /**< If we use HWMP_ROOTMODE as 4, every 5 sec, + our DUT sends action_frame with root announce. */ +} mesh_hwmp_root_mode_e; + +/** + * @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_mpath_info_h; + +/** + * @brief Gets the maximum data rate. + * @details This function is to get the maximum data rate + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] data_rate The maximum data rate. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_data_rate() + * + */ +int wifi_mesh_network_get_data_rate(wifi_mesh_network_h network, int *data_rate); + +/** + * @brief Sets the maximum data rate. + * @details This function is to set the maximum data rate + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] data_rate The maximum data rate. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_data_rate() + * + */ +int wifi_mesh_network_set_data_rate(wifi_mesh_network_h network, int data_rate); + +/** + * @brief Cancel scanning for the mesh network. + * @details Stop scanning process of mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_scan() + * @see wifi_mesh_specific_scan() + * @see wifi_mesh_scan() + * + */ +int wifi_mesh_cancel_scan(wifi_mesh_h handle); + +/** + * @brief Sets gate options + * @details This function sets mesh gate options. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] gate_announce Enable / Disable Gate Announce to peers + * @param[in] hwmp_root_mode HWMP (Hybrid Wireless Mesh Protocol) Root Mode \n + * #MESH_HWMP_ROOT_REACTIVE_MODE \n + * #MESH_HWMP_ROOT_SIMPLE_PROACTIVE_MODE \n + * #MESH_HWMP_ROOT_FORCED_PROACTIVE_MODE \n + * #MESH_HWMP_ROOT_PROACTIVE_WITH_RANN_MODE \n + * @param[in] stp Enable / Disable Gate Announce to peers + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_unset_gate() + * + */ +int wifi_mesh_set_gate(wifi_mesh_h handle, int gate_announce, int hwmp_root_mode, bool stp); + +/** + * @brief Unsets gate options + * @details This function unsets mesh gate options. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_set_gate() + * + */ +int wifi_mesh_unset_gate(wifi_mesh_h handle); + +/** + * @brief Called after wifi_mesh_get_stations_info() + * @details This function can receive joined station information from mesh network. + * + * @since_tizen 4.0 + * + * @param[out] station mesh station information handle + * @param[out] user_data user data pointer + * + * @pre The callback must be registered with wifi_mesh_foreach_found_network() + * + * @see wifi_mesh_foreach_found_network() + */ +typedef void (*wifi_mesh_found_station_cb)(mesh_station_info_h station, void* user_data); + +/** + * @brief Get information of all connected stations. + * @details Get information about all stations present in the currently connected mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] cb The callback function to receive station information + * @param[in] user_data User data + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see mesh_get_path_info() + * + */ +int wifi_mesh_get_stations_info(wifi_mesh_h handle, wifi_mesh_found_station_cb cb, void *user_data); + +/** + * @brief Called after wifi_mesh_get_stations_info() + * @details This function can receive joined station information from mesh network. + * + * @since_tizen 4.0 + * + * @param[out] path mesh path information handle + * @param[out] user_data user data pointer + * + * @pre The callback must be registered with wifi_mesh_foreach_found_network() + * + * @see wifi_mesh_foreach_found_network() + */ +typedef void (*mesh_found_mpath_cb)(mesh_mpath_info_h path, void* user_data); + +/** + * @brief Get information of all mesh paths. + * @details Get information about all mesh paths present in the currently connected mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] cb The callback function to receive mesh path information + * @param[in] user_data User data + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_get_stations_info() + * + */ +int wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *user_data); + +/** + * @brief Sets network device interface name. + * @details This function provides the ability to manually select interfaces for advanced users. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] mesh An interface name for mesh network + * @param[in] gate An interface name for external network + * @param[in] softap An interface name for internal softap + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + */ +int wifi_mesh_set_interfaces(wifi_mesh_h handle, + const char *mesh, const char* gate, const char *softap); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_WIFI_MESH_INTERNAL_H__ */ diff --git a/include/wifi-mesh.h b/include/wifi-mesh.h new file mode 100644 index 0000000..0951724 --- /dev/null +++ b/include/wifi-mesh.h @@ -0,0 +1,1007 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_WIFI_MESH_H__ +#define __TIZEN_WIFI_MESH_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file wifi-mesh.h + */ + +/** +* @addtogroup CAPI_NETWORK_WIFI_MESH_MODULE +* @{ +*/ + +/** + * @brief The Wi-Fi mesh handle. + * @since_tizen 4.0 +*/ +typedef void *wifi_mesh_h; + +/*********************************************************************** + TEMP +***********************************************************************/ +#ifndef TIZEN_ERROR_MESH +#define TIZEN_ERROR_MESH -0x02F60000 +#endif + +/** + * @brief Enumeration for the Wi-Fi mesh error type. + * @since_tizen 4.0 + */ +typedef enum { + WIFI_MESH_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + WIFI_MESH_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + WIFI_MESH_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ + WIFI_MESH_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ + WIFI_MESH_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + WIFI_MESH_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */ + WIFI_MESH_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ + WIFI_MESH_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission Denied */ + WIFI_MESH_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< DBus error */ + WIFI_MESH_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not Supported */ + WIFI_MESH_ERROR_OPERATION_FAILED = TIZEN_ERROR_MESH | 0x01, /**< Operation failed */ + WIFI_MESH_ERROR_OPERATION_ABORTED = TIZEN_ERROR_MESH | 0x02, /**< Operation is aborted */ + WIFI_MESH_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_MESH | 0x03, /**< Mesh Already Initialized */ +} wifi_mesh_error_e; + +/** +* @} +*/ + +/** +* @addtogroup CAPI_NETWORK_WIFI_MESH_MONITOR_MODULE +* @{ +*/ + +/** + * @brief The maximum length of mesh id + * + * @since_tizen 4.0 + */ +#define MAX_MESHID_LEN 32 + +/** + * @brief The maximum length of BSSID + * + * @since_tizen 4.0 + */ +#define MAX_BSSID_LEN 18 + +/** + * @brief The maximum length of passphrase + * + * @since_tizen 4.0 + */ +#define MAX_PASSPHRASE_LEN (64+1) + +/** + * @brief Enumeration for the security type of the Wi-Fi Mesh network. + * @since_tizen 4.0 + */ +typedef enum { + MESH_SECURITY_NONE = 0, /**< Open network */ + MESH_SECURITY_SAE, /**< Simultaneous Authentication of Equals */ +} wifi_mesh_security_type_e; + +/** + * @brief Enumeration for the connection state of the Wi-Fi Mesh network. + * @since_tizen 4.0 + */ +typedef enum { + WIFI_MESH_CONNECTION_STATE_DISCONNECTED = 0, /**< Wi-Fi Mesh network is disconnected */ + WIFI_MESH_CONNECTION_STATE_ASSOCIATION, /**< Service is trying to establish low-level network connection to the mesh network. */ + WIFI_MESH_CONNECTION_STATE_CONFIGURATION, /**< Service is trying to retrieve/configure IP settings. */ + WIFI_MESH_CONNECTION_STATE_CONNECTED /**< Wi-Fi Mesh network is connected */ +} wifi_mesh_connection_state_e; + +/** + * @brief The events for wifi_mesh_event_cb + * + * @since_tizen 4.0 + */ +typedef enum { + WIFI_MESH_EVENT_ENABLED = 0x00, /**< This event is received after enabling mesh network */ + WIFI_MESH_EVENT_SCAN_DONE = 0x01, /**< This event comes after scanning operation completed */ + WIFI_MESH_EVENT_CONNECTION_STATE = 0x02, /**< This event takes place when mesh network connection state is changed */ + WIFI_MESH_EVENT_STATION_JOIN = 0x03, /**< This event takes place when new station joined */ + WIFI_MESH_EVENT_STATION_LEFT = 0x04, /**< This event takes place when existing station left */ +} wifi_mesh_event_e; + +/** + * @brief The structure type for the WIFI_MESH_EVENT_ENABLED callback data. + * @details The result of creating or joining mesh network. + * + * @since_tizen 4.0 + */ +typedef struct { + int result; /**< The result of creating or joining mesh network */ +} wifi_mesh_enabled_event_s; + +/** + * @brief The structure type for the WIFI_MESH_EVENT_STATION_JOIN or WIFI_MESH_EVENT_STATION_LEFT callback data. + * @details Result of join or left event of other station. + * + * @since_tizen 4.0 + */ +typedef struct { + char bssid[MAX_BSSID_LEN]; /**< The BSSID of the station that generated the event */ +} wifi_mesh_other_station_event_s; + +/** + * @brief The structure type for the WIFI_MESH_EVENT_CONNECTION_STATE callback data. + * @details The state of mesh network connection. + * + * @since_tizen 4.0 + */ +typedef struct { + char mesh_id[MAX_MESHID_LEN]; /**< The Mesh ID of the network that generated the event */ + char bssid[MAX_BSSID_LEN]; /**< The BSSID of the network that generated the event */ + int channel; /**< The channel of the network that generated the event */ + wifi_mesh_security_type_e security; /**< The security type of network */ + wifi_mesh_connection_state_e state; /**< The state of mesh network connection. */ +} wifi_mesh_connection_state_event_s; + +/** + * @brief The structure type for response data of wifi_mesh_event_cb. + * @details This function can receive events from the devices in the network. + * ex) enable, station information, connection state and etc + * + * @since_tizen 4.0 + */ +typedef struct { + union { + wifi_mesh_enabled_event_s *wifi_mesh_enable; /**< The result of enabling mesh system service. */ + wifi_mesh_other_station_event_s *sta_info; /**< This event comes from other stations. */ + wifi_mesh_connection_state_event_s *connection_state; /**< The state of mesh network connection. */ + } data; +} wifi_mesh_event_data_s; + +/** +* @} +*/ + +/** +* @addtogroup CAPI_NETWORK_WIFI_MESH_MODULE +* @{ +*/ + +/** + * @brief The Wi-Fi mesh network profile handle. + * @since_tizen 4.0 +*/ +typedef void* wifi_mesh_network_h; + +/** + * @brief The Wi-Fi mesh network peer handle. + * @since_tizen 4.0 +*/ +typedef void* wifi_mesh_peer_h; + +/** + * @brief Creates a network handle. + * @details This function is to allocate new mesh network information + * + * @since_tizen 4.0 + * + * @param[out] network The mesh network information handle, we will allocate mesh + * network information structure internally. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_OUT_OF_MEMORY Memory error + * + * @see wifi_mesh_network_clone() + * @see wifi_mesh_network_new_with() + * @see wifi_mesh_network_destroy() + * + */ +int wifi_mesh_network_new(wifi_mesh_network_h* network); + +/** + * @brief Clones a network handle. + * @details This function is to clone mesh network information + * + * @since_tizen 4.0 + * + * @param[out] dst The target Wi-Fi mesh network information handle, we will allocate mesh + * network information structure internally. + * @param[in] src The source mesh network information handle. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_OUT_OF_MEMORY Memory error + * + * @see wifi_mesh_network_new() + * @see wifi_mesh_network_new_with() + * @see wifi_mesh_network_destroy() + * + */ +int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_network_h src); + +/** + * @brief Creates network handle with parameters. + * @details This function is to allocate new mesh network information + * + * @since_tizen 4.0 + * + * @param[out] network The mesh network information handle, we will allocate mesh + * network information structure internally. + * @param[in] meshid The Mesh Network ID + * @param[in] bssid The Basic Service Set ID + * @param[in] channel The operating channel number + * @param[in] rssi The Received Signal Strength Indicator + * @param[in] security The security type for network + * @param[in] passphrase The passphrase for network connection + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_OUT_OF_MEMORY Memory error + * + * @see wifi_mesh_network_clone() + * @see wifi_mesh_network_new_with() + * @see wifi_mesh_network_destroy() + * + */ +int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const char *meshid, + const char *bssid, int channel, int rssi, wifi_mesh_security_type_e security, + const char *passphrase); + +/** + * @brief Destroys network handle. + * @details This function is to destroy mesh network information + * + * @since_tizen 4.0 + * + * @param[in] network The target Wi-Fi mesh network information handle. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_OUT_OF_MEMORY Memory error + * + * @see wifi_mesh_network_new() + * @see wifi_mesh_network_new_with() + * @see wifi_mesh_network_clone() + * @see wifi_mesh_network_destroy() + * + */ +int wifi_mesh_network_destroy(wifi_mesh_network_h network); + +/** + * @brief Gets a Wi-Fi mesh network id. + * @details This function is to return mesh network id + * @remark The returned string should be freed when no longer needed. + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] meshid The mesh network id. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_meshid() + * + */ +int wifi_mesh_network_get_meshid(wifi_mesh_network_h network, char **meshid); + +/** + * @brief Sets a Wi-Fi mesh network id. + * @details This function is to set Wi-Fi mesh network id + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] meshid The mesh network id. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_meshid() + * + */ +int wifi_mesh_network_set_meshid(wifi_mesh_network_h network, const char *meshid); + +/** + * @brief Gets BSSID. + * @details This function is to get basic service set id + * @remark The returned string should be freed when no longer needed. + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] bssid The basic service set id. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_bssid() + * + */ +int wifi_mesh_network_get_bssid(wifi_mesh_network_h network, char **bssid); + +/** + * @brief Sets BSSID. + * @details This function is to set basic service set id + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] bssid The basic service set id. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_bssid() + * + */ +int wifi_mesh_network_set_bssid(wifi_mesh_network_h network, const char *bssid); + +/** + * @brief Gets channel. + * @details This function is to get channel + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] channel The operating channel number. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_channel() + * + */ +int wifi_mesh_network_get_channel(wifi_mesh_network_h network, int *channel); + +/** + * @brief Sets channel. + * @details This function is to get channel + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] channel The operating channel number. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_channel() + * + */ +int wifi_mesh_network_set_channel(wifi_mesh_network_h network, int channel); + +/** + * @brief Gets RSSI. + * @details This function is to get rssi + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] rssi The received signal strength indicator. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_rssi() + * + */ +int wifi_mesh_network_get_rssi(wifi_mesh_network_h network, int *rssi); + +/** + * @brief Sets RSSI. + * @details This function is to set rssi + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] rssi The received signal strength indicator. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_rssi() + * + */ +int wifi_mesh_network_set_rssi(wifi_mesh_network_h network, int rssi); + +/** + * @brief Gets the security type. + * @details This function is to get the security type. + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] security The security type for network. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_set_security() + * + */ +int wifi_mesh_network_get_security(wifi_mesh_network_h network, wifi_mesh_security_type_e *security); + +/** + * @brief Sets the security type. + * @details This function is to set the security type. + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] security The security type for network. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_security() + * + */ +int wifi_mesh_network_set_security(wifi_mesh_network_h network, wifi_mesh_security_type_e security); + +/** + * @brief Sets the passphrase for network connection. + * @details This function is to set the passphrase. + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[in] passphrase The passphrase for network connection. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see wifi_mesh_network_get_security() + * @see wifi_mesh_network_set_security() + */ +int wifi_mesh_network_set_passphrase(wifi_mesh_network_h network, const char* passphrase); + +/** + * @brief Gets the connection state. + * @details This function is to get the connection state + * + * @since_tizen 4.0 + * + * @param[in] network The Wi-Fi mesh network information handle. + * @param[out] state The maximum data rate. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int wifi_mesh_network_get_connection_state(wifi_mesh_network_h network, wifi_mesh_connection_state_e *state); + +/** + * @brief Gets address from the Wi-Fi mesh peer. + * @details This function is to return mesh network id + * @remark The returned string should be freed when no longer needed. + * + * @since_tizen 4.0 + * + * @param[in] peer The mesh peer information handle. + * @param[out] address The address of mesh peer. + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int wifi_mesh_peer_get_address(wifi_mesh_peer_h peer, char **address); + +/** + * @brief Initializes a Wi-Fi Mesh network. + * @since_tizen 4.0 + * @privlevel public + * @remarks You must release @a handle using wifi_mesh_deinitialize(). + * @param[out] handle The Wi-Fi mesh handle + * @return @c 0 on success, otherwise negative error value + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_ALREADY_INITIALIZED Already initialized + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MESH_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MESH_ERROR_PERMISSION_DENIED Permission Denied + * @retval #WIFI_MESH_ERROR_OUT_OF_MEMORY Out of memory + * @retval #WIFI_MESH_ERROR_NOT_SUPPORTED Not supported + */ +int wifi_mesh_initialize(wifi_mesh_h *handle); + +/** + * @brief Deinitializes the Wi-Fi Mesh network. + * @since_tizen 4.0 + * @param[in] handle The Wi-Fi mesh handle + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MESH_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MESH_ERROR_NOT_SUPPORTED Not supported + */ +int wifi_mesh_deinitialize(wifi_mesh_h handle); + +/** + * @brief Specifies the type of function passed to wifi_mesh_enable() + * @details This function can receive events from the Wi-Fi mesh network. + * ex) enabled state, scan result + * + * @since_tizen 4.0 + * + * @remarks You can receive below events. + * @see #WIFI_MESH_EVENT_ENABLED + * @see #WIFI_MESH_EVENT_SCAN_DONE + * @see #WIFI_MESH_EVENT_STATION_JOIN + * @see #WIFI_MESH_EVENT_STATION_LEFT + * + * @param[out] event_type The event identification + * @param[out] event parameter data pointer + * + * @pre The callback must be registered with wifi_mesh_enable() + * + * @see wifi_mesh_set_event_cb() + */ +typedef void (*wifi_mesh_event_cb)(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event); + +/** + * @brief Sets event handler for the Wi-Fi mesh network service. + * @details Sets event handler to get events from the Wi-Fi mesh network service. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] event_handler The event handler + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * @retval #WIFI_MESH_ERROR_NOT_SUPPORTED Not supported + * + * @see wifi_mesh_initialize() + * @see wifi_mesh_deinitialize() + * + */ +int wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler); + +/** + * @brief Enable the Wi-Fi mesh service. + * @details All this function to start Wi-Fi mesh service + * + * @since_tizen 4.0 + * + * @remarks You must free all resources of the mesh by calling wifi_mesh_deinitialize() + * if mesh service is no longer needed. + * + * @param[in] handle The Wi-Fi mesh handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_initialize() + * @see wifi_mesh_deinitialize() + * @see wifi_mesh_event_cb() + * @see wifi_mesh_disable() + * + */ +int wifi_mesh_enable(wifi_mesh_h handle); + +/** + * @brief disable the Wi-Fi mesh service. + * @details all this function to stop Wi-Fi mesh service + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * @remarks You must free all resources of the mesh by calling wifi_mesh_deinitialize() + * if mesh service is no longer needed. + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_initialize() + * @see wifi_mesh_deinitialize() + * @see wifi_mesh_enable() + * + */ +int wifi_mesh_disable(wifi_mesh_h handle); + +/** + * @brief Scan Wi-Fi mesh networks. + * @details Scan all Wi-Fi mesh network to get network state. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_specific_scan() + * @see wifi_mesh_cancel_scan() + * + */ +int wifi_mesh_scan(wifi_mesh_h handle); + +/** + * @brief Scan for the specific mesh network. + * @details Scan specific SSID and channel to get specific Wi-Fi mesh networks. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] ssid Specific SSID to scan + * @param[in] channel The channel number to scan + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_scan() + * @see wifi_mesh_cancel_scan() + * + */ +int wifi_mesh_specific_scan(wifi_mesh_h handle, const char* ssid, int channel); + +/** + * @brief Called after wifi_mesh_foreach_found_network() + * @details This function can receive scan results from Wi-Fi mesh networks. + * + * @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 wifi_mesh_foreach_found_network() + * + * @see wifi_mesh_foreach_found_network() + */ +typedef void (*wifi_mesh_found_network_cb)(wifi_mesh_network_h network, void* user_data); + +/** + * @brief Gets found Wi-Fi mesh network bss information + * @details This function returns network information found through wifi_mesh_found_network_cb. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi 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 #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_scan() + * @see wifi_mesh_found_network_cb() + * + */ +int wifi_mesh_foreach_found_network(wifi_mesh_h handle, + wifi_mesh_found_network_cb cb, void *user_data); + +/** + * @brief Called after wifi_mesh_foreach_connected_peers() + * @details This function can receive connected peers on the Wi-Fi mesh network. + * + * @since_tizen 4.0 + * + * @param[out] network The mesh peer information handle + * @param[out] user_data user data pointer + * + * @pre The callback must be registered with wifi_mesh_foreach_connected_peers() + * + * @see wifi_mesh_foreach_connected_peers() + */ +typedef void (*wifi_mesh_connected_peer_cb)(wifi_mesh_peer_h peer, void* user_data); + +/** + * @brief Gets found Wi-Fi mesh network peer information + * @details This function returns network information found through wifi_mesh_connected_peer_cb. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] cb callback function pointer to inform peer information + * @param[in] user_data user data pointer + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see mesh_find_peers() + * @see wifi_mesh_connected_peer_cb() + * + */ +int wifi_mesh_foreach_connected_peers(wifi_mesh_h handle, + wifi_mesh_connected_peer_cb cb, void *user_data); + +/** + * @brief Enables the Wi-Fi mesh network. + * @details This function is to join or create Wi-Fi mesh network using saved Wi-Fi mesh network configuration + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_stop_mesh() + * + */ +int wifi_mesh_start_mesh(wifi_mesh_h handle); + +/** + * @brief Disables the Wi-Fi mesh network. + * @details This function is to disjoin or destroy current Wi-Fi mesh network + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_start_mesh() + * + */ +int wifi_mesh_stop_mesh(wifi_mesh_h handle); + +/** + * @brief Get the Wi-Fi mesh connection state. + * @details Check if current device is joined Wi-Fi mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[out] is_joined The state of mesh network connection. + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_start_mesh() + * @see wifi_mesh_found_network_cb() + * + */ +int wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined); + +/** + * @brief Gets current joined Wi-Fi mesh network information. + * @details Return current joined Wi-Fi mesh network information.. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[out] network Wi-Fi Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_start_mesh() + * + */ +int wifi_mesh_get_joined_network(wifi_mesh_h handle, wifi_mesh_network_h* network); + +/** + * @brief Sets softap options + * @details This function sets softap options. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] ssid The SSID + * @param[in] key The pre-shared key + * @param[in] channel The operating channel number + * @param[in] visibility The broadcast option (1:Broadcast SSID, 2:Hidden) + * @param[in] max_stations The maximum allowable number of stations (default:10) + * @param[in] security Security option (1:WPA1, 2:WPA2) + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_enable_softap() + * @see wifi_mesh_disable_softap() + * + */ +int wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, const char* key, + int channel, bool visibility, int max_stations, int security); + +/** + * @brief Enables softap + * @details This function enables softap. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_set_softap() + * @see wifi_mesh_disable_softap() + * + */ +int wifi_mesh_enable_softap(wifi_mesh_h handle); + +/** + * @brief Disable softap + * @details This function disables softap. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_set_softap() + * @see wifi_mesh_enable_softap() + * + */ +int wifi_mesh_disable_softap(wifi_mesh_h handle); + +/** + * @brief Creates new Wi-Fi mesh network configuration + * @details This function creates new mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] network Wi-Fi Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_connect_network() + * @see wifi_mesh_disconnect_network() + * @see wifi_mesh_forget_network() + * + */ +int wifi_mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h network); + +/** + * @brief Connects existing Wi-Fi mesh network + * @details This function makes a connection to existing Wi-Fi mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] network Wi-Fi Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_create_network() + * @see wifi_mesh_disconnect_network() + * @see wifi_mesh_forget_network() + * + */ +int wifi_mesh_connect_network(wifi_mesh_h handle, wifi_mesh_network_h network); + +/** + * @brief Disconnects existing Wi-Fi mesh network + * @details This function disconnects with existing Wi-Fi mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] network Wi-Fi Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_create_network() + * @see wifi_mesh_forget_network() + * + */ +int wifi_mesh_disconnect_network(wifi_mesh_h handle, wifi_mesh_network_h network); + +/** + * @brief Forgets existing Wi-Fi mesh network + * @details This function removes the information of connected network. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[in] network Wi-Fi Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_create_network() + * @see wifi_mesh_connect_network() + * @see wifi_mesh_disconnect_network() + * + */ +int wifi_mesh_forget_network(wifi_mesh_h handle, wifi_mesh_network_h network); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_WIFI_MESH_H__ */ diff --git a/include/wifi-mesh_dbus.h b/include/wifi-mesh_dbus.h new file mode 100644 index 0000000..05a0131 --- /dev/null +++ b/include/wifi-mesh_dbus.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WIFI_MESH_DBUS_H__ +#define __WIFI_MESH_DBUS_H__ + +#include "wifi-mesh.h" +#include "wifi-mesh-internal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MESH_SERVER_NAME "net.mesh" +#define MESH_OBJECT_PATH "/net/mesh" +#define MESH_SERVICE_INTERFACE "net.mesh" + +#define MESH_MANAGER_NAME "net.mesh.manager" +#define MESH_MANAGER_OBJ_PATH "/net/mesh/manager" +#define MESH_MANAGER_INTERFACE "net.mesh.manager" + +#define MESH_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */ + +int _mesh_dbus_start(wifi_mesh_h m); +int _mesh_dbus_stop(wifi_mesh_h m); + +int _wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler); +int _wifi_mesh_enable(wifi_mesh_h handle); +int _wifi_mesh_disable(wifi_mesh_h handle); +int _wifi_mesh_scan(wifi_mesh_h handle); +int _wifi_mesh_specific_scan(wifi_mesh_h handle, const char* ssid, int channel); +int _wifi_mesh_cancel_scan(wifi_mesh_h handle); +int _wifi_mesh_get_scan_result(wifi_mesh_h handle); +int _mesh_foreach_found_mesh_network(wifi_mesh_h handle, + wifi_mesh_found_network_cb cb, void *user_data); +int _wifi_mesh_find_peers(wifi_mesh_h handle); +int _wifi_mesh_foreach_connected_peers(wifi_mesh_h handle, + wifi_mesh_connected_peer_cb cb, void *user_data); +int _wifi_mesh_enable_mesh(wifi_mesh_h handle); +int _wifi_mesh_disable_mesh(wifi_mesh_h handle); +int _wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined); +int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _network); +int _wifi_mesh_set_gate(wifi_mesh_h handle, bool gate_announce, int hwmp_root_mode, bool stp); +int _wifi_mesh_unset_gate(wifi_mesh_h handle); +int _wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, const char* key, const char* mode, + int channel, int visibility, int max_stations, int security); +int _wifi_mesh_enable_softap(wifi_mesh_h handle); +int _wifi_mesh_disable_softap(wifi_mesh_h handle); +int _mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h _network); +int _mesh_connect_network(wifi_mesh_h handle, wifi_mesh_network_h _network); +int _mesh_disconnect_network(wifi_mesh_h handle, wifi_mesh_network_h _network); +int _mesh_forget_network(wifi_mesh_h handle, wifi_mesh_network_h _network); +int _mesh_set_interface(wifi_mesh_h handle, const char *mesh, const char *gate, const char *softap); +int _wifi_mesh_get_stations_info(wifi_mesh_h handle, wifi_mesh_found_station_cb cb, void *user_data); +int _wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *user_data); +int _wifi_mesh_set_interfaces(wifi_mesh_h handle, const char *mesh, const char *gate, const char *softap); + +#ifdef __cplusplus +} +#endif + +#endif /** __WIFI_MESH_DBUS_H__ */ diff --git a/include/wifi-mesh_log.h b/include/wifi-mesh_log.h new file mode 100644 index 0000000..2842cd6 --- /dev/null +++ b/include/wifi-mesh_log.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_WIFI_MESH_LOG_H__ +#define __CAPI_WIFI_MESH_LOG_H__ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "WIFI_MESH" + +#define RET_IF(expr) \ + do { \ + if (expr) { \ + LOGE("(%s)", #expr); \ + return; \ + } \ + } while (0) + +#define RETV_IF(expr, val) \ + do {\ + if (expr) { \ + LOGE("(%s)", #expr); \ + return (val); \ + } \ + } while (0) + +#define RETM_IF(expr, fmt, arg...) \ + do {\ + if (expr) { \ + LOGE(fmt, ##arg); \ + return; \ + } \ + } while (0) + +#define RETVM_IF(expr, val, fmt, arg...) \ + do {\ + if (expr) { \ + LOGE(fmt, ##arg); \ + return (val); \ + } \ + } while (0) + +#define ERR_IF(expr) \ + do { \ + if (expr) { \ + LOGE("(%s)", #expr); \ + } \ + } while (0) + +#define WARN_IF(expr, fmt, arg...) \ + do { \ + if (expr) { \ + LOGW(fmt, ##arg); \ + } \ + } while (0) + +#endif /* __CAPI_MESH_LOG_H__ */ diff --git a/include/wifi-mesh_private.h b/include/wifi-mesh_private.h new file mode 100644 index 0000000..67b3093 --- /dev/null +++ b/include/wifi-mesh_private.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_WIFI_MESH_PRIVATE_H__ +#define __CAPI_WIFI_MESH_PRIVATE_H__ + +#include +#include +#include +#include + +#include "wifi-mesh.h" + +#define MESH_FEATURE "http://tizen.org/feature/network.mesh" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return WIFI_MESH_ERROR_INVALID_PARAMETER; \ + } + +#if 0 +#define CHECK_FEATURE_SUPPORTED(feature_name) { \ + bool mesh_supported = FALSE; \ + if (!system_info_get_platform_bool(feature_name, &mesh_supported)) { \ + if (mesh_supported == FALSE) { \ + LOGE("mesh feature is disabled"); \ + return WIFI_MESH_ERROR_NOT_SUPPORTED; \ + } \ + } else { \ + LOGE("Error - Feature getting from System Info"); \ + return WIFI_MESH_ERROR_OPERATION_FAILED; \ + } \ +} +#else +#define CHECK_FEATURE_SUPPORTED(feature_name) { \ + LOGE("[Feature] Should be check !"); \ + } +#endif + +typedef struct mesh_handle { + gpointer dbus_connection; + GCancellable *ca; + GList *dbus_sub_ids; + wifi_mesh_event_cb event_handler; +/* TODO: Below members are related with event callback + * Need to be considered + */ +#if 0 + char *path; + GHashTable *evt_list; + + GHashTable *cache_property; + guint prop_callback_evt_id; +#endif +} mesh_handle_s; + +struct mesh_peer_s { + char address[MAX_BSSID_LEN]; /**< Peer address */ +}; + +struct mesh_network_s { + char meshid[MAX_MESHID_LEN]; /**< Mesh ID */ + char bssid[MAX_BSSID_LEN]; /**< BSSID */ + int channel; /**< Channel */ + int rssi; /**< RSSI */ + int data_rate; /**< Data rate */ + wifi_mesh_security_type_e security; /**< Security type */ + char passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase */ + wifi_mesh_connection_state_e state; /**< Connection state */ +}; + +struct mesh_station_info_s { + gchar bssid[MAX_BSSID_LEN]; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */ + guint inactive_time; /**< inactive time ex) 1685 ms */ + guint64 rx_bytes; /**< rx bytes ex) 34174 */ + guint rx_packets; /**< rx packet ex) 1181 */ + guint64 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 */ + guint64 beacon_rx; /**< beacon rx ex) 0 */ + guint64 rx_drop_misc; /**< rx drop misc ex) 0 */ + gint signal; /**< Signal ex) -64 dBm */ + gint signal_avg; /**< Average Signal ex) -63 dBm */ + guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */ + guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */ + gushort mesh_llid; /**< mesh_llid ex) 51731 */ + gushort mesh_plid; /**< mesh plid ex) 35432 */ + guchar mesh_plink; /**< mesh plink ex) ESTAB */ + guint local_ps_mode; /**< mesh local power save mode ex) ACTIVE */ + guint peer_ps_mode; /**< mesh peer power save mode ex) ACTIVE */ + guint non_peer_ps_mode; /**< mesh non-peer power save mode ex) ACTIVE */ + gboolean authorized; /**< authorized ex) yes */ + gboolean authenticated; /**< authenticated ex) yes */ + gboolean associated; /**< associated ex) yes */ + gboolean preamble; /**< preamble ex) long */ + gboolean wmm_wme; /**< WMM/WME supported ex) yes */ + gboolean mfp; /**< MFP ex) no */ + gboolean tdls_peer; /**< TDLS peer ex) no */ + guchar dtim_period; /**< DTIM period ex) 0 */ + gushort beacon_interval; /**< beacon interval ex) 1000 */ + gboolean cts_protection; /**< CTS protection */ + gboolean short_preamble; /**< short preamble */ + gboolean short_slot_time; /**< short slot time supported ex) yes */ + guint connected_time; /**< connected time : ex) 256 seconds */ +}; + +struct mesh_mpath_dump_s { + gchar dest_addr[MAX_BSSID_LEN]; /**< destination address */ + gchar next_hop[MAX_BSSID_LEN]; /**< next hop address */ + gchar iface[IFNAMSIZ]; /**< network interface for mesh */ + guint sn; /**< sequence number */ + guint metric; /**< metric */ + guint qlen; /**< driver queue length */ + guint exptime; /**< expire time */ + guint discovery_timeout; /**< Discovery timeout */ + guchar discovery_retries; /**< Discovery retries */ + guchar flags; /**< Flags */ +}; + +#define NOTUSED(var) (var = var) + +#endif /* __CAPI_WIFI_MESH_PRIVATE_H__ */ diff --git a/include/wifi-mesh_service_error.h b/include/wifi-mesh_service_error.h new file mode 100644 index 0000000..ba51996 --- /dev/null +++ b/include/wifi-mesh_service_error.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WIFI_MESH_SERVICE_ERROR_H__ +#define __WIFI_MESH_SERVICE_ERROR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SERVICE_ERROR_NONE = 0, /**< Successful */ + SERVICE_ERROR_IO_ERROR, /**< I/O error */ + SERVICE_ERROR_NO_DATA, /**< Data not exists */ + SERVICE_ERROR_OUT_OF_MEMORY, /**< out of memory */ + SERVICE_ERROR_OPERATION_FAILED, /**< operation failed */ + SERVICE_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + SERVICE_ERROR_ALREADY_REGISTERED, /**< Request already registered */ + SERVICE_ERROR_IN_PROGRESS /**< operation is in progress */ +} service_error_e; + +#ifdef __cplusplus +} +#endif + +#endif /** __WIFI_MESH_SERVICE_ERROR_H__ */ diff --git a/packaging/capi-network-mesh.manifest b/packaging/capi-network-mesh.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/packaging/capi-network-mesh.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-network-mesh.spec b/packaging/capi-network-mesh.spec deleted file mode 100644 index d80d032..0000000 --- a/packaging/capi-network-mesh.spec +++ /dev/null @@ -1,65 +0,0 @@ -%define major 0 -%define minor 1 -%define patchlevel 1 - -Name: capi-network-mesh -Version: %{major}.%{minor}.%{patchlevel} -Release: 1 -License: Apache-2.0 -Summary: Mesh Core API -Group: System/Libraries -Source0: %{name}-%{version}.tar.gz -Source1001: %{name}.manifest -BuildRequires: cmake -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(gio-2.0) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(capi-base-common) -BuildRequires: pkgconfig(capi-system-info) -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig - -%description -Mesh network Core API library - -%package devel -Summary: Mesh Core API -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -Mesh Core API library (development library) - -%prep -%setup -q -cp %{SOURCE1001} . - -%build -MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DLIB_INSTALL_DIR=%{_libdir} \ - -DBIN_INSTALL_DIR=%{_bindir} \ - -DLIB_PATH=%{_lib} \ - -DFULLVER=%{version} \ - -DMAJORVER=${MAJORVER} - -make %{?jobs:-j%jobs} - -%install -rm -rf %{buildroot} -%make_install - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - -%files -%manifest capi-network-mesh.manifest -%attr(644,-,-) %{_libdir}/libcapi-network-mesh.so.* -%license LICENSE -%{_bindir}/mesh_test - -%files devel -%{_includedir}/network/*.h -%{_libdir}/pkgconfig/*.pc -%{_libdir}/libcapi-network-mesh.so diff --git a/packaging/capi-network-wifi-mesh.manifest b/packaging/capi-network-wifi-mesh.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/capi-network-wifi-mesh.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/capi-network-wifi-mesh.spec b/packaging/capi-network-wifi-mesh.spec new file mode 100644 index 0000000..a8b13c5 --- /dev/null +++ b/packaging/capi-network-wifi-mesh.spec @@ -0,0 +1,65 @@ +%define major 0 +%define minor 1 +%define patchlevel 1 + +Name: capi-network-wifi-mesh +Version: %{major}.%{minor}.%{patchlevel} +Release: 1 +License: Apache-2.0 +Summary: Wi-Fi Mesh Core API +Group: System/Libraries +Source0: %{name}-%{version}.tar.gz +Source1001: %{name}.manifest +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +Wi-Fi Mesh network Core API library + +%package devel +Summary: Wi-Fi Mesh Core API +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +Mesh Core API library (development library) + +%prep +%setup -q +cp %{SOURCE1001} . + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DLIB_INSTALL_DIR=%{_libdir} \ + -DBIN_INSTALL_DIR=%{_bindir} \ + -DLIB_PATH=%{_lib} \ + -DFULLVER=%{version} \ + -DMAJORVER=${MAJORVER} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest capi-network-wifi-mesh.manifest +%attr(644,-,-) %{_libdir}/libcapi-network-wifi-mesh.so.* +%license LICENSE +%{_bindir}/wifi-mesh-test + +%files devel +%{_includedir}/network/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-network-wifi-mesh.so diff --git a/src/mesh.c b/src/mesh.c deleted file mode 100644 index 436bcdb..0000000 --- a/src/mesh.c +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "mesh.h" -#include "mesh_log.h" -#include "mesh_private.h" -#include "mesh_dbus.h" - -/** - * Mesh network CAPI - */ - -EXPORT_API int mesh_network_new(mesh_network_h* network) -{ - struct mesh_network_s *net; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net = calloc(1, sizeof(struct mesh_network_s)); - if (NULL == net) { - /* LCOV_EXCL_START */ - LOGE("Out of memory"); - return MESH_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - *network = (mesh_network_h)net; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_clone(mesh_network_h* dst, mesh_network_h src) -{ - struct mesh_network_s *net = NULL; - struct mesh_network_s *_src = src; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (dst == NULL || src == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net = calloc(1, sizeof(struct mesh_network_s)); - if (NULL == net) { - /* LCOV_EXCL_START */ - LOGE("Out of memory"); - return MESH_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - snprintf(net->meshid, MAX_MESHID_LEN, "%s", _src->meshid); - snprintf(net->bssid, MAX_BSSID_LEN, "%s", _src->bssid); - net->channel = _src->channel; - net->rssi = _src->rssi; - net->data_rate = _src->data_rate; - net->security = _src->security; - if (strlen(_src->passphrase) > 0) - snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", _src->passphrase); - - *dst = (mesh_network_h)net; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_new_with(mesh_network_h* network, const char *meshid, - const char *bssid, int channel, int rssi, mesh_security_type_e security, - const char *passphrase) -{ - struct mesh_network_s *net; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net = calloc(1, sizeof(struct mesh_network_s)); - if (meshid) - snprintf(net->meshid, MAX_MESHID_LEN, "%s", meshid); - if (bssid) - snprintf(net->bssid, MAX_BSSID_LEN, "%s", bssid); - net->channel = channel; - net->rssi = rssi; - net->security = security; - if (passphrase) - snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase); - - *network = (mesh_network_h)net; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_destroy(mesh_network_h network) -{ - struct mesh_network_s *net = network; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (NULL == net) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - free(net); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_meshid(mesh_network_h network, char **meshid) -{ - struct mesh_network_s *net = network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || meshid == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *meshid = strdup(net->meshid); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_meshid(mesh_network_h network, const char *meshid) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || meshid == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - snprintf(net->meshid, MAX_MESHID_LEN, "%s", meshid); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_bssid(mesh_network_h network, char **bssid) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || bssid == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *bssid = strdup(net->bssid); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_bssid(mesh_network_h network, const char *bssid) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || bssid == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - snprintf(net->bssid, MAX_BSSID_LEN, "%s", bssid); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_channel(mesh_network_h network, int *channel) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || channel == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *channel = net->channel; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_channel(mesh_network_h network, int channel) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net->channel = channel; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_rssi(mesh_network_h network, int *rssi) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || rssi == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *rssi = net->rssi; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_rssi(mesh_network_h network, int rssi) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net->rssi = rssi; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_security(mesh_network_h network, mesh_security_type_e *security) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || security == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *security = net->security; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_security(mesh_network_h network, mesh_security_type_e security) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net->security = security; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_passphrase(mesh_network_h network, const char* passphrase) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - if (passphrase) - snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase); - else - memset(net->passphrase, 0x0, MAX_PASSPHRASE_LEN); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_get_connection_state(mesh_network_h network, - mesh_connection_state_e *state) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || state == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *state = net->state; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_peer_get_address(mesh_peer_h peer, char **address) -{ - struct mesh_peer_s *peer_info = (struct mesh_peer_s *)peer; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (peer == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *address = strdup(peer_info->address); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_initialize(mesh_h *mesh) -{ - int rv; - struct mesh_handle* handle; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (mesh == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - handle = g_new0(struct mesh_handle, 1); - if (NULL == handle) { - LOGE("Failed to create handle"); - return MESH_ERROR_OUT_OF_MEMORY; - } - *mesh = handle; - - rv = _mesh_dbus_start(*mesh); - if (rv != MESH_ERROR_NONE) - LOGD("D-Bus init: (0x%X)", rv); - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_deinitialize(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - rv = _mesh_dbus_stop(handle); - - LOGI("Destroy handle: %p", handle); - - return rv; -} - -EXPORT_API int mesh_set_event_cb(mesh_h handle, mesh_event_cb event_handler) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_set_event_cb(handle, event_handler); - return rv; -} - -EXPORT_API int mesh_enable(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_enable(handle); - return rv; -} - -EXPORT_API int mesh_disable(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_disable(handle); - return rv; -} - -EXPORT_API int mesh_scan(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_scan(handle); - return rv; -} - -EXPORT_API int mesh_specific_scan(mesh_h handle, const char* ssid, int channel) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == ssid, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_specific_scan(handle, ssid, channel); - return rv; -} - -EXPORT_API int mesh_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_network_cb cb, void *user_data) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_get_scan_result(handle); - if (MESH_ERROR_NONE != rv) - return rv; - - rv = _mesh_foreach_found_mesh_network(handle, cb, user_data); - return rv; -} - -EXPORT_API int mesh_foreach_connected_peers(mesh_h handle, - mesh_connected_peer_cb cb, void *user_data) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_find_peers(handle); - if (MESH_ERROR_NONE != rv) - return rv; - - rv = _mesh_foreach_connected_peers(handle, cb, user_data); - return rv; -} - -EXPORT_API int mesh_enable_mesh(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_enable_mesh(handle); - return rv; -} - -EXPORT_API int mesh_disable_mesh(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_disable_mesh(handle); - return rv; -} - -EXPORT_API int mesh_is_joined(mesh_h handle, bool* is_joined) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_is_joined(handle, is_joined); - return rv; -} - -EXPORT_API int mesh_get_joined_network(mesh_h handle, mesh_network_h *network) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_get_joined_mesh_network(handle, network); - return rv; -} - -EXPORT_API int mesh_set_softap(mesh_h handle, const char* ssid, - const char* key, int channel, bool visibility, - int max_stations, int security) -{ - int rv = 0; - char buf[32] = {0,}; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == ssid, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == key, MESH_ERROR_INVALID_PARAMETER); - - if (channel <= 13) - memcpy(buf, "g", strlen("g")); - else - memcpy(buf, "a", strlen("a")); - - rv = _mesh_set_softap(handle, ssid, key, buf, channel, - visibility, max_stations, security); - return rv; -} - -EXPORT_API int mesh_enable_softap(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_enable_softap(handle); - return rv; -} - -EXPORT_API int mesh_disable_softap(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_disable_softap(handle); - return rv; -} - -EXPORT_API int mesh_create_mesh_network(mesh_h handle, mesh_network_h network) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_create_network(handle, network); - return rv; -} - -EXPORT_API int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_connect_network(handle, network); - return rv; -} - -EXPORT_API int mesh_disconnect_mesh_network(mesh_h handle, mesh_network_h network) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_disconnect_network(handle, network); - return rv; -} - -EXPORT_API int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_forget_network(handle, network); - return rv; -} - diff --git a/src/mesh_dbus.c b/src/mesh_dbus.c deleted file mode 100644 index be8cebc..0000000 --- a/src/mesh_dbus.c +++ /dev/null @@ -1,1421 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "mesh.h" -#include "mesh_log.h" -#include "mesh_dbus.h" -#include "mesh_private.h" -#include "service_error.h" - -static GDBusProxy *_gproxy_mesh_service = NULL; - -static int _mesh_close_gdbus_call(mesh_h m); - -static mesh_error_e __convert_service_error_type(service_error_e err_type) -{ - switch (err_type) { - case SERVICE_ERROR_NONE: - return MESH_ERROR_NONE; - case SERVICE_ERROR_IO_ERROR: - return MESH_ERROR_IO_ERROR; - case SERVICE_ERROR_NO_DATA: - return MESH_ERROR_NO_DATA; - case SERVICE_ERROR_OUT_OF_MEMORY: - return MESH_ERROR_OUT_OF_MEMORY; - case SERVICE_ERROR_OPERATION_FAILED: - return MESH_ERROR_OPERATION_FAILED; - case SERVICE_ERROR_INVALID_PARAMETER: - return MESH_ERROR_INVALID_PARAMETER; - case SERVICE_ERROR_ALREADY_REGISTERED: - return MESH_ERROR_ALREADY_IN_PROGRESS; - case SERVICE_ERROR_IN_PROGRESS: - return MESH_ERROR_NOW_IN_PROGRESS; - default: - return MESH_ERROR_OPERATION_FAILED; - } -} - -static GDBusProxy *_proxy_get_mesh_service(struct mesh_handle *handle) -{ - GDBusProxy *proxy = NULL; - RETVM_IF(NULL == handle, NULL, "Connection Object is invalid"); - - if (NULL == _gproxy_mesh_service) { - proxy = g_dbus_proxy_new_sync(handle->dbus_connection, - G_DBUS_PROXY_FLAGS_NONE, NULL, - MESH_SERVER_NAME, - MESH_OBJECT_PATH, - MESH_SERVICE_INTERFACE, - NULL, NULL); - } else - proxy = _gproxy_mesh_service; - - return proxy; -} - -static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, - gpointer *user_data) -{ - GDBusProxy *proxy = G_DBUS_PROXY(object); - gchar *name_owner = g_dbus_proxy_get_name_owner(proxy); - mesh_h handle = (mesh_h)user_data; - - LOGD("Name owner notify [%s]", name_owner); - - if (NULL == name_owner) - _mesh_close_gdbus_call(handle); - - g_free(name_owner); -} - -static int _mesh_create_gdbus_call(mesh_h handle) -{ - int id; - GError *error = NULL; - struct mesh_handle *h = handle; - - if (NULL == h) - return MESH_ERROR_INVALID_PARAMETER; - - if (h->dbus_connection != NULL) - return MESH_ERROR_ALREADY_IN_PROGRESS; - - h->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (h->dbus_connection == NULL) { - if (error != NULL) { - LOGE("Failed to connect to the D-BUS daemon [%s]", error->message); - g_error_free(error); - } - return MESH_ERROR_IO_ERROR; - } - - id = g_signal_connect(h->dbus_connection, "notify::g-name-owner", - G_CALLBACK(_dbus_name_owner_notify), h); - if (0 == id) { - LOGE("g_signal_connect() Fail"); - g_object_unref(h->dbus_connection); - h->dbus_connection = NULL; - return MESH_ERROR_IO_ERROR; - } - - return MESH_ERROR_NONE; -} - -static int _mesh_close_gdbus_call(mesh_h handle) -{ - struct mesh_handle *h = handle; - - /* CHECK: is connection ref count required? */ - g_object_unref(h->dbus_connection); - h->dbus_connection = NULL; - - return MESH_ERROR_NONE; -} - -static GList *g_networks = { 0, }; -static void _mesh_free_network(gpointer data) -{ - struct mesh_network_s *network = data; - g_free(network); - network = NULL; -} - -static void _mesh_remove_networks() -{ - if (g_networks) - g_list_free_full(g_networks, _mesh_free_network); - g_networks = NULL; -} - -static void _mesh_append_network(gpointer data) -{ - g_networks = g_list_append(g_networks, data); -} - -static GList *g_peers = NULL; -static void _mesh_remove_peers() -{ - if (g_peers) - g_list_free(g_peers); - g_peers = NULL; -} - -static void _mesh_append_peer(gpointer data) -{ - g_peers = g_list_append(g_peers, data); -} - -int _mesh_get_scan_result(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - - gchar *key; - GVariant *val; - gsize len = 0; - - /* Clear previous scan results */ - _mesh_remove_networks(); - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_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) { - g_variant_get(variant, "(aa{sv}i)", &iter, &result); - result = __convert_service_error_type(result); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - struct mesh_network_s *network_info = - g_malloc0(sizeof(struct mesh_network_s)); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - if (strcasecmp(key, "mesh_id") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(network_info->meshid, buf, len); - LOGD(" MeshID [%s]", network_info->meshid); - } else if (strcasecmp(key, "bssid") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(network_info->bssid, buf, len); - LOGD(" BSSID [%s]", network_info->bssid); - } else if (strcasecmp(key, "rssi") == 0) { - network_info->rssi = g_variant_get_int32(val); - LOGD(" RSSI [%d]", network_info->rssi); - } else if (strcasecmp(key, "channel") == 0) { - network_info->channel = g_variant_get_uint32(val); - LOGD(" Channel [%d]", network_info->channel); - } else if (strcasecmp(key, "security") == 0) { - guint sec = g_variant_get_uint32(val); - network_info->security = ((1 == sec) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE); - LOGD(" Security [%s]", - (MESH_SECURITY_SAE == network_info->security) ? "SAE" : "NONE"); - } else if (strcasecmp(key, "state") == 0) { - network_info->state = g_variant_get_uint32(val); - LOGD(" State [%d]", network_info->state); - } - } - _mesh_append_network(network_info); - - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_find_peers(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - - gchar *key; - GVariant *val; - gsize len = 0; - - /* Clear previous peer list */ - _mesh_remove_peers(); - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_connected_peers", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(aa{sv}i)", &iter, &result); - result = __convert_service_error_type(result); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - struct mesh_peer_s *peer_info = - g_malloc0(sizeof(struct mesh_peer_s)); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - if (strcasecmp(key, "Address") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(peer_info->address, buf, len); - LOGD(" Address [%s]", peer_info->address); - } - } - /* Last element */ - _mesh_append_peer(peer_info); - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -static void _mesh_signal_handler(GDBusConnection *connection, - const gchar *sender_name, const gchar *object_path, const gchar *interface_name, - const gchar *signal_name, GVariant *parameters, gpointer user_data) -{ - mesh_handle_s *h = user_data; - - RETM_IF(NULL == h, "user_data is null"); - RETM_IF(NULL == h->event_handler, "event_handler is null"); - LOGD("signal received = %s", signal_name); - - if (0 == g_strcmp0(signal_name, "mesh_enabled")) { - int result = MESH_ERROR_NONE; - mesh_event_data_s ev; - - g_variant_get(parameters, "(i)", &result); - - ev.data.mesh_enable = calloc(1, sizeof(mesh_mesh_enabled_event_s)); - RETM_IF(NULL == ev.data.mesh_enable, "Failed to memory allocation !"); - ev.data.mesh_enable->result = __convert_service_error_type(result); - - h->event_handler(MESH_EVENT_ENABLED, &ev); - free(ev.data.mesh_enable); - } else if (0 == g_strcmp0(signal_name, "scan_done")) { - h->event_handler(MESH_EVENT_SCAN_DONE, NULL); - } else if (0 == g_strcmp0(signal_name, "connection_state")) { - char *mesh_id = NULL; - char *bssid = NULL; - int channel = 0; - int state = 0; - int security = 0; - mesh_event_data_s ev; - - g_variant_get(parameters, "(ssiii)", &mesh_id, &bssid, &channel, &security, &state); - - ev.data.connection_state = calloc(1, sizeof(mesh_connection_state_event_s)); - RETM_IF(NULL == ev.data.connection_state, "Failed to memory allocation !"); - - g_snprintf(ev.data.connection_state->mesh_id, MAX_MESHID_LEN, "%s", mesh_id); - g_snprintf(ev.data.connection_state->bssid, MAX_BSSID_LEN, "%s", bssid); - ev.data.connection_state->channel = channel; - ev.data.connection_state->security = (mesh_security_type_e)security; - ev.data.connection_state->state = (mesh_connection_state_e)state; - - h->event_handler(MESH_EVENT_CONNECTION_STATE, &ev); - free(ev.data.connection_state); - } else if (0 == g_strcmp0(signal_name, "sta_joined")) { - char *bssid = NULL; - mesh_event_data_s ev; - ev.data.sta_info = calloc(1, sizeof(mesh_other_station_event_s)); - RETM_IF(NULL == ev.data.sta_info, "Failed to memory allocation !"); - g_variant_get(parameters, "(s)", &bssid); - memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); - h->event_handler(MESH_EVENT_STATION_JOIN, &ev); - free(ev.data.sta_info); - } else if (0 == g_strcmp0(signal_name, "sta_left")) { - char *bssid = NULL; - mesh_event_data_s ev; - ev.data.sta_info = calloc(1, sizeof(mesh_other_station_event_s)); - RETM_IF(NULL == ev.data.sta_info, "Failed to memory allocation !"); - g_variant_get(parameters, "(s)", &bssid); - memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); - h->event_handler(MESH_EVENT_STATION_LEFT, &ev); - free(ev.data.sta_info); - } -} - -static void _mesh_subscribe_event(mesh_h handle) -{ - unsigned int id; - struct mesh_handle *h = handle; - - /* mesh_enabled */ - id = g_dbus_connection_signal_subscribe((GDBusConnection *)h->dbus_connection, - NULL, MESH_SERVER_NAME, "mesh_enabled", MESH_OBJECT_PATH, NULL, - G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); - if (0 == id) { - LOGE("g_dbus_connection_signal_subscribe(mesh_enabled) Fail(%d)", errno); - return; - } - h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); - LOGD("subscribed for mesh_enabled signal %d", id); - - /* scan_done */ - id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, - "scan_done", MESH_OBJECT_PATH, NULL, - G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); - if (0 == id) { - LOGE("g_dbus_connection_signal_subscribe(scan_done) Fail(%d)", errno); - return; - } - h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); - LOGD("subscribed for scan_done signal %d", id); - - /* connection_state */ - id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, - "connection_state", MESH_OBJECT_PATH, NULL, - G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); - if (0 == id) { - LOGE("g_dbus_connection_signal_subscribe(connection_state) Fail(%d)", errno); - return; - } - h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); - LOGD("subscribed for connection_state signal %d", id); - - /* sta_joined */ - id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, - "sta_joined", MESH_OBJECT_PATH, NULL, - G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); - if (0 == id) { - LOGE("g_dbus_connection_signal_subscribe(sta_joined) Fail(%d)", errno); - return; - } - h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); - LOGD("subscribed for sta_joined signal %d", id); - - /* sta_left */ - id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, - "sta_left", MESH_OBJECT_PATH, NULL, - G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); - if (0 == id) { - LOGE("g_dbus_connection_signal_subscribe(sta_left) Fail(%d)", errno); - return; - } - h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); - LOGD("subscribed for sta_left signal %d", id); -} - -static void _on_unsubscribe_ids(gpointer data, gpointer user_data) -{ - unsigned int id = GPOINTER_TO_UINT(data); - struct mesh_handle *h = (struct mesh_handle*)user_data; - - LOGD("[Signal unsubscribe] : %d", id); - g_dbus_connection_signal_unsubscribe( - (GDBusConnection *)h->dbus_connection, id); -} - -static void _mesh_unsubscribe_event(mesh_h handle) -{ - struct mesh_handle *h = handle; - RET_IF(NULL == h); - - g_list_foreach(h->dbus_sub_ids, _on_unsubscribe_ids, h); - - g_list_free(h->dbus_sub_ids); - h->dbus_sub_ids = NULL; -} - -int _mesh_dbus_start(mesh_h handle) -{ - struct mesh_handle *h = handle; - int rv; - - rv = _mesh_create_gdbus_call(handle); - if (MESH_ERROR_NONE != rv) - return rv; - - h->ca = g_cancellable_new(); - - /* Create all proxies here */ - _gproxy_mesh_service = _proxy_get_mesh_service(h); - RETVM_IF(NULL == _gproxy_mesh_service, - MESH_ERROR_IO_ERROR, "Couldn't get _gproxy_mesh_service"); - g_dbus_proxy_set_default_timeout( - G_DBUS_PROXY(_gproxy_mesh_service), MESH_DBUS_PROXY_TIMEOUT); - - /* Subscribe events */ - _mesh_subscribe_event(handle); - - return MESH_ERROR_NONE; -} - -int _mesh_dbus_stop(mesh_h handle) -{ - struct mesh_handle *h = handle; - int rv; - - if (NULL == h) - return MESH_ERROR_INVALID_PARAMETER; - - _mesh_unsubscribe_event(handle); - - /* Unref all proxies here */ - if (_gproxy_mesh_service) { - g_object_unref(_gproxy_mesh_service); - _gproxy_mesh_service = NULL; - } - - g_cancellable_cancel(h->ca); - g_object_unref(h->ca); - h->ca = NULL; - - rv = _mesh_close_gdbus_call(handle); - return rv; -} - -struct mesh_mpath_list_s { - int count; - GList *list; -}; -struct mesh_mpath_list_s g_mpath; - -#if 0 -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; -} -#endif - -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() -{ - /* If there is no dynamically allocated one, use g_list_free */ - g_list_free(g_mpath.list); - g_mpath.list = NULL; - g_mpath.count = 0; -} - -int _mesh_set_event_cb(mesh_h handle, mesh_event_cb event_handler) -{ - struct mesh_handle *h = handle; - RETV_IF(NULL == h, MESH_ERROR_INVALID_PARAMETER); - h->event_handler = event_handler; - return MESH_ERROR_NONE; -} - -int _mesh_enable(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - - variant = g_dbus_connection_call_sync(h->dbus_connection, - MESH_MANAGER_NAME, - MESH_MANAGER_OBJ_PATH, - MESH_MANAGER_INTERFACE, - "enable", - NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("enabled status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_disable(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - _mesh_remove_peers(); - _mesh_remove_networks(); - _mesh_remove_mpath(); - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - - variant = g_dbus_connection_call_sync(h->dbus_connection, - MESH_MANAGER_NAME, - MESH_MANAGER_OBJ_PATH, - MESH_MANAGER_INTERFACE, - "disable", - NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("Disabled status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - h->event_handler = NULL; - - return result; -} - -int _mesh_scan(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "scan", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("scan status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_specific_scan(mesh_h handle, const char* ssid, int channel) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "specific_scan", - g_variant_new("(si)", ssid, channel), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("specific_scan status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_cancel_scan(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "cancel_scan", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("cancle_scan status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_network_cb cb, void *user_data) -{ - int i; - GList *iter = NULL; - struct mesh_network_s *data = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); - - if (0 >= g_list_length(g_networks)) { - LOGD("No scan result"); - return MESH_ERROR_NONE; - } - - /* Get a first item */ - i = 0; - iter = g_list_first(g_networks); - - while (NULL != iter) { - data = iter->data; - if (data) - LOGE("data is null"); - cb(data, user_data); - /* Next item */ - iter = g_list_next(iter); - i++; - } - - return MESH_ERROR_NONE; -} - -int _mesh_foreach_connected_peers(mesh_h handle, - mesh_connected_peer_cb cb, void *user_data) -{ - int i; - GList *iter = NULL; - struct mesh_network_s *data = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); - - if (0 >= g_list_length(g_peers)) { - LOGD("No peer data"); - return MESH_ERROR_NONE; - } - - /* Get a first item */ - i = 0; - iter = g_list_first(g_peers); - - while (NULL != iter) { - data = iter->data; - if (data) - LOGE("data is null"); - cb(data, user_data); - /* Next item */ - iter = g_list_next(iter); - i++; - } - - return MESH_ERROR_NONE; -} - -int _mesh_enable_mesh(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "enable_mesh", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("enable_mesh status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_disable_mesh(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disable_mesh", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("disable_mesh status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -/* TODO: Parameter verification required */ -int _mesh_is_joined(mesh_h handle, bool* is_joined) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - gboolean state; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "is_joined", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(bi)", &state, &result); - LOGD("Mesh is_joined status 0x%x", result); - result = __convert_service_error_type(result); - *is_joined = ((state) ? true : false); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -struct mesh_network_s g_joined_network; - -int _mesh_get_joined_mesh_network(mesh_h handle, mesh_network_h* _network) -{ - int result = MESH_ERROR_NONE; - GVariant *variant = NULL; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _network, MESH_ERROR_INVALID_PARAMETER); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_joined_mesh_network", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - char *meshid = NULL; - char *bssid = NULL; - int channel = -1; - int security = -1; - int state = 0; - int svc_result = 0; - - g_variant_get(variant, "(ssiiii)", &meshid, &bssid, &channel, - &security, &state, &svc_result); - LOGD("get_joined_mesh_network status 0x%x", svc_result); - result = __convert_service_error_type(svc_result); - - /* Clear previous information */ - memset(g_joined_network.meshid, 0, MAX_MESHID_LEN); - memset(g_joined_network.bssid, 0, MAX_BSSID_LEN); - g_joined_network.channel = 0; - g_joined_network.rssi = -1; - g_joined_network.data_rate = 0; - g_joined_network.security = MESH_SECURITY_NONE; - g_joined_network.state = MESH_CONNECTION_STATE_DISCONNECTED; - - if (SERVICE_ERROR_NO_DATA == svc_result) { - *_network = NULL; - return MESH_ERROR_NONE; - } - - if (MESH_ERROR_NONE != result) - return result; - - if (meshid) { - LOGE(" Mesh ID : %s", meshid); - snprintf(g_joined_network.meshid, MAX_MESHID_LEN, "%s", meshid); - } - if (bssid) { - LOGE(" BSSID : %s", bssid); - snprintf(g_joined_network.bssid, MAX_BSSID_LEN, "%s", bssid); - } - g_joined_network.channel = channel; - g_joined_network.rssi = -1; - g_joined_network.security = security; - g_joined_network.state = state; - - *_network = &g_joined_network; - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_set_gate(mesh_h handle, bool gate_announce, int hwmp_root_mode, bool stp) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_gate", - g_variant_new("(bqq)", gate_announce, hwmp_root_mode, stp), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("set_gate status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_unset_gate(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "unset_gate", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("unset_gate status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_set_softap(mesh_h handle, const char* ssid, - const char* key, const char* mode, - int channel, int visibility, - int max_stations, int security) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_softap", - g_variant_new("(sssiiii)", ssid, key, mode, - channel, visibility, max_stations, security), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("set_softap status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_enable_softap(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "enable_softap", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("enable_softap status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_disable_softap(mesh_h handle) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disable_softap", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("disable_softap status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_create_network(mesh_h handle, mesh_network_h _network) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - struct mesh_network_s *n = _network; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "create_mesh_network", - g_variant_new("(sii)", n->meshid, n->channel, n->security), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("create_network status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_connect_network(mesh_h handle, mesh_network_h _network) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - struct mesh_network_s *n = _network; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "connect_mesh_network", - g_variant_new("(siis)", n->meshid, n->channel, n->security, n->passphrase), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("connect network status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_disconnect_network(mesh_h handle, mesh_network_h _network) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - struct mesh_network_s *n = _network; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disconnect_mesh_network", - g_variant_new("(sii)", n->meshid, n->channel, n->security), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("disconnect network status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_forget_network(mesh_h handle, mesh_network_h _network) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - struct mesh_network_s *n = _network; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - LOGD("mesid=%s channel=%d security=%d", n->meshid, n->channel, n->security); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "forget_mesh_network", - g_variant_new("(sii)", n->meshid, n->channel, n->security), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("forget_network status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - - gchar *key; - GVariant *val; - gsize len = 0; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_station_info", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - /* handle station list here */ - g_variant_get(variant, "(aa{sv}i)", &iter, &result); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - struct mesh_station_info_s station; - memset(&station, 0, sizeof(struct mesh_station_info_s)); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - if (strcasecmp(key, "bssid") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(station.bssid, buf, len); - LOGE("bssid=%s", station.bssid); - } else if (strcasecmp(key, "inactive_time") == 0) { - station.inactive_time = g_variant_get_uint32(val); - LOGE("inactive_time = %ld", station.inactive_time); - } else if (strcasecmp(key, "rx_bytes") == 0) { - station.rx_bytes = g_variant_get_uint64(val); - LOGE("rx_bytes = %ld", station.rx_bytes); - } else if (strcasecmp(key, "rx_packets") == 0) { - station.rx_packets = g_variant_get_uint32(val); - LOGE("rx_packets = %d", station.rx_packets); - } else if (strcasecmp(key, "tx_bytes") == 0) { - station.tx_bytes = g_variant_get_uint64(val); - LOGE("tx_bytes = %ld", station.tx_bytes); - } else if (strcasecmp(key, "tx_packets") == 0) { - station.tx_packets = g_variant_get_uint32(val); - LOGE("rx_packets = %d", station.tx_packets); - } else if (strcasecmp(key, "tx_retries") == 0) { - station.tx_retries = g_variant_get_uint32(val); - LOGE("tx_retries = %d", station.tx_retries); - } else if (strcasecmp(key, "tx_failed") == 0) { - station.tx_failed = g_variant_get_uint32(val); - LOGE("tx_failed = %d", station.tx_failed); - } else if (strcasecmp(key, "beacon_loss") == 0) { - station.beacon_loss = g_variant_get_uint32(val); - LOGE("beacon_loss = %d", station.beacon_loss); - } else if (strcasecmp(key, "beacon_rx") == 0) { - station.beacon_rx = g_variant_get_uint64(val); - LOGE("beacon_rx = %d", station.beacon_rx); - } else if (strcasecmp(key, "rx_drop_misc") == 0) { - station.rx_drop_misc = g_variant_get_uint64(val); - LOGE("rx_drop_misc = %d", station.rx_drop_misc); - } else if (strcasecmp(key, "signal") == 0) { - station.signal = g_variant_get_int32(val); - LOGE("signal = %d", station.signal); - } else if (strcasecmp(key, "signal_avg") == 0) { - station.signal_avg = g_variant_get_int32(val); - LOGE("signal_avg = %d", station.signal_avg); - } else if (strcasecmp(key, "tx_bitrate") == 0) { - station.tx_bitrate = g_variant_get_uint32(val); - LOGE("tx_bitrate = %d", station.tx_bitrate); - } else if (strcasecmp(key, "rx_bitrate") == 0) { - station.rx_bitrate = g_variant_get_uint32(val); - LOGE("rx_bitrate = %d", station.rx_bitrate); - } else if (strcasecmp(key, "mesh_llid") == 0) { - station.mesh_llid = g_variant_get_uint16(val); - LOGE("mesh_llid = %d", station.mesh_llid); - } else if (strcasecmp(key, "mesh_plid") == 0) { - station.mesh_plid = g_variant_get_uint16(val); - LOGE("mesh_plid = %d", station.mesh_plid); - } else if (strcasecmp(key, "mesh_plink") == 0) { - station.mesh_plink = g_variant_get_byte(val); - LOGE("mesh_plink = %d", station.mesh_plink); - } else if (strcasecmp(key, "local_ps_mode") == 0) { - station.local_ps_mode = g_variant_get_uint32(val); - LOGE("local_ps_mode = %d", station.local_ps_mode); - } else if (strcasecmp(key, "peer_ps_mode") == 0) { - station.peer_ps_mode = g_variant_get_uint32(val); - LOGE("peer_ps_mode = %d", station.peer_ps_mode); - } else if (strcasecmp(key, "non_peer_ps_mode") == 0) { - station.non_peer_ps_mode = g_variant_get_uint32(val); - LOGE("non_peer_ps_mode = %d", station.non_peer_ps_mode); - } else if (strcasecmp(key, "authorized") == 0) { - station.authorized = g_variant_get_boolean(val); - LOGE("authorized = %d", station.authorized); - } else if (strcasecmp(key, "authenticated") == 0) { - station.authenticated = g_variant_get_boolean(val); - LOGE("authenticated = %d", station.authenticated); - } else if (strcasecmp(key, "associated") == 0) { - station.associated = g_variant_get_boolean(val); - LOGE("associated = %d", station.associated); - } else if (strcasecmp(key, "preamble") == 0) { - station.preamble = g_variant_get_boolean(val); - LOGE("preamble = %d", station.preamble); - } else if (strcasecmp(key, "WMM_WME") == 0) { - station.wmm_wme = g_variant_get_boolean(val); - LOGE("wmm_wme = %d", station.wmm_wme); - } else if (strcasecmp(key, "MFP") == 0) { - station.mfp = g_variant_get_boolean(val); - LOGE("mfp = %d", station.mfp); - } else if (strcasecmp(key, "TDLS_peer") == 0) { - station.tdls_peer = g_variant_get_boolean(val); - LOGE("tdls_peer = %d", station.tdls_peer); - } else if (strcasecmp(key, "DTIM_period") == 0) { - station.dtim_period = g_variant_get_byte(val); - LOGE("dtim_period = %d", station.dtim_period); - } else if (strcasecmp(key, "beacon_interval") == 0) { - station.beacon_interval = g_variant_get_uint16(val); - LOGE("beacon_interval = %d", station.beacon_interval); - } else if (strcasecmp(key, "short_slot_time") == 0) { - station.short_slot_time = g_variant_get_boolean(val); - LOGE("short_slot_time = %d", station.short_slot_time); - } else if (strcasecmp(key, "connected_time") == 0) { - station.connected_time = g_variant_get_uint32(val); - LOGE("connected_time = %d", station.connected_time); - /* Let users know what stations joined */ - if (cb) cb(&station, user_data); - } - } - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - LOGD("get_saved_mesh_networks status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - - gchar *key; - GVariant *val; - gsize len = 0; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_mpath_info", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - /* handle station list here */ - _mesh_remove_mpath(); - - /* handle station list here */ - g_variant_get(variant, "(aa{sv}i)", &iter, &result); - LOGE("1"); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - struct mesh_mpath_dump_s *mpath = g_malloc0(sizeof(struct mesh_mpath_dump_s)); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - if (strcasecmp(key, "DEST_ADDR") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(mpath->dest_addr, buf, len); - LOGE("dest_addr=%s", mpath->dest_addr); - } else if (strcasecmp(key, "NEXT_HOP") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(mpath->next_hop, buf, len); - LOGE("next_hop= %s", mpath->next_hop); - } else if (strcasecmp(key, "IFACE") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(mpath->iface, buf, len); - LOGE("iface= %s", mpath->iface); - } else if (strcasecmp(key, "SN") == 0) { - mpath->sn = g_variant_get_uint32(val); - LOGE("sn= %d", mpath->sn); - } else if (strcasecmp(key, "METRIC") == 0) { - mpath->metric = g_variant_get_uint32(val); - LOGE("metric= %d", mpath->metric); - } else if (strcasecmp(key, "QEN") == 0) { - mpath->qlen = g_variant_get_uint32(val); - LOGE("qlen= %d", mpath->qlen); - } else if (strcasecmp(key, "EXPTIME") == 0) { - mpath->exptime = g_variant_get_uint32(val); - LOGE("exptime= %d", mpath->exptime); - } else if (strcasecmp(key, "DTIM") == 0) { - mpath->discovery_timeout = g_variant_get_uint32(val); - LOGE("discovery_timeout= %d", mpath->discovery_timeout); - } else if (strcasecmp(key, "DRET") == 0) { - mpath->discovery_retries = g_variant_get_byte(val); - LOGE("discovery_retries= %d", mpath->discovery_retries); - } else if (strcasecmp(key, "FLAGS") == 0) { - mpath->flags = g_variant_get_byte(val); - LOGE("flags= %d", mpath->flags); - - /* Add temporal mesh path buffer */ - _mesh_add_mpath((gpointer)mpath); - - if (cb) - cb(mpath, user_data); - } - } - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - LOGD("get_saved_mesh_networks status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - -int _mesh_set_interfaces(mesh_h handle, const char *mesh, const char *gate, const char *softap) -{ - GVariant *variant = NULL; - int result = MESH_ERROR_NONE; - GError *error = NULL; - struct mesh_handle *h = handle; - - RETV_IF(NULL == h->dbus_connection, MESH_ERROR_IO_ERROR); - RETV_IF(NULL == _gproxy_mesh_service, MESH_ERROR_IO_ERROR); - - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_interfaces", - g_variant_new("(sss)", mesh, gate, softap), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - g_variant_get(variant, "(i)", &result); - LOGD("set_interfaces status 0x%x", result); - result = __convert_service_error_type(result); - } else if (error) { - LOGE("Failed DBus call [%s]", error->message); - g_error_free(error); - return MESH_ERROR_IO_ERROR; - } - - return result; -} - diff --git a/src/mesh_internal.c b/src/mesh_internal.c deleted file mode 100644 index 91d4d4a..0000000 --- a/src/mesh_internal.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mesh.h" -#include "mesh_log.h" -#include "mesh_private.h" -#include "mesh_dbus.h" - -/** - * Mesh network CAPI - */ - -EXPORT_API int mesh_network_get_data_rate(mesh_network_h network, int *data_rate) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL || data_rate == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - *data_rate = net->data_rate; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_network_set_data_rate(mesh_network_h network, int data_rate) -{ - struct mesh_network_s *net = (struct mesh_network_s *)network; - - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - if (network == NULL) { - /* LCOV_EXCL_START */ - LOGE("Invalid parameter"); - return MESH_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ - } - - net->data_rate = data_rate; - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_cancel_scan(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_cancel_scan(handle); - return rv; -} - -EXPORT_API int mesh_set_gate(mesh_h handle, int gate_announce, int hwmp_root_mode, bool stp) -{ - int rv = 0; - int _stp = stp ? 1 : 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_set_gate(handle, gate_announce, hwmp_root_mode, _stp); - return rv; -} - -EXPORT_API int mesh_unset_gate(mesh_h handle) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_unset_gate(handle); - return rv; -} - -EXPORT_API int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_get_stations_info(handle, cb, user_data); - return rv; -} - -EXPORT_API int mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_get_mpath_info(handle, cb, user_data); - return rv; -} - -EXPORT_API int mesh_set_interfaces(mesh_h handle, - const char *mesh, const char* gate, const char *softap) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == mesh, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_set_interfaces(handle, mesh, gate, softap); - return rv; -} - diff --git a/src/wifi-mesh-dbus.c b/src/wifi-mesh-dbus.c new file mode 100644 index 0000000..f3fb6af --- /dev/null +++ b/src/wifi-mesh-dbus.c @@ -0,0 +1,1421 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "wifi-mesh.h" +#include "wifi-mesh_log.h" +#include "wifi-mesh_dbus.h" +#include "wifi-mesh_private.h" +#include "wifi-mesh_service_error.h" + +static GDBusProxy *_gproxy_mesh_service = NULL; + +static int _wifi_mesh_close_gdbus_call(wifi_mesh_h m); + +static wifi_mesh_error_e __convert_service_error_type(service_error_e err_type) +{ + switch (err_type) { + case SERVICE_ERROR_NONE: + return WIFI_MESH_ERROR_NONE; + case SERVICE_ERROR_IO_ERROR: + return WIFI_MESH_ERROR_IO_ERROR; + case SERVICE_ERROR_NO_DATA: + return WIFI_MESH_ERROR_NO_DATA; + case SERVICE_ERROR_OUT_OF_MEMORY: + return WIFI_MESH_ERROR_OUT_OF_MEMORY; + case SERVICE_ERROR_OPERATION_FAILED: + return WIFI_MESH_ERROR_OPERATION_FAILED; + case SERVICE_ERROR_INVALID_PARAMETER: + return WIFI_MESH_ERROR_INVALID_PARAMETER; + case SERVICE_ERROR_ALREADY_REGISTERED: + return WIFI_MESH_ERROR_ALREADY_IN_PROGRESS; + case SERVICE_ERROR_IN_PROGRESS: + return WIFI_MESH_ERROR_NOW_IN_PROGRESS; + default: + return WIFI_MESH_ERROR_OPERATION_FAILED; + } +} + +static GDBusProxy *_proxy_get_mesh_service(struct mesh_handle *handle) +{ + GDBusProxy *proxy = NULL; + RETVM_IF(NULL == handle, NULL, "Connection Object is invalid"); + + if (NULL == _gproxy_mesh_service) { + proxy = g_dbus_proxy_new_sync(handle->dbus_connection, + G_DBUS_PROXY_FLAGS_NONE, NULL, + MESH_SERVER_NAME, + MESH_OBJECT_PATH, + MESH_SERVICE_INTERFACE, + NULL, NULL); + } else + proxy = _gproxy_mesh_service; + + return proxy; +} + +static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, + gpointer *user_data) +{ + GDBusProxy *proxy = G_DBUS_PROXY(object); + gchar *name_owner = g_dbus_proxy_get_name_owner(proxy); + wifi_mesh_h handle = (wifi_mesh_h)user_data; + + LOGD("Name owner notify [%s]", name_owner); + + if (NULL == name_owner) + _wifi_mesh_close_gdbus_call(handle); + + g_free(name_owner); +} + +static int _wifi_mesh_create_gdbus_call(wifi_mesh_h handle) +{ + int id; + GError *error = NULL; + struct mesh_handle *h = handle; + + if (NULL == h) + return WIFI_MESH_ERROR_INVALID_PARAMETER; + + if (h->dbus_connection != NULL) + return WIFI_MESH_ERROR_ALREADY_IN_PROGRESS; + + h->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (h->dbus_connection == NULL) { + if (error != NULL) { + LOGE("Failed to connect to the D-BUS daemon [%s]", error->message); + g_error_free(error); + } + return WIFI_MESH_ERROR_IO_ERROR; + } + + id = g_signal_connect(h->dbus_connection, "notify::g-name-owner", + G_CALLBACK(_dbus_name_owner_notify), h); + if (0 == id) { + LOGE("g_signal_connect() Fail"); + g_object_unref(h->dbus_connection); + h->dbus_connection = NULL; + return WIFI_MESH_ERROR_IO_ERROR; + } + + return WIFI_MESH_ERROR_NONE; +} + +static int _wifi_mesh_close_gdbus_call(wifi_mesh_h handle) +{ + struct mesh_handle *h = handle; + + /* CHECK: is connection ref count required? */ + g_object_unref(h->dbus_connection); + h->dbus_connection = NULL; + + return WIFI_MESH_ERROR_NONE; +} + +static GList *g_networks = { 0, }; +static void _wifi_mesh_free_network(gpointer data) +{ + struct mesh_network_s *network = data; + g_free(network); + network = NULL; +} + +static void _mesh_remove_networks() +{ + if (g_networks) + g_list_free_full(g_networks, _wifi_mesh_free_network); + g_networks = NULL; +} + +static void _wifi_mesh_append_network(gpointer data) +{ + g_networks = g_list_append(g_networks, data); +} + +static GList *g_peers = NULL; +static void _wifi_mesh_remove_peers() +{ + if (g_peers) + g_list_free(g_peers); + g_peers = NULL; +} + +static void _wifi_mesh_append_peer(gpointer data) +{ + g_peers = g_list_append(g_peers, data); +} + +int _wifi_mesh_get_scan_result(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + + gchar *key; + GVariant *val; + gsize len = 0; + + /* Clear previous scan results */ + _mesh_remove_networks(); + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_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) { + g_variant_get(variant, "(aa{sv}i)", &iter, &result); + result = __convert_service_error_type(result); + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + struct mesh_network_s *network_info = + g_malloc0(sizeof(struct mesh_network_s)); + while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { + if (strcasecmp(key, "mesh_id") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(network_info->meshid, buf, len); + LOGD(" MeshID [%s]", network_info->meshid); + } else if (strcasecmp(key, "bssid") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(network_info->bssid, buf, len); + LOGD(" BSSID [%s]", network_info->bssid); + } else if (strcasecmp(key, "rssi") == 0) { + network_info->rssi = g_variant_get_int32(val); + LOGD(" RSSI [%d]", network_info->rssi); + } else if (strcasecmp(key, "channel") == 0) { + network_info->channel = g_variant_get_uint32(val); + LOGD(" Channel [%d]", network_info->channel); + } else if (strcasecmp(key, "security") == 0) { + guint sec = g_variant_get_uint32(val); + network_info->security = ((1 == sec) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE); + LOGD(" Security [%s]", + (MESH_SECURITY_SAE == network_info->security) ? "SAE" : "NONE"); + } else if (strcasecmp(key, "state") == 0) { + network_info->state = g_variant_get_uint32(val); + LOGD(" State [%d]", network_info->state); + } + } + _wifi_mesh_append_network(network_info); + + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); + + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_find_peers(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + + gchar *key; + GVariant *val; + gsize len = 0; + + /* Clear previous peer list */ + _wifi_mesh_remove_peers(); + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_connected_peers", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(aa{sv}i)", &iter, &result); + result = __convert_service_error_type(result); + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + struct mesh_peer_s *peer_info = + g_malloc0(sizeof(struct mesh_peer_s)); + while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { + if (strcasecmp(key, "Address") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(peer_info->address, buf, len); + LOGD(" Address [%s]", peer_info->address); + } + } + /* Last element */ + _wifi_mesh_append_peer(peer_info); + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); + + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +static void _mesh_signal_handler(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, const gchar *interface_name, + const gchar *signal_name, GVariant *parameters, gpointer user_data) +{ + mesh_handle_s *h = user_data; + + RETM_IF(NULL == h, "user_data is null"); + RETM_IF(NULL == h->event_handler, "event_handler is null"); + LOGD("signal received = %s", signal_name); + + if (0 == g_strcmp0(signal_name, "wifi_mesh_enabled")) { + int result = WIFI_MESH_ERROR_NONE; + wifi_mesh_event_data_s ev; + + g_variant_get(parameters, "(i)", &result); + + ev.data.wifi_mesh_enable = calloc(1, sizeof(wifi_mesh_enabled_event_s)); + RETM_IF(NULL == ev.data.wifi_mesh_enable, "Failed to memory allocation !"); + ev.data.wifi_mesh_enable->result = __convert_service_error_type(result); + + h->event_handler(WIFI_MESH_EVENT_ENABLED, &ev); + free(ev.data.wifi_mesh_enable); + } else if (0 == g_strcmp0(signal_name, "scan_done")) { + h->event_handler(WIFI_MESH_EVENT_SCAN_DONE, NULL); + } else if (0 == g_strcmp0(signal_name, "connection_state")) { + char *mesh_id = NULL; + char *bssid = NULL; + int channel = 0; + int state = 0; + int security = 0; + wifi_mesh_event_data_s ev; + + g_variant_get(parameters, "(ssiii)", &mesh_id, &bssid, &channel, &security, &state); + + ev.data.connection_state = calloc(1, sizeof(wifi_mesh_connection_state_event_s)); + RETM_IF(NULL == ev.data.connection_state, "Failed to memory allocation !"); + + g_snprintf(ev.data.connection_state->mesh_id, MAX_MESHID_LEN, "%s", mesh_id); + g_snprintf(ev.data.connection_state->bssid, MAX_BSSID_LEN, "%s", bssid); + ev.data.connection_state->channel = channel; + ev.data.connection_state->security = (wifi_mesh_security_type_e)security; + ev.data.connection_state->state = (wifi_mesh_connection_state_e)state; + + h->event_handler(WIFI_MESH_EVENT_CONNECTION_STATE, &ev); + free(ev.data.connection_state); + } else if (0 == g_strcmp0(signal_name, "sta_joined")) { + char *bssid = NULL; + wifi_mesh_event_data_s ev; + ev.data.sta_info = calloc(1, sizeof(wifi_mesh_other_station_event_s)); + RETM_IF(NULL == ev.data.sta_info, "Failed to memory allocation !"); + g_variant_get(parameters, "(s)", &bssid); + memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); + h->event_handler(WIFI_MESH_EVENT_STATION_JOIN, &ev); + free(ev.data.sta_info); + } else if (0 == g_strcmp0(signal_name, "sta_left")) { + char *bssid = NULL; + wifi_mesh_event_data_s ev; + ev.data.sta_info = calloc(1, sizeof(wifi_mesh_other_station_event_s)); + RETM_IF(NULL == ev.data.sta_info, "Failed to memory allocation !"); + g_variant_get(parameters, "(s)", &bssid); + memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN); + h->event_handler(WIFI_MESH_EVENT_STATION_LEFT, &ev); + free(ev.data.sta_info); + } +} + +static void _mesh_subscribe_event(wifi_mesh_h handle) +{ + unsigned int id; + struct mesh_handle *h = handle; + + /* wifi_mesh_enabled */ + id = g_dbus_connection_signal_subscribe((GDBusConnection *)h->dbus_connection, + NULL, MESH_SERVER_NAME, "wifi_mesh_enabled", MESH_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); + if (0 == id) { + LOGE("g_dbus_connection_signal_subscribe(wifi_mesh_enabled) Fail(%d)", errno); + return; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOGD("subscribed for wifi_mesh_enabled signal %d", id); + + /* scan_done */ + id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, + "scan_done", MESH_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); + if (0 == id) { + LOGE("g_dbus_connection_signal_subscribe(scan_done) Fail(%d)", errno); + return; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOGD("subscribed for scan_done signal %d", id); + + /* connection_state */ + id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, + "connection_state", MESH_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); + if (0 == id) { + LOGE("g_dbus_connection_signal_subscribe(connection_state) Fail(%d)", errno); + return; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOGD("subscribed for connection_state signal %d", id); + + /* sta_joined */ + id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, + "sta_joined", MESH_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); + if (0 == id) { + LOGE("g_dbus_connection_signal_subscribe(sta_joined) Fail(%d)", errno); + return; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOGD("subscribed for sta_joined signal %d", id); + + /* sta_left */ + id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME, + "sta_left", MESH_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL); + if (0 == id) { + LOGE("g_dbus_connection_signal_subscribe(sta_left) Fail(%d)", errno); + return; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOGD("subscribed for sta_left signal %d", id); +} + +static void _on_unsubscribe_ids(gpointer data, gpointer user_data) +{ + unsigned int id = GPOINTER_TO_UINT(data); + struct mesh_handle *h = (struct mesh_handle*)user_data; + + LOGD("[Signal unsubscribe] : %d", id); + g_dbus_connection_signal_unsubscribe( + (GDBusConnection *)h->dbus_connection, id); +} + +static void _mesh_unsubscribe_event(wifi_mesh_h handle) +{ + struct mesh_handle *h = handle; + RET_IF(NULL == h); + + g_list_foreach(h->dbus_sub_ids, _on_unsubscribe_ids, h); + + g_list_free(h->dbus_sub_ids); + h->dbus_sub_ids = NULL; +} + +int _mesh_dbus_start(wifi_mesh_h handle) +{ + struct mesh_handle *h = handle; + int rv; + + rv = _wifi_mesh_create_gdbus_call(handle); + if (WIFI_MESH_ERROR_NONE != rv) + return rv; + + h->ca = g_cancellable_new(); + + /* Create all proxies here */ + _gproxy_mesh_service = _proxy_get_mesh_service(h); + RETVM_IF(NULL == _gproxy_mesh_service, + WIFI_MESH_ERROR_IO_ERROR, "Couldn't get _gproxy_mesh_service"); + g_dbus_proxy_set_default_timeout( + G_DBUS_PROXY(_gproxy_mesh_service), MESH_DBUS_PROXY_TIMEOUT); + + /* Subscribe events */ + _mesh_subscribe_event(handle); + + return WIFI_MESH_ERROR_NONE; +} + +int _mesh_dbus_stop(wifi_mesh_h handle) +{ + struct mesh_handle *h = handle; + int rv; + + if (NULL == h) + return WIFI_MESH_ERROR_INVALID_PARAMETER; + + _mesh_unsubscribe_event(handle); + + /* Unref all proxies here */ + if (_gproxy_mesh_service) { + g_object_unref(_gproxy_mesh_service); + _gproxy_mesh_service = NULL; + } + + g_cancellable_cancel(h->ca); + g_object_unref(h->ca); + h->ca = NULL; + + rv = _wifi_mesh_close_gdbus_call(handle); + return rv; +} + +struct mesh_mpath_list_s { + int count; + GList *list; +}; +struct mesh_mpath_list_s g_mpath; + +#if 0 +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; +} +#endif + +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() +{ + /* If there is no dynamically allocated one, use g_list_free */ + g_list_free(g_mpath.list); + g_mpath.list = NULL; + g_mpath.count = 0; +} + +int _wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler) +{ + struct mesh_handle *h = handle; + RETV_IF(NULL == h, WIFI_MESH_ERROR_INVALID_PARAMETER); + h->event_handler = event_handler; + return WIFI_MESH_ERROR_NONE; +} + +int _wifi_mesh_enable(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_connection_call_sync(h->dbus_connection, + MESH_MANAGER_NAME, + MESH_MANAGER_OBJ_PATH, + MESH_MANAGER_INTERFACE, + "enable", + NULL, NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("enabled status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_disable(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + _wifi_mesh_remove_peers(); + _mesh_remove_networks(); + _mesh_remove_mpath(); + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_connection_call_sync(h->dbus_connection, + MESH_MANAGER_NAME, + MESH_MANAGER_OBJ_PATH, + MESH_MANAGER_INTERFACE, + "disable", + NULL, NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("Disabled status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + h->event_handler = NULL; + + return result; +} + +int _wifi_mesh_scan(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "scan", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("scan status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_specific_scan(wifi_mesh_h handle, const char* ssid, int channel) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "specific_scan", + g_variant_new("(si)", ssid, channel), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("specific_scan status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_cancel_scan(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "cancel_scan", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("cancle_scan status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _mesh_foreach_found_mesh_network(wifi_mesh_h handle, + wifi_mesh_found_network_cb cb, void *user_data) +{ + int i; + GList *iter = NULL; + struct mesh_network_s *data = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == cb, WIFI_MESH_ERROR_INVALID_PARAMETER); + + if (0 >= g_list_length(g_networks)) { + LOGD("No scan result"); + return WIFI_MESH_ERROR_NONE; + } + + /* Get a first item */ + i = 0; + iter = g_list_first(g_networks); + + while (NULL != iter) { + data = iter->data; + if (data) + LOGE("data is null"); + cb(data, user_data); + /* Next item */ + iter = g_list_next(iter); + i++; + } + + return WIFI_MESH_ERROR_NONE; +} + +int _wifi_mesh_foreach_connected_peers(wifi_mesh_h handle, + wifi_mesh_connected_peer_cb cb, void *user_data) +{ + int i; + GList *iter = NULL; + struct mesh_network_s *data = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == cb, WIFI_MESH_ERROR_INVALID_PARAMETER); + + if (0 >= g_list_length(g_peers)) { + LOGD("No peer data"); + return WIFI_MESH_ERROR_NONE; + } + + /* Get a first item */ + i = 0; + iter = g_list_first(g_peers); + + while (NULL != iter) { + data = iter->data; + if (data) + LOGE("data is null"); + cb(data, user_data); + /* Next item */ + iter = g_list_next(iter); + i++; + } + + return WIFI_MESH_ERROR_NONE; +} + +int _wifi_mesh_enable_mesh(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "enable_mesh", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("enable_mesh status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_disable_mesh(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disable_mesh", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("disable_mesh status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +/* TODO: Parameter verification required */ +int _wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + gboolean state; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "is_joined", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(bi)", &state, &result); + LOGD("Mesh is_joined status 0x%x", result); + result = __convert_service_error_type(result); + *is_joined = ((state) ? true : false); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +struct mesh_network_s g_joined_network; + +int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _network) +{ + int result = WIFI_MESH_ERROR_NONE; + GVariant *variant = NULL; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _network, WIFI_MESH_ERROR_INVALID_PARAMETER); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_joined_mesh_network", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + char *meshid = NULL; + char *bssid = NULL; + int channel = -1; + int security = -1; + int state = 0; + int svc_result = 0; + + g_variant_get(variant, "(ssiiii)", &meshid, &bssid, &channel, + &security, &state, &svc_result); + LOGD("get_joined_mesh_network status 0x%x", svc_result); + result = __convert_service_error_type(svc_result); + + /* Clear previous information */ + memset(g_joined_network.meshid, 0, MAX_MESHID_LEN); + memset(g_joined_network.bssid, 0, MAX_BSSID_LEN); + g_joined_network.channel = 0; + g_joined_network.rssi = -1; + g_joined_network.data_rate = 0; + g_joined_network.security = MESH_SECURITY_NONE; + g_joined_network.state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED; + + if (SERVICE_ERROR_NO_DATA == svc_result) { + *_network = NULL; + return WIFI_MESH_ERROR_NONE; + } + + if (WIFI_MESH_ERROR_NONE != result) + return result; + + if (meshid) { + LOGE(" Mesh ID : %s", meshid); + snprintf(g_joined_network.meshid, MAX_MESHID_LEN, "%s", meshid); + } + if (bssid) { + LOGE(" BSSID : %s", bssid); + snprintf(g_joined_network.bssid, MAX_BSSID_LEN, "%s", bssid); + } + g_joined_network.channel = channel; + g_joined_network.rssi = -1; + g_joined_network.security = security; + g_joined_network.state = state; + + *_network = &g_joined_network; + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_set_gate(wifi_mesh_h handle, bool gate_announce, int hwmp_root_mode, bool stp) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_gate", + g_variant_new("(bqq)", gate_announce, hwmp_root_mode, stp), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("set_gate status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_unset_gate(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "unset_gate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("unset_gate status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, + const char* key, const char* mode, + int channel, int visibility, + int max_stations, int security) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_softap", + g_variant_new("(sssiiii)", ssid, key, mode, + channel, visibility, max_stations, security), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("set_softap status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_enable_softap(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "enable_softap", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("enable_softap status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_disable_softap(wifi_mesh_h handle) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disable_softap", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("disable_softap status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h _network) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + struct mesh_network_s *n = _network; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "create_mesh_network", + g_variant_new("(sii)", n->meshid, n->channel, n->security), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("create_network status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _mesh_connect_network(wifi_mesh_h handle, wifi_mesh_network_h _network) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + struct mesh_network_s *n = _network; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "connect_mesh_network", + g_variant_new("(siis)", n->meshid, n->channel, n->security, n->passphrase), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("connect network status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _mesh_disconnect_network(wifi_mesh_h handle, wifi_mesh_network_h _network) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + struct mesh_network_s *n = _network; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disconnect_mesh_network", + g_variant_new("(sii)", n->meshid, n->channel, n->security), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("disconnect network status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _mesh_forget_network(wifi_mesh_h handle, wifi_mesh_network_h _network) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + struct mesh_network_s *n = _network; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + LOGD("mesid=%s channel=%d security=%d", n->meshid, n->channel, n->security); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "forget_mesh_network", + g_variant_new("(sii)", n->meshid, n->channel, n->security), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("forget_network status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_get_stations_info(wifi_mesh_h handle, wifi_mesh_found_station_cb cb, void *user_data) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + + gchar *key; + GVariant *val; + gsize len = 0; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_station_info", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + /* handle station list here */ + g_variant_get(variant, "(aa{sv}i)", &iter, &result); + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + struct mesh_station_info_s station; + memset(&station, 0, sizeof(struct mesh_station_info_s)); + while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { + if (strcasecmp(key, "bssid") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(station.bssid, buf, len); + LOGE("bssid=%s", station.bssid); + } else if (strcasecmp(key, "inactive_time") == 0) { + station.inactive_time = g_variant_get_uint32(val); + LOGE("inactive_time = %ld", station.inactive_time); + } else if (strcasecmp(key, "rx_bytes") == 0) { + station.rx_bytes = g_variant_get_uint64(val); + LOGE("rx_bytes = %ld", station.rx_bytes); + } else if (strcasecmp(key, "rx_packets") == 0) { + station.rx_packets = g_variant_get_uint32(val); + LOGE("rx_packets = %d", station.rx_packets); + } else if (strcasecmp(key, "tx_bytes") == 0) { + station.tx_bytes = g_variant_get_uint64(val); + LOGE("tx_bytes = %ld", station.tx_bytes); + } else if (strcasecmp(key, "tx_packets") == 0) { + station.tx_packets = g_variant_get_uint32(val); + LOGE("rx_packets = %d", station.tx_packets); + } else if (strcasecmp(key, "tx_retries") == 0) { + station.tx_retries = g_variant_get_uint32(val); + LOGE("tx_retries = %d", station.tx_retries); + } else if (strcasecmp(key, "tx_failed") == 0) { + station.tx_failed = g_variant_get_uint32(val); + LOGE("tx_failed = %d", station.tx_failed); + } else if (strcasecmp(key, "beacon_loss") == 0) { + station.beacon_loss = g_variant_get_uint32(val); + LOGE("beacon_loss = %d", station.beacon_loss); + } else if (strcasecmp(key, "beacon_rx") == 0) { + station.beacon_rx = g_variant_get_uint64(val); + LOGE("beacon_rx = %d", station.beacon_rx); + } else if (strcasecmp(key, "rx_drop_misc") == 0) { + station.rx_drop_misc = g_variant_get_uint64(val); + LOGE("rx_drop_misc = %d", station.rx_drop_misc); + } else if (strcasecmp(key, "signal") == 0) { + station.signal = g_variant_get_int32(val); + LOGE("signal = %d", station.signal); + } else if (strcasecmp(key, "signal_avg") == 0) { + station.signal_avg = g_variant_get_int32(val); + LOGE("signal_avg = %d", station.signal_avg); + } else if (strcasecmp(key, "tx_bitrate") == 0) { + station.tx_bitrate = g_variant_get_uint32(val); + LOGE("tx_bitrate = %d", station.tx_bitrate); + } else if (strcasecmp(key, "rx_bitrate") == 0) { + station.rx_bitrate = g_variant_get_uint32(val); + LOGE("rx_bitrate = %d", station.rx_bitrate); + } else if (strcasecmp(key, "mesh_llid") == 0) { + station.mesh_llid = g_variant_get_uint16(val); + LOGE("mesh_llid = %d", station.mesh_llid); + } else if (strcasecmp(key, "mesh_plid") == 0) { + station.mesh_plid = g_variant_get_uint16(val); + LOGE("mesh_plid = %d", station.mesh_plid); + } else if (strcasecmp(key, "mesh_plink") == 0) { + station.mesh_plink = g_variant_get_byte(val); + LOGE("mesh_plink = %d", station.mesh_plink); + } else if (strcasecmp(key, "local_ps_mode") == 0) { + station.local_ps_mode = g_variant_get_uint32(val); + LOGE("local_ps_mode = %d", station.local_ps_mode); + } else if (strcasecmp(key, "peer_ps_mode") == 0) { + station.peer_ps_mode = g_variant_get_uint32(val); + LOGE("peer_ps_mode = %d", station.peer_ps_mode); + } else if (strcasecmp(key, "non_peer_ps_mode") == 0) { + station.non_peer_ps_mode = g_variant_get_uint32(val); + LOGE("non_peer_ps_mode = %d", station.non_peer_ps_mode); + } else if (strcasecmp(key, "authorized") == 0) { + station.authorized = g_variant_get_boolean(val); + LOGE("authorized = %d", station.authorized); + } else if (strcasecmp(key, "authenticated") == 0) { + station.authenticated = g_variant_get_boolean(val); + LOGE("authenticated = %d", station.authenticated); + } else if (strcasecmp(key, "associated") == 0) { + station.associated = g_variant_get_boolean(val); + LOGE("associated = %d", station.associated); + } else if (strcasecmp(key, "preamble") == 0) { + station.preamble = g_variant_get_boolean(val); + LOGE("preamble = %d", station.preamble); + } else if (strcasecmp(key, "WMM_WME") == 0) { + station.wmm_wme = g_variant_get_boolean(val); + LOGE("wmm_wme = %d", station.wmm_wme); + } else if (strcasecmp(key, "MFP") == 0) { + station.mfp = g_variant_get_boolean(val); + LOGE("mfp = %d", station.mfp); + } else if (strcasecmp(key, "TDLS_peer") == 0) { + station.tdls_peer = g_variant_get_boolean(val); + LOGE("tdls_peer = %d", station.tdls_peer); + } else if (strcasecmp(key, "DTIM_period") == 0) { + station.dtim_period = g_variant_get_byte(val); + LOGE("dtim_period = %d", station.dtim_period); + } else if (strcasecmp(key, "beacon_interval") == 0) { + station.beacon_interval = g_variant_get_uint16(val); + LOGE("beacon_interval = %d", station.beacon_interval); + } else if (strcasecmp(key, "short_slot_time") == 0) { + station.short_slot_time = g_variant_get_boolean(val); + LOGE("short_slot_time = %d", station.short_slot_time); + } else if (strcasecmp(key, "connected_time") == 0) { + station.connected_time = g_variant_get_uint32(val); + LOGE("connected_time = %d", station.connected_time); + /* Let users know what stations joined */ + if (cb) cb(&station, user_data); + } + } + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); + LOGD("get_saved_mesh_networks status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *user_data) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + + gchar *key; + GVariant *val; + gsize len = 0; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_mpath_info", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + /* handle station list here */ + _mesh_remove_mpath(); + + /* handle station list here */ + g_variant_get(variant, "(aa{sv}i)", &iter, &result); + LOGE("1"); + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + struct mesh_mpath_dump_s *mpath = g_malloc0(sizeof(struct mesh_mpath_dump_s)); + while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { + if (strcasecmp(key, "DEST_ADDR") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(mpath->dest_addr, buf, len); + LOGE("dest_addr=%s", mpath->dest_addr); + } else if (strcasecmp(key, "NEXT_HOP") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(mpath->next_hop, buf, len); + LOGE("next_hop= %s", mpath->next_hop); + } else if (strcasecmp(key, "IFACE") == 0) { + const char *buf = g_variant_get_string(val, &len); + memcpy(mpath->iface, buf, len); + LOGE("iface= %s", mpath->iface); + } else if (strcasecmp(key, "SN") == 0) { + mpath->sn = g_variant_get_uint32(val); + LOGE("sn= %d", mpath->sn); + } else if (strcasecmp(key, "METRIC") == 0) { + mpath->metric = g_variant_get_uint32(val); + LOGE("metric= %d", mpath->metric); + } else if (strcasecmp(key, "QEN") == 0) { + mpath->qlen = g_variant_get_uint32(val); + LOGE("qlen= %d", mpath->qlen); + } else if (strcasecmp(key, "EXPTIME") == 0) { + mpath->exptime = g_variant_get_uint32(val); + LOGE("exptime= %d", mpath->exptime); + } else if (strcasecmp(key, "DTIM") == 0) { + mpath->discovery_timeout = g_variant_get_uint32(val); + LOGE("discovery_timeout= %d", mpath->discovery_timeout); + } else if (strcasecmp(key, "DRET") == 0) { + mpath->discovery_retries = g_variant_get_byte(val); + LOGE("discovery_retries= %d", mpath->discovery_retries); + } else if (strcasecmp(key, "FLAGS") == 0) { + mpath->flags = g_variant_get_byte(val); + LOGE("flags= %d", mpath->flags); + + /* Add temporal mesh path buffer */ + _mesh_add_mpath((gpointer)mpath); + + if (cb) + cb(mpath, user_data); + } + } + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); + LOGD("get_saved_mesh_networks status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + +int _wifi_mesh_set_interfaces(wifi_mesh_h handle, const char *mesh, const char *gate, const char *softap) +{ + GVariant *variant = NULL; + int result = WIFI_MESH_ERROR_NONE; + GError *error = NULL; + struct mesh_handle *h = handle; + + RETV_IF(NULL == h->dbus_connection, WIFI_MESH_ERROR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, WIFI_MESH_ERROR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "set_interfaces", + g_variant_new("(sss)", mesh, gate, softap), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("set_interfaces status 0x%x", result); + result = __convert_service_error_type(result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + } + + return result; +} + diff --git a/src/wifi-mesh-internal.c b/src/wifi-mesh-internal.c new file mode 100644 index 0000000..80ae01d --- /dev/null +++ b/src/wifi-mesh-internal.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wifi-mesh.h" +#include "wifi-mesh_log.h" +#include "wifi-mesh_private.h" +#include "wifi-mesh_dbus.h" + +/** + * Wi-Fi Mesh network CAPI + */ + +EXPORT_API int wifi_mesh_network_get_data_rate(wifi_mesh_network_h network, int *data_rate) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || data_rate == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *data_rate = net->data_rate; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_data_rate(wifi_mesh_network_h network, int data_rate) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net->data_rate = data_rate; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_cancel_scan(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_cancel_scan(handle); + return rv; +} + +EXPORT_API int wifi_mesh_set_gate(wifi_mesh_h handle, int gate_announce, int hwmp_root_mode, bool stp) +{ + int rv = 0; + int _stp = stp ? 1 : 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_set_gate(handle, gate_announce, hwmp_root_mode, _stp); + return rv; +} + +EXPORT_API int wifi_mesh_unset_gate(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_unset_gate(handle); + return rv; +} + +EXPORT_API int wifi_mesh_get_stations_info(wifi_mesh_h handle, wifi_mesh_found_station_cb cb, void *user_data) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_get_stations_info(handle, cb, user_data); + return rv; +} + +EXPORT_API int wifi_mesh_get_mpath_info(wifi_mesh_h handle, mesh_found_mpath_cb cb, void *user_data) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_get_mpath_info(handle, cb, user_data); + return rv; +} + +EXPORT_API int wifi_mesh_set_interfaces(wifi_mesh_h handle, + const char *mesh, const char* gate, const char *softap) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == mesh, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_set_interfaces(handle, mesh, gate, softap); + return rv; +} + diff --git a/src/wifi-mesh.c b/src/wifi-mesh.c new file mode 100644 index 0000000..b34d3c7 --- /dev/null +++ b/src/wifi-mesh.c @@ -0,0 +1,644 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "wifi-mesh.h" +#include "wifi-mesh_log.h" +#include "wifi-mesh_private.h" +#include "wifi-mesh_dbus.h" + +/** + * Wi-Fi Mesh network CAPI + */ + +EXPORT_API int wifi_mesh_network_new(wifi_mesh_network_h* network) +{ + struct mesh_network_s *net; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net = calloc(1, sizeof(struct mesh_network_s)); + if (NULL == net) { + /* LCOV_EXCL_START */ + LOGE("Out of memory"); + return WIFI_MESH_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + *network = (wifi_mesh_network_h)net; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_network_h src) +{ + struct mesh_network_s *net = NULL; + struct mesh_network_s *_src = src; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (dst == NULL || src == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net = calloc(1, sizeof(struct mesh_network_s)); + if (NULL == net) { + /* LCOV_EXCL_START */ + LOGE("Out of memory"); + return WIFI_MESH_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + snprintf(net->meshid, MAX_MESHID_LEN, "%s", _src->meshid); + snprintf(net->bssid, MAX_BSSID_LEN, "%s", _src->bssid); + net->channel = _src->channel; + net->rssi = _src->rssi; + net->data_rate = _src->data_rate; + net->security = _src->security; + if (strlen(_src->passphrase) > 0) + snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", _src->passphrase); + + *dst = (wifi_mesh_network_h)net; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const char *meshid, + const char *bssid, int channel, int rssi, wifi_mesh_security_type_e security, + const char *passphrase) +{ + struct mesh_network_s *net; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net = calloc(1, sizeof(struct mesh_network_s)); + if (meshid) + snprintf(net->meshid, MAX_MESHID_LEN, "%s", meshid); + if (bssid) + snprintf(net->bssid, MAX_BSSID_LEN, "%s", bssid); + net->channel = channel; + net->rssi = rssi; + net->security = security; + if (passphrase) + snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase); + + *network = (wifi_mesh_network_h)net; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_destroy(wifi_mesh_network_h network) +{ + struct mesh_network_s *net = network; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (NULL == net) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + free(net); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_meshid(wifi_mesh_network_h network, char **meshid) +{ + struct mesh_network_s *net = network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || meshid == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *meshid = strdup(net->meshid); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_meshid(wifi_mesh_network_h network, const char *meshid) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || meshid == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + snprintf(net->meshid, MAX_MESHID_LEN, "%s", meshid); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_bssid(wifi_mesh_network_h network, char **bssid) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || bssid == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *bssid = strdup(net->bssid); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_bssid(wifi_mesh_network_h network, const char *bssid) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || bssid == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + snprintf(net->bssid, MAX_BSSID_LEN, "%s", bssid); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_channel(wifi_mesh_network_h network, int *channel) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || channel == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *channel = net->channel; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_channel(wifi_mesh_network_h network, int channel) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net->channel = channel; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_rssi(wifi_mesh_network_h network, int *rssi) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || rssi == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *rssi = net->rssi; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_rssi(wifi_mesh_network_h network, int rssi) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net->rssi = rssi; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_security(wifi_mesh_network_h network, wifi_mesh_security_type_e *security) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || security == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *security = net->security; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_security(wifi_mesh_network_h network, wifi_mesh_security_type_e security) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + net->security = security; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_set_passphrase(wifi_mesh_network_h network, const char* passphrase) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + if (passphrase) + snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase); + else + memset(net->passphrase, 0x0, MAX_PASSPHRASE_LEN); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_network_get_connection_state(wifi_mesh_network_h network, + wifi_mesh_connection_state_e *state) +{ + struct mesh_network_s *net = (struct mesh_network_s *)network; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (network == NULL || state == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *state = net->state; + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_peer_get_address(wifi_mesh_peer_h peer, char **address) +{ + struct mesh_peer_s *peer_info = (struct mesh_peer_s *)peer; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (peer == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + *address = strdup(peer_info->address); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_initialize(wifi_mesh_h *mesh) +{ + int rv; + struct mesh_handle* handle; + + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (mesh == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + + handle = g_new0(struct mesh_handle, 1); + if (NULL == handle) { + LOGE("Failed to create handle"); + return WIFI_MESH_ERROR_OUT_OF_MEMORY; + } + *mesh = handle; + + rv = _mesh_dbus_start(*mesh); + if (rv != WIFI_MESH_ERROR_NONE) + LOGD("D-Bus init: (0x%X)", rv); + + return WIFI_MESH_ERROR_NONE; +} + +EXPORT_API int wifi_mesh_deinitialize(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + rv = _mesh_dbus_stop(handle); + + LOGI("Destroy handle: %p", handle); + + return rv; +} + +EXPORT_API int wifi_mesh_set_event_cb(wifi_mesh_h handle, wifi_mesh_event_cb event_handler) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_set_event_cb(handle, event_handler); + return rv; +} + +EXPORT_API int wifi_mesh_enable(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_enable(handle); + return rv; +} + +EXPORT_API int wifi_mesh_disable(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_disable(handle); + return rv; +} + +EXPORT_API int wifi_mesh_scan(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_scan(handle); + return rv; +} + +EXPORT_API int wifi_mesh_specific_scan(wifi_mesh_h handle, const char* ssid, int channel) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == ssid, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_specific_scan(handle, ssid, channel); + return rv; +} + +EXPORT_API int wifi_mesh_foreach_found_network(wifi_mesh_h handle, + wifi_mesh_found_network_cb cb, void *user_data) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == cb, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_get_scan_result(handle); + if (WIFI_MESH_ERROR_NONE != rv) + return rv; + + rv = _mesh_foreach_found_mesh_network(handle, cb, user_data); + return rv; +} + +EXPORT_API int wifi_mesh_foreach_connected_peers(wifi_mesh_h handle, + wifi_mesh_connected_peer_cb cb, void *user_data) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == cb, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_find_peers(handle); + if (WIFI_MESH_ERROR_NONE != rv) + return rv; + + rv = _wifi_mesh_foreach_connected_peers(handle, cb, user_data); + return rv; +} + +EXPORT_API int wifi_mesh_start_mesh(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_enable_mesh(handle); + return rv; +} + +EXPORT_API int wifi_mesh_stop_mesh(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_disable_mesh(handle); + return rv; +} + +EXPORT_API int wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_is_joined(handle, is_joined); + return rv; +} + +EXPORT_API int wifi_mesh_get_joined_network(wifi_mesh_h handle, wifi_mesh_network_h *network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_get_joined_mesh_network(handle, network); + return rv; +} + +EXPORT_API int wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, + const char* key, int channel, bool visibility, + int max_stations, int security) +{ + int rv = 0; + char buf[32] = {0,}; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == ssid, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == key, WIFI_MESH_ERROR_INVALID_PARAMETER); + + if (channel <= 13) + memcpy(buf, "g", strlen("g")); + else + memcpy(buf, "a", strlen("a")); + + rv = _wifi_mesh_set_softap(handle, ssid, key, buf, channel, + visibility, max_stations, security); + return rv; +} + +EXPORT_API int wifi_mesh_enable_softap(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_enable_softap(handle); + return rv; +} + +EXPORT_API int wifi_mesh_disable_softap(wifi_mesh_h handle) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _wifi_mesh_disable_softap(handle); + return rv; +} + +EXPORT_API int wifi_mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == network, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_create_network(handle, network); + return rv; +} + +EXPORT_API int wifi_mesh_connect_network(wifi_mesh_h handle, wifi_mesh_network_h network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == network, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_connect_network(handle, network); + return rv; +} + +EXPORT_API int wifi_mesh_disconnect_network(wifi_mesh_h handle, wifi_mesh_network_h network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == network, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_disconnect_network(handle, network); + return rv; +} + +EXPORT_API int wifi_mesh_forget_network(wifi_mesh_h handle, wifi_mesh_network_h network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, WIFI_MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == network, WIFI_MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_forget_network(handle, network); + return rv; +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5a191bd..d804958 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) -SET(test "mesh_test") +SET(test "wifi-mesh-test") INCLUDE(FindPkgConfig) pkg_check_modules(${test} REQUIRED dlog glib-2.0 gio-2.0) @@ -17,11 +17,11 @@ SET(CMAKE_EXE_LINKER_FLAGS "-lpthread") SET(NEW_SOURCES main.c menu.c - mesh_device.c - mesh_network.c + wifi-mesh-device.c + wifi-mesh-network.c ) -# mesh test tool -ADD_EXECUTABLE(mesh_test ${NEW_SOURCES}) -TARGET_LINK_LIBRARIES(mesh_test ${${fw_name}_LDFLAGS} ${pkgs_LDFLAGS} capi-network-mesh) -INSTALL(TARGETS mesh_test DESTINATION ${BIN_INSTALL_DIR}) +# Wi-Fi mesh test tool +ADD_EXECUTABLE(${test} ${NEW_SOURCES}) +TARGET_LINK_LIBRARIES(${test} ${${fw_name}_LDFLAGS} ${pkgs_LDFLAGS} capi-network-wifi-mesh) +INSTALL(TARGETS ${test} DESTINATION ${BIN_INSTALL_DIR}) diff --git a/test/common.h b/test/common.h index e6ff888..d421e09 100644 --- a/test/common.h +++ b/test/common.h @@ -18,15 +18,15 @@ #ifndef __COMMON_H__ #define __COMMON_H__ -#include -#include +#include +#include __BEGIN_DECLS #define CASE_TO_STR(x) case x: return #x; -const char* mesh_error_to_string(mesh_error_e err); -const char* _mesh_connection_event_to_string(mesh_connection_state_e e); +const char* wifi_mesh_error_to_string(wifi_mesh_error_e err); +const char* wifi_mesh_connection_event_to_string(wifi_mesh_connection_state_e e); __END_DECLS diff --git a/test/main.c b/test/main.c index d7be69c..1aa3c46 100644 --- a/test/main.c +++ b/test/main.c @@ -29,7 +29,7 @@ #include "menu.h" #include "common.h" -mesh_h mesh = NULL; +wifi_mesh_h mesh = NULL; extern struct menu_data menu_mesh_device[]; extern struct menu_data menu_mesh_network[]; @@ -37,79 +37,80 @@ extern struct menu_data menu_mesh_network[]; /* Scanned Mesh Network */ extern GList *g_found_network_list; -const char* mesh_error_to_string(mesh_error_e err) +const char* wifi_mesh_error_to_string(wifi_mesh_error_e err) { switch (err) { /* CHECK: List all enum values here */ - CASE_TO_STR(MESH_ERROR_NONE) - CASE_TO_STR(MESH_ERROR_INVALID_PARAMETER) - CASE_TO_STR(MESH_ERROR_OUT_OF_MEMORY) - CASE_TO_STR(MESH_ERROR_NO_DATA) - CASE_TO_STR(MESH_ERROR_INVALID_OPERATION) - CASE_TO_STR(MESH_ERROR_ALREADY_IN_PROGRESS) - CASE_TO_STR(MESH_ERROR_NOW_IN_PROGRESS) - CASE_TO_STR(MESH_ERROR_PERMISSION_DENIED) - CASE_TO_STR(MESH_ERROR_IO_ERROR) - CASE_TO_STR(MESH_ERROR_NOT_SUPPORTED) - CASE_TO_STR(MESH_ERROR_OPERATION_FAILED) - CASE_TO_STR(MESH_ERROR_OPERATION_ABORTED) + CASE_TO_STR(WIFI_MESH_ERROR_NONE) + CASE_TO_STR(WIFI_MESH_ERROR_INVALID_PARAMETER) + CASE_TO_STR(WIFI_MESH_ERROR_OUT_OF_MEMORY) + CASE_TO_STR(WIFI_MESH_ERROR_NO_DATA) + CASE_TO_STR(WIFI_MESH_ERROR_INVALID_OPERATION) + CASE_TO_STR(WIFI_MESH_ERROR_ALREADY_IN_PROGRESS) + CASE_TO_STR(WIFI_MESH_ERROR_NOW_IN_PROGRESS) + CASE_TO_STR(WIFI_MESH_ERROR_PERMISSION_DENIED) + CASE_TO_STR(WIFI_MESH_ERROR_IO_ERROR) + CASE_TO_STR(WIFI_MESH_ERROR_NOT_SUPPORTED) + CASE_TO_STR(WIFI_MESH_ERROR_OPERATION_FAILED) + CASE_TO_STR(WIFI_MESH_ERROR_OPERATION_ABORTED) + CASE_TO_STR(WIFI_MESH_ERROR_ALREADY_INITIALIZED) default : return "Unknown Error"; } } -static const char* _mesh_event_to_string(mesh_event_e e) +static const char* _wifi_mesh_event_to_string(wifi_mesh_event_e e) { switch (e) { /* CHECK: List all enum values here */ - CASE_TO_STR(MESH_EVENT_ENABLED) - CASE_TO_STR(MESH_EVENT_SCAN_DONE) - CASE_TO_STR(MESH_EVENT_CONNECTION_STATE) - CASE_TO_STR(MESH_EVENT_STATION_JOIN) - CASE_TO_STR(MESH_EVENT_STATION_LEFT) + CASE_TO_STR(WIFI_MESH_EVENT_ENABLED) + CASE_TO_STR(WIFI_MESH_EVENT_SCAN_DONE) + CASE_TO_STR(WIFI_MESH_EVENT_CONNECTION_STATE) + CASE_TO_STR(WIFI_MESH_EVENT_STATION_JOIN) + CASE_TO_STR(WIFI_MESH_EVENT_STATION_LEFT) default : return "MESH_EVENT_UNKNOWN"; } } -const char* _mesh_connection_event_to_string(mesh_connection_state_e e) +const char* wifi_mesh_connection_event_to_string(wifi_mesh_connection_state_e e) { switch (e) { /* CHECK: List all enum values here */ - CASE_TO_STR(MESH_CONNECTION_STATE_DISCONNECTED) - CASE_TO_STR(MESH_CONNECTION_STATE_ASSOCIATION) - CASE_TO_STR(MESH_CONNECTION_STATE_CONFIGURATION) - CASE_TO_STR(MESH_CONNECTION_STATE_CONNECTED) + CASE_TO_STR(WIFI_MESH_CONNECTION_STATE_DISCONNECTED) + CASE_TO_STR(WIFI_MESH_CONNECTION_STATE_ASSOCIATION) + CASE_TO_STR(WIFI_MESH_CONNECTION_STATE_CONFIGURATION) + CASE_TO_STR(WIFI_MESH_CONNECTION_STATE_CONNECTED) default : return "Unknown state"; } } -void event_cb(mesh_event_e event_type, mesh_event_data_s* event) +void event_cb(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event) { msg(""); - msgp("Event received [%s]", _mesh_event_to_string(event_type)); + msgp("Event received [%s]", _wifi_mesh_event_to_string(event_type)); switch (event_type) { - case MESH_EVENT_ENABLED: { - msgp(" Mesh Network Enabled Result = %d", event->data.mesh_enable->result); + case WIFI_MESH_EVENT_ENABLED: { + msgp(" Mesh Network Enabled Result = %d", event->data.wifi_mesh_enable->result); } break; - case MESH_EVENT_SCAN_DONE: { + case WIFI_MESH_EVENT_SCAN_DONE: { msgp(" Mesh Scan Done"); } break; - case MESH_EVENT_CONNECTION_STATE:{ + case WIFI_MESH_EVENT_CONNECTION_STATE:{ msgp(" Connection state changed [%s]", - _mesh_connection_event_to_string(event->data.connection_state->state)); + wifi_mesh_connection_event_to_string(event->data.connection_state->state)); msgp(" From Mesh ID[%-10s] BSSID[%s] Channel[%d] Security[%4s]", event->data.connection_state->mesh_id, event->data.connection_state->bssid, event->data.connection_state->channel, (MESH_SECURITY_SAE == event->data.connection_state->security) ? "SAE" : "NONE"); } break; - case MESH_EVENT_STATION_JOIN: { + case WIFI_MESH_EVENT_STATION_JOIN: { msgp(" New Station Joined = %s", event->data.sta_info->bssid); } break; - case MESH_EVENT_STATION_LEFT: { + case WIFI_MESH_EVENT_STATION_LEFT: { msgp(" A Station Left = %s", event->data.sta_info->bssid); } break; default: @@ -123,10 +124,10 @@ static int __init_func(MManager *mm, struct menu_data *menu) #if 0 int ret = -1; - ret = mesh_initialize(&mesh); + ret = wifi_mesh_initialize(&mesh); if (ret != 0) { msg("Failed to initialize mesh: [%s(0x%X)]", - mesh_error_to_string(ret), ret); + wifi_mesh_error_to_string(ret), ret); return RET_FAILURE; } #endif @@ -135,7 +136,7 @@ static int __init_func(MManager *mm, struct menu_data *menu) static struct menu_data menu_main[] = { { "1", "Device", menu_mesh_device, NULL, NULL }, - { "2", "Mesh network", menu_mesh_network, NULL, NULL }, + { "2", "Wi-Fi Mesh network", menu_mesh_network, NULL, NULL }, { NULL, NULL, }, }; @@ -163,7 +164,7 @@ int main(int arg, char **argv) mainloop = g_main_loop_new(NULL, FALSE); msg(""); - msg("* Mesh Test application "); + msg("* Wi-Fi Mesh Test application "); msg("* Build On: %s %s", __DATE__, __TIME__); if (__create_init_menu(init_menu) == FALSE) @@ -184,7 +185,7 @@ OUT: g_list_free(g_found_network_list); if (mesh) - mesh_deinitialize(mesh); + wifi_mesh_deinitialize(mesh); g_main_loop_unref(mainloop); msg("******* Bye bye *******"); diff --git a/test/mesh_device.c b/test/mesh_device.c deleted file mode 100644 index 57a85ad..0000000 --- a/test/mesh_device.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "menu.h" -#include "common.h" - -extern mesh_h mesh; -extern void event_cb(mesh_event_e event_type, mesh_event_data_s* event); - -static int run_mesh_create(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("create"); - - ret = mesh_initialize(&mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to initialize mesh: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_initialize() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_destroy(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("destroy"); - - ret = mesh_deinitialize(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to de-initialize mesh: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_deinitialize() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_enable(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("enable"); - - ret = mesh_set_event_cb(mesh, event_cb); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to set callback for mesh network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_set_event_cb() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - ret = mesh_enable(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to enable mesh network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_enable() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_disable(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("disable"); - - ret = mesh_disable(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to disable mesh network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_disable() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static char mesh_interface[MENU_DATA_SIZE + 1] = "mesh0"; -static char gate_interface[MENU_DATA_SIZE + 1] = "eth0"; -static char softap_interface[MENU_DATA_SIZE + 1] = "wlan1"; -static int run_mesh_set_interfaces(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("set_interfaces"); - - ret = mesh_set_interfaces(mesh, mesh_interface, gate_interface, softap_interface); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to set interfaces: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_set_interfaces() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static struct menu_data menu_mesh_interface[] = { - { "1", "mesh", NULL, NULL, mesh_interface }, - { "2", "gate", NULL, NULL, gate_interface }, - { "3", "softap", NULL, NULL, softap_interface }, - { "4", "run", NULL, run_mesh_set_interfaces, NULL }, - { NULL, NULL, }, -}; - -struct menu_data menu_mesh_device[] = { - { "1", "initialize", NULL, run_mesh_create, NULL }, - { "2", "deinitialize", NULL, run_mesh_destroy, NULL }, - { "3", "enable", NULL, run_mesh_enable, NULL }, - { "4", "disable", NULL, run_mesh_disable, NULL }, - { "5", "set_inteface", menu_mesh_interface, NULL, NULL}, - { NULL, NULL, }, -}; diff --git a/test/mesh_network.c b/test/mesh_network.c deleted file mode 100644 index 6642624..0000000 --- a/test/mesh_network.c +++ /dev/null @@ -1,691 +0,0 @@ - -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "menu.h" -#include "common.h" - -extern mesh_h mesh; - -static char gate_announce[MENU_DATA_SIZE + 1] = "1"; -static char hwmp_root_mode[MENU_DATA_SIZE + 1] = "4"; -static char stp[MENU_DATA_SIZE + 1] = "1"; - -static char ssid[MENU_DATA_SIZE + 1] = "meshnet"; -static char passphrase[MENU_DATA_SIZE + 1] = "11223344"; -static char mode[MENU_DATA_SIZE + 1] = "ac"; -static char softap_channel[MENU_DATA_SIZE + 1] = "36"; -static char visibility[MENU_DATA_SIZE + 1] = "1"; -static char max_stations[MENU_DATA_SIZE + 1] = "10"; -static char security[MENU_DATA_SIZE + 1] = "2"; - -static char meshid[MENU_DATA_SIZE + 1] = "meshnet"; -static char mesh_channel[MENU_DATA_SIZE + 1] = "161"; -static char mesh_security[MENU_DATA_SIZE + 1] = "0"; -static char mesh_passphrase[MENU_DATA_SIZE + 1] = ""; - -static char network_idx[MENU_DATA_SIZE + 1] = "1"; - -/* Found Mesh Network */ -static int g_scan_net_idx = 0; -GList *g_found_network_list = NULL; - -static void found_mesh_network_cb(mesh_network_h network, void* user_data) -{ - int ret; - mesh_network_h net = NULL; - char *meshid = NULL; - char *bssid = NULL; - int rssi; - int data_rate; - mesh_security_type_e security; - int channel; - - ret = mesh_network_clone(&net, network); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to clone found network: [%s(0x%X)]", mesh_error_to_string(ret), ret); - return; - } - - g_found_network_list = g_list_append(g_found_network_list, net); - - mesh_network_get_meshid(net, &meshid); - mesh_network_get_bssid(net, &bssid); - mesh_network_get_channel(net, &channel); - mesh_network_get_rssi(net, &rssi); - mesh_network_get_data_rate(net, &data_rate); - mesh_network_get_security(net, &security); - msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d] RSSI[%ddBm] Date Rate[%dMbps] Security[%4s]", - g_scan_net_idx, meshid, bssid, channel, rssi == 0 ? 0 : rssi-120, data_rate, - (MESH_SECURITY_SAE == security) ? "SAE" : "NONE"); - - g_scan_net_idx++; - - if (meshid) free(meshid); - if (bssid) free(bssid); -} - -static void connected_peer_cb(mesh_peer_h peer, void* user_data) -{ - char *address = NULL; - - mesh_peer_get_address(peer, &address); - msgb(" Peer Address [%s]", address); - - if (address) - free(address); -} - -static void found_station_cb(mesh_station_info_h station, void* user_data) -{ - msg("Station Information Received: %p", station); -} - -static void found_mpath_cb(mesh_mpath_info_h mpath, void* user_data) -{ - msg("Station Information Received: %p", mpath); -} - -#if 0 -static int run_show_found_network(MManager *mm, struct menu_data *menu) -{ - int i = 1; /* Displays from 1 */ - char *_meshid = NULL; - int _channel = 1; - mesh_security_type_e _security = MESH_SECURITY_NONE; - - GList *iter = NULL; - - if (NULL == g_found_network_list) { - msgp("There is not any scan result.. do scan first"); - return RET_FAILURE; - } - - msg("Scan Results : "); - iter = g_found_network_list; - while (iter != NULL) { - mesh_network_h _net = iter->data; - mesh_network_get_meshid(_net, &_meshid); - mesh_network_get_channel(_net, &_channel); - mesh_network_get_security(_net, &_security); - msgb(" [%02d] Mesh ID[%-10s] Channel[%d] Security[%4s]", i++, - _meshid, _channel, (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE"); - - if (_meshid) free(_meshid); - - iter = g_list_next(iter); - } - - return RET_SUCCESS; -} -#endif - -static int run_mesh_scan(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Scan"); - - ret = mesh_scan(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to scan: [%s(0x%X)]", mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_scan() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Get Found Mesh Network"); - - /* Clear previous found network list */ - g_scan_net_idx = 1; - if (g_found_network_list) - g_list_free_full(g_found_network_list, (void *)mesh_network_destroy); - - g_found_network_list = NULL; - - ret = mesh_foreach_found_mesh_network(mesh, found_mesh_network_cb, NULL); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_foreach_found_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_foreach_found_mesh_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_specific_scan(MManager *mm, struct menu_data *menu) -{ - int ret; - int channel = 1; - - msg("Specific scan"); - - if (strlen(mesh_channel)) - channel = (unsigned short)strtol(mesh_channel, NULL, 10); - - ret = mesh_specific_scan(mesh, meshid, channel); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to specific scan: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_specific_scan() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_cancel_scan(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Cancel Scan"); - - ret = mesh_cancel_scan(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to cancel scan: [%s(0x%X)]", mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_cancel_scan() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_enable(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Enable Mesh"); - - ret = mesh_enable_mesh(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to enable mesh network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_enable_mesh() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_mesh_disable(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Disable Mesh"); - - ret = mesh_disable_mesh(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to disable mesh network: [%s(0x%X)]", mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_disable_mesh() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu) -{ - int ret; - char *_meshid = NULL; - char *_bssid = NULL; - int _channel = -1; - bool joined = false; - mesh_connection_state_e _state = MESH_CONNECTION_STATE_DISCONNECTED; - mesh_security_type_e _security = MESH_SECURITY_NONE; - mesh_network_h network = NULL; - - msg("Get Joined Mesh Network Information"); - - ret = mesh_is_joined(mesh, &joined); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to check network join status: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - - ret = mesh_get_joined_network(mesh, &network); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to get joined mesh network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - - if (NULL != network) { - mesh_network_get_meshid(network, &_meshid); - msgb(" Mesh ID = %s", _meshid); - mesh_network_get_bssid(network, &_bssid); - msgb(" BSSID = %s", _bssid); - mesh_network_get_channel(network, &_channel); - msgb(" Channel = %d", _channel); - mesh_network_get_security(network, &_security); - msgb(" Security = %s", - (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE"); - mesh_network_get_connection_state(network, &_state); - msgb(" State = %s", _mesh_connection_event_to_string(_state)); - - if (_meshid) free(_meshid); - if (_bssid) free(_bssid); - } - msg(""); - msg(" - mesh_get_joined_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_get_connected_peers(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Get Connected Mesh Peers"); - - ret = mesh_foreach_connected_peers(mesh, connected_peer_cb, NULL); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_foreach_connected_peers: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_foreach_connected_peers() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_set_gate(MManager *mm, struct menu_data *menu) -{ - int ret; - bool _gate_announce = true; - int _hwmp_root_mode = 4; - bool _stp = true; - - msg("Set Gate Option"); - - if (strlen(gate_announce)) - _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16); - if (strlen(hwmp_root_mode)) - _hwmp_root_mode = (unsigned short)strtol(hwmp_root_mode, NULL, 10); - if (strlen(stp)) - _stp = (unsigned short)strtol(stp, NULL, 10); - - ret = mesh_set_gate(mesh, _gate_announce, _hwmp_root_mode, _stp); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to set gate options: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_set_gate() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_unset_gate(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Disable All Gate Option"); - - ret = mesh_unset_gate(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to unset gate option: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_unset_gate() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_set_softap(MManager *mm, struct menu_data *menu) -{ - int ret; - int _channel = 1; - int _visibility = 1; - int _max_stations = 10; - int _security = 2; - msg("Set SoftAp Option"); - - if (strlen(softap_channel)) - _channel = (unsigned short)strtol(softap_channel, NULL, 10); - if (strlen(visibility)) { - _visibility = (unsigned short)strtol(visibility, NULL, 10); - if (1 != _visibility) _visibility = 0; - } - if (strlen(max_stations)) - _max_stations = (unsigned short)strtol(max_stations, NULL, 10); - if (strlen(security)) - _security = (unsigned short)strtol(security, NULL, 10); - - ret = mesh_set_softap(mesh, ssid, passphrase, - _channel, _visibility, _max_stations, _security); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to set softap options: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_set_softap() ret: [0x%X] [%s]", ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_enable_softap(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Enable SoftAp"); - - ret = mesh_enable_softap(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to enable soft ap: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_enable_softap() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_disable_softap(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Disable SoftAp"); - - ret = mesh_disable_softap(mesh); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to disable soft ap: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_disable_softap() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_create_network(MManager *mm, struct menu_data *menu) -{ - int ret; - int _mesh_channel = 1; - mesh_security_type_e security = MESH_SECURITY_NONE; - mesh_network_h net = NULL; - - msg("Create a new Mesh Network"); - - if (strlen(mesh_channel)) - _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10); - - if (strlen(mesh_security)) { - ret = (unsigned short)strtol(mesh_security, NULL, 10); - security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE); - } - - mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0, - security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL); - ret = mesh_create_mesh_network(mesh, net); - mesh_network_destroy(net); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_create_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_create_mesh_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_connect_network(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mesh_network_h net = NULL; - mesh_security_type_e security = MESH_SECURITY_NONE; - msg("Connect to Mesh Network"); - - if (strlen(network_idx)) { - idx = (unsigned short)strtol(network_idx, NULL, 10); - if (0 >= idx) { - msgp("Invalid index. set to 1"); - idx = 1; - } - } - - if (g_found_network_list) { - net = g_list_nth_data(g_found_network_list, idx - 1); - if (NULL == net) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - /* Set passphrase */ - mesh_network_get_security(net, &security); - if (MESH_SECURITY_NONE != security) { - if (strlen(mesh_passphrase)) { - ret = mesh_network_set_passphrase(net, mesh_passphrase); - if (MESH_ERROR_NONE != ret) - msgr("Failed to set passphrase !"); - } else { - msgr("If security enabled, passphrase should be set !"); - return RET_FAILURE; - } - } - - ret = mesh_connect_mesh_network(mesh, net); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_connect_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_connect_mesh_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_disconnect_network(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mesh_network_h net = NULL; - msg("Disconnect with Mesh Network"); - - if (strlen(network_idx)) { - idx = (unsigned short)strtol(network_idx, NULL, 10); - if (0 >= idx) { - msgp("Invalid index. set to 1"); - idx = 1; - } - } - - if (g_found_network_list) { - net = g_list_nth_data(g_found_network_list, idx - 1); - if (NULL == net) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - ret = mesh_disconnect_mesh_network(mesh, net); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_disconnect_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_disconnect_mesh_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_forget_network(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mesh_network_h net = NULL; - msg("Forget Mesh Network"); - - if (strlen(network_idx)) { - idx = (unsigned short)strtol(network_idx, NULL, 10); - if (0 >= idx) { - msgp("Invalid index. set to 1"); - idx = 1; - } - } - - if (g_found_network_list) { - net = g_list_nth_data(g_found_network_list, idx - 1); - if (NULL == net) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - ret = mesh_forget_mesh_network(mesh, net); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_forget_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_forget_mesh_network() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_get_station_information(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Get Mesh Station Information"); - - ret = mesh_get_stations_info(mesh, found_station_cb, NULL); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_get_stations_info: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_get_stations_info() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} - -static int run_get_mpath_information(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Get Mesh Path Information"); - - ret = mesh_get_mpath_info(mesh, found_mpath_cb, NULL); - if (MESH_ERROR_NONE != ret) { - msgr("Failed to mesh_get_mpath_info: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mesh_get_mpath_info() ret: [0x%X] [%s]", - ret, mesh_error_to_string(ret)); - - return RET_SUCCESS; -} -static struct menu_data menu_specific_scan[] = { - { "1", "Mesh ID", NULL, NULL, meshid }, - { "2", "Channel", NULL, NULL, mesh_channel }, - { "3", "Run", NULL, run_mesh_specific_scan, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_gate_option[] = { - { "1", "Gate Announcement", NULL, NULL, gate_announce }, - { "2", "HWMP Root Mode", NULL, NULL, hwmp_root_mode }, - { "3", "STP", NULL, NULL, stp }, - { "4", "Run", NULL, run_set_gate, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_softap_option[] = { - { "1", "SSID", NULL, NULL, ssid }, - { "2", "passphrase", NULL, NULL, passphrase }, - { "3", "802.11 mode", NULL, NULL, mode }, - { "4", "channel", NULL, NULL, softap_channel }, - { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility }, - { "6", "max. client num", NULL, NULL, max_stations }, - { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security }, - { "7", "run", NULL, run_set_softap, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_create_network[] = { - { "1", "Mesh ID", NULL, NULL, meshid }, - { "2", "Channel", NULL, NULL, mesh_channel }, - { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security }, - { "4", "Passphrase", NULL, NULL, mesh_passphrase }, - { "5", "Run", NULL, run_create_network, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_connect_network[] = { - { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, - { "1", "Index", NULL, NULL, network_idx }, - { "2", "Passphrase", NULL, NULL, mesh_passphrase }, - { "3", "Run", NULL, run_connect_network, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_disconnect_network[] = { - { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, - { "1", "Index", NULL, NULL, network_idx }, - { "2", "Run", NULL, run_disconnect_network, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_forget_network[] = { - { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, - { "1", "Index", NULL, NULL, network_idx }, - { "2", "Run", NULL, run_forget_network, NULL }, - { NULL, NULL, }, -}; - - -struct menu_data menu_mesh_network[] = { - { "1", "Scan", NULL, run_mesh_scan, NULL }, - { "2", "Get found mesh network", NULL, run_get_found_mesh_network, NULL }, - { "3", "Specific scan", menu_specific_scan, NULL, NULL }, - { "4", "Cancel scan", NULL, run_mesh_cancel_scan, NULL }, - { "5", "Enable mesh", NULL, run_mesh_enable, NULL }, - { "6", "Disable mesh", NULL, run_mesh_disable, NULL }, - { "7", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL }, - { "8", "Set gate", menu_gate_option, NULL, NULL }, - { "9", "Unset gate", NULL, run_unset_gate, NULL }, - { "10", "Set softap", menu_softap_option, NULL, NULL }, - { "11", "Enable softap", NULL, run_enable_softap, NULL }, - { "12", "Disable softap", NULL, run_disable_softap, NULL }, - { "13", "Create network", menu_create_network, NULL, NULL }, - { "14", "Connect network", menu_connect_network, NULL, NULL }, - { "15", "Disconnect network", menu_disconnect_network, NULL, NULL }, - { "16", "Forget network", menu_forget_network, NULL, NULL }, - { "17", "Get connected mesh peers", NULL, run_get_connected_peers, NULL }, - { "18", "Get mesh station information", NULL, run_get_station_information, NULL }, - { "19", "Get mesh path information", NULL, run_get_mpath_information, NULL }, - { NULL, NULL, }, -}; diff --git a/test/wifi-mesh-device.c b/test/wifi-mesh-device.c new file mode 100644 index 0000000..c5f4d44 --- /dev/null +++ b/test/wifi-mesh-device.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "menu.h" +#include "common.h" + +extern wifi_mesh_h mesh; +extern void event_cb(wifi_mesh_event_e event_type, wifi_mesh_event_data_s* event); + +static int run_mesh_create(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("create"); + + ret = wifi_mesh_initialize(&mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to initialize mesh: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_initialize() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_mesh_destroy(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("destroy"); + + ret = wifi_mesh_deinitialize(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to de-initialize mesh: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_deinitialize() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("enable"); + + ret = wifi_mesh_set_event_cb(mesh, event_cb); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to set callback for mesh network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_set_event_cb() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + ret = wifi_mesh_enable(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to enable mesh network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_enable() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("disable"); + + ret = wifi_mesh_disable(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to disable mesh network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_disable() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static char mesh_interface[MENU_DATA_SIZE + 1] = "mesh0"; +static char gate_interface[MENU_DATA_SIZE + 1] = "eth0"; +static char softap_interface[MENU_DATA_SIZE + 1] = "wlan1"; +static int run_wifi_mesh_set_interfaces(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("set_interfaces"); + + ret = wifi_mesh_set_interfaces(mesh, mesh_interface, gate_interface, softap_interface); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to set interfaces: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_set_interfaces() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static struct menu_data menu_mesh_interface[] = { + { "1", "mesh", NULL, NULL, mesh_interface }, + { "2", "gate", NULL, NULL, gate_interface }, + { "3", "softap", NULL, NULL, softap_interface }, + { "4", "run", NULL, run_wifi_mesh_set_interfaces, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_mesh_device[] = { + { "1", "initialize", NULL, run_mesh_create, NULL }, + { "2", "deinitialize", NULL, run_mesh_destroy, NULL }, + { "3", "enable", NULL, run_wifi_mesh_enable, NULL }, + { "4", "disable", NULL, run_wifi_mesh_disable, NULL }, + { "5", "set_inteface", menu_mesh_interface, NULL, NULL}, + { NULL, NULL, }, +}; diff --git a/test/wifi-mesh-network.c b/test/wifi-mesh-network.c new file mode 100644 index 0000000..77b05d5 --- /dev/null +++ b/test/wifi-mesh-network.c @@ -0,0 +1,691 @@ + +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "menu.h" +#include "common.h" + +extern wifi_mesh_h mesh; + +static char gate_announce[MENU_DATA_SIZE + 1] = "1"; +static char hwmp_root_mode[MENU_DATA_SIZE + 1] = "4"; +static char stp[MENU_DATA_SIZE + 1] = "1"; + +static char ssid[MENU_DATA_SIZE + 1] = "meshnet"; +static char passphrase[MENU_DATA_SIZE + 1] = "11223344"; +static char mode[MENU_DATA_SIZE + 1] = "ac"; +static char softap_channel[MENU_DATA_SIZE + 1] = "36"; +static char visibility[MENU_DATA_SIZE + 1] = "1"; +static char max_stations[MENU_DATA_SIZE + 1] = "10"; +static char security[MENU_DATA_SIZE + 1] = "2"; + +static char meshid[MENU_DATA_SIZE + 1] = "meshnet"; +static char mesh_channel[MENU_DATA_SIZE + 1] = "161"; +static char mesh_security[MENU_DATA_SIZE + 1] = "0"; +static char mesh_passphrase[MENU_DATA_SIZE + 1] = ""; + +static char network_idx[MENU_DATA_SIZE + 1] = "1"; + +/* Found Mesh Network */ +static int g_scan_net_idx = 0; +GList *g_found_network_list = NULL; + +static void found_mesh_network_cb(wifi_mesh_network_h network, void* user_data) +{ + int ret; + wifi_mesh_network_h net = NULL; + char *meshid = NULL; + char *bssid = NULL; + int rssi; + int data_rate; + wifi_mesh_security_type_e security; + int channel; + + ret = wifi_mesh_network_clone(&net, network); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to clone found network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret); + return; + } + + g_found_network_list = g_list_append(g_found_network_list, net); + + wifi_mesh_network_get_meshid(net, &meshid); + wifi_mesh_network_get_bssid(net, &bssid); + wifi_mesh_network_get_channel(net, &channel); + wifi_mesh_network_get_rssi(net, &rssi); + wifi_mesh_network_get_data_rate(net, &data_rate); + wifi_mesh_network_get_security(net, &security); + msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d] RSSI[%ddBm] Date Rate[%dMbps] Security[%4s]", + g_scan_net_idx, meshid, bssid, channel, rssi == 0 ? 0 : rssi-120, data_rate, + (MESH_SECURITY_SAE == security) ? "SAE" : "NONE"); + + g_scan_net_idx++; + + if (meshid) free(meshid); + if (bssid) free(bssid); +} + +static void connected_peer_cb(wifi_mesh_peer_h peer, void* user_data) +{ + char *address = NULL; + + wifi_mesh_peer_get_address(peer, &address); + msgb(" Peer Address [%s]", address); + + if (address) + free(address); +} + +static void found_station_cb(mesh_station_info_h station, void* user_data) +{ + msg("Station Information Received: %p", station); +} + +static void found_mpath_cb(mesh_mpath_info_h mpath, void* user_data) +{ + msg("Station Information Received: %p", mpath); +} + +#if 0 +static int run_show_found_network(MManager *mm, struct menu_data *menu) +{ + int i = 1; /* Displays from 1 */ + char *_meshid = NULL; + int _channel = 1; + wifi_mesh_security_type_e _security = MESH_SECURITY_NONE; + + GList *iter = NULL; + + if (NULL == g_found_network_list) { + msgp("There is not any scan result.. do scan first"); + return RET_FAILURE; + } + + msg("Scan Results : "); + iter = g_found_network_list; + while (iter != NULL) { + wifi_mesh_network_h _net = iter->data; + wifi_mesh_network_get_meshid(_net, &_meshid); + wifi_mesh_network_get_channel(_net, &_channel); + wifi_mesh_network_get_security(_net, &_security); + msgb(" [%02d] Mesh ID[%-10s] Channel[%d] Security[%4s]", i++, + _meshid, _channel, (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE"); + + if (_meshid) free(_meshid); + + iter = g_list_next(iter); + } + + return RET_SUCCESS; +} +#endif + +static int run_wifi_mesh_scan(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Scan"); + + ret = wifi_mesh_scan(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Get Found Mesh Network"); + + /* Clear previous found network list */ + g_scan_net_idx = 1; + if (g_found_network_list) + g_list_free_full(g_found_network_list, (void *)wifi_mesh_network_destroy); + + g_found_network_list = NULL; + + ret = wifi_mesh_foreach_found_network(mesh, found_mesh_network_cb, NULL); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_foreach_found_network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_foreach_found_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_specific_scan(MManager *mm, struct menu_data *menu) +{ + int ret; + int channel = 1; + + msg("Specific scan"); + + if (strlen(mesh_channel)) + channel = (unsigned short)strtol(mesh_channel, NULL, 10); + + ret = wifi_mesh_specific_scan(mesh, meshid, channel); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to specific scan: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_specific_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Cancel Scan"); + + ret = wifi_mesh_cancel_scan(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to cancel scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_cancel_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Enable Mesh"); + + ret = wifi_mesh_start_mesh(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to enable mesh network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_start_mesh() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Disable Mesh"); + + ret = wifi_mesh_stop_mesh(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to disable mesh network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_stop_mesh() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu) +{ + int ret; + char *_meshid = NULL; + char *_bssid = NULL; + int _channel = -1; + bool joined = false; + wifi_mesh_connection_state_e _state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED; + wifi_mesh_security_type_e _security = MESH_SECURITY_NONE; + wifi_mesh_network_h network = NULL; + + msg("Get Joined Mesh Network Information"); + + ret = wifi_mesh_is_joined(mesh, &joined); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to check network join status: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + + ret = wifi_mesh_get_joined_network(mesh, &network); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to get joined mesh network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + + if (NULL != network) { + wifi_mesh_network_get_meshid(network, &_meshid); + msgb(" Mesh ID = %s", _meshid); + wifi_mesh_network_get_bssid(network, &_bssid); + msgb(" BSSID = %s", _bssid); + wifi_mesh_network_get_channel(network, &_channel); + msgb(" Channel = %d", _channel); + wifi_mesh_network_get_security(network, &_security); + msgb(" Security = %s", + (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE"); + wifi_mesh_network_get_connection_state(network, &_state); + msgb(" State = %s", wifi_mesh_connection_event_to_string(_state)); + + if (_meshid) free(_meshid); + if (_bssid) free(_bssid); + } + msg(""); + msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_get_connected_peers(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Get Connected Mesh Peers"); + + ret = wifi_mesh_foreach_connected_peers(mesh, connected_peer_cb, NULL); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_foreach_connected_peers: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_foreach_connected_peers() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_set_gate(MManager *mm, struct menu_data *menu) +{ + int ret; + bool _gate_announce = true; + int _hwmp_root_mode = 4; + bool _stp = true; + + msg("Set Gate Option"); + + if (strlen(gate_announce)) + _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16); + if (strlen(hwmp_root_mode)) + _hwmp_root_mode = (unsigned short)strtol(hwmp_root_mode, NULL, 10); + if (strlen(stp)) + _stp = (unsigned short)strtol(stp, NULL, 10); + + ret = wifi_mesh_set_gate(mesh, _gate_announce, _hwmp_root_mode, _stp); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to set gate options: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_set_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_unset_gate(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Disable All Gate Option"); + + ret = wifi_mesh_unset_gate(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to unset gate option: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_unset_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_set_softap(MManager *mm, struct menu_data *menu) +{ + int ret; + int _channel = 1; + int _visibility = 1; + int _max_stations = 10; + int _security = 2; + msg("Set SoftAp Option"); + + if (strlen(softap_channel)) + _channel = (unsigned short)strtol(softap_channel, NULL, 10); + if (strlen(visibility)) { + _visibility = (unsigned short)strtol(visibility, NULL, 10); + if (1 != _visibility) _visibility = 0; + } + if (strlen(max_stations)) + _max_stations = (unsigned short)strtol(max_stations, NULL, 10); + if (strlen(security)) + _security = (unsigned short)strtol(security, NULL, 10); + + ret = wifi_mesh_set_softap(mesh, ssid, passphrase, + _channel, _visibility, _max_stations, _security); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to set softap options: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_enable_softap(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Enable SoftAp"); + + ret = wifi_mesh_enable_softap(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to enable soft ap: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_enable_softap() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_disable_softap(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Disable SoftAp"); + + ret = wifi_mesh_disable_softap(mesh); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to disable soft ap: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_disable_softap() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_create_network(MManager *mm, struct menu_data *menu) +{ + int ret; + int _mesh_channel = 1; + wifi_mesh_security_type_e security = MESH_SECURITY_NONE; + wifi_mesh_network_h net = NULL; + + msg("Create a new Mesh Network"); + + if (strlen(mesh_channel)) + _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10); + + if (strlen(mesh_security)) { + ret = (unsigned short)strtol(mesh_security, NULL, 10); + security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE); + } + + wifi_mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0, + security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL); + ret = wifi_mesh_create_network(mesh, net); + wifi_mesh_network_destroy(net); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_create_network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_create_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_connect_network(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx = 1; + wifi_mesh_network_h net = NULL; + wifi_mesh_security_type_e security = MESH_SECURITY_NONE; + msg("Connect to Mesh Network"); + + if (strlen(network_idx)) { + idx = (unsigned short)strtol(network_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); + if (NULL == net) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + /* Set passphrase */ + wifi_mesh_network_get_security(net, &security); + if (MESH_SECURITY_NONE != security) { + if (strlen(mesh_passphrase)) { + ret = wifi_mesh_network_set_passphrase(net, mesh_passphrase); + if (WIFI_MESH_ERROR_NONE != ret) + msgr("Failed to set passphrase !"); + } else { + msgr("If security enabled, passphrase should be set !"); + return RET_FAILURE; + } + } + + ret = wifi_mesh_connect_network(mesh, net); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_connect_network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_connect_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_disconnect_network(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx = 1; + wifi_mesh_network_h net = NULL; + msg("Disconnect with Mesh Network"); + + if (strlen(network_idx)) { + idx = (unsigned short)strtol(network_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); + if (NULL == net) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = wifi_mesh_disconnect_network(mesh, net); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_disconnect_network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_disconnect_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_forget_network(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx = 1; + wifi_mesh_network_h net = NULL; + msg("Forget Mesh Network"); + + if (strlen(network_idx)) { + idx = (unsigned short)strtol(network_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); + if (NULL == net) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = wifi_mesh_forget_network(mesh, net); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_forget_network: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_forget_network() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_get_station_information(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Get Mesh Station Information"); + + ret = wifi_mesh_get_stations_info(mesh, found_station_cb, NULL); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} + +static int run_get_mpath_information(MManager *mm, struct menu_data *menu) +{ + int ret; + msg("Get Mesh Path Information"); + + ret = wifi_mesh_get_mpath_info(mesh, found_mpath_cb, NULL); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to wifi_mesh_get_mpath_info: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - wifi_mesh_get_mpath_info() ret: [0x%X] [%s]", + ret, wifi_mesh_error_to_string(ret)); + + return RET_SUCCESS; +} +static struct menu_data menu_specific_scan[] = { + { "1", "Mesh ID", NULL, NULL, meshid }, + { "2", "Channel", NULL, NULL, mesh_channel }, + { "3", "Run", NULL, run_wifi_mesh_specific_scan, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_gate_option[] = { + { "1", "Gate Announcement", NULL, NULL, gate_announce }, + { "2", "HWMP Root Mode", NULL, NULL, hwmp_root_mode }, + { "3", "STP", NULL, NULL, stp }, + { "4", "Run", NULL, run_set_gate, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_softap_option[] = { + { "1", "SSID", NULL, NULL, ssid }, + { "2", "passphrase", NULL, NULL, passphrase }, + { "3", "802.11 mode", NULL, NULL, mode }, + { "4", "channel", NULL, NULL, softap_channel }, + { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility }, + { "6", "max. client num", NULL, NULL, max_stations }, + { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security }, + { "7", "run", NULL, run_set_softap, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_create_network[] = { + { "1", "Mesh ID", NULL, NULL, meshid }, + { "2", "Channel", NULL, NULL, mesh_channel }, + { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security }, + { "4", "Passphrase", NULL, NULL, mesh_passphrase }, + { "5", "Run", NULL, run_create_network, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_connect_network[] = { + { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Passphrase", NULL, NULL, mesh_passphrase }, + { "3", "Run", NULL, run_connect_network, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_disconnect_network[] = { + { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Run", NULL, run_disconnect_network, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_forget_network[] = { + { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Run", NULL, run_forget_network, NULL }, + { NULL, NULL, }, +}; + + +struct menu_data menu_mesh_network[] = { + { "1", "Scan", NULL, run_wifi_mesh_scan, NULL }, + { "2", "Get found mesh network", NULL, run_get_found_mesh_network, NULL }, + { "3", "Specific scan", menu_specific_scan, NULL, NULL }, + { "4", "Cancel scan", NULL, run_wifi_mesh_cancel_scan, NULL }, + { "5", "Enable mesh", NULL, run_wifi_mesh_enable, NULL }, + { "6", "Disable mesh", NULL, run_wifi_mesh_disable, NULL }, + { "7", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL }, + { "8", "Set gate", menu_gate_option, NULL, NULL }, + { "9", "Unset gate", NULL, run_unset_gate, NULL }, + { "10", "Set softap", menu_softap_option, NULL, NULL }, + { "11", "Enable softap", NULL, run_enable_softap, NULL }, + { "12", "Disable softap", NULL, run_disable_softap, NULL }, + { "13", "Create network", menu_create_network, NULL, NULL }, + { "14", "Connect network", menu_connect_network, NULL, NULL }, + { "15", "Disconnect network", menu_disconnect_network, NULL, NULL }, + { "16", "Forget network", menu_forget_network, NULL, NULL }, + { "17", "Get connected mesh peers", NULL, run_get_connected_peers, NULL }, + { "18", "Get mesh station information", NULL, run_get_station_information, NULL }, + { "19", "Get mesh path information", NULL, run_get_mpath_information, NULL }, + { NULL, NULL, }, +};