open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
mqtt.h File Reference
#include <mqtt_pal.h>

Go to the source code of this file.

Data Structures

struct  mqtt_fixed_header
 
struct  mqtt_response_connack
 
struct  mqtt_response_publish
 
struct  mqtt_response_puback
 
struct  mqtt_response_pubrec
 
struct  mqtt_response_pubrel
 
struct  mqtt_response_pubcomp
 
struct  mqtt_response_suback
 
struct  mqtt_response_unsuback
 
struct  mqtt_response_pingresp
 
struct  mqtt_response
 
struct  mqtt_queued_message
 
struct  mqtt_message_queue
 
struct  mqtt_client
 

Macros

#define MQTT_PROTOCOL_LEVEL   0x04
 
#define __ALL_MQTT_ERRORS(MQTT_ERROR)
 
#define GENERATE_ENUM(ENUM)   ENUM,
 
#define GENERATE_STRING(STRING)   #STRING,
 
#define __mqtt_packed_cstrlen(x)   (2 + (unsigned int)strlen(x))
 
#define MQTT_SUBSCRIBE_REQUEST_MAX_NUM_TOPICS   8
 
#define MQTT_UNSUBSCRIBE_REQUEST_MAX_NUM_TOPICS   8
 
#define mqtt_mq_get(mq_ptr, index)   (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - 1 - index)
 
#define mqtt_mq_length(mq_ptr)   (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - (mq_ptr)->queue_tail)
 
#define mqtt_mq_currsz(mq_ptr)   (mq_ptr->curr >= (uint8_t*) ((mq_ptr)->queue_tail - 1)) ? 0 : ((uint8_t*) ((mq_ptr)->queue_tail - 1)) - (mq_ptr)->curr
 

Enumerations

enum  MQTTControlPacketType
 
enum  MQTTErrors
 
enum  MQTTConnackReturnCode
 
enum  MQTTSubackReturnCodes
 
enum  MQTTConnectFlags
 
enum  MQTTPublishFlags
 
enum  MQTTQueuedMessageState
 

Functions

const char * mqtt_error_str (enum MQTTErrors error)
 
ssize_t __mqtt_pack_uint16 (uint8_t *buf, uint16_t integer)
 
uint16_t __mqtt_unpack_uint16 (const uint8_t *buf)
 
ssize_t __mqtt_pack_str (uint8_t *buf, const char *str)
 
ssize_t mqtt_unpack_fixed_header (struct mqtt_response *response, const uint8_t *buf, size_t bufsz)
 
ssize_t mqtt_unpack_connack_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 
ssize_t mqtt_unpack_publish_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 
ssize_t mqtt_unpack_pubxxx_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 
ssize_t mqtt_unpack_suback_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 
ssize_t mqtt_unpack_response (struct mqtt_response *response, const uint8_t *buf, size_t bufsz)
 
ssize_t mqtt_pack_fixed_header (uint8_t *buf, size_t bufsz, const struct mqtt_fixed_header *fixed_header)
 
ssize_t mqtt_pack_connection_request (uint8_t *buf, size_t bufsz, const char *client_id, const char *will_topic, const void *will_message, size_t will_message_size, const char *user_name, const char *password, uint8_t connect_flags, uint16_t keep_alive)
 
ssize_t mqtt_pack_publish_request (uint8_t *buf, size_t bufsz, const char *topic_name, uint16_t packet_id, const void *application_message, size_t application_message_size, uint8_t publish_flags)
 
ssize_t mqtt_pack_pubxxx_request (uint8_t *buf, size_t bufsz, enum MQTTControlPacketType control_type, uint16_t packet_id)
 
ssize_t mqtt_pack_subscribe_request (uint8_t *buf, size_t bufsz, unsigned int packet_id,...)
 
ssize_t mqtt_pack_unsubscribe_request (uint8_t *buf, size_t bufsz, unsigned int packet_id,...)
 
ssize_t mqtt_pack_ping_request (uint8_t *buf, size_t bufsz)
 
