* limitations under the License.
*/
+#define _GNU_SOURCE
+#include <pthread.h>
#include <glib.h>
#include <ctype.h>
#include <stdio.h>
static bool wifi_is_feature_checked[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
static bool wifi_feature_supported[WIFI_SUPPORTED_FEATURE_MAX] = {0, };
+static pthread_mutex_t g_wifi_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+
//LCOV_EXCL_START
static wifi_manager_error_e __convert_to_ap_error_type(net_err_e err_type)
{
static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
{
+ WIFI_LOCK;
bool is_requested = false;
net_profile_info_s *prof_info_p = NULL;
wifi_manager_error_e result = WIFI_MANAGER_ERROR_NONE;
wifi_manager_handle_s *wifi_handle = user_data;
+ if (!__wifi_check_handle_validity(wifi_handle)) {
+ WIFI_LOG(WIFI_ERROR, "Wifi handle is not initialized");
+ WIFI_UNLOCK;
+ return;
+ }
+
switch (event_cb->Event) {
case NET_EVENT_OPEN_RSP:
case NET_EVENT_WIFI_WPS_RSP:
(event_cb->Error !=
NET_ERR_CONNECTION_WPS_OVERLAP) &&
(event_cb->Error !=
- NET_ERR_CONNECTION_WPS_WEP_PROHIBITED))
+ NET_ERR_CONNECTION_WPS_WEP_PROHIBITED)) {
+ WIFI_UNLOCK;
return;
+ }
result = __convert_to_ap_error_type(event_cb->Error);
WIFI_LOG(WIFI_INFO, "Connection open error %s",
__state_changed_cb(wifi_handle, event_cb->ProfileName, prof_info_p,
WIFI_MANAGER_CONNECTION_STATE_CONNECTED);
+ WIFI_UNLOCK;
return;
case NET_ERR_ACTIVE_CONNECTION_EXISTS:
+ WIFI_UNLOCK;
return;
default:
if (event_cb->Datalength == sizeof(net_profile_info_s))
is_requested = true;
/* fall through */
case NET_EVENT_CLOSE_IND:
- if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true)
+ if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
+ WIFI_UNLOCK;
return;
+ }
result = __convert_to_ap_error_type(event_cb->Error);
WIFI_LOG(WIFI_ERROR, "Connection close error %s",
wifi_handle->is_disconnect_wps_pin = false;
}
+ WIFI_UNLOCK;
return;
default:
break;
break;
case NET_EVENT_NET_STATE_IND:
- if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true)
+ if (_wifi_check_profile_name_validity(event_cb->ProfileName) != true) {
+ WIFI_UNLOCK;
return;
+ }
- if (event_cb->Datalength != sizeof(net_profile_info_s))
+ if (event_cb->Datalength != sizeof(net_profile_info_s)) {
+ WIFI_UNLOCK;
return;
+ }
prof_info_p = (net_profile_info_s *)event_cb->Data;
net_state_type_e profile_state = prof_info_p->ProfileState;
default:
break;
}
+
+ WIFI_UNLOCK;
}
int _wifi_init(wifi_manager_h wifi, const char *ifname)
return __convert_net_err_to_wifi_dpp_error(rv);
}
//LCOV_EXCL_STOP
+
+void _wifi_lock(void)
+{
+ pthread_mutex_lock(&g_wifi_thread_mutex);
+}
+
+void _wifi_unlock(void)
+{
+ pthread_mutex_unlock(&g_wifi_thread_mutex);
+}
return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
+ WIFI_LOCK;
+
if (__wifi_check_handle_validity(*wifi)) {
WIFI_LOG(WIFI_ERROR, "Already initialized"); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_ALREADY_INITIALIZED; //LCOV_EXCL_LINE
}
rv = _wifi_create_handle(wifi);
if (rv != WIFI_MANAGER_ERROR_NONE) {
WIFI_LOG(WIFI_ERROR, "Init failed[%d]", rv); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
_wifi_deinit(*wifi); //LCOV_EXCL_LINE
_wifi_destroy_handle(wifi); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
} else if (rv != NET_ERR_NONE) {
WIFI_LOG(WIFI_ERROR, "Init failed[%d]", rv); //LCOV_EXCL_LINE
_wifi_deinit(*wifi); //LCOV_EXCL_LINE
_wifi_destroy_handle(wifi); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
}
_wifi_add_to_handle_list(wifi);
WIFI_LOG(WIFI_INFO, "Wi-Fi successfully initialized");
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__;
return WIFI_MANAGER_ERROR_NONE;
}
return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
+ WIFI_LOCK;
+
if (__wifi_check_handle_validity(*wifi)) {
WIFI_LOG(WIFI_ERROR, "Already initialized"); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_ALREADY_INITIALIZED; //LCOV_EXCL_LINE
}
rv = _wifi_create_handle(wifi);
if (rv != WIFI_MANAGER_ERROR_NONE) {
WIFI_LOG(WIFI_ERROR, "Init failed[%d]", rv); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
_wifi_deinit(*wifi); //LCOV_EXCL_LINE
_wifi_destroy_handle(wifi); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
} else if (rv != NET_ERR_NONE) {
WIFI_LOG(WIFI_ERROR, "Init failed[%d]", rv); //LCOV_EXCL_LINE
_wifi_deinit(*wifi); //LCOV_EXCL_LINE
_wifi_destroy_handle(wifi); //LCOV_EXCL_LINE
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
}
_wifi_add_to_handle_list(wifi);
WIFI_LOG(WIFI_INFO, "Wi-Fi successfully initialized with interface name [%s]", ifname);
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__;
return WIFI_MANAGER_ERROR_NONE;
}
CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
- RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__);
+ WIFI_LOCK;
+ RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi,
+ WIFI_UNLOCK;\
+ __NETWORK_CAPI_FUNC_EXIT__);
wifi_manager_unset_rssi_level_changed_cb(wifi);
WIFI_LOG(WIFI_INFO, "Wi-Fi successfully de-initialized");
+ WIFI_UNLOCK;
__NETWORK_CAPI_FUNC_EXIT__;
return WIFI_MANAGER_ERROR_NONE;
}
int rv;
rv = wifi_manager_initialize(wifi);
- if (rv == WIFI_MANAGER_ERROR_NONE)
+ if (rv == WIFI_MANAGER_ERROR_NONE) {
+ WIFI_LOCK;
_wifi_set_cs_tid(*wifi, tid);
+ WIFI_UNLOCK;
+ }
__NETWORK_CAPI_FUNC_EXIT__;
return rv;
int rv;
+ WIFI_LOCK;
_wifi_unset_cs_tid(tid);
+ WIFI_UNLOCK;
+
rv = wifi_manager_deinitialize(wifi);
__NETWORK_CAPI_FUNC_EXIT__;