libwebsockets
Lightweight C library for HTML5 websockets
lws-system.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_system_ops
 

Macros

#define LWSSYSGAUTH_HEX   (1 << 0)
 

Typedefs

typedef struct lws_system_blob lws_system_blob_t
 
typedef void(* lws_attach_cb_t) (struct lws_context *context, int tsi, void *opaque)
 
typedef struct lws_system_ops lws_system_ops_t
 

Enumerations

enum  lws_system_blob_item_t {
  LWS_SYSBLOB_TYPE_AUTH , LWS_SYSBLOB_TYPE_CLIENT_CERT_DER = LWS_SYSBLOB_TYPE_AUTH + 2 , LWS_SYSBLOB_TYPE_CLIENT_KEY_DER , LWS_SYSBLOB_TYPE_DEVICE_SERIAL ,
  LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION , LWS_SYSBLOB_TYPE_DEVICE_TYPE , LWS_SYSBLOB_TYPE_NTP_SERVER , LWS_SYSBLOB_TYPE_MQTT_CLIENT_ID ,
  LWS_SYSBLOB_TYPE_MQTT_USERNAME , LWS_SYSBLOB_TYPE_MQTT_PASSWORD , LWS_SYSBLOB_TYPE_COUNT
}
 
enum  lws_system_states_t {
  LWS_SYSTATE_UNKNOWN , LWS_SYSTATE_CONTEXT_CREATED , LWS_SYSTATE_INITIALIZED , LWS_SYSTATE_IFACE_COLDPLUG ,
  LWS_SYSTATE_DHCP , LWS_SYSTATE_CPD_PRE_TIME , LWS_SYSTATE_TIME_VALID , LWS_SYSTATE_CPD_POST_TIME ,
  LWS_SYSTATE_POLICY_VALID , LWS_SYSTATE_REGISTERED , LWS_SYSTATE_AUTH1 , LWS_SYSTATE_AUTH2 ,
  LWS_SYSTATE_ONE_TIME_UPDATES , LWS_SYSTATE_OPERATIONAL , LWS_SYSTATE_POLICY_INVALID , LWS_SYSTATE_CONTEXT_DESTROYING ,
  LWS_SYSTATE_AWAITING_MODAL_UPDATING , LWS_SYSTATE_MODAL_UPDATING
}
 
enum  lws_cpd_result_t { LWS_CPD_UNKNOWN = 0 , LWS_CPD_INTERNET_OK , LWS_CPD_CAPTIVE_PORTAL , LWS_CPD_NO_INTERNET }
 
enum  {
  LWSDH_IPV4_SUBNET_MASK = 0 , LWSDH_IPV4_BROADCAST , LWSDH_LEASE_SECS , LWSDH_REBINDING_SECS ,
  LWSDH_RENEWAL_SECS , _LWSDH_NUMS_COUNT , LWSDH_SA46_IP = 0 , LWSDH_SA46_DNS_SRV_1 ,
  LWSDH_SA46_DNS_SRV_2 , LWSDH_SA46_DNS_SRV_3 , LWSDH_SA46_DNS_SRV_4 , LWSDH_SA46_IPV4_ROUTER ,
  LWSDH_SA46_NTP_SERVER , LWSDH_SA46_DHCP_SERVER , _LWSDH_SA46_COUNT
}
 

Functions

LWS_EXTERN LWS_VISIBLE void lws_system_blob_direct_set (lws_system_blob_t *b, const uint8_t *ptr, size_t len)
 
LWS_EXTERN LWS_VISIBLE void lws_system_blob_heap_empty (lws_system_blob_t *b)
 
LWS_EXTERN LWS_VISIBLE int lws_system_blob_heap_append (lws_system_blob_t *b, const uint8_t *ptr, size_t len)
 
LWS_EXTERN LWS_VISIBLE size_t lws_system_blob_get_size (lws_system_blob_t *b)
 
LWS_EXTERN LWS_VISIBLE int lws_system_blob_get_single_ptr (lws_system_blob_t *b, const uint8_t **ptr)
 
