net_event.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Copyright (c) 2016 Intel Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Network Events code public header
  9. */
  10. #ifndef ZEPHYR_INCLUDE_NET_NET_EVENT_H_
  11. #define ZEPHYR_INCLUDE_NET_NET_EVENT_H_
  12. #include <net/net_ip.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /**
  17. * @addtogroup net_mgmt
  18. * @{
  19. */
  20. /** @cond INTERNAL_HIDDEN */
  21. /* Network Interface events */
  22. #define _NET_IF_LAYER NET_MGMT_LAYER_L2
  23. #define _NET_IF_CORE_CODE 0x001
  24. #define _NET_EVENT_IF_BASE (NET_MGMT_EVENT_BIT | \
  25. NET_MGMT_IFACE_BIT | \
  26. NET_MGMT_LAYER(_NET_IF_LAYER) | \
  27. NET_MGMT_LAYER_CODE(_NET_IF_CORE_CODE))
  28. enum net_event_if_cmd {
  29. NET_EVENT_IF_CMD_DOWN = 1,
  30. NET_EVENT_IF_CMD_UP,
  31. };
  32. #define NET_EVENT_IF_DOWN \
  33. (_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_DOWN)
  34. #define NET_EVENT_IF_UP \
  35. (_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_UP)
  36. /* IPv6 Events */
  37. #define _NET_IPV6_LAYER NET_MGMT_LAYER_L3
  38. #define _NET_IPV6_CORE_CODE 0x060
  39. #define _NET_EVENT_IPV6_BASE (NET_MGMT_EVENT_BIT | \
  40. NET_MGMT_IFACE_BIT | \
  41. NET_MGMT_LAYER(_NET_IPV6_LAYER) | \
  42. NET_MGMT_LAYER_CODE(_NET_IPV6_CORE_CODE))
  43. enum net_event_ipv6_cmd {
  44. NET_EVENT_IPV6_CMD_ADDR_ADD = 1,
  45. NET_EVENT_IPV6_CMD_ADDR_DEL,
  46. NET_EVENT_IPV6_CMD_MADDR_ADD,
  47. NET_EVENT_IPV6_CMD_MADDR_DEL,
  48. NET_EVENT_IPV6_CMD_PREFIX_ADD,
  49. NET_EVENT_IPV6_CMD_PREFIX_DEL,
  50. NET_EVENT_IPV6_CMD_MCAST_JOIN,
  51. NET_EVENT_IPV6_CMD_MCAST_LEAVE,
  52. NET_EVENT_IPV6_CMD_ROUTER_ADD,
  53. NET_EVENT_IPV6_CMD_ROUTER_DEL,
  54. NET_EVENT_IPV6_CMD_ROUTE_ADD,
  55. NET_EVENT_IPV6_CMD_ROUTE_DEL,
  56. NET_EVENT_IPV6_CMD_DAD_SUCCEED,
  57. NET_EVENT_IPV6_CMD_DAD_FAILED,
  58. NET_EVENT_IPV6_CMD_NBR_ADD,
  59. NET_EVENT_IPV6_CMD_NBR_DEL,
  60. };
  61. #define NET_EVENT_IPV6_ADDR_ADD \
  62. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_ADD)
  63. #define NET_EVENT_IPV6_ADDR_DEL \
  64. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_DEL)
  65. #define NET_EVENT_IPV6_MADDR_ADD \
  66. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_ADD)
  67. #define NET_EVENT_IPV6_MADDR_DEL \
  68. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_DEL)
  69. #define NET_EVENT_IPV6_PREFIX_ADD \
  70. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_ADD)
  71. #define NET_EVENT_IPV6_PREFIX_DEL \
  72. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_PREFIX_DEL)
  73. #define NET_EVENT_IPV6_MCAST_JOIN \
  74. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_JOIN)
  75. #define NET_EVENT_IPV6_MCAST_LEAVE \
  76. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MCAST_LEAVE)
  77. #define NET_EVENT_IPV6_ROUTER_ADD \
  78. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_ADD)
  79. #define NET_EVENT_IPV6_ROUTER_DEL \
  80. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_DEL)
  81. #define NET_EVENT_IPV6_ROUTE_ADD \
  82. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_ADD)
  83. #define NET_EVENT_IPV6_ROUTE_DEL \
  84. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_DEL)
  85. #define NET_EVENT_IPV6_DAD_SUCCEED \
  86. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_SUCCEED)
  87. #define NET_EVENT_IPV6_DAD_FAILED \
  88. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_FAILED)
  89. #define NET_EVENT_IPV6_NBR_ADD \
  90. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_ADD)
  91. #define NET_EVENT_IPV6_NBR_DEL \
  92. (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_DEL)
  93. /* IPv4 Events*/
  94. #define _NET_IPV4_LAYER NET_MGMT_LAYER_L3
  95. #define _NET_IPV4_CORE_CODE 0x004
  96. #define _NET_EVENT_IPV4_BASE (NET_MGMT_EVENT_BIT | \
  97. NET_MGMT_IFACE_BIT | \
  98. NET_MGMT_LAYER(_NET_IPV4_LAYER) | \
  99. NET_MGMT_LAYER_CODE(_NET_IPV4_CORE_CODE))
  100. enum net_event_ipv4_cmd {
  101. NET_EVENT_IPV4_CMD_ADDR_ADD = 1,
  102. NET_EVENT_IPV4_CMD_ADDR_DEL,
  103. NET_EVENT_IPV4_CMD_ROUTER_ADD,
  104. NET_EVENT_IPV4_CMD_ROUTER_DEL,
  105. NET_EVENT_IPV4_CMD_DHCP_START,
  106. NET_EVENT_IPV4_CMD_DHCP_BOUND,
  107. NET_EVENT_IPV4_CMD_DHCP_STOP,
  108. NET_EVENT_IPV4_CMD_MCAST_JOIN,
  109. NET_EVENT_IPV4_CMD_MCAST_LEAVE,
  110. };
  111. #define NET_EVENT_IPV4_ADDR_ADD \
  112. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_ADD)
  113. #define NET_EVENT_IPV4_ADDR_DEL \
  114. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_DEL)
  115. #define NET_EVENT_IPV4_ROUTER_ADD \
  116. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_ADD)
  117. #define NET_EVENT_IPV4_ROUTER_DEL \
  118. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ROUTER_DEL)
  119. #define NET_EVENT_IPV4_DHCP_START \
  120. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_START)
  121. #define NET_EVENT_IPV4_DHCP_BOUND \
  122. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_BOUND)
  123. #define NET_EVENT_IPV4_DHCP_STOP \
  124. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_STOP)
  125. #define NET_EVENT_IPV4_MCAST_JOIN \
  126. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_JOIN)
  127. #define NET_EVENT_IPV4_MCAST_LEAVE \
  128. (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_LEAVE)
  129. /* L4 network events */
  130. #define _NET_L4_LAYER NET_MGMT_LAYER_L4
  131. #define _NET_L4_CORE_CODE 0x114
  132. #define _NET_EVENT_L4_BASE (NET_MGMT_EVENT_BIT | \
  133. NET_MGMT_IFACE_BIT | \
  134. NET_MGMT_LAYER(_NET_L4_LAYER) | \
  135. NET_MGMT_LAYER_CODE(_NET_L4_CORE_CODE))
  136. enum net_event_l4_cmd {
  137. NET_EVENT_L4_CMD_CONNECTED = 1,
  138. NET_EVENT_L4_CMD_DISCONNECTED,
  139. NET_EVENT_L4_CMD_DNS_SERVER_ADD,
  140. NET_EVENT_L4_CMD_DNS_SERVER_DEL,
  141. };
  142. #define NET_EVENT_L4_CONNECTED \
  143. (_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_CONNECTED)
  144. #define NET_EVENT_L4_DISCONNECTED \
  145. (_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DISCONNECTED)
  146. #define NET_EVENT_DNS_SERVER_ADD \
  147. (_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_ADD)
  148. #define NET_EVENT_DNS_SERVER_DEL \
  149. (_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_DEL)
  150. /** @endcond */
  151. #ifdef CONFIG_NET_MGMT_EVENT_INFO
  152. /**
  153. * @brief Network Management event information structure
  154. * Used to pass information on network events like
  155. * NET_EVENT_IPV6_ADDR_ADD,
  156. * NET_EVENT_IPV6_ADDR_DEL,
  157. * NET_EVENT_IPV6_MADDR_ADD and
  158. * NET_EVENT_IPV6_MADDR_DEL
  159. * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
  160. * information.
  161. */
  162. struct net_event_ipv6_addr {
  163. struct in6_addr addr;
  164. };
  165. /**
  166. * @brief Network Management event information structure
  167. * Used to pass information on network events like
  168. * NET_EVENT_IPV6_NBR_ADD and
  169. * NET_EVENT_IPV6_NBR_DEL
  170. * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
  171. * information.
  172. * @Note: idx will be '-1' in case of NET_EVENT_IPV6_NBR_DEL event.
  173. */
  174. struct net_event_ipv6_nbr {
  175. struct in6_addr addr;
  176. int idx; /* NBR index*/
  177. };
  178. /**
  179. * @brief Network Management event information structure
  180. * Used to pass information on network events like
  181. * NET_EVENT_IPV6_ROUTE_ADD and
  182. * NET_EVENT_IPV6_ROUTE_DEL
  183. * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
  184. * information.
  185. */
  186. struct net_event_ipv6_route {
  187. struct in6_addr nexthop;
  188. struct in6_addr addr; /* addr/prefix */
  189. uint8_t prefix_len;
  190. };
  191. #endif /* CONFIG_NET_MGMT_EVENT_INFO */
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. /**
  196. * @}
  197. */
  198. #endif /* ZEPHYR_INCLUDE_NET_NET_EVENT_H_ */