1 |
583 |
jeremybenn |
/*
|
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 |
|
|
*/
|
57 |
|
|
#define NETIF_FLAG_UP 0x1U
|
58 |
|
|
/** if set, the netif has broadcast capability */
|
59 |
|
|
#define NETIF_FLAG_BROADCAST 0x2U
|
60 |
|
|
/** if set, the netif is one end of a point-to-point connection */
|
61 |
|
|
#define NETIF_FLAG_POINTTOPOINT 0x4U
|
62 |
|
|
/** if set, the interface is configured using DHCP */
|
63 |
|
|
#define NETIF_FLAG_DHCP 0x08U
|
64 |
|
|
/** if set, the interface has an active link
|
65 |
|
|
* (set by the network interface driver) */
|
66 |
|
|
#define NETIF_FLAG_LINK_UP 0x10U
|
67 |
|
|
|
68 |
|
|
/** Generic data structure used for all lwIP network interfaces.
|
69 |
|
|
* The following fields should be filled in by the initialization
|
70 |
|
|
* function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
|
71 |
|
|
|
72 |
|
|
struct netif {
|
73 |
|
|
/** pointer to next in linked list */
|
74 |
|
|
struct netif *next;
|
75 |
|
|
|
76 |
|
|
/** IP address configuration in network byte order */
|
77 |
|
|
struct ip_addr ip_addr;
|
78 |
|
|
struct ip_addr netmask;
|
79 |
|
|
struct ip_addr gw;
|
80 |
|
|
|
81 |
|
|
/** This function is called by the network device driver
|
82 |
|
|
* to pass a packet up the TCP/IP stack. */
|
83 |
|
|
err_t (* input)(struct pbuf *p, struct netif *inp);
|
84 |
|
|
/** This function is called by the IP module when it wants
|
85 |
|
|
* to send a packet on the interface. This function typically
|
86 |
|
|
* first resolves the hardware address, then sends the packet. */
|
87 |
|
|
err_t (* output)(struct netif *netif, struct pbuf *p,
|
88 |
|
|
struct ip_addr *ipaddr);
|
89 |
|
|
/** This function is called by the ARP module when it wants
|
90 |
|
|
* to send a packet on the interface. This function outputs
|
91 |
|
|
* the pbuf as-is on the link medium. */
|
92 |
|
|
err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
|
93 |
|
|
/** This field can be set by the device driver and could point
|
94 |
|
|
* to state information for the device. */
|
95 |
|
|
void *state;
|
96 |
|
|
#if LWIP_DHCP
|
97 |
|
|
/** the DHCP client state information for this netif */
|
98 |
|
|
struct dhcp *dhcp;
|
99 |
|
|
#endif
|
100 |
|
|
/** number of bytes used in hwaddr */
|
101 |
|
|
u8_t hwaddr_len;
|
102 |
|
|
/** link level hardware address of this interface */
|
103 |
|
|
u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
|
104 |
|
|
/** maximum transfer unit (in bytes) */
|
105 |
|
|
u16_t mtu;
|
106 |
|
|
/** flags (see NETIF_FLAG_ above) */
|
107 |
|
|
u8_t flags;
|
108 |
|
|
/** link type */
|
109 |
|
|
u8_t link_type;
|
110 |
|
|
/** descriptive abbreviation */
|
111 |
|
|
char name[2];
|
112 |
|
|
/** number of this interface */
|
113 |
|
|
u8_t num;
|
114 |
|
|
};
|
115 |
|
|
|
116 |
|
|
/** The list of network interfaces. */
|
117 |
|
|
extern struct netif *netif_list;
|
118 |
|
|
/** The default network interface. */
|
119 |
|
|
extern struct netif *netif_default;
|
120 |
|
|
|
121 |
|
|
/* netif_init() must be called first. */
|
122 |
|
|
void netif_init(void);
|
123 |
|
|
|
124 |
|
|
struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
|
125 |
|
|
struct ip_addr *gw,
|
126 |
|
|
void *state,
|
127 |
|
|
err_t (* init)(struct netif *netif),
|
128 |
|
|
err_t (* input)(struct pbuf *p, struct netif *netif));
|
129 |
|
|
|
130 |
|
|
void
|
131 |
|
|
netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
|
132 |
|
|
struct ip_addr *gw);
|
133 |
|
|
void netif_remove(struct netif * netif);
|
134 |
|
|
|
135 |
|
|
/* Returns a network interface given its name. The name is of the form
|
136 |
|
|
"et0", where the first two letters are the "name" field in the
|
137 |
|
|
netif structure, and the digit is in the num field in the same
|
138 |
|
|
structure. */
|
139 |
|
|
struct netif *netif_find(char *name);
|
140 |
|
|
|
141 |
|
|
void netif_set_default(struct netif *netif);
|
142 |
|
|
|
143 |
|
|
void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
|
144 |
|
|
void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
|
145 |
|
|
void netif_set_gw(struct netif *netif, struct ip_addr *gw);
|
146 |
|
|
void netif_set_up(struct netif *netif);
|
147 |
|
|
void netif_set_down(struct netif *netif);
|
148 |
|
|
u8_t netif_is_up(struct netif *netif);
|
149 |
|
|
|
150 |
|
|
#endif /* __LWIP_NETIF_H__ */
|