-
Notifications
You must be signed in to change notification settings - Fork 30
/
esp_tls_lwmqtt.h
64 lines (54 loc) · 1.84 KB
/
esp_tls_lwmqtt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef ESP_TLS_LWMQTT_H
#define ESP_TLS_LWMQTT_H
#include <esp_log.h>
#include <lwmqtt.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/entropy.h>
#include <mbedtls/error.h>
#include <mbedtls/net_sockets.h>
#include <mbedtls/platform.h>
#include <mbedtls/ssl.h>
#include <sdkconfig.h>
/**
* The tls lwmqtt network object for the esp platform.
*/
typedef struct {
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
mbedtls_x509_crt cacert;
mbedtls_net_context socket;
uint8_t *ca_buf;
size_t ca_len;
bool verify;
} esp_tls_lwmqtt_network_t;
/**
* Initiate a connection to the specified remote host.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_connect(esp_tls_lwmqtt_network_t *n, char *host, char *port);
/**
* Wait until the socket is connected or a timeout has been reached.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_wait(esp_tls_lwmqtt_network_t *n, bool *connected, uint32_t timeout);
/**
* Terminate the connection.
*/
void esp_tls_lwmqtt_network_disconnect(esp_tls_lwmqtt_network_t *n);
/**
* Will set available to the available amount of data in the underlying network buffer.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_peek(esp_tls_lwmqtt_network_t *n, size_t *available, uint32_t timeout);
/**
* Will wait for a socket until data is available or the timeout has been reached.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_select(esp_tls_lwmqtt_network_t *n, bool *available, uint32_t timeout);
/**
* The tls lwmqtt network read callback for the esp platform.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_read(void *ref, uint8_t *buf, size_t len, size_t *received, uint32_t timeout);
/**
* The tls lwmqtt network write callback for the esp platform.
*/
lwmqtt_err_t esp_tls_lwmqtt_network_write(void *ref, uint8_t *buf, size_t len, size_t *sent, uint32_t timeout);
#endif // ESP_LWMQTT_H