This commit is contained in:
pvvx 2017-04-28 05:00:05 +03:00
parent 01d402f038
commit b1d891c21e
30 changed files with 3219 additions and 3085 deletions

View file

@ -0,0 +1,9 @@
#ifndef _user_config_h_
#define _user_config_h_
#define SYS_VERSION "1.0.0"
#define SDK_VERSION "3.5.3"
#endif // _user_config_h_

View file

@ -10,55 +10,60 @@
//=========================================
//==== Wlan Config ========================
#define DEF_WIFI_MODE RTW_MODE_STA // Стартовый режим WiFi: RTW_MODE_STA_AP, RTW_MODE_AP, RTW_MODE_STA, RTW_MODE_NONE
#define DEF_WIFI_AP_STATIONS 3 // Max number of STAs, should be 1..3, default is 3
#define DEF_WIFI_COUNTRY RTW_COUNTRY_RU // Страна для установки органичений каналов и прочего...
#define DEF_WIFI_TX_PWR RTW_TX_PWR_PERCENTAGE_50 // RTW_TX_PWR_PERCENTAGE_75 // RTW_TX_PWR_PERCENTAGE_100
#define DEF_WIFI_MODE RTW_MODE_STA_AP // Стартовый режим WiFi: RTW_MODE_STA_AP, RTW_MODE_AP, RTW_MODE_STA, RTW_MODE_NONE
#define DEF_WIFI_AP_STATIONS 3 // Max number of STAs, should be 1..3, default is 3
#define DEF_WIFI_COUNTRY RTW_COUNTRY_RU // Регион использования WiFi...
#define DEF_WIFI_TX_PWR RTW_TX_PWR_PERCENTAGE_25 // RTW_TX_PWR_PERCENTAGE_75 // RTW_TX_PWR_PERCENTAGE_100
#define DEF_WIFI_BGN RTW_NETWORK_BGN // rtw_network_mode_t
#define DEF_WIFI_ST_SLEEP 0 // 0 - none, 1 - on
#define DEF_WIFI_ADAPTIVITY RTW_ADAPTIVITY_NORMAL // RTW_ADAPTIVITY_DISABLE/RTW_ADAPTIVITY_NORMAL/RTW_ADAPTIVITY_CARRIER_SENSE
#define DEF_LOAD_CFG ( 0 \
| BID_WIFI_AP_CFG \
| BID_WIFI_ST_CFG \
| BID_AP_DHCP_CFG \
| BID_ST_DHCP_CFG \
)// | BID_WIFI_CFG \
/* Опции загрузки конфигов по старту */
//#define DEF_LOAD_CFG 0 // старт в назначенном режиме по умолчанию
//#define DEF_LOAD_CFG BID_ALL_WIFI_CFG // старт в назначенном общем режиме по умолчанию, с загрузками последних конфигураций ST и AP
#define DEF_LOAD_CFG (BID_ALL_WIFI_CFG | BID_WIFI_CFG) // старт в записанном режиме
#define DEF_SAVE_CFG ( 0 \
| BID_WIFI_AP_CFG \
| BID_WIFI_ST_CFG \
| BID_AP_DHCP_CFG \
| BID_ST_DHCP_CFG \
| BID_WIFI_CFG \
)
/* Опции разрешения записи конфигов по упсешному соединению или выполнению операции установок режимов WiFi без ошибок */
#define DEF_SAVE_CFG (BID_ALL_WIFI_CFG | BID_WIFI_CFG) // сохранение по успешному соединению/выполненю для всех конфигов:
// (для ST или AP пишутся раздельно) с проверкой на изменения
//==== Interface 0 - wlan0 = AP ===========
#define DEF_AP_SSID "RTL871X"
#define DEF_AP_PASSWORD "0123456789"
#define DEF_AP_SECURITY RTW_SECURITY_WPA2_AES_PSK // RTW_SECURITY_OPEN, RTW_SECURITY_WEP_PSK
#define DEF_AP_BEACON 100 // 100...6000 ms
#define DEF_AP_CHANNEL 1 // 1..14
#define DEF_AP_CHANNEL 1 // 1..14
#define DEF_AP_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
/* Варианты типов Security для AP:
RTW_SECURITY_OPEN - Open Security
RTW_SECURITY_WPA_TKIP_PSK - WPA Security
RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher
RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers */
#define DEF_AP_SECURITY RTW_SECURITY_WPA2_AES_PSK // WEP security is NOT IMPLEMENTED. It is NOT SECURE!
#define DEF_AP_BEACON 100 // 100...6000 ms
#define DEF_AP_CHANNEL 1 // 1..14
#define DEF_AP_CHANNEL 1 // 1..14
#define DEF_AP_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
#define DEF_AP_IP IP4ADDR(192,168,4,1)
#define DEF_AP_MSK IP4ADDR(255,255,255,0)
#define DEF_AP_GW IP4ADDR(192,168,4,1)
#define DEF_AP_DHCP_START 2
#define DEF_AP_DHCP_STOP 15
// if not defined DHCP_START && DHCP_STOP -> 2..255
//#define DEF_AP_DHCP_START 2 // DHCP ip start xx.xx.xx.2
//#define DEF_AP_DHCP_STOP 15 // DHCP ip stop xx.xx.xx.15
//==== Interface 1 - wlan1 = STA ==========
#define DEF_ST_SSID "HOMEAP"
#define DEF_ST_PASSWORD "0123456789"
#define DEF_ST_SECURITY RTW_SECURITY_WPA_WPA2_MIXED
#define DEF_ST_SSID "HOMEAP" // Имя SSID AP (роутера) для присоединения по умолчанию (первый старт)
#define DEF_ST_PASSWORD "0123456789" // Пароль AP (роутера) для присоединения по умолчанию (первый старт)
#define DEF_ST_SECURITY RTW_SECURITY_WPA_WPA2_MIXED // Тип Security
#define DEF_ST_BSSID { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } // If bssid set is not ff.ff.ff.ff.ff.ff,
// station will connect to the router with both ssid[] and bssid[] matched.
#define DEF_ST_CHANNEL 1 // 1..14
#define DEF_ST_AUTORECONNECT 3 // 0 - none, 1..254 - count, 255 - all
#define DEF_ST_RECONNECT_PAUSE 1 // 1 sec
#define DEF_ST_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on, =2 Static ip, =3 - auto
#define DEF_ST_USE_BSSID 0 // station will connect to the router with both ssid[] and bssid[] matched.
#define DEF_ST_CHANNEL 1 // 1..14
#define DEF_ST_AUTORECONNECT 1 // 0 - none, 1..254 - count, 255 - all
#define DEF_ST_RECONNECT_PAUSE 1 // 5 sec
#define DEF_ST_SLEEP 3 // 0 - Off, 1 - IPS, 2 - LPS, 3 - IPS/LPS mode
#define DEF_ST_LPS_DTIM 0 // LPS DTIM
#define DEF_ST_DHCP_MODE 1 // =0 dhcp off,
// =1 - dhcp on, - динамический ip
// =2 Static ip, - fixed ip
// =3 - auto fix - старт в режиме "dhcp on", после получения ip - фиксация и переключение в режим рестартов со "Static ip"
#define DEF_ST_IP IP4ADDR(192,168,1,100)
#define DEF_ST_MSK IP4ADDR(255,255,255,0)
#define DEF_ST_GW IP4ADDR(192,168,1,1)
//==== Interface 2 - eth0 =================
#define DEF_EH_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
#define DEF_EH_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
#define DEF_EH_IP IP4ADDR(192,168,7,200)
#define DEF_EH_MSK IP4ADDR(255,255,255,0)
#define DEF_EH_GW IP4ADDR(192,168,7,1)

