uip_netif.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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_NETIF_H__
  33. #define __LWIP_NETIF_H__
  34. //#include "lwip/opt.h"
  35. #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
  36. #include "lwip/err.h"
  37. #include "uip_ipaddr.h"
  38. //#include "lwip/inet.h"
  39. //#include "lwip/pbuf.h"
  40. #include "uip_pbuf.h"
  41. #include "uip-conf.h"
  42. #if LWIP_DHCP
  43. struct dhcp;
  44. #endif
  45. #if LWIP_AUTOIP
  46. struct autoip;
  47. #endif
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /* Throughout this file, IP addresses are expected to be in
  52. * the same byte order as in IP_PCB. */
  53. /** must be the maximum of all used hardware address lengths
  54. across all types of interfaces in use */
  55. #define NETIF_MAX_HWADDR_LEN 6U
  56. /** TODO: define the use (where, when, whom) of netif flags */
  57. /** whether the network interface is 'up'. this is
  58. * a software flag used to control whether this network
  59. * interface is enabled and processes traffic.
  60. */
  61. #define NETIF_FLAG_UP 0x01U
  62. /** if set, the netif has broadcast capability */
  63. #define NETIF_FLAG_BROADCAST 0x02U
  64. /** if set, the netif is one end of a point-to-point connection */
  65. #define NETIF_FLAG_POINTTOPOINT 0x04U
  66. /** if set, the interface is configured using DHCP */
  67. #define NETIF_FLAG_DHCP 0x08U
  68. /** if set, the interface has an active link
  69. * (set by the network interface driver) */
  70. #define NETIF_FLAG_LINK_UP 0x10U
  71. /** if set, the netif is an device using ARP */
  72. #define NETIF_FLAG_ETHARP 0x20U
  73. /** if set, the netif has IGMP capability */
  74. #define NETIF_FLAG_IGMP 0x40U
  75. /** Generic data structure used for all lwIP network interfaces.
  76. * The following fields should be filled in by the initialization
  77. * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
  78. struct ip_addr {
  79. rt_uint16_t uip_ip4addr_t[2];
  80. } ;
  81. struct netif {
  82. /** pointer to next in linked list */
  83. struct netif *next;
  84. /** IP address configuration in network byte order */
  85. struct ip_addr ip_addr;
  86. struct ip_addr netmask;
  87. struct ip_addr gw;
  88. /** This function is called by the network device driver
  89. * to pass a packet up the TCP/IP stack. */
  90. err_t (* input)(struct pbuf *p, struct netif *inp);
  91. /** This function is called by the IP module when it wants
  92. * to send a packet on the interface. This function typically
  93. * first resolves the hardware address, then sends the packet. */
  94. err_t (* output)(struct netif *netif, struct pbuf *p,
  95. struct ip_addr *ipaddr);
  96. /** This function is called by the ARP module when it wants
  97. * to send a packet on the interface. This function outputs
  98. * the pbuf as-is on the link medium. */
  99. err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
  100. #if LWIP_NETIF_STATUS_CALLBACK
  101. /** This function is called when the netif state is set to up or down
  102. */
  103. void (* status_callback)(struct netif *netif);
  104. #endif /* LWIP_NETIF_STATUS_CALLBACK */
  105. #if LWIP_NETIF_LINK_CALLBACK
  106. /** This function is called when the netif link is set to up or down
  107. */
  108. void (* link_callback)(struct netif *netif);
  109. #endif /* LWIP_NETIF_LINK_CALLBACK */
  110. /** This field can be set by the device driver and could point
  111. * to state information for the device. */
  112. void *state;
  113. #if LWIP_DHCP
  114. /** the DHCP client state information for this netif */
  115. struct dhcp *dhcp;
  116. #endif /* LWIP_DHCP */
  117. #if LWIP_AUTOIP
  118. /** the AutoIP client state information for this netif */
  119. struct autoip *autoip;
  120. #endif
  121. #if LWIP_NETIF_HOSTNAME
  122. /* the hostname for this netif, NULL is a valid value */
  123. char* hostname;
  124. #endif /* LWIP_NETIF_HOSTNAME */
  125. /** maximum transfer unit (in bytes) */
  126. u16_t mtu;
  127. /** number of bytes used in hwaddr */
  128. u8_t hwaddr_len;
  129. /** link level hardware address of this interface */
  130. u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
  131. /** flags (see NETIF_FLAG_ above) */
  132. u8_t flags;
  133. /** descriptive abbreviation */
  134. char name[2];
  135. /** number of this interface */
  136. u8_t num;
  137. #if LWIP_SNMP
  138. /** link type (from "snmp_ifType" enum from snmp.h) */
  139. u8_t link_type;
  140. /** (estimate) link speed */
  141. u32_t link_speed;
  142. /** timestamp at last change made (up/down) */
  143. u32_t ts;
  144. /** counters */
  145. u32_t ifinoctets;
  146. u32_t ifinucastpkts;
  147. u32_t ifinnucastpkts;
  148. u32_t ifindiscards;
  149. u32_t ifoutoctets;
  150. u32_t ifoutucastpkts;
  151. u32_t ifoutnucastpkts;
  152. u32_t ifoutdiscards;
  153. #endif /* LWIP_SNMP */
  154. #if LWIP_IGMP
  155. /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
  156. err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
  157. #endif /* LWIP_IGMP */
  158. #if LWIP_NETIF_HWADDRHINT
  159. u8_t *addr_hint;
  160. #endif /* LWIP_NETIF_HWADDRHINT */
  161. #if ENABLE_LOOPBACK
  162. /* List of packets to be queued for ourselves. */
  163. struct pbuf *loop_first;
  164. struct pbuf *loop_last;
  165. #if LWIP_LOOPBACK_MAX_PBUFS
  166. u16_t loop_cnt_current;
  167. #endif /* LWIP_LOOPBACK_MAX_PBUFS */
  168. #endif /* ENABLE_LOOPBACK */
  169. };
  170. #if LWIP_SNMP
  171. #define NETIF_INIT_SNMP(netif, type, speed) \
  172. /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
  173. netif->link_type = type; \
  174. /* your link speed here (units: bits per second) */ \
  175. netif->link_speed = speed; \
  176. netif->ts = 0; \
  177. netif->ifinoctets = 0; \
  178. netif->ifinucastpkts = 0; \
  179. netif->ifinnucastpkts = 0; \
  180. netif->ifindiscards = 0; \
  181. netif->ifoutoctets = 0; \
  182. netif->ifoutucastpkts = 0; \
  183. netif->ifoutnucastpkts = 0; \
  184. netif->ifoutdiscards = 0
  185. #else /* LWIP_SNMP */
  186. #define NETIF_INIT_SNMP(netif, type, speed)
  187. #endif /* LWIP_SNMP */
  188. /** The list of network interfaces. */
  189. extern struct netif *netif_list;
  190. /** The default network interface. */
  191. extern struct netif *netif_default;
  192. #define netif_init() /* Compatibility define, not init needed. */
  193. struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
  194. struct ip_addr *gw,
  195. void *state,
  196. err_t (* init)(struct netif *netif),
  197. err_t (* input)(struct pbuf *p, struct netif *netif));
  198. void
  199. netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
  200. struct ip_addr *gw);
  201. void netif_remove(struct netif * netif);
  202. /* Returns a network interface given its name. The name is of the form
  203. "et0", where the first two letters are the "name" field in the
  204. netif structure, and the digit is in the num field in the same
  205. structure. */
  206. struct netif *netif_find(char *name);
  207. void netif_set_default(struct netif *netif);
  208. void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
  209. void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
  210. void netif_set_gw(struct netif *netif, struct ip_addr *gw);
  211. void netif_set_up(struct netif *netif);
  212. void netif_set_down(struct netif *netif);
  213. u8_t netif_is_up(struct netif *netif);
  214. #if LWIP_NETIF_STATUS_CALLBACK
  215. /*
  216. * Set callback to be called when interface is brought up/down
  217. */
  218. void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
  219. #endif /* LWIP_NETIF_STATUS_CALLBACK */
  220. #if LWIP_NETIF_LINK_CALLBACK
  221. void netif_set_link_up(struct netif *netif);
  222. void netif_set_link_down(struct netif *netif);
  223. u8_t netif_is_link_up(struct netif *netif);
  224. /*
  225. * Set callback to be called when link is brought up/down
  226. */
  227. void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
  228. #endif /* LWIP_NETIF_LINK_CALLBACK */
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #if ENABLE_LOOPBACK
  233. err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
  234. void netif_poll(struct netif *netif);
  235. #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
  236. void netif_poll_all(void);
  237. #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
  238. #endif /* ENABLE_LOOPBACK */
  239. #endif /* __LWIP_NETIF_H__ */