net/mqtt: Allow an MQTT publisher app to receive msgs

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>
This commit is contained in:
Flavio Santes 2016-12-17 10:36:14 -06:00 committed by Tomasz Bursztyka
commit 76e479974a
3 changed files with 171 additions and 35 deletions

View file

@ -345,7 +345,7 @@ int mqtt_rx_connack(struct mqtt_ctx *ctx, struct net_buf *rx,
/**
* @brief mqtt_rx_puback Parses and validates the MQTT PUBACK message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -354,7 +354,7 @@ int mqtt_rx_puback(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_pubcomp Parses and validates the MQTT PUBCOMP message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -363,7 +363,7 @@ int mqtt_rx_pubcomp(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_pubrec Parses and validates the MQTT PUBREC message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -373,7 +373,7 @@ int mqtt_rx_pubrec(struct mqtt_ctx *ctx, struct net_buf *rx);
* @brief mqtt_rx_pubrel Parses and validates the MQTT PUBREL message
* @details rx is an RX buffer from the IP stack
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -382,7 +382,7 @@ int mqtt_rx_pubrel(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_pingresp Parses the MQTT PINGRESP message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -391,7 +391,7 @@ int mqtt_rx_pingresp(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_suback Parses the MQTT SUBACK message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -400,7 +400,7 @@ int mqtt_rx_suback(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_unsuback Parses the MQTT UNSUBACK message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
*/
@ -409,7 +409,7 @@ int mqtt_rx_unsuback(struct mqtt_ctx *ctx, struct net_buf *rx);
/**
* @brief mqtt_rx_publish Parses the MQTT PUBLISH message
* @param [in] ctx MQTT context structure
* @param [in] rx RX buffer from the IP stack
* @param [in] rx Data buffer
* @return 0 on success
* @return -EINVAL on error
* @return -ENOMEM if no data buffer is available