* This code only handles the packet encoding and decoding according to the MQTT specification and
* provides usage information in order to respect the protocol flow, but does not provide the communication
* parts of the protocol, which should be application specific.
+ * This lets the application designer choose between any of the possible MQTT flow available, from single
+ * "in-flight" message window to a single server to multiple servers and complex message queues.
*
*/
};
/* Create MQTT connect packet
- * This function must be called in order to connectte the connect MQTT packet used to
- * connect to the server.
+ * This function must be called in order to create the connect MQTT packet used to connect to the
+ * server.
* The client must send a connect packet whenever the server does not acknoledge a publish,
* subscribe, unsubscribe, or ping packet, or when the server explicitely closes the connection.
*
MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE = 3,
MQTT_CONNACK_REFUSED_BAD_USER_NAME_OR_PASSWORD = 4,
MQTT_CONNACK_REFUSED_NOT_AUTHORIZED = 5,
+ MQTT_CONNACK_MAX,
};
/* MQTT connack packet */
* the server accepts the connection and has a stored session for this client id */
#define MQTT_CONNACK_SESSION_PRESENT (0x01 << 0)
-/* Check and Decode MQTT connack packet */
-int mqtt_unpackconnack_response_pkt(uint8_t* buf, uint8_t buf_size);
+/* Check MQTT connack packet
+ * This function may get called to check a supposed connect acknowledge packet.
+ * The function checks for conformance to the MQTT protocol and returns 0 if the packet is valid and
+ * the server accepted the connection.
+ * The function returns -EPROTO in case of invalid connack packet or -EREMOTEIO in case of connection
+ * refused by the server (ret_code is then valid in the packet).
+ */
+int mqtt_check_connack_response_pkt(struct mqtt_connack_response_pkt* pkt);
/***************************************************************************** */
/* publish and puback packets */
}
+/***************************************************************************** */
+/* Check MQTT connack packet
+ * This function may get called to check a supposed connect acknowledge packet.
+ * The function checks for conformance to the MQTT protocol and returns 0 if the packet is valid,
+ * regardless of the retrun code value.
+ * The function returns -EPROTO in case of protocol error.
+ */
+int mqtt_check_connack_response_pkt(struct mqtt_connack_response_pkt* pkt)
+{
+ if (pkt->control != (MQTT_CONTROL_CONNACK << 4)) {
+ return -EPROTO;
+ }
+ if (pkt->rem_len != 2) {
+ return -EPROTO;
+ }
+ if (pkt->flags & 0xFE) {
+ return -EPROTO;
+ }
+ if (pkt->ret_code >= MQTT_CONNACK_MAX) {
+ return -EPROTO;
+ }
+ if (pkt->ret_code != 0) {
+ return -EREMOTEIO;
+ }
+ return 0;
+}
+
+
+
+/***************************************************************************** */
+