net: mqtt: Mark existing implementation as legacy

Rename existing headers and sybols to mqtt_legacy, to allow new
implementation to keep old config and header names.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2018-09-21 10:59:18 +02:00 committed by Anas Nashif
commit f50aa6d3fb
17 changed files with 41 additions and 40 deletions

View file

@ -7,7 +7,7 @@
#ifndef ZEPHYR_INCLUDE_NET_MQTT_H_ #ifndef ZEPHYR_INCLUDE_NET_MQTT_H_
#define ZEPHYR_INCLUDE_NET_MQTT_H_ #define ZEPHYR_INCLUDE_NET_MQTT_H_
#include <net/mqtt_types.h> #include <net/mqtt_legacy_types.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/net_app.h> #include <net/net_app.h>
@ -72,7 +72,7 @@ struct mqtt_ctx {
char *peer_addr_str; char *peer_addr_str;
u16_t peer_port; u16_t peer_port;
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
/** TLS parameters */ /** TLS parameters */
u8_t *request_buf; u8_t *request_buf;
size_t request_buf_len; size_t request_buf_len;

View file

@ -33,7 +33,7 @@ CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=3
CONFIG_PRINTK=y CONFIG_PRINTK=y
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_MAIN_STACK_SIZE=2048 CONFIG_MAIN_STACK_SIZE=2048

View file

@ -22,7 +22,7 @@ CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=y CONFIG_NET_IPV6=y
# Enable the MQTT Lib # Enable the MQTT Lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"

View file

@ -22,7 +22,7 @@ CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y CONFIG_NET_IPV4=y
# Enable the MQTT Lib # Enable the MQTT Lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"

View file

@ -25,7 +25,7 @@
#endif #endif
#endif #endif
#ifdef CONFIG_MQTT_LIB_TLS #ifdef CONFIG_MQTT_LEGACY_LIB_TLS
#define SERVER_PORT 8883 #define SERVER_PORT 8883
#else #else
#define SERVER_PORT 1883 #define SERVER_PORT 1883

View file

@ -5,7 +5,7 @@
*/ */
#include <zephyr.h> #include <zephyr.h>
#include <net/mqtt.h> #include <net/mqtt_legacy.h>
#include <net/net_context.h> #include <net/net_context.h>
@ -66,7 +66,7 @@ static struct mqtt_client_ctx client_ctx;
/* This routine sets some basic properties for the network context variable */ /* This routine sets some basic properties for the network context variable */
static int network_setup(void); static int network_setup(void);
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
#include "test_certs.h" #include "test_certs.h"
@ -311,7 +311,7 @@ static void publisher(void)
client_ctx.mqtt_ctx.peer_addr_str = SERVER_ADDR; client_ctx.mqtt_ctx.peer_addr_str = SERVER_ADDR;
client_ctx.mqtt_ctx.peer_port = SERVER_PORT; client_ctx.mqtt_ctx.peer_port = SERVER_PORT;
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
/** TLS setup */ /** TLS setup */
client_ctx.mqtt_ctx.request_buf = tls_request_buf; client_ctx.mqtt_ctx.request_buf = tls_request_buf;
client_ctx.mqtt_ctx.request_buf_len = TLS_REQUEST_BUF_SIZE; client_ctx.mqtt_ctx.request_buf_len = TLS_REQUEST_BUF_SIZE;

View file

@ -3,7 +3,7 @@ add_subdirectory_if_kconfig(coap_sock)
add_subdirectory_if_kconfig(lwm2m) add_subdirectory_if_kconfig(lwm2m)
add_subdirectory_if_kconfig(sntp) add_subdirectory_if_kconfig(sntp)
add_subdirectory_ifdef(CONFIG_DNS_RESOLVER dns) add_subdirectory_ifdef(CONFIG_DNS_RESOLVER dns)
add_subdirectory_ifdef(CONFIG_MQTT_LIB mqtt) add_subdirectory_ifdef(CONFIG_MQTT_LEGACY_LIB mqtt)
add_subdirectory_ifdef(CONFIG_NET_APP app) add_subdirectory_ifdef(CONFIG_NET_APP app)
add_subdirectory_ifdef(CONFIG_NET_CONFIG_SETTINGS config) add_subdirectory_ifdef(CONFIG_NET_CONFIG_SETTINGS config)
add_subdirectory_ifdef(CONFIG_NET_SOCKETS sockets) add_subdirectory_ifdef(CONFIG_NET_SOCKETS sockets)

View file

@ -6,42 +6,42 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
config MQTT_LIB config MQTT_LEGACY_LIB
bool "MQTT Library Support" bool "Legacy MQTT Library Support"
select NET_APP_CLIENT select NET_APP_CLIENT
help help
Enable the Zephyr MQTT Library Enable the Zephyr MQTT Library
config MQTT_MSG_MAX_SIZE config MQTT_LEGACY_MSG_MAX_SIZE
int "Max size of a MQTT message" int "Max size of a MQTT message"
depends on MQTT_LIB depends on MQTT_LEGACY_LIB
default 128 default 128
range 128 1024 range 128 1024
help help
Set the maximum size of the MQTT message. So, no messages Set the maximum size of the MQTT message. So, no messages
longer than CONFIG_MQTT_MSG_SIZE will be processed. longer than CONFIG_MQTT_MSG_SIZE will be processed.
config MQTT_ADDITIONAL_BUFFER_CTR config MQTT_LEGACY_ADDITIONAL_BUFFER_CTR
int "Additional buffers available for the MQTT application" int "Additional buffers available for the MQTT application"
depends on MQTT_LIB depends on MQTT_LEGACY_LIB
default 0 default 0
help help
Set some additional buffers. When two or more concurrent contexts are Set some additional buffers. When two or more concurrent contexts are
used in the same application, additional buffers may help to have a 1:1 used in the same application, additional buffers may help to have a 1:1
relation between application contexts and internal buffers. relation between application contexts and internal buffers.
config MQTT_SUBSCRIBE_MAX_TOPICS config MQTT_LEGACY_SUBSCRIBE_MAX_TOPICS
int "Max number of topics to subscribe to" int "Max number of topics to subscribe to"
depends on MQTT_LIB depends on MQTT_LEGACY_LIB
default 1 default 1
range 1 8 range 1 8
help help
Set the maximum number of topics handled by the SUBSCRIBE/SUBACK Set the maximum number of topics handled by the SUBSCRIBE/SUBACK
messages during reception. messages during reception.
config MQTT_LIB_TLS config MQTT_LEGACY_LIB_TLS
bool "Enable TLS support for the MQTT application" bool "Enable TLS support for the MQTT application"
depends on MQTT_LIB depends on MQTT_LEGACY_LIB
select NET_APP_TLS select NET_APP_TLS
help help
Enables MQTT library with TLS support Enables MQTT library with TLS support

View file

@ -7,7 +7,7 @@
#define LOG_MODULE_NAME net_mqtt #define LOG_MODULE_NAME net_mqtt
#define NET_LOG_LEVEL LOG_LEVEL_ERR #define NET_LOG_LEVEL LOG_LEVEL_ERR
#include <net/mqtt.h> #include <net/mqtt_legacy.h>
#include "mqtt_pkt.h" #include "mqtt_pkt.h"
#include <net/net_ip.h> #include <net/net_ip.h>
@ -16,8 +16,8 @@
#include <net/buf.h> #include <net/buf.h>
#include <errno.h> #include <errno.h>
#define MSG_SIZE CONFIG_MQTT_MSG_MAX_SIZE #define MSG_SIZE CONFIG_MQTT_LEGACY_MSG_MAX_SIZE
#define MQTT_BUF_CTR (1 + CONFIG_MQTT_ADDITIONAL_BUFFER_CTR) #define MQTT_BUF_CTR (1 + CONFIG_MQTT_LEGACY_ADDITIONAL_BUFFER_CTR)
/* Memory pool internally used to handle messages that may exceed the size of /* Memory pool internally used to handle messages that may exceed the size of
* system defined network buffer. By using this memory pool, routines don't deal * system defined network buffer. By using this memory pool, routines don't deal
@ -27,7 +27,7 @@ NET_BUF_POOL_DEFINE(mqtt_msg_pool, MQTT_BUF_CTR, MSG_SIZE, 0, NULL);
#define MQTT_PUBLISHER_MIN_MSG_SIZE 2 #define MQTT_PUBLISHER_MIN_MSG_SIZE 2
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
#define TLS_HS_DEFAULT_TIMEOUT 3000 #define TLS_HS_DEFAULT_TIMEOUT 3000
#endif #endif
@ -556,7 +556,7 @@ int mqtt_rx_pingresp(struct mqtt_ctx *ctx, struct net_buf *rx)
int mqtt_rx_suback(struct mqtt_ctx *ctx, struct net_buf *rx) int mqtt_rx_suback(struct mqtt_ctx *ctx, struct net_buf *rx)
{ {
enum mqtt_qos suback_qos[CONFIG_MQTT_SUBSCRIBE_MAX_TOPICS]; enum mqtt_qos suback_qos[CONFIG_MQTT_LEGACY_SUBSCRIBE_MAX_TOPICS];
u16_t pkt_id; u16_t pkt_id;
u16_t len; u16_t len;
u8_t items; u8_t items;
@ -567,7 +567,8 @@ int mqtt_rx_suback(struct mqtt_ctx *ctx, struct net_buf *rx)
len = rx->len; len = rx->len;
rc = mqtt_unpack_suback(data, len, &pkt_id, &items, rc = mqtt_unpack_suback(data, len, &pkt_id, &items,
CONFIG_MQTT_SUBSCRIBE_MAX_TOPICS, suback_qos); CONFIG_MQTT_LEGACY_SUBSCRIBE_MAX_TOPICS,
suback_qos);
if (rc != 0) { if (rc != 0) {
return -EINVAL; return -EINVAL;
} }
@ -663,12 +664,12 @@ struct net_buf *mqtt_linearize_packet(struct mqtt_ctx *ctx, struct net_pkt *rx,
u16_t offset; u16_t offset;
int rc; int rc;
/* CONFIG_MQTT_MSG_MAX_SIZE is defined via Kconfig. So here it's /* CONFIG_MQTT_LEGACY_MSG_MAX_SIZE is defined via Kconfig. So here it's
* determined if the input packet could fit our data buffer or if * determined if the input packet could fit our data buffer or if
* it has the expected size. * it has the expected size.
*/ */
data_len = net_pkt_appdatalen(rx); data_len = net_pkt_appdatalen(rx);
if (data_len < min_size || data_len > CONFIG_MQTT_MSG_MAX_SIZE) { if (data_len < min_size || data_len > CONFIG_MQTT_LEGACY_MSG_MAX_SIZE) {
return NULL; return NULL;
} }
@ -779,7 +780,7 @@ void app_connected(struct net_app_ctx *ctx, int status, void *data)
return; return;
} }
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
k_sem_give(&mqtt->tls_hs_wait); k_sem_give(&mqtt->tls_hs_wait);
#endif #endif
} }
@ -835,7 +836,7 @@ int mqtt_connect(struct mqtt_ctx *ctx)
goto error_connect; goto error_connect;
} }
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
rc = net_app_client_tls(&ctx->net_app_ctx, rc = net_app_client_tls(&ctx->net_app_ctx,
ctx->request_buf, ctx->request_buf,
ctx->request_buf_len, ctx->request_buf_len,
@ -857,7 +858,7 @@ int mqtt_connect(struct mqtt_ctx *ctx)
goto error_connect; goto error_connect;
} }
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
/* TLS handshake is not finished until app_connected is called */ /* TLS handshake is not finished until app_connected is called */
rc = k_sem_take(&ctx->tls_hs_wait, ctx->tls_hs_timeout); rc = k_sem_take(&ctx->tls_hs_wait, ctx->tls_hs_timeout);
if (rc < 0) { if (rc < 0) {
@ -884,7 +885,7 @@ int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type)
ctx->app_type = app_type; ctx->app_type = app_type;
ctx->rcv = mqtt_parser; ctx->rcv = mqtt_parser;
#if defined(CONFIG_MQTT_LIB_TLS) #if defined(CONFIG_MQTT_LEGACY_LIB_TLS)
if (ctx->tls_hs_timeout == 0) { if (ctx->tls_hs_timeout == 0) {
ctx->tls_hs_timeout = TLS_HS_DEFAULT_TIMEOUT; ctx->tls_hs_timeout = TLS_HS_DEFAULT_TIMEOUT;
} }

View file

@ -20,7 +20,7 @@
#include <zephyr/types.h> #include <zephyr/types.h>
#include <stddef.h> #include <stddef.h>
#include <net/mqtt_types.h> #include <net/mqtt_legacy_types.h>
#define MQTT_PACKET_TYPE(first_byte) (((first_byte) & 0xF0) >> 4) #define MQTT_PACKET_TYPE(first_byte) (((first_byte) & 0xF0) >> 4)

View file

@ -7,7 +7,7 @@ CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y
# enable the MQTT lib # enable the MQTT lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_ZTEST=y CONFIG_ZTEST=y
CONFIG_MAIN_STACK_SIZE=1280 CONFIG_MAIN_STACK_SIZE=1280

View file

@ -17,7 +17,7 @@ CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y CONFIG_NET_IPV4=y
# Enable the MQTT Lib # Enable the MQTT Lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"

View file

@ -22,8 +22,8 @@ CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=y CONFIG_NET_IPV6=y
# Enable the MQTT Lib # Enable the MQTT Lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_MQTT_LIB_TLS=y CONFIG_MQTT_LEGACY_LIB_TLS=y
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"

View file

@ -7,7 +7,7 @@
#define LOG_MODULE_NAME net_test #define LOG_MODULE_NAME net_test
#define NET_LOG_LEVEL LOG_LEVEL_WRN #define NET_LOG_LEVEL LOG_LEVEL_WRN
#include <net/mqtt.h> #include <net/mqtt_legacy.h>
#include <ztest.h> #include <ztest.h>
#include <net/net_context.h> #include <net/net_context.h>

View file

@ -17,7 +17,7 @@ CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y CONFIG_NET_IPV4=y
# Enable the MQTT Lib # Enable the MQTT Lib
CONFIG_MQTT_LIB=y CONFIG_MQTT_LEGACY_LIB=y
CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"

View file

@ -8,7 +8,7 @@
#define NET_LOG_LEVEL LOG_LEVEL_WRN #define NET_LOG_LEVEL LOG_LEVEL_WRN
#include <ztest.h> #include <ztest.h>
#include <net/mqtt.h> #include <net/mqtt_legacy.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/net_pkt.h> #include <net/net_pkt.h>