]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/lwip_tcpip/v2_0/include/lwip/netif.h
Initial revision
[karo-tx-redboot.git] / packages / net / lwip_tcpip / v2_0 / include / lwip / netif.h
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
35 #include "lwip/opt.h"
36
37 #include "lwip/err.h"
38
39 #include "lwip/ip_addr.h"
40
41 #include "lwip/inet.h"
42 #include "lwip/pbuf.h"
43 #if LWIP_DHCP
44 #  include "lwip/dhcp.h"
45 #endif
46
47 /** must be the maximum of all used hardware address lengths
48     across all types of interfaces in use */
49 #define NETIF_MAX_HWADDR_LEN 6U
50
51 /** TODO: define the use (where, when, whom) of netif flags */
52
53 /** whether the network interface is 'up'. this is
54  * a software flag used to control whether this network
55  * interface is enabled and processes traffic */
56 #define NETIF_FLAG_UP 0x1U
57 /** if set, the netif has broadcast capability */
58 #define NETIF_FLAG_BROADCAST 0x2U
59 /** if set, the netif is one end of a point-to-point connection */
60 #define NETIF_FLAG_POINTTOPOINT 0x4U
61 /** if set, the interface is configured using DHCP */
62 #define NETIF_FLAG_DHCP 0x08U
63 /** if set, the interface has an active link
64  *  (set by the interface) */
65 #define NETIF_FLAG_LINK_UP 0x10U
66
67 /** generic data structure used for all lwIP network interfaces */
68 struct netif {
69   /** pointer to next in linked list */
70   struct netif *next;
71   /** The following fields should be filled in by the
72       initialization function for the device driver. */
73   
74   /** IP address configuration in network byte order */
75   struct ip_addr ip_addr;
76   struct ip_addr netmask;
77   struct ip_addr gw;
78
79   /** This function is called by the network device driver
80       to pass a packet up the TCP/IP stack. */
81   err_t (* input)(struct pbuf *p, struct netif *inp);
82   /** This function is called by the IP module when it wants
83       to send a packet on the interface. This function typically
84       first resolves the hardware address, then sends the packet. */
85   err_t (* output)(struct netif *netif, struct pbuf *p,
86        struct ip_addr *ipaddr);
87   /** This function is called by the ARP module when it wants
88       to send a packet on the interface. This function outputs
89       the pbuf as-is on the link medium. */
90   err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
91   /** This field can be set by the device driver and could point
92       to state information for the device. */
93   void *state;
94 #if LWIP_DHCP
95   /** the DHCP client state information for this netif */
96   struct dhcp *dhcp;
97 #endif
98   /** number of bytes used in hwaddr */
99   unsigned char hwaddr_len;
100   /** link level hardware address of this interface */
101   unsigned char hwaddr[NETIF_MAX_HWADDR_LEN];
102   /** maximum transfer unit (in bytes) */
103   u16_t mtu;
104   /** descriptive abbreviation */
105   char name[2];
106   /** number of this interface */
107   u8_t num;
108   /** NETIF_FLAG_* */
109   u8_t flags;
110 };
111
112 /** The list of network interfaces. */
113 extern struct netif *netif_list;
114 /** The default network interface. */
115 extern struct netif *netif_default;
116
117 /* netif_init() must be called first. */
118 void netif_init(void);
119
120 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
121       struct ip_addr *gw,
122       void *state,
123       err_t (* init)(struct netif *netif),
124       err_t (* input)(struct pbuf *p, struct netif *netif));
125
126 void
127 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
128     struct ip_addr *gw);
129 void netif_remove(struct netif * netif);
130
131 /* Returns a network interface given its name. The name is of the form
132    "et0", where the first two letters are the "name" field in the
133    netif structure, and the digit is in the num field in the same
134    structure. */
135 struct netif *netif_find(char *name);
136
137 void netif_set_default(struct netif *netif);
138
139 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
140 void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
141 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
142
143 #endif /* __LWIP_NETIF_H__ */