MQTTConnect.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*******************************************************************************
  2. * Copyright (c) 2014 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. * Xiang Rong - 442039 Add makefile to Embedded C client
  16. *******************************************************************************/
  17. #ifndef MQTTCONNECT_H_
  18. #define MQTTCONNECT_H_
  19. #if !defined(DLLImport)
  20. #define DLLImport
  21. #endif
  22. #if !defined(DLLExport)
  23. #define DLLExport
  24. #endif
  25. typedef union
  26. {
  27. unsigned char all; /**< all connect flags */
  28. #if defined(REVERSED)
  29. struct
  30. {
  31. unsigned int username : 1; /**< 3.1 user name */
  32. unsigned int password : 1; /**< 3.1 password */
  33. unsigned int willRetain : 1; /**< will retain setting */
  34. unsigned int willQoS : 2; /**< will QoS value */
  35. unsigned int will : 1; /**< will flag */
  36. unsigned int cleansession : 1; /**< clean session flag */
  37. unsigned int : 1; /**< unused */
  38. } bits;
  39. #else
  40. struct
  41. {
  42. unsigned int : 1; /**< unused */
  43. unsigned int cleansession : 1; /**< cleansession flag */
  44. unsigned int will : 1; /**< will flag */
  45. unsigned int willQoS : 2; /**< will QoS value */
  46. unsigned int willRetain : 1; /**< will retain setting */
  47. unsigned int password : 1; /**< 3.1 password */
  48. unsigned int username : 1; /**< 3.1 user name */
  49. } bits;
  50. #endif
  51. } MQTTConnectFlags; /**< connect flags byte */
  52. /**
  53. * Defines the MQTT "Last Will and Testament" (LWT) settings for
  54. * the connect packet.
  55. */
  56. typedef struct
  57. {
  58. /** The eyecatcher for this structure. must be MQTW. */
  59. char struct_id[4];
  60. /** The version number of this structure. Must be 0 */
  61. int struct_version;
  62. /** The LWT topic to which the LWT message will be published. */
  63. MQTTString topicName;
  64. /** The LWT payload. */
  65. MQTTString message;
  66. /**
  67. * The retained flag for the LWT message (see MQTTAsync_message.retained).
  68. */
  69. unsigned char retained;
  70. /**
  71. * The quality of service setting for the LWT message (see
  72. * MQTTAsync_message.qos and @ref qos).
  73. */
  74. char qos;
  75. } MQTTPacket_willOptions;
  76. #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 }
  77. typedef struct
  78. {
  79. /** The eyecatcher for this structure. must be MQTC. */
  80. char struct_id[4];
  81. /** The version number of this structure. Must be 0 */
  82. int struct_version;
  83. /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1
  84. */
  85. unsigned char MQTTVersion;
  86. MQTTString clientID;
  87. unsigned short keepAliveInterval;
  88. unsigned char cleansession;
  89. unsigned char willFlag;
  90. MQTTPacket_willOptions will;
  91. MQTTString username;
  92. MQTTString password;
  93. } MQTTPacket_connectData;
  94. typedef union
  95. {
  96. unsigned char all; /**< all connack flags */
  97. #if defined(REVERSED)
  98. struct
  99. {
  100. unsigned int sessionpresent : 1; /**< session present flag */
  101. unsigned int : 7; /**< unused */
  102. } bits;
  103. #else
  104. struct
  105. {
  106. unsigned int : 7; /**< unused */
  107. unsigned int sessionpresent : 1; /**< session present flag */
  108. } bits;
  109. #endif
  110. } MQTTConnackFlags; /**< connack flags byte */
  111. #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
  112. MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
  113. DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options);
  114. DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len);
  115. DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent);
  116. DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen);
  117. DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen);
  118. DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen);
  119. #endif /* MQTTCONNECT_H_ */