Skip to content

Commit

Permalink
Merge pull request #5 from redfast00/master
Browse files Browse the repository at this point in the history
Implemented #1
  • Loading branch information
ernacktob authored Mar 31, 2017
2 parents c69f7be + a5361da commit 9223f28
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LIBS = c gcc hal pp phy net80211 lwip wpa main
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH

# 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 -Wl,-wrap=ppEnqueueRxq -Wl,-wrap=ppTxPkt

# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
Expand Down
137 changes: 0 additions & 137 deletions Makefile2

This file was deleted.

10 changes: 6 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is currently a dirty hack, and not quite perfect.

DISCLAIMER: THIS IS A PROOF OF CONCEPT ONLY. USE AT YOUR OWN RISK!

The code in this project was compiled and linked against the esp_iot_sdk_v1.2.0.
The code in this project was compiled and linked against the esp_iot_sdk_v1.2.0. and also works with esp_iot_sdk_v0.9.3.

SENDING
--------
Expand Down Expand Up @@ -59,9 +59,9 @@ here and there. Please let me know if you find something interesting.
NOTES
-----

Update: Better method for hooking into ppEnqueueRxq https://github.com/ernacktob/esp8266_wifi_raw/issues/1
Update: Better method for hooking into ppEnqueueRxq and ppTxPkt https://github.com/ernacktob/esp8266_wifi_raw/issues/1

This program requires a modified libnet80211 and libpp library, which we called libnet80211_2.a and libpp2.a.
<strike>This program requires a modified libnet80211 and libpp library, which we called libnet80211_2.a and libpp2.a.
The modified libraries can be seen in the lib/ folder.

The modified net80211 library has its symbol table changed so that all references to ppTxPkt
Expand All @@ -77,4 +77,6 @@ the actual function definition, and this one should not be changed. Follow these
`sed s/ppTxPkt/aaTxPkt/g2 libpp.a > libpp2.a`

The Makefile must also be modified to link to net80211_2 and pp2 instead of net80211 and pp.
Use `make -f Makefile2` to build, or run the `./compile_and_flash` script (pass the port as a command line argument).
Use `make -f Makefile2` to build, or run the `./compile_and_flash` script (pass the port as a command line argument).</strike>

The makefile is modified in order to wrap the ppTxPkt and ppEnqueueRxq functions (see LDFLAGS).
2 changes: 1 addition & 1 deletion compile_and_flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORT=$1
make clean
make -f Makefile2
make

until sudo -E env "PATH=$PATH" make flash ESPPORT=$PORT; do
sleep 1
Expand Down
Binary file removed lib/libnet80211_2.a
Binary file not shown.
Binary file removed lib/libpp2.a
Binary file not shown.
22 changes: 10 additions & 12 deletions user/wifi_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#define SOFTAP_IF 0x01
#define SOFTAP_MODE 0x02

extern void ICACHE_FLASH_ATTR ppTxPkt(void *);
extern void ICACHE_FLASH_ATTR ppEnqueueRxq(void *);

static int called = 0;
static wifi_raw_recv_cb_fn rx_func = NULL;
Expand All @@ -24,7 +22,7 @@ static wifi_raw_recv_cb_fn rx_func = NULL;
My guess is that this is some kind of interrupt
that should execute as fast as possible, and
ICACHE_FLASH_ATTR stores it in a slower-to-access location... */
void aaEnqueueRxq(void *a)
void __wrap_ppEnqueueRxq(void *a)
{
// int i;
// for (i = 0; i < 30; i++){
Expand All @@ -47,13 +45,13 @@ void aaEnqueueRxq(void *a)
if (rx_func)
rx_func((struct RxPacket *)(((void **)a)[4]));

ppEnqueueRxq(a);
__real_ppEnqueueRxq(a);
}

/* Warning: this is an experiment, and relies
on undocumented library calls. Might not work as expected,
and not guaranteed to work in any other sdk version... */
void ICACHE_FLASH_ATTR aaTxPkt(void *buf, uint16 len)
void ICACHE_FLASH_ATTR __wrap_ppTxPkt(void *buf, uint16 len)
{
static int level = 0;
static void *upper_buf;
Expand All @@ -63,7 +61,7 @@ void ICACHE_FLASH_ATTR aaTxPkt(void *buf, uint16 len)
just behave exactly like ppTxPkt. */
/* this might need a mutex... */
if (!called) {
ppTxPkt(buf); //library function call normally without our interception
__real_ppTxPkt(buf); //library function call normally without our interception
return;
}

Expand Down Expand Up @@ -93,7 +91,7 @@ void ICACHE_FLASH_ATTR aaTxPkt(void *buf, uint16 len)

level = 1;

/* Go down one level into ieee80211_output_pbuf.
/* Go down one level into ieee80211_output_pbuf.
ieee80211_output_pbuf calls aaTxPkt because the libnet80211_2 has all references to
ppTxPkt modified to our aaTxPkt instead*/
if (ieee80211_output_pbuf(ifp, pb))
Expand All @@ -109,7 +107,7 @@ void ICACHE_FLASH_ATTR aaTxPkt(void *buf, uint16 len)
the packet data in the appropriate memory addresses. */

memcpy(((uint8 **)buf)[4], upper_buf, upper_len);
ppTxPkt(buf);
__real_ppTxPkt(buf);
}
}

Expand All @@ -128,17 +126,17 @@ void ICACHE_FLASH_ATTR wifi_send_raw_packet(void *data, uint16 len)
/* Save current opmode and switch to SOFTAP_MODE */
uint8 mode;
mode = wifi_get_opmode();
//Need softap mode in order to send
//Need softap mode in order to send
wifi_set_opmode(SOFTAP_MODE);

/* this also needs a mutex */
//pptx packet could get called by something other than
//pptx packet could get called by something other than
//our send packet function
called = 1;
aaTxPkt(data, len); //sending a raw packet with data, length
__wrap_ppTxPkt(data, len); //sending a raw packet with data, length
called = 0;

//Restoring previous opmode
//Restoring previous opmode
wifi_set_opmode(mode);
//Restoring rx_func after sending
rx_func = recv_func;
Expand Down

0 comments on commit 9223f28

Please sign in to comment.