-
Notifications
You must be signed in to change notification settings - Fork 21
/
esp_rawsend.c
135 lines (112 loc) · 3.1 KB
/
esp_rawsend.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "esp_rawsend.h"
#include <mystuff.h>
//From https://github.com/ernacktob/esp8266_wifi_raw
extern void ICACHE_FLASH_ATTR ppEnqueueRxq(void *);
wifi_raw_recv_cb_fn wifi_mcb;
void ICACHE_FLASH_ATTR wifi_set_raw_recv_cb(wifi_raw_recv_cb_fn rx_fn)
{
wifi_mcb = rx_fn;
}
void aaEnqueueRxq(void * v)
{
if (wifi_mcb)
wifi_mcb((struct RxPacket *)( ((void **)v)[4]), v );
ppEnqueueRxq(v);
}
//I use a less evasive mechanism to send than the other packet thing.
//We need to get our hands on this pointer, but I don't know it's absolute location
//So, we wait for a TX packet callback and steal it from there.
static void * pxpkt = 0; //This is the pointer to the structure that let's us raw send.
static void txcb(uint8_t *buf, uint16 reason)
{
pxpkt = buf;
return;
#ifdef DO_DEEP_TX_DEBUG
return;
char ct[16];
int i = 0;
ets_sprintf( ct, "<%p %d --> NODE:%p\n", buf, reason, eagle_lwip_getif(1) );
uart0_sendStr( ct );
for( i = 0; i <100; i++ )
{
ets_sprintf( ct, "%02x ", buf[i] );
uart0_sendStr( ct );
}
uart0_sendStr( "\n" );
uint8_t * innerbuf = ((uint32_t*)buf)[1];
ets_sprintf( ct, "\nInner [1]: %p\n", innerbuf );
uart0_sendStr( ct );
for( i = 0; i <100; i++ )
{
ets_sprintf( ct, "%02x ", innerbuf[i] );
uart0_sendStr( ct );
}
innerbuf = ((uint32_t*)buf)[4];
ets_sprintf( ct, "\nInner [4]: %p\n", innerbuf );
uart0_sendStr( ct );
for( i = 0; i <100; i++ )
{
ets_sprintf( ct, "%02x ", innerbuf[i] );
uart0_sendStr( ct );
}
innerbuf = ((uint32_t*)buf)[8];
ets_sprintf( ct, "\nInner [8]: %p\n", innerbuf ); //nothing else here...
uart0_sendStr( ct );
for( i = 0; i <100; i++ )
{
ets_sprintf( ct, "%02x ", innerbuf[i] );
uart0_sendStr( ct );
}
uint32_t * inner8next = innerbuf;
inner8next = inner8next[5];
ets_sprintf( ct, "\nInner [8][5]: %p\n", inner8next ); //Nothing more here.
uart0_sendStr( ct );
for( i = 0; i <100; i++ )
{
ets_sprintf( ct, "%02x ", ((uint8_t*)inner8next)[i] );
uart0_sendStr( ct );
}
#endif
}
void SetupRawsend()
{
int i;
for( i = 0; i <7; i++ )
{
ppRegisterTxCallback( txcb, i );
}
}
int CanRawsend()
{
return pxpkt!=0;
}
//I don't use this anymore, so really no need to do it.
//I strongly recommend using esp freedom if possible.
void RawSendBuffer( uint8_t * buffer, int length )
{
if( !pxpkt )
{
printf( "Nosend." );
return;
}
struct Ctrl{
uint8_t reserved; //No idea
uint8_t channel:4; //This is a guess
uint8_t size_lsb:4;
uint8_t size_msb; //This is almost always 192.
uint8_t code;
} * control = ((struct Ctrl**)pxpkt)[1];
#ifdef DO_DEEP_TX_DEBUG
char buffer[100];
ets_sprintf( buffer, "Res: %d Chan: %d Size: %d Code: %d // TXLen: %d\n", control->reserved, control->channel, control->size_lsb + (control->size_msb<<4), control->code, ((uint32_t*)pxpkt)[5]>>16 );
uart0_sendStr(buffer);
#endif
int size = length; //Actual size of payload.
if( size < 24 ) size = 24;
control->size_lsb = size&0x0f;
control->size_msb = size>>4;
((uint32_t*)pxpkt)[5] = (((uint32_t*)pxpkt)[5] & 0xff ) | ((size-24)<<16);
uint8_t * rawpacket = ((uint8_t**)pxpkt)[4];
ets_memcpy( rawpacket, buffer, length );
ppTxPkt( pxpkt );
}