Skip to content

Commit

Permalink
Build with SDK 2.1, KRACK WPA2 patch in fw, incl. liblwip
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ger committed Oct 19, 2017
1 parent 2aa8b64 commit deba409
Show file tree
Hide file tree
Showing 12 changed files with 4,706 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -35,17 +35,17 @@ TARGET = app
# which modules (subdirectories) of the project to include in compiling
MODULES = driver user
#MODULES = driver user-simple
EXTRA_INCDIR = $(BUILD_AREA)/esp-open-sdk/esp-open-lwip/include include
EXTRA_INCDIR = include $(BUILD_AREA)/esp-open-sdk/esp-open-lwip/include
#EXTRA_INCDIR = include

# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal pp phy net80211 lwip_open wpa main
LIBS = c gcc hal pp phy net80211 lwip_open_napt wpa main

# compiler flags using during compilation of source files
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -DLWIP_OPEN_SRC

# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -L.

# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -8,7 +8,7 @@ The Firmware starts with the following default configuration:
- ssid: ssid, pasword: password
- slip interface address: 192.168.240.1

This means it connects to the internet via AP ssid,password and offer at the UART0 a SLIP interface with IP address 192.168.240.1. This default can be changed in the file user_config.h.
This means it connects to the internet via AP ssid,password and offers at UART0 a SLIP interface with IP address 192.168.240.1. This default can be changed in the file user_config.h.

