mqtt_sn_debug.c
Go to the documentation of this file.
1 /**
2  * @file mqtt_sn_debug.c
3  * @brief Data logging functions for debugging purpose (MQTT-SN)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL MQTT_SN_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mqtt_sn/mqtt_sn_client.h"
37 #include "mqtt_sn/mqtt_sn_debug.h"
38 #include "debug.h"
39 
40 //Check TCP/IP stack configuration
41 #if (MQTT_SN_CLIENT_SUPPORT == ENABLED)
42 
43 //MQTT-SN message types
44 const char_t *const mqttSnMsgTypeLabel[] =
45 {
46  "ADVERTISE", //0x00
47  "SEARCHGW", //0x01
48  "GWINFO", //0x02
49  "Reserved", //0x03
50  "CONNECT", //0x04
51  "CONNACK", //0x05
52  "WILLTOPICREQ", //0x06
53  "WILLTOPIC", //0x07
54  "WILLMSGREQ", //0x08
55  "WILLMSG", //0x09
56  "REGISTER", //0x0A
57  "REGACK", //0x0B
58  "PUBLISH", //0x0C
59  "PUBACK", //0x0D
60  "PUBCOMP", //0x0E
61  "PUBREC", //0x0F
62  "PUBREL", //0x10
63  "Reserved", //0x11
64  "SUBSCRIBE", //0x12
65  "SUBACK", //0x13
66  "UNSUBSCRIBE", //0x14
67  "UNSUBACK", //0x15
68  "PINGREQ", //0x16
69  "PINGRESP", //0x17
70  "DISCONNECT", //0x18
71  "Reserved", //0x19
72  "WILLTOPICUPD", //0x1A
73  "WILLTOPICRESP", //0x1B
74  "WILLMSGUPD", //0x1C
75  "WILLMSGRESP" //0x1D
76 };
77 
78 //MQTT-SN return codes
79 const char_t *const mqttSnReturnCodeLabel[] =
80 {
81  "Accepted", //0x00
82  "Rejected: congestion", //0x01
83  "Rejected: invalid topic ID", //0x02
84  "Rejected: not supported", //0x03
85 };
86 
87 
88 /**
89  * @brief Dump MQTT-SN message for debugging purpose
90  * @param[in] message Pointer to the message
91  * @param[in] length Length of the message, in bytes
92  * @return Error code
93  **/
94 
95 error_t mqttSnDumpMessage(const uint8_t *message, size_t length)
96 {
97 #if (MQTT_SN_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
98  error_t error;
99  uint8_t type;
100 
101  //Sanity check
102  if(length == 0)
103  return ERROR_INVALID_LENGTH;
104 
105  //Check whether the first octet is 0x01
106  if(message[0] == 0x01)
107  {
108  const MqttSnExtHeader *header;
109 
110  //Point to message header
111  header = (MqttSnExtHeader *) message;
112 
113  //Malformed message?
114  if(length < sizeof(MqttSnExtHeader))
115  return ERROR_INVALID_LENGTH;
116  if(length < ntohs(header->length))
117  return ERROR_INVALID_LENGTH;
118 
119  //Dump message length
120  TRACE_DEBUG(" Length = %" PRIuSIZE "\r\n", ntohs(header->length));
121 
122  //The Length field specifies the total number of octets contained in
123  //the message, including the Length field itself
124  length = ntohs(header->length) - sizeof(MqttSnExtHeader);
125 
126  //Retrieve message type
127  type = header->msgType;
128  //Point to the payload
129  message = header->data;
130  }
131  else
132  {
133  const MqttSnHeader *header;
134 
135  //Point to message header
136  header = (MqttSnHeader *) message;
137 
138  //Malformed message?
139  if(length < sizeof(MqttSnHeader))
140  return ERROR_INVALID_LENGTH;
141  if(length < header->length)
142  return ERROR_INVALID_LENGTH;
143 
144  //Dump message length
145  TRACE_DEBUG(" Length = %" PRIuSIZE "\r\n", header->length);
146 
147  //The Length field specifies the total number of octets contained in
148  //the message, including the Length field itself
149  length = header->length - sizeof(MqttSnHeader);
150 
151  //Retrieve message type
152  type = header->msgType;
153  //Point to the payload
154  message = header->data;
155  }
156 
157  //Dump message type
158  TRACE_DEBUG(" MsgType = 0x%02" PRIX8 " (%s)\r\n", type,
160 
161  //Check message type
162  switch(type)
163  {
164  //ADVERTISE message?
166  //Dump ADVERTISE message
168  break;
169  //SEARCHGW message?
171  //Dump SEARCHGW message
173  break;
174  //GWINFO message?
176  //Dump GWINFO message
178  break;
179  //CONNECT message?
181  //Dump CONNECT message
183  break;
184  //CONNACK message?
186  //Dump CONNACK message
188  break;
189  //WILLTOPICREQ message?
191  //Dump WILLTOPICREQ message
193  break;
194  //WILLTOPIC message?
196  //Dump WILLTOPIC message
198  break;
199  //WILLMSGREQ message?
201  //Dump WILLMSGREQ message
203  break;
204  //WILLMSG message?
206  //Dump WILLMSG message
208  break;
209  //REGISTER message?
211  //Dump REGISTER message
213  break;
214  //REGACK message?
216  //Dump REGACK message
218  break;
219  //PUBLISH message?
221  //Dump PUBLISH message
223  break;
224  //PUBACK message?
226  //Dump PUBACK message
228  break;
229  //PUBREC message?
231  //Dump PUBREC message
233  break;
234  //PUBREL message?
236  //Dump PUBREL message
238  break;
239  //PUBCOMP message?
241  //Dump PUBCOMP message
243  break;
244  //SUBSCRIBE message?
246  //Dump SUBSCRIBE message
248  break;
249  //SUBACK message?
251  //Dump SUBACK message
253  break;
254  //UNSUBSCRIBE message?
256  //Dump UNSUBSCRIBE message
258  break;
259  //UNSUBACK message?
261  //Dump UNSUBACK message
263  break;
264  //PINGREQ message?
266  //Dump PINGREQ message
268  break;
269  //PINGRESP message?
271  //Dump PINGRESP message
273  break;
274  //DISCONNECT message?
276  //Dump DISCONNECT message
278  break;
279  //WILLTOPICUPD message?
281  //Dump WILLTOPICUPD message
283  break;
284  //WILLTOPICRESP message?
286  //Dump WILLTOPICRESP message
288  break;
289  //WILLMSGUPD message?
291  //Dump WILLMSGUPD message
293  break;
294  //WILLMSGRESP message?
296  //Dump DISCONNECT message
298  break;
299  //Unknown message?
300  default:
301  //Report an error
302  error = ERROR_INVALID_TYPE;
303  break;
304  }
305 
306  //Return error code
307  return error;
308 #else
309  //Not implemented
310  return NO_ERROR;
311 #endif
312 }
313 
314 
315 /**
316  * @brief Dump ADVERTISE message
317  * @param[in] message Pointer to the message
318  * @param[in] length Length of the message, in bytes
319  * @return Error code
320  **/
321 
323  size_t length)
324 {
325  //Malformed message?
326  if(length < sizeof(MqttSnAdvertise))
327  return ERROR_INVALID_LENGTH;
328 
329  //Dump ADVERTISE message
330  TRACE_DEBUG(" GwId = %" PRIu8 "\r\n", message->gwId);
331  TRACE_DEBUG(" Duration = %" PRIu16 "\r\n", message->duration);
332 
333  //Successful processing
334  return NO_ERROR;
335 }
336 
337 
338 /**
339  * @brief Dump SEARCHGW message
340  * @param[in] message Pointer to the message
341  * @param[in] length Length of the message, in bytes
342  * @return Error code
343  **/
344 
346 {
347  //Malformed message?
348  if(length < sizeof(MqttSnSearchGw))
349  return ERROR_INVALID_LENGTH;
350 
351  //Dump SEARCHGW message
352  TRACE_DEBUG(" Radius = %" PRIu8 "\r\n", message->radius);
353 
354  //Successful processing
355  return NO_ERROR;
356 }
357 
358 
359 /**
360  * @brief Dump GWINFO message
361  * @param[in] message Pointer to the message
362  * @param[in] length Length of the message, in bytes
363  * @return Error code
364  **/
365 
367 {
368  //Malformed message?
369  if(length < sizeof(MqttSnGwInfo))
370  return ERROR_INVALID_LENGTH;
371 
372  //Retrieve the length of the GwAdd field
373  length -= sizeof(MqttSnGwInfo);
374 
375  //Dump GWINFO message
376  TRACE_DEBUG(" GwId = %" PRIu8 "\r\n", message->gwId);
377  TRACE_DEBUG_ARRAY(" GwAdd = ", message->gwAdd, length);
378 
379  //Successful processing
380  return NO_ERROR;
381 }
382 
383 
384 /**
385  * @brief Dump CONNECT message
386  * @param[in] message Pointer to the message
387  * @param[in] length Length of the message, in bytes
388  * @return Error code
389  **/
390 
392 {
393  //Malformed message?
394  if(length < sizeof(MqttSnConnect))
395  return ERROR_INVALID_LENGTH;
396 
397  //Dump CONNECT message
398  mqttSnDumpFlags(message->flags);
399  TRACE_DEBUG(" ProtocolId = %" PRIu8 "\r\n", message->protocolId);
400  TRACE_DEBUG(" Duration = %" PRIu16 "\r\n", ntohs(message->duration));
401  TRACE_DEBUG(" ClientId = %s\r\n", message->clientId);
402 
403  //Successful processing
404  return NO_ERROR;
405 }
406 
407 
408 /**
409  * @brief Dump CONNACK message
410  * @param[in] message Pointer to the message
411  * @param[in] length Length of the message, in bytes
412  * @return Error code
413  **/
414 
416 {
417  //Malformed message?
418  if(length < sizeof(MqttSnConnAck))
419  return ERROR_INVALID_LENGTH;
420 
421  //Dump CONNACK message
422  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
423  mqttSnGetReturnCodeDesc(message->returnCode));
424 
425  //Successful processing
426  return NO_ERROR;
427 }
428 
429 
430 /**
431  * @brief Dump WILLTOPICREQ message
432  * @param[in] message Pointer to the message
433  * @param[in] length Length of the message, in bytes
434  * @return Error code
435  **/
436 
438 {
439  //The WILLTOPICREQ message has only a header and no variable part
440  return NO_ERROR;
441 }
442 
443 
444 /**
445  * @brief Dump WILLTOPIC message
446  * @param[in] message Pointer to the message
447  * @param[in] length Length of the message, in bytes
448  * @return Error code
449  **/
450 
452 {
453  //Malformed message?
454  if(length < sizeof(MqttSnWillTopic))
455  return ERROR_INVALID_LENGTH;
456 
457  //Dump WILLTOPIC message
458  mqttSnDumpFlags(message->flags);
459  TRACE_DEBUG(" WillTopic = %s\r\n", message->willTopic);
460 
461  //Successful processing
462  return NO_ERROR;
463 }
464 
465 
466 /**
467  * @brief Dump WILLMSGREQ message
468  * @param[in] message Pointer to the message
469  * @param[in] length Length of the message, in bytes
470  * @return Error code
471  **/
472 
474 {
475  //The WILLMSGREQ message has only a header and no variable part
476  return NO_ERROR;
477 }
478 
479 
480 /**
481  * @brief Dump WILLMSG message
482  * @param[in] message Pointer to the message
483  * @param[in] length Length of the message, in bytes
484  * @return Error code
485  **/
486 
488 {
489  //Dump WILLMSG message
490  TRACE_DEBUG(" WillMsg (%" PRIuSIZE " bytes)\r\n", length);
492 
493  //Successful processing
494  return NO_ERROR;
495 }
496 
497 
498 /**
499  * @brief Dump REGISTER message
500  * @param[in] message Pointer to the message
501  * @param[in] length Length of the message, in bytes
502  * @return Error code
503  **/
504 
506 {
507  //Malformed message?
508  if(length < sizeof(MqttSnRegister))
509  return ERROR_INVALID_LENGTH;
510 
511  //Dump REGISTER message
512  TRACE_DEBUG(" TopicId = 0x%04" PRIX16 "\r\n", ntohs(message->topicId));
513  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
514  TRACE_DEBUG(" TopicName = %s\r\n", message->topicName);
515 
516  //Successful processing
517  return NO_ERROR;
518 }
519 
520 
521 /**
522  * @brief Dump REGACK message
523  * @param[in] message Pointer to the message
524  * @param[in] length Length of the message, in bytes
525  * @return Error code
526  **/
527 
529 {
530  //Malformed message?
531  if(length < sizeof(MqttSnRegAck))
532  return ERROR_INVALID_LENGTH;
533 
534  //Dump REGACK message
535  TRACE_DEBUG(" TopicId = 0x%04" PRIX16 "\r\n", ntohs(message->topicId));
536  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
537  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
538  mqttSnGetReturnCodeDesc(message->returnCode));
539 
540  //Successful processing
541  return NO_ERROR;
542 }
543 
544 
545 /**
546  * @brief Dump PUBLISH message
547  * @param[in] message Pointer to the message
548  * @param[in] length Length of the message, in bytes
549  * @return Error code
550  **/
551 
553 {
554  //Malformed message?
555  if(length < sizeof(MqttSnPublish))
556  return ERROR_INVALID_LENGTH;
557 
558  //Retrieve the length of the published data
559  length -= sizeof(MqttSnPublish);
560 
561  //Dump flags
562  mqttSnDumpFlags(message->flags);
563 
564  //Check the type of topic identifier
565  if(message->flags.topicIdType == MQTT_SN_NORMAL_TOPIC_ID)
566  {
567  //Dump normal topic ID
568  TRACE_DEBUG(" TopicId = 0x%04" PRIX16 "\r\n",
569  ntohs(message->topicId));
570  }
571  else if(message->flags.topicIdType == MQTT_SN_PREDEFINED_TOPIC_ID)
572  {
573  //Dump predefined topic ID
574  TRACE_DEBUG(" PredefinedTopicId = 0x%04" PRIX16 "\r\n",
575  ntohs(message->topicId));
576  }
577  else if(message->flags.topicIdType == MQTT_SN_SHORT_TOPIC_NAME)
578  {
579  //Dump short topic name
580  TRACE_DEBUG(" ShortTopicName = %c%c\r\n",
581  MSB(ntohs(message->topicId)), LSB(ntohs(message->topicId)));
582  }
583  else
584  {
585  //Just for sanity
586  }
587 
588  //Debug message
589  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
590  TRACE_DEBUG(" Data (%" PRIuSIZE " bytes)\r\n", length);
591  TRACE_DEBUG_ARRAY(" ", message->data, length);
592 
593  //Successful processing
594  return NO_ERROR;
595 }
596 
597 
598 /**
599  * @brief Dump PUBACK message
600  * @param[in] message Pointer to the message
601  * @param[in] length Length of the message, in bytes
602  * @return Error code
603  **/
604 
606 {
607  //Malformed message?
608  if(length < sizeof(MqttSnPubAck))
609  return ERROR_INVALID_LENGTH;
610 
611  //Dump PUBACK message
612  TRACE_DEBUG(" TopicId = 0x%04" PRIX16 "\r\n", ntohs(message->topicId));
613  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
614  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
615  mqttSnGetReturnCodeDesc(message->returnCode));
616 
617  //Successful processing
618  return NO_ERROR;
619 }
620 
621 
622 /**
623  * @brief Dump PUBREC message
624  * @param[in] message Pointer to the message
625  * @param[in] length Length of the message, in bytes
626  * @return Error code
627  **/
628 
630 {
631  //Malformed message?
632  if(length < sizeof(MqttSnPubRec))
633  return ERROR_INVALID_LENGTH;
634 
635  //Dump PUBREC message
636  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
637 
638  //Successful processing
639  return NO_ERROR;
640 }
641 
642 
643 /**
644  * @brief Dump PUBREL message
645  * @param[in] message Pointer to the message
646  * @param[in] length Length of the message, in bytes
647  * @return Error code
648  **/
649 
651 {
652  //Malformed message?
653  if(length < sizeof(MqttSnPubRel))
654  return ERROR_INVALID_LENGTH;
655 
656  //Dump PUBREL message
657  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
658 
659  //Successful processing
660  return NO_ERROR;
661 }
662 
663 
664 /**
665  * @brief Dump PUBCOMP message
666  * @param[in] message Pointer to the message
667  * @param[in] length Length of the message, in bytes
668  * @return Error code
669  **/
670 
672 {
673  //Malformed message?
674  if(length < sizeof(MqttSnPubComp))
675  return ERROR_INVALID_LENGTH;
676 
677  //Dump PUBCOMP message
678  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
679 
680  //Successful processing
681  return NO_ERROR;
682 }
683 
684 
685 /**
686  * @brief Dump SUBSCRIBE message
687  * @param[in] message Pointer to the message
688  * @param[in] length Length of the message, in bytes
689  * @return Error code
690  **/
691 
693 {
694  //Malformed message?
695  if(length < sizeof(MqttSnSubscribe))
696  return ERROR_INVALID_LENGTH;
697 
698  //Dump SUBSCRIBE message
699  mqttSnDumpFlags(message->flags);
700  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
701 
702  //Check the type of topic identifier
703  if(message->flags.topicIdType == MQTT_SN_NORMAL_TOPIC_NAME)
704  {
705  //Dump topic name
706  TRACE_DEBUG(" TopicName = %s\r\n", message->topicName);
707  }
708  else if(message->flags.topicIdType == MQTT_SN_SHORT_TOPIC_NAME)
709  {
710  //Dump short topic name
711  TRACE_DEBUG(" ShortTopicName = %s\r\n", message->topicName);
712  }
713  else if(message->flags.topicIdType == MQTT_SN_PREDEFINED_TOPIC_ID)
714  {
715  //Dump predefined topic ID
716  TRACE_DEBUG(" PredefinedTopicId = 0x%04" PRIX16 "\r\n",
717  LOAD16BE(message->topicName));
718  }
719  else
720  {
721  //Just for sanity
722  }
723 
724  //Successful processing
725  return NO_ERROR;
726 }
727 
728 
729 /**
730  * @brief Dump SUBACK message
731  * @param[in] message Pointer to the message
732  * @param[in] length Length of the message, in bytes
733  * @return Error code
734  **/
735 
737 {
738  //Malformed message?
739  if(length < sizeof(MqttSnSubAck))
740  return ERROR_INVALID_LENGTH;
741 
742  //Dump SUBACK message
743  mqttSnDumpFlags(message->flags);
744  TRACE_DEBUG(" TopicId = 0x%04" PRIX16 "\r\n", ntohs(message->topicId));
745  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
746  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
747  mqttSnGetReturnCodeDesc(message->returnCode));
748 
749  //Successful processing
750  return NO_ERROR;
751 }
752 
753 
754 /**
755  * @brief Dump UNSUBSCRIBE message
756  * @param[in] message Pointer to the message
757  * @param[in] length Length of the message, in bytes
758  * @return Error code
759  **/
760 
762 {
763  //Malformed message?
764  if(length < sizeof(MqttSnUnsubscribe))
765  return ERROR_INVALID_LENGTH;
766 
767  //Dump UNSUBSCRIBE message
768  mqttSnDumpFlags(message->flags);
769  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
770 
771  //Check the type of topic identifier
772  if(message->flags.topicIdType == MQTT_SN_NORMAL_TOPIC_NAME)
773  {
774  //Dump topic name
775  TRACE_DEBUG(" TopicName = %s\r\n", message->topicName);
776  }
777  else if(message->flags.topicIdType == MQTT_SN_SHORT_TOPIC_NAME)
778  {
779  //Dump short topic name
780  TRACE_DEBUG(" ShortTopicName = %s\r\n", message->topicName);
781  }
782  else if(message->flags.topicIdType == MQTT_SN_PREDEFINED_TOPIC_ID)
783  {
784  //Dump predefined topic ID
785  TRACE_DEBUG(" PredefinedTopicId = 0x%04" PRIX16 "\r\n",
786  LOAD16BE(message->topicName));
787  }
788  else
789  {
790  //Just for sanity
791  }
792 
793  //Successful processing
794  return NO_ERROR;
795 }
796 
797 
798 /**
799  * @brief Dump UNSUBACK message
800  * @param[in] message Pointer to the message
801  * @param[in] length Length of the message, in bytes
802  * @return Error code
803  **/
804 
806 {
807  //Malformed message?
808  if(length < sizeof(MqttSnUnsubAck))
809  return ERROR_INVALID_LENGTH;
810 
811  //Dump UNSUBACK message
812  TRACE_DEBUG(" MsgId = 0x%04" PRIX16 "\r\n", ntohs(message->msgId));
813 
814  //Successful processing
815  return NO_ERROR;
816 }
817 
818 
819 /**
820  * @brief Dump PINGREQ message
821  * @param[in] message Pointer to the message
822  * @param[in] length Length of the message, in bytes
823  * @return Error code
824  **/
825 
827 {
828  //Dump PINGREQ message
829  TRACE_DEBUG(" ClientId = %s\r\n", (char_t *) message);
830 
831  //Successful processing
832  return NO_ERROR;
833 }
834 
835 
836 /**
837  * @brief Dump PINGRESP message
838  * @param[in] message Pointer to the message
839  * @param[in] length Length of the message, in bytes
840  * @return Error code
841  **/
842 
844 {
845  //The PINGRESP message has only a header and no variable part
846  return NO_ERROR;
847 }
848 
849 
850 /**
851  * @brief Dump DISCONNECT message
852  * @param[in] message Pointer to the message
853  * @param[in] length Length of the message, in bytes
854  * @return Error code
855  **/
856 
858 {
859  //Malformed message?
860  if(length < sizeof(MqttSnDisconnect))
861  return ERROR_INVALID_LENGTH;
862 
863  //Dump DISCONNECT message
864  TRACE_DEBUG(" Duration = %" PRIu16 "\r\n", ntohs(message->duration));
865 
866  //Successful processing
867  return NO_ERROR;
868 }
869 
870 
871 /**
872  * @brief Dump WILLTOPICUPD message
873  * @param[in] message Pointer to the message
874  * @param[in] length Length of the message, in bytes
875  * @return Error code
876  **/
877 
879 {
880  //Malformed message?
881  if(length < sizeof(MqttSnWillTopicUpd))
882  return ERROR_INVALID_LENGTH;
883 
884  //Dump WILLTOPICUPD message
885  mqttSnDumpFlags(message->flags);
886  TRACE_DEBUG(" WillTopic = %s\r\n", message->willTopic);
887 
888  //Successful processing
889  return NO_ERROR;
890 }
891 
892 
893 /**
894  * @brief Dump WILLTOPICRESP message
895  * @param[in] message Pointer to the message
896  * @param[in] length Length of the message, in bytes
897  * @return Error code
898  **/
899 
901 {
902  //Malformed message?
903  if(length < sizeof(MqttSnWillTopicResp))
904  return ERROR_INVALID_LENGTH;
905 
906  //Dump WILLTOPICRESP message
907  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
908  mqttSnGetReturnCodeDesc(message->returnCode));
909 
910  //Successful processing
911  return NO_ERROR;
912 }
913 
914 
915 /**
916  * @brief Dump WILLMSGUPD message
917  * @param[in] message Pointer to the message
918  * @param[in] length Length of the message, in bytes
919  * @return Error code
920  **/
921 
923 {
924  //Dump WILLMSGUPD message
925  TRACE_DEBUG(" WillMsg (%" PRIuSIZE " bytes)\r\n", length);
927 
928  //Successful processing
929  return NO_ERROR;
930 }
931 
932 
933 /**
934  * @brief Dump WILLMSGRESP message
935  * @param[in] message Pointer to the message
936  * @param[in] length Length of the message, in bytes
937  * @return Error code
938  **/
939 
941 {
942  //Malformed message?
943  if(length < sizeof(MqttSnWillMsgResp))
944  return ERROR_INVALID_LENGTH;
945 
946  //Dump WILLMSGRESP message
947  TRACE_DEBUG(" ReturnCode = %" PRIu8 " (%s)\r\n", message->returnCode,
948  mqttSnGetReturnCodeDesc(message->returnCode));
949 
950  //Successful processing
951  return NO_ERROR;
952 }
953 
954 
955 /**
956  * @brief Dump flags
957  * @param[in] flags Value of the flags
958  **/
959 
961 {
962  //Check whether any flag is set
963  if(flags.all != 0)
964  {
965  //Dump the value of the Flags field
966  TRACE_DEBUG(" Flags = 0x%02" PRIX8 " (", flags.all);
967 
968  //Dump flags
969  while(1)
970  {
971  if(flags.dup)
972  {
973  TRACE_DEBUG("DUP");
974  flags.dup = FALSE;
975  }
976  else if(flags.qos == MQTT_SN_QOS_LEVEL_1)
977  {
978  TRACE_DEBUG("QoS Level 1");
979  flags.qos = 0;
980  }
981  else if(flags.qos == MQTT_SN_QOS_LEVEL_2)
982  {
983  TRACE_DEBUG("QoS Level 2");
984  flags.qos = 0;
985  }
986  else if(flags.qos == MQTT_SN_QOS_LEVEL_MINUS_1)
987  {
988  TRACE_DEBUG("QoS Level -1");
989  flags.qos = 0;
990  }
991  else if(flags.retain)
992  {
993  TRACE_DEBUG("Retain");
994  flags.retain = FALSE;
995  }
996  else if(flags.will)
997  {
998  TRACE_DEBUG("Will");
999  flags.will = FALSE;
1000  }
1001  else if(flags.cleanSession)
1002  {
1003  TRACE_DEBUG("Clean Session");
1004  flags.cleanSession = FALSE;
1005  }
1006  else if(flags.topicIdType == MQTT_SN_PREDEFINED_TOPIC_ID)
1007  {
1008  TRACE_DEBUG("Predefined Topic ID");
1009  flags.topicIdType = 0;
1010  }
1011  else if(flags.topicIdType == MQTT_SN_SHORT_TOPIC_NAME)
1012  {
1013  TRACE_DEBUG("Short Topic Name");
1014  flags.topicIdType = 0;
1015  }
1016  else
1017  {
1018  }
1019 
1020  if(flags.all != 0)
1021  {
1022  TRACE_DEBUG(", ");
1023  }
1024  else
1025  {
1026  TRACE_DEBUG(")\r\n");
1027  break;
1028  }
1029  }
1030  }
1031  else
1032  {
1033  //Dump the value of the Flags field
1034  TRACE_DEBUG(" Flags = 0x%02" PRIX8 "\r\n", flags.all);
1035  }
1036 }
1037 
1038 
1039 /**
1040  * @brief Get the name of the specified MQTT-SN message
1041  * @param[in] msgType Message type
1042  * @return Message name (NULL-terminated string)
1043  **/
1044 
1046 {
1047  //Default description
1048  static const char_t defaultLabel[] = "Unknown";
1049 
1050  //Get the name associated with the message type
1052  {
1053  return mqttSnMsgTypeLabel[msgType];
1054  }
1055  else
1056  {
1057  return defaultLabel;
1058  }
1059 }
1060 
1061 
1062 /**
1063  * @brief Get the description of the specified return code
1064  * @param[in] returnCode Value of the return code
1065  * @return Description of the return code (NULL-terminated string)
1066  **/
1067 
1069 {
1070  //Default description
1071  static const char_t defaultLabel[] = "Unknown";
1072 
1073  //Get the description associated with the return code
1075  {
1077  }
1078  else
1079  {
1080  return defaultLabel;
1081  }
1082 }
1083 
1084 #endif
uint8_t message[]
Definition: chap.h:154
uint8_t type
Definition: coap_common.h:176
#define PRIuSIZE
char char_t
Definition: compiler_port.h:48
#define ntohs(value)
Definition: cpu_endian.h:421
#define LOAD16BE(p)
Definition: cpu_endian.h:186
Debugging facilities.
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:108
#define TRACE_DEBUG(...)
Definition: debug.h:107
error_t
Error codes.
Definition: error.h:43
@ ERROR_INVALID_TYPE
Definition: error.h:115
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_INVALID_LENGTH
Definition: error.h:111
MQTT-SN client.
@ MQTT_SN_MSG_TYPE_WILLTOPICRESP
@ MQTT_SN_MSG_TYPE_SUBACK
@ MQTT_SN_MSG_TYPE_PINGREQ
@ MQTT_SN_MSG_TYPE_DISCONNECT
@ MQTT_SN_MSG_TYPE_UNSUBACK
@ MQTT_SN_MSG_TYPE_UNSUBSCRIBE
@ MQTT_SN_MSG_TYPE_GWINFO
@ MQTT_SN_MSG_TYPE_PUBLISH
@ MQTT_SN_MSG_TYPE_WILLTOPICUPD
@ MQTT_SN_MSG_TYPE_CONNECT
@ MQTT_SN_MSG_TYPE_ADVERTISE
@ MQTT_SN_MSG_TYPE_SUBSCRIBE
@ MQTT_SN_MSG_TYPE_PUBACK
@ MQTT_SN_MSG_TYPE_REGISTER
@ MQTT_SN_MSG_TYPE_WILLTOPICREQ
@ MQTT_SN_MSG_TYPE_PINGRESP
@ MQTT_SN_MSG_TYPE_WILLTOPIC
@ MQTT_SN_MSG_TYPE_WILLMSGUPD
@ MQTT_SN_MSG_TYPE_PUBREC
@ MQTT_SN_MSG_TYPE_WILLMSGRESP
@ MQTT_SN_MSG_TYPE_PUBCOMP
@ MQTT_SN_MSG_TYPE_WILLMSGREQ
@ MQTT_SN_MSG_TYPE_PUBREL
@ MQTT_SN_MSG_TYPE_REGACK
@ MQTT_SN_MSG_TYPE_CONNACK
@ MQTT_SN_MSG_TYPE_SEARCHGW
@ MQTT_SN_MSG_TYPE_WILLMSG
MqttSnPubRel
MqttSnSubAck
MqttSnPubComp
MqttSnSubscribe
MqttSnFlags
MqttSnAdvertise
MqttSnUnsubscribe
MqttSnWillTopicResp
MqttSnPubRec
MqttSnWillMsgResp
MqttSnPublish
MqttSnGwInfo
@ MQTT_SN_QOS_LEVEL_MINUS_1
No connection setup.
@ MQTT_SN_QOS_LEVEL_1
At least once delivery.
@ MQTT_SN_QOS_LEVEL_2
Exactly once delivery.
MqttSnHeader
MqttSnPubAck
MqttSnExtHeader
MqttSnWillTopicUpd
@ MQTT_SN_NORMAL_TOPIC_ID
Normal topic ID.
@ MQTT_SN_SHORT_TOPIC_NAME
Short topic name.
@ MQTT_SN_PREDEFINED_TOPIC_ID
Predefined topic ID.
@ MQTT_SN_NORMAL_TOPIC_NAME
Normal topic name.
void MqttSnPingResp
PINGRESP message.
MqttSnDisconnect
MqttSnRegAck
MqttSnSearchGw
void MqttSnWillMsgUpd
WILLMSGUPD message.
void MqttSnWillTopicReq
WILLTOPICREQ message.
uint8_t msgType
void MqttSnWillMsg
WILLMSG message.
void MqttSnWillMsgReq
WILLMSGREQ message.
uint8_t returnCode
MqttSnRegister
MqttSnConnAck
MqttSnConnect
MqttSnUnsubAck
MqttSnWillTopic
void MqttSnPingReq
PINGREQ message.
error_t mqttSnDumpPingResp(const MqttSnPingResp *message, size_t length)
Dump PINGRESP message.
const char_t *const mqttSnMsgTypeLabel[]
Definition: mqtt_sn_debug.c:44
error_t mqttSnDumpPubRec(const MqttSnPubRec *message, size_t length)
Dump PUBREC message.
error_t mqttSnDumpRegister(const MqttSnRegister *message, size_t length)
Dump REGISTER message.
error_t mqttSnDumpPubComp(const MqttSnPubComp *message, size_t length)
Dump PUBCOMP message.
const char_t *const mqttSnReturnCodeLabel[]
Definition: mqtt_sn_debug.c:79
error_t mqttSnDumpWillTopicReq(const MqttSnWillTopicReq *message, size_t length)
Dump WILLTOPICREQ message.
error_t mqttSnDumpDisconnect(const MqttSnDisconnect *message, size_t length)
Dump DISCONNECT message.
error_t mqttSnDumpWillMsgResp(const MqttSnWillMsgResp *message, size_t length)
Dump WILLMSGRESP message.
const char_t * mqttSnGetReturnCodeDesc(uint16_t returnCode)
Get the description of the specified return code.
error_t mqttSnDumpSearchGw(const MqttSnSearchGw *message, size_t length)
Dump SEARCHGW message.
error_t mqttSnDumpSubAck(const MqttSnSubAck *message, size_t length)
Dump SUBACK message.
const char_t * mqttSnGetMessageName(uint16_t msgType)
Get the name of the specified MQTT-SN message.
error_t mqttSnDumpGwInfo(const MqttSnGwInfo *message, size_t length)
Dump GWINFO message.
error_t mqttSnDumpUnsubAck(const MqttSnUnsubAck *message, size_t length)
Dump UNSUBACK message.
error_t mqttSnDumpWillTopicUpd(const MqttSnWillTopicUpd *message, size_t length)
Dump WILLTOPICUPD message.
error_t mqttSnDumpMessage(const uint8_t *message, size_t length)
Dump MQTT-SN message for debugging purpose.
Definition: mqtt_sn_debug.c:95
error_t mqttSnDumpConnect(const MqttSnConnect *message, size_t length)
Dump CONNECT message.
error_t mqttSnDumpSubscribe(const MqttSnSubscribe *message, size_t length)
Dump SUBSCRIBE message.
error_t mqttSnDumpConnAck(const MqttSnConnAck *message, size_t length)
Dump CONNACK message.
error_t mqttSnDumpPubRel(const MqttSnPubRel *message, size_t length)
Dump PUBREL message.
error_t mqttSnDumpWillTopic(const MqttSnWillTopic *message, size_t length)
Dump WILLTOPIC message.
error_t mqttSnDumpPubAck(const MqttSnPubAck *message, size_t length)
Dump PUBACK message.
error_t mqttSnDumpPingReq(const MqttSnPingReq *message, size_t length)
Dump PINGREQ message.
error_t mqttSnDumpRegAck(const MqttSnRegAck *message, size_t length)
Dump REGACK message.
error_t mqttSnDumpWillMsgReq(const MqttSnWillMsgReq *message, size_t length)
Dump WILLMSGREQ message.
error_t mqttSnDumpAdvertise(const MqttSnAdvertise *message, size_t length)
Dump ADVERTISE message.
void mqttSnDumpFlags(MqttSnFlags flags)
Dump flags.
error_t mqttSnDumpUnsubscribe(const MqttSnUnsubscribe *message, size_t length)
Dump UNSUBSCRIBE message.
error_t mqttSnDumpPublish(const MqttSnPublish *message, size_t length)
Dump PUBLISH message.
error_t mqttSnDumpWillMsgUpd(const MqttSnWillMsgUpd *message, size_t length)
Dump WILLMSGUPD message.
error_t mqttSnDumpWillMsg(const MqttSnWillMsg *message, size_t length)
Dump WILLMSG message.
error_t mqttSnDumpWillTopicResp(const MqttSnWillTopicResp *message, size_t length)
Dump WILLTOPICRESP message.
Data logging functions for debugging purpose (MQTT-SN)
TCP/IP stack core.
#define LSB(x)
Definition: os_port.h:55
#define arraysize(a)
Definition: os_port.h:71
#define FALSE
Definition: os_port.h:46
#define MSB(x)
Definition: os_port.h:59
uint8_t length
Definition: tcp.h:368
uint8_t flags
Definition: tcp.h:351