/*
* raw_wifi_tst.c
* Created on: 04/04/2017
*/
#include <autoconf.h>
#include "FreeRTOS.h"
#include "drv_types.h"
#include "diag.h"
#include "wifi_api.h"
#include "wifi_conf.h"
#include "rtl8195a/rtl_libc.h"
#include "hal_platform.h"
#include "lwip/netif.h"
#if (!defined(CONFIG_ENABLE_P2P)) || (!CONFIG_ENABLE_P2P)
#error "Set CONFIG_ENABLE_P2P!"
#endif
//------------------------------------------------------------------------------
extern struct netif xnetif[NET_IF_NUM];
extern Rltk_wlan_t rltk_wlan_info[2]; // in wrapper.h
LOCAL int wifi_up(void) {
int ret = 0;
info_printf("Initializing WIFI...\n");
ret = rltk_wlan_init(0, 1); // rtw_mode_t
netif_set_up(&xnetif[0]);
if (ret < 0) return ret;
uint32 timeout = xTaskGetTickCount();
rltk_wlan_start(0);
while (1) {
if (rltk_wlan_running(0)) {
printf("WIFI initialized (%d ms)\n", xTaskGetTickCount() - timeout);
break;
}
if(xTaskGetTickCount() - timeout > 2000) {
error_printf("WIFI init timeout!\n");
break;
}
vTaskDelay(20);
}
return ret;
}
//------------------------------------------------------------------------------
u8 RandSK(u8 max) {
u8 buf;
do {
rtw_get_random_bytes(&buf, 1);
} while (buf>max);
return buf;
}
//------------------------------------------------------------------------------
LOCAL void fATRT(int argc, char *argv[])
{
char wlan0[10] = "wlan0";
u8 alfa[65] = "1234567890qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_.";
u8 packet[128] = { 0x80, 0x00, 0x00, 0x00,
/*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
/*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
/*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
/*22*/ 0xc0, 0x6c,
/*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00,
/*32*/ 0x64, 0x00,
/*34*/ 0x01, 0x04,
/* SSID */
/*36*/ 0x00, 0x06, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72,
0x01, 0x08, 0x82, 0x84,
0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01,
/*56*/ 0x04};
u8 channel = 1;
//_adapter *ad0 = rltk_wlan_info[0].dev;
if(argc > 1) {
channel = atoi(argv[1]);
}
if((!channel) || channel > 14) channel = 1;
// Source MAC Address
packet[10] = packet[16] = 1;//RandSK256();
packet[11] = packet[17] = 1;//RandSK256();
packet[12] = packet[18] = 1;//RandSK256();
packet[13] = packet[19] = 1;//RandSK256();
packet[14] = packet[20] = 1;//RandSK256();
packet[15] = packet[21] = 1;//RandSK256();
// Randomize SSID (Fixed size 6. Lazy right?)
packet[38] = alfa[RandSK(65)];
packet[39] = alfa[RandSK(65)];
packet[40] = alfa[RandSK(65)];
packet[41] = alfa[RandSK(65)];
packet[42] = alfa[RandSK(65)];
packet[43] = alfa[RandSK(65)];
packet[56] = channel;
uint32 timeout = xTaskGetTickCount();
wifi_up();
// for(int i=0; i<10000; i++) {
for(int i=0; i<3; i++) {
wext_send_mgnt(wlan0, &packet, 57, NULL);
vTaskDelay(2); // + WDT
}
// printf("prep C\n");
printf("WIFI start && send 3 packet (%d ms)\n", xTaskGetTickCount() - timeout);
}
//------------------------------------------------------------------------------
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_rwt[] = {
{"ATRT", 0, fATRT, ": Raw WiFi Test"}
};