libwebsockets
Lightweight C library for HTML5 websockets
lws-netdev.h File Reference

Go to the source code of this file.

Data Structures

struct  lws_netdev_config
 
struct  lws_netdev_ops
 
struct  lws_netdevs
 
struct  lws_netdev_instance
 
struct  lws_wifi_creds
 
struct  lws_netdev_instance_wifi
 
struct  lws_wifi_sta
 

Macros

#define LWS_WIFI_MAX_SCAN_TRACK   16
 
#define LWS_ETH_ALEN   6
 
#define rssi_averaged(_x)
 
#define lws_netdev_wifi_plat_ops
 

Typedefs

typedef uint8_t lws_wifi_ch_t
 
typedef int8_t lws_wifi_rssi_t
 
typedef struct lws_netdev_config lws_netdev_config_t
 
typedef struct lws_netdev_ops lws_netdev_ops_t
 
typedef struct lws_netdevs lws_netdevs_t
 
typedef struct lws_netdev_instance lws_netdev_instance_t
 
typedef struct lws_wifi_creds lws_wifi_creds_t
 
typedef struct lws_netdev_instance_wifi lws_netdev_instance_wifi_t
 
typedef struct lws_wifi_sta lws_wifi_sta_t
 

Enumerations

enum  lws_netdev_type_t { LWSNDTYP_UNKNOWN , LWSNDTYP_WIFI , LWSNDTYP_ETH }
 
enum  {
  LNDIW_ALG_OPEN , LNDIW_ALG_WPA2 , LNDIW_MODE_STA = (1 << 0) , LNDIW_MODE_AP = (1 << 1) ,
  LNDIW_UP = (1 << 7) , LNDIW_ACQ_IPv4 = (1 << 0) , LNDIW_ACQ_IPv6 = (1 << 1)
}
 
enum  lws_netdev_wifi_state_t {
  LWSNDVWIFI_STATE_INITIAL , LWSNDVWIFI_STATE_SCAN , LWSNDVWIFI_STATE_AP , LWSNDVWIFI_STATE_AP_SCAN ,
  LWSNDVWIFI_STATE_STAT_GRP_AP , LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN , LWSNDVWIFI_STATE_STAT , LWSNDVWIFI_STATE_STAT_HAPPY
}
 

Functions

LWS_VISIBLE LWS_EXTERN lws_netdevs_tlws_netdevs_from_ctx (struct lws_context *ctx)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_credentials_settings_set (lws_netdevs_t *nds)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_credentials_settings_get (lws_netdevs_t *nds)
 
LWS_VISIBLE LWS_EXTERN struct lws_netdev_instancelws_netdev_wifi_create_plat (struct lws_context *ctx, const lws_netdev_ops_t *ops, const char *name, void *platinfo)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_configure_plat (struct lws_netdev_instance *nd, lws_netdev_config_t *config)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_event_plat (struct lws_netdev_instance *nd, lws_usec_t timestamp, void *buf, size_t len)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_up_plat (struct lws_netdev_instance *nd)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_down_plat (struct lws_netdev_instance *nd)
 
LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_destroy_plat (struct lws_netdev_instance **pnd)
 
LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_scan_plat (lws_netdev_instance_t *nd)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_connect_plat (lws_netdev_instance_t *wnd, const char *ssid, const char *passphrase, uint8_t *bssid)
 
LWS_VISIBLE LWS_EXTERN lws_netdev_instance_tlws_netdev_find (lws_netdevs_t *netdevs, const char *ifname)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_plat_init (void)
 
LWS_VISIBLE LWS_EXTERN int lws_netdev_plat_wifi_init (void)
 

Data Structure Documentation

◆ lws_netdev_config

struct lws_netdev_config

Definition at line 42 of file lws-netdev.h.

+ Collaboration diagram for lws_netdev_config:
Data Fields
void * plat_config

◆ lws_netdevs

