Skip to content

Commit

Permalink
LwIP v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ourairquality committed Jul 3, 2017
1 parent a0297eb commit 3041c59
Show file tree
Hide file tree
Showing 32 changed files with 725 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "lwip/lwip"]
path = lwip/lwip
url = https://github.com/SuperHouse/esp-lwip.git
url = https://github.com/ourairquality/lwip.git
[submodule "extras/mbedtls/mbedtls"]
path = extras/mbedtls/mbedtls
url = https://github.com/ARMmbed/mbedtls.git
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Current status is alpha quality, actively developed. AP STATION mode (ie wifi cl
## Open Source Components

* [FreeRTOS](http://www.freertos.org/) V9.0.0
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v1.4.1, modified via the [esp-lwip project](https://github.com/kadamski/esp-lwip) by @kadamski.
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v2.0.3, with [some modifications](https://github.com/ourairquality/lwip/).
* [newlib](https://github.com/projectgus/newlib-xtensa) v2.2.0, with patches for xtensa support and locking stubs for thread-safe operation on FreeRTOS.

For details of how third party libraries are integrated, [see the wiki page](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries).
Expand Down
4 changes: 2 additions & 2 deletions core/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ static void init_g_ic(void) {
if (sdk_g_ic.s._unknown310 > 4) {
sdk_g_ic.s._unknown310 = 4;
}
if (sdk_g_ic.s._unknown1e4._unknown1e4 == 0xffffffff) {
bzero(&sdk_g_ic.s._unknown1e4, sizeof(sdk_g_ic.s._unknown1e4));
if (sdk_g_ic.s.sta_ssid.ssid_length == 0xffffffff) {
bzero(&sdk_g_ic.s.sta_ssid, sizeof(sdk_g_ic.s.sta_ssid));
bzero(&sdk_g_ic.s.sta_password, sizeof(sdk_g_ic.s.sta_password));
}
sdk_g_ic.s.wifi_led_enable = 0;
Expand Down
49 changes: 23 additions & 26 deletions core/include/sdk_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct _unknown_wpa1 {
};


struct sdk_netif_conninfo {
struct sdk_cnx_node {
uint8_t mac_addr[6];
uint8_t _unknown07[2];

Expand All @@ -105,10 +105,12 @@ struct sdk_netif_conninfo {
uint16_t _unknown9c; // ieee80211_hostap. increases by one one each timer func called.
uint16_t _unknown9e;

uint32_t _unknowna0[18];
uint32_t _unknowna0[17];

int8_t _unknowne8; //
int8_t _unknowne9; // ppInstallKey
void *_unknowne4;

uint8_t _unknowne8; //
uint8_t _unknowne9; // ppInstallKey
int8_t _unknownea;
int8_t _unknowneb;

Expand All @@ -128,9 +130,9 @@ struct sdk_g_ic_netif_info {
uint32_t _unknown48; // 0x48
uint8_t _unknown4c; // 0x4c
uint8_t _unknown4d[59]; // 0x4d - 0x88
struct sdk_netif_conninfo *_unknown88; // 0x88
struct sdk_cnx_node *_unknown88; // 0x88
uint32_t _unknown8c; // 0x8c
struct sdk_netif_conninfo *conninfo[6]; // 0x90 - 0xa8
struct sdk_cnx_node *cnx_nodes[6]; // 0x90 - 0xa8
uint8_t _unknowna8[12]; // 0xa8 - 0xb4
struct _unknown_softap1 *_unknownb4;
uint8_t statusb8; // 0xb8 (arg of sta_status_set)
Expand Down Expand Up @@ -206,10 +208,9 @@ struct sdk_g_ic_volatile_st {
};


struct sdk_g_ic_unk0_st {
uint16_t _unknown1e4; // sdk_wpa_config_profile
uint16_t _unknown1e6; // sdk_wpa_config_profile
uint8_t sta_ssid[32]; // 0x1e8 Station ssid. Null terminated string.
struct sdk_g_ic_ssid_with_length {
uint32_t ssid_length; // 0x1e4 sdk_wpa_config_profile
uint8_t ssid[32]; // 0x1e8 Station ssid. Null terminated string.
};

// This is the portion of g_ic which is loaded/saved to the flash ROM, and thus
Expand All @@ -224,7 +225,8 @@ struct sdk_g_ic_saved_st {
uint8_t wifi_led_gpio;
uint8_t wifi_led_state; // 0 or 1.

struct sdk_g_ic_unk0_st _unknown1e4;
// Current station ap config ssid and length.
struct sdk_g_ic_ssid_with_length sta_ssid; // 0x1e4

uint8_t _unknown208;
uint8_t _unknown209; // sdk_wpa_config_profile
Expand Down Expand Up @@ -260,7 +262,7 @@ struct sdk_g_ic_saved_st {
uint8_t _unknown30d; // result of ieee80211_chan2ieee
uint8_t _unknown30e;
uint8_t _unknown30f;
uint8_t _unknown310; // count of entries in the softap conninfo array, less two.
uint8_t _unknown310; // count of entries in the softap cnx_node array, less two.

uint8_t _unknown311[3];

Expand Down Expand Up @@ -331,16 +333,16 @@ _Static_assert(offsetof(struct _unknown_softap1, _unknown18) == 0x18, "bad struc
_Static_assert(sizeof(struct _unknown_wpa1) == 0x4c, "_unknown_wpa1 is the wrong size!");
_Static_assert(offsetof(struct _unknown_wpa1, _unknown48) == 0x48, "bad struct");

_Static_assert(offsetof(struct sdk_netif_conninfo, _unknown78) == 0x78, "bad struct");
_Static_assert(offsetof(struct sdk_netif_conninfo, _unknown108) == 0x108, "bad struct");
_Static_assert(offsetof(struct sdk_cnx_node, _unknown78) == 0x78, "bad struct");
_Static_assert(offsetof(struct sdk_cnx_node, _unknown108) == 0x108, "bad struct");

_Static_assert(offsetof(struct sdk_g_ic_netif_info, started) == 0xbb, "bad struct");

_Static_assert(sizeof(struct sdk_g_ic_volatile_st) == 0x1d8, "sdk_g_ic_volatile_st is the wrong size!");
_Static_assert(offsetof(struct sdk_g_ic_volatile_st, _unknown1d5) == 0x1d5, "bad struct");

_Static_assert(sizeof(struct sdk_g_ic_saved_st) == 0x370, "sdk_g_ic_saved_st is the wrong size!");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, _unknown1e4) == 0x1e4 - 0x1d8, "bad struct");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, sta_ssid) == 0x1e4 - 0x1d8, "bad struct");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, _unknown546) == 0x546 - 0x1d8, "bad struct");

_Static_assert(sizeof(struct sdk_g_ic_st) == 0x548, "sdk_g_ic_st is the wrong size!");
Expand All @@ -357,21 +359,16 @@ _Static_assert(offsetof(struct esf_buf, length) == 0x16, "bad struct");
// ieee80211_output_pbuf and perhaps elsewhere. The value is just passed through
// lwip and and not used by lwip so just ensure this slot is at the expected
// offset.
_Static_assert(offsetof(struct netif, state) == 28, "netif->state offset wrong!");
_Static_assert(offsetof(struct netif, state) == 4, "netif->state offset wrong!");

// Some sdk uses of netif->hwaddr have been converted to source code, but many
// remain, but the content of this slot should not change in future versions of
// lwip, so just ensure it is at the expected offset.
_Static_assert(offsetof(struct netif, hwaddr) == 41, "netif->hwaddr offset wrong!");

// Most sdk uses of the netif->flags have been converted to source code. One
// known sdk binary read of the flags remains in wl_cnx.o:sdk_cnx_sta_leave
// which checks the NETIF_FLAG_DHCP flag. The NETIF_FLAG_DHCP has been removed
// in lwip v2, so some lwip hacks are needed to handle this for now until
// wl_cnx.o is converted so source code too.
_Static_assert(offsetof(struct netif, flags) == 47, "netif->flags offset wrong!");
// lwip, so just ensure it is at the expected offset. Note the sdk binary
// libraries have been patched to move this offset from 41 to 42 to keep it
// 16-bit aligned to keep lwip v2 happy.
_Static_assert(offsetof(struct netif, hwaddr) == 8, "netif->hwaddr offset wrong!");

_Static_assert(offsetof(struct pbuf, eb) == 16, "pbuf->eb offset wrong!");
_Static_assert(offsetof(struct pbuf, esf_buf) == 16, "pbuf->esf_buf offset wrong!");


/// Misc.
Expand Down
7 changes: 4 additions & 3 deletions examples/http_get/http_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define WEB_SERVER "chainxor.org"
#define WEB_PORT 80
#define WEB_URL "http://chainxor.org/"
#define WEB_PATH "/"

void http_get_task(void *pvParameters)
{
Expand Down Expand Up @@ -75,7 +75,8 @@ void http_get_task(void *pvParameters)
freeaddrinfo(res);

const char *req =
"GET "WEB_URL"\r\n"
"GET "WEB_PATH" HTTP/1.1\r\n"
"Host: "WEB_SERVER"\r\n"
"User-Agent: esp-open-rtos/0.1 esp8266\r\n"
"\r\n";
if (write(s, req, strlen(req)) < 0) {
Expand Down Expand Up @@ -126,6 +127,6 @@ void user_init(void)
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&config);

xTaskCreate(&http_get_task, "get_task", 256, NULL, 2, NULL);
xTaskCreate(&http_get_task, "get_task", 384, NULL, 2, NULL);
}

5 changes: 2 additions & 3 deletions examples/tls_server/tls_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ void tls_server_task(void *pvParameters)
socklen_t peer_addr_len = sizeof(struct sockaddr_in);
getpeername(client_ctx.fd, (struct sockaddr *)&peer_addr, &peer_addr_len);
unsigned char buf[256];
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\nFree heap size is %d bytes\n",
ip4_addr1(&peer_addr.sin_addr), ip4_addr2(&peer_addr.sin_addr),
ip4_addr3(&peer_addr.sin_addr), ip4_addr4(&peer_addr.sin_addr),
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\nFree heap size is %d bytes\n",
IP2STR((ip4_addr_t *)&peer_addr.sin_addr.s_addr),
peer_addr.sin_port, xPortGetFreeHeapSize());
while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
{
Expand Down
5 changes: 2 additions & 3 deletions examples/tls_server_bearssl/tls_server_bearssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ void tls_server_task(void *pvParameters)

/* Prepare a message to the client */
unsigned char buf[100];
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\r\nFree heap size is %d bytes\r\n",
ip4_addr1(&sa.sin_addr), ip4_addr2(&sa.sin_addr),
ip4_addr3(&sa.sin_addr), ip4_addr4(&sa.sin_addr),
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\r\nFree heap size is %d bytes\r\n",
IP2STR((ip4_addr_t *)&sa.sin_addr.s_addr),
ntohs(sa.sin_port), xPortGetFreeHeapSize());

/* Send the message and close the connection */
Expand Down
Loading

0 comments on commit 3041c59

Please sign in to comment.