From e4bc8fab7a9a3e5ac08a7b857b0fad1976980166 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 13 May 2015 16:40:54 +1000 Subject: [PATCH] First set of changes for from-source esp-lwip --- examples/http_get/FreeRTOSConfig.h | 2 +- lwip/esp_interface.c | 80 ++++++++++++++++++++++++++++-- lwip/include/arch/bpstruct.h | 1 - lwip/include/arch/cc.h | 7 ++- lwip/include/lwipopts.h | 6 +++ lwip/lwip | 2 +- 6 files changed, 91 insertions(+), 7 deletions(-) delete mode 100644 lwip/include/arch/bpstruct.h diff --git a/examples/http_get/FreeRTOSConfig.h b/examples/http_get/FreeRTOSConfig.h index 27b2b3f..e6701cf 100644 --- a/examples/http_get/FreeRTOSConfig.h +++ b/examples/http_get/FreeRTOSConfig.h @@ -84,7 +84,7 @@ #define configTICK_RATE_HZ ( ( portTickType ) 100 ) #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 15 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short )156 ) -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24 * 1024 ) ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 18 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 16 ) #define configUSE_TRACE_FACILITY 0 #define configUSE_STATS_FORMATTING_FUNCTIONS 0 diff --git a/lwip/esp_interface.c b/lwip/esp_interface.c index daa88f1..587f8d8 100644 --- a/lwip/esp_interface.c +++ b/lwip/esp_interface.c @@ -2,15 +2,89 @@ These two symbols are called from libnet80211.a */ +#include "lwip/opt.h" -/* called from hostap_input... less clear what this is for! */ -void ethernetif_init(void) +#include "lwip/def.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include +#include +#include "netif/etharp.h" +#include "netif/ppp_oe.h" + +/* declared in libnet80211.a */ +int8_t ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); +//sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb); + +static err_t +low_level_output(struct netif *netif, struct pbuf *p) { + struct pbuf *q; + for(q = p; q != NULL; q = q->next) { + ieee80211_output_pbuf(netif, q); + } + + LINK_STATS_INC(link.xmit); + + return ERR_OK; +} + + +err_t ethernetif_init(struct netif *netif) +{ + LWIP_ASSERT("netif != NULL", (netif != NULL)); + +#if LWIP_NETIF_HOSTNAME + /* Initialize interface hostname */ + netif->hostname = "lwip"; +#endif /* LWIP_NETIF_HOSTNAME */ + + /* + * Initialize the snmp variables and counters inside the struct netif. + * The last argument should be replaced with your link speed, in units + * of bits per second. + */ + NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS); + + //netif->state = (void *)0xDEADBEEF; /* this appears unused by esp layer */ + netif->name[0] = 'e'; + netif->name[1] = 'n'; + netif->output = etharp_output; + /* NB: in the SDK there's a static wrapper function to this, not sure what it does!! */ + netif->linkoutput = low_level_output; + + /* low level init components */ + netif->hwaddr_len = 6; + /* hwaddr seems to be set elsewhere, or (more likely) is per-packet by MAC layer */ + netif->mtu = 1500; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; + + return ERR_OK; } /* called from ieee80211_deliver_data with new IP frames */ -void ethernetif_input(void) +void ethernetif_input(struct netif *netif, struct pbuf *p) { + struct eth_hdr *ethhdr = p->payload; + /* examine packet payloads ethernet header */ + switch (htons(ethhdr->type)) { + /* IP or ARP packet? */ + case ETHTYPE_IP: + case ETHTYPE_ARP: +// case ETHTYPE_IPV6: + /* 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: + pbuf_free(p); + p = NULL; + break; + } } diff --git a/lwip/include/arch/bpstruct.h b/lwip/include/arch/bpstruct.h deleted file mode 100644 index 1d81e3f..0000000 --- a/lwip/include/arch/bpstruct.h +++ /dev/null @@ -1 +0,0 @@ -#pragma pack(push,1) diff --git a/lwip/include/arch/cc.h b/lwip/include/arch/cc.h index 782f11b..828b381 100644 --- a/lwip/include/arch/cc.h +++ b/lwip/include/arch/cc.h @@ -59,7 +59,7 @@ typedef uint32_t u32_t; typedef int32_t s32_t; typedef size_t mem_ptr_t; -typedef u32_t sys_prot_t; +typedef int sys_prot_t; /* Define (sn)printf formatters for these lwIP types */ #define X8_F "02x" @@ -84,4 +84,9 @@ typedef u32_t sys_prot_t; printf("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__); \ handler;} } while(0) +#define LWIP_PLATFORM_BYTESWAP 1 + +#define LWIP_PLATFORM_HTONS(_n) ((u16_t)((((_n) & 0xff) << 8) | (((_n) >> 8) & 0xff))) +#define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) )) + #endif /* __ARCH_CC_H__ */ diff --git a/lwip/include/lwipopts.h b/lwip/include/lwipopts.h index 3096e4a..761ea33 100644 --- a/lwip/include/lwipopts.h +++ b/lwip/include/lwipopts.h @@ -32,6 +32,12 @@ #ifndef __LWIPOPTS_H__ #define __LWIPOPTS_H__ +#define LWIP_ESP 1 +#define ESP_RTOS 1 +#define PBUF_RSV_FOR_WLAN 1 +#define EBUF_LWIP 1 +#define ESP_TIMEWAIT_THRESHOLD 10000 + /* ----------------------------------------------- ---------- Platform specific locking ---------- diff --git a/lwip/lwip b/lwip/lwip index 5b8b5d4..808c242 160000 --- a/lwip/lwip +++ b/lwip/lwip @@ -1 +1 @@ -Subproject commit 5b8b5d459e7dd890724515bbfad86c705234f9ec +Subproject commit 808c24237c1e9a3862b2eb1e0a94fd34ede6ec79