emqx_reason_codes.erl 6.7 KB

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