To connect a linux-based host, start the firmware on the esp, connect it via serial to USB, and use the following commands on the host:
```
Expand Down Expand Up @@ -48,11 +48,11 @@ The console understands the following command:
- scan: does a scan for APs

# Building and Flashing
To build this binary you download and install the esp-open-sdk (https://github.com/pfalcon/esp-open-sdk) and my version of the esp-open-lwip library (https://github.com/martin-ger/esp-open-lwip). Replace that in the esp-open-sdk tree. "make clean" in the esp_open_lwip dir and once again a "make" in the upper esp_open_sdk will do the job. This installs a new version of the liblwip_open.a that contains the SLIP interface and the NAT features.
To build this binary you download and install the esp-open-sdk (https://github.com/pfalcon/esp-open-sdk). Make sure, you can compile and download the included "blinky" example.

Then adjust the BUILD_AREA variable in the Makefile and any desired options in user/user_config.h.
Then download this source tree in a separate directory and adjust the BUILD_AREA variable in the Makefile and any desired options in user/user_config.h. Build the esp_wifi_repeater firmware with "make". "make flash" flashes it onto an esp8266.

Build the esp_wifi_repeater firmware with "make". "make flash" flashes it onto an esp8266.
The source tree includes a binary version of the liblwip_open plus the required additional includes from my fork of esp-open-lwip. *No additional install action is required for that.* Only if you don't want to use the precompiled library, checkout the sources from https://github.com/martin-ger/esp-open-lwip . Use it to replace the directory "esp-open-lwip" in the esp-open-sdk tree. "make clean" in the esp_open_lwip dir and once again a "make" in the upper esp_open_sdk directory. This will compile a liblwip_open.a that contains the NAT-features. Replace liblwip_open_napt.a with that binary.

If you want to use the precompiled binaries you can flash them with "esptool.py --port /dev/ttyUSB0 write_flash -fs 32m 0x00000 firmware/0x00000.bin 0x10000 firmware/0x10000.bin" (use -fs 8m for an ESP-01)

Expand Down
4 changes: 2 additions & 2 deletions driver/softuart.c
Expand Up @@ -131,7 +131,7 @@ void Softuart_Init(Softuart *s, uint32_t baudrate)

//set high for tx idle
GPIO_OUTPUT_SET(GPIO_ID_PIN(s->pin_tx.gpio_id), 1);
os_delay_us(100000);
os_delay_us(0xffff);

os_printf("SOFTUART TX INIT DONE\r\n");
}
Expand All @@ -155,7 +155,7 @@ void Softuart_Init(Softuart *s, uint32_t baudrate)
ETS_GPIO_INTR_DISABLE();

//attach interrupt handler and a pointer that will be passed around each time
ETS_GPIO_INTR_ATTACH(Softuart_Intr_Handler, s);
ETS_GPIO_INTR_ATTACH((ets_isr_t)Softuart_Intr_Handler, s);

//not sure what this does... (quote from example):
// void gpio_register_set(uint32 reg_id, uint32 value);
Expand Down
Binary file modified firmware/0x00000.bin
Binary file not shown.
Binary file modified firmware/0x10000.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions firmware/sha1sums
@@ -0,0 +1,2 @@
0257aa40626f161ba3090170400a1d9274d41de4 0x00000.bin
021555b56a1a66c9b14d7d0e0fb85963a41180c7 0x10000.bin
106 changes: 106 additions & 0 deletions include/lwip/app/dhcpserver.h
@@ -0,0 +1,106 @@
#ifndef __DHCPS_H__
#define __DHCPS_H__

#define USE_DNS

typedef struct dhcps_state{
sint16_t state;
} dhcps_state;

// ����dhcpclient�Զ����һ��DHCP msg�ṹ��
typedef struct dhcps_msg {
uint8_t op, htype, hlen, hops;
uint8_t xid[4];
uint16_t secs, flags;
uint8_t ciaddr[4];
uint8_t yiaddr[4];
uint8_t siaddr[4];
uint8_t giaddr[4];
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t file[128];
uint8_t options[312];
}dhcps_msg;

#ifndef LWIP_OPEN_SRC
struct dhcps_lease {
bool enable;
struct ip_addr start_ip;
struct ip_addr end_ip;
};

enum dhcps_offer_option{
OFFER_START = 0x00,
OFFER_ROUTER = 0x01,
OFFER_END
};
#endif

struct dhcps_pool{
struct ip_addr ip;
uint8 mac[6];
uint32 lease_timer;
};

typedef struct _list_node{
void *pnode;
struct _list_node *pnext;
}list_node;

extern uint32 dhcps_lease_time;
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
#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
#define DHCP_MSG_LEN 236

#define DHCPS_SERVER_PORT 67
#define DHCPS_CLIENT_PORT 68

#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7

#define DHCP_OPTION_SUBNET_MASK 1
#define DHCP_OPTION_ROUTER 3
#define DHCP_OPTION_DNS_SERVER 6
#define DHCP_OPTION_REQ_IPADDR 50
#define DHCP_OPTION_LEASE_TIME 51
#define DHCP_OPTION_MSG_TYPE 53
#define DHCP_OPTION_SERVER_ID 54
#define DHCP_OPTION_INTERFACE_MTU 26
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
#define DHCP_OPTION_BROADCAST_ADDRESS 28
#define DHCP_OPTION_REQ_LIST 55
#define DHCP_OPTION_END 255

//#define USE_CLASS_B_NET 1
#define DHCPS_DEBUG 0
#define MAX_STATION_NUM 8

#define DHCPS_STATE_OFFER 1
#define DHCPS_STATE_DECLINE 2
#define DHCPS_STATE_ACK 3
#define DHCPS_STATE_NAK 4
#define DHCPS_STATE_IDLE 5
#define DHCPS_STATE_RELEASE 6

#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)

void dhcps_start(struct ip_info *info);
void dhcps_stop(void);

void dhcps_set_DNS(struct ip_addr *dns_ip) ICACHE_FLASH_ATTR;
struct dhcps_pool *dhcps_get_mapping(uint16_t no) ICACHE_FLASH_ATTR;
void dhcps_set_mapping(struct ip_addr *addr, uint8 *mac, uint32 lease_time) ICACHE_FLASH_ATTR;

#endif

115 changes: 115 additions & 0 deletions include/lwip/lwip_napt.h
@@ -0,0 +1,115 @@
#ifndef __LWIP_NAPT_H__
#define __LWIP_NAPT_H__

#include "lwip/opt.h"

#ifdef __cplusplus
extern "C" {
#endif

#if IP_FORWARD
#if IP_NAPT

/* Default size of the tables used for NAPT */
#define IP_NAPT_MAX 512
#define IP_PORTMAP_MAX 32

/* Timeouts in sec for the various protocol types */
#define IP_NAPT_TIMEOUT_MS_TCP (30*60*1000)
#define IP_NAPT_TIMEOUT_MS_TCP_DISCON (20*1000)
#define IP_NAPT_TIMEOUT_MS_UDP (2*1000)
#define IP_NAPT_TIMEOUT_MS_ICMP (2*1000)

#define IP_NAPT_PORT_RANGE_START 49152
#define IP_NAPT_PORT_RANGE_END 61439

struct napt_table {
u32_t last;
u32_t src;
u32_t dest;
u16_t sport;
u16_t dport;
u16_t mport;
u8_t proto;
u8_t fin1 : 1;
u8_t fin2 : 1;
u8_t finack1 : 1;
u8_t finack2 : 1;
u8_t synack : 1;
u8_t rst : 1;
u16_t next, prev;
};

struct portmap_table {
u32_t maddr;
u32_t daddr;
u16_t mport;
u16_t dport;
u8_t proto;
u8 valid;
};

extern struct portmap_table *ip_portmap_table;

/**
* Allocates and initializes the NAPT tables.
*
* @param max_nat max number of enties in the NAPT table (use IP_NAPT_MAX if in doubt)
* @param max_portmap max number of enties in the NAPT table (use IP_PORTMAP_MAX if in doubt)
*/
void ICACHE_FLASH_ATTR
ip_napt_init(uint16_t max_nat, uint8_t max_portmap);


/**
* Enable/Disable NAPT for a specified interface.
*
* @param addr ip address of the interface
* @param enable non-zero to enable NAPT, or 0 to disable.
*/
void ICACHE_FLASH_ATTR
ip_napt_enable(u32_t addr, int enable);


/**
* Enable/Disable NAPT for a specified interface.
*
* @param netif number of the interface
* @param enable non-zero to enable NAPT, or 0 to disable.
*/
void ICACHE_FLASH_ATTR
ip_napt_enable_no(u8_t number, int enable);


/**
* Register port mapping on the external interface to internal interface.
* When the same port mapping is registered again, the old mapping is overwritten.
* In this implementation, only 1 unique port mapping can be defined for each target address/port.
*
* @param proto target protocol
* @param maddr ip address of the external interface
* @param mport mapped port on the external interface, in host byte order.
* @param daddr destination ip address
* @param dport destination port, in host byte order.
*/
u8_t ICACHE_FLASH_ATTR
ip_portmap_add(u8_t proto, u32_t maddr, u16_t mport, u32_t daddr, u16_t dport);


/**
* Unregister port mapping on the external interface to internal interface.
*
* @param proto target protocol
* @param maddr ip address of the external interface
*/
u8_t ICACHE_FLASH_ATTR
ip_portmap_remove(u8_t proto, u16_t mport);

#endif /* IP_NAPT */
#endif /* IP_FORWARD */

#ifdef __cplusplus
}
#endif

#endif /* __LWIP_NAPT_H__ */

0 comments on commit deba409

Please sign in to comment.