ssize_t mqtt_pack_disconnect (uint8_t *buf, size_t bufsz)
 
void mqtt_mq_init (struct mqtt_message_queue *mq, void *buf, size_t bufsz)
 
void mqtt_mq_clean (struct mqtt_message_queue *mq)
 
struct mqtt_queued_messagemqtt_mq_register (struct mqtt_message_queue *mq, size_t nbytes)
 
struct mqtt_queued_messagemqtt_mq_find (struct mqtt_message_queue *mq, enum MQTTControlPacketType control_type, uint16_t *packet_id)
 
uint16_t __mqtt_next_pid (struct mqtt_client *client)
 
ssize_t __mqtt_send (struct mqtt_client *client)
 
ssize_t __mqtt_recv (struct mqtt_client *client)
 
enum MQTTErrors mqtt_sync (struct mqtt_client *client)
 
enum MQTTErrors mqtt_init (struct mqtt_client *client, mqtt_pal_socket_handle sockfd, uint8_t *sendbuf, size_t sendbufsz, uint8_t *recvbuf, size_t recvbufsz, void(*publish_response_callback)(void **state, struct mqtt_response_publish *publish))
 
void mqtt_init_reconnect (struct mqtt_client *client, void(*reconnect_callback)(struct mqtt_client *client, void **state), void *reconnect_state, void(*publish_response_callback)(void **state, struct mqtt_response_publish *publish))
 
void mqtt_reinit (struct mqtt_client *client, mqtt_pal_socket_handle socketfd, uint8_t *sendbuf, size_t sendbufsz, uint8_t *recvbuf, size_t recvbufsz)
 
enum MQTTErrors mqtt_connect (struct mqtt_client *client, const char *client_id, const char *will_topic, const void *will_message, size_t will_message_size, const char *user_name, const char *password, uint8_t connect_flags, uint16_t keep_alive)
 
enum MQTTErrors mqtt_publish (struct mqtt_client *client, const char *topic_name, const void *application_message, size_t application_message_size, uint8_t publish_flags)
 
ssize_t __mqtt_puback (struct mqtt_client *client, uint16_t packet_id)
 
ssize_t __mqtt_pubrec (struct mqtt_client *client, uint16_t packet_id)
 
ssize_t __mqtt_pubrel (struct mqtt_client *client, uint16_t packet_id)
 
ssize_t __mqtt_pubcomp (struct mqtt_client *client, uint16_t packet_id)
 
enum MQTTErrors mqtt_subscribe (struct mqtt_client *client, const char *topic_name, int max_qos_level)
 
enum MQTTErrors mqtt_unsubscribe (struct mqtt_client *client, const char *topic_name)
 
enum MQTTErrors mqtt_ping (struct mqtt_client *client)
 
enum MQTTErrors __mqtt_ping (struct mqtt_client *client)
 
enum MQTTErrors mqtt_disconnect (struct mqtt_client *client)
 
enum MQTTErrors mqtt_reconnect (struct mqtt_client *client)
 

Macro Definition Documentation

◆ MQTT_PROTOCOL_LEVEL

#define MQTT_PROTOCOL_LEVEL   0x04

Definition at line 80 of file mqtt.h.

◆ __ALL_MQTT_ERRORS

