zephyr/subsys/net/lib/mqtt_sock/mqtt_transport.c
Robert Lubos 37563a92d5 net: mqtt: Add BSD socket implementation
Add new, socket based MQTT implementation, based on MQTT from Nordic
nRF5 SDK, introducing the following features:

* transport independent MQTT logic, with support for multiple transports
* support for multiple MQTT versions (3.1.0 and 3.1.1 supported)
* single event handler - no need to keep callback array in RAM
* automatic send of Ping Requests, for connection keep-alive
* message/event parameters wrapped into strucutres - easier extension
  for future MQTT versions
* no separate thread needed to run MQTT - application only needs to call
  mqtt_input and mqtt_live periodically

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00

52 lines
1.4 KiB
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file mqtt_transport.c
*
* @brief Internal functions to handle transport in MQTT module.
*/
#include "mqtt_transport.h"
/* Transport handler functions for TCP socket transport. */
extern int mqtt_client_tcp_connect(struct mqtt_client *client);
extern int mqtt_client_tcp_write(struct mqtt_client *client, const u8_t *data,
u32_t datalen);
extern int mqtt_client_tcp_read(struct mqtt_client *client, u8_t *data,
u32_t buflen);
extern int mqtt_client_tcp_disconnect(struct mqtt_client *client);
/**@brief Function pointer array for TCP/TLS transport handlers. */
const struct transport_procedure transport_fn[MQTT_TRANSPORT_NUM] = {
{
mqtt_client_tcp_connect,
mqtt_client_tcp_write,
mqtt_client_tcp_read,
mqtt_client_tcp_disconnect,
}
};
int mqtt_transport_connect(struct mqtt_client *client)
{
return transport_fn[client->transport.type].connect(client);
}
int mqtt_transport_write(struct mqtt_client *client, const u8_t *data,
u32_t datalen)
{
return transport_fn[client->transport.type].write(client, data,
datalen);
}
int mqtt_transport_read(struct mqtt_client *client, u8_t *data, u32_t buflen)
{
return transport_fn[client->transport.type].read(client, data, buflen);
}
int mqtt_transport_disconnect(struct mqtt_client *client)
{
return transport_fn[client->transport.type].disconnect(client);
}