Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/netif.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
0003  * All rights reserved. 
0004  * 
0005  * Redistribution and use in source and binary forms, with or without modification, 
0006  * are permitted provided that the following conditions are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright notice,
0009  *    this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright notice,
0011  *    this list of conditions and the following disclaimer in the documentation
0012  *    and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission. 
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0025  * OF SUCH DAMAGE.
0026  *
0027  * This file is part of the lwIP TCP/IP stack.
0028  * 
0029  * Author: Adam Dunkels <adam@sics.se>
0030  *
0031  */
0032 #ifndef __LWIP_NETIF_H__
0033 #define __LWIP_NETIF_H__
0034 
0035 #include "lwip/opt.h"
0036 
0037 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
0038 
0039 #include "lwip/err.h"
0040 
0041 #include "lwip/ip_addr.h"
0042 
0043 #include "lwip/inet.h"
0044 #include "lwip/pbuf.h"
0045 #if LWIP_DHCP
0046 struct dhcp;
0047 #endif
0048 #if LWIP_AUTOIP
0049 struct autoip;
0050 #endif
0051 
0052 #ifdef __cplusplus
0053 extern "C" {
0054 #endif
0055 
0056 /* Throughout this file, IP addresses are expected to be in
0057  * the same byte order as in IP_PCB. */
0058 
0059 /** must be the maximum of all used hardware address lengths
0060     across all types of interfaces in use */
0061 #define NETIF_MAX_HWADDR_LEN 6U
0062 
0063 /** TODO: define the use (where, when, whom) of netif flags */
0064 
0065 /** whether the network interface is 'up'. this is
0066  * a software flag used to control whether this network
0067  * interface is enabled and processes traffic.
0068  */
0069 #define NETIF_FLAG_UP           0x01U
0070 /** if set, the netif has broadcast capability */
0071 #define NETIF_FLAG_BROADCAST    0x02U
0072 /** if set, the netif is one end of a point-to-point connection */
0073 #define NETIF_FLAG_POINTTOPOINT 0x04U
0074 /** if set, the interface is configured using DHCP */
0075 #define NETIF_FLAG_DHCP         0x08U
0076 /** if set, the interface has an active link
0077  *  (set by the network interface driver) */
0078 #define NETIF_FLAG_LINK_UP      0x10U
0079 /** if set, the netif is an device using ARP */
0080 #define NETIF_FLAG_ETHARP       0x20U
0081 /** if set, the netif has IGMP capability */
0082 #define NETIF_FLAG_IGMP         0x40U
0083 
0084 /** Generic data structure used for all lwIP network interfaces.
0085  *  The following fields should be filled in by the initialization
0086  *  function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
0087 
0088 struct netif {
0089   /** pointer to next in linked list */
0090   struct netif *next;
0091 
0092   /** IP address configuration in network byte order */
0093   struct ip_addr ip_addr;
0094   struct ip_addr netmask;
0095   struct ip_addr gw;
0096 
0097   /** This function is called by the network device driver
0098    *  to pass a packet up the TCP/IP stack. */
0099   err_t (* input)(struct pbuf *p, struct netif *inp);
0100   /** This function is called by the IP module when it wants
0101    *  to send a packet on the interface. This function typically
0102    *  first resolves the hardware address, then sends the packet. */
0103   err_t (* output)(struct netif *netif, struct pbuf *p,
0104        struct ip_addr *ipaddr);
0105   /** This function is called by the ARP module when it wants
0106    *  to send a packet on the interface. This function outputs
0107    *  the pbuf as-is on the link medium. */
0108   err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
0109 #if LWIP_NETIF_STATUS_CALLBACK
0110   /** This function is called when the netif state is set to up or down
0111    */
0112   void (* status_callback)(struct netif *netif);
0113 #endif /* LWIP_NETIF_STATUS_CALLBACK */
0114 #if LWIP_NETIF_LINK_CALLBACK
0115   /** This function is called when the netif link is set to up or down
0116    */
0117   void (* link_callback)(struct netif *netif);
0118 #endif /* LWIP_NETIF_LINK_CALLBACK */
0119   /** This field can be set by the device driver and could point
0120    *  to state information for the device. */
0121   void *state;
0122 #if LWIP_DHCP
0123   /** the DHCP client state information for this netif */
0124   struct dhcp *dhcp;
0125 #endif /* LWIP_DHCP */
0126 #if LWIP_AUTOIP
0127   /** the AutoIP client state information for this netif */
0128   struct autoip *autoip;
0129 #endif
0130 #if LWIP_NETIF_HOSTNAME
0131   /* the hostname for this netif, NULL is a valid value */
0132   char*  hostname;
0133 #endif /* LWIP_NETIF_HOSTNAME */
0134   /** maximum transfer unit (in bytes) */
0135   u16_t mtu;
0136   /** number of bytes used in hwaddr */
0137   u8_t hwaddr_len;
0138   /** link level hardware address of this interface */
0139   u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
0140   /** flags (see NETIF_FLAG_ above) */
0141   u8_t flags;
0142   /** descriptive abbreviation */
0143   char name[2];
0144   /** number of this interface */
0145   u8_t num;
0146 #if LWIP_SNMP
0147   /** link type (from "snmp_ifType" enum from snmp.h) */
0148   u8_t link_type;
0149   /** (estimate) link speed */
0150   u32_t link_speed;
0151   /** timestamp at last change made (up/down) */
0152   u32_t ts;
0153   /** counters */
0154   u32_t ifinoctets;
0155   u32_t ifinucastpkts;
0156   u32_t ifinnucastpkts;
0157   u32_t ifindiscards;
0158   u32_t ifoutoctets;
0159   u32_t ifoutucastpkts;
0160   u32_t ifoutnucastpkts;
0161   u32_t ifoutdiscards;
0162 #endif /* LWIP_SNMP */
0163 #if LWIP_IGMP
0164   /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
0165   err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
0166 #endif /* LWIP_IGMP */
0167 #if LWIP_NETIF_HWADDRHINT
0168   u8_t *addr_hint;
0169 #endif /* LWIP_NETIF_HWADDRHINT */
0170 #if ENABLE_LOOPBACK
0171   /* List of packets to be queued for ourselves. */
0172   struct pbuf *loop_first;
0173   struct pbuf *loop_last;
0174 #if LWIP_LOOPBACK_MAX_PBUFS
0175   u16_t loop_cnt_current;
0176 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
0177 #endif /* ENABLE_LOOPBACK */
0178 };
0179 
0180 #if LWIP_SNMP
0181 #define NETIF_INIT_SNMP(netif, type, speed) \
0182   /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
0183   netif->link_type = type;    \
0184   /* your link speed here (units: bits per second) */  \
0185   netif->link_speed = speed;  \
0186   netif->ts = 0;              \
0187   netif->ifinoctets = 0;      \
0188   netif->ifinucastpkts = 0;   \
0189   netif->ifinnucastpkts = 0;  \
0190   netif->ifindiscards = 0;    \
0191   netif->ifoutoctets = 0;     \
0192   netif->ifoutucastpkts = 0;  \
0193   netif->ifoutnucastpkts = 0; \
0194   netif->ifoutdiscards = 0
0195 #else /* LWIP_SNMP */
0196 #define NETIF_INIT_SNMP(netif, type, speed)
0197 #endif /* LWIP_SNMP */
0198 
0199 
0200 /** The list of network interfaces. */
0201 extern struct netif *netif_list;
0202 /** The default network interface. */
0203 extern struct netif *netif_default;
0204 
0205 #define netif_init() /* Compatibility define, not init needed. */
0206 
0207 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
0208       struct ip_addr *gw,
0209       void *state,
0210       err_t (* init)(struct netif *netif),
0211       err_t (* input)(struct pbuf *p, struct netif *netif));
0212 
0213 void
0214 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
0215     struct ip_addr *gw);
0216 void netif_remove(struct netif * netif);
0217 
0218 /* Returns a network interface given its name. The name is of the form
0219    "et0", where the first two letters are the "name" field in the
0220    netif structure, and the digit is in the num field in the same
0221    structure. */
0222 struct netif *netif_find(char *name);
0223 
0224 void netif_set_default(struct netif *netif);
0225 
0226 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
0227 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
0228 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
0229 
0230 void netif_set_up(struct netif *netif);
0231 void netif_set_down(struct netif *netif);
0232 u8_t netif_is_up(struct netif *netif);
0233 
0234 #if LWIP_NETIF_STATUS_CALLBACK
0235 /*
0236  * Set callback to be called when interface is brought up/down
0237  */
0238 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
0239 #endif /* LWIP_NETIF_STATUS_CALLBACK */
0240 
0241 #if LWIP_NETIF_LINK_CALLBACK
0242 void netif_set_link_up(struct netif *netif);
0243 void netif_set_link_down(struct netif *netif);
0244 u8_t netif_is_link_up(struct netif *netif);
0245 /*
0246  * Set callback to be called when link is brought up/down
0247  */
0248 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
0249 #endif /* LWIP_NETIF_LINK_CALLBACK */
0250 
0251 #ifdef __cplusplus
0252 }
0253 #endif
0254 
0255 #if ENABLE_LOOPBACK
0256 err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
0257 void netif_poll(struct netif *netif);
0258 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
0259 void netif_poll_all(void);
0260 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
0261 #endif /* ENABLE_LOOPBACK */
0262 
0263 #endif /* __LWIP_NETIF_H__ */