struct lws_netdevs

Definition at line 75 of file lws-netdev.h.

+ Collaboration diagram for lws_netdevs:
Data Fields
lws_dll2_owner_t owner

list of netdevs / lws_netdev_instance_t -based objects

lws_dll2_owner_t owner_creds

list of known credentials

struct lwsac * ac_creds

lwsac holding retreived credentials settings, or NULL

lws_settings_instance_t * si
lws_sockaddr46 sa46_dns_resolver
uint8_t refcount_creds

when there are multiple netdevs, must refcount creds in mem

◆ lws_netdev_instance

struct lws_netdev_instance

Definition at line 96 of file lws-netdev.h.

+ Collaboration diagram for lws_netdev_instance:
Data Fields
const char * name
const lws_netdev_ops_t * ops
void * platinfo
lws_dll2_t list
uint8_t mac[LWS_ETH_ALEN]
uint8_t type

◆ lws_wifi_creds

struct lws_wifi_creds

Definition at line 171 of file lws-netdev.h.

+ Collaboration diagram for lws_wifi_creds:
Data Fields
lws_dll2_t list
uint8_t bssid[LWS_ETH_ALEN]
char passphrase[64]
char ssid[33]
uint8_t alg

◆ lws_netdev_instance_wifi

struct lws_netdev_instance_wifi

Definition at line 184 of file lws-netdev.h.

+ Collaboration diagram for lws_netdev_instance_wifi:
Data Fields
lws_netdev_instance_t inst
lws_dll2_owner_t scan
lws_sorted_usec_list_t sul_scan
lws_wifi_creds_t * ap_cred
const char * ap_ip
const char * sta_ads
char current_attempt_ssid[33]
uint8_t current_attempt_bssid[LWS_ETH_ALEN]
uint8_t flags
uint8_t state

◆ lws_wifi_sta

struct lws_wifi_sta

Definition at line 205 of file lws-netdev.h.

+ Collaboration diagram for lws_wifi_sta:
Data Fields
lws_dll2_t list
uint32_t last_seen
uint32_t last_tried
uint8_t bssid[LWS_ETH_ALEN]
char * ssid
uint8_t ssid_len
lws_wifi_ch_t ch
lws_wifi_rssi_t rssi[8]
int16_t rssi_avg
uint8_t authmode
uint8_t rssi_count
uint8_t rssi_next

Macro Definition Documentation

◆ LWS_WIFI_MAX_SCAN_TRACK

#define LWS_WIFI_MAX_SCAN_TRACK   16

Definition at line 25 of file lws-netdev.h.

◆ LWS_ETH_ALEN

#define LWS_ETH_ALEN   6

Definition at line 26 of file lws-netdev.h.

◆ rssi_averaged

#define rssi_averaged (   _x)
Value:
(_x->rssi_count ? \
((int)_x->rssi_avg / (int)_x->rssi_count) : \
-200)

Definition at line 225 of file lws-netdev.h.

◆ lws_netdev_wifi_plat_ops

#define lws_netdev_wifi_plat_ops
Value:
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_configure_plat(struct lws_netdev_instance *nd, lws_netdev_config_t *config)
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_down_plat(struct lws_netdev_instance *nd)
LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_destroy_plat(struct lws_netdev_instance **pnd)
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_up_plat(struct lws_netdev_instance *nd)
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_event_plat(struct lws_netdev_instance *nd, lws_usec_t timestamp, void *buf, size_t len)
LWS_VISIBLE LWS_EXTERN struct lws_netdev_instance * lws_netdev_wifi_create_plat(struct lws_context *ctx, const lws_netdev_ops_t *ops, const char *name, void *platinfo)
LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_scan_plat(lws_netdev_instance_t *nd)
LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_connect_plat(lws_netdev_instance_t *wnd, const char *ssid, const char *passphrase, uint8_t *bssid)

Definition at line 264 of file lws-netdev.h.

