From b361236f33a6b1b6761751f20b028f87383d8ad8 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Thu, 18 Oct 2018 15:55:21 +0900 Subject: [PATCH] Added unexpected state transition handling Change-Id: I15dcd0876b6785d997fe1e90a72f9e6795241211 Signed-off-by: Jaehyun Kim --- src/network_signal.c | 169 ++++++++++++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 83 deletions(-) diff --git a/src/network_signal.c b/src/network_signal.c index f7c67a3..51b71be 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -631,6 +631,85 @@ static void __net_handle_failure_ind(const char *profile_name) __NETWORK_FUNC_EXIT__; } +static void __net_handle_disconnect_ind(const char *profile_name) +{ + __NETWORK_FUNC_ENTER__; + + net_event_info_s event_data = { 0, }; + + const char *svc_name1 = + request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName; + const char *svc_name2 = + request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName; + const char *svc_name3 = + request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName; + + if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE && + strstr(profile_name, svc_name2) != NULL) { + memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION], 0, + sizeof(network_request_table_s)); + + /** Send Open Resp */ + event_data.Error = NET_ERR_OPERATION_ABORTED; + event_data.Event = NET_EVENT_OPEN_RSP; + g_strlcpy(event_data.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX+1); + + WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_OPEN_RSP"); + + _net_dbus_pending_call_unref(); + + _net_client_callback(&event_data); + goto out; + } + + if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE && + g_strcmp0(profile_name, svc_name3) == 0) { + memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS], 0, + sizeof(network_request_table_s)); + + /** Send WPS Resp */ + event_data.Error = NET_ERR_OPERATION_ABORTED; + event_data.Event = NET_EVENT_WIFI_WPS_RSP; + g_strlcpy(event_data.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX+1); + + WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_WIFI_WPS_RSP"); + _net_dbus_pending_call_unref(); + + _net_client_callback(&event_data); + goto out; + } + + if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE && + g_strcmp0(profile_name, svc_name1) == 0) { + memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0, + sizeof(network_request_table_s)); + + /** Send Close Resp */ + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_CLOSE_RSP; + g_strlcpy(event_data.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX+1); + + WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_CLOSE_RSP"); + + _net_dbus_pending_call_unref(); + + _net_client_callback(&event_data); + goto out; + } + + /** Send Close Ind */ + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_CLOSE_IND; + g_strlcpy(event_data.ProfileName, profile_name, NET_PROFILE_NAME_LEN_MAX+1); + + WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_CLOSE_IND"); + + _net_client_callback(&event_data); + net_forget_ap_finshed(NET_ERR_NONE); +out: + __NETWORK_FUNC_EXIT__; +} + static int __net_handle_service_state_changed(const gchar *sig_path, const char *key, const char *state) { @@ -663,8 +742,13 @@ static int __net_handle_service_state_changed(const gchar *sig_path, case NET_STATE_TYPE_IDLE: if (NetworkInfo.wifi_state == WIFI_CONNECTED) NetworkInfo.wifi_state = WIFI_ON; - if (old_state == NET_STATE_TYPE_DISCONNECT) + if (old_state == NET_STATE_TYPE_DISCONNECT) { + break; + } else if (old_state != NET_STATE_TYPE_FAILURE) { + __net_handle_disconnect_ind(sig_path); break; + } + case NET_STATE_TYPE_ASSOCIATION: case NET_STATE_TYPE_CONFIGURATION: __net_handle_state_ind(sig_path, new_state); @@ -730,88 +814,7 @@ static int __net_handle_service_state_changed(const gchar *sig_path, } case NET_STATE_TYPE_DISCONNECT: { - const char *svc_name1 = - request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName; - const char *svc_name2 = - request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName; - const char *svc_name3 = - request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName; - - if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE && - strstr(sig_path, svc_name2) != NULL) { - memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION], 0, - sizeof(network_request_table_s)); - - /** Send Open Resp */ - event_data.Error = NET_ERR_OPERATION_ABORTED; - event_data.Event = NET_EVENT_OPEN_RSP; - g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1); - - event_data.Datalength = 0; - event_data.Data = NULL; - - WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_OPEN_RSP"); - - _net_dbus_pending_call_unref(); - - _net_client_callback(&event_data); - break; - } - - if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE && - g_strcmp0(sig_path, svc_name3) == 0) { - memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS], 0, - sizeof(network_request_table_s)); - - /** Send WPS Resp */ - event_data.Error = NET_ERR_OPERATION_ABORTED; - event_data.Event = NET_EVENT_WIFI_WPS_RSP; - g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1); - - event_data.Datalength = 0; - event_data.Data = NULL; - - WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_WIFI_WPS_RSP"); - _net_dbus_pending_call_unref(); - - _net_client_callback(&event_data); - break; - } - - if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE && - g_strcmp0(sig_path, svc_name1) == 0) { - memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0, - sizeof(network_request_table_s)); - - /** Send Close Resp */ - event_data.Error = Error; - event_data.Event = NET_EVENT_CLOSE_RSP; - g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1); - - event_data.Datalength = 0; - event_data.Data = NULL; - - WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_CLOSE_RSP"); - - _net_dbus_pending_call_unref(); - - _net_client_callback(&event_data); - break; - } - - /** Send Close Ind */ - event_data.Error = Error; - event_data.Event = NET_EVENT_CLOSE_IND; - g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1); - - event_data.Datalength = 0; - event_data.Data = NULL; - - WIFI_LOG(WIFI_INFO, "Sending NET_EVENT_CLOSE_IND"); - - _net_client_callback(&event_data); - net_forget_ap_finshed(NET_ERR_NONE); - + __net_handle_disconnect_ind(sig_path); break; } case NET_STATE_TYPE_FAILURE: -- 2.7.4