#define __ALL_MQTT_ERRORS ( MQTT_ERROR)
Value:
MQTT_ERROR(MQTT_ERROR_NULLPTR) \
@ MQTT_ERROR_CONNECTION_CLOSED
Definition mqtt.h:125
@ MQTT_ERROR_RESPONSE_INVALID_CONTROL_TYPE
Definition mqtt.h:125
@ MQTT_ERROR_MALFORMED_REQUEST
Definition mqtt.h:125
@ MQTT_ERROR_CONNECT_NOT_CALLED
Definition mqtt.h:125
@ MQTT_ERROR_SEND_BUFFER_IS_FULL
Definition mqtt.h:125
@ MQTT_ERROR_MALFORMED_RESPONSE
Definition mqtt.h:125
@ MQTT_ERROR_NULLPTR
Definition mqtt.h:125
@ MQTT_ERROR_UNSUBSCRIBE_TOO_MANY_TOPICS
Definition mqtt.h:125
@ MQTT_ERROR_CONNECTION_REFUSED
Definition mqtt.h:125
@ MQTT_ERROR_RECV_BUFFER_TOO_SMALL
Definition mqtt.h:125
@ MQTT_ERROR_SOCKET_ERROR
Definition mqtt.h:125
@ MQTT_ERROR_CONTROL_INVALID_FLAGS
Definition mqtt.h:125
@ MQTT_ERROR_ACK_OF_UNKNOWN
Definition mqtt.h:125
@ MQTT_ERROR_CLEAN_SESSION_IS_REQUIRED
Definition mqtt.h:125
@ MQTT_ERROR_INITIAL_RECONNECT
Definition mqtt.h:125
@ MQTT_ERROR_CONTROL_FORBIDDEN_TYPE
Definition mqtt.h:125
@ MQTT_ERROR_SUBSCRIBE_FAILED
Definition mqtt.h:125
@ MQTT_ERROR_CONNECT_CLIENT_ID_REFUSED
Definition mqtt.h:125
@ MQTT_ERROR_SUBSCRIBE_TOO_MANY_TOPICS
Definition mqtt.h:125
@ MQTT_ERROR_CONNACK_FORBIDDEN_CODE
Definition mqtt.h:125
@ MQTT_ERROR_PUBLISH_FORBIDDEN_QOS
Definition mqtt.h:125
@ MQTT_ERROR_CONNECT_NULL_WILL_MESSAGE
Definition mqtt.h:125
@ MQTT_ERROR_CONNECT_FORBIDDEN_WILL_QOS
Definition mqtt.h:125
@ MQTT_ERROR_RECONNECTING
Definition mqtt.h:125
@ MQTT_ERROR_CONTROL_WRONG_TYPE
Definition mqtt.h:125
@ MQTT_ERROR_NOT_IMPLEMENTED
Definition mqtt.h:125
@ MQTT_ERROR_INVALID_REMAINING_LENGTH
Definition mqtt.h:125
@ MQTT_ERROR_CONNACK_FORBIDDEN_FLAGS
Definition mqtt.h:125

Definition at line 83 of file mqtt.h.

◆ GENERATE_ENUM

#define GENERATE_ENUM ( ENUM)    ENUM,

todo: add more connection refused errors

Definition at line 116 of file mqtt.h.

◆ GENERATE_STRING

#define GENERATE_STRING ( STRING)    #STRING,

Definition at line 119 of file mqtt.h.

◆ __mqtt_packed_cstrlen

#define __mqtt_packed_cstrlen ( x)    (2 + (unsigned int)strlen(x))

Definition at line 142 of file mqtt.h.

◆ MQTT_SUBSCRIBE_REQUEST_MAX_NUM_TOPICS

#define MQTT_SUBSCRIBE_REQUEST_MAX_NUM_TOPICS   8

Definition at line 337 of file mqtt.h.

◆ MQTT_UNSUBSCRIBE_REQUEST_MAX_NUM_TOPICS

#define MQTT_UNSUBSCRIBE_REQUEST_MAX_NUM_TOPICS   8

Definition at line 345 of file mqtt.h.

◆ mqtt_mq_get

#define mqtt_mq_get ( mq_ptr,
index )   (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - 1 - index)

Definition at line 419 of file mqtt.h.

◆ mqtt_mq_length

#define mqtt_mq_length ( mq_ptr)    (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - (mq_ptr)->queue_tail)

Definition at line 422 of file mqtt.h.

◆ mqtt_mq_currsz

#define mqtt_mq_currsz ( mq_ptr)    (mq_ptr->curr >= (uint8_t*) ((mq_ptr)->queue_tail - 1)) ? 0 : ((uint8_t*) ((mq_ptr)->queue_tail - 1)) - (mq_ptr)->curr

Definition at line 425 of file mqtt.h.