Typedef Documentation

◆ lws_wifi_ch_t

typedef uint8_t lws_wifi_ch_t

Definition at line 28 of file lws-netdev.h.

◆ lws_wifi_rssi_t

typedef int8_t lws_wifi_rssi_t

Definition at line 29 of file lws-netdev.h.

◆ lws_netdev_config_t

◆ lws_netdev_ops_t

◆ lws_netdevs_t

typedef struct lws_netdevs lws_netdevs_t

◆ lws_netdev_instance_t

◆ lws_wifi_creds_t

◆ lws_netdev_instance_wifi_t

◆ lws_wifi_sta_t

typedef struct lws_wifi_sta lws_wifi_sta_t

Enumeration Type Documentation

◆ lws_netdev_type_t

Enumerator
LWSNDTYP_UNKNOWN 
LWSNDTYP_WIFI 
LWSNDTYP_ETH 

Definition at line 32 of file lws-netdev.h.

32  {
lws_netdev_type_t
Definition: lws-netdev.h:32
@ LWSNDTYP_ETH
Definition: lws-netdev.h:35
@ LWSNDTYP_WIFI
Definition: lws-netdev.h:34
@ LWSNDTYP_UNKNOWN
Definition: lws-netdev.h:33

◆ anonymous enum

anonymous enum
Enumerator
LNDIW_ALG_OPEN 
LNDIW_ALG_WPA2 
LNDIW_MODE_STA 
LNDIW_MODE_AP 
LNDIW_UP 
LNDIW_ACQ_IPv4 
LNDIW_ACQ_IPv6 

Definition at line 105 of file lws-netdev.h.

105  {
108 
109  LNDIW_MODE_STA = (1 << 0),
110  LNDIW_MODE_AP = (1 << 1),
111  LNDIW_UP = (1 << 7),
112 
113  LNDIW_ACQ_IPv4 = (1 << 0),
114  LNDIW_ACQ_IPv6 = (1 << 1),
115 };
@ LNDIW_ACQ_IPv6
Definition: lws-netdev.h:114
@ LNDIW_ALG_WPA2
Definition: lws-netdev.h:107
@ LNDIW_MODE_AP
Definition: lws-netdev.h:110
@ LNDIW_ACQ_IPv4
Definition: lws-netdev.h:113
@ LNDIW_UP
Definition: lws-netdev.h:111
@ LNDIW_MODE_STA
Definition: lws-netdev.h:109
@ LNDIW_ALG_OPEN
Definition: lws-netdev.h:106

◆ lws_netdev_wifi_state_t

Enumerator
LWSNDVWIFI_STATE_INITIAL 
LWSNDVWIFI_STATE_SCAN 
LWSNDVWIFI_STATE_AP 
LWSNDVWIFI_STATE_AP_SCAN 
LWSNDVWIFI_STATE_STAT_GRP_AP 
LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN 
LWSNDVWIFI_STATE_STAT 
LWSNDVWIFI_STATE_STAT_HAPPY 

Definition at line 121 of file lws-netdev.h.

121  {
123  /*
124  * We should gratuitously try whatever last worked for us, then
125  * if that fails, worry about the rest of the logic
126  */
128  /*
129  * Unconnected, scanning: AP known in one of the config slots ->
130  * configure it, start timeout + LWSNDVWIFI_STATE_STAT, if no AP
131  * already up in same group with lower MAC, after a random
132  * period start up our AP (LWSNDVWIFI_STATE_AP)
133  */
135  /* Trying to be the group AP... periodically do a scan
136  * LWSNDVWIFI_STATE_AP_SCAN, faster and then slower
137  */
139  /*
140  * doing a scan while trying to be the group AP... if we see a
141  * lower MAC being the AP for the same group AP, abandon being
142  * an AP and join that AP as a station
143  */
145  /*
146  * We have decided to join another group member who is being the
147  * AP, as its MAC is lower than ours. This is a stable state,
148  * but we still do periodic scans
149  * LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN and will always prefer an
150  * AP configured in a slot.
151  */
153  /*
154  * We have joined a group member who is doing the AP job... we
155  * want to check every now and then if a configured AP has
156  * appeared that we should better use instead. Otherwise stay
157  * in LWSNDVWIFI_STATE_STAT_GRP_AP
158  */
160  /*
161  * trying to connect to another non-group AP. If we don't get an
162  * IP within a timeout and retries, mark it as unusable it and go back
163  */
lws_netdev_wifi_state_t
Definition: lws-netdev.h:121
@ LWSNDVWIFI_STATE_AP_SCAN
Definition: lws-netdev.h:138
@ LWSNDVWIFI_STATE_STAT_GRP_AP
Definition: lws-netdev.h:144
@ LWSNDVWIFI_STATE_STAT_HAPPY
Definition: lws-netdev.h:164
@ LWSNDVWIFI_STATE_SCAN
Definition: lws-netdev.h:127
@ LWSNDVWIFI_STATE_STAT
Definition: lws-netdev.h:159
@ LWSNDVWIFI_STATE_INITIAL
Definition: lws-netdev.h:122
@ LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN
Definition: lws-netdev.h:152
@ LWSNDVWIFI_STATE_AP
Definition: lws-netdev.h:134

Function Documentation

◆ lws_netdevs_from_ctx()

LWS_VISIBLE LWS_EXTERN lws_netdevs_t* lws_netdevs_from_ctx ( struct lws_context *  ctx)

◆ lws_netdev_credentials_settings_set()

LWS_VISIBLE LWS_EXTERN int lws_netdev_credentials_settings_set ( lws_netdevs_t nds)

◆ lws_netdev_credentials_settings_get()

LWS_VISIBLE LWS_EXTERN int lws_netdev_credentials_settings_get ( lws_netdevs_t nds)

◆ lws_netdev_wifi_create_plat()

LWS_VISIBLE LWS_EXTERN struct lws_netdev_instance* lws_netdev_wifi_create_plat ( struct lws_context *  ctx,
const lws_netdev_ops_t ops,
const char *  name,
void *  platinfo 
)

◆ lws_netdev_wifi_configure_plat()

LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_configure_plat ( struct lws_netdev_instance nd,
lws_netdev_config_t config 
)

◆ lws_netdev_wifi_event_plat()

LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_event_plat ( struct lws_netdev_instance nd,
lws_usec_t  timestamp,
void *  buf,
size_t  len 
)

◆ lws_netdev_wifi_up_plat()

LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_up_plat ( struct lws_netdev_instance nd)

◆ lws_netdev_wifi_down_plat()

LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_down_plat ( struct lws_netdev_instance nd)

◆ lws_netdev_wifi_destroy_plat()

LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_destroy_plat ( struct lws_netdev_instance **  pnd)

◆ lws_netdev_wifi_scan_plat()

LWS_VISIBLE LWS_EXTERN void lws_netdev_wifi_scan_plat ( lws_netdev_instance_t nd)

◆ lws_netdev_wifi_connect_plat()

LWS_VISIBLE LWS_EXTERN int lws_netdev_wifi_connect_plat ( lws_netdev_instance_t wnd,
const char *  ssid,
const char *  passphrase,
uint8_t *  bssid 
)

◆ lws_netdev_find()

LWS_VISIBLE LWS_EXTERN lws_netdev_instance_t* lws_netdev_find ( lws_netdevs_t netdevs,
const char *  ifname 
)

◆ lws_netdev_plat_init()

LWS_VISIBLE LWS_EXTERN int lws_netdev_plat_init ( void  )

◆ lws_netdev_plat_wifi_init()

LWS_VISIBLE LWS_EXTERN int lws_netdev_plat_wifi_init ( void  )