LWS_EXTERN LWS_VISIBLE int lws_system_blob_get (lws_system_blob_t *b, uint8_t *ptr, size_t *len, size_t ofs)
 
LWS_EXTERN LWS_VISIBLE void lws_system_blob_destroy (lws_system_blob_t *b)
 
LWS_EXTERN LWS_VISIBLE lws_system_blob_tlws_system_get_blob (struct lws_context *context, lws_system_blob_item_t type, int idx)
 
LWS_EXTERN LWS_VISIBLE int lws_tls_jit_trust_got_cert_cb (struct lws_context *cx, void *got_opaque, const uint8_t *skid, size_t skid_len, const uint8_t *der, size_t der_len)
 
LWS_EXTERN LWS_VISIBLE const lws_system_ops_tlws_system_get_ops (struct lws_context *context)
 
LWS_EXTERN LWS_VISIBLE int __lws_system_attach (struct lws_context *context, int tsi, lws_attach_cb_t cb, lws_system_states_t state, void *opaque, struct lws_attach_item **get)
 

Macro Definition Documentation

◆ LWSSYSGAUTH_HEX

#define LWSSYSGAUTH_HEX   (1 << 0)

Definition at line 240 of file lws-system.h.

Typedef Documentation

◆ lws_system_blob_t

typedef struct lws_system_blob lws_system_blob_t

Definition at line 1 of file lws-system.h.

◆ lws_attach_cb_t

typedef void(* lws_attach_cb_t) (struct lws_context *context, int tsi, void *opaque)

Definition at line 163 of file lws-system.h.

◆ lws_system_ops_t

Enumeration Type Documentation

◆ lws_system_blob_item_t

Enumerator
LWS_SYSBLOB_TYPE_AUTH 
LWS_SYSBLOB_TYPE_CLIENT_CERT_DER 
LWS_SYSBLOB_TYPE_CLIENT_KEY_DER 
LWS_SYSBLOB_TYPE_DEVICE_SERIAL 
LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION 
LWS_SYSBLOB_TYPE_DEVICE_TYPE 
LWS_SYSBLOB_TYPE_NTP_SERVER 
LWS_SYSBLOB_TYPE_MQTT_CLIENT_ID 
LWS_SYSBLOB_TYPE_MQTT_USERNAME 
LWS_SYSBLOB_TYPE_MQTT_PASSWORD 
LWS_SYSBLOB_TYPE_COUNT 

Definition at line 33 of file lws-system.h.