Enumeration Type Documentation

◆ MQTTControlPacketType

Enumerator
MQTT_CONTROL_CONNECT 
MQTT_CONTROL_CONNACK 
MQTT_CONTROL_PUBLISH 
MQTT_CONTROL_PUBACK 
MQTT_CONTROL_PUBREC 
MQTT_CONTROL_PUBREL 
MQTT_CONTROL_PUBCOMP 
MQTT_CONTROL_SUBSCRIBE 
MQTT_CONTROL_SUBACK 
MQTT_CONTROL_UNSUBSCRIBE 
MQTT_CONTROL_UNSUBACK 
MQTT_CONTROL_PINGREQ 
MQTT_CONTROL_PINGRESP 
MQTT_CONTROL_DISCONNECT 

Definition at line 50 of file mqtt.h.

◆ MQTTErrors

enum MQTTErrors
Enumerator
MQTT_ERROR_UNKNOWN 
MQTT_ERROR_NULLPTR 
MQTT_ERROR_CONTROL_FORBIDDEN_TYPE 
MQTT_ERROR_CONTROL_INVALID_FLAGS 
MQTT_ERROR_CONTROL_WRONG_TYPE 
MQTT_ERROR_CONNECT_CLIENT_ID_REFUSED 
MQTT_ERROR_CONNECT_NULL_WILL_MESSAGE 
MQTT_ERROR_CONNECT_FORBIDDEN_WILL_QOS 
MQTT_ERROR_CONNACK_FORBIDDEN_FLAGS 
MQTT_ERROR_CONNACK_FORBIDDEN_CODE 
MQTT_ERROR_PUBLISH_FORBIDDEN_QOS 
MQTT_ERROR_SUBSCRIBE_TOO_MANY_TOPICS 
MQTT_ERROR_MALFORMED_RESPONSE 
MQTT_ERROR_UNSUBSCRIBE_TOO_MANY_TOPICS 
MQTT_ERROR_RESPONSE_INVALID_CONTROL_TYPE 
MQTT_ERROR_CONNECT_NOT_CALLED 
MQTT_ERROR_SEND_BUFFER_IS_FULL 
MQTT_ERROR_SOCKET_ERROR 
MQTT_ERROR_MALFORMED_REQUEST 
MQTT_ERROR_RECV_BUFFER_TOO_SMALL 
MQTT_ERROR_ACK_OF_UNKNOWN 
MQTT_ERROR_NOT_IMPLEMENTED 
MQTT_ERROR_CONNECTION_REFUSED 
MQTT_ERROR_SUBSCRIBE_FAILED 
MQTT_ERROR_CONNECTION_CLOSED 
MQTT_ERROR_INITIAL_RECONNECT 
MQTT_ERROR_INVALID_REMAINING_LENGTH 
MQTT_ERROR_CLEAN_SESSION_IS_REQUIRED 
MQTT_ERROR_RECONNECTING 
MQTT_OK 

Definition at line 123 of file mqtt.h.

◆ MQTTConnackReturnCode

RESPONSES.

Enumerator
MQTT_CONNACK_ACCEPTED 
MQTT_CONNACK_REFUSED_PROTOCOL_VERSION 
MQTT_CONNACK_REFUSED_IDENTIFIER_REJECTED 
MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE 
MQTT_CONNACK_REFUSED_BAD_USER_NAME_OR_PASSWORD 
MQTT_CONNACK_REFUSED_NOT_AUTHORIZED 

Definition at line 147 of file mqtt.h.

◆ MQTTSubackReturnCodes

Enumerator
MQTT_SUBACK_SUCCESS_MAX_QOS_0 
MQTT_SUBACK_SUCCESS_MAX_QOS_1 
MQTT_SUBACK_SUCCESS_MAX_QOS_2 
MQTT_SUBACK_FAILURE 

Definition at line 217 of file mqtt.h.

◆ MQTTConnectFlags

