Android限制AP最大连接数

背景

  • Platform: RK3399
  • OS: Android7.1.2
  • Kernel: v4.4.103

在项目中,因使用的WIFI模块的性能限制,在作为AP热点时候不能带很多台station,所以需要限制AP最大连接数。

解决

热点配置文件/data/misc/wifi/hostapd.conf里面带上max_num_sta参数限制最大连接数,但Android原生代码不包含此参数, 该文件最终是由/system/netd/server/SoftapController.cpp生成。

  • Android7.1路径(Android O会有所不同):
    /system/netd/server/SoftapController.cpp

添加头文件:

1
#include <cutils/properties.h> //环境变量操作头文件

添加处理代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//start add for sta limit 20200817,
int max_num_sta = 0; //0为不限制
char buf[PROPERTY_VALUE_MAX] = {'\0',};
if (property_get("sys.softap.limit", buf, "0")) {
max_num_sta = atoi(buf);
if(max_num_sta != 0) {
if(max_num_sta < 0 || max_num_sta > 255)
max_num_sta = 0;
}
}

std::string wbuf;
if(max_num_sta) {
std::string wbuf_tmp(StringPrintf("interface=%s\n"
"driver=nl80211\n"
"ctrl_interface=/data/misc/wifi/hostapd\n"
"ssid=%s\n"
"channel=%d\n"
"ieee80211n=1\n"
"hw_mode=%c\n"
"ignore_broadcast_ssid=%d\n"
"wowlan_triggers=any\n"
"max_num_sta=%d\n",
argv[2], argv[3], channel, (channel <= 14) ? 'g' : 'a', hidden, max_num_sta));
wbuf = wbuf_tmp;
}
else {
std::string wbuf_tmp(StringPrintf("interface=%s\n"
"driver=nl80211\n"
"ctrl_interface=/data/misc/wifi/hostapd\n"
"ssid=%s\n"
"channel=%d\n"
"ieee80211n=1\n"
"hw_mode=%c\n"
"ignore_broadcast_ssid=%d\n"
"wowlan_triggers=any\n",
argv[2], argv[3], channel, (channel <= 14) ? 'g' : 'a', hidden));
wbuf = wbuf_tmp;
}
//end add for sta limit 20200817,zdd

在系统环境变量中(system.prop)添加:

1
sys.softap.limit=3

参考

https://blog.csdn.net/laoguanhua/article/details/82810386

Donate comment here