netifapi.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Redistribution and use in source and binary forms, with or without modification,
  3. * are permitted provided that the following conditions are met:
  4. *
  5. * 1. Redistributions of source code must retain the above copyright notice,
  6. * this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation
  9. * and/or other materials provided with the distribution.
  10. * 3. The name of the author may not be used to endorse or promote products
  11. * derived from this software without specific prior written permission.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  16. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  18. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  21. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  22. * OF SUCH DAMAGE.
  23. *
  24. * This file is part of the lwIP TCP/IP stack.
  25. *
  26. */
  27. #ifndef __LWIP_NETIFAPI_H__
  28. #define __LWIP_NETIFAPI_H__
  29. #include "lwip/opt.h"
  30. #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
  31. #include "lwip/sys.h"
  32. #include "lwip/netif.h"
  33. #include "lwip/dhcp.h"
  34. #include "lwip/autoip.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. typedef void (*netifapi_void_fn)(struct netif *netif);
  39. typedef err_t (*netifapi_errt_fn)(struct netif *netif);
  40. struct netifapi_msg_msg {
  41. #if !LWIP_TCPIP_CORE_LOCKING
  42. sys_sem_t sem;
  43. #endif /* !LWIP_TCPIP_CORE_LOCKING */
  44. err_t err;
  45. struct netif *netif;
  46. union {
  47. struct {
  48. ip_addr_t *ipaddr;
  49. ip_addr_t *netmask;
  50. ip_addr_t *gw;
  51. void *state;
  52. netif_init_fn init;
  53. netif_input_fn input;
  54. } add;
  55. struct {
  56. netifapi_void_fn voidfunc;
  57. netifapi_errt_fn errtfunc;
  58. } common;
  59. } msg;
  60. };
  61. struct netifapi_msg {
  62. void (* function)(struct netifapi_msg_msg *msg);
  63. struct netifapi_msg_msg msg;
  64. };
  65. /* API for application */
  66. err_t netifapi_netif_add ( struct netif *netif,
  67. ip_addr_t *ipaddr,
  68. ip_addr_t *netmask,
  69. ip_addr_t *gw,
  70. void *state,
  71. netif_init_fn init,
  72. netif_input_fn input);
  73. err_t netifapi_netif_set_addr ( struct netif *netif,
  74. ip_addr_t *ipaddr,
  75. ip_addr_t *netmask,
  76. ip_addr_t *gw );
  77. err_t netifapi_netif_common ( struct netif *netif,
  78. netifapi_void_fn voidfunc,
  79. netifapi_errt_fn errtfunc);
  80. #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL)
  81. #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL)
  82. #define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL)
  83. #define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL)
  84. #define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start)
  85. #define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL)
  86. #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start)
  87. #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop)
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* LWIP_NETIF_API */
  92. #endif /* __LWIP_NETIFAPI_H__ */