#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
*/
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;
* @param[in] channel The operating channel number
* @param[in] rssi The Received Signal Strength Indicator
* @param[in] data_rate The maximum data rate
+ * @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
*
*/
int mesh_network_new_with(mesh_network_h* network, const char *meshid,
- const char *bssid, int channel, int rssi, int data_rate);
+ const char *bssid, int channel, int rssi, int data_rate,
+ mesh_security_type_e security, const char *passphrase);
/**
* @brief Destroys network handle for network information.
* @retval #MESH_ERROR_NONE Successful
* @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see mesh_network_set_meshid()
+ * @see mesh_network_get_meshid()
*
*/
int mesh_network_set_meshid(mesh_network_h network, const char *meshid);
* @retval #MESH_ERROR_NONE Successful
* @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see mesh_network_set_meshid()
+ * @see mesh_network_get_bssid()
*
*/
int mesh_network_set_bssid(mesh_network_h network, const char *bssid);
* @retval #MESH_ERROR_NONE Successful
* @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see mesh_network_get_rssi()
+ * @see mesh_network_set_rssi()
*
*/
int mesh_network_get_rssi(mesh_network_h network, int *rssi);
* @retval #MESH_ERROR_NONE Successful
* @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see mesh_network_get_data_rate()
+ * @see mesh_network_set_data_rate()
*
*/
int mesh_network_get_data_rate(mesh_network_h network, int *data_rate);
int mesh_network_set_data_rate(mesh_network_h network, int data_rate);
/**
+ * @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
*
int channel; /**< Channel */
int rssi; /**< RSSI */
int data_rate; /**< Data rate */
- int security; /**< Security type */
+ mesh_security_type_e security; /**< Security type */
+ char passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase */
mesh_connection_state_e state; /**< Connection state */
};
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <stdio.h>
#include <stdlib.h>
#include "mesh.h"
LOGE("Out of memory"); //LCOV_EXCL_LINE
return MESH_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
- memcpy(net->meshid, _src->meshid, MAX_MESHID_LEN);
- memcpy(net->bssid, _src->bssid, MAX_BSSID_LEN);
+ 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 (_src->passphrase)
+ snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", _src->passphrase);
*dst = (mesh_network_h)net;
}
EXPORT_API int mesh_network_new_with(mesh_network_h* network, const char *meshid,
- const char *bssid, int channel, int rssi, int data_rate)
+ const char *bssid, int channel, int rssi, int data_rate,
+ mesh_security_type_e security, const char *passphrase)
{
struct mesh_network_s *net;
}
net = calloc(1, sizeof(struct mesh_network_s));
- if (meshid) memcpy(net->meshid, meshid, MAX_MESHID_LEN);
- if (bssid) memcpy(net->bssid, bssid, MAX_BSSID_LEN);
+ 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->data_rate = data_rate;
+ net->security = security;
+ if (passphrase)
+ snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase);
+
*network = (mesh_network_h)net;
return MESH_ERROR_NONE;
struct mesh_network_s *net = network;
CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
- if (net == NULL) {
+ if (NULL == net) {
LOGE("Invalid parameter"); //LCOV_EXCL_LINE
return; //LCOV_EXCL_LINE
}
- if (net) free(net);
+
+ free(net);
}
EXPORT_API int mesh_network_get_meshid(mesh_network_h network, char **meshid)
return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- memcpy(net->meshid, meshid, MAX_MESHID_LEN);
+ snprintf(net->meshid, MAX_MESHID_LEN, "%s", meshid);
return MESH_ERROR_NONE;
}
return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- memcpy(net->bssid, bssid, MAX_BSSID_LEN);
+ snprintf(net->bssid, MAX_BSSID_LEN, "%s", bssid);
return MESH_ERROR_NONE;
}
return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- *rssi = net->channel;
+ *rssi = net->rssi;
return MESH_ERROR_NONE;
}
return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- *data_rate = net->channel;
+ *data_rate = net->data_rate;
return MESH_ERROR_NONE;
}
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 ) {
+ LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+ return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ *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) {
+ LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+ return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ 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) {
+ LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+ return MESH_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ 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)
{
* limitations under the License.
*/
+#include <stdio.h>
#include <stdlib.h>
#include "mesh.h"
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) {
+ 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) {
+ 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) {
+ 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) {
+ else if (strcasecmp(key, "channel") == 0) {
network_info->channel = g_variant_get_uint32(val);
LOGD(" Channel [%d]", network_info->channel);
}
- else if (strcasecmp(key, "state") == 0) {
+ 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);
}
char *bssid = NULL;
int channel = 0;
int state = 0;
+ int security = 0;
mesh_event_data_s ev;
- g_variant_get(parameters, "(ssii)", &mesh_id, &bssid, &channel, &state);
+ 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_CONNECTION_STATE_EVENT, &ev);
g_variant_get(parameters, "(s)", &bssid);
memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN);
h->event_handler(MESH_STATION_JOIN_EVENT, &ev);
- g_free(ev.data.sta_info);
+ free(ev.data.sta_info);
} else if (0 == g_strcmp0(signal_name, "sta_left")) {
char *bssid = NULL;
mesh_event_data_s ev;
g_variant_get(parameters, "(s)", &bssid);
memcpy(ev.data.sta_info->bssid, bssid, MAX_BSSID_LEN);
h->event_handler(MESH_STATION_LEFT_EVENT, &ev);
- g_free(ev.data.sta_info);
+ free(ev.data.sta_info);
}
}
char *meshid = NULL;
char *bssid = NULL;
int channel = -1;
+ int security = -1;
int state = 0;
int svc_result = 0;
- g_variant_get(variant, "(ssiii)", &meshid, &bssid, &channel, &state, &svc_result);
+ 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);
g_joined_network.channel = 0;
g_joined_network.rssi = -1;
g_joined_network.data_rate = 0;
- g_joined_network.security = 0;
+ g_joined_network.security = MESH_SECURITY_NONE;
g_joined_network.state = MESH_CONNECTION_STATE_DISCONNECTED;
if (SERVICE_ERROR_NO_DATA == svc_result) {
if (meshid) {
LOGE(" Mesh ID : %s", meshid);
- g_snprintf(g_joined_network.meshid, MAX_MESHID_LEN, "%s", meshid);
+ snprintf(g_joined_network.meshid, MAX_MESHID_LEN, "%s", meshid);
}
if (bssid) {
LOGE(" BSSID : %s", bssid);
- g_snprintf(g_joined_network.bssid, MAX_BSSID_LEN, "%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;
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("(sii)", n->meshid, n->channel, n->security),
+ g_variant_new("(siis)", n->meshid, n->channel, n->security, n->passphrase),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, &error);
case MESH_CONNECTION_STATE_EVENT:{
msgp(" Connection state changed [%s]",
_mesh_connection_event_to_string(event->data.connection_state->state));
- msgp(" From Mesh ID[%-10s] BSSID[%s] Channel[%d]",
+ 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);
+ event->data.connection_state->channel,
+ (MESH_SECURITY_SAE == event->data.connection_state->security) ? "SAE" : "NONE");
} break;
case MESH_STATION_JOIN_EVENT: {
msgp(" New Station Joined = %s", event->data.sta_info->bssid);
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";
mesh_network_h net = NULL;
char *meshid = NULL;
char *bssid = NULL;
+ mesh_security_type_e security;
int channel;
ret = mesh_network_clone(&net, network);
mesh_network_get_meshid(net, &meshid);
mesh_network_get_bssid(net, &bssid);
mesh_network_get_channel(net, &channel);
- msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d]", g_scan_net_idx, meshid, bssid, channel);
+ mesh_network_get_security(net, &security);
+ msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d] Security[%4s]",
+ g_scan_net_idx, meshid, bssid, channel,
+ (MESH_SECURITY_SAE == security) ? "SAE" : "NONE");
g_scan_net_idx++;
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;
mesh_network_h _net = iter->data;
mesh_network_get_meshid(_net, &_meshid);
mesh_network_get_channel(_net, &_channel);
- msgb(" [%02d] Mesh ID[%-10s] Channel[%d]", i++, _meshid, _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);
return RET_SUCCESS;
}
+#endif
static int run_mesh_scan(MManager *mm, struct menu_data *menu)
{
char *_bssid = NULL;
int _channel = -1;
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");
if (NULL != network) {
mesh_network_get_meshid(network, &_meshid);
- msgb(" Mesh ID = %s", _meshid);
+ msgb(" Mesh ID = %s", _meshid);
mesh_network_get_bssid(network, &_bssid);
- msgb(" BSSID = %s", _bssid);
+ msgb(" BSSID = %s", _bssid);
mesh_network_get_channel(network, &_channel);
- msgb(" Channel = %d", _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));
+ msgb(" State = %s", _mesh_connection_event_to_string(_state));
if (_meshid) free(_meshid);
if (_bssid) free(_bssid);
{
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);
- mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0, 0);
+ 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, 0, security, NULL);
ret = mesh_create_mesh_network(mesh, net);
mesh_network_destroy(net);
if (MESH_ERROR_NONE != ret) {
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)) {
}
}
+ /* 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)]",
static struct menu_data menu_create_network[] = {
{ "1", "Mesh ID", NULL, NULL, meshid },
{ "2", "Channel", NULL, NULL, mesh_channel },
- { "3", "Run", NULL, run_create_network, NULL },
+ { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security },
+ { "4", "Run", NULL, run_create_network, NULL },
{ NULL, NULL, },
};
static struct menu_data menu_connect_network[] = {
- { "0", "Show found networks", NULL, run_show_found_network, NULL },
+ { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
{ "1", "Index", NULL, NULL, network_idx },
- { "2", "Run", NULL, run_connect_network, NULL },
+ { "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_show_found_network, NULL },
+ { "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_show_found_network, NULL },
+ { "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, },