if_var.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef _NET_IF_VAR_H_
  2. #define _NET_IF_VAR_H_
  3. /*
  4. * Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (c) 1983, 1993 by
  36. * The Regents of the University of California. All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. * 1. Redistributions of source code must retain the above copyright
  42. * notice, this list of conditions and the following disclaimer.
  43. * 2. Redistributions in binary form must reproduce the above copyright
  44. * notice, this list of conditions and the following disclaimer in the
  45. * documentation and/or other materials provided with the distribution.
  46. * 3. Neither the name of the University nor the names of its contributors
  47. * may be used to endorse or promote products derived from this software
  48. * without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  51. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  54. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  55. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  56. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  57. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  58. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  59. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  60. * SUCH DAMAGE.
  61. */
  62. /*
  63. * $Log$
  64. * Revision 1.8 2008/08/28 11:12:15 haraldkipp
  65. * Added interface flags, which will be required to implement Ethernet ioctl
  66. * functions.
  67. *
  68. * Revision 1.7 2008/08/11 07:00:20 haraldkipp
  69. * BSD types replaced by stdint types (feature request #1282721).
  70. *
  71. * Revision 1.6 2007/05/02 11:22:51 haraldkipp
  72. * Added multicast table entry.
  73. *
  74. * Revision 1.5 2005/02/04 15:08:37 haraldkipp
  75. * ARP redesign requires removal flag.
  76. *
  77. * Revision 1.4 2004/03/18 11:17:16 haraldkipp
  78. * Comments updated
  79. *
  80. * Revision 1.3 2004/02/02 18:53:49 drsung
  81. * gateway ip address was not set, if static network configuration from EEPROM is used.
  82. *
  83. * Revision 1.2 2003/08/05 20:19:13 haraldkipp
  84. * DNS removed from interface
  85. *
  86. * Revision 1.1.1.1 2003/05/09 14:41:12 haraldkipp
  87. * Initial using 3.2.1
  88. *
  89. * Revision 1.10 2003/03/31 14:33:26 harald
  90. * Moved some declarations to ppp device
  91. *
  92. * Revision 1.9 2003/02/04 18:00:42 harald
  93. * Version 3 released
  94. *
  95. * Revision 1.8 2002/10/29 15:40:49 harald
  96. * *** empty log message ***
  97. *
  98. * Revision 1.7 2002/06/26 17:29:18 harald
  99. * First pre-release with 2.4 stack
  100. *
  101. */
  102. #include <sys/types.h>
  103. #include <stdint.h>
  104. #include <sys/device.h>
  105. #include <dev/netbuf.h>
  106. #include <net/if_types.h>
  107. /*!
  108. * \file net/if_var.h
  109. * \brief Network interface structure.
  110. *
  111. * Each network device in Nut/Net has an associated
  112. * network interface structure.
  113. */
  114. /*!
  115. * \addtogroup xgARP
  116. */
  117. /*@{*/
  118. #define ATF_REM 0x01 /*!< \brief Entry marked for removal. */
  119. #define ATF_COM 0x02 /*!< \brief Completed entry. */
  120. #define ATF_PERM 0x04 /*!< \brief Permanent entry. */
  121. /*!
  122. * \brief ARP entry type.
  123. */
  124. typedef struct _ARPENTRY ARPENTRY;
  125. /*!
  126. * \struct _ARPENTRY if_var.h net/if_var.h
  127. * \brief ARP entry structure.
  128. *
  129. * Each network interface maintains its own ARP table.
  130. */
  131. struct _ARPENTRY {
  132. ARPENTRY *ae_next; /*!< \brief Linked list chain. */
  133. uint32_t ae_ip; /*!< \brief IP address. */
  134. uint8_t ae_ha[6]; /*!< \brief Hardware address. */
  135. uint8_t ae_flags; /*!< \brief Status flags, permanent and completed. */
  136. uint8_t ae_outdated; /*!< \brief Minutes since last use. */
  137. HANDLE ae_tq; /*!< \brief Threads waiting for entry to be completed. */
  138. };
  139. /*@}*/
  140. /*!
  141. * \addtogroup xgIP
  142. */
  143. /*@{*/
  144. /*!
  145. * \brief Multicast address entry type.
  146. */
  147. typedef struct _MCASTENTRY MCASTENTRY;
  148. /*!
  149. * \struct _MCASTENTRY if_var.h net/if_var.h
  150. * \brief Multicast entry structure.
  151. */
  152. struct _MCASTENTRY {
  153. MCASTENTRY *mca_next;
  154. uint8_t mca_ha[6];
  155. uint32_t mca_ip;
  156. };
  157. #define SIOCSIFMTU 0x1001 /*!< \brief Set maximum transfer unit. */
  158. #define SIOCGIFMTU 0x1002 /*!< \brief Get maximum transfer unit. */
  159. #define SIOCSIFFLAGS 0x1003 /*!< \brief Set interface flags. */
  160. #define SIOCGIFFLAGS 0x1004 /*!< \brief Get interface flags. */
  161. #define SIOCSIFADDR 0x1005 /*!< \brief Set interface address. */
  162. #define SIOCGIFADDR 0x1006 /*!< \brief Get interface address. */
  163. #define SIOCADDMULTI 0x1007 /*!< \brief Add multicast address.*/
  164. #define SIOCDELMULTI 0x1008 /*!< \brief Delete multicast address. */
  165. /*!
  166. * \brief Network interface type.
  167. */
  168. typedef struct ifnet IFNET;
  169. /*!
  170. * \struct ifnet if_var.h net/if_var.h
  171. * \brief Network interface structure.
  172. *
  173. * Contains information about the network interface.
  174. */
  175. struct ifnet {
  176. uint8_t if_type; /*!< \brief Interface type.
  177. * Either IFT_ETHER or IFT_PPP.
  178. */
  179. uint32_t if_flags; /*!< \brief Interface flags. */
  180. uint8_t if_mac[6]; /*!< \brief Hardware net address. */
  181. uint32_t if_local_ip; /*!< \brief IP address. */
  182. uint32_t if_remote_ip; /*!< \brief Remote IP address for point to point. */
  183. uint32_t if_mask; /*!< \brief IP network mask. */
  184. uint16_t if_mtu; /*!< \brief Maximum size of a transmission unit. */
  185. uint16_t if_pkt_id; /*!< \brief Packet identifier. */
  186. ARPENTRY *arpTable; /*!< \brief Linked list of arp entries. */
  187. MCASTENTRY *if_mcast; /*!< \brief Linked list of multicast address entries. */
  188. void (*if_recv) (NUTDEVICE *, NETBUF *); /*!< \brief Receive routine. */
  189. int (*if_send) (NUTDEVICE *, NETBUF *); /*!< \brief Send routine. */
  190. int (*if_output) (NUTDEVICE *, uint16_t, uint8_t *, NETBUF *); /*!< \brief Media output routine. */
  191. int (*if_ioctl) (NUTDEVICE *, int, void *); /*!< \brief Interface specific control function. */
  192. #ifdef NUT_PERFMON
  193. uint32_t if_in_octets;
  194. uint32_t if_in_ucast_pkts;
  195. uint32_t if_in_n_ucast_pkts;
  196. uint32_t if_in_discards;
  197. uint32_t if_in_errors;
  198. uint32_t if_in_unknown_protos;
  199. uint32_t if_out_octets;
  200. uint32_t if_out_ucast_pkts;
  201. uint32_t if_out_n_ucast_pkts;
  202. uint32_t if_out_discards;
  203. uint32_t if_out_errors;
  204. uint32_t if_out_q_len;
  205. #endif
  206. };
  207. /* The following macros avoid contamination of the source code with too
  208. many #ifdefs. */
  209. #ifdef NUT_PERFMON
  210. #define NUT_PERFMON_ADD(s, a) ((s) += (a))
  211. #define NUT_PERFMON_INC(s) ((s)++)
  212. #else
  213. #define NUT_PERFMON_ADD(s, a)
  214. #define NUT_PERFMON_INC(s)
  215. #endif
  216. /*@}*/
  217. extern int NutNetIfConfig2(const char *name, void *mac_dev, uint32_t ip_addr,
  218. uint32_t ip_mask, uint32_t gateway);
  219. extern int NutNetIfConfig(const char *name, void *mac_dev, uint32_t ip_addr,
  220. uint32_t ip_mask);
  221. extern int NutNetIfSetup(NUTDEVICE * dev, uint32_t ip_addr, uint32_t ip_mask,
  222. uint32_t gateway);
  223. extern int NutNetIfAddMcastAddr(const char *name, uint32_t ip_addr);
  224. extern int NutNetIfDelMcastAddr(const char *name, uint32_t ip_addr);
  225. extern int NutNetLoadConfig(const char *name);
  226. extern int NutNetSaveConfig(void);
  227. #endif