00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LWIP_NETIF_H__
00033 #define __LWIP_NETIF_H__
00034
00035 #include "lwip/opt.h"
00036
00037 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
00038
00039 #include "lwip/err.h"
00040
00041 #include "lwip/ip_addr.h"
00042
00043 #include "lwip/inet.h"
00044 #include "lwip/pbuf.h"
00045 #if LWIP_DHCP
00046 struct dhcp;
00047 #endif
00048 #if LWIP_AUTOIP
00049 struct autoip;
00050 #endif
00051
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055
00056
00057
00058
00059
00060
00061 #define NETIF_MAX_HWADDR_LEN 6U
00062
00063
00064
00065
00066
00067
00068
00069 #define NETIF_FLAG_UP 0x01U
00070
00071 #define NETIF_FLAG_BROADCAST 0x02U
00072
00073 #define NETIF_FLAG_POINTTOPOINT 0x04U
00074
00075 #define NETIF_FLAG_DHCP 0x08U
00076
00077
00078 #define NETIF_FLAG_LINK_UP 0x10U
00079
00080 #define NETIF_FLAG_ETHARP 0x20U
00081
00082 #define NETIF_FLAG_IGMP 0x40U
00083
00084
00085
00086
00087
00088 struct netif {
00089
00090 struct netif *next;
00091
00092
00093 struct ip_addr ip_addr;
00094 struct ip_addr netmask;
00095 struct ip_addr gw;
00096
00097
00098
00099 err_t (* input)(struct pbuf *p, struct netif *inp);
00100
00101
00102
00103 err_t (* output)(struct netif *netif, struct pbuf *p,
00104 struct ip_addr *ipaddr);
00105
00106
00107
00108 err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
00109 #if LWIP_NETIF_STATUS_CALLBACK
00110
00111
00112 void (* status_callback)(struct netif *netif);
00113 #endif
00114 #if LWIP_NETIF_LINK_CALLBACK
00115
00116
00117 void (* link_callback)(struct netif *netif);
00118 #endif
00119
00120
00121 void *state;
00122 #if LWIP_DHCP
00123
00124 struct dhcp *dhcp;
00125 #endif
00126 #if LWIP_AUTOIP
00127
00128 struct autoip *autoip;
00129 #endif
00130 #if LWIP_NETIF_HOSTNAME
00131
00132 char* hostname;
00133 #endif
00134
00135 u16_t mtu;
00136
00137 u8_t hwaddr_len;
00138
00139 u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
00140
00141 u8_t flags;
00142
00143 char name[2];
00144
00145 u8_t num;
00146 #if LWIP_SNMP
00147
00148 u8_t link_type;
00149
00150 u32_t link_speed;
00151
00152 u32_t ts;
00153
00154 u32_t ifinoctets;
00155 u32_t ifinucastpkts;
00156 u32_t ifinnucastpkts;
00157 u32_t ifindiscards;
00158 u32_t ifoutoctets;
00159 u32_t ifoutucastpkts;
00160 u32_t ifoutnucastpkts;
00161 u32_t ifoutdiscards;
00162 #endif
00163 #if LWIP_IGMP
00164
00165 err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
00166 #endif
00167 #if LWIP_NETIF_HWADDRHINT
00168 u8_t *addr_hint;
00169 #endif
00170 #if ENABLE_LOOPBACK
00171
00172 struct pbuf *loop_first;
00173 struct pbuf *loop_last;
00174 #if LWIP_LOOPBACK_MAX_PBUFS
00175 u16_t loop_cnt_current;
00176 #endif
00177 #endif
00178 };
00179
00180 #if LWIP_SNMP
00181 #define NETIF_INIT_SNMP(netif, type, speed) \
00182 \
00183 netif->link_type = type; \
00184 \
00185 netif->link_speed = speed; \
00186 netif->ts = 0; \
00187 netif->ifinoctets = 0; \
00188 netif->ifinucastpkts = 0; \
00189 netif->ifinnucastpkts = 0; \
00190 netif->ifindiscards = 0; \
00191 netif->ifoutoctets = 0; \
00192 netif->ifoutucastpkts = 0; \
00193 netif->ifoutnucastpkts = 0; \
00194 netif->ifoutdiscards = 0
00195 #else
00196 #define NETIF_INIT_SNMP(netif, type, speed)
00197 #endif
00198
00199
00200
00201 extern struct netif *netif_list;
00202
00203 extern struct netif *netif_default;
00204
00205 #define netif_init()
00206
00207 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
00208 struct ip_addr *gw,
00209 void *state,
00210 err_t (* init)(struct netif *netif),
00211 err_t (* input)(struct pbuf *p, struct netif *netif));
00212
00213 void
00214 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
00215 struct ip_addr *gw);
00216 void netif_remove(struct netif * netif);
00217
00218
00219
00220
00221
00222 struct netif *netif_find(char *name);
00223
00224 void netif_set_default(struct netif *netif);
00225
00226 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
00227 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
00228 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
00229
00230 void netif_set_up(struct netif *netif);
00231 void netif_set_down(struct netif *netif);
00232 u8_t netif_is_up(struct netif *netif);
00233
00234 #if LWIP_NETIF_STATUS_CALLBACK
00235
00236
00237
00238 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
00239 #endif
00240
00241 #if LWIP_NETIF_LINK_CALLBACK
00242 void netif_set_link_up(struct netif *netif);
00243 void netif_set_link_down(struct netif *netif);
00244 u8_t netif_is_link_up(struct netif *netif);
00245
00246
00247
00248 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
00249 #endif
00250
00251 #ifdef __cplusplus
00252 }
00253 #endif
00254
00255 #if ENABLE_LOOPBACK
00256 err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
00257 void netif_poll(struct netif *netif);
00258 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
00259 void netif_poll_all(void);
00260 #endif
00261 #endif
00262
00263 #endif