View file

@ -22,6 +22,7 @@ extern struct netif xnetif[NET_IF_NUM];
//==========================================================
//--- CONSOLE --------------------------
// ATPN=<SSID>[,password[,encryption[,auto reconnect[,reconnect pause]]]: WIFI Connect to AP
LOCAL void fATPN(int argc, char *argv[]){
if(argc > 1) {
@ -35,28 +36,28 @@ LOCAL void fATPN(int argc, char *argv[]){
pswlen = strlen(wifi_st_cfg.password);
strncpy(wifi_st_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
if(pswlen > 7) {
wifi_st_cfg.security_type = RTW_SECURITY_WPA2_AES_PSK;
wifi_st_cfg.security = IDX_SECURITY_WPA2_AES_PSK;
}
else if(!pswlen) {
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
else {
printf("password len < 8!\n");
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
}
else {
// default
wifi_st_cfg.password[0] = 0;
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
if(argc > 3) {
if(pswlen > 7) {
wifi_st_cfg.security_type = idx_to_rtw_security(atoi(argv[3]));
wifi_st_cfg.security = atoi(argv[3]);
}
else {
printf("password len < 8!\n");
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
}
if(argc > 4) {
@ -68,6 +69,9 @@ LOCAL void fATPN(int argc, char *argv[]){
}
else wifi_st_cfg.reconnect_pause = 5;
show_wifi_st_cfg();
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(wifi_run_mode | RTW_MODE_STA);
}
}
@ -85,22 +89,22 @@ LOCAL void fATPA(int argc, char *argv[]){
strncpy(wifi_ap_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
int i = strlen(wifi_ap_cfg.password);
if(i > 7) {
wifi_ap_cfg.security_type = RTW_SECURITY_WPA2_AES_PSK;
wifi_ap_cfg.security = 1; // IDX_SECURITY_WPA2_AES_PSK;
}
else if(i == 0) {
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
else {
printf("password len < 8!\n");
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
}
else {
wifi_ap_cfg.password[0] = 0;
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
if(argc > 3) {
wifi_ap_cfg.security_type = (argv[3][0] == '0')? RTW_SECURITY_OPEN : RTW_SECURITY_WPA2_AES_PSK;
wifi_ap_cfg.security = (argv[3][0] == '0')? 0 : 1; //RTW_SECURITY_OPEN : RTW_SECURITY_WPA2_AES_PSK;
}
if(argc > 4) {
wifi_ap_cfg.channel = atoi(argv[4]);
@ -117,6 +121,9 @@ LOCAL void fATPA(int argc, char *argv[]){
else wifi_ap_cfg.max_sta = 3;
show_wifi_ap_cfg();
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(wifi_run_mode | RTW_MODE_AP);
}
}
@ -126,9 +133,13 @@ LOCAL void fATPA(int argc, char *argv[]){
LOCAL void fATWR(int argc, char *argv[]){
rtw_mode_t mode = RTW_MODE_NONE;
if(argc > 1) mode = atoi(argv[1]);
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(mode);
}
#if CONFIG_WLAN_CONNECT_CB
// Close connections
LOCAL void fATOF(int argc, char *argv[]){
connect_close();
@ -138,8 +149,25 @@ LOCAL void fATOF(int argc, char *argv[]){
LOCAL void fATON(int argc, char *argv[]){
connect_start();
}
#endif
LOCAL void fATWI(int argc, char *argv[]) {
#if 1
if(argc > 2) {
uint8_t c = argv[1][0] | 0x20;
if(c == 's') {
int i = atoi(argv[2]);
printf("Save configs(%d)..\n", i);
write_wifi_cfg(atoi(argv[2]));
}
else if(c == 'l') {
wifi_cfg.load_flg = atoi(argv[2]);
}
else if(c == 'm') {
wifi_cfg.mode = atoi(argv[2]);
}
}
#endif
rtw_wifi_setting_t Setting;
if((wifi_run_mode & RTW_MODE_AP)
&& wifi_get_setting(wlan_ap_name, &Setting) == 0) {
@ -163,22 +191,6 @@ LOCAL void fATWI(int argc, char *argv[]) {
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
show_wifi_st_cfg();
printf("\n");
#if 1
if(argc > 2) {
uint8_t c = argv[1][0] | 0x20;
if(c == 's') {
int i = atoi(argv[2]);
printf("Save configs(%d)..\n", i);
write_wifi_cfg(atoi(argv[2]));
}
else if(c == 'l') {
wifi_cfg.load_flg = atoi(argv[2]);
}
else if(c == 'm') {
wifi_cfg.mode = atoi(argv[2]);
}
}
#endif
}
extern uint8_t rtw_power_percentage_idx;
@ -212,77 +224,100 @@ LOCAL void fATSF(int argc, char *argv[])
printf("\nTSF: %08x%08x\n", (uint32_t)(tsf>>32), (uint32_t)(tsf));
}
LOCAL void fATWP(int argc, char *argv[]) {
if(argc > 1) {
release_wakelock(0xffff);
wifi_set_power_mode(1, 1);
wifi_set_lps_dtim(atoi(argv[1]));
}
else {
unsigned char x;
if(wifi_get_lps_dtim(&x) >= 0) {
printf("DTIM: %d\n", x);
}
}
}
/* -------- WiFi Scan ------------------------------- */
volatile uint8_t scan_end;
/* -------- WiFi Scan ------------------------------- */
LOCAL rtw_result_t _scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
LOCAL void scan_result_handler(internal_scan_handler_t* ap_scan_result)
{
if (malloced_scan_result->scan_complete != RTW_TRUE) {
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
if(scan_end == 1) {
if (ap_scan_result) {
if(ap_scan_result->scan_cnt) {
printf("\nScan networks:\n\n");
printf("N\tType\tMAC\t\t\tSignal\tCh\tWPS\tSecyrity\tSSID\n\n");
};
printf("%d\t", scan_end++);
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
printf("\t%d\t", record->signal_strength);
printf("%d\t", record->channel);
printf("%d\t", record->wps_type);
{
uint8 * s = rtw_security_to_str(record->security);
printf("%s\t", s);
if(strlen(s) < 8) printf("\t");
}
printf("%s\n", record->SSID.val);
for(int i = 0 ; i < ap_scan_result->scan_cnt; i++) {
rtw_scan_result_t* record = &ap_scan_result->ap_details[i];
printf("%d\t", i+1);
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
printf("\t%d\t", record->signal_strength);
printf("%d\t", record->channel);
printf("%d\t", record->wps_type);
{
uint8 * s = rtw_security_to_str(record->security);
printf("%s\t", s);
if(strlen(s) < 8) printf("\t");
}
record->SSID.val[record->SSID.len] = '\0';
printf("%s\n", record->SSID.val);
}
}
} else {
scan_end = 0;
printf("\n");
printf("Scan networks: None!\n");
}
return RTW_SUCCESS;
}
/* -------- WiFi Scan ------------------------------- */
#define scan_channels 14
LOCAL void fATSN(int argc, char *argv[])
{
int i;
u8 *channel_list = (u8*)pvPortMalloc(scan_channels*2);
if(channel_list) {
scan_end = 1;
u8 * pscan_config = &channel_list[scan_channels];
//parse command channel list
for(i = 1; i <= scan_channels; i++){
*(channel_list + i - 1) = i;
*(pscan_config + i - 1) = PSCAN_ENABLE;
};
if(wifi_set_pscan_chan(channel_list, pscan_config, scan_channels) < 0){
printf("ERROR: wifi set partial scan channel fail\n");
} else if(wifi_scan_networks(_scan_result_handler, NULL ) != RTW_SUCCESS){
printf("ERROR: wifi scan failed\n");
} else {
i = 300;
while(i-- && scan_end) {
vTaskDelay(10);
};
};
vPortFree(channel_list);
} else {
printf("ERROR: Can't malloc memory for channel list\n");
};
api_wifi_scan(scan_result_handler);
}
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
extern void cmd_ap_wps(int argc, char **argv);
extern void cmd_wps(int argc, char **argv);
//extern void cmd_wifi_on(int argc, char **argv);
#endif
#if CONFIG_ENABLE_P2P
extern void cmd_wifi_p2p_start(int argc, char **argv);
extern void cmd_wifi_p2p_stop(int argc, char **argv);
extern void cmd_p2p_listen(int argc, char **argv);
extern void cmd_p2p_find(int argc, char **argv);
extern void cmd_p2p_peers(int argc, char **argv);
extern void cmd_p2p_info(int argc, char **argv);
extern void cmd_p2p_disconnect(int argc, char **argv);
extern void cmd_p2p_connect(int argc, char **argv);
extern void cmd_wifi_p2p_auto_go_start(int argc, char **argv);
extern void cmd_p2p_peers(int argc, char **argv);
#endif //CONFIG_ENABLE_P2P
MON_RAM_TAB_SECTION COMMAND_TABLE console_cmd_wifi_api[] = {
{"ATPN", 1, fATPN, "=<SSID>[,password[,encryption[,auto-reconnect[,reconnect pause]]]: WIFI Connect to AP"},
{"ATPA", 1, fATPA, "=<SSID>[,password[,encryption[,channel[,hidden[,max connections]]]]]: Start WIFI AP"},
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
{"WPS_AP", 1, cmd_ap_wps, "=<pbc/pin>[,pin]: WiFi AP WPS"},
{"WPS_ST", 1, cmd_wps, "=<pbc/pin>[,pin]: WiFi Station WPS"},
#endif
#if CONFIG_ENABLE_P2P
{"P2P_START", 0, cmd_wifi_p2p_start, ": p2p start" },
{"P2P_ASTART", 0, cmd_wifi_p2p_auto_go_start, ": p2p auto go start" },
{"P2P_STOP", 0, cmd_wifi_p2p_stop, ": p2p stop"},
{"P2P_PEERS", 0, cmd_p2p_peers, ": p2p peers" },
{"P2P_FIND", 0, cmd_p2p_find, ": p2p find"},
{"P2P_INFO", 0, cmd_p2p_info, ": p2p info"},
{"P2P_DISCCONNECT", 0, cmd_p2p_disconnect, ": p2p disconnect"},
{"P2P_CONNECT", 0, cmd_p2p_connect, ": p2p connect"},
#endif
{"ATWR", 0, fATWR, ": WIFI Connect, Disconnect"},
#if CONFIG_WLAN_CONNECT_CB
{"ATON", 0, fATON, ": Open connections"},
{"ATOF", 0, fATOF, ": Close connections"},
{"ATOFF", 0, fATOF, ": Close connections"},
#endif
{"ATWI", 0, fATWI, ": WiFi Info"},
#if CONFIG_DEBUG_LOG > 3
{"ATWT", 1, fATWT, "=<tx_power>: WiFi tx power: 0 - 100%, 1 - 75%, 2 - 50%, 3 - 25%, 4 - 12.5%"},
{"ATSF", 0, fATSF, ": Test TSF value"},
#endif
{"ATWP", 0, fATWP, ": WiFi power"},
{"ATSN", 0, fATSN, ": Scan networks"}
};