#define MAX_BSSID_LEN 18
/**
- * @brief Enumeration for the state of the Mesh network.
+ * @brief Enumeration for the connection state of the Mesh network.
* @since_tizen 4.0
*/
typedef enum {
- MESH_STATE_DEACTIVATED = 0, /**< Mesh network is Deactivated */
- MESH_STATE_ACTIVATED = 1, /**< Mesh network is activated */
-} mesh_state_e;
+ 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
typedef enum {
MESH_MESH_ENABLED_EVENT = 0x00, /**< This event is received after enabling mesh network */
MESH_SCAN_DONE_EVENT = 0x01, /**< This event comes after scanning operation completed */
- MESH_JOIN_NETWORK_EVENT = 0x02, /**< This event comes after joining a mesh network */
- MESH_LEFT_NETWORK_EVENT = 0x03, /**< This event comes after left the current mesh network */
- MESH_STATION_JOIN_EVENT = 0x04, /**< This event takes place when new station joined */
- MESH_STATION_LEFT_EVENT = 0x05, /**< This event takes place when existing station left */
- MESH_CONNECTED_EVENT = 0x06, /**< This event comes after all network connection sequence finished */
+ MESH_CONNECTION_STATE_EVENT = 0x02, /**< This event takes place when mesh network connection state is changed */
+ MESH_STATION_JOIN_EVENT = 0x03, /**< This event takes place when new station joined */
+ MESH_STATION_LEFT_EVENT = 0x04, /**< This event takes place when existing station left */
} mesh_event_e;
/**
} mesh_other_station_event_s;
/**
- * @brief The structure type for the MESH_CONNECTED_EVENT callback data.
- * @details The result of connecting mesh network.
+ * @brief The structure type for the MESH_CONNECTION_STATE_EVENT callback data.
+ * @details The state of mesh network connection.
*
* @since_tizen 4.0
*/
typedef struct {
- int result; /**< The result of connecting mesh network. */
-} mesh_connected_event_s;
+ 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_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.
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_connected_event_s *connected_result; /**< The result of mesh network connection. */
+ mesh_connection_state_event_s *connection_state; /**< The state of mesh network connection. */
} data;
} mesh_event_data_s;
int mesh_network_set_data_rate(mesh_network_h network, int data_rate);
/**
+ * @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.
else if (strcasecmp(key, "channel") == 0) {
network_info->channel = g_variant_get_uint32(val);
LOGD(" Channel [%d]", network_info->channel);
-
- /* Last element */
- _mesh_append_network(network_info);
+ }
+ 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);
free(ev.data.mesh_enable);
} else if (0 == g_strcmp0(signal_name, "scan_done")) {
h->event_handler(MESH_SCAN_DONE_EVENT, NULL);
- } else if (0 == g_strcmp0(signal_name, "joined_network")) {
- h->event_handler(MESH_JOIN_NETWORK_EVENT, NULL);
- } else if (0 == g_strcmp0(signal_name, "left_network")) {
- h->event_handler(MESH_LEFT_NETWORK_EVENT, NULL);
- } else if (0 == g_strcmp0(signal_name, "mesh_connected")) {
- int result = MESH_ERROR_NONE;
+ } else if (0 == g_strcmp0(signal_name, "connection_state")) {
+ char *mesh_id = NULL;
+ char *bssid = NULL;
+ int channel = 0;
+ int state = 0;
mesh_event_data_s ev;
- g_variant_get(parameters, "(i)", &result);
+ g_variant_get(parameters, "(ssii)", &mesh_id, &bssid, &channel, &state);
- ev.data.connected_result = calloc(1, sizeof(mesh_connected_event_s));
- RETM_IF(NULL == ev.data.connected_result, "Failed to memory allocation !");
- ev.data.connected_result->result = __convert_service_error_type(result);
+ ev.data.connection_state = calloc(1, sizeof(mesh_connection_state_event_s));
+ RETM_IF(NULL == ev.data.connection_state, "Failed to memory allocation !");
- h->event_handler(MESH_CONNECTED_EVENT, &ev);
- free(ev.data.connected_result);
+ 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->state = (mesh_connection_state_e)state;
+
+ h->event_handler(MESH_CONNECTION_STATE_EVENT, &ev);
+ free(ev.data.connection_state);
} else if (0 == g_strcmp0(signal_name, "sta_joined")) {
char *bssid = NULL;
mesh_event_data_s ev;
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);
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);
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,
- "joined_network", MESH_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL);
- if (0 == id) {
- LOGE("g_dbus_connection_signal_subscribe(joined_network) Fail(%d)", errno);
- return;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
- LOGD("subscribed for joined_network signal %d", id);
-
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME,
- "left_network", MESH_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _mesh_signal_handler, h, NULL);
- if (0 == id) {
- LOGE("g_dbus_connection_signal_subscribe(left_network) Fail(%d)", errno);
- return;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
- LOGD("subscribed for left_network signal %d", id);
-
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, MESH_SERVER_NAME,
- "mesh_connected", MESH_OBJECT_PATH, NULL,
+ "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(mesh_connected) Fail(%d)", errno);
+ 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 mesh_connected signal %d", 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);
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);
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;
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);
char *meshid = NULL;
char *bssid = NULL;
int channel = -1;
+ int state = 0;
int svc_result = 0;
- g_variant_get(variant, "(ssii)", &meshid, &bssid, &channel, &svc_result);
+ g_variant_get(variant, "(ssiii)", &meshid, &bssid, &channel, &state, &svc_result);
LOGD("get_joined_mesh_network status 0x%x", svc_result);
result = __convert_service_error_type(svc_result);
g_joined_network.rssi = -1;
g_joined_network.data_rate = 0;
g_joined_network.security = 0;
+ g_joined_network.state = MESH_CONNECTION_STATE_DISCONNECTED;
if (SERVICE_ERROR_NO_DATA == svc_result) {
*_network = NULL;
}
g_joined_network.channel = channel;
g_joined_network.rssi = -1;
+ g_joined_network.state = state;
*_network = &g_joined_network;
} else if (error) {
/* CHECK: List all enum values here */
CASE_TO_STR(MESH_MESH_ENABLED_EVENT)
CASE_TO_STR(MESH_SCAN_DONE_EVENT)
- CASE_TO_STR(MESH_JOIN_NETWORK_EVENT)
- CASE_TO_STR(MESH_LEFT_NETWORK_EVENT)
+ CASE_TO_STR(MESH_CONNECTION_STATE_EVENT)
CASE_TO_STR(MESH_STATION_JOIN_EVENT)
CASE_TO_STR(MESH_STATION_LEFT_EVENT)
- CASE_TO_STR(MESH_CONNECTED_EVENT)
default :
return "MESH_EVENT_UNKNOWN";
}
}
+const char* _mesh_connection_event_to_string(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)
+ default :
+ return "Unknown state";
+ }
+}
+
void event_cb(mesh_event_e event_type, mesh_event_data_s* event)
{
msg("");
case MESH_SCAN_DONE_EVENT: {
msgp(" Mesh Scan Done");
} break;
- case MESH_JOIN_NETWORK_EVENT:{
- msgp(" Joined Network");
- } break;
- case MESH_LEFT_NETWORK_EVENT: {
- msgp(" Left Current Network");
+ 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]",
+ event->data.connection_state->mesh_id,
+ event->data.connection_state->bssid,
+ event->data.connection_state->channel);
} break;
case MESH_STATION_JOIN_EVENT: {
msgp(" New Station Joined = %s", event->data.sta_info->bssid);
case MESH_STATION_LEFT_EVENT: {
msgp(" A Station Left = %s", event->data.sta_info->bssid);
} break;
- case MESH_CONNECTED_EVENT: {
- msgp(" Connection sequence finished [%s]",
- mesh_error_to_string(event->data.connected_result->result));
- } break;
+ default:
+ msgr(" Unexpected event !");
+ break;
}
}