A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netif.h Source File

netif.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_NETIF_H__
00033 #define __LWIP_NETIF_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #include "lwip/err.h"
00038 
00039 #include "lwip/ip_addr.h"
00040 
00041 #include "lwip/inet.h"
00042 #include "lwip/pbuf.h"
00043 #if LWIP_DHCP
00044 struct dhcp;
00045 #endif
00046 #if LWIP_AUTOIP
00047 struct autoip;
00048 #endif
00049 
00050 #ifdef __cplusplus
00051 // XXX: WTF
00052 //extern "C" {
00053 #endif
00054 
00055 /* Throughout this file, IP addresses are expected to be in
00056  * the same byte order as in IP_PCB. */
00057 
00058 /** must be the maximum of all used hardware address lengths
00059     across all types of interfaces in use */
00060 #define NETIF_MAX_HWADDR_LEN 6U
00061 
00062 /** TODO: define the use (where, when, whom) of netif flags */
00063 
00064 /** whether the network interface is 'up'. this is
00065  * a software flag used to control whether this network
00066  * interface is enabled and processes traffic.
00067  */
00068 #define NETIF_FLAG_UP           0x01U
00069 /** if set, the netif has broadcast capability */
00070 #define NETIF_FLAG_BROADCAST    0x02U
00071 /** if set, the netif is one end of a point-to-point connection */
00072 #define NETIF_FLAG_POINTTOPOINT 0x04U
00073 /** if set, the interface is configured using DHCP */
00074 #define NETIF_FLAG_DHCP         0x08U
00075 /** if set, the interface has an active link
00076  *  (set by the network interface driver) */
00077 #define NETIF_FLAG_LINK_UP      0x10U
00078 /** if set, the netif is an device using ARP */
00079 #define NETIF_FLAG_ETHARP       0x20U
00080 /** if set, the netif has IGMP capability */
00081 #define NETIF_FLAG_IGMP         0x40U
00082 
00083 /** Generic data structure used for all lwIP network interfaces.
00084  *  The following fields should be filled in by the initialization
00085  *  function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
00086 
00087 struct netif {
00088   /** pointer to next in linked list */
00089   struct netif *next;
00090 
00091   /** IP address configuration in network byte order */
00092   struct ip_addr ip_addr;
00093   struct ip_addr netmask;
00094   struct ip_addr gw;
00095 
00096   /** This function is called by the network device driver
00097    *  to pass a packet up the TCP/IP stack. */
00098   err_t (* input)(struct pbuf *p, struct netif *inp);
00099   /** This function is called by the IP module when it wants
00100    *  to send a packet on the interface. This function typically
00101    *  first resolves the hardware address, then sends the packet. */
00102   err_t (* output)(struct netif *netif, struct pbuf *p,
00103        struct ip_addr *ipaddr);
00104   /** This function is called by the ARP module when it wants
00105    *  to send a packet on the interface. This function outputs
00106    *  the pbuf as-is on the link medium. */
00107   err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
00108 #if LWIP_NETIF_STATUS_CALLBACK
00109   /** This function is called when the netif state is set to up or down
00110    */
00111   void (* status_callback)(struct netif *netif);
00112 #endif /* LWIP_NETIF_STATUS_CALLBACK */
00113 #if LWIP_NETIF_LINK_CALLBACK
00114   /** This function is called when the netif link is set to up or down
00115    */
00116   void (* link_callback)(struct netif *netif);
00117 #endif /* LWIP_NETIF_LINK_CALLBACK */
00118   /** This field can be set by the device driver and could point
00119    *  to state information for the device. */
00120   void *state;
00121 #if LWIP_DHCP
00122   /** the DHCP client state information for this netif */
00123   struct dhcp *dhcp;
00124 #endif /* LWIP_DHCP */
00125 #if LWIP_AUTOIP
00126   /** the AutoIP client state information for this netif */
00127   struct autoip *autoip;
00128 #endif
00129 #if LWIP_NETIF_HOSTNAME
00130   /* the hostname for this netif, NULL is a valid value */
00131   char*  hostname;
00132 #endif /* LWIP_NETIF_HOSTNAME */
00133   /** number of bytes used in hwaddr */
00134   u8_t hwaddr_len;
00135   /** link level hardware address of this interface */
00136   u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
00137   /** maximum transfer unit (in bytes) */
00138   u16_t mtu;
00139   /** flags (see NETIF_FLAG_ above) */
00140   u8_t flags;
00141   /** descriptive abbreviation */
00142   char name[2];
00143   /** number of this interface */
00144   u8_t num;
00145 #if LWIP_SNMP
00146   /** link type (from "snmp_ifType" enum from snmp.h) */
00147   u8_t link_type;
00148   /** (estimate) link speed */
00149   u32_t link_speed;
00150   /** timestamp at last change made (up/down) */
00151   u32_t ts;
00152   /** counters */
00153   u32_t ifinoctets;
00154   u32_t ifinucastpkts;
00155   u32_t ifinnucastpkts;
00156   u32_t ifindiscards;
00157   u32_t ifoutoctets;
00158   u32_t ifoutucastpkts;
00159   u32_t ifoutnucastpkts;
00160   u32_t ifoutdiscards;
00161 #endif /* LWIP_SNMP */
00162 #if LWIP_IGMP
00163   /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
00164   err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
00165 #endif /* LWIP_IGMP */
00166 #if LWIP_NETIF_HWADDRHINT
00167   u8_t *addr_hint;
00168 #endif /* LWIP_NETIF_HWADDRHINT */
00169 };
00170 
00171 #if LWIP_SNMP
00172 #define NETIF_INIT_SNMP(netif, type, speed) \
00173   /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
00174   netif->link_type = type;    \
00175   /* your link speed here (units: bits per second) */  \
00176   netif->link_speed = speed;  \
00177   netif->ts = 0;              \
00178   netif->ifinoctets = 0;      \
00179   netif->ifinucastpkts = 0;   \
00180   netif->ifinnucastpkts = 0;  \
00181   netif->ifindiscards = 0;    \
00182   netif->ifoutoctets = 0;     \
00183   netif->ifoutucastpkts = 0;  \
00184   netif->ifoutnucastpkts = 0; \
00185   netif->ifoutdiscards = 0
00186 #else /* LWIP_SNMP */
00187 #define NETIF_INIT_SNMP(netif, type, speed)
00188 #endif /* LWIP_SNMP */
00189 
00190 
00191 /** The list of network interfaces. */
00192 extern struct netif *netif_list;
00193 /** The default network interface. */
00194 extern struct netif *netif_default;
00195 
00196 #define netif_init() /* Compatibility define, not init needed. */
00197 
00198 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
00199       struct ip_addr *gw,
00200       void *state,
00201       err_t (* init)(struct netif *netif),
00202       err_t (* input)(struct pbuf *p, struct netif *netif));
00203 
00204 void
00205 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
00206     struct ip_addr *gw);
00207 void netif_remove(struct netif * netif);
00208 
00209 /* Returns a network interface given its name. The name is of the form
00210    "et0", where the first two letters are the "name" field in the
00211    netif structure, and the digit is in the num field in the same
00212    structure. */
00213 struct netif *netif_find(char *name);
00214 
00215 void netif_set_default(struct netif *netif);
00216 
00217 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
00218 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
00219 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
00220 
00221 void netif_set_up(struct netif *netif);
00222 void netif_set_down(struct netif *netif);
00223 u8_t netif_is_up(struct netif *netif);
00224 
00225 #if LWIP_NETIF_STATUS_CALLBACK
00226 /*
00227  * Set callback to be called when interface is brought up/down
00228  */
00229 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
00230 #endif /* LWIP_NETIF_STATUS_CALLBACK */
00231 
00232 #if LWIP_NETIF_LINK_CALLBACK
00233 void netif_set_link_up(struct netif *netif);
00234 void netif_set_link_down(struct netif *netif);
00235 u8_t netif_is_link_up(struct netif *netif);
00236 /*
00237  * Set callback to be called when link is brought up/down
00238  */
00239 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
00240 #endif /* LWIP_NETIF_LINK_CALLBACK */
00241 
00242 #ifdef __cplusplus
00243 // XXX: WTF
00244 //}
00245 #endif
00246 
00247 #endif /* __LWIP_NETIF_H__ */