Implement mesh_test and rest of APIs
authorsaerome kim <saerome.kim@samsung.com>
Wed, 8 Mar 2017 08:22:53 +0000 (17:22 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:09:10 +0000 (11:09 +0900)
Signed-off-by: saerome kim <saerome.kim@samsung.com>
include/mesh.h [changed mode: 0644->0755]
include/mesh_private.h [changed mode: 0644->0755]
src/mesh.c [changed mode: 0644->0755]
src/mesh_dbus.c [changed mode: 0644->0755]
test/main.c [changed mode: 0644->0755]
test/mesh_device.c [changed mode: 0644->0755]
test/mesh_network.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 8609375..fac1ef1
@@ -123,6 +123,289 @@ typedef void* mesh_station_info_h;
 typedef void* mesh_path_info_h;
 
 /**
+ * @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 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] data_rate The maxinum data rate
+ *
+ * @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, int data_rate);
+
+/**
+ * @brief Destroys network handle for network information.
+ * @details This function is to destroy mesh network information
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] netowrk 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()
+ *
+ */
+void mesh_network_destroy(mesh_network_h network);
+
+/**
+ * @brief Gets network mesh network id.
+ * @details This function is to return mesh network id
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] netowrk The mesh network information handle.
+ * @param[out] meshid The mesh network id.
+ *
+ * @return None
+ *
+ * @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] netowrk 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_set_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
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] netowrk 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] netowrk 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_meshid()
+ *
+ */
+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] netowrk The mesh network information handle.
+ * @param[out] chanel The opeatring 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] netowrk The mesh network information handle.
+ * @param[in] chanel The opeatring 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] netowrk 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_get_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] netowrk 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 maximum data rate.
+ * @details This function is to get the maximum data rate
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] netowrk 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_get_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] netowrk 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 Initializes Mesh network.
  * @since_tizen 4.0
  * @privlevel public
@@ -323,10 +606,46 @@ typedef void (*mesh_found_mesh_netwrok_cb)(mesh_network_h network, void* user_da
  * @see mesh_found_mesh_netwrok_cb()
  *
  */
-int mesh_foreach_found_mesh_netwrok(mesh_h handle,
+int mesh_foreach_scanned_mesh_netwrok(mesh_h handle,
        mesh_found_mesh_netwrok_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.
  *
@@ -365,17 +684,123 @@ int mesh_is_joined(mesh_h handle, int* is_joined);
  * @see mesh_enable_mesh()
  *
  */
-int mesh_get_joined_network(mesh_h handle, mesh_network_h network);
+int mesh_get_joined_network(mesh_h handle, mesh_network_h* network);
+
+/**
+ * @brief Sets gate options
+ * @details This function sets mesh gate options.
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] handle The mesh handle
+ * @param[in] stp Eanble / Disable STP (Spanning Tree Protocol)
+ * @param[in] gate_announce 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, bool stp, bool gate_announce);
+
+/**
+ * @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 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 maxinum 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 Adds new mesh network configuration
- * @details This function adds new network configuration.
+ * @details This function adds new network configuration to connect.
  *
  * @since_tizen 4.0
  *
  * @param[in] handle The mesh handle
  * @param[in] network callback function pointer to know saved network information
- * @param[in] user_data user data pointer
  *
  *
  * @return 0 on success, otherwise a negative error value.
old mode 100644 (file)
new mode 100755 (executable)
index e540475..e2db364
@@ -82,9 +82,10 @@ struct mesh_handle {
 #endif
 } mesh_handle_s;
 
+
 struct mesh_network_s {
-       char meshid[32]; /**< meshid */
-       char bssid[32]; /**< bssid */
+       char meshid[MAX_MESHID_LEN]; /**< meshid */
+       char bssid[MAX_BSSID_LEN]; /**< bssid */
        int channel; /**< channel */
        int rssi; /**< rssi */
        int data_rate; /**< data rate */
old mode 100644 (file)
new mode 100755 (executable)
index 72c920d..4527784
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdlib.h>
 
 #include "mesh.h"
 #include "mesh_log.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) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net = calloc(1, sizeof(struct mesh_network_s));
+       if (NULL == net) {
+               LOGE("Out of memory"); //LCOV_EXCL_LINE
+               return MESH_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+       }
+       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;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (dst == NULL || src == NULL) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net = calloc(1, sizeof(struct mesh_network_s));
+       if (NULL == net) {
+               LOGE("Out of memory"); //LCOV_EXCL_LINE
+               return MESH_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+       }
+       memcpy(dst, src, sizeof(struct mesh_network_s));
+       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, int data_rate)
+{
+       struct mesh_network_s *net;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (network == NULL) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net = calloc(1, sizeof(struct mesh_network_s));
+       memcpy(net->meshid, meshid, MAX_MESHID_LEN);
+       memcpy(net->bssid, bssid, MAX_BSSID_LEN);
+       net->channel = channel;
+       net->rssi = rssi;
+       net->data_rate = data_rate;
+       network = (mesh_network_h)net;
+
+       return MESH_ERROR_NONE;
+}
+
+EXPORT_API void mesh_network_destroy(mesh_network_h network)
+{
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+       free(network);
+}
+
+EXPORT_API int mesh_network_get_meshid(mesh_network_h network, char *meshid)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (network == NULL || meshid == NULL ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       meshid = 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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       memcpy(net->meshid, meshid, MAX_MESHID_LEN);
+
+       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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       bssid = 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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       memcpy(net->bssid, bssid, MAX_BSSID_LEN);
+
+       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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       *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) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       *rssi = net->channel;
+
+       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) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net->rssi = rssi;
+
+       return MESH_ERROR_NONE;
+}
+
+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 ) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       *data_rate = net->channel;
+
+       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) {
+               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+               return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net->data_rate = data_rate;
+
+       return MESH_ERROR_NONE;
+}
+
 EXPORT_API int mesh_initialize(mesh_h *mesh)
 {
        int rv;
@@ -148,7 +382,7 @@ EXPORT_API int mesh_specific_scan(mesh_h handle, const char* ssid, int channel)
        return MESH_ERROR_NONE;
 }
 
