emqx_reason_codes.erl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. %% Copyright (c) 2018 EMQ Technologies Co., Ltd. All Rights Reserved.
  2. %%
  3. %% Licensed under the Apache License, Version 2.0 (the "License");
  4. %% you may not use this file except in compliance with the License.
  5. %% You may obtain a copy of the License at
  6. %%
  7. %% http://www.apache.org/licenses/LICENSE-2.0
  8. %%
  9. %% Unless required by applicable law or agreed to in writing, software
  10. %% distributed under the License is distributed on an "AS IS" BASIS,
  11. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. %% See the License for the specific language governing permissions and
  13. %% limitations under the License.
  14. %% @doc MQTT5 reason codes
  15. -module(emqx_reason_codes).
  16. -include("emqx_mqtt.hrl").
  17. -export([name/2, text/1]).
  18. -export([compat/2]).
  19. name(I, Ver) when Ver >= ?MQTT_PROTO_V5 ->
  20. name(I);
  21. name(0, _Ver) -> connection_acceptd;
  22. name(1, _Ver) -> unacceptable_protocol_version;
  23. name(2, _Ver) -> client_identifier_not_valid;
  24. name(3, _Ver) -> server_unavaliable;
  25. name(4, _Ver) -> malformed_username_or_password;
  26. name(5, _Ver) -> unauthorized_client;
  27. name(I, _Ver) -> list_to_atom("unkown_connack" ++ integer_to_list(I)).
  28. name(16#00) -> success;
  29. name(16#01) -> granted_qos1;
  30. name(16#02) -> granted_qos2;
  31. name(16#04) -> disconnect_with_will_message;
  32. name(16#10) -> no_matching_subscribers;
  33. name(16#11) -> no_subscription_existed;
  34. name(16#18) -> continue_authentication;
  35. name(16#19) -> re_authenticate;
  36. name(16#80) -> unspecified_error;
  37. name(16#81) -> malformed_Packet;
  38. name(16#82) -> protocol_error;
  39. name(16#83) -> implementation_specific_error;
  40. name(16#84) -> unsupported_protocol_version;
  41. name(16#85) -> client_identifier_not_valid;
  42. name(16#86) -> bad_username_or_password;
  43. name(16#87) -> not_authorized;
  44. name(16#88) -> server_unavailable;
  45. name(16#89) -> server_busy;
  46. name(16#8A) -> banned;
  47. name(16#8B) -> server_shutting_down;
  48. name(16#8C) -> bad_authentication_method;
  49. name(16#8D) -> keepalive_timeout;
  50. name(16#8E) -> session_taken_over;
  51. name(16#8F) -> topic_filter_invalid;
  52. name(16#90) -> topic_name_invalid;
  53. name(16#91) -> packet_identifier_inuse;
  54. name(16#92) -> packet_identifier_not_found;
  55. name(16#93) -> receive_maximum_exceeded;
  56. name(16#94) -> topic_alias_invalid;
  57. name(16#95) -> packet_too_large;
  58. name(16#96) -> message_rate_too_high;
  59. name(16#97) -> quota_exceeded;
  60. name(16#98) -> administrative_action;
  61. name(16#99) -> payload_format_invalid;
  62. name(16#9A) -> retain_not_supported;
  63. name(16#9B) -> qos_not_supported;
  64. name(16#9C) -> use_another_server;
  65. name(16#9D) -> server_moved;
  66. name(16#9E) -> shared_subscriptions_not_supported;
  67. name(16#9F) -> connection_rate_exceeded;
  68. name(16#A0) -> maximum_connect_time;
  69. name(16#A1) -> subscription_identifiers_not_supported;
  70. name(16#A2) -> wildcard_subscriptions_not_supported;
  71. name(Code) -> list_to_atom("unkown_reason_code" ++ integer_to_list(Code)).
  72. text(16#00) -> <<"Success">>;
  73. text(16#01) -> <<"Granted QoS 1">>;
  74. text(16#02) -> <<"Granted QoS 2">>;
  75. text(16#04) -> <<"Disconnect with Will Message">>;
  76. text(16#10) -> <<"No matching subscribers">>;
  77. text(16#11) -> <<"No subscription existed">>;
  78. text(16#18) -> <<"Continue authentication">>;
  79. text(16#19) -> <<"Re-authenticate">>;
  80. text(16#80) -> <<"Unspecified error">>;
  81. text(16#81) -> <<"Malformed Packet">>;
  82. text(16#82) -> <<"Protocol Error">>;
  83. text(16#83) -> <<"Implementation specific error">>;
  84. text(16#84) -> <<"Unsupported Protocol Version">>;
  85. text(16#85) -> <<"Client Identifier not valid">>;
  86. text(16#86) -> <<"Bad User Name or Password">>;
  87. text(16#87) -> <<"Not authorized">>;
  88. text(16#88) -> <<"Server unavailable">>;
  89. text(16#89) -> <<"Server busy">>;
  90. text(16#8A) -> <<"Banned">>;
  91. text(16#8B) -> <<"Server shutting down">>;
  92. text(16#8C) -> <<"Bad authentication method">>;
  93. text(16#8D) -> <<"Keep Alive timeout">>;
  94. text(16#8E) -> <<"Session taken over">>;
  95. text(16#8F) -> <<"Topic Filter invalid">>;
  96. text(16#90) -> <<"Topic Name invalid">>;
  97. text(16#91) -> <<"Packet Identifier in use">>;
  98. text(16#92) -> <<"Packet Identifier not found">>;
  99. text(16#93) -> <<"Receive Maximum exceeded">>;
  100. text(16#94) -> <<"Topic Alias invalid">>;
  101. text(16#95) -> <<"Packet too large">>;
  102. text(16#96) -> <<"Message rate too high">>;
  103. text(16#97) -> <<"Quota exceeded">>;
  104. text(16#98) -> <<"Administrative action">>;
  105. text(16#99) -> <<"Payload format invalid">>;
  106. text(16#9A) -> <<"Retain not supported">>;
  107. text(16#9B) -> <<"QoS not supported">>;
  108. text(16#9C) -> <<"Use another server">>;
  109. text(16#9D) -> <<"Server moved">>;
  110. text(16#9E) -> <<"Shared Subscriptions not supported">>;
  111. text(16#9F) -> <<"Connection rate exceeded">>;
  112. text(16#A0) -> <<"Maximum connect time">>;
  113. text(16#A1) -> <<"Subscription Identifiers not supported">>;
  114. text(16#A2) -> <<"Wildcard Subscriptions not supported">>;
  115. text(Code) -> iolist_to_binary(["Unkown Reason Code:", integer_to_list(Code)]).
  116. compat(connack, 16#80) -> ?CONNACK_PROTO_VER;
  117. compat(connack, 16#81) -> ?CONNACK_PROTO_VER;
  118. compat(connack, 16#82) -> ?CONNACK_PROTO_VER;
  119. compat(connack, 16#83) -> ?CONNACK_PROTO_VER;
  120. compat(connack, 16#84) -> ?CONNACK_PROTO_VER;
  121. compat(connack, 16#85) -> ?CONNACK_INVALID_ID;
  122. compat(connack, 16#86) -> ?CONNACK_CREDENTIALS;
  123. compat(connack, 16#87) -> ?CONNACK_AUTH;
  124. compat(connack, 16#88) -> ?CONNACK_SERVER;
  125. compat(connack, 16#89) -> ?CONNACK_SERVER;
  126. compat(connack, 16#8A) -> ?CONNACK_AUTH;
  127. compat(connack, 16#8B) -> ?CONNACK_SERVER;
  128. compat(connack, 16#8C) -> ?CONNACK_AUTH;
  129. compat(connack, 16#97) -> ?CONNACK_SERVER;
  130. compat(connack, 16#9C) -> ?CONNACK_SERVER;
  131. compat(connack, 16#9D) -> ?CONNACK_SERVER;
  132. compat(connack, 16#9F) -> ?CONNACK_SERVER;
  133. compat(suback, Code) when Code =< ?QOS2 -> Code;
  134. compat(suback, Code) when Code >= 16#80 -> 16#80.