Enumerator
MQTT_CONNECT_RESERVED 
MQTT_CONNECT_CLEAN_SESSION 
MQTT_CONNECT_WILL_FLAG 
MQTT_CONNECT_WILL_QOS_0 
MQTT_CONNECT_WILL_QOS_1 
MQTT_CONNECT_WILL_QOS_2 
MQTT_CONNECT_WILL_RETAIN 
MQTT_CONNECT_PASSWORD 
MQTT_CONNECT_USER_NAME 

Definition at line 290 of file mqtt.h.

◆ MQTTPublishFlags

Enumerator
MQTT_PUBLISH_DUP 
MQTT_PUBLISH_QOS_0 
MQTT_PUBLISH_QOS_1 
MQTT_PUBLISH_QOS_2 
MQTT_PUBLISH_QOS_MASK 
MQTT_PUBLISH_RETAIN 

Definition at line 314 of file mqtt.h.

◆ MQTTQueuedMessageState

Enumerator
MQTT_QUEUED_UNSENT 
MQTT_QUEUED_AWAITING_ACK 
MQTT_QUEUED_COMPLETE 

Definition at line 360 of file mqtt.h.

Function Documentation

◆ mqtt_error_str()

const char * mqtt_error_str ( enum MQTTErrors error)

◆ __mqtt_pack_uint16()

ssize_t __mqtt_pack_uint16 ( uint8_t * buf,
uint16_t integer )

◆ __mqtt_unpack_uint16()

uint16_t __mqtt_unpack_uint16 ( const uint8_t * buf)

◆ __mqtt_pack_str()

ssize_t __mqtt_pack_str ( uint8_t * buf,
const char * str )

◆ mqtt_unpack_fixed_header()

ssize_t mqtt_unpack_fixed_header ( struct mqtt_response * response,
const uint8_t * buf,
size_t bufsz )

◆ mqtt_unpack_connack_response()

ssize_t mqtt_unpack_connack_response ( struct mqtt_response * mqtt_response,
const uint8_t * buf )

◆ mqtt_unpack_publish_response()

ssize_t mqtt_unpack_publish_response ( struct mqtt_response * mqtt_response,
const uint8_t * buf )

◆ mqtt_unpack_pubxxx_response()

ssize_t mqtt_unpack_pubxxx_response ( struct mqtt_response * mqtt_response,
const uint8_t * buf )

◆ mqtt_unpack_suback_response()

ssize_t mqtt_unpack_suback_response ( struct mqtt_response * mqtt_response,
const uint8_t * buf )

◆ mqtt_unpack_response()

ssize_t mqtt_unpack_response ( struct mqtt_response * response,
const uint8_t * buf,
size_t bufsz )

◆ mqtt_pack_fixed_header()

ssize_t mqtt_pack_fixed_header ( uint8_t * buf,
size_t bufsz,
const struct mqtt_fixed_header * fixed_header )

REQUESTS.

◆ mqtt_pack_connection_request()

ssize_t mqtt_pack_connection_request ( uint8_t * buf,
size_t bufsz,
const char * client_id,
const char * will_topic,
const void * will_message,
size_t will_message_size,
const char * user_name,
const char * password,
uint8_t connect_flags,
uint16_t keep_alive )

◆ mqtt_pack_publish_request()

ssize_t mqtt_pack_publish_request ( uint8_t * buf,
size_t bufsz,
const char * topic_name,
uint16_t packet_id,
const void * application_message,
size_t application_message_size,
uint8_t publish_flags )

◆ mqtt_pack_pubxxx_request()

ssize_t mqtt_pack_pubxxx_request ( uint8_t * buf,
size_t bufsz,
enum MQTTControlPacketType control_type,
uint16_t packet_id )

◆ mqtt_pack_subscribe_request()

ssize_t mqtt_pack_subscribe_request ( uint8_t * buf,
size_t bufsz,
unsigned int packet_id,
... )

◆ mqtt_pack_unsubscribe_request()

ssize_t mqtt_pack_unsubscribe_request ( uint8_t * buf,
size_t bufsz,
unsigned int packet_id,
... )

◆ mqtt_pack_ping_request()