-EXPORT_API int mesh_foreach_round_mesh_network(mesh_h handle,
+EXPORT_API int mesh_foreach_scanned_mesh_netwrok(mesh_h handle,
        mesh_found_mesh_netwrok_cb cb, void *user_data)
 {
        int rv = 0;
@@ -210,7 +444,7 @@ EXPORT_API int mesh_is_joined(mesh_h handle, int* is_joined)
        return MESH_ERROR_NONE;
 }
 
-EXPORT_API int mesh_get_joined_network(mesh_h handle, mesh_network_h network)
+EXPORT_API int mesh_get_joined_network(mesh_h handle, mesh_network_h *network)
 {
        int rv = 0;
        CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
@@ -256,19 +490,23 @@ EXPORT_API int mesh_unset_gate(mesh_h handle)
 }
 
 EXPORT_API int mesh_set_softap(mesh_h handle, const char* ssid,
-               const char* key, const char* mode,
-               int channel, int visibility,
+               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);
-       RETV_IF(NULL == mode, MESH_ERROR_INVALID_PARAMETER);
 
-       rv = _mesh_set_softap(handle, ssid, key, mode, channel,
+       if (channel <= 13)
+               memcpy(buf, "n", strlen("n"));
+       else
+               memcpy(buf, "a", strlen("a"));
+
+       rv = _mesh_set_softap(handle, ssid, key, buf, channel,
                        visibility, max_stations, security);
        if (rv == MESH_ITNL_ERR_IO_ERROR) {
                return MESH_ERROR_IO_ERROR;
old mode 100644 (file)
new mode 100755 (executable)
index c5f52be..13ce925
@@ -320,7 +320,7 @@ int _mesh_cancel_scan(mesh_h handle)
        RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR);
        RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR);
 
-       variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "cancle_scan",
+       variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "cancel_scan",
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
old mode 100644 (file)
new mode 100755 (executable)
index 14d0116..6c4b2ef
@@ -34,6 +34,11 @@ mesh_h mesh = NULL;
 extern struct menu_data menu_mesh_device[];
 extern struct menu_data menu_mesh_network[];
 
+/* Scanned Mesh Network */
+extern GHashTable *g_hash_scan_net_list;
+/* Mesh Network Configuration */
+extern GHashTable *g_hash_saved_net_list;
+
 const char* mesh_error_to_string(mesh_error_e err)
 {
        switch (err) {
@@ -55,7 +60,7 @@ const char* mesh_error_to_string(mesh_error_e err)
 
 void event_cb(mesh_event_e event_type, void* param)
 {
-       
+
 }
 
 static int __init_func(MManager *mm, struct menu_data *menu)
@@ -119,6 +124,8 @@ int main(int arg, char **argv)
        g_main_loop_run(mainloop);
 
 OUT:
+       g_hash_table_remove_all(g_hash_scan_net_list);
+       g_hash_table_remove_all(g_hash_saved_net_list);
        g_main_loop_unref(mainloop);
        msg("******* Bye bye *******");
 
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 7c96bf3..4c8cfab
 #include "menu.h"
 #include "common.h"
 
+extern mesh_h mesh;
+
+static char stp[MENU_DATA_SIZE + 1] = "1";
+static char gate_announce[MENU_DATA_SIZE + 1] = "1";
+
+static char ssid[MENU_DATA_SIZE + 1] = "meshnet";
+static char key[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 network_idx[MENU_DATA_SIZE + 1] = "1";
+
+/* Scanned Mesh Network */
+static int g_scan_net_idx = 0;
+GHashTable *g_hash_scan_net_list = NULL;
+
+/* Mesh Network Configuration */
+static int g_saved_net_idx = 0;
+GHashTable *g_hash_saved_net_list = NULL;
+
+void found_mesh_netwrok_cb(mesh_network_h network, void* user_data)
+{
+       int ret;
+       mesh_network_h net = NULL;
+       char meshid[MAX_MESHID_LEN] = {0,};
+       char bssid[MAX_BSSID_LEN] = {0,};
+       int channel;
+       ret = mesh_network_clone(&net, network);
+       if (0 != ret) {
+               msg("Failed to clone scaned network: [%s(0x%X)]", mesh_error_to_string(ret), ret);
+               return;
+       }
+       if (g_hash_table_insert(g_hash_scan_net_list, GINT_TO_POINTER(g_scan_net_idx), net)) {
+               g_scan_net_idx++;
+               mesh_network_get_meshid(net, meshid);
+               mesh_network_get_bssid(net, bssid);
+               mesh_network_get_channel(net, &channel);
+               msg("[%d] meshid=%s bssid=%s channel=%d", g_scan_net_idx, meshid, bssid, channel);
+       }
+}
+
+void saved_mesh_netwrok_cb(mesh_network_h network, void* user_data)
+{
+       int ret;
+       mesh_network_h net = NULL;
+       char meshid[MAX_MESHID_LEN] = {0,};
+       char bssid[MAX_BSSID_LEN] = {0,};
+       int channel;
+       ret = mesh_network_clone(&net, network);
+       if (0 != ret) {
+               msg("Failed to clone configured network: [%s(0x%X)]", mesh_error_to_string(ret), ret);
+               return;
+       }
+       if (g_hash_table_insert(g_hash_saved_net_list, GINT_TO_POINTER(g_saved_net_idx), net)) {
+               g_saved_net_idx++;
+               mesh_network_get_meshid(net, meshid);
+               mesh_network_get_bssid(net, meshid);
+               mesh_network_get_channel(net, &channel);
+               msg("[%d] meshid=%s bssid=%s channel=%d", g_saved_net_idx, meshid, bssid, channel);
+       }
+}
+
 static int run_mesh_scan(MManager *mm, struct menu_data *menu)
 {
+       int ret;
        msg("Scan");
+
+       ret = mesh_scan(mesh);
+       if (ret != 0) {
+               msg("Failed to scan: [%s(0x%X)]", mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_get_scanned_mesh_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       msg("Get Scanned Mesh Network");
+
+       /* Clear previous scanned network list */
+       g_scan_net_idx = 0;
+       if (g_hash_scan_net_list) g_hash_table_remove_all(g_hash_scan_net_list);
+       g_hash_scan_net_list = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free);
+
+       ret = mesh_foreach_scanned_mesh_netwrok(mesh, found_mesh_netwrok_cb, NULL);
+       if (ret != 0) {
+               msg("Failed to mesh_foreach_scanned_mesh_network: [%s(0x%X)]",
+                               mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
        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, 16);
+
+       ret = mesh_specific_scan(mesh, meshid, channel);
+       if (ret != 0) {
+               msg("Failed to specific scan: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
        return RET_SUCCESS;
 }
 
 static int run_mesh_cancel_scan(MManager *mm, struct menu_data *menu)
 {
-       msg("Cancel scan");
+       int ret;
+       msg("Cancel Scan");
+
+       ret = mesh_cancel_scan(mesh);
+       if (ret != 0) {
+               msg("Failed to cancel scan: [%s(0x%X)]", mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       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 (ret != 0) {
+               msg("Failed to enable mesh network: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       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 (ret != 0) {
+               msg("Failed to disable mesh network: [%s(0x%X)]", mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       mesh_network_h network = NULL;
+
+       msg("Get Joined Mesh Network Information");
+
+       ret = mesh_get_joined_network(mesh, &network);
+       if (ret != 0) {
+               msg("Failed to enable mesh network: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       mesh_network_destroy(network);
+
+       return RET_SUCCESS;
+}
+
+static int run_set_gate(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       bool _stp = true;
+       bool _gate_announce = true;
+
+       msg("Set Gate Option");
+
+       if (strlen(stp))
+               _stp = (unsigned short)strtol(stp, NULL, 16);
+       if (strlen(gate_announce))
+               _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16);
+
+       ret = mesh_set_gate(mesh, _stp, _gate_announce);
+       if (ret != 0) {
+               msg("Failed to set gate options: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       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 (ret != 0) {
+               msg("Failed to unset gate option: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       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, 16);
+       if (strlen(visibility)) {
+               _visibility = (unsigned short)strtol(visibility, NULL, 16);
+               if (1 != _visibility) _visibility = 0;
+       }
+       if (strlen(max_stations))
+               _max_stations = (unsigned short)strtol(max_stations, NULL, 16);
+       if (strlen(security))
+               _security = (unsigned short)strtol(security, NULL, 16);
+
+       ret = mesh_set_softap(mesh, ssid, key, _channel, _visibility, _max_stations, _security);
+       if (ret != 0) {
+               msg("Failed to unset gate option: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       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 (ret != 0) {
+               msg("Failed to enable soft ap: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       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 (ret != 0) {
+               msg("Failed to disable soft ap: [%s(0x%X)]",
+                       mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_get_saved_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       msg("Get Saved Mesh Network Configuration");
+
+       /* Clear previous saved network configurations */
+       g_saved_net_idx = 0;
+       if (g_hash_saved_net_list) g_hash_table_remove_all(g_hash_saved_net_list);
+       g_hash_saved_net_list = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free);
+
+       ret = mesh_foreach_saved_mesh_network(mesh, saved_mesh_netwrok_cb, NULL);
+       if (ret != 0) {
+               msg("Failed to mesh_foreach_saved_mesh_network: [%s(0x%X)]",
+                               mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_add_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx = 1;
+       mesh_network_h net = NULL;
+       msg("Add Network Configuration");
+
+       if (strlen(network_idx))
+               idx = (unsigned short)strtol(network_idx, NULL, 16);
+
+       net = g_hash_table_lookup(g_hash_scan_net_list, GINT_TO_POINTER(idx));
+       if (NULL == net) {
+               msg("Failed to g_hash_table_lookup");
+               return RET_FAILURE;
+       }
+
+       ret = mesh_add_mesh_network(mesh, net);
+       if (ret != 0) {
+               msg("Failed to mesh_add_mesh_network: [%s(0x%X)]",
+                               mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_select_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx = 1;
+       mesh_network_h net = NULL;
+       msg("Select Save Network Configuration");
+
+       if (strlen(network_idx))
+               idx = (unsigned short)strtol(network_idx, NULL, 16);
+
+       net = g_hash_table_lookup(g_hash_scan_net_list, GINT_TO_POINTER(idx));
+       if (NULL == net) {
+               msg("Failed to g_hash_table_lookup");
+               return RET_FAILURE;
+       }
+
+       ret = mesh_select_mesh_network(mesh, net);
+       if (ret != 0) {
+               msg("Failed to mesh_select_mesh_network: [%s(0x%X)]",
+                               mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       return RET_SUCCESS;
+}
+
+static int run_remove_network(MManager *mm, struct menu_data *menu)
+{
+       int ret;
+       int idx = 1;
+       mesh_network_h net = NULL;
+       msg("Remove Save Network Configuration");
+
+       if (strlen(network_idx))
+               idx = (unsigned short)strtol(network_idx, NULL, 16);
+
+       net = g_hash_table_lookup(g_hash_scan_net_list, GINT_TO_POINTER(idx));
+       if (NULL == net) {
+               msg("Failed to g_hash_table_lookup");
+               return RET_FAILURE;
+       }
+
+       ret = mesh_select_mesh_network(mesh, net);
+       if (ret != 0) {
+               msg("Failed to mesh_remove_mesh_network: [%s(0x%X)]",
+                               mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
        return RET_SUCCESS;
 }
 
-static int run_mesh_join(MManager *mm, struct menu_data *menu)
+static int run_get_station_information(MManager *mm, struct menu_data *menu)
 {
-       msg("Join");
+       msg("Get Mesh Station Information");
        return RET_SUCCESS;
 }
 
-static int run_mesh_disjoin(MManager *mm, struct menu_data *menu)
+static int run_get_mpath_information(MManager *mm, struct menu_data *menu)
 {
-       msg("Disjoin");
+       msg("Get Mesh Path Information");
        return RET_SUCCESS;
 }
+static struct menu_data menu_specific_scan[] = {
+       { "1", "meshid", 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", "stp", NULL, NULL, stp },
+       { "2", "gate_announce", NULL, NULL, gate_announce },
+       { "3", "run", NULL, run_set_gate, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_softap_option[] = {
+       { "1", "ssid", NULL, NULL, ssid },
+       { "2", "key", NULL, NULL, key },
+       { "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_add_network[] = {
+       { "1", "meshid", NULL, NULL, meshid },
+       { "2", "channel", NULL, NULL, mesh_channel },
+       { "3", "run", NULL, run_add_network, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_select_network[] = {
+       { "1", "index", NULL, NULL, network_idx },
+       { "3", "run", NULL, run_select_network, NULL },
+       { NULL, NULL, },
+};
+
+static struct menu_data menu_remove_network[] = {
+       { "1", "index", NULL, NULL, network_idx },
+       { "3", "run", NULL, run_remove_network, NULL },
+       { NULL, NULL, },
+};
+
 
 struct menu_data menu_mesh_network[] = {
        { "1", "Scan", NULL, run_mesh_scan, NULL },
-       { "2", "Specific scan", NULL, run_mesh_specific_scan, NULL },
-       { "3", "cancel scan", NULL, run_mesh_cancel_scan, NULL },
-       { "4", "Join", NULL, run_mesh_join, NULL },
-       { "5", "Disjoin", NULL, run_mesh_disjoin, NULL },
+       { "2", "get scanned mesh network", NULL, run_get_scanned_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", "Get Saved Mesh Network", NULL, run_get_saved_network, NULL },
+       { "14", "add network", menu_add_network, NULL, NULL },
+       { "15", "select network", menu_select_network, NULL, NULL },
+       { "16", "remove network", menu_remove_network, NULL, NULL },
+       { "17", "get mesh station information", NULL, run_get_station_information, NULL },
+       { "18", "get mesh path information", NULL, run_get_mpath_information, NULL },
        { NULL, NULL, },
 };