typedef enum {
NO_AP,
HAVE_AP_NO_STA,
HAVE_AP_HAVE_STA,
}wifi_t;
int getwifi_status(void)
{
#define WIFI_FLAG_STR "sta's macaddr:"
char buf[64] = {0};
int n = 0;
FILE *m_pStream = NULL;
if (NULL == m_pStream) {
m_pStream = fopen("/proc/net/rtl8812au/wlan0/all_sta_info", "r");
return NO_AP;
}
if (fseek(m_pStream, 0, SEEK_SET) < 0) {
if (m_pStream) {
fclose(m_pStream);
m_pStream = NULL;
}
return NO_AP;
}
while (NULL != (fgets(buf, 64, m_pStream))) {
if (!strncmp(buf, WIFI_FLAG_STR, strlen(WIFI_FLAG_STR))) {
n++;
}
}
/*
count = 0,1,no device
count = 2,found wifi,no conect
count >=3,sta num = (count-2)
*/
if (n <= 1) {
return NO_AP;
}
if (2 == n) {
return HAVE_AP_NO_STA;
}
return HAVE_AP_HAVE_STA;
}
linux 检查设备wifi连接的状态
最新推荐文章于 2024-08-18 19:36:19 发布