netifapi.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * @file
  3. * netif API (to be used from non-TCPIP threads)
  4. */
  5. /*
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  20. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  22. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  25. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  26. * OF SUCH DAMAGE.
  27. *
  28. * This file is part of the lwIP TCP/IP stack.
  29. *
  30. */
  31. #ifndef LWIP_HDR_NETIFAPI_H
  32. #define LWIP_HDR_NETIFAPI_H
  33. #include "lwip/opt.h"
  34. #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
  35. #include "lwip/sys.h"
  36. #include "lwip/netif.h"
  37. #include "lwip/dhcp.h"
  38. #include "lwip/autoip.h"
  39. #include "lwip/priv/tcpip_priv.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #if LWIP_MPU_COMPATIBLE
  44. #define NETIFAPI_IPADDR_DEF(type, m) type m
  45. #else /* LWIP_MPU_COMPATIBLE */
  46. #define NETIFAPI_IPADDR_DEF(type, m) const type * m
  47. #endif /* LWIP_MPU_COMPATIBLE */
  48. typedef void (*netifapi_void_fn)(struct netif *netif);
  49. typedef err_t (*netifapi_errt_fn)(struct netif *netif);
  50. struct netifapi_msg {
  51. struct tcpip_api_call_data call;
  52. struct netif *netif;
  53. union {
  54. struct {
  55. #if LWIP_IPV4
  56. NETIFAPI_IPADDR_DEF(ip4_addr_t, ipaddr);
  57. NETIFAPI_IPADDR_DEF(ip4_addr_t, netmask);
  58. NETIFAPI_IPADDR_DEF(ip4_addr_t, gw);
  59. #endif /* LWIP_IPV4 */
  60. void *state;
  61. netif_init_fn init;
  62. netif_input_fn input;
  63. } add;
  64. struct {
  65. netifapi_void_fn voidfunc;
  66. netifapi_errt_fn errtfunc;
  67. } common;
  68. } msg;
  69. };
  70. /* API for application */
  71. err_t netifapi_netif_add(struct netif *netif,
  72. #if LWIP_IPV4
  73. const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
  74. #endif /* LWIP_IPV4 */
  75. void *state, netif_init_fn init, netif_input_fn input);
  76. #if LWIP_IPV4
  77. err_t netifapi_netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr,
  78. const ip4_addr_t *netmask, const ip4_addr_t *gw);
  79. #endif /* LWIP_IPV4*/
  80. err_t netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
  81. netifapi_errt_fn errtfunc);
  82. /** @ingroup netifapi_netif */
  83. #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL)
  84. /** @ingroup netifapi_netif */
  85. #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL)
  86. /** @ingroup netifapi_netif */
  87. #define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL)
  88. /** @ingroup netifapi_netif */
  89. #define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL)
  90. /** @ingroup netifapi_netif */
  91. #define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL)
  92. /** @ingroup netifapi_netif */
  93. #define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL)
  94. /**
  95. * @defgroup netifapi_dhcp4 DHCPv4
  96. * @ingroup netifapi
  97. * To be called from non-TCPIP threads
  98. */
  99. /** @ingroup netifapi_dhcp4 */
  100. #define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start)
  101. /** @ingroup netifapi_dhcp4 */
  102. #define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL)
  103. /** @ingroup netifapi_dhcp4 */
  104. #define netifapi_dhcp_inform(n) netifapi_netif_common(n, dhcp_inform, NULL)
  105. /** @ingroup netifapi_dhcp4 */
  106. #define netifapi_dhcp_renew(n) netifapi_netif_common(n, NULL, dhcp_renew)
  107. /** @ingroup netifapi_dhcp4 */
  108. #define netifapi_dhcp_release(n) netifapi_netif_common(n, NULL, dhcp_release)
  109. /**
  110. * @defgroup netifapi_autoip AUTOIP
  111. * @ingroup netifapi
  112. * To be called from non-TCPIP threads
  113. */
  114. /** @ingroup netifapi_autoip */
  115. #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start)
  116. /** @ingroup netifapi_autoip */
  117. #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop)
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* LWIP_NETIF_API */
  122. #endif /* LWIP_HDR_NETIFAPI_H */