Skip to content

Commit

Permalink
Finished OOP migration
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Carlson <[email protected]>
  • Loading branch information
bcarlson-dev committed Mar 5, 2025
1 parent caae539 commit 5e57ad2
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 191 deletions.
49 changes: 27 additions & 22 deletions inc/ec_configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*
* @param chirp_tlv The chirp TLV to send
* @param len The length of the chirp TLV
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
using send_chirp_func = std::function<int(em_dpp_chirp_value_t*, size_t)>;
using send_chirp_func = std::function<bool(em_dpp_chirp_value_t*, size_t)>;

/**
* @brief Sends a proxied encapsulated DPP message
Expand All @@ -25,17 +25,17 @@ using send_chirp_func = std::function<int(em_dpp_chirp_value_t*, size_t)>;
* @param encap_dpp_len The length of the 1905 Encap DPP TLV
* @param chirp_tlv The chirp value to include in the message. If NULL, the message will not include a chirp value
* @param chirp_len The length of the chirp value
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
using send_encap_dpp_func = std::function<int(em_encap_dpp_t*, size_t, em_dpp_chirp_value_t*, size_t)>;
using send_encap_dpp_func = std::function<bool(em_encap_dpp_t*, size_t, em_dpp_chirp_value_t*, size_t)>;

/**
* @brief Set the CCE IEs in the beacon and probe response frames
*
* @param bool Whether to enable or disable the inclusion of CCE IEs in the beacon and probe response frames
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
using toggle_cce_func = std::function<int(bool)>;
using toggle_cce_func = std::function<bool(bool)>;

class ec_configurator_t {
public:
Expand All @@ -46,14 +46,14 @@ class ec_configurator_t {
* @param send_prox_encap_dpp_msg The function to send a proxied encapsulated DPP message
*/
// TODO: Add send_action_frame and send_gas_frame functions
ec_configurator_t(send_chirp_func send_chirp_notification, send_encap_dpp_func send_prox_encap_dpp_msg);
ec_configurator_t(std::string mac_addr, send_chirp_func send_chirp_notification, send_encap_dpp_func send_prox_encap_dpp_msg);
~ec_configurator_t(); // Destructor

