mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 15:15:15 +08:00
Merge branch 'feature/remove_wifi_from_lwip' into 'refactor'
feat(lwip): remove wifi from lwip See merge request sdk/ESP8266_RTOS_SDK!66
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
|
||||
#define USE_DNS
|
||||
|
||||
#include "esp_wifi.h"
|
||||
|
||||
typedef struct dhcps_state {
|
||||
s16_t state;
|
||||
} dhcps_state;
|
||||
@ -53,7 +55,6 @@ extern u32_t dhcps_lease_time;
|
||||
#define DHCPS_MAX_LEASE 0x64
|
||||
#define BOOTP_BROADCAST 0x8000
|
||||
|
||||
#define DHCP_REQUEST 1
|
||||
#define DHCP_REPLY 2
|
||||
#define DHCP_HTYPE_ETHERNET 1
|
||||
#define DHCP_HLEN_ETHERNET 6
|
||||
|
@ -118,9 +118,6 @@ struct pbuf {
|
||||
* the stack itself, or pbuf->next pointers from a chain.
|
||||
*/
|
||||
u16_t ref;
|
||||
|
||||
/* add a pointer for esf_buf */
|
||||
void * eb;
|
||||
};
|
||||
|
||||
#if LWIP_SUPPORT_CUSTOM_PBUF
|
||||
|
@ -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_ */
|
@ -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_ */
|
@ -1130,9 +1130,6 @@ dhcp_bind(struct netif *netif)
|
||||
/* bring the interface up */
|
||||
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 */
|
||||
dhcp_set_state(dhcp, DHCP_BOUND);
|
||||
}
|
||||
|
@ -1,3 +1,17 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_common.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/err.h"
|
||||
@ -9,12 +23,13 @@
|
||||
#ifndef LWIP_OPEN_SRC
|
||||
#include "net80211/ieee80211_var.h"
|
||||
#endif
|
||||
#include "netif/wlan_lwip_if.h"
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
extern struct netif *esp_netif[2];
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//static const uint8_t xid[4] = {0xad, 0xde, 0x12, 0x23};
|
||||
//static u8_t old_xid[4] = {0};
|
||||
@ -43,9 +58,10 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
|
||||
list_node* plist = NULL;
|
||||
struct dhcps_pool* pdhcps_pool = NULL;
|
||||
struct dhcps_pool* pdhcps_node = NULL;
|
||||
if (*phead == NULL)
|
||||
|
||||
if (*phead == NULL) {
|
||||
*phead = pinsert;
|
||||
else {
|
||||
} else {
|
||||
plist = *phead;
|
||||
pdhcps_node = pinsert->pnode;
|
||||
pdhcps_pool = plist->pnode;
|
||||
@ -56,11 +72,13 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
|
||||
} else {
|
||||
while (plist->pnext != NULL) {
|
||||
pdhcps_pool = plist->pnext->pnode;
|
||||
|
||||
if (pdhcps_node->ip.addr < pdhcps_pool->ip.addr) {
|
||||
pinsert->pnext = plist->pnext;
|
||||
plist->pnext = pinsert;
|
||||
break;
|
||||
}
|
||||
|
||||
plist = plist->pnext;
|
||||
}
|
||||
|
||||
@ -69,6 +87,7 @@ void node_insert_to_list(list_node **phead, list_node* pinsert)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pinsert->pnext = NULL;
|
||||
}
|
||||
|
||||
@ -83,6 +102,7 @@ void node_remove_from_list(list_node **phead, list_node* pdelete)
|
||||
list_node* plist = NULL;
|
||||
|
||||
plist = *phead;
|
||||
|
||||
if (plist == NULL) {
|
||||
*phead = NULL;
|
||||
} else {
|
||||
@ -95,6 +115,7 @@ void node_remove_from_list(list_node **phead, list_node* pdelete)
|
||||
plist->pnext = pdelete->pnext;
|
||||
pdelete->pnext = NULL;
|
||||
}
|
||||
|
||||
plist = plist->pnext;
|
||||
}
|
||||
}
|
||||
@ -285,7 +306,9 @@ static void send_offer(struct dhcps_msg *m)
|
||||
u8_t* data;
|
||||
u16_t cnt = 0;
|
||||
u16_t i;
|
||||
#if DHCPS_DEBUG
|
||||
err_t SendOffer_err_t;
|
||||
#endif
|
||||
create_msg(m);
|
||||
|
||||
end = add_msg_type(&m->options[4], DHCPOFFER);
|
||||
@ -296,6 +319,7 @@ static void send_offer(struct dhcps_msg *m)
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("udhcp: send_offer>>p->ref = %d\n", p->ref);
|
||||
#endif
|
||||
|
||||
if (p != NULL) {
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
@ -304,16 +328,19 @@ static void send_offer(struct dhcps_msg *m)
|
||||
os_printf("dhcps: send_offer>>p->len = %d\n", p->len);
|
||||
#endif
|
||||
q = p;
|
||||
|
||||
while (q != NULL) {
|
||||
data = (u8_t*)q->payload;
|
||||
for(i=0; i<q->len; i++)
|
||||
{
|
||||
|
||||
for (i = 0; i < q->len; i++) {
|
||||
data[i] = ((u8_t*) m)[cnt++];
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("%02x ", data[i]);
|
||||
|
||||
if ((i + 1) % 16 == 0) {
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -326,10 +353,14 @@ static void send_offer(struct dhcps_msg *m)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
SendOffer_err_t = udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
os_printf("dhcps: send_offer>>udp_sendto result %x\n", SendOffer_err_t);
|
||||
#else
|
||||
udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
#endif
|
||||
|
||||
if (p->ref != 0) {
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("udhcp: send_offer>>free pbuf\n");
|
||||
@ -352,7 +383,9 @@ static void send_nak(struct dhcps_msg *m)
|
||||
u8_t* data;
|
||||
u16_t cnt = 0;
|
||||
u16_t i;
|
||||
#if DHCPS_DEBUG
|
||||
err_t SendNak_err_t;
|
||||
#endif
|
||||
create_msg(m);
|
||||
|
||||
end = add_msg_type(&m->options[4], DHCPNAK);
|
||||
@ -362,6 +395,7 @@ static void send_nak(struct dhcps_msg *m)
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("udhcp: send_nak>>p->ref = %d\n", p->ref);
|
||||
#endif
|
||||
|
||||
if (p != NULL) {
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
@ -370,16 +404,19 @@ static void send_nak(struct dhcps_msg *m)
|
||||
os_printf("dhcps: send_nak>>p->len = %d\n", p->len);
|
||||
#endif
|
||||
q = p;
|
||||
|
||||
while (q != NULL) {
|
||||
data = (u8_t*)q->payload;
|
||||
for(i=0; i<q->len; i++)
|
||||
{
|
||||
|
||||
for (i = 0; i < q->len; i++) {
|
||||
data[i] = ((u8_t*) m)[cnt++];
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("%02x ", data[i]);
|
||||
|
||||
if ((i + 1) % 16 == 0) {
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -392,10 +429,14 @@ static void send_nak(struct dhcps_msg *m)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
SendNak_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
SendNak_err_t = udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
os_printf("dhcps: send_nak>>udp_sendto result %x\n", SendNak_err_t);
|
||||
#else
|
||||
udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
#endif
|
||||
|
||||
if (p->ref != 0) {
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("udhcp: send_nak>>free pbuf\n");
|
||||
@ -418,7 +459,9 @@ static void send_ack(struct dhcps_msg *m)
|
||||
u8_t* data;
|
||||
u16_t cnt = 0;
|
||||
u16_t i;
|
||||
#if DHCPS_DEBUG
|
||||
err_t SendAck_err_t;
|
||||
#endif
|
||||
create_msg(m);
|
||||
|
||||
end = add_msg_type(&m->options[4], DHCPACK);
|
||||
@ -429,6 +472,7 @@ static void send_ack(struct dhcps_msg *m)
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("udhcp: send_ack>>p->ref = %d\n", p->ref);
|
||||
#endif
|
||||
|
||||
if (p != NULL) {
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
@ -437,16 +481,19 @@ static void send_ack(struct dhcps_msg *m)
|
||||
os_printf("dhcps: send_ack>>p->len = %d\n", p->len);
|
||||
#endif
|
||||
q = p;
|
||||
|
||||
while (q != NULL) {
|
||||
data = (u8_t*)q->payload;
|
||||
for(i=0; i<q->len; i++)
|
||||
{
|
||||
|
||||
for (i = 0; i < q->len; i++) {
|
||||
data[i] = ((u8_t*) m)[cnt++];
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("%02x ", data[i]);
|
||||
|
||||
if ((i + 1) % 16 == 0) {
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -459,9 +506,12 @@ static void send_ack(struct dhcps_msg *m)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
SendAck_err_t = udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
os_printf("dhcps: send_ack>>udp_sendto result %x\n", SendAck_err_t);
|
||||
#else
|
||||
udp_sendto(pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT);
|
||||
#endif
|
||||
|
||||
if (p->ref != 0) {
|
||||
@ -498,6 +548,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: (s16_t)*optptr = %d\n", (s16_t)*optptr);
|
||||
#endif
|
||||
|
||||
switch ((s16_t) *optptr) {
|
||||
|
||||
case DHCP_OPTION_MSG_TYPE: //53
|
||||
@ -516,9 +567,10 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||
#endif
|
||||
s.state = DHCPS_STATE_NAK;
|
||||
}
|
||||
|
||||
break;
|
||||
case DHCP_OPTION_END:
|
||||
{
|
||||
|
||||
case DHCP_OPTION_END: {
|
||||
is_dhcp_parse_end = true;
|
||||
}
|
||||
break;
|
||||
@ -547,10 +599,12 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||
} else {
|
||||
s.state = DHCPS_STATE_NAK;
|
||||
}
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: DHCPD_STATE_NAK\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DHCPDECLINE://4
|
||||
@ -567,6 +621,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: return s.state = %d\n", s.state);
|
||||
#endif
|
||||
@ -577,6 +632,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
|
||||
static s16_t parse_msg(struct dhcps_msg* m, u16_t len)
|
||||
{
|
||||
u32_t lease_timer = (dhcps_lease_time * 60) / DHCPS_COARSE_TIMER_SECS;
|
||||
|
||||
if (memcmp((char*)m->options,
|
||||
&magic_cookie,
|
||||
sizeof(magic_cookie)) == 0) {
|
||||
@ -621,17 +677,20 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
first_address.addr = dhcps_lease.start_ip.addr;
|
||||
client_address.addr = client_address_plus.addr;
|
||||
renew = false;
|
||||
|
||||
// addr_tmp.addr = htonl(client_address_plus.addr);
|
||||
// addr_tmp.addr++;
|
||||
// client_address_plus.addr = htonl(addr_tmp.addr);
|
||||
if (plist != NULL) {
|
||||
for (pback_node = plist; pback_node != NULL; pback_node = pback_node->pnext) {
|
||||
pdhcps_pool = pback_node->pnode;
|
||||
|
||||
if (memcmp(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac)) == 0) {
|
||||
// os_printf("the same device request ip\n");
|
||||
if (memcmp(&pdhcps_pool->ip.addr, m->ciaddr, sizeof(pdhcps_pool->ip.addr)) == 0) {
|
||||
renew = true;
|
||||
}
|
||||
|
||||
client_address.addr = pdhcps_pool->ip.addr;
|
||||
pdhcps_pool->lease_timer = lease_timer;
|
||||
pnode = pback_node;
|
||||
@ -662,6 +721,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
if (client_address_plus.addr > dhcps_lease.end_ip.addr) {
|
||||
client_address.addr = first_address.addr;
|
||||
}
|
||||
|
||||
if (client_address.addr > dhcps_lease.end_ip.addr) {
|
||||
client_address_plus.addr = dhcps_lease.start_ip.addr;
|
||||
pdhcps_pool = NULL;
|
||||
@ -675,6 +735,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
pnode->pnode = pdhcps_pool;
|
||||
pnode->pnext = NULL;
|
||||
node_insert_to_list(&plist, pnode);
|
||||
|
||||
if (client_address.addr == dhcps_lease.end_ip.addr) {
|
||||
client_address_plus.addr = dhcps_lease.start_ip.addr;
|
||||
} else {
|
||||
@ -685,6 +746,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
}
|
||||
|
||||
POOL_CHECK:
|
||||
|
||||
if ((client_address.addr > dhcps_lease.end_ip.addr) || (ip_addr_isany(&client_address))) {
|
||||
if (pnode != NULL) {
|
||||
node_remove_from_list(&plist, pnode);
|
||||
@ -696,6 +758,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
os_free(pdhcps_pool);
|
||||
pdhcps_pool = NULL;
|
||||
}
|
||||
|
||||
// client_address_plus.addr = dhcps_lease.start_ip.addr;
|
||||
return 4;
|
||||
}
|
||||
@ -713,12 +776,14 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
os_free(pdhcps_pool);
|
||||
pdhcps_pool = NULL;
|
||||
}
|
||||
|
||||
memset(&client_address, 0x0, sizeof(client_address));
|
||||
}
|
||||
|
||||
if (wifi_softap_set_station_info(m->chaddr, &client_address) == false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
@ -731,6 +796,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
@ -761,13 +827,18 @@ static void handle_dhcp(void *arg,
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: handle_dhcp-> receive a packet\n");
|
||||
#endif
|
||||
if (p==NULL) return;
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pmsg_dhcps = (struct dhcps_msg*)os_zalloc(sizeof(struct dhcps_msg));
|
||||
|
||||
if (NULL == pmsg_dhcps) {
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
p_dhcps_msg = (u8_t*)pmsg_dhcps;
|
||||
tlen = p->tot_len;
|
||||
data = p->payload;
|
||||
@ -781,9 +852,11 @@ static void handle_dhcp(void *arg,
|
||||
p_dhcps_msg[dhcps_msg_cnt++] = data[i];
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("%02x ", data[i]);
|
||||
|
||||
if ((i + 1) % 16 == 0) {
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -795,13 +868,16 @@ static void handle_dhcp(void *arg,
|
||||
#endif
|
||||
|
||||
data = p->next->payload;
|
||||
|
||||
for (i = 0; i < p->next->len; i++) {
|
||||
p_dhcps_msg[dhcps_msg_cnt++] = data[i];
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("%02x ", data[i]);
|
||||
|
||||
if ((i + 1) % 16 == 0) {
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -821,21 +897,25 @@ static void handle_dhcp(void *arg,
|
||||
#endif
|
||||
send_offer(pmsg_dhcps);
|
||||
break;
|
||||
|
||||
case DHCPS_STATE_ACK://3
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: handle_dhcp-> DHCPD_STATE_ACK\n");
|
||||
#endif
|
||||
send_ack(pmsg_dhcps);
|
||||
break;
|
||||
|
||||
case DHCPS_STATE_NAK://4
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: handle_dhcp-> DHCPD_STATE_NAK\n");
|
||||
#endif
|
||||
send_nak(pmsg_dhcps);
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
os_printf("dhcps: handle_dhcp-> pbuf_free(p)\n");
|
||||
#endif
|
||||
@ -849,16 +929,19 @@ static void wifi_softap_init_dhcps_lease(u32_t ip)
|
||||
u32_t softap_ip = 0, local_ip = 0;
|
||||
u32_t start_ip = 0;
|
||||
u32_t end_ip = 0;
|
||||
|
||||
if (dhcps_lease.enable == TRUE) {
|
||||
softap_ip = htonl(ip);
|
||||
start_ip = htonl(dhcps_lease.start_ip.addr);
|
||||
end_ip = htonl(dhcps_lease.end_ip.addr);
|
||||
|
||||
/*config ip information can't contain local ip*/
|
||||
if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) {
|
||||
dhcps_lease.enable = FALSE;
|
||||
} else {
|
||||
/*config ip information must be in the same segment as the local ip*/
|
||||
softap_ip >>= 8;
|
||||
|
||||
if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip))
|
||||
|| (end_ip - start_ip > DHCPS_MAX_LEASE)) {
|
||||
dhcps_lease.enable = FALSE;
|
||||
@ -870,10 +953,12 @@ static void wifi_softap_init_dhcps_lease(u32_t ip)
|
||||
local_ip = softap_ip = htonl(ip);
|
||||
softap_ip &= 0xFFFFFF00;
|
||||
local_ip &= 0xFF;
|
||||
if (local_ip >= 0x80)
|
||||
|
||||
if (local_ip >= 0x80) {
|
||||
local_ip -= DHCPS_MAX_LEASE;
|
||||
else
|
||||
} else {
|
||||
local_ip ++;
|
||||
}
|
||||
|
||||
bzero(&dhcps_lease, sizeof(dhcps_lease));
|
||||
dhcps_lease.start_ip.addr = softap_ip | local_ip;
|
||||
@ -881,22 +966,24 @@ static void wifi_softap_init_dhcps_lease(u32_t ip)
|
||||
dhcps_lease.start_ip.addr = htonl(dhcps_lease.start_ip.addr);
|
||||
dhcps_lease.end_ip.addr = htonl(dhcps_lease.end_ip.addr);
|
||||
}
|
||||
|
||||
// os_printf("start_ip = 0x%x, end_ip = 0x%x\n",dhcps_lease.start_ip, dhcps_lease.end_ip);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
void dhcps_start(struct ip_info* info)
|
||||
{
|
||||
struct netif * apnetif = NULL;
|
||||
apnetif = (struct netif *)wifi_get_netif(SOFTAP_IF);
|
||||
struct netif* apnetif = esp_netif[0x01];
|
||||
|
||||
if (apnetif->dhcps_pcb != NULL) {
|
||||
udp_remove(apnetif->dhcps_pcb);
|
||||
}
|
||||
|
||||
pcb_dhcps = udp_new();
|
||||
|
||||
if (pcb_dhcps == NULL || info == NULL) {
|
||||
os_printf("dhcps_start(): could not obtain pcb\n");
|
||||
}
|
||||
|
||||
apnetif->dhcps_pcb = pcb_dhcps;
|
||||
|
||||
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
|
||||
@ -914,9 +1001,10 @@ void dhcps_start(struct ip_info *info)
|
||||
|
||||
void dhcps_stop(void)
|
||||
{
|
||||
struct netif * apnetif = (struct netif *)wifi_get_netif(0x01);
|
||||
struct netif* apnetif = esp_netif[0x01];
|
||||
|
||||
udp_disconnect(pcb_dhcps);
|
||||
|
||||
// dhcps_lease_flag = true;
|
||||
if (apnetif->dhcps_pcb != NULL) {
|
||||
udp_remove(apnetif->dhcps_pcb);
|
||||
@ -927,6 +1015,7 @@ void dhcps_stop(void)
|
||||
list_node* pnode = NULL;
|
||||
list_node* pback_node = NULL;
|
||||
pnode = plist;
|
||||
|
||||
while (pnode != NULL) {
|
||||
pback_node = pnode;
|
||||
pnode = pback_node->pnext;
|
||||
@ -951,8 +1040,9 @@ bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (please == NULL || wifi_softap_dhcps_status() == DHCP_STARTED)
|
||||
if (please == NULL || wifi_softap_dhcps_status() == DHCP_STARTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (please->enable) {
|
||||
bzero(&info, sizeof(struct ip_info));
|
||||
@ -962,18 +1052,21 @@ bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please)
|
||||
end_ip = htonl(please->end_ip.addr);
|
||||
|
||||
/*config ip information can't contain local ip*/
|
||||
if ((start_ip <= softap_ip) && (softap_ip <= end_ip))
|
||||
if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*config ip information must be in the same segment as the local ip*/
|
||||
softap_ip >>= 8;
|
||||
|
||||
if ((start_ip >> 8 != softap_ip)
|
||||
|| (end_ip >> 8 != softap_ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (end_ip - start_ip > DHCPS_MAX_LEASE)
|
||||
if (end_ip - start_ip > DHCPS_MAX_LEASE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bzero(&dhcps_lease, sizeof(dhcps_lease));
|
||||
// dhcps_lease.start_ip.addr = start_ip;
|
||||
@ -981,6 +1074,7 @@ bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please)
|
||||
dhcps_lease.start_ip.addr = please->start_ip.addr;
|
||||
dhcps_lease.end_ip.addr = please->end_ip.addr;
|
||||
}
|
||||
|
||||
dhcps_lease.enable = please->enable;
|
||||
// dhcps_lease_flag = false;
|
||||
return true;
|
||||
@ -1001,13 +1095,17 @@ bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NULL == please)
|
||||
if (NULL == please) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dhcps_lease.enable == FALSE) {
|
||||
if (wifi_softap_dhcps_status() == DHCP_STOPPED)
|
||||
if (wifi_softap_dhcps_status() == DHCP_STOPPED) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
please->start_ip.addr = dhcps_lease.start_ip.addr;
|
||||
please->end_ip.addr = dhcps_lease.end_ip.addr;
|
||||
return true;
|
||||
@ -1022,16 +1120,20 @@ static void kill_oldest_dhcps_pool(void)
|
||||
p = pre->pnext;
|
||||
minpre = pre;
|
||||
minp = p;
|
||||
|
||||
while (p != NULL) {
|
||||
pdhcps_pool = p->pnode;
|
||||
pmin_pool = minp->pnode;
|
||||
|
||||
if (pdhcps_pool->lease_timer < pmin_pool->lease_timer) {
|
||||
minp = p;
|
||||
minpre = pre;
|
||||
}
|
||||
|
||||
pre = p;
|
||||
p = p->pnext;
|
||||
}
|
||||
|
||||
minpre->pnext = minp->pnext;
|
||||
os_free(minp->pnode);
|
||||
minp->pnode = NULL;
|
||||
@ -1046,9 +1148,11 @@ void dhcps_coarse_tmr(void)
|
||||
list_node* pnode = NULL;
|
||||
struct dhcps_pool* pdhcps_pool = NULL;
|
||||
pnode = plist;
|
||||
|
||||
while (pnode != NULL) {
|
||||
pdhcps_pool = pnode->pnode;
|
||||
pdhcps_pool->lease_timer --;
|
||||
|
||||
if (pdhcps_pool->lease_timer == 0) {
|
||||
pback_node = pnode;
|
||||
pnode = pback_node->pnext;
|
||||
@ -1063,29 +1167,34 @@ void dhcps_coarse_tmr(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (num_dhcps_pool >= MAX_STATION_NUM)
|
||||
if (num_dhcps_pool >= MAX_STATION_NUM) {
|
||||
kill_oldest_dhcps_pool();
|
||||
}
|
||||
}
|
||||
|
||||
bool wifi_softap_set_dhcps_offer_option(u8_t level, void* optarg)
|
||||
{
|
||||
bool offer_flag = true;
|
||||
u8_t option = 0;
|
||||
if (optarg == NULL && wifi_softap_dhcps_status() == false)
|
||||
return false;
|
||||
|
||||
if (level <= OFFER_START || level >= OFFER_END)
|
||||
if (optarg == NULL && wifi_softap_dhcps_status() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (level <= OFFER_START || level >= OFFER_END) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case OFFER_ROUTER:
|
||||
offer = (*(uint8*)optarg) & 0x01;
|
||||
offer_flag = true;
|
||||
break;
|
||||
|
||||
default :
|
||||
offer_flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return offer_flag;
|
||||
}
|
||||
|
||||
@ -1104,6 +1213,7 @@ bool wifi_softap_set_dhcps_lease_time(u32_t minute)
|
||||
if (minute == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dhcps_lease_time = minute;
|
||||
return true;
|
||||
}
|
||||
@ -1119,6 +1229,7 @@ bool wifi_softap_reset_dhcps_lease_time(void)
|
||||
if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dhcps_lease_time = DHCPS_LEASE_TIME_DEF;
|
||||
return true;
|
||||
}
|
||||
|
@ -357,7 +357,6 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
|
||||
p->len = p->tot_len = length;
|
||||
p->next = NULL;
|
||||
p->type = type;
|
||||
p->eb = NULL;
|
||||
|
||||
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
|
||||
((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
|
||||
@ -736,9 +735,6 @@ pbuf_free(struct pbuf *p)
|
||||
|| type == PBUF_ESF_RX
|
||||
#endif //EBUF_LWIP
|
||||
) {
|
||||
#ifdef EBUF_LWIP
|
||||
system_pp_recycle_rx_pkt(p->eb);
|
||||
#endif //EBUF_LWIP
|
||||
memp_free(MEMP_PBUF, p);
|
||||
/* type == PBUF_RAM */
|
||||
} else {
|
||||
|
@ -1,64 +1,28 @@
|
||||
/**
|
||||
* @file
|
||||
* Ethernet Interface Skeleton
|
||||
*
|
||||
*/
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* 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.
|
||||
* 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>
|
||||
*
|
||||
*/
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/snmp.h"
|
||||
#include "lwip/ethip6.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
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
/* Define those to better describe your network interface. */
|
||||
#define IFNAME0 'e'
|
||||
#define IFNAME1 'n'
|
||||
|
||||
char *hostname;
|
||||
bool default_hostname = 1;
|
||||
int8_t ieee80211_output_pbuf(uint8_t fd, uint8_t* dataptr, uint16_t datalen);
|
||||
int8_t wifi_get_netif(uint8_t fd);
|
||||
void wifi_station_set_default_hostname(uint8_t* hwaddr);
|
||||
|
||||
/**
|
||||
* In this function, the hardware should be initialized.
|
||||
@ -67,9 +31,13 @@ bool default_hostname = 1;
|
||||
* @param netif the already initialized lwip network interface structure
|
||||
* for this ethernetif
|
||||
*/
|
||||
static void
|
||||
low_level_init(struct netif *netif)
|
||||
static void low_level_init(struct netif* netif)
|
||||
{
|
||||
if (netif == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
|
||||
@ -94,7 +62,7 @@ low_level_init(struct netif *netif)
|
||||
* @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)
|
||||
* @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
|
||||
* strange results. You might consider waiting for space in the DMA queue
|
||||
@ -102,33 +70,37 @@ low_level_init(struct netif *netif)
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
|
||||
static err_t
|
||||
low_level_output(struct netif *netif, struct pbuf *p)
|
||||
static int8_t low_level_output(struct netif* netif, struct pbuf* p)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
struct pbuf *q;
|
||||
err_t err = ERR_OK;
|
||||
// initiate transfer();
|
||||
int8_t err = ERR_OK;
|
||||
|
||||
if (netif == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
struct pbuf *tmp;
|
||||
for(q = p; q != NULL; q = q->next) {
|
||||
/* Send the data from the pbuf to the interface, one pbuf at a
|
||||
time. The size of the data in each pbuf is kept in the ->len
|
||||
variable. */
|
||||
// send data from(q->payload, q->len);
|
||||
tmp = q->next;
|
||||
uint8_t* outputbuf = (uint8_t*)os_malloc(p->len + 36);
|
||||
if (outputbuf == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR no memory\n");
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
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) {
|
||||
err = ERR_OK;
|
||||
}
|
||||
q->next = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
// signal that packet should be sent();
|
||||
|
||||
@ -136,8 +108,9 @@ low_level_output(struct netif *netif, struct pbuf *p)
|
||||
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
|
||||
#if LWIP_STATS
|
||||
LINK_STATS_INC(link.xmit);
|
||||
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -150,32 +123,33 @@ low_level_output(struct netif *netif, struct pbuf *p)
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
*/
|
||||
void
|
||||
ethernetif_input(struct netif *netif, struct pbuf *p)
|
||||
void ethernetif_input(struct netif* netif, struct pbuf* p)
|
||||
{
|
||||
struct ethernetif *ethernetif;
|
||||
struct eth_hdr* ethhdr;
|
||||
|
||||
if(p == NULL)
|
||||
if (p == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR pbuf is NULL\n");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (p->payload == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR payload is NULL\n");
|
||||
pbuf_free(p);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (netif == NULL) {
|
||||
TCPIP_ATAPTER_LOG("ERROR netif is NULL\n");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
|
||||
TCPIP_ATAPTER_LOG("ERROR netif is not up\n");
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
ethernetif = netif->state;
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
ethhdr = p->payload;
|
||||
|
||||
@ -185,16 +159,19 @@ ethernetif_input(struct netif *netif, struct pbuf *p)
|
||||
case ETHTYPE_IPV6:
|
||||
case ETHTYPE_ARP:
|
||||
#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"));
|
||||
if (netif->input(p, netif) != ERR_OK) {
|
||||
TCPIP_ATAPTER_LOG("ERROR IP input error\n");
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -202,6 +179,7 @@ ethernetif_input(struct netif *netif, struct pbuf *p)
|
||||
p = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
_exit:
|
||||
;
|
||||
}
|
||||
@ -216,24 +194,28 @@ _exit:
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* 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 */
|
||||
if ((struct netif *)wifi_get_netif(STATION_IF) == netif) {
|
||||
wifi_get_macaddr(STATION_IF, mac);
|
||||
if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
|
||||
wifi_get_macaddr(TCPIP_ADAPTER_IF_STA, mac);
|
||||
} else {
|
||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||
wifi_get_macaddr(TCPIP_ADAPTER_IF_AP, mac);
|
||||
}
|
||||
|
||||
memcpy(netif->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
if ((struct netif *)wifi_get_netif(STATION_IF) == netif) {
|
||||
|
||||
if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
|
||||
if (default_hostname == 1) {
|
||||
wifi_station_set_default_hostname(netif->hwaddr);
|
||||
}
|
||||
@ -243,6 +225,7 @@ err_t ethernetif_init(struct netif *netif)
|
||||
} else {
|
||||
netif->hostname = NULL;
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user