emqx_coap.hrl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 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. -ifndef(EMQX_COAP_HRL).
  17. -define(APP, emqx_coap).
  18. -define(DEFAULT_COAP_PORT, 5683).
  19. -define(DEFAULT_COAPS_PORT, 5684).
  20. -define(MAX_MESSAGE_ID, 65535).
  21. -define(MAX_BLOCK_SIZE, 1024).
  22. -define(DEFAULT_MAX_AGE, 60).
  23. -define(MAXIMUM_MAX_AGE, 4294967295).
  24. -type coap_message_id() :: 1..?MAX_MESSAGE_ID.
  25. -type message_type() :: con | non | ack | reset.
  26. -type max_age() :: 1..?MAXIMUM_MAX_AGE.
  27. -type message_option_name() ::
  28. if_match
  29. | uri_host
  30. | etag
  31. | if_none_match
  32. | uri_port
  33. | location_path
  34. | uri_path
  35. | content_format
  36. | max_age
  37. | uri_query
  38. | 'accept'
  39. | location_query
  40. | proxy_uri
  41. | proxy_scheme
  42. | size1
  43. | observer
  44. | block1
  45. | block2.
  46. -type message_options() :: #{
  47. if_match => list(binary()),
  48. uri_host => binary(),
  49. etag => list(binary()),
  50. if_none_match => boolean(),
  51. uri_port => 0..65535,
  52. location_path => list(binary()),
  53. uri_path => list(binary()),
  54. content_format => 0..65535,
  55. max_age => non_neg_integer(),
  56. uri_query => list(binary()) | map(),
  57. 'accept' => 0..65535,
  58. location_query => list(binary()),
  59. proxy_uri => binary(),
  60. proxy_scheme => binary(),
  61. size1 => non_neg_integer(),
  62. observer => non_neg_integer(),
  63. block1 => {non_neg_integer(), boolean(), non_neg_integer()},
  64. block2 => {non_neg_integer(), boolean(), non_neg_integer()}
  65. }.
  66. -record(coap_mqtt_auth, {clientid, username, password}).
  67. -record(coap_message, {
  68. type :: message_type(),
  69. method,
  70. id,
  71. token = <<>>,
  72. options = #{},
  73. payload = <<>>
  74. }).
  75. -type coap_message() :: #coap_message{}.
  76. -define(QUERY_PARAMS_MAPPING, [
  77. {<<"c">>, <<"clientid">>},
  78. {<<"t">>, <<"token">>},
  79. {<<"u">>, <<"username">>},
  80. {<<"p">>, <<"password">>},
  81. {<<"q">>, <<"qos">>},
  82. {<<"r">>, <<"retain">>}
  83. ]).
  84. -endif.