Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mqtt_sn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 René Beckmann
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
22#ifndef ZEPHYR_INCLUDE_NET_MQTT_SN_H_
23#define ZEPHYR_INCLUDE_NET_MQTT_SN_H_
24
25#include <stddef.h>
26
27#include <zephyr/net_buf.h>
28#include <zephyr/types.h>
29
30#include <sys/types.h>
31
32#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
33#include <zephyr/net/net_ip.h>
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
50
73
83
89
99#define MQTT_SN_DATA_STRING_LITERAL(literal) ((struct mqtt_sn_data){literal, sizeof(literal) - 1})
100
108#define MQTT_SN_DATA_BYTES(...) \
109 ((struct mqtt_sn_data) { (uint8_t[]){ __VA_ARGS__ }, sizeof((uint8_t[]){ __VA_ARGS__ })})
110
122
137
147
148struct mqtt_sn_client;
149
158typedef void (*mqtt_sn_evt_cb_t)(struct mqtt_sn_client *client, const struct mqtt_sn_evt *evt);
159
173 int (*init)(struct mqtt_sn_transport *transport);
174
180 void (*deinit)(struct mqtt_sn_transport *transport);
181
185 int (*msg_send)(struct mqtt_sn_client *client, void *buf, size_t sz);
186
192 ssize_t (*recv)(struct mqtt_sn_client *client, void *buffer, size_t length);
193
204 int (*poll)(struct mqtt_sn_client *client);
205};
206
207#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
211struct mqtt_sn_transport_udp {
213 struct mqtt_sn_transport tp;
214
216 int sock;
217
219 struct sockaddr gwaddr;
220 socklen_t gwaddrlen;
221};
222
223#define UDP_TRANSPORT(transport) CONTAINER_OF(transport, struct mqtt_sn_transport_udp, tp)
224
232int mqtt_sn_transport_udp_init(struct mqtt_sn_transport_udp *udp, struct sockaddr *gwaddr,
233 socklen_t addrlen);
234#endif
235
292
307int mqtt_sn_client_init(struct mqtt_sn_client *client, const struct mqtt_sn_data *client_id,
308 struct mqtt_sn_transport *transport, mqtt_sn_evt_cb_t evt_cb, void *tx,
309 size_t txsz, void *rx, size_t rxsz);
310
319
329int mqtt_sn_connect(struct mqtt_sn_client *client, bool will, bool clean_session);
330
339
348int mqtt_sn_sleep(struct mqtt_sn_client *client, uint16_t duration);
349
359int mqtt_sn_subscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos,
360 struct mqtt_sn_data *topic_name);
361
371int mqtt_sn_unsubscribe(struct mqtt_sn_client *client, enum mqtt_sn_qos qos,
372 struct mqtt_sn_data *topic_name);
373
387int mqtt_sn_publish(struct mqtt_sn_client *client, enum mqtt_sn_qos qos,
388 struct mqtt_sn_data *topic_name, bool retain, struct mqtt_sn_data *data);
389
400int mqtt_sn_input(struct mqtt_sn_client *client);
401
413 struct mqtt_sn_data *topic_name);
414
415#ifdef __cplusplus
416}
417#endif
418
419#endif /* ZEPHYR_INCLUDE_NET_MQTT_SN_H_ */
420
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
Buffer management.
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
struct mqtt_sn_evt_param::@356 publish
Structure holding publish event details.
enum mqtt_sn_topic_type topic_type
The type of topic for the event.
Definition mqtt_sn.h:132
uint16_t topic_id
The identifier for the topic of the event.
Definition mqtt_sn.h:134