Currently, for the following MQTT msg fields:
- client_id
- will_topic
- user_name
- topic
their length is computed inside the routine that receives the MQTT msg.
Although this simplifies development, also imposes one restriction:
data must be null-terminated. Sometimes, data is received from other
sources and not generated by the application, so the null-terminated
constraint may be considered problematic for the user.
This patch removes the assumption that string fields are null-terminated.
Current data structures are already prepared to handle this case, so no
API change is required.
Change-Id: I5a147a5b21e0da49541cbe62baac363c8737cd3e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
This patch updates the Remaining Length field from uint16_t to
uint32_t. The MQTT std specifies that this field must be
unsigned 4 bytes length.
Change-Id: I319d0745c673faece4bbd4db29b1bafad78ac199
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
This commit changes the net_buf getter functions in nbuf.h
by adding a timeout parameter. These function prototypes
are changed to accept a timeout parameter.
net_nbuf_get_rx()
net_nbuf_get_tx()
net_nbuf_get_data()
net_nbuf_get_reserve_rx()
net_nbuf_get_reserve_tx()
net_nbuf_get_reserve_data()
net_nbuf_copy()
net_nbuf_copy_all()
net_nbuf_push()
net_nbuf_append()
net_nbuf_write()
net_nbuf_insert()
Following convinience functions have not been changed
net_nbuf_append_u8
net_nbuf_append_be16
net_nbuf_append_be32
net_nbuf_insert_u8
net_nbuf_insert_be16
net_nbuf_insert_be32
net_nbuf_write_u8
net_nbuf_write_be16
net_nbuf_write_be32
so they call the base function using K_FOREVER. Use the
base function if you want to have a timeout when net_buf
is allocated.
Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Delete redundant line and let the common exit point to release
the buffers.
Change-Id: I97e0ef79803083fabd841fb3d38d67c04ff31f7b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Don't try to process null or zero-length buffers generated by
the IP stack. Zero-length buffers are valid at the TCP layer but
contain no information for applications.
Change-Id: If66d301527f56ca8e8761789b7fd6931fc37b8e0
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Add the malformed callback that will be executed when a message
is received and it does not follow the MQTT v3.1.1 spec.
There is another case when this callback may be executed: when
the IP stack reception buffer's size is not enough to hold an
MQTT message.
The publisher and subscriber parser routines are updated to make
use of this callback. Inline documentation is also updated.
Change-Id: Id1d34336c4322673ca85f2db0b8d432db3c9afa8
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
1) Remove some variables pointing to user-provided data.
2) Pass the context structure instead of those variables.
3) Homogenize the use of "ctx" for all the callbacks receiving the
struct mqtt_ctx * pointer.
Now users must use the CONTAINER_OF macro to access data required
by the MQTT callbacks.
Change-Id: I871c0bd8601a67b39187683215579f9ed0087cf9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Although the buffer size validation works as it is inside the
mqtt_linearize_buffer routine, let's move it before getting a
data buffer from the buffer poll.
Change-Id: Id80af8a1e188929769463b04deaef3956b63cd00
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.
Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.
Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file. Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.
Jira: ZEP-1457
Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This patch adds the mqtt_subscriber_parser routine and modifies the
mqtt_init routine to allow an MQTT subscriber app to receive MQTT msgs.
Change-Id: Ie54ab892dacbc4386acab78a8991eba1850d8171
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Changes applied by this patch:
- Add the mqtt_publisher_parser routine
- Add the MQTT_PACKET_TYPE macro to get the MQTT msg packet type
(required by mqtt_publisher_parser)
- Add the mqtt_linearize_buffer (required by mqtt_publisher_parser)
- Add the mqtt_recv callback for reception
- Modify the mqtt_init routine to install the reception callback
The mqtt_publisher_parser routine is a callback used internally
to execute the appropriate mqtt_rx routine. Only the following
messages are handled by this routine:
MQTT_CONNACK, MQTT_PUBACK, MQTT_PUBREC, MQTT_PUBCOMP and MQTT_PINGRESP.
On error, it executes the ctx->malformed cb, if defined.
This commit also introduces the mqtt_linearize_buffer routine that
will be used to linearize an IP stack fragmented buffer. This patch
makes use of the net_nbuf_linear_copy routine to linearize the
incoming buffer. mqtt_rx_xxxx routines are also updated to handle
linear buffers (no fragmentation).
Currently, all the network protocol routines assume that the input
buffer is not fragmented. Future versions will remove that assumption
and the mqtt_linearize_buffer routine will be removed as well.
Public MQTT API is not affected by this patch.
Change-Id: I02fece67052ffbc7cb393d5ca545c503da463c4b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Avoid undesired behaviors by exiting once an error is detected.
Change-Id: Id8e6accd6cd096274fe1c40a615d290967f1d4b9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
This commit improves the buffer error handling in the mqtt_tx
routines.
Change-Id: Ic8e5761d927fe881b2376b6ac948a412e3b1168a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
The mqtt_rx_publish is used to process incoming MQTT PUBLISH
messages. This routine performes the following steps:
- take ownership of the rx buffer containing the MQTT PUBLISH msg,
- call the MQTT parser routine, and
- determine, based on the incoming message's MQTT QoS,
the next action.
Change-Id: I3cc011cf0c280205161d0484f12a2cfa79fdf44a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Use the appropriate data type for some variables:
- const input arguments
- int32_t instead of uint32_t for timeout
- uint8_t instead of int for variables that take just a few
possitive values.
Change-Id: Id7d762b400fa17e6751829ac401cd7c13aabb7b2
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
This commit changes some function signatures found at the private
MQTT Packet Lib. Input arguments representing arrays can be considered
'const', avoiding compiler warnings when passing "const arrays" in
MQTT applications.
Change-Id: I3ebaa9c7ff5fba74324bf79c55027cdd82669eaa
Signed-off-by: Flavio Santes <flavio.santes@intel.com>