ieee802154_mgmt.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2017 Intel Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief IEEE 802.15.4 Management interface public header
  9. */
  10. #ifndef ZEPHYR_INCLUDE_NET_IEEE802154_MGMT_H_
  11. #define ZEPHYR_INCLUDE_NET_IEEE802154_MGMT_H_
  12. #include <net/ieee802154.h>
  13. #include <net/net_mgmt.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief IEEE 802.15.4 library
  19. * @defgroup ieee802154_mgmt IEEE 802.15.4 Library
  20. * @ingroup networking
  21. * @{
  22. */
  23. #define _NET_IEEE802154_LAYER NET_MGMT_LAYER_L2
  24. #define _NET_IEEE802154_CODE 0x154
  25. #define _NET_IEEE802154_BASE (NET_MGMT_IFACE_BIT | \
  26. NET_MGMT_LAYER(_NET_IEEE802154_LAYER) |\
  27. NET_MGMT_LAYER_CODE(_NET_IEEE802154_CODE))
  28. #define _NET_IEEE802154_EVENT (_NET_IEEE802154_BASE | NET_MGMT_EVENT_BIT)
  29. enum net_request_ieee802154_cmd {
  30. NET_REQUEST_IEEE802154_CMD_SET_ACK = 1,
  31. NET_REQUEST_IEEE802154_CMD_UNSET_ACK,
  32. NET_REQUEST_IEEE802154_CMD_PASSIVE_SCAN,
  33. NET_REQUEST_IEEE802154_CMD_ACTIVE_SCAN,
  34. NET_REQUEST_IEEE802154_CMD_CANCEL_SCAN,
  35. NET_REQUEST_IEEE802154_CMD_ASSOCIATE,
  36. NET_REQUEST_IEEE802154_CMD_DISASSOCIATE,
  37. NET_REQUEST_IEEE802154_CMD_SET_CHANNEL,
  38. NET_REQUEST_IEEE802154_CMD_GET_CHANNEL,
  39. NET_REQUEST_IEEE802154_CMD_SET_PAN_ID,
  40. NET_REQUEST_IEEE802154_CMD_GET_PAN_ID,
  41. NET_REQUEST_IEEE802154_CMD_SET_EXT_ADDR,
  42. NET_REQUEST_IEEE802154_CMD_GET_EXT_ADDR,
  43. NET_REQUEST_IEEE802154_CMD_SET_SHORT_ADDR,
  44. NET_REQUEST_IEEE802154_CMD_GET_SHORT_ADDR,
  45. NET_REQUEST_IEEE802154_CMD_GET_TX_POWER,
  46. NET_REQUEST_IEEE802154_CMD_SET_TX_POWER,
  47. NET_REQUEST_IEEE802154_CMD_SET_SECURITY_SETTINGS,
  48. NET_REQUEST_IEEE802154_CMD_GET_SECURITY_SETTINGS,
  49. };
  50. #define NET_REQUEST_IEEE802154_SET_ACK \
  51. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_SET_ACK)
  52. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_ACK);
  53. #define NET_REQUEST_IEEE802154_UNSET_ACK \
  54. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_UNSET_ACK)
  55. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_UNSET_ACK);
  56. #define NET_REQUEST_IEEE802154_PASSIVE_SCAN \
  57. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_PASSIVE_SCAN)
  58. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_PASSIVE_SCAN);
  59. #define NET_REQUEST_IEEE802154_ACTIVE_SCAN \
  60. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_ACTIVE_SCAN)
  61. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_ACTIVE_SCAN);
  62. #define NET_REQUEST_IEEE802154_CANCEL_SCAN \
  63. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_CANCEL_SCAN)
  64. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_CANCEL_SCAN);
  65. #define NET_REQUEST_IEEE802154_ASSOCIATE \
  66. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_ASSOCIATE)
  67. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_ASSOCIATE);
  68. #define NET_REQUEST_IEEE802154_DISASSOCIATE \
  69. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_DISASSOCIATE)
  70. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_DISASSOCIATE);
  71. #define NET_REQUEST_IEEE802154_SET_CHANNEL \
  72. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_SET_CHANNEL)
  73. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_CHANNEL);
  74. #define NET_REQUEST_IEEE802154_GET_CHANNEL \
  75. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_GET_CHANNEL)
  76. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_CHANNEL);
  77. #define NET_REQUEST_IEEE802154_SET_PAN_ID \
  78. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_SET_PAN_ID)
  79. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_PAN_ID);
  80. #define NET_REQUEST_IEEE802154_GET_PAN_ID \
  81. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_GET_PAN_ID)
  82. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_PAN_ID);
  83. #define NET_REQUEST_IEEE802154_SET_EXT_ADDR \
  84. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_SET_EXT_ADDR)
  85. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_EXT_ADDR);
  86. #define NET_REQUEST_IEEE802154_GET_EXT_ADDR \
  87. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_GET_EXT_ADDR)
  88. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_EXT_ADDR);
  89. #define NET_REQUEST_IEEE802154_SET_SHORT_ADDR \
  90. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_SET_SHORT_ADDR)
  91. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_SHORT_ADDR);
  92. #define NET_REQUEST_IEEE802154_GET_SHORT_ADDR \
  93. (_NET_IEEE802154_BASE | NET_REQUEST_IEEE802154_CMD_GET_SHORT_ADDR)
  94. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_SHORT_ADDR);
  95. #define NET_REQUEST_IEEE802154_GET_TX_POWER \
  96. (_NET_IEEE802154_BASE | \
  97. NET_REQUEST_IEEE802154_CMD_GET_TX_POWER)
  98. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_TX_POWER);
  99. #define NET_REQUEST_IEEE802154_SET_TX_POWER \
  100. (_NET_IEEE802154_BASE | \
  101. NET_REQUEST_IEEE802154_CMD_SET_TX_POWER)
  102. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_TX_POWER);
  103. #ifdef CONFIG_NET_L2_IEEE802154_SECURITY
  104. #define NET_REQUEST_IEEE802154_SET_SECURITY_SETTINGS \
  105. (_NET_IEEE802154_BASE | \
  106. NET_REQUEST_IEEE802154_CMD_SET_SECURITY_SETTINGS)
  107. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_SET_SECURITY_SETTINGS);
  108. #define NET_REQUEST_IEEE802154_GET_SECURITY_SETTINGS \
  109. (_NET_IEEE802154_BASE | \
  110. NET_REQUEST_IEEE802154_CMD_GET_SECURITY_SETTINGS)
  111. NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_IEEE802154_GET_SECURITY_SETTINGS);
  112. #endif /* CONFIG_NET_L2_IEEE802154_SECURITY */
  113. enum net_event_ieee802154_cmd {
  114. NET_EVENT_IEEE802154_CMD_SCAN_RESULT = 1,
  115. };
  116. #define NET_EVENT_IEEE802154_SCAN_RESULT \
  117. (_NET_IEEE802154_EVENT | NET_EVENT_IEEE802154_CMD_SCAN_RESULT)
  118. #define IEEE802154_IS_CHAN_SCANNED(_channel_set, _chan) \
  119. (_channel_set & BIT(_chan - 1))
  120. #define IEEE802154_IS_CHAN_UNSCANNED(_channel_set, _chan) \
  121. (!IEEE802154_IS_CHAN_SCANNED(_channel_set, _chan))
  122. /* Useful define to request all channels to be scanned,
  123. * from 11 to 26 included.
  124. */
  125. #define IEEE802154_ALL_CHANNELS (0x03FFFC00)
  126. /**
  127. * @brief Scanning parameters
  128. *
  129. * Used to request a scan and get results as well
  130. */
  131. struct ieee802154_req_params {
  132. /** The set of channels to scan, use above macros to manage it */
  133. uint32_t channel_set;
  134. /** Duration of scan, per-channel, in milliseconds */
  135. uint32_t duration;
  136. /** Current channel in use as a result */
  137. uint16_t channel;
  138. /** Current pan_id in use as a result */
  139. uint16_t pan_id;
  140. /** Result address */
  141. union {
  142. uint8_t addr[IEEE802154_MAX_ADDR_LENGTH];
  143. uint16_t short_addr;
  144. };
  145. /** length of address */
  146. uint8_t len;
  147. /** Link quality information, between 0 and 255 */
  148. uint8_t lqi;
  149. };
  150. /**
  151. * @brief Security parameters
  152. *
  153. * Used to setup the link-layer security settings
  154. */
  155. struct ieee802154_security_params {
  156. uint8_t key[16];
  157. uint8_t key_len;
  158. uint8_t key_mode : 2;
  159. uint8_t level : 3;
  160. uint8_t _unused : 3;
  161. };
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. /**
  166. * @}
  167. */
  168. #endif /* ZEPHYR_INCLUDE_NET_IEEE802154_MGMT_H_ */