hostapd: adjust patches to work with git am
[openwrt/staging/xback.git] / package / network / services / hostapd / patches / 720-iface_max_num_sta.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 26 May 2021 14:34:46 +0200
3 Subject: [PATCH] hostapd: add support for specifying the maxassoc parameter as
4 a device option
5
6 It allows enforcing a limit on associated stations to be enforced for the
7 full device, e.g. in order to deal with hardware/driver limitations
8
9 --- a/hostapd/config_file.c
10 +++ b/hostapd/config_file.c
11 @@ -3041,6 +3041,14 @@ static int hostapd_config_fill(struct ho
12 line, bss->max_num_sta, MAX_STA_COUNT);
13 return 1;
14 }
15 + } else if (os_strcmp(buf, "iface_max_num_sta") == 0) {
16 + conf->max_num_sta = atoi(pos);
17 + if (conf->max_num_sta < 0 ||
18 + conf->max_num_sta > MAX_STA_COUNT) {
19 + wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
20 + line, conf->max_num_sta, MAX_STA_COUNT);
21 + return 1;
22 + }
23 } else if (os_strcmp(buf, "wpa") == 0) {
24 bss->wpa = atoi(pos);
25 } else if (os_strcmp(buf, "extended_key_id") == 0) {
26 --- a/src/ap/ap_config.h
27 +++ b/src/ap/ap_config.h
28 @@ -1057,6 +1057,8 @@ struct hostapd_config {
29 unsigned int track_sta_max_num;
30 unsigned int track_sta_max_age;
31
32 + int max_num_sta;
33 +
34 char country[3]; /* first two octets: country code as described in
35 * ISO/IEC 3166-1. Third octet:
36 * ' ' (ascii 32): all environments
37 --- a/src/ap/beacon.c
38 +++ b/src/ap/beacon.c
39 @@ -1567,7 +1567,7 @@ void handle_probe_req(struct hostapd_dat
40 if (hapd->conf->no_probe_resp_if_max_sta &&
41 is_multicast_ether_addr(mgmt->da) &&
42 is_multicast_ether_addr(mgmt->bssid) &&
43 - hapd->num_sta >= hapd->conf->max_num_sta &&
44 + hostapd_check_max_sta(hapd) &&
45 !ap_get_sta(hapd, mgmt->sa)) {
46 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
47 " since no room for additional STA",
48 --- a/src/ap/hostapd.c
49 +++ b/src/ap/hostapd.c
50 @@ -247,6 +247,29 @@ static int hostapd_iface_conf_changed(st
51 return 0;
52 }
53
54 +static inline int hostapd_iface_num_sta(struct hostapd_iface *iface)
55 +{
56 + int num_sta = 0;
57 + int i;
58 +
59 + for (i = 0; i < iface->num_bss; i++)
60 + num_sta += iface->bss[i]->num_sta;
61 +
62 + return num_sta;
63 +}
64 +
65 +
66 +int hostapd_check_max_sta(struct hostapd_data *hapd)
67 +{
68 + if (hapd->num_sta >= hapd->conf->max_num_sta)
69 + return 1;
70 +
71 + if (hapd->iconf->max_num_sta &&
72 + hostapd_iface_num_sta(hapd->iface) >= hapd->iconf->max_num_sta)
73 + return 1;
74 +
75 + return 0;
76 +}
77
78 int hostapd_reload_config(struct hostapd_iface *iface)
79 {
80 --- a/src/ap/hostapd.h
81 +++ b/src/ap/hostapd.h
82 @@ -754,6 +754,7 @@ void hostapd_cleanup_cs_params(struct ho
83 void hostapd_periodic_iface(struct hostapd_iface *iface);
84 int hostapd_owe_trans_get_info(struct hostapd_data *hapd);
85 void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx);
86 +int hostapd_check_max_sta(struct hostapd_data *hapd);
87
88 void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap);
89 void hostapd_cleanup_cca_params(struct hostapd_data *hapd);