34#ifndef CYW43_INCLUDED_CYW43_H
35#define CYW43_INCLUDED_CYW43_H
37#include "cyw43_config.h"
40#include "lwip/netif.h"
45#include "shared/netutils/dhcpserver.h"
66#define CYW43_VERSION_MAJOR 1
67#define CYW43_VERSION_MINOR 1
68#define CYW43_VERSION_MICRO 0
76#define CYW43_VERSION (CYW43_VERSION_MAJOR << 16 | CYW43_VERSION_MINOR << 8 | CYW43_VERSION_MICRO)
84#define CYW43_TRACE_ASYNC_EV (0x0001)
85#define CYW43_TRACE_ETH_TX (0x0002)
86#define CYW43_TRACE_ETH_RX (0x0004)
87#define CYW43_TRACE_ETH_FULL (0x0008)
88#define CYW43_TRACE_MAC (0x0010)
98#define CYW43_LINK_DOWN (0)
99#define CYW43_LINK_JOIN (1)
100#define CYW43_LINK_NOIP (2)
101#define CYW43_LINK_UP (3)
102#define CYW43_LINK_FAIL (-1)
103#define CYW43_LINK_NONET (-2)
104#define CYW43_LINK_BADAUTH (-3)
111 uint32_t trace_flags;
114 volatile uint32_t wifi_scan_state;
115 uint32_t wifi_join_state;
123 bool pend_rejoin_wpa;
135 struct netif netif[2];
136 #if LWIP_IPV4 && LWIP_DHCP
137 struct dhcp dhcp_client;
142 dhcp_server_t dhcp_server;
148 #if CYW43_ENABLE_BLUETOOTH
153extern cyw43_t cyw43_state;
154extern void (*cyw43_poll)(void);
155extern uint32_t cyw43_sleep;
187int cyw43_ioctl(cyw43_t *self, uint32_t cmd,
size_t len, uint8_t *buf, uint32_t iface);
328 return self->wifi_scan_state == 1;
350int cyw43_wifi_join(cyw43_t *self,
size_t ssid_len,
const uint8_t *ssid,
size_t key_len,
const uint8_t *key, uint32_t auth_type,
const uint8_t *bssid, uint32_t channel);
394 *len = self->ap_ssid_len;
395 *buf = self->ap_ssid;
407 return self->ap_auth;
419 self->ap_channel = (uint8_t)channel;
432 self->ap_ssid_len = (uint8_t)
MIN(len,
sizeof(self->ap_ssid));
433 memcpy(self->ap_ssid, buf, self->ap_ssid_len);
446 self->ap_key_len = (uint8_t)
MIN(len,
sizeof(self->ap_key));
447 memcpy(self->ap_key, buf, self->ap_key_len);
466 self->ap_auth = auth;
505 return self->initted;
626static inline uint32_t
cyw43_pm_value(uint8_t pm_mode, uint16_t pm2_sleep_ret_ms, uint8_t li_beacon_period, uint8_t li_dtim_period, uint8_t li_assoc) {
627 return li_assoc << 20
628 | li_dtim_period << 16
629 | li_beacon_period << 12
630 | (pm2_sleep_ret_ms / 10) << 4
637#define CYW43_DEFAULT_PM (CYW43_PERFORMANCE_PM)
642#define CYW43_NONE_PM (cyw43_pm_value(CYW43_NO_POWERSAVE_MODE, 10, 0, 0, 0))
647#define CYW43_AGGRESSIVE_PM (cyw43_pm_value(CYW43_PM1_POWERSAVE_MODE, 10, 0, 0, 0))
652#define CYW43_PERFORMANCE_PM (cyw43_pm_value(CYW43_PM2_POWERSAVE_MODE, 200, 1, 1, 10))
654#if CYW43_ENABLE_BLUETOOTH
661int cyw43_bluetooth_hci_init(
void);
671int cyw43_bluetooth_hci_read(uint8_t *buf, uint32_t max_size, uint32_t *len);
680int cyw43_bluetooth_hci_write(uint8_t *buf,
size_t len);
685void cyw43_bluetooth_hci_process(
void);
689#if CYW43_ENABLE_BLUETOOTH_OVER_UART
698int cyw43_bluetooth_controller_init(
void);
705int cyw43_bluetooth_controller_deinit(
void);
712int cyw43_bluetooth_controller_sleep_maybe(
void);
719bool cyw43_bluetooth_controller_woken(
void);
726int cyw43_bluetooth_controller_wakeup(
void);
void cyw43_wifi_set_up(cyw43_t *self, int itf, bool up, uint32_t country)
Set up and initialise wifi.
Definition cyw43_ctrl.c:553
static void cyw43_wifi_ap_set_channel(cyw43_t *self, uint32_t channel)
Set the the channel for the access point.
Definition cyw43.h:418
static uint32_t cyw43_pm_value(uint8_t pm_mode, uint16_t pm2_sleep_ret_ms, uint8_t li_beacon_period, uint8_t li_dtim_period, uint8_t li_assoc)
Return a power management value to pass to cyw43_wifi_pm.
Definition cyw43.h:626
static bool cyw43_wifi_scan_active(cyw43_t *self)
Determine if a wifi scan is in progress.
Definition cyw43.h:327
int cyw43_wifi_scan(cyw43_t *self, cyw43_wifi_scan_options_t *opts, void *env, int(*result_cb)(void *, const cyw43_ev_scan_result_t *))
Perform a wifi scan for wifi networks.
Definition cyw43_ctrl.c:587
void cyw43_deinit(cyw43_t *self)
Shut the driver down.
Definition cyw43_ctrl.c:118
void cyw43_cb_tcpip_init(cyw43_t *self, int itf)
Initialise the IP stack.
Definition cyw43_lwip.c:168
int cyw43_wifi_get_mac(cyw43_t *self, int itf, uint8_t mac[6])
Get the mac address of the device.
Definition cyw43_ctrl.c:539
int cyw43_wifi_link_status(cyw43_t *self, int itf)
Get the wifi link status.
Definition cyw43_ctrl.c:613
int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel)
Connect or join a wifi network.
Definition cyw43_ctrl.c:635
void cyw43_cb_tcpip_deinit(cyw43_t *self, int itf)
Deinitialise the IP stack.
Definition cyw43_lwip.c:246
static void cyw43_wifi_ap_set_auth(cyw43_t *self, uint32_t auth)
Set the security authorisation used in AP mode.
Definition cyw43.h:465
int cyw43_wifi_pm(cyw43_t *self, uint32_t pm)
Set the wifi power management mode.
Definition cyw43_ctrl.c:494
int cyw43_wifi_leave(cyw43_t *self, int itf)
Disassociate from a wifi network.
Definition cyw43_ctrl.c:666
static void cyw43_wifi_ap_set_ssid(cyw43_t *self, size_t len, const uint8_t *buf)
Set the ssid for the access point.
Definition cyw43.h:431
int cyw43_wifi_get_rssi(cyw43_t *self, int32_t *rssi)
Get the signal strength (RSSI) of the wifi network.
Definition cyw43_ctrl.c:672
int cyw43_gpio_get(cyw43_t *self, int gpio, bool *val)
Get the value of the cyw43 gpio.
Definition cyw43_ctrl.c:749
static bool cyw43_is_initialized(cyw43_t *self)
Determines if the cyw43 driver been initialised.
Definition cyw43.h:504
int cyw43_wifi_get_bssid(cyw43_t *self, uint8_t bssid[6])
Get the BSSID of the connected wifi network.
Definition cyw43_ctrl.c:679
static void cyw43_wifi_ap_get_ssid(cyw43_t *self, size_t *len, const uint8_t **buf)
Get the ssid for the access point.
Definition cyw43.h:393
int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, bool is_pbuf)
Send a raw ethernet packet.
Definition cyw43_ctrl.c:458
int cyw43_wifi_get_pm(cyw43_t *self, uint32_t *pm)
Get the wifi power management mode.
Definition cyw43_ctrl.c:515
void cyw43_cb_tcpip_set_link_up(cyw43_t *self, int itf)
Notify the IP stack that the link is up.
Definition cyw43_lwip.c:292
void cyw43_wifi_ap_get_stas(cyw43_t *self, int *num_stas, uint8_t *macs)
Get the number of devices (STAs) associated with the wifi access point.
Definition cyw43_ctrl.c:717
int cyw43_wifi_update_multicast_filter(cyw43_t *self, uint8_t *addr, bool add)
Add/remove multicast group address.
Definition cyw43_ctrl.c:546
static void cyw43_wifi_ap_set_password(cyw43_t *self, size_t len, const uint8_t *buf)
Set the password for the wifi access point.
Definition cyw43.h:445
int cyw43_ioctl(cyw43_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface)
Send an ioctl command to cyw43.
Definition cyw43_ctrl.c:444
void cyw43_init(cyw43_t *self)
Initialize the driver.
Definition cyw43_ctrl.c:85
static uint32_t cyw43_wifi_ap_get_auth(cyw43_t *self)
Get the security authorisation used in AP mode.
Definition cyw43.h:406
int cyw43_tcpip_link_status(cyw43_t *self, int itf)
Get the link status.
Definition cyw43_lwip.c:300
int cyw43_gpio_set(cyw43_t *self, int gpio, bool val)
Set the value of the cyw43 gpio.
Definition cyw43_ctrl.c:737
void cyw43_wifi_ap_get_max_stas(cyw43_t *self, int *max_stas)
Get the maximum number of devices (STAs) that can be associated with the wifi access point.
Definition cyw43_ctrl.c:713
void cyw43_cb_tcpip_set_link_down(cyw43_t *self, int itf)
Notify the IP stack that the link is down.
Definition cyw43_lwip.c:296
struct _cyw43_wifi_scan_options_t cyw43_wifi_scan_options_t
wifi scan options passed to cyw43_wifi_scan
struct _cyw43_ev_scan_result_t cyw43_ev_scan_result_t
Structure to return wifi scan results.