110-notify-mgmt-frames.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. From 53f8fdb534d5222a0e852e38afde3f49832ace06 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <[email protected]>
  3. Date: Thu, 26 Nov 2020 09:27:40 +0100
  4. Subject: [PATCH] hostapd: Add an option to notify management frames on
  5. ctrl_iface
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. In some contexts (e.g. Multi-AP) it can be useful to have access to
  10. some of the management frames in upper layers (e.g. to be able to
  11. process the content of association requests externally).
  12. Add 'notify_mgmt_frames'. When enabled, it will notify the ctrl_iface
  13. when a management frame arrives using 'AP_MGMT_FRAME_RECEIVED'.
  14. Note that to avoid completely flooding the ctrl_iface, not all
  15. management frames are included (e.g. beacons are excluded).
  16. Signed-off-by: Raphaël Mélotte <[email protected]>
  17. ---
  18. hostapd/config_file.c | 2 ++
  19. hostapd/hostapd.conf | 4 ++++
  20. src/ap/ap_config.h | 2 ++
  21. src/ap/ieee802_11.c | 25 +++++++++++++++++++++++++
  22. src/common/wpa_ctrl.h | 3 +++
  23. 5 files changed, 36 insertions(+)
  24. diff --git a/hostapd/config_file.c b/hostapd/config_file.c
  25. index e09e6e141..6b88ecd17 100644
  26. --- a/hostapd/config_file.c
  27. +++ b/hostapd/config_file.c
  28. @@ -4323,6 +4323,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
  29. bss->multicast_to_unicast = atoi(pos);
  30. } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
  31. bss->broadcast_deauth = atoi(pos);
  32. + } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
  33. + conf->notify_mgmt_frames = atoi(pos);
  34. #ifdef CONFIG_DPP
  35. } else if (os_strcmp(buf, "dpp_connector") == 0) {
  36. os_free(bss->dpp_connector);
  37. diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
  38. index ce3ecdddf..28dcd4f57 100644
  39. --- a/hostapd/hostapd.conf
  40. +++ b/hostapd/hostapd.conf
  41. @@ -550,6 +550,10 @@ wmm_ac_vo_acm=0
  42. # Default: 1 (enabled)
  43. #broadcast_deauth=1
  44. +# Get notifications for management frames:
  45. +# Default: 0 (disabled)
  46. +#notify_mgmt_frames=0
  47. +
  48. ##### IEEE 802.11n related configuration ######################################
  49. # ieee80211n: Whether IEEE 802.11n (HT) is enabled
  50. diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
  51. index ea581a822..2f89d6ab9 100644
  52. --- a/src/ap/ap_config.h
  53. +++ b/src/ap/ap_config.h
  54. @@ -1008,6 +1008,8 @@ struct hostapd_config {
  55. unsigned int airtime_update_interval;
  56. #define AIRTIME_MODE_MAX (__AIRTIME_MODE_MAX - 1)
  57. #endif /* CONFIG_AIRTIME_POLICY */
  58. +
  59. + u8 notify_mgmt_frames;
  60. };
  61. diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
  62. index c85a28db4..fc1291024 100644
  63. --- a/src/ap/ieee802_11.c
  64. +++ b/src/ap/ieee802_11.c
  65. @@ -4591,6 +4591,28 @@ static int handle_action(struct hostapd_data *hapd,
  66. return 1;
  67. }
  68. +/**
  69. + * notify_mgmt_frame - notify of management frames on the control interface.
  70. + * @hapd: hostapd BSS data structure (the BSS to which the management frame was
  71. + * sent to)
  72. + * @buf: management frame data (starting from IEEE 802.11 header)
  73. + * @len: length of frame data in octets
  74. + *
  75. + * Notify the control interface of any management frame.
  76. + */
  77. +static void notify_mgmt_frame(struct hostapd_data *hapd, const u8 *buf,
  78. + size_t len)
  79. +{
  80. +
  81. + int hex_len = len * 2 + 1;
  82. + char *hex = os_malloc(hex_len);
  83. +
  84. + if (hex) {
  85. + wpa_snprintf_hex(hex, hex_len, buf, len);
  86. + wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, AP_MGMT_FRAME_RECEIVED "buf=%s", hex);
  87. + os_free(hex);
  88. + }
  89. +}
  90. /**
  91. * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
  92. @@ -4665,6 +4687,9 @@ int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
  93. if (hapd->iconf->track_sta_max_num)
  94. sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
  95. + if (hapd->iconf->notify_mgmt_frames)
  96. + notify_mgmt_frame(hapd, buf, len);
  97. +
  98. switch (stype) {
  99. case WLAN_FC_STYPE_AUTH:
  100. wpa_printf(MSG_DEBUG, "mgmt::auth");
  101. diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h
  102. index b24ae63e5..eeff9fcaa 100644
  103. --- a/src/common/wpa_ctrl.h
  104. +++ b/src/common/wpa_ctrl.h
  105. @@ -375,6 +375,9 @@ extern "C" {
  106. #define WDS_STA_INTERFACE_ADDED "WDS-STA-INTERFACE-ADDED "
  107. #define WDS_STA_INTERFACE_REMOVED "WDS-STA-INTERFACE-REMOVED "
  108. +/* Event triggered for received management frame */
  109. +#define AP_MGMT_FRAME_RECEIVED "AP-MGMT-FRAME-RECEIVED "
  110. +
  111. /* BSS command information masks */
  112. #define WPA_BSS_MASK_ALL 0xFFFDFFFF
  113. --
  114. 2.28.0