feat(lwip): remove wifi from lwip

This commit is contained in:
zhangjunhao
2018-04-17 14:50:11 +08:00
parent b4637e2559
commit d79ec658ae
8 changed files with 1027 additions and 1135 deletions

View File

@ -3,49 +3,51 @@
#define USE_DNS #define USE_DNS
typedef struct dhcps_state{ #include "esp_wifi.h"
s16_t state;
typedef struct dhcps_state {
s16_t state;
} dhcps_state; } dhcps_state;
// <20><><EFBFBD><EFBFBD>dhcpclient<6E>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DHCP msg<73><EFBFBD><E1B9B9> // <20><><EFBFBD><EFBFBD>dhcpclient<6E>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DHCP msg<73><EFBFBD><E1B9B9>
typedef struct dhcps_msg { typedef struct dhcps_msg {
u8_t op, htype, hlen, hops; u8_t op, htype, hlen, hops;
u8_t xid[4]; u8_t xid[4];
u16_t secs, flags; u16_t secs, flags;
u8_t ciaddr[4]; u8_t ciaddr[4];
u8_t yiaddr[4]; u8_t yiaddr[4];
u8_t siaddr[4]; u8_t siaddr[4];
u8_t giaddr[4]; u8_t giaddr[4];
u8_t chaddr[16]; u8_t chaddr[16];
u8_t sname[64]; u8_t sname[64];
u8_t file[128]; u8_t file[128];
u8_t options[312]; u8_t options[312];
}dhcps_msg; } dhcps_msg;
#ifndef LWIP_OPEN_SRC #ifndef LWIP_OPEN_SRC
struct dhcps_lease { struct dhcps_lease {
bool enable; bool enable;
struct ip_addr start_ip; struct ip_addr start_ip;
struct ip_addr end_ip; struct ip_addr end_ip;
}; };
enum dhcps_offer_option{ enum dhcps_offer_option {
OFFER_START = 0x00, OFFER_START = 0x00,
OFFER_ROUTER = 0x01, OFFER_ROUTER = 0x01,
OFFER_END OFFER_END
}; };
#endif #endif
struct dhcps_pool{ struct dhcps_pool {
struct ip_addr ip; struct ip_addr ip;
u8_t mac[6]; u8_t mac[6];
u32_t lease_timer; u32_t lease_timer;
}; };
typedef struct _list_node{ typedef struct _list_node {
void *pnode; void* pnode;
struct _list_node *pnext; struct _list_node* pnext;
}list_node; } list_node;
extern u32_t dhcps_lease_time; extern u32_t dhcps_lease_time;
#define DHCPS_COARSE_TIMER_SECS 1 #define DHCPS_COARSE_TIMER_SECS 1
@ -53,7 +55,6 @@ extern u32_t dhcps_lease_time;
#define DHCPS_MAX_LEASE 0x64 #define DHCPS_MAX_LEASE 0x64
#define BOOTP_BROADCAST 0x8000 #define BOOTP_BROADCAST 0x8000
#define DHCP_REQUEST 1
#define DHCP_REPLY 2 #define DHCP_REPLY 2
#define DHCP_HTYPE_ETHERNET 1 #define DHCP_HTYPE_ETHERNET 1
#define DHCP_HLEN_ETHERNET 6 #define DHCP_HLEN_ETHERNET 6
@ -96,7 +97,7 @@ extern u32_t dhcps_lease_time;
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0) #define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
void dhcps_start(struct ip_info *info); void dhcps_start(struct ip_info* info);
void dhcps_stop(void); void dhcps_stop(void);
#endif #endif

View File

@ -118,9 +118,6 @@ struct pbuf {
* the stack itself, or pbuf->next pointers from a chain. * the stack itself, or pbuf->next pointers from a chain.
*/ */
u16_t ref; u16_t ref;
/* add a pointer for esf_buf */
void * eb;
}; };
#if LWIP_SUPPORT_CUSTOM_PBUF #if LWIP_SUPPORT_CUSTOM_PBUF

