打开wpa开关

Signed-off-by: likuanxin <likuanxin@huawei.com>
This commit is contained in:
likuanxin 2023-12-29 16:06:46 +08:00
parent 446b8a769b
commit 367270edb0
5 changed files with 38 additions and 18 deletions

View File

@ -40,16 +40,19 @@ static pthread_mutex_t g_wpaObjMutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned int g_wpaRefCount = 0;
static struct IWpaInterface *g_wpaObj = NULL;
static struct HDIDeviceManager *g_devMgr = NULL;
static unsigned int g_wpaStubProcessDeath = 29189;
WifiErrorNo HdiWpaStart()
{
LOGI("HdiWpaStart start...");
pthread_mutex_lock(&g_wpaObjMutex);
if (g_wpaRefCount != 0) {
if (g_wpaRefCount != 0 && g_wpaObj != NULL && g_devMgr != NULL) {
++g_wpaRefCount;
pthread_mutex_unlock(&g_wpaObjMutex);
LOGI("%{public}s wpa ref count: %d", __func__, g_wpaRefCount);
LOGI("%{public}s wpa ref count: %{public}d", __func__, g_wpaRefCount);
return WIFI_IDL_OPT_OK;
} else {
g_wpaRefCount = 0;
}
g_devMgr = HDIDeviceManagerGet();
@ -143,6 +146,7 @@ WifiErrorNo HdiAddWpaIface(const char *ifName, const char *confName)
int32_t ret = g_wpaObj->AddWpaIface(g_wpaObj, ifName, confName);
if (ret != HDF_SUCCESS) {
LOGE("%{public}s AddWpaIface failed: %{public}d", __func__, ret);
HdiWpaResetGlobalObj(ret);
pthread_mutex_unlock(&g_wpaObjMutex);
return WIFI_IDL_OPT_FAILED;
}
@ -171,6 +175,7 @@ WifiErrorNo HdiRemoveWpaIface(const char *ifName)
int32_t ret = g_wpaObj->RemoveWpaIface(g_wpaObj, ifName);
if (ret != HDF_SUCCESS) {
LOGE("%{public}s RemoveWpaIface failed: %{public}d", __func__, ret);
HdiWpaResetGlobalObj(ret);
pthread_mutex_unlock(&g_wpaObjMutex);
return WIFI_IDL_OPT_FAILED;
}
@ -259,4 +264,15 @@ WifiErrorNo CopyConfigFile(const char* configName)
LOGE("Copy config file failed: %{public}s", configName);
return WIFI_IDL_OPT_FAILED;
}
void HdiWpaResetGlobalObj(int errorCode)
{
if (g_wpaStubProcessDeath == errorCode) {
g_wpaRefCount = 0;
g_wpaObj = NULL;
g_devMgr = NULL;
LOGE("%{public}s reset wpa g_wpaObj", __func__);
}
HdiWpaStart();
}
#endif

View File

@ -111,6 +111,8 @@ WifiErrorNo CopyUserFile(const char *srcFilePath, const char* destFilePath);
*/
WifiErrorNo CopyConfigFile(const char* configName);
void HdiWpaResetGlobalObj(int errorCode);
#ifdef __cplusplus
}
#endif

View File

@ -79,6 +79,7 @@ static WifiErrorNo RegisterEventCallback()
if (result != HDF_SUCCESS) {
pthread_mutex_unlock(&g_hdiCallbackMutex);
LOGE("RegisterEventCallback: RegisterEventCallback failed result:%{public}d", result);
HdiWpaResetGlobalObj(result);
return WIFI_IDL_OPT_FAILED;
}

View File

@ -93,6 +93,7 @@ int32_t OnEventStateChanged(struct IWpaCallback *self,
if (cbk.onWpaStateChanged) {
cbk.onWpaStateChanged(statechangedParam->status);
}
LOGI("OnEventStateChanged:callback out status = %{public}d",statechangedParam->status);
return 0;
}

View File

@ -48,38 +48,38 @@ WifiStaHalInterface &WifiStaHalInterface::GetInstance(void)
WifiErrorNo WifiStaHalInterface::StartWifi(void)
{
WifiErrorNo ret = WIFI_IDL_OPT_OK;
int32_t ret = WIFI_IDL_OPT_OK;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret = mHdiWpaClient->StartWifi();
ret |= mHdiWpaClient->StartWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret = mIdlClient->StartWifi();
ret |= mIdlClient->StartWifi();
#endif
#ifdef HDI_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiClient, WIFI_IDL_OPT_FAILED);
ret = mHdiClient->StartWifi();
ret |= mHdiClient->StartWifi();
#endif
return ret;
return (WifiErrorNo)ret;
}
WifiErrorNo WifiStaHalInterface::StopWifi(void)
{
WifiErrorNo ret = WIFI_IDL_OPT_OK;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret = mHdiWpaClient->StopWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret = mIdlClient->StopWifi();
#endif
int32_t ret = WIFI_IDL_OPT_OK;
#ifdef HDI_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiClient, WIFI_IDL_OPT_FAILED);
ret = mHdiClient->StopWifi();
ret |= mHdiClient->StopWifi();
#endif
return ret;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret |= mHdiWpaClient->StopWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret |= mIdlClient->StopWifi();
#endif
return (WifiErrorNo)ret;
}
WifiErrorNo WifiStaHalInterface::Connect(int networkId)