20#ifndef ZEPHYR_INCLUDE_NET_MQTT_SN_H_
21#define ZEPHYR_INCLUDE_NET_MQTT_SN_H_
30#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
97#define MQTT_SN_DATA_STRING_LITERAL(literal) ((struct mqtt_sn_data){literal, sizeof(literal) - 1})
106#define MQTT_SN_DATA_BYTES(...) \
107 ((struct mqtt_sn_data) { (uint8_t[]){ __VA_ARGS__ }, sizeof((uint8_t[]){ __VA_ARGS__ })})
205#ifdef CONFIG_MQTT_SN_TRANSPORT_UDP
209struct mqtt_sn_transport_udp {
221#define UDP_TRANSPORT(transport) CONTAINER_OF(transport, struct mqtt_sn_transport_udp, tp)
230int mqtt_sn_transport_udp_init(
struct mqtt_sn_transport_udp *udp,
struct sockaddr *gwaddr,
307 size_t txsz,
void *rx,
size_t rxsz);
size_t socklen_t
Length of a socket address.
Definition net_ip.h:168
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:42
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:112
mqtt_sn_return_code
MQTT-SN return codes.
Definition mqtt_sn.h:75
int mqtt_sn_disconnect(struct mqtt_sn_client *client)
Disconnect the client.
mqtt_sn_topic_type
MQTT-SN topic types.
Definition mqtt_sn.h:52
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:156
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:46
@ MQTT_SN_QOS_2
QOS 2.
Definition mqtt_sn.h:45
@ MQTT_SN_QOS_1
QOS 1.
Definition mqtt_sn.h:44
@ MQTT_SN_QOS_0
QOS 0.
Definition mqtt_sn.h:43
@ MQTT_SN_EVT_PINGRESP
Received a PINGRESP.
Definition mqtt_sn.h:118
@ MQTT_SN_EVT_CONNECTED
Connected to a gateway.
Definition mqtt_sn.h:113
@ MQTT_SN_EVT_PUBLISH
Received a PUBLISH message.
Definition mqtt_sn.h:117
@ MQTT_SN_EVT_ASLEEP
Entered ASLEEP state.
Definition mqtt_sn.h:115
@ MQTT_SN_EVT_DISCONNECTED
Disconnected.
Definition mqtt_sn.h:114
@ MQTT_SN_EVT_AWAKE
Entered AWAKE state.
Definition mqtt_sn.h:116
@ MQTT_SN_CODE_ACCEPTED
Accepted.
Definition mqtt_sn.h:76
@ MQTT_SN_CODE_REJECTED_CONGESTION
Rejected: congestion.
Definition mqtt_sn.h:77
@ MQTT_SN_CODE_REJECTED_NOTSUP
Rejected: Not Supported.
Definition mqtt_sn.h:79
@ MQTT_SN_CODE_REJECTED_TOPIC_ID
Rejected: Invalid Topic ID.
Definition mqtt_sn.h:78
@ MQTT_SN_TOPIC_TYPE_NORMAL
Normal topic.
Definition mqtt_sn.h:57
@ MQTT_SN_TOPIC_TYPE_PREDEF
Pre-defined topic.
Definition mqtt_sn.h:64
@ MQTT_SN_TOPIC_TYPE_SHORT
Short topic.
Definition mqtt_sn.h:69
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:3908
Structure describing an MQTT-SN client.
Definition mqtt_sn.h:237
int state
Current state of the MQTT-SN client.
Definition mqtt_sn.h:279
uint16_t next_msg_id
Message ID for the next message to be sent.
Definition mqtt_sn.h:270
uint8_t ping_retries
Number of retries for failed ping attempts.
Definition mqtt_sn.h:285
sys_slist_t publish
List of pending publish messages.
Definition mqtt_sn.h:273
struct net_buf_simple tx
Buffer for outgoing data.
Definition mqtt_sn.h:261
enum mqtt_sn_qos will_qos
Quality of Service for the Will message.
Definition mqtt_sn.h:252
struct k_work_delayable process_work
Delayable work structure for processing MQTT-SN events.
Definition mqtt_sn.h:288
struct mqtt_sn_data client_id
1-23 character unique client ID
Definition mqtt_sn.h:239
struct mqtt_sn_data will_msg
Will message.
Definition mqtt_sn.h:249
sys_slist_t topic
List of registered topics.
Definition mqtt_sn.h:276
mqtt_sn_evt_cb_t evt_cb
Event callback.
Definition mqtt_sn.h:267
bool will_retain
Flag indicating if the will message should be retained by the broker.
Definition mqtt_sn.h:255
struct mqtt_sn_transport * transport
Underlying transport to be used by the client.
Definition mqtt_sn.h:258
struct net_buf_simple rx
Buffer for incoming data.
Definition mqtt_sn.h:264
int64_t last_ping
Timestamp of the last ping request.
Definition mqtt_sn.h:282
struct mqtt_sn_data will_topic
Topic for Will message.
Definition mqtt_sn.h:244
Abstracts memory buffers.
Definition mqtt_sn.h:83
uint16_t size
Size of data, in bytes.
Definition mqtt_sn.h:85
const uint8_t * data
Pointer to data.
Definition mqtt_sn.h:84
MQTT-SN event structure to be handled by the event callback.
Definition mqtt_sn.h:139
union mqtt_sn_evt_param param
Event parameters.
Definition mqtt_sn.h:143
enum mqtt_sn_evt_type type
Event type.
Definition mqtt_sn.h:141
Structure to describe an MQTT-SN transport.
Definition mqtt_sn.h:165
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:190
int(* init)(struct mqtt_sn_transport *transport)
Will be called once on client init to initialize the transport.
Definition mqtt_sn.h:171
int(* poll)(struct mqtt_sn_client *client)
Check if incoming data is available.
Definition mqtt_sn.h:202
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:183
void(* deinit)(struct mqtt_sn_transport *transport)
Will be called on client deinit.
Definition mqtt_sn.h:178
Simple network buffer representation.
Definition buf.h:87
Generic sockaddr struct.
Definition net_ip.h:385
static fdata_t data[2]
Definition test_fifo_contexts.c:15
static ZTEST_BMEM char buffer[8]
Definition test_mbox_api.c:433
static ZTEST_DMEM int tp
Definition main.c:41
Event metadata.
Definition mqtt_sn.h:124
struct mqtt_sn_data data
The payload data associated with the event.
Definition mqtt_sn.h:128
enum mqtt_sn_topic_type topic_type
The type of topic for the event.
Definition mqtt_sn.h:130
uint16_t topic_id
The identifier for the topic of the event.
Definition mqtt_sn.h:132
struct mqtt_sn_evt_param::@329 publish
Structure holding publish event details.