33  {
44 
45 #if defined(LWS_WITH_SECURE_STREAMS_AUTH_SIGV4)
46  /* extend 4 more auth blobs, each has 2 slots */
47  LWS_SYSBLOB_TYPE_EXT_AUTH1,
48  LWS_SYSBLOB_TYPE_EXT_AUTH2 = LWS_SYSBLOB_TYPE_EXT_AUTH1 + 2,
49  LWS_SYSBLOB_TYPE_EXT_AUTH3 = LWS_SYSBLOB_TYPE_EXT_AUTH2 + 2,
50  LWS_SYSBLOB_TYPE_EXT_AUTH4 = LWS_SYSBLOB_TYPE_EXT_AUTH3 + 2,
51  LWS_SYSBLOB_TYPE_EXT_AUTH4_1,
52 #endif
53 
54  LWS_SYSBLOB_TYPE_COUNT /* ... always last */
lws_system_blob_item_t
Definition: lws-system.h:33
@ LWS_SYSBLOB_TYPE_NTP_SERVER
Definition: lws-system.h:40
@ LWS_SYSBLOB_TYPE_MQTT_USERNAME
Definition: lws-system.h:42
@ LWS_SYSBLOB_TYPE_MQTT_PASSWORD
Definition: lws-system.h:43
@ LWS_SYSBLOB_TYPE_MQTT_CLIENT_ID
Definition: lws-system.h:41
@ LWS_SYSBLOB_TYPE_CLIENT_CERT_DER
Definition: lws-system.h:35
@ LWS_SYSBLOB_TYPE_COUNT
Definition: lws-system.h:54
@ LWS_SYSBLOB_TYPE_DEVICE_SERIAL
Definition: lws-system.h:37
@ LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION
Definition: lws-system.h:38
@ LWS_SYSBLOB_TYPE_AUTH
Definition: lws-system.h:34
@ LWS_SYSBLOB_TYPE_DEVICE_TYPE
Definition: lws-system.h:39
@ LWS_SYSBLOB_TYPE_CLIENT_KEY_DER
Definition: lws-system.h:36

◆ lws_system_states_t

Enumerator
LWS_SYSTATE_UNKNOWN 
LWS_SYSTATE_CONTEXT_CREATED 
LWS_SYSTATE_INITIALIZED 
LWS_SYSTATE_IFACE_COLDPLUG 
LWS_SYSTATE_DHCP 
LWS_SYSTATE_CPD_PRE_TIME 
LWS_SYSTATE_TIME_VALID 
LWS_SYSTATE_CPD_POST_TIME 
LWS_SYSTATE_POLICY_VALID 
LWS_SYSTATE_REGISTERED 
LWS_SYSTATE_AUTH1 
LWS_SYSTATE_AUTH2 
LWS_SYSTATE_ONE_TIME_UPDATES 
LWS_SYSTATE_OPERATIONAL 
LWS_SYSTATE_POLICY_INVALID 
LWS_SYSTATE_CONTEXT_DESTROYING 
LWS_SYSTATE_AWAITING_MODAL_UPDATING 
LWS_SYSTATE_MODAL_UPDATING 

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

105  { /* keep system_state_names[] in sync in context.c */
107 
108  LWS_SYSTATE_CONTEXT_CREATED, /* context was just created */
109  LWS_SYSTATE_INITIALIZED, /* protocols initialized. Lws itself
110  * can operate normally */
111  LWS_SYSTATE_IFACE_COLDPLUG, /* existing net ifaces iterated */
112  LWS_SYSTATE_DHCP, /* at least one net iface configured */
113  LWS_SYSTATE_CPD_PRE_TIME, /* Captive portal detect without valid
114  * time, good for non-https tests... if
115  * you care about it, implement and
116  * call lws_system_ops_t
117  * .captive_portal_detect_request()
118  * and move the state forward according
119  * to the result. */
120  LWS_SYSTATE_TIME_VALID, /* ntpclient ran, or hw time valid...
121  * tls cannot work until we reach here
122  */
123  LWS_SYSTATE_CPD_POST_TIME, /* Captive portal detect after time was
124  * time, good for https tests... if
125  * you care about it, implement and
126  * call lws_system_ops_t
127  * .captive_portal_detect_request()
128  * and move the state forward according
129  * to the result. */
130 
131  LWS_SYSTATE_POLICY_VALID, /* user code knows how to operate... */
132  LWS_SYSTATE_REGISTERED, /* device has an identity... */
133  LWS_SYSTATE_AUTH1, /* identity used for main auth token */
134  LWS_SYSTATE_AUTH2, /* identity used for optional auth */
135 
136  LWS_SYSTATE_ONE_TIME_UPDATES, /* pre-OPERATIONAL one-time updates,
137  * when a firmware needs to perform
138  * one-time upgrades to state before
139  * OPERATIONAL */
140 
141  LWS_SYSTATE_OPERATIONAL, /* user code can operate normally */
142 
143  LWS_SYSTATE_POLICY_INVALID, /* user code is changing its policies
144  * drop everything done with old
145  * policy, switch to new then enter
146  * LWS_SYSTATE_POLICY_VALID */
147  LWS_SYSTATE_CONTEXT_DESTROYING, /* Context is being destroyed */
148  LWS_SYSTATE_AWAITING_MODAL_UPDATING, /* We're negotiating with the
149  * user code for update mode */
150  LWS_SYSTATE_MODAL_UPDATING, /* We're updating the firmware */
lws_system_states_t
Definition: lws-system.h:105
@ LWS_SYSTATE_POLICY_VALID
Definition: lws-system.h:131
@ LWS_SYSTATE_AUTH1
Definition: lws-system.h:133
@ LWS_SYSTATE_MODAL_UPDATING
Definition: lws-system.h:150
@ LWS_SYSTATE_AUTH2
Definition: lws-system.h:134
@ LWS_SYSTATE_CONTEXT_DESTROYING
Definition: lws-system.h:147
@ LWS_SYSTATE_CPD_PRE_TIME
Definition: lws-system.h:113
@ LWS_SYSTATE_AWAITING_MODAL_UPDATING
Definition: lws-system.h:148
@ LWS_SYSTATE_UNKNOWN
Definition: lws-system.h:106
@ LWS_SYSTATE_IFACE_COLDPLUG
Definition: lws-system.h:111
@ LWS_SYSTATE_DHCP
Definition: lws-system.h:112
@ LWS_SYSTATE_REGISTERED
Definition: lws-system.h:132
@ LWS_SYSTATE_OPERATIONAL
Definition: lws-system.h:141
@ LWS_SYSTATE_INITIALIZED
Definition: lws-system.h:109
@ LWS_SYSTATE_ONE_TIME_UPDATES
Definition: lws-system.h:136
@ LWS_SYSTATE_TIME_VALID
Definition: lws-system.h:120
@ LWS_SYSTATE_CONTEXT_CREATED
Definition: lws-system.h:108
@ LWS_SYSTATE_POLICY_INVALID
Definition: lws-system.h:143
@ LWS_SYSTATE_CPD_POST_TIME
Definition: lws-system.h:123

◆ lws_cpd_result_t

Enumerator
LWS_CPD_UNKNOWN 
LWS_CPD_INTERNET_OK 
LWS_CPD_CAPTIVE_PORTAL 
LWS_CPD_NO_INTERNET 

Definition at line 155 of file lws-system.h.

155  {
156  LWS_CPD_UNKNOWN = 0, /* test didn't happen ince last DHCP acq yet */
157  LWS_CPD_INTERNET_OK, /* no captive portal: our CPD test passed OK,
158  * we can go out on the internet */
159  LWS_CPD_CAPTIVE_PORTAL, /* we inferred we're behind a captive portal */
160  LWS_CPD_NO_INTERNET, /* we couldn't touch anything */
lws_cpd_result_t
Definition: lws-system.h:155
@ LWS_CPD_UNKNOWN
Definition: lws-system.h:156
@ LWS_CPD_CAPTIVE_PORTAL
Definition: lws-system.h:159
@ LWS_CPD_NO_INTERNET
Definition: lws-system.h:160
@ LWS_CPD_INTERNET_OK
Definition: lws-system.h:157

◆ anonymous enum

anonymous enum
Enumerator
LWSDH_IPV4_SUBNET_MASK 
LWSDH_IPV4_BROADCAST 
LWSDH_LEASE_SECS 
LWSDH_REBINDING_SECS 
LWSDH_RENEWAL_SECS 
_LWSDH_NUMS_COUNT 
LWSDH_SA46_IP 
LWSDH_SA46_DNS_SRV_1 
LWSDH_SA46_DNS_SRV_2 
LWSDH_SA46_DNS_SRV_3 
LWSDH_SA46_DNS_SRV_4 
LWSDH_SA46_IPV4_ROUTER 
LWSDH_SA46_NTP_SERVER 
LWSDH_SA46_DHCP_SERVER 
_LWSDH_SA46_COUNT 

Definition at line 305 of file lws-system.h.

305  {
311 
313 
314  LWSDH_SA46_IP = 0,
322 
324 };
@ LWSDH_REBINDING_SECS
Definition: lws-system.h:309
@ LWSDH_SA46_DNS_SRV_4
Definition: lws-system.h:318
@ LWSDH_SA46_IPV4_ROUTER
Definition: lws-system.h:319
@ LWSDH_IPV4_BROADCAST
Definition: lws-system.h:307
@ LWSDH_SA46_NTP_SERVER
Definition: lws-system.h:320
@ _LWSDH_NUMS_COUNT
Definition: lws-system.h:312
@ LWSDH_SA46_IP
Definition: lws-system.h:314
@ LWSDH_SA46_DHCP_SERVER
Definition: lws-system.h:321
@ LWSDH_SA46_DNS_SRV_3
Definition: lws-system.h:317
@ LWSDH_IPV4_SUBNET_MASK
Definition: lws-system.h:306
@ LWSDH_RENEWAL_SECS
Definition: lws-system.h:310
@ LWSDH_SA46_DNS_SRV_1
Definition: lws-system.h:315
@ LWSDH_LEASE_SECS
Definition: lws-system.h:308
@ LWSDH_SA46_DNS_SRV_2
Definition: lws-system.h:316
@ _LWSDH_SA46_COUNT
Definition: lws-system.h:323

Function Documentation

◆ lws_system_blob_direct_set()

LWS_EXTERN LWS_VISIBLE void lws_system_blob_direct_set ( lws_system_blob_t b,
const uint8_t ptr,
size_t  len 
)

◆ lws_system_blob_heap_empty()

LWS_EXTERN LWS_VISIBLE void lws_system_blob_heap_empty ( lws_system_blob_t b)

◆ lws_system_blob_heap_append()

LWS_EXTERN LWS_VISIBLE int lws_system_blob_heap_append ( lws_system_blob_t b,
const uint8_t ptr,
size_t  len 
)

◆ lws_system_blob_get_size()

LWS_EXTERN LWS_VISIBLE size_t lws_system_blob_get_size ( lws_system_blob_t b)

◆ lws_system_blob_get_single_ptr()

LWS_EXTERN LWS_VISIBLE int lws_system_blob_get_single_ptr ( lws_system_blob_t b,
const uint8_t **  ptr 
)

◆ lws_system_blob_get()

LWS_EXTERN LWS_VISIBLE int lws_system_blob_get ( lws_system_blob_t b,
uint8_t ptr,
size_t *  len,
size_t  ofs 
)

◆ lws_system_blob_destroy()

LWS_EXTERN LWS_VISIBLE void lws_system_blob_destroy ( lws_system_blob_t b)

◆ lws_system_get_blob()

LWS_EXTERN LWS_VISIBLE lws_system_blob_t* lws_system_get_blob ( struct lws_context *  context,
lws_system_blob_item_t  type,
int  idx 
)

◆ lws_tls_jit_trust_got_cert_cb()

LWS_EXTERN LWS_VISIBLE int lws_tls_jit_trust_got_cert_cb ( struct lws_context *  cx,
void *  got_opaque,
const uint8_t skid,
size_t  skid_len,
const uint8_t der,
size_t  der_len 
)

◆ lws_system_get_ops()

LWS_EXTERN LWS_VISIBLE const lws_system_ops_t* lws_system_get_ops ( struct lws_context *  context)

lws_system_get_ops() - get ahold of the system ops struct from the context

Parameters
contextthe lws_context

Returns the system ops struct. It may return NULL and if not, anything in there may be NULL.

◆ __lws_system_attach()

LWS_EXTERN LWS_VISIBLE int __lws_system_attach ( struct lws_context *  context,
int  tsi,
lws_attach_cb_t  cb,
lws_system_states_t  state,
void *  opaque,
struct lws_attach_item **  get 
)

__lws_system_attach() - get and set items on context attach list

Parameters
contextcontext to get or set attach items to
tsithread service index (normally 0)
cbcallback to call from context event loop thread
statethe lws_system state we have to be in or have passed through
opaqueoptional pointer to user specific info given to callback
getNULL, or pointer to pointer to take detached tail item on exit

This allows other threads to enqueue callback requests to happen from a pt's event loop thread safely. The callback gets the context pointer and a user opaque pointer that can be optionally given when the item is added to the attach list.

This api is the no-locking core function for getting and setting items on the pt's attach list. The lws_system operation (*attach) is the actual api that user and internal code calls for this feature, it should perform system-specific locking, call this helper, release the locking and then return the result. This api is public only so it can be used in the locked implementation of (*attach).

If get is NULL, then the call adds to the head of the pt attach list using cb, state, and opaque; if get is non-NULL, then *get is set to the first waiting attached item that meets the state criteria and that item is removed from the list.

This is a non-threadsafe helper only designed to be called from implementations of struct lws_system's (*attach) operation where system- specific locking has been applied around it, making it threadsafe.