34#ifndef _FREERTOS_DRIVERS_NET_C32XX_CC32XXWIFI_HXX_
35#define _FREERTOS_DRIVERS_NET_C32XX_CC32XXWIFI_HXX_
44#include "freertos_drivers/common/WifiDefs.hxx"
118 struct SockTriggerEvent;
121 struct HttpServerEvent;
124 struct HttpServerResponse;
127 struct NetAppRequest;
130 struct NetAppResponse;
133 struct FatalErrorEvent;
137 WLAN_CONNECTION_NO_CHANGE,
158 struct WlanNetworkEntry
180 uint32_t content_length,
const uint8_t *md,
size_t md_len,
181 const uint8_t *payload,
size_t payload_len,
bool has_more)>;
203 void start(WlanRole role = WlanRole::STA,
285 return WlanState::WRONG_PASSWORD;
287 return WlanState::NOT_ASSOCIATED;
291 return WlanState::NO_IP;
293 return WlanState::OK;
304 bool conn,
bool has_ip,
bool wrong_password,
const string &
ssid)
309 strcpy(this->ssid,
ssid.c_str());
315 void TEST_set_ip(uint32_t ip)
355 const char *key,
unsigned priority);
455 void set_ip_acquired_callback(std::function<
void(
bool)> callback)
506 const char *token_name, std::function<std::string()> callback)
541 const string &redirect =
"");
595 friend class ::NetworkSpace;
668 std::vector<std::function<void()> >
callbacks_;
671 std::vector<std::pair<
const char *, std::function<std::string()>>>
Socket implementation for the CC32xx class WiFi devices.
Interface that aids in unit testing.
SecurityType
Security types.
@ SEC_WEP
WEP security mode.
@ SEC_OPEN
open (no security)
@ SEC_WPA2
WPA2 security mode.
virtual void wlan_setup_ap(const char *ssid, const char *security_key, SecurityType security_type)=0
Setup access point role credentials.
virtual int wlan_profile_del(int index)=0
Delete a saved WLAN profile.
virtual ~CC32xxWiFiInterface()
Destructor.
Provides the startup and mantainance methods for configuring and using the CC32xx Wi-Fi stack.
string http_get_ip_address()
Get the IP address for a http request.
bool wlan_profile_test_none()
Test if there are any saved profiles.
unsigned securityFailure
Disconnected due to wrong password.
void net_app_event_handler(NetAppEvent *event)
This function handles network events such as IP acquisition, IP leased, IP released etc.
void trigger_event_handler(SockTriggerEvent *event)
Notifies the service about a wifi asynchronous socket event callback.
static SecurityType security_type_from_simplelink(uint8_t sec_type)
Translates the SimpleLink code to SecurityType enum.
int wlan_power_policy_set(WlanPowerPolicy wpp)
Set the power policy.
int wakeup
loopback socket to wakeup select()
void wlan_connection_policy_set(WlanConnectionPolicy policy)
Sets connection policy to auto connect.
std::vector< std::pair< const char *, PostFunction > > httpPostCallbacks_
List of callbacks for http post handlers.
static SecurityType security_type_from_scan(unsigned sec_type)
Translates the SimpleLink code from the network scan to SecurityType enum.
void netapp_request_callback(NetAppRequest *request, NetAppResponse *response)
This function handles netapp request callbacks.
void stop()
Stops the Wi-Fi in preparation for a reboot.
void set_default_state()
Set the CC32xx to its default state, including station mode.
bool is_started()
Get the started state of the network processor.
std::function< void(bool)> ipAcquiredCallback_
Callback for when IP is acquired.
void wlan_setup_ap(const char *ssid, const char *security_key, SecurityType security_type) override
Setup access point role credentials.
void wlan_set_scan_params(int mask, int min_rssi)
Sets the scan parameters.
void wlan_event_handler(WlanEvent *event)
This function handles WLAN events.
void wlan_get_ap_config(string *ssid, SecurityType *security_type)
Retrieve current AP config.
unsigned started
network processor started
void wlan_mac(uint8_t mac[6])
Get the device MAC address.
int16_t rssi
receive signal strength indicator
int wlan_get_ap_station_count()
Retrieves how many stations are connected to the wifi in AP mode.
void fatal_error_callback(FatalErrorEvent *event)
This Function Handles the Fatal errors.
int wlan_profile_del(int index) override
Delete a saved WLAN profile.
void wlan_set_role(WlanRole new_role)
Change the default Wlan Role.
int wlan_profile_del(const char *ssid)
Delete a saved WLAN profile.
char ssid[33]
SSID of AP, or AP we are connected to.
unsigned smartConfigStart
Smart config in progress.
void add_http_post_callback(const char *uri, PostFunction callback)
Registers a handler for an HTTP POST operation.
void fd_remove(int16_t sd)
Remove a socket from the known sockets that might be part of the sl_Select fdset.
WlanRole wlanRole
the Wi-Fi role we are in
OSMutex lock_
Protects callbacks_ vector.
void connecting_update_blinker()
Updates the blinker based on connection state.
uint32_t ipAddress
assigned IP adress
void sock_event_handler(SockEvent *event)
This function handles socket events indication.
static std::string get_version()
Returns a string contianing the version numbers of the network interface.
void run_on_network_thread(std::function< void()> callback)
Executes the given function on the network thread.
static constexpr int PROFILE_DELETE_ALL
the value passed to wlan_profile_del() to remove all profiles
unsigned connected
AP connected state.
WlanConnectionPolicy
The Wlan reconnect policy.
@ WLAN_CONNECTION_FAST_RECONNECT
Reconnect to the last connected AP.
@ WLAN_CONNECTION_SCAN
Scan for wifi networks and connect to the nearest that is stored in the profiles (by profile priority...
void fd_set_read(int16_t sd)
Add socket to the read fd set.
uint32_t wlan_ip()
Get the assigned IP address.
CountryCode wlan_country_code_get()
Get the current country code.
int wlan_rssi()
Get the receive signal strength indicator.
int wlan_profile_add(const char *ssid, SecurityType sec_type, const char *key, unsigned priority)
Add a saved WLAN profile.
void start(WlanRole role=WlanRole::STA, WlanPowerPolicy power_policy=WLAN_NO_CHANGE_POLICY, WlanConnectionPolicy connection_policy=WLAN_CONNECTION_NO_CHANGE)
Startup the Wi-Fi.
std::vector< std::function< void()> > callbacks_
List of callbacks to execute on the network thread.
int wlan_profile_get(int index, char ssid[], SecurityType *sec_type, uint32_t *priority)
Get a saved WLAN profile by index.
std::function< void(uint16_t handle, uint32_t content_length, const uint8_t *md, size_t md_len, const uint8_t *payload, size_t payload_len, bool has_more)> PostFunction
This function type is used for POST callback operations to the application.
WlanConnectionPolicy connectionPolicy
scan or reconnect to last AP
int wlan_network_list_get(WlanNetworkEntry *entries, size_t count)
Get a list of available networks.
void fd_set_write(int16_t sd)
Add socket to the write fd set.
void wlan_task()
Thread that will manage the WLAN connection inside object context.
WlanRole wlan_role()
Get the current Wi-Fi role.
static uint8_t security_type_to_simplelink(SecurityType sec_type)
Translates the SecurityType enum to the internal SimpleLink code.
void http_server_callback(HttpServerEvent *event, HttpServerResponse *response)
This function handles http server callback indication.
void select_wakeup()
Asynchronously wakeup the select call.
const char * wlan_ssid()
Get the SSID of the access point we are connected to.
unsigned ipAcquired
IP address aquired state.
WlanPowerPolicy wlanPowerPolicy
the desired power policy
static constexpr unsigned IPPROTO_TCP_TLS
Pass this option as protocol to socket to create a secure socket.
static constexpr int NUM_PROFILES
What is the maximum number of profiles in the CC32xx.
void wlan_rescan()
Initiate rescanning available networks.
static void * wlan_task_entry(void *context)
Thread that will manage the WLAN connection.
void test_mode_start()
Startup the Wi-Fi in test mode.
void wlan_wps_pbc_initiate()
Initiate a WPS Push Button Control connection.
WlanConnectResult wlan_connect(const char *ssid, const char *security_key, SecurityType security_type)
Connect to access point.
WlanPowerPolicy
The WLAN power policy.
@ WLAN_ALWAYS_ON_POLICY
WLAN power policy always on.
@ WLAN_NORMAL_POLICY
WLAN power policy normal.
@ WLAN_LOW_LATENCY_POLICY
WLAN power policy low latency.
@ WLAN_LOW_POWER_POLICY
WLAN power policy low power.
@ WLAN_NO_CHANGE_POLICY
WLAN power policy to be left alone.
void wlan_set_mac(uint8_t mac[6])
Sets the device MAC address.
void add_http_get_token_callback(const char *token_name, std::function< std::string()> callback)
Add an HTTP get token callback.
void send_post_respose(uint16_t handle, uint16_t http_status=204, const string &redirect="")
Sends a POST response.
int wlan_country_code_set(CountryCode cc, bool restart=false)
Set the current country code.
WlanState wlan_startup_state()
static constexpr unsigned SO_SIMPLELINK_SD
Retrieves the socket descriptor for setting TLS parameters.
unsigned connectionFailed
Connection attempt failed status.
std::vector< std::pair< const char *, std::function< std::string()> > > httpGetTokenCallbacks_
List of callbacks for http get tokens.
unsigned ipLeased
IP address leased to a client(AP mode)
bool get_post_data(uint16_t handle, void *buf, size_t *len)
Retrieves additional payload for http POST operations.
void wlan_disconnect()
Disconnects from the current AP.
int wlan_power_policy_get(WlanPowerPolicy *wpp)
Get the power policy.
Class to allow convenient locking and unlocking of mutexes in a C context.
This class provides a mutex API.
static CC32xxWiFi * instance()
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
CC32xx forward declaration Helper.
metadata for a WLAN netowrk entry.
int rssi
receive signal strength indicator of the AP
SecurityType sec_type
security type of the AP