/**
* @brief Set the CCE IEs in the beacon and probe response frames
*
* @param bool Whether to enable or disable the inclusion of CCE IEs in the beacon and probe response frames
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
toggle_cce_func m_toggle_cce;

Expand All @@ -70,11 +70,12 @@ class ec_configurator_t {
*
* @param buff The frame to handle
* @param len The length of the frame
* @return bool true if successful, false otherwise
*
* @note Optional to implement because the controller+configurator does not handle 802.11,
* but the proxy agent + configurator does.
*/
virtual int handle_presence_announcement(uint8_t *buff, unsigned int len) {
virtual bool handle_presence_announcement(uint8_t *buff, unsigned int len) {
return 0; // Optional to implement
}

Expand All @@ -83,51 +84,51 @@ class ec_configurator_t {
*
* @param buff The frame to handle
* @param len The length of the frame
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*
* @note Optional to implement because the controller+configurator does not handle 802.11,
* but the proxy agent + configurator does.
*/
virtual int handle_auth_response(uint8_t *buff, unsigned int len) {
return 0; // Optional to implement
virtual bool handle_auth_response(uint8_t *buff, unsigned int len) {
return true; // Optional to implement
}

/**
* @brief Handles an configuration request 802.11+GAS frame, performing the necessary actions
*
* @param buff The frame to handle
* @param len The length of the frame
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*
* @note Optional to implement because the controller+configurator does not handle 802.11,
* but the proxy agent + configurator does.
*/
virtual int handle_cfg_request(uint8_t *buff, unsigned int len) {
return 0; // Optional to implement
virtual bool handle_cfg_request(uint8_t *buff, unsigned int len) {
return true; // Optional to implement
}

/**
* @brief Handles an configuration result 802.11+GAS frame, performing the necessary actions
*
* @param buff The frame to handle
* @param len The length of the frame
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*
* @note Optional to implement because the controller+configurator does not handle 802.11,
* but the proxy agent + configurator does.
*/
virtual int handle_cfg_result(uint8_t *buff, unsigned int len) {
return 0; // Optional to implement
virtual bool handle_cfg_result(uint8_t *buff, unsigned int len) {
return true; // Optional to implement
}

/**
* @brief Handle a chirp notification msg tlv and direct to the correct place (802.11 or 1905)
*
* @param chirp_tlv The chirp TLV to parse and handle
* @param tlv_len The length of the chirp TLV
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
virtual int process_chirp_notification(em_dpp_chirp_value_t* chirp_tlv, uint16_t tlv_len) = 0;
virtual bool process_chirp_notification(em_dpp_chirp_value_t* chirp_tlv, uint16_t tlv_len) = 0;

/**
* @brief Handle a proxied encapsulated DPP message TLVs (including chirp value) and direct to the correct place (802.11 or 1905)
Expand All @@ -136,9 +137,11 @@ class ec_configurator_t {
* @param encap_tlv_len The length of the 1905 Encap DPP TLV
* @param chirp_tlv The DPP Chirp Value TLV to parse and handle (NULL if not present)
* @param chirp_tlv_len The length of the DPP Chirp Value TLV (0 if not present)
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
virtual int process_proxy_encap_dpp_msg(em_encap_dpp_t *encap_tlv, uint16_t encap_tlv_len, em_dpp_chirp_value_t *chirp_tlv, uint16_t chirp_tlv_len) = 0;
virtual bool process_proxy_encap_dpp_msg(em_encap_dpp_t *encap_tlv, uint16_t encap_tlv_len, em_dpp_chirp_value_t *chirp_tlv, uint16_t chirp_tlv_len) = 0;

inline std::string get_mac_addr() { return m_mac_addr; };

// Disable copy construction and assignment
// Requires use of references or pointers when working with instances of this class
Expand All @@ -154,6 +157,8 @@ class ec_configurator_t {

send_encap_dpp_func m_send_prox_encap_dpp_msg;

std::string m_mac_addr;

// The connections to the Enrollees/Agents
std::map<std::string, ec_connection_context_t> m_connections;

Expand Down
15 changes: 8 additions & 7 deletions inc/ec_ctrl_configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

class ec_ctrl_configurator_t : public ec_configurator_t {
public:
ec_ctrl_configurator_t(send_chirp_func send_chirp_notification, send_encap_dpp_func send_prox_encap_dpp_msg) :
ec_configurator_t(send_chirp_notification, send_prox_encap_dpp_msg) {};
ec_ctrl_configurator_t(std::string mac_addr, send_chirp_func send_chirp_notification, send_encap_dpp_func send_prox_encap_dpp_msg) :
ec_configurator_t(mac_addr, send_chirp_notification, send_prox_encap_dpp_msg) {};
// No MAC address needed for controller configurator

/**
* @brief Handle a chirp notification msg tlv and direct to 1905 agent
*
* @param chirp_tlv The chirp TLV to parse and handle
* @param tlv_len The length of the chirp TLV
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
int process_chirp_notification(em_dpp_chirp_value_t* chirp_tlv, uint16_t tlv_len);
bool process_chirp_notification(em_dpp_chirp_value_t* chirp_tlv, uint16_t tlv_len);

/**
* @brief Handle a proxied encapsulated DPP message TLVs (including chirp value) and direct to 1905 agent
Expand All @@ -24,17 +25,17 @@ class ec_ctrl_configurator_t : public ec_configurator_t {
* @param encap_tlv_len The length of the 1905 Encap DPP TLV
* @param chirp_tlv The DPP Chirp Value TLV to parse and handle (NULL if not present)
* @param chirp_tlv_len The length of the DPP Chirp Value TLV (0 if not present)
* @return int 0 if successful, -1 otherwise
* @return bool true if successful, false otherwise
*/
int process_proxy_encap_dpp_msg(em_encap_dpp_t *encap_tlv, uint16_t encap_tlv_len, em_dpp_chirp_value_t *chirp_tlv, uint16_t chirp_tlv_len);
bool process_proxy_encap_dpp_msg(em_encap_dpp_t *encap_tlv, uint16_t encap_tlv_len, em_dpp_chirp_value_t *chirp_tlv, uint16_t chirp_tlv_len);

private:
// Private member variables can be added here

std::pair<uint8_t*, uint16_t> create_auth_request(std::string enrollee_mac);
std::pair<uint8_t*, uint16_t> create_recfg_auth_request();
std::pair<uint8_t*, uint16_t> create_auth_confirm();
std::pair<uint8_t*, uint16_t> create_recfg_auth_confirm();
std::pair<uint8_t*, uint16_t> create_recfg_auth_confirm(std::string enrollee_mac);
std::pair<uint8_t*, uint16_t> create_config_response();
};

Expand Down
56 changes: 50 additions & 6 deletions inc/ec_enrollee.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,62 @@
#include "em_base.h"

#include <map>
#include <string>

class ec_enrollee_t {
public:
// TODO: Add Send Action Frame, Send GAS Frame
ec_enrollee_t();
/**
* @brief The EasyConnect Enrollee
*
* Broadcasts 802.11 presence announcements, handles 802.11 frames from Proxy Agents and sends 802.11 responses to Proxy Agents.
*
* @param mac_addr The MAC address of the device
*
* @note The default state of an enrollee is non-onboarding. All non-controller devices are started as (non-onboarding) enrollees
* until they are told that they are on the network at which point they can be upgraded to a proxy agent.
*/
ec_enrollee_t(std::string mac_addr);

// Destructor
~ec_enrollee_t();

int start(bool do_reconfig);
/**
* @brief Start the EC enrollee onboarding
*
* @param do_reconfig Whether to reconfigure/reauth the enrollee
* @return bool true if successful, false otherwise
*/
bool start(bool do_reconfig);

/**
* @brief Handle an authentication request 802.11 frame, performing the necessary actions and responding with an authentication response via 802.11
*
* @param buff The frame to handle
* @param len The length of the frame
* @return bool true if successful, false otherwise
*/
bool handle_auth_request(uint8_t *buff, unsigned int len);

int handle_auth_request(uint8_t *buff, unsigned int len);
/**
* @brief Handle an authentication confirmation 802.11 frame, performing the necessary actions
*
* @param buff The frame to handle
* @param len The length of the frame
* @return bool true if successful, false otherwise
*/
bool handle_auth_confirm(uint8_t *buff, unsigned int len);

int handle_auth_confirm(uint8_t *buff, unsigned int len);
/**
* @brief Handle a configuration request 802.11+GAS frame, performing the necessary actions and responding with a configuration result via 802.11
*
* @param buff The frame to handle
* @param len The length of the frame
* @return bool true if successful, false otherwise
*/
bool handle_config_response(uint8_t *buff, unsigned int len);

int handle_config_response(uint8_t *buff, unsigned int len);
inline std::string get_mac_addr() { return m_mac_addr; };

// Disable copy construction and assignment
// Requires use of references or pointers when working with instances of this class
Expand All @@ -36,7 +76,9 @@ class ec_enrollee_t {
* @brief Called when recieving a Authentication Request,
* this function checks that the "Responder" (self) is capable of
* supporting the role indicated by the Initiator's capabilities.
*
*
* @param caps The capabilities of the Initiator
* @return bool true if the Responder supports the Initiator's capabilities, false otherwise
*/
bool check_supports_init_caps(ec_dpp_capabilities_t caps);

Expand All @@ -54,6 +96,8 @@ class ec_enrollee_t {

ec_data_t m_boot_data;

std::string m_mac_addr;


};

Expand Down
Loading

0 comments on commit 5e57ad2

Please sign in to comment.