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