View File

@ -1,173 +0,0 @@
/* $NetBSD: if_llc.h,v 1.12 1999/11/19 20:41:19 thorpej Exp $ */
/*-
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)if_llc.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NET_IF_LLC_H_
#define _NET_IF_LLC_H_
/*
* IEEE 802.2 Link Level Control headers, for use in conjunction with
* 802.{3,4,5} media access control methods.
*
* Headers here do not use bit fields due to shortcommings in many
* compilers.
*/
struct llc {
uint8_t llc_dsap;
uint8_t llc_ssap;
union {
struct {
uint8_t control;
uint8_t format_id;
uint8_t class;
uint8_t window_x2;
} __packed type_u;
struct {
uint8_t num_snd_x2;
uint8_t num_rcv_x2;
} __packed type_i;
struct {
uint8_t control;
uint8_t num_rcv_x2;
} __packed type_s;
struct {
uint8_t control;
/*
* We cannot put the following fields in a structure because
* the structure rounding might cause padding.
*/
uint8_t frmr_rej_pdu0;
uint8_t frmr_rej_pdu1;
uint8_t frmr_control;
uint8_t frmr_control_ext;
uint8_t frmr_cause;
} __packed type_frmr;
struct {
uint8_t control;
uint8_t org_code[3];
uint16_t ether_type;
} __packed type_snap;
struct {
uint8_t control;
uint8_t control_ext;
} __packed type_raw;
} __packed llc_un;
} __packed;
struct frmrinfo {
uint8_t frmr_rej_pdu0;
uint8_t frmr_rej_pdu1;
uint8_t frmr_control;
uint8_t frmr_control_ext;
uint8_t frmr_cause;
} __packed;
#define llc_control llc_un.type_u.control
#define llc_control_ext llc_un.type_raw.control_ext
#define llc_fid llc_un.type_u.format_id
#define llc_class llc_un.type_u.class
#define llc_window llc_un.type_u.window_x2
#define llc_frmrinfo llc_un.type_frmr.frmr_rej_pdu0
#define llc_frmr_pdu0 llc_un.type_frmr.frmr_rej_pdu0
#define llc_frmr_pdu1 llc_un.type_frmr.frmr_rej_pdu1
#define llc_frmr_control llc_un.type_frmr.frmr_control
#define llc_frmr_control_ext llc_un.type_frmr.frmr_control_ext
#define llc_frmr_cause llc_un.type_frmr.frmr_cause
#define llc_snap llc_un.type_snap
/*
* Don't use sizeof(struct llc_un) for LLC header sizes
*/
#define LLC_ISFRAMELEN 4
#define LLC_UFRAMELEN 3
#define LLC_FRMRLEN 7
#define LLC_SNAPFRAMELEN 8
#ifdef CTASSERT
CTASSERT(sizeof (struct llc) == LLC_SNAPFRAMELEN);
#endif
/*
* Unnumbered LLC format commands
*/
#define LLC_UI 0x3
#define LLC_UI_P 0x13
#define LLC_DISC 0x43
#define LLC_DISC_P 0x53
#define LLC_UA 0x63
#define LLC_UA_P 0x73
#define LLC_TEST 0xe3
#define LLC_TEST_P 0xf3
#define LLC_FRMR 0x87
#define LLC_FRMR_P 0x97
#define LLC_DM 0x0f
#define LLC_DM_P 0x1f
#define LLC_XID 0xaf
#define LLC_XID_P 0xbf
#define LLC_SABME 0x6f
#define LLC_SABME_P 0x7f
/*
* Supervisory LLC commands
*/
#define LLC_RR 0x01
#define LLC_RNR 0x05
#define LLC_REJ 0x09
/*
* Info format - dummy only
*/
#define LLC_INFO 0x00
/*
* ISO PDTR 10178 contains among others
*/
#define LLC_8021D_LSAP 0x42
#define LLC_X25_LSAP 0x7e
#define LLC_SNAP_LSAP 0xaa
#define LLC_ISO_LSAP 0xfe
#define RFC1042_LEN 6
#define RFC1042 {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}
#define ETHERNET_TUNNEL {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}
/*
* copied from sys/net/ethernet.h
*/
#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */
#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */
#endif /* _NET_IF_LLC_H_ */

