emqx_reason_codes.erl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020 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([ name/1
  20. , name/2
  21. , text/1
  22. , text/2
  23. ]).
  24. -export([ frame_error/1
  25. , connack_error/1
  26. ]).
  27. -export([compat/2]).
  28. name(I, Ver) when Ver >= ?MQTT_PROTO_V5 ->
  29. name(I);
  30. name(0, _Ver) -> connection_accepted;
  31. name(1, _Ver) -> unacceptable_protocol_version;
  32. name(2, _Ver) -> client_identifier_not_valid;
  33. name(3, _Ver) -> server_unavaliable;
  34. name(4, _Ver) -> malformed_username_or_password;
  35. name(5, _Ver) -> unauthorized_client;
  36. name(_, _Ver) -> unknown_error.
  37. name(16#00) -> success;
  38. name(16#01) -> granted_qos1;
  39. name(16#02) -> granted_qos2;
  40. name(16#04) -> disconnect_with_will_message;
  41. name(16#10) -> no_matching_subscribers;
  42. name(16#11) -> no_subscription_existed;
  43. name(16#18) -> continue_authentication;
  44. name(16#19) -> re_authenticate;
  45. name(16#80) -> unspecified_error;
  46. name(16#81) -> malformed_packet;
  47. name(16#82) -> protocol_error;
  48. name(16#83) -> implementation_specific_error;
  49. name(16#84) -> unsupported_protocol_version;
  50. name(16#85) -> client_identifier_not_valid;
  51. name(16#86) -> bad_username_or_password;
  52. name(16#87) -> not_authorized;
  53. name(16#88) -> server_unavailable;
  54. name(16#89) -> server_busy;
  55. name(16#8A) -> banned;
  56. name(16#8B) -> server_shutting_down;
  57. name(16#8C) -> bad_authentication_method;
  58. name(16#8D) -> keepalive_timeout;
  59. name(16#8E) -> session_taken_over;
  60. name(16#8F) -> topic_filter_invalid;
  61. name(16#90) -> topic_name_invalid;
  62. name(16#91) -> packet_identifier_inuse;
  63. name(16#92) -> packet_identifier_not_found;
  64. name(16#93) -> receive_maximum_exceeded;
  65. name(16#94) -> topic_alias_invalid;
  66. name(16#95) -> packet_too_large;
  67. name(16#96) -> message_rate_too_high;
  68. name(16#97) -> quota_exceeded;
  69. name(16#98) -> administrative_action;
  70. name(16#99) -> payload_format_invalid;
  71. name(16#9A) -> retain_not_supported;
  72. name(16#9B) -> qos_not_supported;
  73. name(16#9C) -> use_another_server;
  74. name(16#9D) -> server_moved;
  75. name(16#9E) -> shared_subscriptions_not_supported;
  76. name(16#9F) -> connection_rate_exceeded;
  77. name(16#A0) -> maximum_connect_time;
  78. name(16#A1) -> subscription_identifiers_not_supported;
  79. name(16#A2) -> wildcard_subscriptions_not_supported;
  80. name(_Code) -> unknown_error.
  81. text(I, Ver) when Ver >= ?MQTT_PROTO_V5 ->
  82. text(I);
  83. text(0, _Ver) -> <<"Connection accepted">>;
  84. text(1, _Ver) -> <<"unacceptable_protocol_version">>;
  85. text(2, _Ver) -> <<"client_identifier_not_valid">>;
  86. text(3, _Ver) -> <<"server_unavaliable">>;
  87. text(4, _Ver) -> <<"malformed_username_or_password">>;
  88. text(5, _Ver) -> <<"unauthorized_client">>;
  89. text(_, _Ver) -> <<"unknown_error">>.
  90. text(16#00) -> <<"Success">>;
  91. text(16#01) -> <<"Granted QoS 1">>;
  92. text(16#02) -> <<"Granted QoS 2">>;
  93. text(16#04) -> <<"Disconnect with Will Message">>;
  94. text(16#10) -> <<"No matching subscribers">>;
  95. text(16#11) -> <<"No subscription existed">>;
  96. text(16#18) -> <<"Continue authentication">>;
  97. text(16#19) -> <<"Re-authenticate">>;
  98. text(16#80) -> <<"Unspecified error">>;
  99. text(16#81) -> <<"Malformed Packet">>;
  100. text(16#82) -> <<"Protocol Error">>;
  101. text(16#83) -> <<"Implementation specific error">>;
  102. text(16#84) -> <<"Unsupported Protocol Version">>;
  103. text(16#85) -> <<"Client Identifier not valid">>;
  104. text(16#86) -> <<"Bad User Name or Password">>;
  105. text(16#87) -> <<"Not authorized">>;
  106. text(16#88) -> <<"Server unavailable">>;
  107. text(16#89) -> <<"Server busy">>;
  108. text(16#8A) -> <<"Banned">>;
  109. text(16#8B) -> <<"Server shutting down">>;
  110. text(16#8C) -> <<"Bad authentication method">>;
  111. text(16#8D) -> <<"Keep Alive timeout">>;
  112. text(16#8E) -> <<"Session taken over">>;
  113. text(16#8F) -> <<"Topic Filter invalid">>;
  114. text(16#90) -> <<"Topic Name invalid">>;
  115. text(16#91) -> <<"Packet Identifier in use">>;
  116. text(16#92) -> <<"Packet Identifier not found">>;
  117. text(16#93) -> <<"Receive Maximum exceeded">>;
  118. text(16#94) -> <<"Topic Alias invalid">>;
  119. text(16#95) -> <<"Packet too large">>;
  120. text(16#96) -> <<"Message rate too high">>;
  121. text(16#97) -> <<"Quota exceeded">>;
  122. text(16#98) -> <<"Administrative action">>;
  123. text(16#99) -> <<"Payload format invalid">>;
  124. text(16#9A) -> <<"Retain not supported">>;
  125. text(16#9B) -> <<"QoS not supported">>;
  126. text(16#9C) -> <<"Use another server">>;
  127. text(16#9D) -> <<"Server moved">>;
  128. text(16#9E) -> <<"Shared Subscriptions not supported">>;
  129. text(16#9F) -> <<"Connection rate exceeded">>;
  130. text(16#A0) -> <<"Maximum connect time">>;
  131. text(16#A1) -> <<"Subscription Identifiers not supported">>;
  132. text(16#A2) -> <<"Wildcard Subscriptions not supported">>;
  133. text(_Code) -> <<"Unknown error">>.
  134. compat(connack, 16#80) -> ?CONNACK_PROTO_VER;
  135. compat(connack, 16#81) -> ?CONNACK_PROTO_VER;
  136. compat(connack, 16#82) -> ?CONNACK_PROTO_VER;
  137. compat(connack, 16#83) -> ?CONNACK_PROTO_VER;
  138. compat(connack, 16#84) -> ?CONNACK_PROTO_VER;
  139. compat(connack, 16#85) -> ?CONNACK_INVALID_ID;
  140. compat(connack, 16#86) -> ?CONNACK_CREDENTIALS;
  141. compat(connack, 16#87) -> ?CONNACK_AUTH;
  142. compat(connack, 16#88) -> ?CONNACK_SERVER;
  143. compat(connack, 16#89) -> ?CONNACK_SERVER;
  144. compat(connack, 16#8A) -> ?CONNACK_AUTH;
  145. compat(connack, 16#8B) -> ?CONNACK_SERVER;
  146. compat(connack, 16#8C) -> ?CONNACK_AUTH;
  147. compat(connack, 16#90) -> ?CONNACK_SERVER;
  148. compat(connack, 16#97) -> ?CONNACK_SERVER;
  149. compat(connack, 16#9C) -> ?CONNACK_SERVER;
  150. compat(connack, 16#9D) -> ?CONNACK_SERVER;
  151. compat(connack, 16#9F) -> ?CONNACK_SERVER;
  152. compat(suback, Code) when Code =< ?QOS_2 -> Code;
  153. compat(suback, Code) when Code >= 16#80 -> 16#80;
  154. compat(unsuback, _Code) -> undefined;
  155. compat(_Other, _Code) -> undefined.
  156. frame_error(frame_too_large) -> ?RC_PACKET_TOO_LARGE;
  157. frame_error(_) -> ?RC_MALFORMED_PACKET.
  158. connack_error(protocol_error) -> ?RC_PROTOCOL_ERROR;
  159. connack_error(client_identifier_not_valid) -> ?RC_CLIENT_IDENTIFIER_NOT_VALID;
  160. connack_error(bad_username_or_password) -> ?RC_BAD_USER_NAME_OR_PASSWORD;
  161. connack_error(bad_clientid_or_password) -> ?RC_BAD_USER_NAME_OR_PASSWORD;
  162. connack_error(username_or_password_undefined) -> ?RC_BAD_USER_NAME_OR_PASSWORD;
  163. connack_error(password_error) -> ?RC_BAD_USER_NAME_OR_PASSWORD;
  164. connack_error(not_authorized) -> ?RC_NOT_AUTHORIZED;
  165. connack_error(server_unavailable) -> ?RC_SERVER_UNAVAILABLE;
  166. connack_error(server_busy) -> ?RC_SERVER_BUSY;
  167. connack_error(banned) -> ?RC_BANNED;
  168. connack_error(bad_authentication_method) -> ?RC_BAD_AUTHENTICATION_METHOD;
  169. %% TODO: ???
  170. connack_error(_) -> ?RC_NOT_AUTHORIZED.