tcpip.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  19. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  21. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  25. * OF SUCH DAMAGE.
  26. *
  27. * This file is part of the lwIP TCP/IP stack.
  28. *
  29. * Author: Adam Dunkels <adam@sics.se>
  30. *
  31. */
  32. #ifndef __LWIP_TCPIP_H__
  33. #define __LWIP_TCPIP_H__
  34. #include "lwip/opt.h"
  35. #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
  36. #include "lwip/api_msg.h"
  37. #include "lwip/netifapi.h"
  38. #include "lwip/pbuf.h"
  39. #include "lwip/api.h"
  40. #include "lwip/sys.h"
  41. #include "lwip/timers.h"
  42. #include "lwip/netif.h"
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /** Define this to something that triggers a watchdog. This is called from
  47. * tcpip_thread after processing a message. */
  48. #ifndef LWIP_TCPIP_THREAD_ALIVE
  49. #define LWIP_TCPIP_THREAD_ALIVE()
  50. #endif
  51. #if LWIP_TCPIP_CORE_LOCKING
  52. /** The global semaphore to lock the stack. */
  53. extern sys_mutex_t lock_tcpip_core;
  54. #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
  55. #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
  56. #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
  57. #define TCPIP_APIMSG_ACK(m)
  58. #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
  59. #define TCPIP_NETIFAPI_ACK(m)
  60. #else /* LWIP_TCPIP_CORE_LOCKING */
  61. #define LOCK_TCPIP_CORE()
  62. #define UNLOCK_TCPIP_CORE()
  63. #define TCPIP_APIMSG(m) tcpip_apimsg(m)
  64. #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed)
  65. #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
  66. #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
  67. #endif /* LWIP_TCPIP_CORE_LOCKING */
  68. /** Function prototype for the init_done function passed to tcpip_init */
  69. typedef void (*tcpip_init_done_fn)(void *arg);
  70. /** Function prototype for functions passed to tcpip_callback() */
  71. typedef void (*tcpip_callback_fn)(void *ctx);
  72. void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
  73. #if LWIP_NETCONN
  74. err_t tcpip_apimsg(struct api_msg *apimsg);
  75. #if LWIP_TCPIP_CORE_LOCKING
  76. err_t tcpip_apimsg_lock(struct api_msg *apimsg);
  77. #endif /* LWIP_TCPIP_CORE_LOCKING */
  78. #endif /* LWIP_NETCONN */
  79. err_t tcpip_input(struct pbuf *p, struct netif *inp);
  80. #if LWIP_NETIF_API
  81. err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
  82. #if LWIP_TCPIP_CORE_LOCKING
  83. err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
  84. #endif /* LWIP_TCPIP_CORE_LOCKING */
  85. #endif /* LWIP_NETIF_API */
  86. err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block);
  87. #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
  88. /* free pbufs or heap memory from another context without blocking */
  89. err_t pbuf_free_callback(struct pbuf *p);
  90. err_t mem_free_callback(void *m);
  91. #if LWIP_TCPIP_TIMEOUT
  92. err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
  93. err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
  94. #endif /* LWIP_TCPIP_TIMEOUT */
  95. enum tcpip_msg_type {
  96. #if LWIP_NETCONN
  97. TCPIP_MSG_API,
  98. #endif /* LWIP_NETCONN */
  99. TCPIP_MSG_INPKT,
  100. #if LWIP_NETIF_API
  101. TCPIP_MSG_NETIFAPI,
  102. #endif /* LWIP_NETIF_API */
  103. #if LWIP_TCPIP_TIMEOUT
  104. TCPIP_MSG_TIMEOUT,
  105. TCPIP_MSG_UNTIMEOUT,
  106. #endif /* LWIP_TCPIP_TIMEOUT */
  107. TCPIP_MSG_CALLBACK
  108. };
  109. struct tcpip_msg {
  110. enum tcpip_msg_type type;
  111. sys_sem_t *sem;
  112. union {
  113. #if LWIP_NETCONN
  114. struct api_msg *apimsg;
  115. #endif /* LWIP_NETCONN */
  116. #if LWIP_NETIF_API
  117. struct netifapi_msg *netifapimsg;
  118. #endif /* LWIP_NETIF_API */
  119. struct {
  120. struct pbuf *p;
  121. struct netif *netif;
  122. } inp;
  123. struct {
  124. tcpip_callback_fn function;
  125. void *ctx;
  126. } cb;
  127. #if LWIP_TCPIP_TIMEOUT
  128. struct {
  129. u32_t msecs;
  130. sys_timeout_handler h;
  131. void *arg;
  132. } tmo;
  133. #endif /* LWIP_TCPIP_TIMEOUT */
  134. } msg;
  135. };
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* !NO_SYS */
  140. #endif /* __LWIP_TCPIP_H__ */