This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bwl: add support for nl80211 standard commands
We need support for nl80211 standard commands for things such as obtaining link metrics or device capabilities. In "Send standard NL80211 commands using DWPAL #782" we firstly evaluated the convenience of adding such support in DWPAL and then in BWL. As a result of such evaluation we concluded that DWPAL was not the most suitable place to add such support. Reason is that NL80211 standard commands are not exclusive of devices where DWPAL is used and support is also required for other flavors of the BWL library. Then we decided to add support for standard commands into the BWL library, but shared to all flavors, not only for the DWPAL version. A proposal was made to include support for NL80211 standard commands in the NL80211 classes, then derive BWL DWPAL from BWL NL80211 and override everything except the standard commands. This proposal was not finally implemented to "favor composition instead of inheritance". Instead of inheritance, a nl8011_client interface and a factory for objects of classes implementing such interface have been defined. BWL DWPAL, BWL nl80211 and whatever other part of the application can all be users of the nl80211_client factory, create an instance of a class implementing the nl80211_client interface and use it to send NL80211 standard commands. Although I prefer to inject the dependencies to facilitate unit-testing (if we ever had to), so most probably BWL DWPAL and BWL nl80211 classes that send NL80211 standard commands will have a nl80211_client parameter in their constructor instead of calling the factory. Another goal of this design is that it can be easily extended to send NETLINK_ROUTE commands (probably with a netlink_route_client). Maybe we should move all these classes from BWL to BPL because they are not intended for WiFi only. Created C++ wrappers around libnl and libnl-genl to facilitate sending NL80211 commands through a NL80211 netlink socket. Classes have been created in bwl/shared so NL80211 standard commands will be available to all flavours of the BWL library (except the Dummy one). Public include files have been created in bwl/include. Created a C++ interface with the list of commands available. Create two implementations, one to actually send those commands to the WiFi driver and a fake one for the Dummy implementation of the BWL library. Created a factory class in each BWL implementation to create instances of the NL80211 client. This factory will be used both from within the BWL library or from outside. Add NL80211_CMD_GET_STATION command implementation as an example of how standard commands are to be implemented. Once this design had been validated, the rest of standard commands will be added. Also we will do a code refactoring to use the new classes and eliminate duplicated code. Signed-off-by: Mario Maz <[email protected]>
- Loading branch information
1 parent
9f3a0ae
commit b3c9315
Showing
16 changed files
with
1,031 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* Copyright (c) 2020 MaxLinear | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
|
||
#include "nl80211_client_dummy.h" | ||
|
||
namespace bwl { | ||
|
||
nl80211_client_dummy::nl80211_client_dummy() {} | ||
|
||
nl80211_client_dummy::~nl80211_client_dummy() {} | ||
|
||
bool nl80211_client_dummy::get_sta_info(const std::string &local_interface_name, | ||
const sMacAddr &sta_mac_address, sStaInfo &sta_info) | ||
{ | ||
// Suppress "unused parameter" warning | ||
(void)local_interface_name; | ||
(void)sta_mac_address; | ||
|
||
static int inactive_time_ms = 0; | ||
static int rx_bytes = 0; | ||
static int rx_packets = 0; | ||
static uint32_t tx_bytes = 0; | ||
static uint32_t tx_packets = 0; | ||
static uint32_t tx_retries = 0; | ||
static uint32_t tx_failed = 0; | ||
static uint8_t signal_dBm = 0; | ||
static uint8_t signal_avg_dBm = 0; | ||
static uint16_t tx_bitrate_100kbps = 0; | ||
static uint16_t rx_bitrate_100kbps = 0; | ||
|
||
sta_info.inactive_time_ms = inactive_time_ms++; | ||
sta_info.rx_bytes = rx_bytes++; | ||
sta_info.rx_packets = rx_packets++; | ||
sta_info.tx_bytes = tx_bytes++; | ||
sta_info.tx_packets = tx_packets++; | ||
sta_info.tx_retries = tx_retries++; | ||
sta_info.tx_failed = tx_failed++; | ||
sta_info.signal_dBm = signal_dBm++; | ||
sta_info.signal_avg_dBm = signal_avg_dBm++; | ||
sta_info.tx_bitrate_100kbps = tx_bitrate_100kbps++; | ||
sta_info.rx_bitrate_100kbps = rx_bitrate_100kbps++; | ||
|
||
return true; | ||
} | ||
|
||
} // namespace bwl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* Copyright (c) 2020 MaxLinear | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
#ifndef __BWL_NL80211_CLIENT_DUMMY_H__ | ||
#define __BWL_NL80211_CLIENT_DUMMY_H__ | ||
|
||
#include <bwl/nl80211_client.h> | ||
|
||
namespace bwl { | ||
|
||
/** | ||
* @brief NL80211 client dummy implementation. | ||
* | ||
* This class is used by the dummy flavor of the BWL library and it is intended for testing | ||
* purposes only. | ||
*/ | ||
class nl80211_client_dummy : public nl80211_client { | ||
|
||
public: | ||
/** | ||
* @brief Class constructor. | ||
*/ | ||
nl80211_client_dummy(); | ||
|
||
/** | ||
* @brief Class destructor. | ||
*/ | ||
virtual ~nl80211_client_dummy(); | ||
|
||
/** | ||
* @brief Gets station information. | ||
* | ||
* Fills station information with dummy data. | ||
* | ||
* @param[in] local_interface_name Virtual AP (VAP) interface name. | ||
* @param[in] sta_mac_address MAC address of a station connected to the local interface. | ||
* @param[out] sta_info Station information. | ||
* | ||
* @return Dummy implementation returns always true. | ||
*/ | ||
virtual bool get_sta_info(const std::string &local_interface_name, | ||
const sMacAddr &sta_mac_address, sStaInfo &sta_info) override; | ||
}; | ||
|
||
} // namespace bwl | ||
|
||
#endif |
22 changes: 22 additions & 0 deletions
22
common/beerocks/bwl/dummy/nl80211_client_factory_dummy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* Copyright (c) 2020 MaxLinear | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
|
||
#include <bwl/nl80211_client_factory.h> | ||
|
||
#include "nl80211_client_dummy.h" | ||
|
||
#include <bcl/beerocks_backport.h> | ||
|
||
namespace bwl { | ||
|
||
std::unique_ptr<nl80211_client> nl80211_client_factory::create_instance() | ||
{ | ||
return std::make_unique<nl80211_client_dummy>(); | ||
} | ||
|
||
} // namespace bwl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* Copyright (c) 2020 MaxLinear | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
#ifndef __BWL_NL80211_CLIENT_H__ | ||
#define __BWL_NL80211_CLIENT_H__ | ||
|
||
#include <tlvf/common/sMacAddr.h> | ||
|
||
#include <string> | ||
|
||
namespace bwl { | ||
|
||
/** | ||
* @brief NL80211 client interface. | ||
* | ||
* This interface lists the methods to read and write wireless hardware status and configuration | ||
* through a NL80211 socket. | ||
* | ||
* Programming to an interface allows dependent classes to remain unaware of the different | ||
* implementations of the interface as well as facilitates the creation of mock implementations for | ||
* unit testing. | ||
* | ||
* This is a C++ interface: an abstract class that is designed to be specifically used as a base | ||
* class and which derived classes (implementations) will override each pure virtual function. | ||
* | ||
* Known implementations: nl80211_client_impl (uses NL80211 socket), nl80211_client_dummy (fake | ||
* implementation that returns dummy data). | ||
*/ | ||
class nl80211_client { | ||
|
||
public: | ||
/** | ||
* @brief Station information | ||
* | ||
* Information obtained with NL80211_CMD_GET_STATION command through a NL80211 socket. | ||
* See NL80211_STA_INFO_* in <linux/nl80211.h> for a description of each field. | ||
*/ | ||
struct sStaInfo { | ||
uint32_t inactive_time_ms = 0; | ||
uint32_t rx_bytes = 0; | ||
uint32_t rx_packets = 0; | ||
uint32_t tx_bytes = 0; | ||
uint32_t tx_packets = 0; | ||
uint32_t tx_retries = 0; | ||
uint32_t tx_failed = 0; | ||
uint8_t signal_dBm = 0; | ||
uint8_t signal_avg_dBm = 0; | ||
uint16_t tx_bitrate_100kbps = 0; | ||
uint16_t rx_bitrate_100kbps = 0; | ||
}; | ||
|
||
/** | ||
* @brief Class destructor. | ||
*/ | ||
virtual ~nl80211_client() = default; | ||
|
||
/** | ||
* @brief Gets station information. | ||
* | ||
* Station information contains basically metrics associated to the link between given local | ||
* interface and a the interface of a station whose MAC address is 'sta_mac_address'. | ||
* | ||
* @param[in] local_interface_name Virtual AP (VAP) interface name. | ||
* @param[in] sta_mac_address MAC address of a station connected to the local interface. | ||
* @param[out] sta_info Station information. | ||
* | ||
* @return True on success and false otherwise. | ||
*/ | ||
virtual bool get_sta_info(const std::string &local_interface_name, | ||
const sMacAddr &sta_mac_address, sStaInfo &sta_info) = 0; | ||
|
||
// TODO: add remaining methods | ||
}; | ||
|
||
} // namespace bwl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
* Copyright (c) 2020 MaxLinear | ||
* | ||
* This code is subject to the terms of the BSD+Patent license. | ||
* See LICENSE file for more details. | ||
*/ | ||
#ifndef __BWL_NL80211_CLIENT_FACTORY_H__ | ||
#define __BWL_NL80211_CLIENT_FACTORY_H__ | ||
|
||
#include "nl80211_client.h" | ||
|
||
#include <memory> | ||
|
||
namespace bwl { | ||
|
||
/** | ||
* @brief NL80211 client factory. | ||
* | ||
* Factory to create NL80211 client instances. Each BWL implementation should define one. | ||
*/ | ||
class nl80211_client_factory { | ||
|
||
public: | ||
/** | ||
* @brief Creates a new NL80211 client instance. | ||
* | ||
* @return NL80211 client instance. | ||
*/ | ||
static std::unique_ptr<nl80211_client> create_instance(); | ||
}; | ||
|
||
} // namespace bwl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Shared files directory | ||
|
||
The `shared` directory contains classes shared among all the implementations that use actual WiFi radios (i.e.: the DWPAL and NL80211 flavors but not the Dummy one). | ||
|
||
Currently, these classes provide the following functionality: | ||
- Support for NL80211 standard commands through a NL80211 socket. |
Oops, something went wrong.