Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.

Commit 8ee55fd

Browse files
committed
prplmesh-hostapd: added disable_all_ap_vaps()
added functionality to disable all vaps that are access-points (as opposed to STA for example). the code mimics the existing functionality taken from ap_wlan_hal_dwpal.cpp. added funcvtionlity and unit test note: the example unit-test configuration file did not contain any vap with the mode= line, therefore it was added few of this. also: it was discovered that it is OK to look for non-exiting key within vap's configuration and the code was changed accordingly Signed-off-by: Ran Regev <ran.regev@devalore.com>
1 parent 06911ce commit 8ee55fd

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

common/beerocks/hostapd/configuration.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ std::string Configuration::get_vap_value(const std::string &vap, const std::stri
159159
if (existing_vap == m_hostapd_config_vaps.end()) {
160160
m_last_message = std::string(__FUNCTION__) + " couldn't find requested vap: " + vap +
161161
" (requested key: " + key + ")";
162+
// it is an error to ask for non existing vap
162163
m_ok = false;
163164
return "";
164165
}
@@ -173,7 +174,9 @@ std::string Configuration::get_vap_value(const std::string &vap, const std::stri
173174
if (it_str == existing_vap->second.end()) {
174175
m_last_message = std::string(__FUNCTION__) +
175176
" couldn't find requested key for vap: " + vap + "; requested key: " + key;
176-
m_ok = false;
177+
178+
// it ok not to find the requested key
179+
m_ok = true;
177180
return "";
178181
}
179182

@@ -182,6 +185,17 @@ std::string Configuration::get_vap_value(const std::string &vap, const std::stri
182185
return it_str->substr(key_eq.length());
183186
}
184187

188+
void Configuration::disable_all_ap_vaps() {
189+
for_each(
190+
m_hostapd_config_vaps.begin(),
191+
m_hostapd_config_vaps.end(),
192+
[this](const std::pair<std::string, std::vector<std::string>> &vap) {
193+
if ( get_vap_value(vap.first, "mode") == "ap" ) {
194+
set_create_vap_value(vap.first, "start_disabled", "1");
195+
}
196+
});
197+
}
198+
185199
const std::string &Configuration::get_last_message() const { return m_last_message; }
186200

187201
std::ostream &operator<<(std::ostream &o, const Configuration &conf)

common/beerocks/hostapd/include/configuration.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class Configuration {
8686
*/
8787
std::string get_vap_value(const std::string &vap, const std::string &key);
8888

89+
/**
90+
* @brief disable all ap vaps
91+
* @details disable all vaps that thier mode is "ap",
92+
* (leaving STAs vaps untouched for example)
93+
*/
94+
void disable_all_ap_vaps();
95+
8996
/**
9097
* @brief for debug: return the last internal message
9198
* @details each action on this class changes its internal

common/beerocks/hostapd/unit_tests/configuration_test.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,31 @@ TEST(configuration_test, get_vap_values)
152152
EXPECT_EQ(value, "") << conf;
153153

154154
//// end test ////
155+
}
156+
157+
158+
TEST(configuration_test, diable_all_ap)
159+
{
160+
//// start prerequsite ////
161+
162+
// construct a configuration
163+
prplmesh::hostapd::config::Configuration conf(configuration_file);
164+
ASSERT_FALSE(conf) << conf;
165+
166+
// load the dummy configuration file
167+
conf.load();
168+
ASSERT_TRUE(conf) << conf;
169+
170+
//// end prerequsite ////
155171

156-
// for humans
157-
std::cerr << "received value: " << value << '\n';
172+
//// start test ////
173+
174+
conf.disable_all_ap_vaps();
175+
EXPECT_TRUE(conf) << conf;
176+
177+
conf.store();
178+
EXPECT_TRUE(conf) << conf;
179+
180+
//// end test ////
158181
}
159182
} // namespace

common/beerocks/hostapd/unit_tests/hostapd.exmaple.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interworking=1
4646
disassoc_low_ack=1
4747
preamble=1
4848
wmm_enabled=1
49+
mode=ap
4950
ignore_broadcast_ssid=0
5051
uapsd_advertisement_enabled=1
5152
mbo=1
@@ -79,6 +80,7 @@ mesh_mode=fAP
7980
multi_ap_backhaul_ssid="Multi-AP-24G-2"
8081
multi_ap_backhaul_wpa_passphrase=maprocks2
8182
bss=wlan0.1
83+
mode=non-ap
8284
ctrl_interface=/var/run/hostapd
8385
ap_isolate=1
8486
ap_max_inactivity=60
@@ -148,4 +150,5 @@ wpa=0
148150
bridge=br-lan
149151
bssid=02:9A:96:FB:59:14
150152
start_disabled=1
153+
mode=ap
151154

0 commit comments

Comments
 (0)