ssize_t mqtt_pack_ping_request ( uint8_t * buf,
size_t bufsz )

◆ mqtt_pack_disconnect()

ssize_t mqtt_pack_disconnect ( uint8_t * buf,
size_t bufsz )

◆ mqtt_mq_init()

void mqtt_mq_init ( struct mqtt_message_queue * mq,
void * buf,
size_t bufsz )

◆ mqtt_mq_clean()

void mqtt_mq_clean ( struct mqtt_message_queue * mq)

◆ mqtt_mq_register()

struct mqtt_queued_message * mqtt_mq_register ( struct mqtt_message_queue * mq,
size_t nbytes )

◆ mqtt_mq_find()

struct mqtt_queued_message * mqtt_mq_find ( struct mqtt_message_queue * mq,
enum MQTTControlPacketType control_type,
uint16_t * packet_id )

◆ __mqtt_next_pid()

uint16_t __mqtt_next_pid ( struct mqtt_client * client)

◆ __mqtt_send()

ssize_t __mqtt_send ( struct mqtt_client * client)

◆ __mqtt_recv()

ssize_t __mqtt_recv ( struct mqtt_client * client)

◆ mqtt_sync()

enum MQTTErrors mqtt_sync ( struct mqtt_client * client)

◆ mqtt_init()

enum MQTTErrors mqtt_init ( struct mqtt_client * client,
mqtt_pal_socket_handle sockfd,
uint8_t * sendbuf,
size_t sendbufsz,
uint8_t * recvbuf,
size_t recvbufsz,
void(* publish_response_callback )(void **state, struct mqtt_response_publish *publish) )

◆ mqtt_init_reconnect()

void mqtt_init_reconnect ( struct mqtt_client * client,
void(* reconnect_callback )(struct mqtt_client *client, void **state),
void * reconnect_state,
void(* publish_response_callback )(void **state, struct mqtt_response_publish *publish) )

◆ mqtt_reinit()

void mqtt_reinit ( struct mqtt_client * client,
mqtt_pal_socket_handle socketfd,
uint8_t * sendbuf,
size_t sendbufsz,
uint8_t * recvbuf,
size_t recvbufsz )

◆ mqtt_connect()

enum MQTTErrors mqtt_connect ( struct mqtt_client * client,
const char * client_id,
const char * will_topic,
const void * will_message,
size_t will_message_size,
const char * user_name,
const char * password,
uint8_t connect_flags,
uint16_t keep_alive )

◆ mqtt_publish()

enum MQTTErrors mqtt_publish ( struct mqtt_client * client,
const char * topic_name,
const void * application_message,
size_t application_message_size,
uint8_t publish_flags )

todo: will_message should be a void*

◆ __mqtt_puback()

ssize_t __mqtt_puback ( struct mqtt_client * client,
uint16_t packet_id )

◆ __mqtt_pubrec()

ssize_t __mqtt_pubrec ( struct mqtt_client * client,
uint16_t packet_id )

◆ __mqtt_pubrel()

ssize_t __mqtt_pubrel ( struct mqtt_client * client,
uint16_t packet_id )

◆ __mqtt_pubcomp()

ssize_t __mqtt_pubcomp ( struct mqtt_client * client,
uint16_t packet_id )

◆ mqtt_subscribe()

enum MQTTErrors mqtt_subscribe ( struct mqtt_client * client,
const char * topic_name,
int max_qos_level )

◆ mqtt_unsubscribe()

enum MQTTErrors mqtt_unsubscribe ( struct mqtt_client * client,
const char * topic_name )

◆ mqtt_ping()

enum MQTTErrors mqtt_ping ( struct mqtt_client * client)

◆ __mqtt_ping()

enum MQTTErrors __mqtt_ping ( struct mqtt_client * client)

◆ mqtt_disconnect()

enum MQTTErrors mqtt_disconnect ( struct mqtt_client * client)

◆ mqtt_reconnect()

enum MQTTErrors mqtt_reconnect ( struct mqtt_client * client)