22#ifndef ZEPHYR_INCLUDE_NET_MQTT_SN_H_
23#define ZEPHYR_INCLUDE_NET_MQTT_SN_H_
32#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
99#define MQTT_SN_DATA_STRING_LITERAL(literal) ((struct mqtt_sn_data){literal, sizeof(literal) - 1})
108#define MQTT_SN_DATA_BYTES(...) \
109 ((struct mqtt_sn_data) { (uint8_t[]){ __VA_ARGS__ }, sizeof((uint8_t[]){ __VA_ARGS__ })})
207#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
211struct mqtt_sn_transport_udp {
223#define UDP_TRANSPORT(transport) CONTAINER_OF(transport, struct mqtt_sn_transport_udp, tp)
232int mqtt_sn_transport_udp_init(
struct mqtt_sn_transport_udp *udp,
struct sockaddr *gwaddr,
309 size_t txsz,
void *rx,
size_t rxsz);
size_t socklen_t
Length of a socket address.
Definition net_ip.h:171
int mqtt_sn_unsubscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name)
Unsubscribe from a topic.
int mqtt_sn_publish(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name, bool retain, struct mqtt_sn_data *data)
Publish a value.
void mqtt_sn_client_deinit(struct mqtt_sn_client *client)
Deinitialize the client.
mqtt_sn_qos
Quality of Service.
Definition mqtt_sn.h:44
int mqtt_sn_connect(struct mqtt_sn_client *client, bool will, bool clean_session)
Connect the client.
int mqtt_sn_subscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name)
Subscribe to a given topic.
mqtt_sn_evt_type
Event types that can be emitted by the library.
Definition mqtt_sn.h:114
mqtt_sn_return_code
MQTT-SN return codes.
Definition mqtt_sn.h:77
int mqtt_sn_disconnect(struct mqtt_sn_client *client)
Disconnect the client.
mqtt_sn_topic_type
MQTT-SN topic types.
Definition mqtt_sn.h:54
int mqtt_sn_get_topic_name(struct mqtt_sn_client *client, uint16_t id, struct mqtt_sn_data *topic_name)
Get topic name by topic ID.
int mqtt_sn_client_init(struct mqtt_sn_client *client, const struct mqtt_sn_data *client_id, struct mqtt_sn_transport *transport, mqtt_sn_evt_cb_t evt_cb, void *tx, size_t txsz, void *rx, size_t rxsz)
Initialize a client.
void(* mqtt_sn_evt_cb_t)(struct mqtt_sn_client *client, const struct mqtt_sn_evt *evt)
Asynchronous event notification callback registered by the application.
Definition mqtt_sn.h:158
int mqtt_sn_sleep(struct mqtt_sn_client *client, uint16_t duration)
Set the client into sleep state.
int mqtt_sn_input(struct mqtt_sn_client *client)
Check the transport for new incoming data.
@ MQTT_SN_QOS_M1
QOS -1.
Definition mqtt_sn.h:48
@ MQTT_SN_QOS_2
QOS 2.
Definition mqtt_sn.h:47
@ MQTT_SN_QOS_1
QOS 1.
Definition mqtt_sn.h:46
@ MQTT_SN_QOS_0
QOS 0.
Definition mqtt_sn.h:45
@ MQTT_SN_EVT_PINGRESP
Received a PINGRESP.
Definition mqtt_sn.h:120
@ MQTT_SN_EVT_CONNECTED
Connected to a gateway.
Definition mqtt_sn.h:115
@ MQTT_SN_EVT_PUBLISH
Received a PUBLISH message.
Definition mqtt_sn.h:119
@ MQTT_SN_EVT_ASLEEP
Entered ASLEEP state.
Definition mqtt_sn.h:117
@ MQTT_SN_EVT_DISCONNECTED
Disconnected.
Definition mqtt_sn.h:116
@ MQTT_SN_EVT_AWAKE
Entered AWAKE state.
Definition mqtt_sn.h:118
@ MQTT_SN_CODE_ACCEPTED
Accepted.
Definition mqtt_sn.h:78
@ MQTT_SN_CODE_REJECTED_CONGESTION
Rejected: congestion.
Definition mqtt_sn.h:79
@ MQTT_SN_CODE_REJECTED_NOTSUP
Rejected: Not Supported.
Definition mqtt_sn.h:81
@ MQTT_SN_CODE_REJECTED_TOPIC_ID
Rejected: Invalid Topic ID.
Definition mqtt_sn.h:80
@ MQTT_SN_TOPIC_TYPE_NORMAL
Normal topic.
Definition mqtt_sn.h:59
@ MQTT_SN_TOPIC_TYPE_PREDEF
Pre-defined topic.
Definition mqtt_sn.h:66
@ MQTT_SN_TOPIC_TYPE_SHORT
Short topic.
Definition mqtt_sn.h:71
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
__SIZE_TYPE__ ssize_t
Definition types.h:28
IPv6 and IPv4 definitions.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
A structure used to submit work after a delay.
Definition kernel.h:3985
Structure describing an MQTT-SN client.
Definition mqtt_sn.h:239
int state
Current state of the MQTT-SN client.
Definition mqtt_sn.h:281
uint16_t next_msg_id
Message ID for the next message to be sent.
Definition mqtt_sn.h:272
uint8_t ping_retries
Number of retries for failed ping attempts.
Definition mqtt_sn.h:287
sys_slist_t publish
List of pending publish messages.
Definition mqtt_sn.h:275
struct net_buf_simple tx
Buffer for outgoing data.
Definition mqtt_sn.h:263
enum mqtt_sn_qos will_qos
Quality of Service for the Will message.
Definition mqtt_sn.h:254
struct k_work_delayable process_work
Delayable work structure for processing MQTT-SN events.
Definition mqtt_sn.h:290
struct mqtt_sn_data client_id
1-23 character unique client ID
Definition mqtt_sn.h:241
struct mqtt_sn_data will_msg
Will message.
Definition mqtt_sn.h:251
sys_slist_t topic
List of registered topics.
Definition mqtt_sn.h:278
mqtt_sn_evt_cb_t evt_cb
Event callback.
Definition mqtt_sn.h:269
bool will_retain
Flag indicating if the will message should be retained by the broker.
Definition mqtt_sn.h:257
struct mqtt_sn_transport * transport
Underlying transport to be used by the client.
Definition mqtt_sn.h:260
struct net_buf_simple rx
Buffer for incoming data.
Definition mqtt_sn.h:266
int64_t last_ping
Timestamp of the last ping request.
Definition mqtt_sn.h:284
struct mqtt_sn_data will_topic
Topic for Will message.
Definition mqtt_sn.h:246
Abstracts memory buffers.
Definition mqtt_sn.h:85
uint16_t size
Size of data, in bytes.
Definition mqtt_sn.h:87
const uint8_t * data
Pointer to data.
Definition mqtt_sn.h:86
MQTT-SN event structure to be handled by the event callback.
Definition mqtt_sn.h:141
union mqtt_sn_evt_param param
Event parameters.
Definition mqtt_sn.h:145
enum mqtt_sn_evt_type type
Event type.
Definition mqtt_sn.h:143
Structure to describe an MQTT-SN transport.
Definition mqtt_sn.h:167
ssize_t(* recv)(struct mqtt_sn_client *client, void *buffer, size_t length)
Will be called by the library when it wants to receive a message.
Definition mqtt_sn.h:192
int(* init)(struct mqtt_sn_transport *transport)
Will be called once on client init to initialize the transport.
Definition mqtt_sn.h:173
int(* poll)(struct mqtt_sn_client *client)
Check if incoming data is available.
Definition mqtt_sn.h:204
int(* msg_send)(struct mqtt_sn_client *client, void *buf, size_t sz)
Will be called by the library when it wants to send a message.
Definition mqtt_sn.h:185
void(* deinit)(struct mqtt_sn_transport *transport)
Will be called on client deinit.
Definition mqtt_sn.h:180
Simple network buffer representation.
Definition net_buf.h:89
Generic sockaddr struct.
Definition net_ip.h:388
Event metadata.
Definition mqtt_sn.h:126
struct mqtt_sn_data data
The payload data associated with the event.
Definition mqtt_sn.h:130
enum mqtt_sn_topic_type topic_type
The type of topic for the event.
Definition mqtt_sn.h:132
struct mqtt_sn_evt_param::@382 publish
Structure holding publish event details.
uint16_t topic_id
The identifier for the topic of the event.
Definition mqtt_sn.h:134