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;
}
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