720-iface_max_num_sta.patch 2.8 KB

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