uip-fw.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * \addtogroup uipfw
  3. * @{
  4. */
  5. /**
  6. * \file
  7. * uIP packet forwarding header file.
  8. * \author Adam Dunkels <adam@sics.se>
  9. */
  10. /*
  11. * Copyright (c) 2004, Swedish Institute of Computer Science.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. * 3. Neither the name of the Institute nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
  27. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36. * SUCH DAMAGE.
  37. *
  38. * This file is part of the uIP TCP/IP stack
  39. *
  40. * Author: Adam Dunkels <adam@sics.se>
  41. *
  42. * $Id: uip-fw.h,v 1.2 2006/06/12 08:00:30 adam Exp $
  43. */
  44. #ifndef __UIP_FW_H__
  45. #define __UIP_FW_H__
  46. #include "uip.h"
  47. /**
  48. * Representation of a uIP network interface.
  49. */
  50. struct uip_fw_netif {
  51. struct uip_fw_netif *next; /**< Pointer to the next interface when
  52. linked in a list. */
  53. u16_t ipaddr[2]; /**< The IP address of this interface. */
  54. u16_t netmask[2]; /**< The netmask of the interface. */
  55. u8_t (* output)(void);
  56. /**< A pointer to the function that
  57. sends a packet. */
  58. };
  59. /**
  60. * Intantiating macro for a uIP network interface.
  61. *
  62. * Example:
  63. \code
  64. struct uip_fw_netif slipnetif =
  65. {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)};
  66. \endcode
  67. * \param ip1,ip2,ip3,ip4 The IP address of the network interface.
  68. *
  69. * \param nm1,nm2,nm3,nm4 The netmask of the network interface.
  70. *
  71. * \param outputfunc A pointer to the output function of the network interface.
  72. *
  73. * \hideinitializer
  74. */
  75. #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
  76. NULL, \
  77. {HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
  78. {HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
  79. outputfunc
  80. /**
  81. * Set the IP address of a network interface.
  82. *
  83. * \param netif A pointer to the uip_fw_netif structure for the network interface.
  84. *
  85. * \param addr A pointer to an IP address.
  86. *
  87. * \hideinitializer
  88. */
  89. #define uip_fw_setipaddr(netif, addr) \
  90. do { (netif)->ipaddr[0] = ((u16_t *)(addr))[0]; \
  91. (netif)->ipaddr[1] = ((u16_t *)(addr))[1]; } while(0)
  92. /**
  93. * Set the netmask of a network interface.
  94. *
  95. * \param netif A pointer to the uip_fw_netif structure for the network interface.
  96. *
  97. * \param addr A pointer to an IP address representing the netmask.
  98. *
  99. * \hideinitializer
  100. */
  101. #define uip_fw_setnetmask(netif, addr) \
  102. do { (netif)->netmask[0] = ((u16_t *)(addr))[0]; \
  103. (netif)->netmask[1] = ((u16_t *)(addr))[1]; } while(0)
  104. void uip_fw_init(void);
  105. u8_t uip_fw_forward(void);
  106. u8_t uip_fw_output(void);
  107. void uip_fw_register(struct uip_fw_netif *netif);
  108. void uip_fw_default(struct uip_fw_netif *netif);
  109. void uip_fw_periodic(void);
  110. /**
  111. * A non-error message that indicates that a packet should be
  112. * processed locally.
  113. *
  114. * \hideinitializer
  115. */
  116. #define UIP_FW_LOCAL 0
  117. /**
  118. * A non-error message that indicates that something went OK.
  119. *
  120. * \hideinitializer
  121. */
  122. #define UIP_FW_OK 0
  123. /**
  124. * A non-error message that indicates that a packet was forwarded.
  125. *
  126. * \hideinitializer
  127. */
  128. #define UIP_FW_FORWARDED 1
  129. /**
  130. * A non-error message that indicates that a zero-length packet
  131. * transmission was attempted, and that no packet was sent.
  132. *
  133. * \hideinitializer
  134. */
  135. #define UIP_FW_ZEROLEN 2
  136. /**
  137. * An error message that indicates that a packet that was too large
  138. * for the outbound network interface was detected.
  139. *
  140. * \hideinitializer
  141. */
  142. #define UIP_FW_TOOLARGE 3
  143. /**
  144. * An error message that indicates that no suitable interface could be
  145. * found for an outbound packet.
  146. *
  147. * \hideinitializer
  148. */
  149. #define UIP_FW_NOROUTE 4
  150. /**
  151. * An error message that indicates that a packet that should be
  152. * forwarded or output was dropped.
  153. *
  154. * \hideinitializer
  155. */
  156. #define UIP_FW_DROPPED 5
  157. #endif /* __UIP_FW_H__ */
  158. /** @} */