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

Commit c21d2be

Browse files
committed
prplmesh-hostapd: PR 1514 review fixups
this commnit fixes all relevant comments for #1550 https://jira.prplfoundation.org/browse/PPM-249 Signed-off-by: Ran Regev <ran.regev@devalore.com>
1 parent 72cc86f commit c21d2be

4 files changed

Lines changed: 45 additions & 80 deletions

File tree

common/beerocks/hostapd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(PRPLMESH_HOSTAPD_TYPE ${PRPLMESH_HOSTAPD_TYPE} CACHE STRING "Which PRPLMESH_
3737

3838
set(
3939
hostapd_sources
40-
configuration.cpp
40+
source/configuration.cpp
4141
)
4242

4343

common/beerocks/hostapd/include/configuration.h renamed to common/beerocks/hostapd/include/hostapd/configuration.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ class Configuration {
211211
private:
212212
std::string m_configuration_file;
213213

214-
// may be changed because of const functions, therefore mutable
214+
// m_ok hoslds the internal state of the configuration
215+
// the user may query the success/fail state of the last command
216+
// simply by reading the value of this variable.
217+
// the access to it is via operator bool()
218+
// m_ok itslef may be changed because of a call to
219+
// const function, therefore it is mutable
215220
mutable bool m_ok = false;
216221

217222
// each string is a line in the original configuration file
@@ -261,8 +266,8 @@ template <class func, class iter, class ap_predicate>
261266
void Configuration::for_all_ap_vaps(func f, iter current_iter, const iter end, ap_predicate pred)
262267
{
263268
for_each(m_hostapd_config_vaps.begin(), m_hostapd_config_vaps.end(),
264-
[this, &f, &current_iter,
265-
&end, &pred](const std::pair<std::string, std::vector<std::string>> &vap) {
269+
[this, &f, &current_iter, &end,
270+
&pred](const std::pair<std::string, std::vector<std::string>> &vap) {
266271
if (pred(vap.first)) {
267272
if (end == current_iter) {
268273
f(vap.first, end);

common/beerocks/hostapd/configuration.cpp renamed to common/beerocks/hostapd/source/configuration.cpp

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* See LICENSE file for more details.
77
*/
88

9-
#include "configuration.h"
109
#include <algorithm>
1110
#include <easylogging++.h>
1211
#include <fstream>
12+
#include <hostapd/configuration.h>
1313

1414
namespace prplmesh {
1515
namespace hostapd {
@@ -20,9 +20,9 @@ Configuration::operator bool() const { return m_ok; }
2020

2121
bool Configuration::load(const std::string &vap_indication)
2222
{
23-
// please take a look at the end of this file for
24-
// the expected format of hostapd configuration file
25-
// loading the file relays on the expected format
23+
// please take a look at README.md (common/beerocks/hostapd/README.md) for
24+
// the expected format of hostapd configuration file.
25+
// loading the file relies on the expected format
2626
// otherwise the load fails
2727

2828
// for cases when load is called more than once, we
@@ -317,74 +317,29 @@ bool Configuration::is_key_in_line(const std::string &line, const std::string &k
317317
return ret;
318318
}
319319

320-
std::ostream &operator<<(std::ostream &o, const Configuration &conf)
320+
std::ostream &operator<<(std::ostream &os, const Configuration &conf)
321321
{
322-
o << "== configuration details ==\n"
323-
<< "= ok: " << std::boolalpha << conf.m_ok << '\n'
324-
<< "= last message: " << conf.m_last_message << '\n'
325-
<< "= file: " << conf.m_configuration_file << '\n'
326-
<< "= head: " << '\n';
322+
os << "== configuration details ==\n"
323+
<< "= ok: " << std::boolalpha << conf.m_ok << '\n'
324+
<< "= last message: " << conf.m_last_message << '\n'
325+
<< "= file: " << conf.m_configuration_file << '\n'
326+
<< "= head: " << '\n';
327327

328328
for (const auto &line : conf.m_hostapd_config_head) {
329-
o << line << '\n';
329+
os << line << '\n';
330330
}
331331

332-
o << "== vaps (total of: " << conf.m_hostapd_config_vaps.size() << " vaps) ==\n";
332+
os << "== vaps (total of: " << conf.m_hostapd_config_vaps.size() << " vaps) ==\n";
333333

334334
for (const auto &vap : conf.m_hostapd_config_vaps) {
335-
o << " vap: " << vap.first << "\n";
335+
os << " vap: " << vap.first << "\n";
336336
for (const auto &line : vap.second) {
337-
o << line << '\n';
337+
os << line << '\n';
338338
}
339339
}
340340

341-
return o;
341+
return os;
342342
}
343343

344344
} // namespace hostapd
345345
} // namespace prplmesh
346-
347-
/*
348-
//////////////// hostapd configuration format ////////////////
349-
350-
hostapd has a special format that does NOT have an ini like format.
351-
between /// BEGIN hostapd.conf /// and /// END hostapd.conf /// is the
352-
format of the file.
353-
note: the string "bss=" may be replaced by the
354-
user in the call to load() with another vap-indicator (e.g. "interface=")
355-
356-
/// BEGIN hostapd.conf ///
357-
358-
## "head" part ##
359-
360-
# everything until the first `bss=` in the file
361-
# is considered "head"
362-
# after the first `bss=` "vaps" are presented.
363-
# so we expect no parametrs that does not belong to vaps
364-
# after the first `bss=`
365-
# take a look below for more details
366-
367-
# note that we don't expect a space between the key and the equal sign
368-
# the code in this class seeks for `key=` when a key is needed.
369-
# therefore `key =` (with space) will fail
370-
# also, everything immidiatly after the equal sign (=) is
371-
# part of the value. the space before 11 in this is part of the value:
372-
# bassid= 11:22:33:44:55:66
373-
key=value
374-
375-
## "vaps part - we expect at least one vap to be configured ##
376-
377-
# vap (bss and vap are interchangable)
378-
bss=wlan0_0
379-
380-
# this key (ssid) belongs to the previous vap (bss value which is wlan0_0)
381-
ssid=test2
382-
383-
# another vap
384-
bss=wlan0_1
385-
386-
# this key (bssid) belongs to the previous vap wlan0_1
387-
bssid=00:13:10:95:fe:0b
388-
389-
///// END hostapd.conf ///
390-
*/

common/beerocks/hostapd/unit_tests/configuration_test.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
* See LICENSE file for more details.
77
*/
88

9-
#include "configuration.h"
109
#include <fstream>
10+
#include <hostapd/configuration.h>
1111

1212
#include <gtest/gtest.h>
1313

1414
namespace {
1515

16+
//const std::string vap_indication("bss=");
1617
const std::string vap_indication("interface=");
1718
const std::string configuration_path("/tmp/");
1819
const std::string configuration_file_name("omnia.conf");
@@ -56,9 +57,10 @@ const std::string configuration_content(
5657
"wpa=0\n"
5758
"ssid=dummy_ssid_0\n"
5859
"bridge=br-lan\n"
59-
"bssid=02:9A:96:FB:59:0F\n"
60+
"bssid=02:9A:96:FB:59:0F\n" +
6061

61-
"bss=wlan0.0\n"
62+
vap_indication +
63+
"wlan0.0\n"
6264
"ctrl_interface=/var/run/hostapd\n"
6365
"ap_isolate=1\n"
6466
"ap_max_inactivity=60\n"
@@ -100,9 +102,10 @@ const std::string configuration_content(
100102
"wps_state=2\n"
101103
"mesh_mode=fAP\n"
102104
"multi_ap_backhaul_ssid=\"Multi-AP-24G-2\"\n"
103-
"multi_ap_backhaul_wpa_passphrase=maprocks2\n"
105+
"multi_ap_backhaul_wpa_passphrase=maprocks2\n" +
104106

105-
"bss=wlan0.1\n"
107+
vap_indication +
108+
"wlan0.1\n"
106109
"mode=non-ap\n"
107110
"ctrl_interface=/var/run/hostapd\n"
108111
"ap_isolate=1\n"
@@ -134,7 +137,9 @@ const std::string configuration_content(
134137
"sFourAddrMode=1\n"
135138
"max_num_sta=1\n"
136139

137-
"#bss=wlan0.2\n"
140+
"#" +
141+
vap_indication +
142+
"wlan0.2\n"
138143
"#ctrl_interface=/var/run/hostapd\n"
139144
"#ap_isolate=1\n"
140145
"#ap_max_inactivity=60\n"
@@ -154,9 +159,10 @@ const std::string configuration_content(
154159
"#wpa=0\n"
155160
"#bridge=br-lan\n"
156161
"#bssid=02:9A:96:FB:59:13\n"
157-
"#start_disabled=1\n"
162+
"#start_disabled=1\n" +
158163

159-
"bss=wlan0.3\n"
164+
vap_indication +
165+
"wlan0.3\n"
160166
"ctrl_interface=/var/run/hostapd\n"
161167
"ap_isolate=1\n"
162168
"ap_max_inactivity=60\n"
@@ -178,16 +184,13 @@ const std::string configuration_content(
178184
"start_disabled=1\n"
179185
"mode=ap\n");
180186

181-
182-
/*
183187
void clean_start()
184188
{
185189
// save the content of the string (start clean)
186190
std::ofstream tmp(configuration_path + configuration_file_name);
187191
tmp << configuration_content;
188192
tmp.flush();
189193
}
190-
*/
191194

192195
TEST(configuration_test, load)
193196
{
@@ -228,7 +231,7 @@ TEST(configuration_test, store)
228231
//// end prerequsite ////
229232

230233
// add a value to vap
231-
conf.set_create_vap_value("wlan1", "was_i_stroed", "yes_you_were");
234+
conf.set_create_vap_value("wlan0.1", "was_i_stroed", "yes_you_were");
232235
EXPECT_TRUE(conf) << conf;
233236

234237
// store
@@ -315,8 +318,8 @@ TEST(configuration_test, get_head_values)
315318
//// end prerequsite ////
316319

317320
// get existing key
318-
auto val = conf.get_head_value("ctrl_interface");
319-
EXPECT_EQ(val, "/var/run/hostapd");
321+
auto val = conf.get_head_value("acs_num_scans");
322+
EXPECT_EQ(val, "1");
320323

321324
// get non existing key
322325
val = conf.get_head_value("out_of_office");
@@ -332,21 +335,23 @@ TEST(configuration_test, set_string_vap_values)
332335
//// start prerequsite ////
333336

334337
// save the content of the string (start clean)
335-
// // //clean_start();
338+
clean_start();
336339

337340
// construct a configuration
338341
prplmesh::hostapd::Configuration conf(configuration_path + configuration_file_name);
339342
ASSERT_FALSE(conf) << conf;
340343

341344
// load the dummy configuration file
342345
conf.load(vap_indication);
343-
;
344346
ASSERT_TRUE(conf) << conf;
345347

346348
//// end prerequsite ////
347349

348350
//// start test ////
349351

352+
conf.set_create_vap_value("wlan0", "ssid", "ran_home");
353+
EXPECT_TRUE(conf) << conf;
354+
350355
// replace existing value for existing key for existing vap
351356
conf.set_create_vap_value("wlan0.2", "disassoc_low_ack", "734");
352357
EXPECT_TRUE(conf) << conf;

0 commit comments

Comments
 (0)