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