blob: 14571fe9a3816546449527f1f14cef1c5903fa84 [file] [log] [blame]
developere2cc0fa2022-03-29 17:31:03 +08001From 6fc069a54efb892e486dfde59cb97e0023dbbf5d Mon Sep 17 00:00:00 2001
2From: "howard.hsu" <howard-yh.hsu@mediatek.com>
3Date: Wed, 19 Jan 2022 21:27:55 +0800
4Subject: [PATCH 8/9] Add hostapd_neighbor_set_own_report_pref()
5
6If my own BSS is going to terminate itself, the preference value of neighbor
7report must be set to 0.
8---
9 hostapd/ctrl_iface.c | 5 ++++-
10 src/ap/neighbor_db.c | 36 ++++++++++++++++++++++++++++++++++++
11 src/ap/neighbor_db.h | 2 ++
12 3 files changed, 42 insertions(+), 1 deletion(-)
13
14diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
15index 5a82ae6..3146a25 100644
16--- a/hostapd/ctrl_iface.c
17+++ b/hostapd/ctrl_iface.c
18@@ -993,8 +993,11 @@ static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data *hapd,
19 }
20 if (os_strstr(cmd, " abridged=1"))
21 req_mode |= WNM_BSS_TM_REQ_ABRIDGED;
22- if (os_strstr(cmd, " disassoc_imminent=1"))
23+ if (os_strstr(cmd, " disassoc_imminent=1")) {
24 req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
25+ /* Set own BSS neighbor report preference value as 0 */
26+ hostapd_neighbor_set_own_report_pref(hapd, nei_rep, nei_len, 0);
27+ }
28
29 #ifdef CONFIG_MBO
30 pos = os_strstr(cmd, "mbo=");
31diff --git a/src/ap/neighbor_db.c b/src/ap/neighbor_db.c
32index ce6865d..bc1b163 100644
33--- a/src/ap/neighbor_db.c
34+++ b/src/ap/neighbor_db.c
35@@ -352,3 +352,39 @@ void hostapd_neighbor_set_own_report(struct hostapd_data *hapd)
36 wpabuf_free(nr);
37 #endif /* NEED_AP_MLME */
38 }
39+
40+
41+void hostapd_neighbor_set_own_report_pref(struct hostapd_data *hapd, char *nei_buf,
42+ size_t buflen, const int pref)
43+{
44+ struct hostapd_neighbor_entry *nr;
45+ char *pos, *next_nr;
46+
47+ pos = nei_buf;
48+ next_nr = nei_buf;
49+
50+ dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry,
51+ list) {
52+ pos = next_nr;
53+ next_nr = pos + 2 + wpabuf_len(nr->nr);
54+ /* Shift 2 bytes for Element ID and Neighbor report length */
55+ pos = pos + 2;
56+ if(os_memcmp(pos, hapd->own_addr, ETH_ALEN) == 0) {
57+ /* Shift for BSSID + BSSID info + Op_class + channel num + PHY type */
58+ pos = pos + 6 + 4 + 1 + 1 + 1;
59+
60+ /* Iterate Subelement */
61+ while (next_nr - pos > 0) {
62+ if (*pos == 3) {
63+ pos = pos + 2;
64+ *pos = pref;
65+ return;
66+ } else {
67+ pos++;
68+ int shift_len = *pos++;
69+ pos = pos + shift_len;
70+ }
71+ }
72+ }
73+ }
74+}
75diff --git a/src/ap/neighbor_db.h b/src/ap/neighbor_db.h
76index 1ae194d..2e16f72 100644
77--- a/src/ap/neighbor_db.h
78+++ b/src/ap/neighbor_db.h
79@@ -27,4 +27,6 @@ void hostapd_free_neighbor_db(struct hostapd_data *hapd);
80 int hostapd_neighbor_count(struct hostapd_data *hapd);
81 int hostapd_neighbor_insert_buffer(struct hostapd_data *hapd, char *buf,
82 size_t buflen);
83+void hostapd_neighbor_set_own_report_pref(struct hostapd_data *hapd, char *nei_buf,
84+ size_t buflen, const int pref);
85 #endif /* NEIGHBOR_DB_H */
86--
872.18.0
88