377 lines
9.1 KiB
C
Executable File
377 lines
9.1 KiB
C
Executable File
#include <FreeRTOS.h>
|
|
#include <task.h>
|
|
#include <timers.h>
|
|
#include <semphr.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include "kwrap/spinlock.h"
|
|
#include <kwrap/flag.h>
|
|
#include "kwrap/semaphore.h"
|
|
#include <kwrap/task.h>
|
|
#include "init.h"
|
|
#include "tcpip.h"
|
|
#include "lwip/opt.h"
|
|
#include "lwip/def.h"
|
|
#include "lwip/mem.h"
|
|
#include "lwip/pbuf.h"
|
|
#include "lwip/sys.h"
|
|
#include "lwip/tcpip.h"
|
|
#include "lwip/icmp.h"
|
|
#include "timers.h"
|
|
#include "netif/etharp.h"
|
|
#include "err.h"
|
|
#include "netif/ethernet.h"
|
|
#include <kwrap/examsys.h>
|
|
#include <WiFiIpc/nvtwifi.h>
|
|
#include <WiFiIpc/WiFiIpcAPI.h>
|
|
|
|
typedef struct _usr_ap_settings {
|
|
char ssid[64];
|
|
char security[32];
|
|
char passphrase[NVT_MAX_NETWORK_KEY_LEN + 1];
|
|
} usr_ap_settings;
|
|
|
|
static usr_ap_settings g_usr_ap_settings;
|
|
static int sdio_init = 0;
|
|
int bl602_sdio_init(void)
|
|
{
|
|
extern int wifi_sdio_init(void);
|
|
|
|
if (sdio_init == 0)
|
|
{
|
|
if(wifi_sdio_init()){
|
|
printf("\n\rERROR: wifi sdio init failed!\n");
|
|
return -1;
|
|
}
|
|
sdio_init = 1;
|
|
|
|
extern void vos_task_delay_ms(int);
|
|
vos_task_delay_ms(1000);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
EXAMFUNC_ENTRY(user, argc, argv)
|
|
{
|
|
extern int wifi_sdio_init(void);
|
|
|
|
if (sdio_init == 0)
|
|
{
|
|
if(wifi_sdio_init()){
|
|
printf("\n\rERROR: wifi sdio init failed!\n");
|
|
return -1;
|
|
}
|
|
sdio_init = 1;
|
|
|
|
extern void vos_task_delay_ms(int);
|
|
vos_task_delay_ms(1000);
|
|
}
|
|
|
|
if (argc > 1)
|
|
{
|
|
if (!strcmp(argv[1], "wifi_chanel"))
|
|
{
|
|
if (argc == 3 && atoi(argv[2]) >= 1 && atoi(argv[2]) <= 13)
|
|
{
|
|
extern int wifi_stop_ap(void);
|
|
wifi_stop_ap();
|
|
|
|
vos_task_delay_ms(1000);
|
|
|
|
extern int wifi_start_ap( char *ssid, unsigned int security_type, char *password, int ssid_len,
|
|
int password_len, int channel);
|
|
return wifi_start_ap(g_usr_ap_settings.ssid,
|
|
!strcmp(g_usr_ap_settings.security, "none") ? 0 : (!strcmp(g_usr_ap_settings.security, "wpa-psk-tkip") ? (0x00200000|0x0002) : (0x00400000|0x0004)),
|
|
g_usr_ap_settings.passphrase,
|
|
strlen(g_usr_ap_settings.ssid),
|
|
strlen(g_usr_ap_settings.passphrase),
|
|
atoi(argv[2]));
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("\n\rUsage: user wifi_chanel [channel:1~13]\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
EXAMFUNC_ENTRY(wifi, argc, argv)
|
|
{
|
|
extern int wifi_sdio_init(void);
|
|
|
|
if (sdio_init == 0)
|
|
{
|
|
if(wifi_sdio_init()){
|
|
printf("\n\rERROR: wifi sdio init failed!\n");
|
|
return -1;
|
|
}
|
|
sdio_init = 1;
|
|
|
|
extern void vos_task_delay_ms(int);
|
|
vos_task_delay_ms(1000);
|
|
}
|
|
|
|
if (argc > 1)
|
|
{
|
|
#ifdef TODO_YAN
|
|
if (!strcmp(argv[1], "on"))
|
|
{
|
|
extern int wifi_on(unsigned int on);
|
|
wifi_on(1);
|
|
}
|
|
if (!strcmp(argv[1], "off"))
|
|
{
|
|
extern int wifi_on(unsigned int on);
|
|
wifi_on(0);
|
|
}
|
|
#endif
|
|
if (!strcmp(argv[1], "scan"))
|
|
{
|
|
extern int wifi_scan(void);
|
|
wifi_scan();
|
|
}
|
|
if (!strcmp(argv[1], "sta"))
|
|
{
|
|
extern int wifi_connect(char *ssid, unsigned int security_type, char *password, int ssid_len, int password_len,
|
|
int key_id, void *semaphore);
|
|
if (argc == 4)
|
|
{
|
|
if (!strcmp(argv[2], "join")) //sta join ssid
|
|
{
|
|
wifi_connect(argv[3], 0, "", 0, 0, 0, 0);
|
|
}
|
|
}
|
|
if (argc == 5)
|
|
{
|
|
if (!strcmp(argv[2], "join")) //sta join ssid key
|
|
{
|
|
wifi_connect(argv[3], 0, argv[4], 0, 0, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
else if (!strcmp(argv[1], "ap"))
|
|
{
|
|
extern int wifi_stop_ap(void);
|
|
wifi_stop_ap();
|
|
|
|
vos_task_delay_ms(1000);
|
|
|
|
extern int wifi_start_ap( char *ssid, unsigned int security_type, char *password, int ssid_len,
|
|
int password_len, int channel);
|
|
if (argc == 4) //ap ssid channel
|
|
{
|
|
wifi_start_ap(argv[2], 0, "", strlen(argv[2]), 0, atoi(argv[3]));
|
|
}
|
|
if (argc == 5) //ap ssid channel key
|
|
{
|
|
wifi_start_ap(argv[2], (0x00400000|0x0004), argv[4], strlen(argv[2]), strlen(argv[4]), atoi(argv[3]));
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
printf("\n\r===WIFI Command Lists===\n");
|
|
#ifdef TODO_YAN
|
|
printf("\n\rwifi on\n");
|
|
printf("\n\rwifi off\n");
|
|
#endif
|
|
printf("\n\rwifi scan\n");
|
|
printf("\n\rwifi sta join [ssid]\n");
|
|
printf("\n\rwifi sta join [ssid] [key]\n");
|
|
printf("\n\rwifi ap [ssid] [channel]\n");
|
|
printf("\n\rwifi ap [ssid] [channel] [key]\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Note: iwpriv commands must work with MP driver library! */
|
|
EXAMFUNC_ENTRY(iwpriv, argc, argv)
|
|
{
|
|
extern int wifi_sdio_init(void);
|
|
|
|
if (sdio_init == 0)
|
|
{
|
|
if(wifi_sdio_init()){
|
|
printf("\n\rERROR: wifi sdio init failed!\n");
|
|
return -1;
|
|
}
|
|
sdio_init = 1;
|
|
|
|
extern void vos_task_delay_ms(int);
|
|
vos_task_delay_ms(1000);
|
|
}
|
|
|
|
extern int iwpriv_cmd_hub(int argc, char **argv);
|
|
iwpriv_cmd_hub(argc-1, argv+1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int WiFi_Adaptor_Init (int priority)
|
|
{
|
|
extern int wifi_sdio_init(void);
|
|
if (sdio_init == 0)
|
|
{
|
|
if(wifi_sdio_init()){
|
|
printf("\n\rERROR: wifi sdio init failed!\n");
|
|
return -1;
|
|
}
|
|
sdio_init = 1;
|
|
|
|
extern void vos_task_delay_ms(int);
|
|
vos_task_delay_ms(1000);
|
|
}
|
|
|
|
//bl_wifi_sdio_test(sdio_get_func());
|
|
|
|
extern int wifi_mode_check(void);
|
|
wifi_mode_check();
|
|
|
|
extern void LwIP_Init(void);
|
|
LwIP_Init();
|
|
printf("LwIP_Init() ok\n");
|
|
return 0;
|
|
}
|
|
|
|
int WiFi_Adaptor_Interface_Up (nvt_wifi_settings *pwifi)
|
|
{
|
|
extern int wifi_on(unsigned int);
|
|
if(wifi_on(1) < 0){
|
|
printf("\n\rERROR: Wifi on failed!\n");
|
|
return -1;
|
|
}
|
|
|
|
extern int wifi_disable_powersave(void);
|
|
wifi_disable_powersave();
|
|
extern void vos_task_delay_ms(int ms);
|
|
vos_task_delay_ms(1000);
|
|
|
|
extern int wifi_connect(char *ssid,
|
|
unsigned int security_type,
|
|
char *password,
|
|
int ssid_len,
|
|
int password_len,
|
|
int key_id,
|
|
void *semaphore);
|
|
|
|
return wifi_connect(pwifi->ssid,
|
|
!strcmp(pwifi->security, "none") ? 0 : (!strcmp(pwifi->security, "wpa-psk-tkip") ? (0x00200000|0x0002) : (0x00400000|0x0004)),
|
|
pwifi->passphrase,
|
|
strlen(pwifi->ssid),
|
|
strlen(pwifi->passphrase),
|
|
-1,
|
|
NULL);
|
|
}
|
|
|
|
int WiFi_Adaptor_Interface_Down (const char *pIntfName)
|
|
{
|
|
extern int wifi_off(void);
|
|
return wifi_off();
|
|
}
|
|
|
|
int WiFi_Adaptor_Get_Mac (char *mac)
|
|
{
|
|
extern int wifi_get_mac_address(char * mac);
|
|
return wifi_get_mac_address(mac);
|
|
}
|
|
|
|
int WiFi_Adaptor_Set_Mac (const char *pIntfName, char *mac)
|
|
{
|
|
extern int wifi_set_mac_address(char * mac);
|
|
return wifi_set_mac_address(mac);
|
|
}
|
|
|
|
int WiFi_Adaptor_Register_Sta_Cb (const char *pIntfName, wifi_sta_status_cb_func_t *pFunc)
|
|
{
|
|
|
|
extern void (*Wifi_StationStatus_CB)(char *pIntfName, char *pMacAddr, int status);
|
|
|
|
Wifi_StationStatus_CB = pFunc;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int WiFi_Adaptor_Register_Ap_Cb (const char *pIntfName, wifi_link_status_cb_func_t *pFunc)
|
|
{
|
|
|
|
extern void (*Wifi_Link2APStatus_CB)(char *pIntfName, int status);
|
|
|
|
Wifi_Link2APStatus_CB = pFunc;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int WiFi_Adaptor_Config (nvt_wifi_settings *pwifi)
|
|
{
|
|
int channel;
|
|
char ssid[64];
|
|
char mac[6];
|
|
|
|
extern int wifi_on(unsigned int);
|
|
if(wifi_on(1) < 0){
|
|
printf("\n\rERROR: Wifi on failed!\n");
|
|
return -1;
|
|
}
|
|
|
|
extern int wifi_disable_powersave(void);
|
|
wifi_disable_powersave();
|
|
extern void vos_task_delay_ms(int ms);
|
|
vos_task_delay_ms(1000);
|
|
|
|
channel = pwifi->channel;
|
|
if(channel == 0){
|
|
extern int wifi_get_best_channel(void);
|
|
channel = wifi_get_best_channel();
|
|
}
|
|
|
|
strncpy(ssid, pwifi->ssid, sizeof(ssid)-1);
|
|
if(pwifi->auto_ssid_plus_mac){
|
|
if(WiFiIpc_get_wlan0_efuse_mac(mac))
|
|
printf("fail to get mac\n");
|
|
else
|
|
snprintf(ssid, sizeof(ssid), "%s%02x%02x%02x%02x%02x%02x",
|
|
pwifi->ssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
}
|
|
|
|
strncpy(g_usr_ap_settings.ssid, ssid, sizeof(ssid)-1);
|
|
strncpy(g_usr_ap_settings.security, pwifi->security, sizeof(pwifi->security)-1);
|
|
strncpy(g_usr_ap_settings.passphrase, pwifi->passphrase, sizeof(pwifi->passphrase)-1);
|
|
|
|
extern int wifi_start_ap( char *ssid,
|
|
unsigned int security_type,
|
|
char *password,
|
|
int ssid_len,
|
|
int password_len,
|
|
int channel);
|
|
return wifi_start_ap(ssid,
|
|
!strcmp(pwifi->security, "none") ? 0 : (!strcmp(pwifi->security, "wpa-psk-tkip") ? (0x00200000|0x0002) : (0x00400000|0x0004)),
|
|
pwifi->passphrase,
|
|
strlen(ssid),
|
|
strlen(pwifi->passphrase),
|
|
channel);
|
|
}
|
|
|
|
int WiFi_Adaptor_Start_SiteSurvey(const char *pIntfName, int *pStatus)
|
|
{
|
|
if(pStatus)
|
|
*pStatus = -1;
|
|
printf("WiFi_Adaptor_Start_SiteSurvey() is not implemented\n");
|
|
return -1;
|
|
}
|
|
|
|
int WiFi_Adaptor_Query_SiteSurvey(const char *pIntfName)
|
|
{
|
|
printf("WiFi_Adaptor_Query_SiteSurvey() is not implemented\n");
|
|
return -1;
|
|
}
|
|
|
|
int WiFi_Adaptor_Get_SiteSurvey(const char *pIntfName, NVT_SS_STATUS_Tp pStatus, UINT32 size)
|
|
{
|
|
printf("WiFi_Adaptor_Get_SiteSurvey() is not implemented\n");
|
|
return -1;
|
|
}
|
|
|