mqtt_client_transport.c
Go to the documentation of this file.
1 /**
2  * @file mqtt_client_transport.c
3  * @brief Transport protocol abstraction layer
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL MQTT_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/tcp_misc.h"
37 #include "mqtt/mqtt_client.h"
40 #include "mqtt/mqtt_client_misc.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (MQTT_CLIENT_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Open network connection
49  * @param[in] context Pointer to the MQTT client context
50  * @return Error code
51  **/
52 
54 {
55  error_t error;
56 
57  //TCP transport protocol?
58  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
59  {
60  //Open a TCP socket
62 
63  //Valid socket handle?
64  if(context->socket != NULL)
65  {
66  //Associate the socket with the relevant interface
67  error = socketBindToInterface(context->socket, context->interface);
68  }
69  else
70  {
71  //Report an error
72  error = ERROR_OPEN_FAILED;
73  }
74  }
75 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
76  //TLS transport protocol?
77  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
78  {
79  //Open a TCP socket
81 
82  //Valid socket handle?
83  if(context->socket != NULL)
84  {
85  //Associate the socket with the relevant interface
86  error = socketBindToInterface(context->socket, context->interface);
87 
88  //Check status code
89  if(!error)
90  {
91  //Allocate TLS context
92  context->tlsContext = tlsInit();
93 
94  //Valid TLS handle?
95  if(context->tlsContext != NULL)
96  {
97  //Select client operation mode
98  error = tlsSetConnectionEnd(context->tlsContext,
100 
101  //Check status code
102  if(!error)
103  {
104  //Bind TLS to the relevant socket
105  error = tlsSetSocket(context->tlsContext, context->socket);
106  }
107 
108  //Check status code
109  if(!error)
110  {
111  //Restore TLS session, if any
112  error = tlsRestoreSessionState(context->tlsContext,
113  &context->tlsSession);
114  }
115 
116  //Check status code
117  if(!error)
118  {
119  //Invoke user-defined callback, if any
120  if(context->callbacks.tlsInitCallback != NULL)
121  {
122  //Perform TLS related initialization
123  error = context->callbacks.tlsInitCallback(context,
124  context->tlsContext);
125  }
126  }
127  }
128  else
129  {
130  //Report an error
131  error = ERROR_OPEN_FAILED;
132  }
133  }
134  }
135  else
136  {
137  //Report an error
138  error = ERROR_OPEN_FAILED;
139  }
140  }
141 #endif
142 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
143  //WebSocket transport protocol?
144  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS)
145  {
146  //Open a WebSocket
147  context->webSocket = webSocketOpen();
148 
149  //Valid WebSocket handle?
150  if(context->webSocket != NULL)
151  {
152  //Associate the WebSocket with the relevant interface
153  error = webSocketBindToInterface(context->webSocket,
154  context->interface);
155  }
156  else
157  {
158  //Report an error
159  error = ERROR_OPEN_FAILED;
160  }
161  }
162 #endif
163 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED && MQTT_CLIENT_TLS_SUPPORT == ENABLED && \
164  WEB_SOCKET_TLS_SUPPORT == ENABLED)
165  //Secure WebSocket transport protocol?
166  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
167  {
168  //Open a WebSocket
169  context->webSocket = webSocketOpen();
170 
171  //Valid WebSocket handle?
172  if(context->webSocket != NULL)
173  {
174  //Associate the WebSocket with the relevant interface
175  error = webSocketBindToInterface(context->webSocket,
176  context->interface);
177 
178  //Check status code
179  if(!error)
180  {
181  //Register TLS initialization callback
182  error = webSocketRegisterTlsInitCallback(context->webSocket,
183  (WebSocketTlsInitCallback) context->callbacks.tlsInitCallback);
184  }
185  }
186  else
187  {
188  //Report an error
189  error = ERROR_OPEN_FAILED;
190  }
191  }
192 #endif
193  //Unknown transport protocol?
194  else
195  {
196  //Report an error
197  error = ERROR_INVALID_PROTOCOL;
198  }
199 
200  //Return status code
201  return error;
202 }
203 
204 
205 /**
206  * @brief Establish network connection
207  * @param[in] context Pointer to the MQTT client context
208  * @param[in] serverIpAddr IP address of the MQTT server to connect to
209  * @param[in] serverPort TCP port number that will be used to establish the
210  * connection
211  * @return Error code
212  **/
213 
215  const IpAddr *serverIpAddr, uint16_t serverPort)
216 {
217  error_t error;
218 
219  //TCP transport protocol?
220  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
221  {
222  //Set timeout
223  error = socketSetTimeout(context->socket, context->settings.timeout);
224 
225  //Check status code
226  if(!error)
227  {
228  //Connect to the MQTT server using TCP
229  error = socketConnect(context->socket, serverIpAddr, serverPort);
230  }
231  }
232 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
233  //TLS transport protocol?
234  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
235  {
236  //Set timeout
237  error = socketSetTimeout(context->socket, context->settings.timeout);
238 
239  //Check status code
240  if(!error)
241  {
242  //Connect to the MQTT server using TCP
243  error = socketConnect(context->socket, serverIpAddr, serverPort);
244  }
245 
246  //Check status code
247  if(!error)
248  {
249  //Perform TLS handshake
250  error = tlsConnect(context->tlsContext);
251  }
252 
253  //Successful connection?
254  if(!error)
255  {
256  //Save TLS session
257  error = tlsSaveSessionState(context->tlsContext, &context->tlsSession);
258  }
259  }
260 #endif
261 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
262  //WebSocket transport protocol?
263  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS ||
264  context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
265  {
266  //Set timeout
267  error = webSocketSetTimeout(context->webSocket, context->settings.timeout);
268 
269  //Check status code
270  if(!error)
271  {
272  //Set the hostname of the remote server
273  error = webSocketSetHost(context->webSocket, context->settings.host);
274  }
275 
276  //Check status code
277  if(!error)
278  {
279  //The client MUST include "mqtt" in the list of WebSocket
280  //sub-protocols it offers
281  error = webSocketSetSubProtocol(context->webSocket, "mqtt");
282  }
283 
284  //Check status code
285  if(!error)
286  {
287  //Connect to the MQTT server using WebSocket
288  error = webSocketConnect(context->webSocket, serverIpAddr,
289  serverPort, context->settings.uri);
290  }
291  }
292 #endif
293  //Unknown transport protocol?
294  else
295  {
296  //Report an error
297  error = ERROR_INVALID_PROTOCOL;
298  }
299 
300  //Return status code
301  return error;
302 }
303 
304 
305 /**
306  * @brief Shutdown network connection
307  * @param[in] context Pointer to the MQTT client context
308  * @return Error code
309  **/
310 
312 {
313  error_t error;
314 
315  //TCP transport protocol?
316  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
317  {
318  //Set timeout
319  error = socketSetTimeout(context->socket, context->settings.timeout);
320 
321  //Check status code
322  if(!error)
323  {
324  //Shutdown TCP connection
325  error = socketShutdown(context->socket, SOCKET_SD_BOTH);
326  }
327  }
328 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
329  //TLS transport protocol?
330  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
331  {
332  //Set timeout
333  error = socketSetTimeout(context->socket, context->settings.timeout);
334 
335  //Check status code
336  if(!error)
337  {
338  //Shutdown TLS session
339  error = tlsShutdown(context->tlsContext);
340  }
341 
342  //Check status code
343  if(!error)
344  {
345  //Shutdown TCP connection
346  error = socketShutdown(context->socket, SOCKET_SD_BOTH);
347  }
348  }
349 #endif
350 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
351  //WebSocket transport protocol?
352  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS ||
353  context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
354  {
355  //Set timeout
356  error = webSocketSetTimeout(context->webSocket, context->settings.timeout);
357 
358  //Check status code
359  if(!error)
360  {
361  //Shutdown WebSocket connection
362  error = webSocketShutdown(context->webSocket);
363  }
364  }
365 #endif
366  //Unknown transport protocol?
367  else
368  {
369  //Report an error
370  error = ERROR_INVALID_PROTOCOL;
371  }
372 
373  //Return status code
374  return error;
375 }
376 
377 
378 /**
379  * @brief Close network connection
380  * @param[in] context Pointer to the MQTT client context
381  **/
382 
384 {
385  //TCP transport protocol?
386  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
387  {
388  //Close TCP connection
389  if(context->socket != NULL)
390  {
391  socketClose(context->socket);
392  context->socket = NULL;
393  }
394  }
395 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
396  //TLS transport protocol?
397  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
398  {
399  //Release TLS context
400  if(context->tlsContext != NULL)
401  {
402  tlsFree(context->tlsContext);
403  context->tlsContext = NULL;
404  }
405 
406  //Close TCP connection
407  if(context->socket != NULL)
408  {
409  socketClose(context->socket);
410  context->socket = NULL;
411  }
412  }
413 #endif
414 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
415  //WebSocket transport protocol?
416  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS ||
417  context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
418  {
419  //Close WebSocket connection
420  if(context->webSocket != NULL)
421  {
422  webSocketClose(context->webSocket);
423  context->webSocket = NULL;
424  }
425  }
426 #endif
427 }
428 
429 
430 /**
431  * @brief Send data using the relevant transport protocol
432  * @param[in] context Pointer to the MQTT client context
433  * @param[in] data Pointer to a buffer containing the data to be transmitted
434  * @param[in] length Number of bytes to be transmitted
435  * @param[out] written Actual number of bytes written (optional parameter)
436  * @param[in] flags Set of flags that influences the behavior of this function
437  * @return Error code
438  **/
439 
441  const void *data, size_t length, size_t *written, uint_t flags)
442 {
443  error_t error;
444 
445  //TCP transport protocol?
446  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
447  {
448  //Set timeout
449  error = socketSetTimeout(context->socket, context->settings.timeout);
450 
451  //Check status code
452  if(!error)
453  {
454  //Transmit data
455  error = socketSend(context->socket, data, length, written, flags);
456  }
457  }
458 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
459  //TLS transport protocol?
460  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
461  {
462  //Set timeout
463  error = socketSetTimeout(context->socket, context->settings.timeout);
464 
465  //Check status code
466  if(!error)
467  {
468  //Transmit data
469  error = tlsWrite(context->tlsContext, data, length, written, flags);
470  }
471  }
472 #endif
473 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
474  //WebSocket transport protocol?
475  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS ||
476  context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
477  {
478  //Set timeout
479  error = webSocketSetTimeout(context->webSocket, context->settings.timeout);
480 
481  //Check status code
482  if(!error)
483  {
484  //MQTT control packets must be sent in WebSocket binary data frames
485  error = webSocketSend(context->webSocket, data, length,
486  WS_FRAME_TYPE_BINARY, written);
487  }
488  }
489 #endif
490  //Unknown transport protocol?
491  else
492  {
493  //Report an error
494  error = ERROR_INVALID_PROTOCOL;
495  }
496 
497  //Return status code
498  return error;
499 }
500 
501 
502 /**
503  * @brief Receive data using the relevant transport protocol
504  * @param[in] context Pointer to the MQTT client context
505  * @param[out] data Buffer into which received data will be placed
506  * @param[in] size Maximum number of bytes that can be received
507  * @param[out] received Number of bytes that have been received
508  * @param[in] flags Set of flags that influences the behavior of this function
509  * @return Error code
510  **/
511 
513  void *data, size_t size, size_t *received, uint_t flags)
514 {
515  error_t error;
516 
517  //No data has been read yet
518  *received = 0;
519 
520  //TCP transport protocol?
521  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
522  {
523  //Set timeout
524  error = socketSetTimeout(context->socket, context->settings.timeout);
525 
526  //Check status code
527  if(!error)
528  {
529  //Receive data
530  error = socketReceive(context->socket, data, size, received, flags);
531  }
532  }
533 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
534  //TLS transport protocol?
535  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
536  {
537  //Set timeout
538  error = socketSetTimeout(context->socket, context->settings.timeout);
539 
540  //Check status code
541  if(!error)
542  {
543  //Receive data
544  error = tlsRead(context->tlsContext, data, size, received, flags);
545  }
546  }
547 #endif
548 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
549  //WebSocket transport protocol?
550  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS ||
551  context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
552  {
554 
555  //Set timeout
556  error = webSocketSetTimeout(context->webSocket, context->settings.timeout);
557 
558  //Check status code
559  if(!error)
560  {
561  //Receive data
562  error = webSocketReceive(context->webSocket, data, size, &type, received);
563  }
564 
565  //Check status code
566  if(!error)
567  {
568  //MQTT control packets must be sent in WebSocket binary data frames. If
569  //any other type of data frame is received the recipient must close the
570  //network connection
572  error = ERROR_INVALID_TYPE;
573  }
574  }
575 #endif
576  //Unknown transport protocol?
577  else
578  {
579  //Report an error
580  error = ERROR_INVALID_PROTOCOL;
581  }
582 
583  //Return status code
584  return error;
585 }
586 
587 
588 /**
589  * @brief Wait for incoming data
590  * @param[in] context Pointer to the MQTT client context
591  * @param[in] timeout Maximum time to wait before returning
592  * @return Error code
593  **/
594 
596 {
597  uint_t event;
598 
599  //TCP transport protocol?
600  if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TCP)
601  {
602  //Get exclusive access
604  //Wait for some data to be available for reading
605  event = tcpWaitForEvents(context->socket, SOCKET_EVENT_RX_READY, timeout);
606  //Release exclusive access
608  }
609 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
610  //TLS transport protocol?
611  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_TLS)
612  {
613  //Sanity check
614  if(context->tlsContext == NULL)
615  return ERROR_FAILURE;
616 
617  //Check whether some data is pending in the receive buffer
618  if(context->tlsContext->rxBufferLen > 0)
619  {
620  //No need to poll the underlying socket for incoming traffic...
621  event = SOCKET_EVENT_RX_READY;
622  }
623  else
624  {
625  //Get exclusive access
627  //Wait for some data to be available for reading
628  event = tcpWaitForEvents(context->socket, SOCKET_EVENT_RX_READY, timeout);
629  //Release exclusive access
631  }
632  }
633 #endif
634 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
635  //WebSocket transport protocol?
636  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WS)
637  {
638  //Sanity check
639  if(context->webSocket == NULL)
640  return ERROR_FAILURE;
641 
642  //Get exclusive access
644  //Wait for some data to be available for reading
645  event = tcpWaitForEvents(context->webSocket->socket, SOCKET_EVENT_RX_READY, timeout);
646  //Release exclusive access
648  }
649 #endif
650 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED && WEB_SOCKET_TLS_SUPPORT)
651  //Secure WebSocket transport protocol?
652  else if(context->settings.transportProtocol == MQTT_TRANSPORT_PROTOCOL_WSS)
653  {
654  //Sanity check
655  if(context->webSocket == NULL || context->webSocket->tlsContext == NULL)
656  return ERROR_FAILURE;
657 
658  //Check whether some data is pending in the receive buffer
659  if(context->webSocket->tlsContext->rxBufferLen > 0)
660  {
661  //No need to poll the underlying socket for incoming traffic...
662  event = SOCKET_EVENT_RX_READY;
663  }
664  else
665  {
666  //Get exclusive access
668  //Wait for some data to be available for reading
669  event = tcpWaitForEvents(context->webSocket->socket, SOCKET_EVENT_RX_READY, timeout);
670  //Release exclusive access
672  }
673  }
674 #endif
675  //Unknown transport protocol?
676  else
677  {
678  //Report an error
679  return ERROR_INVALID_PROTOCOL;
680  }
681 
682  //Check whether some data is available for reading
683  if(event == SOCKET_EVENT_RX_READY)
684  return NO_ERROR;
685  else
686  return ERROR_TIMEOUT;
687 }
688 
689 #endif
error_t socketSend(Socket *socket, const void *data, size_t length, size_t *written, uint_t flags)
Send data to a connected socket.
Definition: socket.c:514
TlsContext * tlsInit(void)
TLS context initialization.
Definition: tls.c:65
uint8_t length
Definition: dtls_misc.h:149
void mqttClientCloseConnection(MqttClientContext *context)
Close network connection.
error_t mqttClientEstablishConnection(MqttClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish network connection.
error_t tlsSetConnectionEnd(TlsContext *context, TlsConnectionEnd entity)
Set operation mode (client or server)
Definition: tls.c:312
error_t webSocketReceive(WebSocket *webSocket, void *data, size_t size, WebSocketFrameType *type, size_t *received)
Receive data from a WebSocket connection.
Definition: web_socket.c:1136
IP network address.
Definition: ip.h:71
error_t webSocketConnect(WebSocket *webSocket, const IpAddr *serverIpAddr, uint16_t serverPort, const char_t *uri)
Establish a WebSocket connection.
Definition: web_socket.c:404
void socketClose(Socket *socket)
Close an existing socket.
Definition: socket.c:822
error_t mqttClientSendData(MqttClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send data using the relevant transport protocol.
error_t mqttClientOpenConnection(MqttClientContext *context)
Open network connection.
error_t webSocketSetTimeout(WebSocket *webSocket, systime_t timeout)
Set timeout value for blocking operations.
Definition: web_socket.c:257
error_t webSocketSend(WebSocket *webSocket, const void *data, size_t length, WebSocketFrameType type, size_t *written)
Transmit data over the WebSocket connection.
Definition: web_socket.c:951
error_t mqttClientWaitForData(MqttClientContext *context, systime_t timeout)
Wait for incoming data.
error_t tlsRestoreSessionState(TlsContext *context, const TlsSessionState *session)
Restore TLS session.
Definition: tls.c:2585
error_t webSocketSetSubProtocol(WebSocket *webSocket, const char_t *subProtocol)
Set the sub-protocol header field.
Definition: web_socket.c:324
error_t tlsShutdown(TlsContext *context)
Gracefully close TLS session.
Definition: tls.c:2112
Helper functions for TCP.
error_t webSocketBindToInterface(WebSocket *webSocket, NetInterface *interface)
Bind the WebSocket to a particular network interface.
Definition: web_socket.c:380
#define tlsSetSocket(context, socket)
Definition: tls.h:823
Helper functions for MQTT client.
char_t type
error_t
Error codes.
Definition: error.h:42
Transport protocol abstraction layer.
WebSocket * webSocketOpen(void)
Create a WebSocket.
Definition: web_socket.c:95
error_t socketReceive(Socket *socket, void *data, size_t size, size_t *received, uint_t flags)
Receive data from a connected socket.
Definition: socket.c:609
error_t(* WebSocketTlsInitCallback)(WebSocket *webSocket, TlsContext *tlsContext)
TLS initialization callback function.
Definition: web_socket.h:343
WebSocketFrameType
WebSocket frame types.
Definition: web_socket.h:262
Generic error code.
Definition: error.h:45
OsMutex netMutex
Definition: net.c:75
error_t socketConnect(Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort)
Establish a connection to a specified socket.
Definition: socket.c:381
MQTT packet parsing and formatting.
error_t socketShutdown(Socket *socket, uint_t how)
Disable reception, transmission, or both.
Definition: socket.c:785
error_t tlsSaveSessionState(const TlsContext *context, TlsSessionState *session)
Save TLS session.
Definition: tls.c:2427
Socket * socketOpen(uint_t type, uint_t protocol)
Create a socket (UDP or TCP)
Definition: socket.c:95
error_t tlsRead(TlsContext *context, void *data, size_t size, size_t *received, uint_t flags)
Receive application data from a the remote host using TLS.
Definition: tls.c:1798
#define socketBindToInterface
Definition: net_legacy.h:270
error_t mqttClientShutdownConnection(MqttClientContext *context)
Shutdown network connection.
error_t mqttClientReceiveData(MqttClientContext *context, void *data, size_t size, size_t *received, uint_t flags)
Receive data using the relevant transport protocol.
uint8_t flags
Definition: tcp.h:314
error_t webSocketRegisterTlsInitCallback(WebSocket *webSocket, WebSocketTlsInitCallback callback)
Register TLS initialization callback function.
Definition: web_socket.c:233
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void webSocketClose(WebSocket *webSocket)
Close a WebSocket connection.
Definition: web_socket.c:1555
error_t tlsWrite(TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send application data to the remote host using TLS.
Definition: tls.c:1663
WebSocket protocol.
Definition: mqtt_common.h:78
void tlsFree(TlsContext *context)
Release TLS context.
Definition: tls.c:2272
error_t webSocketShutdown(WebSocket *webSocket)
Gracefully close a WebSocket connection.
Definition: web_socket.c:1439
#define MqttClientContext
Definition: mqtt_client.h:142
error_t webSocketSetHost(WebSocket *webSocket, const char_t *host)
Set the domain name of the server (for virtual hosting)
Definition: web_socket.c:282
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
uint8_t data[]
Definition: dtls_misc.h:176
error_t socketSetTimeout(Socket *socket, systime_t timeout)
Set timeout value for blocking operations.
Definition: socket.c:219
error_t tlsConnect(TlsContext *context)
Initiate the TLS handshake.
Definition: tls.c:1572
uint32_t systime_t
Definition: compiler_port.h:46
Success.
Definition: error.h:44
Debugging facilities.
uint_t tcpWaitForEvents(Socket *socket, uint_t eventMask, systime_t timeout)
Wait for a particular TCP event.
Definition: tcp_misc.c:1885
MQTT client.