mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-23 07:00:07 +00:00
!481 softap cannot connected by stations
Merge pull request !481 from fenis_2001/submit_br
This commit is contained in:
commit
fda290204c
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user