View File

@ -1,20 +0,0 @@
/*
* Copyright (c) 2010-2011 Espressif System
*
*/
#ifndef _WLAN_LWIP_IF_H_
#define _WLAN_LWIP_IF_H_
#include "lwip/err.h"
err_t ethernetif_init(struct netif *netif);
void ethernetif_input(struct netif *netif, struct pbuf *p);
#ifndef IOT_SIP_MODE
sint8 ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb);
#else
sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb);
#endif
#endif /* _WLAN_LWIP_IF_H_ */

View File

@ -1130,9 +1130,6 @@ dhcp_bind(struct netif *netif)
/* bring the interface up */ /* bring the interface up */
netif_set_up(netif); netif_set_up(netif);
// use old ip/mask/gw to check whether ip/mask/gw changed
system_station_got_ip_set(&ip, &mask, &gw);
/* netif is now bound to DHCP leased address */ /* netif is now bound to DHCP leased address */
dhcp_set_state(dhcp, DHCP_BOUND); dhcp_set_state(dhcp, DHCP_BOUND);
} }

File diff suppressed because it is too large Load Diff

View File

@ -357,8 +357,7 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
p->len = p->tot_len = length; p->len = p->tot_len = length;
p->next = NULL; p->next = NULL;
p->type = type; p->type = type;
p->eb = NULL;
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned", LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
break; break;
@ -736,9 +735,6 @@ pbuf_free(struct pbuf *p)
|| type == PBUF_ESF_RX || type == PBUF_ESF_RX
#endif //EBUF_LWIP #endif //EBUF_LWIP
) { ) {
#ifdef EBUF_LWIP
system_pp_recycle_rx_pkt(p->eb);
#endif //EBUF_LWIP
memp_free(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);
/* type == PBUF_RAM */ /* type == PBUF_RAM */
} else { } else {

View File

@ -1,64 +1,28 @@
/** // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
* @file //
* Ethernet Interface Skeleton // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
*/ // You may obtain a copy of the License at
/* // http://www.apache.org/licenses/LICENSE-2.0
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. //
* All rights reserved. // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* Redistribution and use in source and binary forms, with or without modification, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* are permitted provided that the following conditions are met: // See the License for the specific language governing permissions and
* // limitations under the License.
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/ethip6.h" #include "lwip/ethip6.h"
#include "netif/etharp.h" #include "netif/etharp.h"
#include "netif/ppp_oe.h" #include "esp_libc.h"
#include "esp_wifi.h"
#include "tcpip_adapter.h"
#include "esp_common.h"
#ifdef MEMLEAK_DEBUG int8_t ieee80211_output_pbuf(uint8_t fd, uint8_t* dataptr, uint16_t datalen);
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; int8_t wifi_get_netif(uint8_t fd);
#endif void wifi_station_set_default_hostname(uint8_t* hwaddr);
/* Define those to better describe your network interface. */
#define IFNAME0 'e'
#define IFNAME1 'n'
char *hostname;
bool default_hostname = 1;
/** /**
* In this function, the hardware should be initialized. * In this function, the hardware should be initialized.
@ -67,23 +31,27 @@ bool default_hostname = 1;
* @param netif the already initialized lwip network interface structure * @param netif the already initialized lwip network interface structure
* for this ethernetif * for this ethernetif
*/ */
static void static void low_level_init(struct netif* netif)
low_level_init(struct netif *netif)
{ {
/* set MAC hardware address length */ if (netif == NULL) {
netif->hwaddr_len = ETHARP_HWADDR_LEN; TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
return;
}
/* maximum transfer unit */ /* set MAC hardware address length */
netif->mtu = 1500; netif->hwaddr_len = ETHARP_HWADDR_LEN;
/* device capabilities */ /* maximum transfer unit */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ netif->mtu = 1500;
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
#if LWIP_IGMP #if LWIP_IGMP
netif->flags |= NETIF_FLAG_IGMP; netif->flags |= NETIF_FLAG_IGMP;
#endif #endif
/* Do whatever else is needed to initialize interface. */ /* Do whatever else is needed to initialize interface. */
} }
/** /**
@ -94,7 +62,7 @@ low_level_init(struct netif *netif)
* @param netif the lwip network interface structure for this ethernetif * @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent * @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent * an int8_t value if the packet couldn't be sent
* *
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue * strange results. You might consider waiting for space in the DMA queue
@ -102,43 +70,48 @@ low_level_init(struct netif *netif)
* dropped because of memory failure (except for the TCP timers). * dropped because of memory failure (except for the TCP timers).
*/ */
static err_t static int8_t low_level_output(struct netif* netif, struct pbuf* p)
low_level_output(struct netif *netif, struct pbuf *p)
{ {
struct ethernetif *ethernetif = netif->state; int8_t err = ERR_OK;
struct pbuf *q;
err_t err = ERR_OK; if (netif == NULL) {
// initiate transfer(); TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
return ERR_ARG;
}
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif #endif
struct pbuf *tmp; uint8_t* outputbuf = (uint8_t*)os_malloc(p->len + 36);
for(q = p; q != NULL; q = q->next) { if (outputbuf == NULL) {
/* Send the data from the pbuf to the interface, one pbuf at a TCPIP_ATAPTER_LOG("ERROR no memory\n");
time. The size of the data in each pbuf is kept in the ->len return ERR_MEM;
variable. */ }
// send data from(q->payload, q->len);
tmp = q->next; outputbuf += 36;
memcpy(outputbuf, p->payload, p->len);
if (netif == esp_netif[TCPIP_ADAPTER_IF_STA]) {
err = ieee80211_output_pbuf(TCPIP_ADAPTER_IF_STA, outputbuf, p->len);
} else {
err = ieee80211_output_pbuf(TCPIP_ADAPTER_IF_AP, outputbuf, p->len);
}
err = ieee80211_output_pbuf(netif, q);
if (err == ERR_MEM) { if (err == ERR_MEM) {
err = ERR_OK; err = ERR_OK;
} }
q->next = tmp;
break;
}
// signal that packet should be sent(); // signal that packet should be sent();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif #endif
LINK_STATS_INC(link.xmit);
return err; #if LWIP_STATS
LINK_STATS_INC(link.xmit);
#endif
return err;
} }
/** /**
@ -150,60 +123,65 @@ low_level_output(struct netif *netif, struct pbuf *p)
* *
* @param netif the lwip network interface structure for this ethernetif * @param netif the lwip network interface structure for this ethernetif
*/ */
void void ethernetif_input(struct netif* netif, struct pbuf* p)
ethernetif_input(struct netif *netif, struct pbuf *p)
{ {
struct ethernetif *ethernetif; struct eth_hdr* ethhdr;
struct eth_hdr *ethhdr;
if(p == NULL) if (p == NULL) {
goto _exit; TCPIP_ATAPTER_LOG("ERROR pbuf is NULL\n");
goto _exit;
}
if(p->payload == NULL) { if (p->payload == NULL) {
pbuf_free(p); TCPIP_ATAPTER_LOG("ERROR payload is NULL\n");
goto _exit; pbuf_free(p);
} goto _exit;
}
if(netif == NULL) { if (netif == NULL) {
goto _exit; TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
} goto _exit;
}
if (!(netif->flags & NETIF_FLAG_LINK_UP)) { if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
pbuf_free(p); TCPIP_ATAPTER_LOG("ERROR netif is not up\n");
p = NULL; pbuf_free(p);
goto _exit; p = NULL;
} goto _exit;
}
ethernetif = netif->state; /* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload;
/* points to packet payload, which starts with an Ethernet header */ switch (htons(ethhdr->type)) {
ethhdr = p->payload; /* IP or ARP packet? */
case ETHTYPE_IP:
switch (htons(ethhdr->type)) { case ETHTYPE_IPV6:
/* IP or ARP packet? */ case ETHTYPE_ARP:
case ETHTYPE_IP:
case ETHTYPE_IPV6:
case ETHTYPE_ARP:
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
/* PPPoE packet? */
case ETHTYPE_PPPOEDISC:
case ETHTYPE_PPPOE:
#endif /* PPPOE_SUPPORT */
/* full packet send to tcpip_thread to process */
if (netif->input(p, netif)!=ERR_OK)
{ LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
p = NULL;
}
break;
default: /* PPPoE packet? */
pbuf_free(p); case ETHTYPE_PPPOEDISC:
p = NULL; case ETHTYPE_PPPOE:
break; #endif /* PPPOE_SUPPORT */
}
/* full packet send to tcpip_thread to process */
if (netif->input(p, netif) != ERR_OK) {
TCPIP_ATAPTER_LOG("ERROR IP input error\n");
pbuf_free(p);
p = NULL;
}
break;
default:
pbuf_free(p);
p = NULL;
break;
}
_exit: _exit:
; ;
} }
/** /**
@ -216,59 +194,64 @@ _exit:
* @param netif the lwip network interface structure for this ethernetif * @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized * @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated * ERR_MEM if private data couldn't be allocated
* any other err_t on error * any other int8_t on error
*/ */
err_t ethernetif_init(struct netif *netif) int8_t ethernetif_init(struct netif* netif)
{ {
LWIP_ASSERT("netif != NULL", (netif != NULL)); uint8_t mac[NETIF_MAX_HWADDR_LEN];
u8_t mac[NETIF_MAX_HWADDR_LEN]; if (netif == NULL) {
TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
}
/* set MAC hardware address */ /* set MAC hardware address */
if ((struct netif *)wifi_get_netif(STATION_IF) == netif) { if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
wifi_get_macaddr(STATION_IF, mac); wifi_get_macaddr(TCPIP_ADAPTER_IF_STA, mac);
} else { } else {
wifi_get_macaddr(SOFTAP_IF, mac); wifi_get_macaddr(TCPIP_ADAPTER_IF_AP, mac);
} }
memcpy(netif->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
memcpy(netif->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if ((struct netif *)wifi_get_netif(STATION_IF) == netif) {
if (default_hostname == 1) {
wifi_station_set_default_hostname(netif->hwaddr);
}
/* Initialize interface hostname */ if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
netif->hostname = hostname; if (default_hostname == 1) {
} else { wifi_station_set_default_hostname(netif->hwaddr);
netif->hostname = NULL; }
}
/* Initialize interface hostname */
netif->hostname = hostname;
} else {
netif->hostname = NULL;
}
#endif /* LWIP_NETIF_HOSTNAME */ #endif /* LWIP_NETIF_HOSTNAME */
/* /*
* Initialize the snmp variables and counters inside the struct netif. * Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units * The last argument should be replaced with your link speed, in units
* of bits per second. * of bits per second.
*/ */
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS); NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
netif->name[0] = IFNAME0; netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1; netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call. /* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output() * You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link * from it if you have to do some checks before sending (e.g. if link
* is available...) */ * is available...) */
netif->output = etharp_output; netif->output = etharp_output;
#if LWIP_IPV6 #if LWIP_IPV6
netif->output_ip6 = ethip6_output; netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
netif->linkoutput = low_level_output; netif->linkoutput = low_level_output;
extern void wifi_station_dhcpc_event(void); extern void wifi_station_dhcpc_event(void);
netif->dhcp_event = wifi_station_dhcpc_event; netif->dhcp_event = wifi_station_dhcpc_event;
/* initialize the hardware */ /* initialize the hardware */
low_level_init(netif); low_level_init(netif);
return ERR_OK; return ERR_OK;
} }