!481 softap cannot connected by stations

Merge pull request !481 from fenis_2001/submit_br
This commit is contained in:
openharmony_ci 2022-07-18 10:41:24 +00:00 committed by Gitee
commit fda290204c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 50 additions and 8 deletions

View File

@ -80,6 +80,7 @@ if (defined(ohos_lite)) {
cflags_cc = [ "-fno-rtti" ]
defines = [
"_GNU_SOURCE",
"OHOS_ARCH_LITE",
"AP_INTF=\"$wifi_feature_with_ap_intf\"",
"AP_NUM=$wifi_feature_with_ap_num",

View File

@ -14,9 +14,14 @@
*/
#include "wifi_hal_common_func.h"
#include <net/if.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include "securec.h"
#include "wifi_log.h"
#define MAC_UINT_SIZE 6
#define MAC_STRING_SIZE 17
@ -122,3 +127,29 @@ int CheckMacIsValid(const char *macStr)
}
return 0;
}
int GetIfaceState(const char *ifaceName)
{
int state = 0;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
LOGE("GetIfaceState: create socket fail");
return state;
}
struct ifreq ifr;
(void)memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr));
if (strcpy_s(ifr.ifr_name, IFNAMSIZ, ifaceName) != EOK) {
LOGE("GetIfaceState: strcpy_s fail");
close(sock);
return state;
}
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
LOGE("GetIfaceState: can not get interface state: %{public}s", ifaceName);
close(sock);
return state;
}
state = ((ifr.ifr_flags & IFF_UP) > 0 ? 1 : 0);
LOGD("GetIfaceState: current interface state: %{public}d", state);
return state;
}

View File

@ -58,7 +58,14 @@ int ConvertMacToArray(const char *macStr, unsigned char *mac, int macSize);
*/
int CheckMacIsValid(const char *macStr);
/**
* @Description Get the state of interface
* @param ifaceName - the name of interface
* @return int - 0: down 1: up
*/
int GetIfaceState(const char *ifaceName);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -56,11 +56,12 @@ WifiErrorNo StartSoftAp(int id)
LOGE("hostapdHalDevice is NULL!");
return WIFI_HAL_HOSTAPD_NOT_INIT;
}
int ret = hostapdHalDevice->enableAp(id);
if (ret != 0) {
LOGE("enableAp failed! ret=%{public}d", ret);
return WIFI_HAL_FAILED;
if (GetIfaceState(AP_INTF) == 0 || id > 0) {
int ret = hostapdHalDevice->enableAp(id);
if (ret != 0) {
LOGE("enableAp failed! ret=%{public}d", ret);
return WIFI_HAL_FAILED;
}
}
LOGI("AP start successfully, id:%{public}d!", id);
@ -380,4 +381,4 @@ WifiErrorNo WifiGetPowerModel(int* mode, int id)
HdiReleaseAp(wifi, apFeature);
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
#endif
}
}

View File

@ -113,12 +113,14 @@ static void DelCallbackMessage(const char *msg, int id)
static void *HostapdReceiveCallback(void *arg)
{
if (arg == NULL) {
LOGE("%{public}s arg is null", __func__);
return NULL;
}
WifiHostapdHalDeviceInfo *halDeviceInfo = arg;
int id = halDeviceInfo->id;
if (halDeviceInfo->hostapdHalDev == NULL ||
halDeviceInfo->hostapdHalDev->ctrlRecv) {
halDeviceInfo->hostapdHalDev->ctrlRecv == NULL) {
LOGE("%{public}s invalid HalDev or ctrlRecv", __func__);
return NULL;
}
struct wpa_ctrl *ctrl = halDeviceInfo->hostapdHalDev->ctrlRecv;