Managed to create a fake AP using
wifi_send_pkt_freedom.
In
micropython/esp8266/modnetwork.c, add the following before
method isconnected() and make deploy:
Code: Select all
STATIC mp_obj_t esp_freedom(mp_obj_t self_in, mp_obj_t chan_in, mp_obj_t buf_in) {
require_if(self_in, STATION_IF);
if ((wifi_get_opmode() & STATION_MODE) == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"STA must be active"));
}
int channel = mp_obj_get_int(chan_in);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
wifi_station_disconnect();
wifi_promiscuous_enable(1);
wifi_set_channel(channel);
wifi_send_pkt_freedom(bufinfo.buf, bufinfo.len, false);
wifi_send_pkt_freedom(bufinfo.buf, bufinfo.len, false);
wifi_send_pkt_freedom(bufinfo.buf, bufinfo.len, false);
wifi_promiscuous_enable(0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_freedom_obj, esp_freedom);
And further down in
STATIC const mp_map_elem_t wlan_if_locals_dict_table add:
Code: Select all
{ MP_OBJ_NEW_QSTR(MP_QSTR_freedom), (mp_obj_t)&esp_freedom_obj },
Usage:
sta_if.freedom(channel, packet)
Fake AP Example:
Code: Select all
import network
import time
import uos
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.scan()
def beacon(ssid, channel, times):
packet = bytearray([0x80,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xb8,0xe8,0x56,0x33,0xde,0x01,0xb8,0xe8,0x56,0x33,0xde,0x01,0xc0,0x6c,0x83,0x51,0xf7,0x8f,0x0f,0x00,0x00,0x00,0x64,0x00,0x01,0x04,0x00,0x00])
packet[37] = len(ssid)
packet.extend(ssid)
packet.extend(bytearray([0x01,0x08,0x82,0x84,0x8b,0x96,0x24,0x30,0x48,0x6c,0x03,0x01,0x01]))
packet[-1] = channel
for i in range(times):
packet[10] = packet[16] = uos.urandom(1)[0]
packet[11] = packet[17] = uos.urandom(1)[0]
packet[12] = packet[18] = uos.urandom(1)[0]
packet[13] = packet[19] = uos.urandom(1)[0]
packet[14] = packet[20] = uos.urandom(1)[0]
packet[15] = packet[21] = uos.urandom(1)[0]
sta_if.freedom(channel, packet)
time.sleep_ms(10)
# create a fake AP called Foo
beacon('Foo', 1, 50)