35#include <lwip/etharp.h>
37#include <lwip/ethip6.h>
39#define LWIP_NETIF_HOSTNAME_DEFAULT "default"
40#define LINK_SPEED_OF_YOUR_NETIF_IN_BPS 100000000
42#define link_rx_drop cachehit
43#define link_rx_overrun cachehit
45#define LWIP_STATIC static
47#ifndef LWIP_NETIF_IFINDEX_MAX_EX
48#define LWIP_NETIF_IFINDEX_MAX_EX 255
54 struct netif *tmpnetif = NULL;
55 const char *prefix = (netif->link_layer_type == WIFI_DRIVER_IF) ?
"wlan" :
"eth";
57 netif->name[0] = prefix[0];
58 netif->name[1] = prefix[1];
60 for (
int i = 0; i < LWIP_NETIF_IFINDEX_MAX_EX; ++i) {
61 if (snprintf_s(netif->full_name,
sizeof(netif->full_name),
sizeof(netif->full_name) - 1,
62 "%s%d", prefix, i) < 0) {
65 NETIF_FOREACH(tmpnetif) {
66 if (strcmp(tmpnetif->full_name, netif->full_name) == 0) {
70 if (tmpnetif == NULL) {
74 netif->full_name[0] =
'\0';
96 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_output : going to send packet pbuf 0x%p of length %"U16_F
" through netif 0x%p\n", \
97 (
void *)p, p->tot_len, (
void *)netif));
100 if (all_pkt_raw_pcbs != NULL) {
101 p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
102 p->flags |= PBUF_FLAG_OUTGOING;
103 (
void)raw_pkt_input(p, netif, NULL);
108 (
void)pbuf_header(p, -ETH_PAD_SIZE);
111 netif->drv_send(netif, p);
114 (
void)pbuf_header(p, ETH_PAD_SIZE);
116 MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
117 LINK_STATS_INC(link.xmit);
137#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
139 struct eth_hdr* ethhdr = NULL;
143 struct eth_hdr *ethhdr = NULL;
147 LWIP_ERROR(
"driverif_input : invalid arguments", ((netif != NULL) && (p != NULL)),
return);
149 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input : going to receive input packet. netif 0x%p, pbuf 0x%p, \
150 packet_length %"U16_F
"\n", (
void *)netif, (
void *)p, p->tot_len));
153 MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
154 if (p->len < SIZEOF_ETH_HDR) {
156 LINK_STATS_INC(link.drop);
157 LINK_STATS_INC(link.link_rx_drop);
162#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
163 ethhdr = (
struct eth_hdr *)p->payload;
164 ethhdr_type = ntohs(ethhdr->type);
165 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input : received packet of type %"U16_F
" netif->input=%p\n", ethhdr_type, netif->input));
170 ret = netif->input(p, netif);
173 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input: IP input error\n"));
175 LINK_STATS_INC(link.drop);
176 LINK_STATS_INC(link.link_rx_drop);
177 if (ret == ERR_MEM) {
178 LINK_STATS_INC(link.link_rx_overrun);
181 LINK_STATS_INC(link.recv);
185 ethhdr = (
struct eth_hdr *)p->payload;
186 ethhdr_type = ntohs(ethhdr->type);
188 switch (ethhdr_type) {
193#if ETHARP_SUPPORT_VLAN
196 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input : received packet of type %"U16_F
"\n", ethhdr_type));
198 if (netif->input != NULL) {
199 ret = netif->input(p, netif);
203 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input: IP input error\n"));
205 LINK_STATS_INC(link.drop);
206 LINK_STATS_INC(link.link_rx_drop);
207 if (ret == ERR_MEM) {
208 MIB2_STATS_NETIF_INC(netif, ifinoverruns);
209 LINK_STATS_INC(link.link_rx_overrun);
212 LINK_STATS_INC(link.recv);
217 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input : received packet is of unsupported type %"U16_F
"\n", ethhdr_type));
219 LINK_STATS_INC(link.drop);
220 LINK_STATS_INC(link.link_rx_drop);
225 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_input : received packet is processed\n"));
243 u16_t link_layer_type;
248 link_layer_type = netif->link_layer_type;
249 LWIP_ERROR(
"driverif_init : invalid link_layer_type in netif", \
250 ((link_layer_type == ETHERNET_DRIVER_IF) || (link_layer_type == WIFI_DRIVER_IF)), \
253 LWIP_ERROR(
"driverif_init : netif hardware length is greater than maximum supported", \
254 (netif->hwaddr_len <= NETIF_MAX_HWADDR_LEN),
return ERR_IF);
256 LWIP_ERROR(
"driverif_init : drv_send is null", (netif->drv_send != NULL),
return ERR_IF);
258#if LWIP_NETIF_PROMISC
259 LWIP_ERROR(
"driverif_init : drv_config is null", (netif->drv_config != NULL),
return ERR_IF);
262#if LWIP_NETIF_HOSTNAME
264 netif->hostname = LWIP_NETIF_HOSTNAME_DEFAULT;
272 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
274 netif->output = etharp_output;
281 netif->mtu = IP_FRAG_MAX_MTU;
285 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
286 #if DRIVER_STATUS_CHECK
287 NETIF_FLAG_DRIVER_RDY |
304 #if LWIP_IPV6 && LWIP_IPV6_MLD
305 #if LWIP_MLD6_ENABLE_MLD_ON_DAD
311#if DRIVER_STATUS_CHECK
312 netif->waketime = -1;
314 LWIP_DEBUGF(DRIVERIF_DEBUG, (
"driverif_init : Initialized netif 0x%p\n", (
void *)netif));
void driverif_input(struct netif *netif, struct pbuf *p)
LWIP_STATIC err_t driverif_output(struct netif *netif, struct pbuf *p)
LWIP_STATIC void driverif_init_ifname(struct netif *netif)
err_t driverif_init(struct netif *netif)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void