mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add wifi_api
This commit is contained in:
parent
1e61910487
commit
affec14b99
27 changed files with 3763 additions and 3052 deletions
|
@ -2112,7 +2112,7 @@ void fATPF(void *arg)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
dhcps_set_addr_pool(1,&start_ip,&end_ip);
|
||||
dhcps_set_addr_pool(&start_ip,&end_ip);
|
||||
|
||||
if(argv[3] != NULL){
|
||||
ip_addr = inet_addr(argv[3]);
|
||||
|
@ -2141,7 +2141,7 @@ exit:
|
|||
if(error_no==0)
|
||||
at_printf("\r\n[ATPF] OK");
|
||||
else
|
||||
at_printf("\r\n[ATPF] ERROR:%d",error_no);
|
||||
at_printf("\r\n[ATPF] ERROR:%d", error_no);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -131,25 +131,25 @@ void LwIP_Init(void)
|
|||
The init function pointer must point to a initialization function for
|
||||
your ethernet netif interface. The following code illustrates it's use.*/
|
||||
//printf("NET_IF_NUM:%d\n\r",NET_IF_NUM);
|
||||
for(idx=NET_IF_NUM - 1;idx>=0;idx--){
|
||||
if(idx==0){
|
||||
for(idx = NET_IF_NUM - 1; idx >= 0 ; idx--) {
|
||||
if(idx == 0){
|
||||
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
}
|
||||
else{
|
||||
#if CONFIG_ETHERNET
|
||||
else if(idx == NET_IF_NUM - 1)
|
||||
{
|
||||
IP4_ADDR(&ipaddr, ETH_IP_ADDR0, ETH_IP_ADDR1, ETH_IP_ADDR2, ETH_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, ETH_NETMASK_ADDR0, ETH_NETMASK_ADDR1 , ETH_NETMASK_ADDR2, ETH_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, ETH_GW_ADDR0, ETH_GW_ADDR1, ETH_GW_ADDR2, ETH_GW_ADDR3);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
IP4_ADDR(&ipaddr, AP_IP_ADDR0, AP_IP_ADDR1, AP_IP_ADDR2, AP_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, AP_NETMASK_ADDR0, AP_NETMASK_ADDR1 , AP_NETMASK_ADDR2, AP_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, AP_GW_ADDR0, AP_GW_ADDR1, AP_GW_ADDR2, AP_GW_ADDR3);
|
||||
}
|
||||
#if CONFIG_ETHERNET
|
||||
if(idx == NET_IF_NUM - 1)
|
||||
{
|
||||
IP4_ADDR(&ipaddr, ETH_IP_ADDR0, ETH_IP_ADDR1, ETH_IP_ADDR2, ETH_IP_ADDR3);
|
||||
IP4_ADDR(&netmask, ETH_NETMASK_ADDR0, ETH_NETMASK_ADDR1 , ETH_NETMASK_ADDR2, ETH_NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, ETH_GW_ADDR0, ETH_GW_ADDR1, ETH_GW_ADDR2, ETH_GW_ADDR3);
|
||||
}
|
||||
#endif
|
||||
xnetif[idx].name[0] = 'r';
|
||||
xnetif[idx].name[1] = '0'+idx;
|
||||
|
||||
|
@ -159,17 +159,16 @@ void LwIP_Init(void)
|
|||
else
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#else
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#endif
|
||||
printf("interface %d is initialized\n", idx);
|
||||
|
||||
info_printf("interface %d is initialized\n", idx);
|
||||
}
|
||||
|
||||
/* Registers the default network interface. */
|
||||
netif_set_default(&xnetif[0]);
|
||||
|
||||
/* When the netif is fully configured this function must be called.*/
|
||||
for(idx = 0;idx < NET_IF_NUM;idx++)
|
||||
for(idx = 0; idx < NET_IF_NUM; idx++)
|
||||
netif_set_up(&xnetif[idx]);
|
||||
|
||||
lwip_init_done = 1;
|
||||
|
|
|
@ -999,7 +999,7 @@ int wifi_on(rtw_mode_t mode) {
|
|||
int wifi_off(void) {
|
||||
// int ret = 0;
|
||||
//pvvx int timeout = 20; // 20 sec ?!
|
||||
int timeout = wifi_test_timeout_ms / 10;
|
||||
uint32 timeout = xTaskGetTickCount();
|
||||
|
||||
if ((rltk_wlan_running(WLAN0_IDX) == 0)
|
||||
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
|
||||
|
@ -1020,18 +1020,15 @@ int wifi_off(void) {
|
|||
while (1) {
|
||||
if ((rltk_wlan_running(WLAN0_IDX) == 0)
|
||||
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
|
||||
info_printf("WIFI deinitialized\n");
|
||||
// info_printf("WIFI deinitialized\n");
|
||||
info_printf("WIFI deinitialized (%d ms)\n", xTaskGetTickCount() - timeout);
|
||||
break;
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
info_printf("ERROR: Deinit WIFI timeout!\n");
|
||||
if(xTaskGetTickCount() - timeout > wifi_test_timeout_ms/portTICK_RATE_MS) {
|
||||
error_printf("WIFI deinitialized timeout!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
vTaskDelay(10 / portTICK_RATE_MS);
|
||||
timeout--;
|
||||
}
|
||||
|
||||
wifi_mode = RTW_MODE_NONE;
|
||||
|
@ -1544,10 +1541,12 @@ int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting) {
|
|||
return ret;
|
||||
}
|
||||
//----------------------------------------------------------------------------//
|
||||
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57 шт
|
||||
int wifi_show_setting(const char *ifname, rtw_wifi_setting_t *pSetting) {
|
||||
int ret = 0;
|
||||
|
||||
printf("\nWIFI %s Setting:\n==============================\n", ifname);
|
||||
printf("\nWIFI '%s' Setting:\n", ifname);
|
||||
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
|
||||
|
||||
switch (pSetting->mode) {
|
||||
case RTW_MODE_AP:
|
||||
|
|
|
@ -94,7 +94,7 @@ static rtw_result_t rtw_indicate_event_handle(int event_cmd, char *buf, int buf_
|
|||
extern gpio_t gpio_led;
|
||||
#endif
|
||||
|
||||
void wifi_indication(WIFI_EVENT_INDICATE event, char *buf, int buf_len,
|
||||
void wifi_indication(WIFI_EVENT_INDICATE event, unsigned char *buf, int buf_len,
|
||||
int flags) {
|
||||
//
|
||||
// If upper layer application triggers additional operations on receiving of wext_wlan_indicate,
|
||||
|
@ -105,7 +105,7 @@ void wifi_indication(WIFI_EVENT_INDICATE event, char *buf, int buf_len,
|
|||
switch (event) {
|
||||
case WIFI_EVENT_DISCONNECT:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: Disconnection indication received\n", __func__);
|
||||
info_printf("%s(%d): Disconnection indication received\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_CONNECT:
|
||||
|
@ -117,25 +117,25 @@ void wifi_indication(WIFI_EVENT_INDICATE event, char *buf, int buf_len,
|
|||
// Sample: return mac address
|
||||
if (buf != NULL && buf_len == 6) {
|
||||
info_printf(
|
||||
"%s: Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
__func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
"%s(%d): Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
__func__, event, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_FOURWAY_HANDSHAKE_DONE:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
if (buf != NULL)
|
||||
info_printf("%s: %s\n", __func__, buf);
|
||||
info_printf("%s(%d): %s\n", __func__, event, buf);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_RESULT_REPORT:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_SCAN_DONE\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_SCAN_DONE\n", __func__, event);
|
||||
//#if CONFIG_DEBUG_LOG > 3
|
||||
// debug_printf("Time at start %d ms.\n", xTaskGetTickCount());
|
||||
//#endif
|
||||
|
@ -143,56 +143,56 @@ void wifi_indication(WIFI_EVENT_INDICATE event, char *buf, int buf_len,
|
|||
break;
|
||||
case WIFI_EVENT_RECONNECTION_FAIL:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: %s\n", __func__, buf);
|
||||
info_printf("%s(%d): %s\n", __func__, event, buf);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_NO_NETWORK:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: %s\n", __func__, buf);
|
||||
info_printf("%s(%d): %s\n", __func__, event, buf);
|
||||
#endif
|
||||
break;
|
||||
#if CONFIG_ENABLE_P2P
|
||||
case WIFI_EVENT_SEND_ACTION_DONE:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: %s\n", __func__);
|
||||
info_printf("%s(%d): %s\n", __func__, event, buf);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_RX_MGNT:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_RX_MGNT\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_RX_MGNT\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
case WIFI_EVENT_STA_ASSOC:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: %s\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_STA_ASSOC\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISASSOC:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: %s\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_STA_DISASSOC\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
#ifdef CONFIG_WPS
|
||||
case WIFI_EVENT_STA_WPS_START:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_STA_WPS_START\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_STA_WPS_START\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_WPS_FINISH:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_WPS_FINISH\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_WPS_FINISH\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_EAPOL_RECVD:
|
||||
#if(WIFI_INDICATE_MSG>0)
|
||||
info_printf("%s: WIFI_EVENT_EAPOL_RECVD\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_EAPOL_RECVD\n", __func__, event);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case WIFI_EVENT_BEACON_AFTER_DHCP:
|
||||
#if(WIFI_INDICATE_MSG>1)
|
||||
info_printf("%s: WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__);
|
||||
info_printf("%s(%d): WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__, event);
|
||||
#endif
|
||||
#if 0 // test beacon
|
||||
gpio_write(&gpio_led, 1);
|
||||
|
|
|
@ -12,7 +12,7 @@ typedef struct
|
|||
} event_list_elem_t;
|
||||
|
||||
void init_event_callback_list(void);
|
||||
extern void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len, int flags);
|
||||
extern void wifi_indication( WIFI_EVENT_INDICATE event, unsigned char *buf, int buf_len, int flags);
|
||||
/** Register the event listener
|
||||
*
|
||||
* @param[in] event_cmds : The event command number indicated
|
||||
|
|
709
RTL00_SDKV35a/component/common/api/wifi_api.c
Normal file
709
RTL00_SDKV35a/component/common/api/wifi_api.c
Normal file
|
@ -0,0 +1,709 @@
|
|||
/*
|
||||
* wifi_api.c
|
||||
*
|
||||
* Created on: 01/11/2017
|
||||
* Author: pvvx
|
||||
*/
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
#include "main.h"
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#error "Udnef CONFIG_EXAMPLE_WLAN_FAST_CONNECT!"
|
||||
#endif
|
||||
#ifndef USE_FLASH_EEP
|
||||
#error "Define USE_FLASH_EEP!"
|
||||
#endif
|
||||
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "flash_api.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include "dhcp/dhcps.h"
|
||||
#include "ethernetif.h"
|
||||
#if CONFIG_ETHERNET
|
||||
#include "ethernet_mii/ethernet_mii.h"
|
||||
#endif
|
||||
|
||||
#include "flash_eep.h"
|
||||
#include "feep_config.h"
|
||||
|
||||
#include "wifi_api.h"
|
||||
#include "wifi_user_set.h"
|
||||
|
||||
//=========================================
|
||||
//--- Wlan Config Init-------------------
|
||||
WIFI_CONFIG wifi_cfg = {
|
||||
.mode = DEF_WIFI_MODE, // rtw_mode_t
|
||||
.sleep = DEF_WIFI_ST_SLEEP,
|
||||
.country_code = DEF_WIFI_COUNTRY,// rtw_country_code_t
|
||||
.tx_pwr = DEF_WIFI_TX_PWR, // rtw_tx_pwr_percentage_t
|
||||
.bgn = DEF_WIFI_BGN, // rtw_network_mode_t
|
||||
.load_flg = DEF_LOAD_CFG,
|
||||
.save_flg = DEF_SAVE_CFG
|
||||
};
|
||||
//---- Interface 0 - wlan0 - AP - init ---
|
||||
SOFTAP_CONFIG wifi_ap_cfg = {
|
||||
.ssid = DEF_AP_SSID,
|
||||
.password = DEF_AP_PASSWORD,
|
||||
.security_type = DEF_AP_SECURITY,
|
||||
.beacon_interval = DEF_AP_BEACON,
|
||||
.channel = DEF_AP_CHANNEL,
|
||||
.ssid_hidden = 0,
|
||||
.max_sta = DEF_WIFI_AP_STATIONS // Max number of STAs, should be 1..3, default is 3
|
||||
};
|
||||
DHCP_CONFIG wifi_ap_dhcp = {
|
||||
.ip = DEF_AP_IP,
|
||||
.mask = DEF_AP_MSK,
|
||||
.gw = DEF_AP_GW,
|
||||
.mode = 2
|
||||
};
|
||||
//---- Interface 1 - wlan1 - ST - init ---
|
||||
STATION_CONFIG wifi_st_cfg = {
|
||||
.ssid = DEF_ST_SSID,
|
||||
.password = DEF_ST_PASSWORD,
|
||||
.bssid = DEF_ST_BSSID,
|
||||
.security_type = DEF_ST_SECURITY,
|
||||
.autoreconnect = DEF_ST_AUTORECONNECT,
|
||||
.reconnect_pause = DEF_ST_RECONNECT_PAUSE
|
||||
};
|
||||
DHCP_CONFIG wifi_st_dhcp = {
|
||||
.ip = DEF_ST_IP,
|
||||
.mask = DEF_ST_MSK,
|
||||
.gw = DEF_ST_GW,
|
||||
.mode = 1
|
||||
};
|
||||
|
||||
rtw_mode_t wifi_run_mode = RTW_MODE_NONE;
|
||||
|
||||
typedef struct _feep_element {
|
||||
uint16 id;
|
||||
uint16 size;
|
||||
void * obj;
|
||||
} FEEP_ELEMENT, *PFEEP_ELEMENT;
|
||||
|
||||
FEEP_ELEMENT feep_tab[] = {
|
||||
{ FEEP_ID_WIFI_AP_CFG, sizeof(wifi_ap_cfg), &wifi_ap_cfg }, // Bit0
|
||||
{ FEEP_ID_WIFI_ST_CFG, sizeof(wifi_st_cfg), &wifi_st_cfg }, // Bit1
|
||||
{ FEEP_ID_AP_DHCP_CFG, sizeof(wifi_ap_dhcp), &wifi_ap_dhcp }, // Bit2
|
||||
{ FEEP_ID_ST_DHCP_CFG, sizeof(wifi_st_dhcp), &wifi_st_dhcp }, // Bit3
|
||||
{ FEEP_ID_WIFI_CFG, sizeof(wifi_cfg), &wifi_cfg }, // Bit4
|
||||
// { FEEP_ID_LWIP_CFG, sizeof(lwip_conn_info), &lwip_conn_info }, // Bit5
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
uint32 read_wifi_cfg(uint32 flg)
|
||||
{
|
||||
uint32 ret = 0;
|
||||
PFEEP_ELEMENT p = feep_tab;
|
||||
for(int m = 1; m && p->id != 0; m <<= 1, p++) {
|
||||
if((flg & m)
|
||||
&& flash_read_cfg(p->obj, p->id, p->size) < p->size) {
|
||||
ret |= m;
|
||||
};
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32 write_wifi_cfg(uint32 flg)
|
||||
{
|
||||
uint32 ret = 0;
|
||||
PFEEP_ELEMENT p = feep_tab;
|
||||
for(int m = 1; m && p->id != 0; m <<= 1, p++) {
|
||||
if((flg & m)
|
||||
&& flash_write_cfg(p->obj, p->id, p->size) < p->size) {
|
||||
ret |= m;
|
||||
};
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
//Function
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int,
|
||||
int);
|
||||
#endif
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
|
||||
_WEAK void connect_start(void)
|
||||
{
|
||||
info_printf("\%s: Time at start %d ms.\n", __func__, xTaskGetTickCount());
|
||||
}
|
||||
|
||||
_WEAK void connect_close(void)
|
||||
{
|
||||
info_printf("\%s: Time at start %d ms.\n", __func__, xTaskGetTickCount());
|
||||
}
|
||||
|
||||
_WEAK void user_start(void)
|
||||
{
|
||||
info_printf("\%s: Time at start %d ms.\n", __func__, xTaskGetTickCount());
|
||||
}
|
||||
|
||||
int wlan_init_done_callback(void) {
|
||||
info_printf("WiFi Init after %d ms\n", xTaskGetTickCount());
|
||||
return 0;
|
||||
}
|
||||
|
||||
//char wlan_st_name[] = WLAN0_NAME;
|
||||
char wlan_st_name[] = WLAN0_NAME;
|
||||
char wlan_ap_name[] = WLAN1_NAME;
|
||||
char wlan_st_netifn = 0;
|
||||
char wlan_ap_netifn = 1;
|
||||
extern rtw_mode_t wifi_mode; // новый режим работы
|
||||
|
||||
uint8 chk_ap_netif_num(void)
|
||||
{
|
||||
if (wifi_mode == RTW_MODE_AP) {
|
||||
wlan_st_name[4] = '1';
|
||||
wlan_ap_name[4] = '0';
|
||||
wlan_st_netifn = 1;
|
||||
wlan_ap_netifn = 0;
|
||||
}
|
||||
else { // if (wifi_mode == RTW_MODE_STA) {
|
||||
wlan_st_name[4] = '0';
|
||||
wlan_ap_name[4] = '1';
|
||||
wlan_st_netifn = 0;
|
||||
wlan_ap_netifn = 1;
|
||||
}
|
||||
return wlan_ap_netifn;
|
||||
}
|
||||
|
||||
rtw_result_t wifi_run_ap(void) {
|
||||
chk_ap_netif_num();
|
||||
|
||||
rtw_result_t ret = RTW_NOTAP;
|
||||
if( (wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP) ){
|
||||
info_printf("Starting AP (%s, netif%d)...\n", wlan_ap_name, wlan_ap_netifn);
|
||||
netif_set_addr(&xnetif[WLAN_AP_NETIF_NUM], &wifi_ap_dhcp.ip,
|
||||
&wifi_ap_dhcp.mask, &wifi_ap_dhcp.gw);
|
||||
if(wext_set_sta_num(wifi_ap_cfg.max_sta) != 0) { // Max number of STAs, should be 1..3, default is 3
|
||||
error_printf("AP not set max connections %d!\n", wifi_ap_cfg.max_sta);
|
||||
};
|
||||
ret = wifi_start_ap(wifi_ap_cfg.ssid, //char *ssid,
|
||||
wifi_ap_cfg.security_type, //rtw_security_t ecurity_type,
|
||||
wifi_ap_cfg.password, //char *password,
|
||||
strlen(wifi_ap_cfg.ssid), //int ssid_len,
|
||||
strlen(wifi_ap_cfg.password), //int password_len,
|
||||
wifi_ap_cfg.channel); //int channel
|
||||
wifi_run_mode |= RTW_MODE_AP;
|
||||
if (ret != RTW_SUCCESS) {
|
||||
error_printf("Error(%d): Start AP failed!\n\n", ret);;
|
||||
} else {
|
||||
int timeout = 10000 / 200;
|
||||
while (1) {
|
||||
char essid[33];
|
||||
if (wext_get_ssid(wlan_ap_name, (unsigned char *) essid) > 0) {
|
||||
if (strcmp((const char * ) essid,
|
||||
(const char * )wifi_ap_cfg.ssid)
|
||||
== 0) {
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetiff->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
dhcps_ip4addr_pool_start = DEF_AP_DHCP_START;
|
||||
dhcps_ip4addr_pool_end = DEF_AP_DHCP_STOP;
|
||||
dhcps_init(&xnetif[WLAN_AP_NETIF_NUM]);
|
||||
info_printf("AP '%s' started after %d ms\n",
|
||||
wifi_ap_cfg.ssid, xTaskGetTickCount());
|
||||
show_wifi_ap_ip();
|
||||
if(wifi_cfg.save_flg & (BID_WIFI_AP_CFG | BID_AP_DHCP_CFG))
|
||||
write_wifi_cfg(wifi_cfg.save_flg & (BID_WIFI_AP_CFG | BID_AP_DHCP_CFG));
|
||||
ret = RTW_SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timeout == 0) {
|
||||
error_printf("Start AP timeout!\n");
|
||||
ret = RTW_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
vTaskDelay(200 / portTICK_RATE_MS);
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
rtw_result_t StartStDHCPClient(void)
|
||||
{
|
||||
debug_printf("Start DHCPClient...\n");
|
||||
int ret = RTW_SUCCESS;
|
||||
struct netif * pnetif = &xnetif[WLAN_ST_NETIF_NUM];
|
||||
DHCP_CONFIG *p = (dhcp_cfg *)&wifi_st_dhcp;
|
||||
unsigned char mode = p->mode;
|
||||
if((mode == 3)
|
||||
&& (p->ip == IP4ADDR(255,255,255,255)
|
||||
|| p->ip == IP4ADDR(0,0,0,0))) {
|
||||
mode = 2;
|
||||
}
|
||||
else mode = 1;
|
||||
if(mode == 2) {
|
||||
netif_set_addr(pnetif, (ip_addr_t *)&p->ip, (ip_addr_t *)&p->mask, (ip_addr_t *)&p->gw);
|
||||
// dhcps_init(pnetif);
|
||||
}
|
||||
else if(mode) {
|
||||
UBaseType_t savePriority = uxTaskPriorityGet(NULL);
|
||||
/* If not rise priority, LwIP DHCP may timeout */
|
||||
vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 3);
|
||||
/* Start DHCP Client */
|
||||
ret = LwIP_DHCP(WLAN_ST_NETIF_NUM, DHCP_START);
|
||||
vTaskPrioritySet(NULL, savePriority);
|
||||
if (ret == DHCP_ADDRESS_ASSIGNED) {
|
||||
p->ip = pnetif->ip_addr.addr;
|
||||
p->gw = pnetif->gw.addr;
|
||||
p->mask = pnetif->netmask.addr;
|
||||
if(p->mode == 3) {
|
||||
p->mode = 2;
|
||||
write_wifi_cfg(BID_ST_DHCP_CFG);
|
||||
}
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
else {
|
||||
debug_printf("LwIP_DHCP ret=%d\n", ret);
|
||||
ret = RTW_ERROR;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
rtw_result_t wifi_run_st(void) {
|
||||
rtw_result_t ret = RTW_SUCCESS;
|
||||
chk_ap_netif_num();
|
||||
if((wifi_mode == RTW_MODE_STA) || (wifi_mode == RTW_MODE_STA_AP)) {
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
// p_wlan_autoreconnect_hdl = NULL;
|
||||
if (wifi_st_cfg.autoreconnect) {
|
||||
ret = wifi_config_autoreconnect(1, wifi_st_cfg.autoreconnect,
|
||||
wifi_st_cfg.reconnect_pause);
|
||||
if (ret != RTW_SUCCESS)
|
||||
warning_printf("ERROR: Operation failed! Error=%d\n", ret);
|
||||
}
|
||||
#endif
|
||||
info_printf("Connected to AP (%s, netif%d)...\n", wlan_st_name, wlan_st_netifn);
|
||||
ret = wifi_connect(wifi_st_cfg.ssid, wifi_st_cfg.security_type,
|
||||
wifi_st_cfg.password, strlen(wifi_st_cfg.ssid),
|
||||
strlen(wifi_st_cfg.password), -1, NULL);
|
||||
wifi_run_mode |= RTW_MODE_STA;
|
||||
if (ret != RTW_SUCCESS) {
|
||||
error_printf("%s: Operation failed! Error(%d)\n", __func__, ret);
|
||||
} else {
|
||||
if(wifi_cfg.save_flg & BID_WIFI_ST_CFG)
|
||||
write_wifi_cfg(BID_WIFI_ST_CFG);
|
||||
// Start DHCPClient
|
||||
ret = StartStDHCPClient();
|
||||
if(ret == RTW_SUCCESS) {
|
||||
show_wifi_st_ip();
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// extern void connect_start(void);
|
||||
connect_start();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _wifi_on(rtw_mode_t mode) {
|
||||
int ret = 0;
|
||||
uint32 timeout = xTaskGetTickCount();
|
||||
uint8 devnum;
|
||||
|
||||
if (rltk_wlan_running(WLAN0_IDX)) {
|
||||
warning_printf("WIFI is already running\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int event_init = 0;
|
||||
if (event_init == 0) {
|
||||
init_event_callback_list();
|
||||
event_init = 1;
|
||||
}
|
||||
wifi_mode = mode;
|
||||
// set wifi mib
|
||||
// adaptivity
|
||||
wext_set_adaptivity(RTW_ADAPTIVITY_DISABLE);
|
||||
info_printf("Initializing WIFI...\n");
|
||||
|
||||
devnum = (mode == RTW_MODE_STA_AP);
|
||||
|
||||
ret = rltk_wlan_init(0, mode);
|
||||
if (ret < 0) return ret;
|
||||
if(devnum) {
|
||||
ret = rltk_wlan_init(1, mode);
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
rltk_wlan_start(0);
|
||||
if(devnum) rltk_wlan_start(1);
|
||||
while (1) {
|
||||
if (rltk_wlan_running(0) &&
|
||||
rltk_wlan_running(devnum) ) {
|
||||
#if CONFIG_DEBUG_LOG > 2
|
||||
printf("WIFI initialized (%d ms)\n", xTaskGetTickCount() - timeout);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if(xTaskGetTickCount() - timeout > wifi_test_timeout_ms/portTICK_RATE_MS) {
|
||||
error_printf("WIFI init timeout!\n");
|
||||
break;
|
||||
}
|
||||
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern int lwip_init_done;
|
||||
|
||||
void _LwIP_Init(void)
|
||||
{
|
||||
int idx;
|
||||
debug_printf("LwIP Init (%d)\n", wifi_mode);
|
||||
/* Create tcp_ip stack thread */
|
||||
tcpip_init( NULL, NULL );
|
||||
|
||||
chk_ap_netif_num(); // Исполняется после _wifi_on()
|
||||
for(int idx = 0; idx < NET_IF_NUM; idx++) {
|
||||
xnetif[idx].name[0] = 'r';
|
||||
xnetif[idx].name[1] = '0' + idx;
|
||||
}
|
||||
netif_add(&xnetif[WLAN_ST_NETIF_NUM], (struct netif *)&wifi_st_dhcp.ip, (struct netif *)&wifi_st_dhcp.mask, (struct netif *)&wifi_st_dhcp.gw, NULL, ðernetif_init, &tcpip_input);
|
||||
netif_add(&xnetif[WLAN_AP_NETIF_NUM], (struct netif *)&wifi_ap_dhcp.ip, (struct netif *)&wifi_ap_dhcp.mask, (struct netif *)&wifi_ap_dhcp.gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#if CONFIG_ETHERNET // && NET_IF_NUM > 2
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
ipaddr.addr = DEF_EH_IP;
|
||||
netmask.addr = DEF_EH_MSK;
|
||||
gw.addr = DEF_EH_GW;
|
||||
netif_add(&xnetif[2], &ipaddr, &netmask, &gw, NULL, ðernetif_mii_init, &tcpip_input);
|
||||
}
|
||||
#endif
|
||||
/* Registers the default network interface. */
|
||||
netif_set_default(&xnetif[0]);
|
||||
/* When the netif is fully configured this function must be called.*/
|
||||
for(idx = 0; idx < NET_IF_NUM; idx++) {
|
||||
netif_set_up(&xnetif[idx]);
|
||||
}
|
||||
info_printf("interface %d is initialized\n", idx);
|
||||
wifi_mode = 0;
|
||||
lwip_init_done = 1;
|
||||
}
|
||||
|
||||
int wifi_run(rtw_mode_t mode) {
|
||||
int ret = 0;
|
||||
#if CONFIG_DEBUG_LOG > 4
|
||||
debug_printf("\n%s(%d), %d\n", __func__, mode, wifi_run_mode);
|
||||
#endif
|
||||
if(wifi_run_mode & RTW_MODE_AP) {
|
||||
info_printf("Deinit old AP...\n");
|
||||
LwIP_DHCP(WLAN_AP_NETIF_NUM, DHCP_STOP);
|
||||
#if CONFIG_DEBUG_LOG > 4
|
||||
debug_printf("dhcps_deinit()\n");
|
||||
#endif
|
||||
dhcps_deinit();
|
||||
wifi_run_mode &= ~RTW_MODE_AP;
|
||||
}
|
||||
if(wifi_run_mode & RTW_MODE_STA) {
|
||||
info_printf("Deinit old ST...\n");
|
||||
LwIP_DHCP(WLAN_ST_NETIF_NUM, DHCP_STOP);
|
||||
wifi_run_mode &= ~RTW_MODE_STA;
|
||||
}
|
||||
// if(mode != wifi_mode)
|
||||
// wifi_mode = mode;
|
||||
// chk_ap_netif_num();
|
||||
if (mode != RTW_MODE_NONE) {
|
||||
if(mode != (volatile)wifi_mode) {
|
||||
info_printf("Deinitializing WIFI ...\n");
|
||||
wifi_off();
|
||||
vTaskDelay(30);
|
||||
debug_printf("WiFi_on(%d)\n", mode);
|
||||
if (_wifi_on(mode) < 0) {
|
||||
error_printf("Wifi On failed!\n");
|
||||
goto error_end;
|
||||
}
|
||||
wifi_mode = mode;
|
||||
};
|
||||
debug_printf("mode == wifi_mode? (%d == %d?)\n", mode, wifi_mode);
|
||||
// if(mode == wifi_mode) {
|
||||
// wifi_set_country(wifi_cfg.country_code);
|
||||
if((wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP)) {
|
||||
wifi_run_ap();
|
||||
}
|
||||
if((wifi_mode == RTW_MODE_STA) || (wifi_mode == RTW_MODE_STA_AP)) {
|
||||
wifi_run_st();
|
||||
}
|
||||
// wifi_config_autoreconnect(1,1,1);
|
||||
#if CONFIG_INTERACTIVE_MODE
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(uart_rx_interrupt_sema);
|
||||
xSemaphoreTake(uart_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
start_interactive_mode();
|
||||
#endif
|
||||
// if(wifi_run_mode == wifi_cfg.mode)
|
||||
ret = 1;
|
||||
// }
|
||||
} else {
|
||||
ret = 1;
|
||||
error_end:
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_close();
|
||||
#endif
|
||||
wifi_off();
|
||||
}
|
||||
chk_ap_netif_num();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wifi_init_thrd(void) {
|
||||
debug_printf("\nLoad Config\n");
|
||||
read_wifi_cfg(DEF_LOAD_CFG);
|
||||
// Call back from wlan driver after wlan init done
|
||||
p_wlan_init_done_callback = wlan_init_done_callback;
|
||||
// Call back from application layer after wifi_connection success
|
||||
// p_write_reconnect_ptr = wlan_write_reconnect_data_to_flash;
|
||||
p_wlan_autoreconnect_hdl = NULL;
|
||||
if (wifi_cfg.mode != RTW_MODE_NONE) {
|
||||
wifi_mode = wifi_cfg.mode;
|
||||
if(!lwip_init_done) {
|
||||
/* Initilaize the LwIP stack */
|
||||
_LwIP_Init();
|
||||
};
|
||||
user_start();
|
||||
#if CONFIG_WIFI_IND_USE_THREAD
|
||||
wifi_manager_init();
|
||||
#endif
|
||||
wifi_run(wifi_cfg.mode);
|
||||
|
||||
// if(wifi_run())
|
||||
}
|
||||
/* Initilaize the console stack */
|
||||
console_init();
|
||||
/* Kill init thread after all init tasks done */
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
rtw_security_t translate_rtw_security(u8 security_type)
|
||||
{
|
||||
rtw_security_t security_mode = RTW_SECURITY_UNKNOWN;
|
||||
|
||||
switch (security_type) {
|
||||
case RTW_ENCRYPTION_OPEN:
|
||||
security_mode = RTW_SECURITY_OPEN;
|
||||
break;
|
||||
case RTW_ENCRYPTION_WEP40:
|
||||
case RTW_ENCRYPTION_WEP104:
|
||||
security_mode = RTW_SECURITY_WEP_PSK;
|
||||
break;
|
||||
case RTW_ENCRYPTION_WPA_TKIP:
|
||||
case RTW_ENCRYPTION_WPA_AES:
|
||||
case RTW_ENCRYPTION_WPA2_TKIP:
|
||||
case RTW_ENCRYPTION_WPA2_AES:
|
||||
case RTW_ENCRYPTION_WPA2_MIXED:
|
||||
security_mode = RTW_SECURITY_WPA2_AES_PSK;
|
||||
break;
|
||||
// case RTW_ENCRYPTION_UNKNOWN:
|
||||
// case RTW_ENCRYPTION_UNDEF:
|
||||
// default:
|
||||
//security_mode = RTW_SECURITY_OPEN;
|
||||
}
|
||||
return security_mode;
|
||||
}
|
||||
|
||||
void show_wifi_ap_ip(void) {
|
||||
printf("SoftAP ip: " IPSTR "\n", IP2STR(&xnetif[WLAN_AP_NETIF_NUM].ip_addr));
|
||||
}
|
||||
void show_wifi_st_ip(void) {
|
||||
printf("Station ip: " IPSTR "\n", IP2STR(&xnetif[WLAN_ST_NETIF_NUM].ip_addr));
|
||||
}
|
||||
|
||||
void show_wifi_st_cfg(void) {
|
||||
printf("\tSSID: '%s'\n", wifi_st_cfg.ssid);
|
||||
printf("\tPassword: '%s'\n", wifi_st_cfg.password);
|
||||
printf("\tSecurity type: %p\n", wifi_st_cfg.security_type);
|
||||
printf("\tAuto-reconnect: %d\n", wifi_st_cfg.autoreconnect);
|
||||
printf("\tReconnect pause: %d\n", wifi_st_cfg.reconnect_pause);
|
||||
}
|
||||
|
||||
void show_wifi_ap_cfg(void) {
|
||||
printf("\tSSID: '%s'\n", wifi_ap_cfg.ssid);
|
||||
printf("\tSSID hidden: %d\n", wifi_ap_cfg.ssid_hidden);
|
||||
printf("\tPassword: '%s'\n", wifi_ap_cfg.password);
|
||||
printf("\tSecurity type: %p\n", wifi_ap_cfg.security_type);
|
||||
printf("\tChannel: %d\n", wifi_ap_cfg.channel);
|
||||
printf("\tBeacon interval: %d ms\n", wifi_ap_cfg.beacon_interval);
|
||||
printf("\tMax connections: %d\n", wifi_ap_cfg.max_sta);
|
||||
}
|
||||
|
||||
void show_wifi_cfg(void) {
|
||||
printf("\tStart mode: %p\n", wifi_cfg.mode);
|
||||
printf("\tCountry code: %d\n", wifi_cfg.country_code);
|
||||
printf("\tSleep mode: %p\n", wifi_cfg.sleep);
|
||||
printf("\tNetwork mode: %d\n", wifi_cfg.bgn);
|
||||
printf("\tTx power: %d\n", wifi_cfg.tx_pwr);
|
||||
printf("\tLoad flags: %p\n", wifi_cfg.load_flg);
|
||||
printf("\tSave flags: %p\n", wifi_cfg.save_flg);
|
||||
}
|
||||
|
||||
//==========================================================
|
||||
//--- CONSOLE --------------------------
|
||||
#include "section_config.h"
|
||||
#include "hal_diag.h"
|
||||
|
||||
// ATPN=<SSID>[,password[,encryption[,auto reconnect[,reconnect pause]]]: WIFI Connect to AP
|
||||
void fATPN(int argc, char *argv[]){
|
||||
if(argc > 1) {
|
||||
if(argv[1][0] == '?') {
|
||||
show_wifi_st_cfg();
|
||||
}
|
||||
else {
|
||||
strncpy(wifi_st_cfg.ssid, argv[1], NDIS_802_11_LENGTH_SSID);
|
||||
if(argc > 2) {
|
||||
strncpy(wifi_st_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
|
||||
int i = strlen(wifi_st_cfg.password);
|
||||
if(i > 7) {
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
else if(!i) {
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else {
|
||||
printf("password len < 8!\n");
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wifi_st_cfg.password[0] = 0;
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
if(argc > 3) {
|
||||
wifi_st_cfg.security_type = translate_rtw_security(atoi(argv[3]));
|
||||
}
|
||||
if(argc > 4) {
|
||||
wifi_st_cfg.autoreconnect = atoi(argv[3]);
|
||||
}
|
||||
else wifi_st_cfg.autoreconnect = 0;
|
||||
if(argc > 5) {
|
||||
wifi_st_cfg.reconnect_pause = atoi(argv[3]);
|
||||
}
|
||||
else wifi_st_cfg.reconnect_pause = 5;
|
||||
show_wifi_st_cfg();
|
||||
wifi_run(wifi_run_mode | RTW_MODE_STA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ATPA=<SSID>[,password[,encryption[,channel[,hidden[,max connections]]]]]: Start WIFI AP
|
||||
void fATPA(int argc, char *argv[]){
|
||||
if(argc > 1) {
|
||||
if(argv[1][0] == '?') {
|
||||
show_wifi_ap_cfg();
|
||||
}
|
||||
else {
|
||||
strncpy(wifi_ap_cfg.ssid, argv[1], NDIS_802_11_LENGTH_SSID);
|
||||
if(argc > 2) {
|
||||
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;
|
||||
}
|
||||
else if(!i) {
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else {
|
||||
printf("password len < 8!\n");
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wifi_ap_cfg.password[0] = 0;
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
if(argc > 3) {
|
||||
wifi_ap_cfg.security_type = translate_rtw_security(atoi(argv[3]));
|
||||
}
|
||||
if(argc > 4) {
|
||||
wifi_ap_cfg.channel = atoi(argv[4]);
|
||||
}
|
||||
// else wifi_ap_cfg.channel = 1;
|
||||
if(argc > 5) {
|
||||
wifi_ap_cfg.ssid_hidden = atoi(argv[5]);
|
||||
}
|
||||
else wifi_ap_cfg.ssid_hidden = 0;
|
||||
|
||||
if(argc > 6) {
|
||||
wifi_ap_cfg.max_sta = atoi(argv[6]);
|
||||
}
|
||||
else wifi_ap_cfg.max_sta = 3;
|
||||
|
||||
show_wifi_ap_cfg();
|
||||
wifi_run(wifi_run_mode | RTW_MODE_AP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WIFI Connect, Disconnect
|
||||
void fATWR(int argc, char *argv[]){
|
||||
rtw_mode_t mode = RTW_MODE_NONE;
|
||||
if(argc) mode = atoi(argv[1]);
|
||||
wifi_run(mode);
|
||||
}
|
||||
|
||||
// Close connections
|
||||
void fATOF(int argc, char *argv[]){
|
||||
connect_close();
|
||||
}
|
||||
|
||||
// Open connections
|
||||
void fATON(int argc, char *argv[]){
|
||||
connect_start();
|
||||
}
|
||||
|
||||
void fATWI(int argc, char *argv[]) {
|
||||
rtw_wifi_setting_t Setting;
|
||||
if((wifi_run_mode & RTW_MODE_AP)
|
||||
&& wifi_get_setting(wlan_ap_name, &Setting) == 0) {
|
||||
wifi_show_setting(wlan_ap_name, &Setting);
|
||||
// show_wifi_ap_ip();
|
||||
printf("\tIP: " IPSTR "\n", IP2STR(&xnetif[WLAN_AP_NETIF_NUM].ip_addr));
|
||||
}
|
||||
if((wifi_run_mode & RTW_MODE_STA)
|
||||
&& wifi_get_setting(wlan_st_name, &Setting) == 0) {
|
||||
wifi_show_setting(wlan_st_name, &Setting);
|
||||
// show_wifi_st_ip();
|
||||
printf("\tIP: " IPSTR "\n", IP2STR(&xnetif[WLAN_ST_NETIF_NUM].ip_addr));
|
||||
}
|
||||
printf("\nWIFI config:\n");
|
||||
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
|
||||
show_wifi_cfg();
|
||||
printf("\nWIFI AP config:\n");
|
||||
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
|
||||
show_wifi_ap_cfg();
|
||||
printf("\nWIFI ST config:\n");
|
||||
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
|
||||
show_wifi_st_cfg();
|
||||
printf("\n");
|
||||
if(argc > 2
|
||||
&& (argv[1][0] == 's'
|
||||
|| argv[1][0] == 'S')) {
|
||||
int i = atoi(argv[2]);
|
||||
printf("Save configs(%d)..\n", i);
|
||||
write_wifi_cfg(atoi(argv[2]));
|
||||
}
|
||||
}
|
||||
|
||||
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"},
|
||||
{"ATWR", 0, fATWR, ": WIFI Connect, Disconnect"},
|
||||
{"ATON", 0, fATON, ": Open connections"},
|
||||
{"ATOF", 0, fATOF, ": Close connections"},
|
||||
{"ATWI", 0, fATWI, ": WiFi Info"}
|
||||
};
|
110
RTL00_SDKV35a/component/common/api/wifi_api.h
Normal file
110
RTL00_SDKV35a/component/common/api/wifi_api.h
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* wifi_user_set.h
|
||||
*
|
||||
* Created on: 01/04/2017
|
||||
* Author: pvvx
|
||||
*/
|
||||
|
||||
#ifndef _WIFI_API_H_
|
||||
#define _WIFI_API_H_
|
||||
|
||||
#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
|
||||
#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
|
||||
#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
|
||||
#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
|
||||
|
||||
#define IPSTR "%d.%d.%d.%d"
|
||||
|
||||
#define IP2STR(ipaddr) \
|
||||
ip4_addr1(ipaddr), \
|
||||
ip4_addr2(ipaddr), \
|
||||
ip4_addr3(ipaddr), \
|
||||
ip4_addr4(ipaddr)
|
||||
|
||||
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57 <20><>
|
||||
|
||||
#define BID_WIFI_AP_CFG (1 << 0)
|
||||
#define BID_WIFI_ST_CFG (1 << 1)
|
||||
#define BID_AP_DHCP_CFG (1 << 2)
|
||||
#define BID_ST_DHCP_CFG (1 << 3)
|
||||
#define BID_WIFI_CFG (1 << 4)
|
||||
|
||||
#define WLAN_ST_NETIF_NUM wlan_st_netifn
|
||||
#define WLAN_AP_NETIF_NUM wlan_ap_netifn
|
||||
//==== FEEP_ID ===========================
|
||||
#define FEEP_ID_WIFI_CFG 0x4347 // id:'GC'
|
||||
#define FEEP_ID_WIFI_AP_CFG 0x5041 // id:'AP'
|
||||
#define FEEP_ID_WIFI_ST_CFG 0x5453 // id:'ST'
|
||||
#define FEEP_ID_AP_DHCP_CFG 0x4144 // id:'DA'
|
||||
#define FEEP_ID_ST_DHCP_CFG 0x5344 // id:'DS'
|
||||
#define FEEP_ID_UART_CFG 0x5530 // id:'0U', type: UART_LOG_CONF
|
||||
#define FEEP_ID_LWIP_CFG 0x4C30 // id:'0L', type: struct atcmd_lwip_conf
|
||||
#define FEEP_ID_DHCP_CFG 0x4430 // id:'0D', type: struct
|
||||
//=========================================
|
||||
#define IW_PASSPHRASE_MAX_SIZE 64
|
||||
#define NDIS_802_11_LENGTH_SSID 32
|
||||
#define IP4ADDR(a,b,c,d) (((unsigned int)((d) & 0xff) << 24) | \
|
||||
((unsigned int)((c) & 0xff) << 16) | \
|
||||
((unsigned int)((b) & 0xff) << 8) | \
|
||||
(unsigned int)((a) & 0xff))
|
||||
//=========================================
|
||||
//--- Wlan Config struct-------------------
|
||||
typedef struct _wifi_config {
|
||||
unsigned char mode; // rtw_mode_t
|
||||
unsigned char sleep;
|
||||
unsigned char country_code; // rtw_country_code_t
|
||||
unsigned char tx_pwr; // rtw_tx_pwr_percentage_t
|
||||
unsigned char bgn; // 802.11 rtw_network_mode_t
|
||||
unsigned char load_flg;
|
||||
unsigned char save_flg;
|
||||
} WIFI_CONFIG, *PWIFI_CONFIG;
|
||||
//---- Interface 0 - wlan0 - AP - struct --
|
||||
typedef struct _softap_config {
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE];
|
||||
rtw_security_t security_type;
|
||||
uint16 beacon_interval; // Note: support 100 ~ 60000 ms, default 100
|
||||
unsigned char channel; // 1..14
|
||||
unsigned char ssid_hidden; // Note: default 0
|
||||
unsigned char max_sta; // 1..3
|
||||
} SOFTAP_CONFIG, *PSOFTAP_CONFIG;
|
||||
//---- Interface 1 - wlan1 - ST - struct -
|
||||
typedef struct _station_config {
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE];
|
||||
rtw_security_t security_type;
|
||||
unsigned char bssid[6]; // Note: If bssid set is not ff.ff.ff.ff.ff.ff,
|
||||
// station will connect to the router with both ssid[] and bssid[] matched.
|
||||
unsigned char autoreconnect; // 0 - none, 1..254 - count, 255 - all
|
||||
unsigned char reconnect_pause; // in sec
|
||||
// rtw_adaptivity_mode_t
|
||||
} STATION_CONFIG, *PSTATION_CONFIG;
|
||||
//--- LwIP Config -------------------------
|
||||
struct lwip_conn_info {
|
||||
int32_t role; //client, server or seed
|
||||
unsigned int protocol; //tcp or udp
|
||||
unsigned int remote_addr; //remote ip
|
||||
unsigned int remote_port; //remote port
|
||||
unsigned int local_addr; //locale ip, not used yet
|
||||
unsigned int local_port; //locale port, not used yet
|
||||
unsigned int reserved; //reserve for further use
|
||||
};
|
||||
//--- DHCP Config -------------------------
|
||||
typedef struct _dhcp_config {
|
||||
unsigned int ip;
|
||||
unsigned int mask;
|
||||
unsigned int gw;
|
||||
unsigned char mode; // =0 dhcp off, =1 - dhcp on, =2 Static ip, =3 - auto
|
||||
} DHCP_CONFIG, *PDHCP_CONFIG;
|
||||
|
||||
void show_wifi_ap_ip(void);
|
||||
void show_wifi_st_ip(void);
|
||||
void show_wifi_cfg(void);
|
||||
void show_wifi_st_cfg(void);
|
||||
void show_wifi_ap_cfg(void);
|
||||
uint32 read_wifi_cfg(uint32 flg);
|
||||
uint32 write_wifi_cfg(uint32 flg);
|
||||
int wifi_run(rtw_mode_t mode);
|
||||
void wifi_init_thrd(void);
|
||||
|
||||
#endif // _WIFI_API_H_
|
Loading…
Add table
Add a link
Reference in a new issue