mirror of
https://github.com/ghsecuritylab/ameba_ws2812b.git
synced 2024-12-25 15:35:19 +00:00
first commit
This commit is contained in:
parent
48de61fed7
commit
28cd8da44d
1181 changed files with 784669 additions and 0 deletions
193
component/common/api/at_cmd/atcmd_google.c
Normal file
193
component/common/api/at_cmd/atcmd_google.c
Normal file
|
@ -0,0 +1,193 @@
|
|||
#include <lwip_netconf.h>
|
||||
#include <stdio.h>
|
||||
#include "log_service.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include "wifi_conf.h"
|
||||
#include "google_nest.h"
|
||||
#include <cJSON.h>
|
||||
|
||||
#define GN_PORT 443
|
||||
|
||||
|
||||
#define _AT_GOOGLE_NEST_ "ATG0"
|
||||
|
||||
//functions that using Google Nest's API
|
||||
void google_data_retrieve_cb(char *response_buf);
|
||||
|
||||
void googlenest_get(char *host_addr, char *host_file)
|
||||
{
|
||||
unsigned char buffer[512];
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_get(&googlenest, googlenest_uri, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nGet data from googlenest: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void google_data_retrieve_cb(char *response_buf) {
|
||||
printf("\r\nResponse_buf:\r\n%s\r\n", response_buf);
|
||||
|
||||
}
|
||||
|
||||
void googlenest_stream(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
google_retrieve_data_hook_callback(google_data_retrieve_cb);
|
||||
gn_stream(&googlenest, googlenest_uri);
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_delete(char *host_addr, char *host_file)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_delete(&googlenest, googlenest_uri) == 0)
|
||||
printf("\r\n\r\nDelete the data is successful!");
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_put(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_put(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nSaving data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_patch(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_patch(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\r\n\r\nUpdating data in firebase is successful!");
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void googlenest_post(char *host_addr, char *host_file, char *data)
|
||||
{
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = host_addr;
|
||||
char *googlenest_uri = host_file;
|
||||
unsigned char buffer[64];
|
||||
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
if(gn_post(&googlenest, googlenest_uri, data, buffer, sizeof(buffer)) == 0)
|
||||
printf("\r\n\r\nInserting data to firebase is successful!\r\n\r\nThe unique name for this list of data is: %s", buffer);
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_googlenest(int argc, char **argv)
|
||||
{
|
||||
if(strcmp(argv[1], "get") == 0) {
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn get address file");
|
||||
else {
|
||||
googlenest_get(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "delete") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn delete address file");
|
||||
else {
|
||||
googlenest_delete(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "put") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn put address file data");
|
||||
else {
|
||||
googlenest_put(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "patch") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn patch address file data");
|
||||
else {
|
||||
googlenest_patch(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "post") ==0){
|
||||
if(argc != 5)
|
||||
printf("\n\rUsage: gn post address file data");
|
||||
else {
|
||||
googlenest_post(argv[2], argv[3], argv[4]);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "stream") ==0){
|
||||
if(argc != 4)
|
||||
printf("\n\rUsage: gn stream address file");
|
||||
else {
|
||||
googlenest_stream(argv[2], argv[3]);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("\n\rUsage: gn method addr file (data)");
|
||||
}
|
||||
|
||||
//AT Command function
|
||||
|
||||
void fATG0(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATG0]: _AT_WLAN_GOOGLENEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATG0]Usage: ATWG=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "gn";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_googlenest(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATG0]Usage: ATG0=[method,address,file,data] or ATG0=[method,address,file]\n\r");
|
||||
}
|
||||
|
||||
log_item_t at_google_items[ ] = {
|
||||
|
||||
{"ATG0", fATG0,}
|
||||
|
||||
};
|
||||
|
||||
void at_google_init(void)
|
||||
{
|
||||
log_service_add_table(at_google_items, sizeof(at_google_items)/sizeof(at_google_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_google_init);
|
512
component/common/api/at_cmd/atcmd_sys.c
Normal file
512
component/common/api/at_cmd/atcmd_sys.c
Normal file
|
@ -0,0 +1,512 @@
|
|||
#include <platform_stdlib.h>
|
||||
#include <platform_opts.h>
|
||||
#include <hal_adc.h>
|
||||
#include <gpio_api.h> // mbed
|
||||
#include <sys_api.h>
|
||||
#include <rtl_lib.h>
|
||||
#include <build_info.h>
|
||||
#include "analogin_api.h"
|
||||
#include "log_service.h"
|
||||
#include "atcmd_sys.h"
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
|
||||
extern u32 ConfigDebugErr;
|
||||
extern u32 ConfigDebugInfo;
|
||||
extern u32 ConfigDebugWarn;
|
||||
extern u32 CmdDumpWord(IN u16 argc, IN u8 *argv[]);
|
||||
extern u32 CmdWriteWord(IN u16 argc, IN u8 *argv[]);
|
||||
|
||||
//-------- AT SYS commands ---------------------------------------------------------------
|
||||
|
||||
void fATSD(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD]: _AT_SYSTEM_DUMP_REGISTER_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_DUMP, AT_DBG_ALWAYS, "[ATSD] Usage: ATSD=REGISTER");
|
||||
return;
|
||||
}
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 2 || argc == 3)
|
||||
CmdDumpWord(argc-1, (unsigned char**)(argv+1));
|
||||
}
|
||||
|
||||
void fATSE(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE]: _AT_SYSTEM_EDIT_REGISTER_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_EDIT, AT_DBG_ALWAYS, "[ATSE] Usage: ATSE=REGISTER[VALUE]");
|
||||
return;
|
||||
}
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3)
|
||||
CmdWriteWord(argc-1, (unsigned char**)(argv+1));
|
||||
}
|
||||
|
||||
#if SUPPORT_MP_MODE
|
||||
void fATSA(void *arg)
|
||||
{
|
||||
u32 tConfigDebugInfo = ConfigDebugInfo;
|
||||
int argc = 0, channel;
|
||||
char *argv[MAX_ARGC] = {0}, *ptmp;
|
||||
u16 offset, gain;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA]: _AT_SYSTEM_ADC_TEST_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_get");
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
|
||||
return;
|
||||
}
|
||||
|
||||
argc = parse_param(arg, argv);
|
||||
if(strcmp(argv[1], "k_get") == 0){
|
||||
sys_adc_calibration(0, &offset, &gain);
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
|
||||
}else if(strcmp(argv[1], "k_set") == 0){
|
||||
if(argc != 4){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=k_set[offet(hex),gain(hex)]");
|
||||
return;
|
||||
}
|
||||
offset = strtoul(argv[2], &ptmp, 16);
|
||||
gain = strtoul(argv[3], &ptmp, 16);
|
||||
sys_adc_calibration(1, &offset, &gain);
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
|
||||
}else{
|
||||
channel = atoi(argv[1]);
|
||||
if(channel < 0 || channel > 2){
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] Usage: ATSA=CHANNEL(0~2)");
|
||||
return;
|
||||
}
|
||||
analogin_t adc;
|
||||
u16 adcdat;
|
||||
|
||||
// Remove debug info massage
|
||||
ConfigDebugInfo = 0;
|
||||
if(channel == 0)
|
||||
analogin_init(&adc, AD_1);
|
||||
else if(channel == 1)
|
||||
analogin_init(&adc, AD_2);
|
||||
else
|
||||
analogin_init(&adc, AD_3);
|
||||
adcdat = analogin_read_u16(&adc)>>4;
|
||||
// Recover debug info massage
|
||||
ConfigDebugInfo = tConfigDebugInfo;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_ADC, AT_DBG_ALWAYS, "[ATSA] A%d = 0x%04X", channel, adcdat);
|
||||
}
|
||||
}
|
||||
|
||||
void fATSG(void *arg)
|
||||
{
|
||||
gpio_t gpio_test;
|
||||
int argc = 0, val;
|
||||
char *argv[MAX_ARGC] = {0}, port, num;
|
||||
PinName pin = NC;
|
||||
u32 tConfigDebugInfo = ConfigDebugInfo;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: _AT_SYSTEM_GPIO_TEST_");
|
||||
if(!arg){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
|
||||
return;
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc != 2){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] Usage: ATSG=PINNAME(ex:A0)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
port = argv[1][0];
|
||||
num = argv[1][1];
|
||||
if(port >= 'a' && port <= 'z')
|
||||
port -= ('a' - 'A');
|
||||
if(num >= 'a' && num <= 'z')
|
||||
num -= ('a' - 'A');
|
||||
switch(port){
|
||||
case 'A':
|
||||
switch(num){
|
||||
case '0': pin = PA_0; break; case '1': pin = PA_1; break; case '2': pin = PA_2; break; case '3': pin = PA_3; break;
|
||||
case '4': pin = PA_4; break; case '5': pin = PA_5; break; case '6': pin = PA_6; break; case '7': pin = PA_7; break;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
switch(num){
|
||||
case '0': pin = PB_0; break; case '1': pin = PB_1; break; case '2': pin = PB_2; break; case '3': pin = PB_3; break;
|
||||
case '4': pin = PB_4; break; case '5': pin = PB_5; break; case '6': pin = PB_6; break; case '7': pin = PB_7; break;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
switch(num){
|
||||
case '0': pin = PC_0; break; case '1': pin = PC_1; break; case '2': pin = PC_2; break; case '3': pin = PC_3; break;
|
||||
case '4': pin = PC_4; break; case '5': pin = PC_5; break; case '6': pin = PC_6; break; case '7': pin = PC_7; break;
|
||||
case '8': pin = PC_8; break; case '9': pin = PC_9; break;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
switch(num){
|
||||
case '0': pin = PD_0; break; case '1': pin = PD_1; break; case '2': pin = PD_2; break; case '3': pin = PD_3; break;
|
||||
case '4': pin = PD_4; break; case '5': pin = PD_5; break; case '6': pin = PD_6; break; case '7': pin = PD_7; break;
|
||||
case '8': pin = PD_8; break; case '9': pin = PD_9; break;
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
switch(num){
|
||||
case '0': pin = PE_0; break; case '1': pin = PE_1; break; case '2': pin = PE_2; break; case '3': pin = PE_3; break;
|
||||
case '4': pin = PE_4; break; case '5': pin = PE_5; break; case '6': pin = PE_6; break; case '7': pin = PE_7; break;
|
||||
case '8': pin = PE_8; break; case '9': pin = PE_9; break; case 'A': pin = PE_A; break;
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
switch(num){
|
||||
case '0': pin = PF_0; break; case '1': pin = PF_1; break; case '2': pin = PF_2; break; case '3': pin = PF_3; break;
|
||||
case '4': pin = PF_4; break; case '5': pin = PF_5; break;
|
||||
}
|
||||
break;
|
||||
case 'G':
|
||||
switch(num){
|
||||
case '0': pin = PG_0; break; case '1': pin = PG_1; break; case '2': pin = PG_2; break; case '3': pin = PG_3; break;
|
||||
case '4': pin = PG_4; break; case '5': pin = PG_5; break; case '6': pin = PG_6; break; case '7': pin = PG_7; break;
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
switch(num){
|
||||
case '0': pin = PH_0; break; case '1': pin = PH_1; break; case '2': pin = PH_2; break; case '3': pin = PH_3; break;
|
||||
case '4': pin = PH_4; break; case '5': pin = PH_5; break; case '6': pin = PH_6; break; case '7': pin = PH_7; break;
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
switch(num){
|
||||
case '0': pin = PI_0; break; case '1': pin = PI_1; break; case '2': pin = PI_2; break; case '3': pin = PI_3; break;
|
||||
case '4': pin = PI_4; break; case '5': pin = PI_5; break; case '6': pin = PI_6; break; case '7': pin = PI_7; break;
|
||||
}
|
||||
break;
|
||||
case 'J':
|
||||
switch(num){
|
||||
case '0': pin = PJ_0; break; case '1': pin = PJ_1; break; case '2': pin = PJ_2; break; case '3': pin = PJ_3; break;
|
||||
case '4': pin = PJ_4; break; case '5': pin = PJ_5; break; case '6': pin = PJ_6; break;
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
switch(num){
|
||||
case '0': pin = PK_0; break; case '1': pin = PK_1; break; case '2': pin = PK_2; break; case '3': pin = PK_3; break;
|
||||
case '4': pin = PK_4; break; case '5': pin = PK_5; break; case '6': pin = PK_6; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(pin == NC){
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG]: Invalid Pin Name");
|
||||
return;
|
||||
}
|
||||
// Remove debug info massage
|
||||
ConfigDebugInfo = 0;
|
||||
// Initial input control pin
|
||||
gpio_init(&gpio_test, pin);
|
||||
gpio_dir(&gpio_test, PIN_INPUT); // Direction: Input
|
||||
gpio_mode(&gpio_test, PullUp); // Pull-High
|
||||
val = gpio_read(&gpio_test);
|
||||
// Recover debug info massage
|
||||
ConfigDebugInfo = tConfigDebugInfo;
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSG] %c%c = %d", port, num, val);
|
||||
}
|
||||
|
||||
void fATSC(void *arg)
|
||||
{
|
||||
AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSC]: _AT_SYSTEM_CLEAR_OTA_SIGNATURE_");
|
||||
sys_clear_ota_signature();
|
||||
}
|
||||
|
||||
void fATSR(void *arg)
|
||||
{
|
||||
AT_DBG_MSG(AT_FLAG_OTA, AT_DBG_ALWAYS, "[ATSR]: _AT_SYSTEM_RECOVER_OTA_SIGNATURE_");
|
||||
sys_recover_ota_signature();
|
||||
}
|
||||
|
||||
void fATSP(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
unsigned long timeout; // ms
|
||||
unsigned long time_begin, time_current;
|
||||
|
||||
gpio_t gpiob_1;
|
||||
int val_old, val_new;
|
||||
|
||||
int expected_zerocount, zerocount;
|
||||
int test_result;
|
||||
|
||||
// parameter check
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: _AT_SYSTEM_POWER_PIN_TEST_");
|
||||
if(!arg) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
} else {
|
||||
argc = parse_param(arg, argv);
|
||||
if (argc < 2) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( strcmp(argv[1], "gpiob1" ) == 0 ) {
|
||||
if (argc < 4) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: Usage: ATSP=gpiob1[timeout,zerocount]");
|
||||
return;
|
||||
}
|
||||
|
||||
// init gpiob1 test
|
||||
test_result = 0;
|
||||
timeout = strtoul(argv[2], NULL, 10);
|
||||
expected_zerocount = atoi(argv[3]);
|
||||
zerocount = 0;
|
||||
val_old = 1;
|
||||
|
||||
sys_log_uart_off();
|
||||
|
||||
gpio_init(&gpiob_1, PB_1);
|
||||
gpio_dir(&gpiob_1, PIN_INPUT);
|
||||
gpio_mode(&gpiob_1, PullDown);
|
||||
|
||||
// gpiob1 test ++
|
||||
time_begin = time_current = xTaskGetTickCount();
|
||||
while (time_current < time_begin + timeout) {
|
||||
val_new = gpio_read(&gpiob_1);
|
||||
|
||||
if (val_new != val_old && val_new == 0) {
|
||||
|
||||
zerocount ++;
|
||||
if (zerocount == expected_zerocount) {
|
||||
test_result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
val_old = val_new;
|
||||
time_current = xTaskGetTickCount();
|
||||
}
|
||||
// gpio test --
|
||||
|
||||
sys_log_uart_on();
|
||||
|
||||
if (test_result == 1) {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: success");
|
||||
} else {
|
||||
AT_DBG_MSG(AT_FLAG_GPIO, AT_DBG_ALWAYS, "[ATSP]: fail, it only got %d zeros", zerocount);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
void fATSL(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
uint32_t lock_id;
|
||||
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL]: _AT_SYS_WAKELOCK_TEST_");
|
||||
|
||||
if (!arg) {
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
return;
|
||||
} else {
|
||||
argc = parse_param(arg, argv);
|
||||
if (argc < 2) {
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch(argv[1][0]) {
|
||||
case 'a': // acquire
|
||||
{
|
||||
if (argc == 3) {
|
||||
lock_id = strtoul(argv[2], NULL, 16);
|
||||
acquire_wakelock(lock_id);
|
||||
}
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
}
|
||||
|
||||
case 'r': // release
|
||||
{
|
||||
if (argc == 3) {
|
||||
lock_id = strtoul(argv[2], NULL, 16);
|
||||
release_wakelock(lock_id);
|
||||
}
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
}
|
||||
|
||||
case '?': // get status
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] wakelock:0x%08x", get_wakelock_status());
|
||||
break;
|
||||
|
||||
default:
|
||||
AT_DBG_MSG(AT_FLAG_OS, AT_DBG_ALWAYS, "[ATSL] Usage ATSL=[a/r/?][bitmask]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATSs(void *arg)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_PRINTK("[ATS@]: _AT_SYSTEM_DBG_SETTING_");
|
||||
if(!arg){
|
||||
AT_PRINTK("[ATS@] Usage: ATS@=[LEVLE,FLAG]");
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3){
|
||||
char *ptmp;
|
||||
gDbgLevel = atoi(argv[1]);
|
||||
gDbgFlag = strtoul(argv[2], &ptmp, 16);
|
||||
}
|
||||
}
|
||||
AT_PRINTK("[ATS@] level = %d, flag = 0x%08X", gDbgLevel, gDbgFlag);
|
||||
}
|
||||
|
||||
void fATSc(void *arg)
|
||||
{
|
||||
int argc = 0, config = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
|
||||
AT_PRINTK("[ATS!]: _AT_SYSTEM_CONFIG_SETTING_");
|
||||
if(!arg){
|
||||
AT_PRINTK("[ATS!] Usage: ATS!=[CONFIG(0,1,2),FLAG]");
|
||||
}else{
|
||||
argc = parse_param(arg, argv);
|
||||
if(argc == 3){
|
||||
char *ptmp;
|
||||
config = atoi(argv[1]);
|
||||
gDbgFlag = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 0)
|
||||
ConfigDebugErr = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 1)
|
||||
ConfigDebugInfo = strtoul(argv[2], &ptmp, 16);
|
||||
if(config == 2)
|
||||
ConfigDebugWarn = strtoul(argv[2], &ptmp, 16);
|
||||
}
|
||||
}
|
||||
AT_PRINTK("[ATS!] ConfigDebugErr = 0x%08X", ConfigDebugErr);
|
||||
AT_PRINTK("[ATS!] ConfigDebugInfo = 0x%08X", ConfigDebugInfo);
|
||||
AT_PRINTK("[ATS!] ConfigDebugWarn = 0x%08X", ConfigDebugWarn);
|
||||
}
|
||||
|
||||
void fATSt(void *arg)
|
||||
{
|
||||
AT_PRINTK("[ATS#]: _AT_SYSTEM_TEST_");
|
||||
}
|
||||
|
||||
void fATSx(void *arg)
|
||||
{
|
||||
AT_PRINTK("[ATS?]: _AT_SYSTEM_HELP_");
|
||||
AT_PRINTK("[ATS?]: COMPILE TIME: %s", RTL8195AFW_COMPILE_TIME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fATGR(void *arg) {
|
||||
|
||||
u32 val;
|
||||
|
||||
printf("=== GPIO_REG_BASE ===\n");
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
gpio_t gpio;
|
||||
|
||||
printf("PA_0\n");
|
||||
|
||||
printf("gpio_init\n");
|
||||
gpio_init(&gpio, PA_0);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_dir PIN_OUTPUT\n");
|
||||
gpio_dir(&gpio, PIN_OUTPUT);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_mode PullNone\n");
|
||||
gpio_mode(&gpio, PullNone);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 1\n");
|
||||
gpio_write(&gpio, 1);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 0\n");
|
||||
gpio_write(&gpio, 0);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
printf("gpio_write 1\n");
|
||||
HAL_WRITE32(GPIO_REG_BASE, GPIO_PORTA_DR, 0x00000001);
|
||||
|
||||
printf("GPIO_PORTA_DR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DR));
|
||||
printf("GPIO_PORTA_DDR = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_DDR));
|
||||
printf("GPIO_PORTA_CTRL = 0x%08x\n", HAL_READ32(GPIO_REG_BASE, GPIO_PORTA_CTRL));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
log_item_t at_sys_items[] = {
|
||||
{"ATSD", fATSD,}, // Dump register
|
||||
{"ATSE", fATSE,}, // Edit register
|
||||
#if SUPPORT_MP_MODE
|
||||
{"ATSA", fATSA,}, // MP ADC test
|
||||
{"ATSG", fATSG,}, // MP GPIO test
|
||||
{"ATSC", fATSC,}, // Clear OTA signature
|
||||
{"ATSR", fATSR,}, // Recover OTA signature
|
||||
{"ATSP", fATSP,}, // MP Power related test
|
||||
#endif
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
{"ATSL", fATSL,}, // wakelock test
|
||||
#endif
|
||||
{"ATS@", fATSs,}, // Debug message setting
|
||||
{"ATS!", fATSc,}, // Debug config setting
|
||||
{"ATS#", fATSt,}, // test command
|
||||
{"ATS?", fATSx,}, // Help
|
||||
|
||||
|
||||
|
||||
{"ATGR", fATGR,}, // gpio register test
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
void at_sys_init(void)
|
||||
{
|
||||
log_service_add_table(at_sys_items, sizeof(at_sys_items)/sizeof(at_sys_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_sys_init);
|
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
5
component/common/api/at_cmd/atcmd_sys.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#ifndef __ATCMD_SYS_H__
|
||||
#define __ATCMD_SYS_H__
|
||||
|
||||
|
||||
#endif
|
979
component/common/api/at_cmd/atcmd_wifi.c
Normal file
979
component/common/api/at_cmd/atcmd_wifi.c
Normal file
|
@ -0,0 +1,979 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "log_service.h"
|
||||
#include "atcmd_wifi.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include "tcpip.h"
|
||||
#include <dhcp/dhcps.h>
|
||||
#include <wlan/wlan_test_inc.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include <wifi/wifi_util.h>
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
/******************************************************************************/
|
||||
#define _AT_WLAN_SET_SSID_ "ATW0"
|
||||
#define _AT_WLAN_SET_PASSPHRASE_ "ATW1"
|
||||
#define _AT_WLAN_SET_KEY_ID_ "ATW2"
|
||||
#define _AT_WLAN_AP_SET_SSID_ "ATW3"
|
||||
#define _AT_WLAN_AP_SET_SEC_KEY_ "ATW4"
|
||||
#define _AT_WLAN_AP_SET_CHANNEL_ "ATW5"
|
||||
#define _AT_WLAN_AP_ACTIVATE_ "ATWA"
|
||||
#define _AT_WLAN_AP_STA_ACTIVATE_ "ATWB"
|
||||
#define _AT_WLAN_JOIN_NET_ "ATWC"
|
||||
#define _AT_WLAN_DISC_NET_ "ATWD"
|
||||
#define _AT_WLAN_WEB_SERVER_ "ATWE"
|
||||
#define _AT_WLAN_PING_TEST_ "ATWI"
|
||||
#define _AT_WLAN_SSL_CLIENT_ "ATWL"
|
||||
#define _AT_WLAN_WIFI_PROMISC_ "ATWM"
|
||||
#define _AT_WLAN_POWER_ "ATWP"
|
||||
#define _AT_WLAN_SIMPLE_CONFIG_ "ATWQ"
|
||||
#define _AT_WLAN_GET_RSSI_ "ATWR"
|
||||
#define _AT_WLAN_SCAN_ "ATWS"
|
||||
#define _AT_WLAN_TCP_TEST_ "ATWT"
|
||||
#define _AT_WLAN_UDP_TEST_ "ATWU"
|
||||
#define _AT_WLAN_WPS_ "ATWW"
|
||||
#define _AT_WLAN_IWPRIV_ "ATWZ"
|
||||
#define _AT_WLAN_INFO_ "ATW?"
|
||||
|
||||
#ifndef CONFIG_SSL_CLIENT
|
||||
#define CONFIG_SSL_CLIENT 0
|
||||
#endif
|
||||
#ifndef CONFIG_WEBSERVER
|
||||
#define CONFIG_WEBSERVER 0
|
||||
#endif
|
||||
#ifndef CONFIG_OTA_UPDATE
|
||||
#define CONFIG_OTA_UPDATE 0
|
||||
#endif
|
||||
#ifndef CONFIG_BSD_TCP
|
||||
#define CONFIG_BSD_TCP 1
|
||||
#endif
|
||||
#ifndef CONFIG_ENABLE_P2P
|
||||
#define CONFIG_ENABLE_P2P 0
|
||||
#endif
|
||||
#define SCAN_WITH_SSID 0
|
||||
#if CONFIG_WEBSERVER
|
||||
#define CONFIG_READ_FLASH 1
|
||||
extern rtw_wifi_setting_t wifi_setting;
|
||||
#endif
|
||||
#if CONFIG_WLAN
|
||||
|
||||
extern void cmd_promisc(int argc, char **argv);
|
||||
extern void cmd_update(int argc, char **argv);
|
||||
extern void cmd_tcp(int argc, char **argv);
|
||||
extern void cmd_udp(int argc, char **argv);
|
||||
extern void cmd_simple_config(int argc, char **argv);
|
||||
#if CONFIG_ENABLE_WPS
|
||||
extern void cmd_wps(int argc, char **argv);
|
||||
#endif
|
||||
extern void cmd_ssl_client(int argc, char **argv);
|
||||
#ifdef CONFIG_WPS_AP
|
||||
extern void cmd_ap_wps(int argc, char **argv);
|
||||
extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
|
||||
#endif //CONFIG_WPS_AP
|
||||
#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);
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
#if CONFIG_LWIP_LAYER
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
#endif
|
||||
static rtw_network_info_t wifi = {0};
|
||||
static rtw_ap_info_t ap = {0};
|
||||
static unsigned char password[65] = {0};
|
||||
static void init_wifi_struct(void)
|
||||
{
|
||||
memset(wifi.ssid.val, 0, sizeof(wifi.ssid.val));
|
||||
memset(wifi.bssid.octet, 0, ETH_ALEN);
|
||||
memset(password, 0, sizeof(password));
|
||||
wifi.ssid.len = 0;
|
||||
wifi.password = NULL;
|
||||
wifi.password_len = 0;
|
||||
wifi.key_id = -1;
|
||||
memset(ap.ssid.val, 0, sizeof(ap.ssid.val));
|
||||
ap.ssid.len = 0;
|
||||
ap.password = NULL;
|
||||
ap.password_len = 0;
|
||||
ap.channel = 1;
|
||||
}
|
||||
|
||||
static void print_scan_result( rtw_scan_result_t* record )
|
||||
{
|
||||
RTW_API_INFO( ( "%s\t ", ( record->bss_type == RTW_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ) );
|
||||
RTW_API_INFO( ( MAC_FMT, MAC_ARG(record->BSSID.octet) ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->signal_strength ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->channel ) );
|
||||
RTW_API_INFO( ( " %d\t ", record->wps_type ) );
|
||||
RTW_API_INFO( ( "%s\t\t ", ( record->security == RTW_SECURITY_OPEN ) ? "Open" :
|
||||
( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" :
|
||||
( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
|
||||
( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
|
||||
( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
|
||||
( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
|
||||
( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
|
||||
"Unknown" ) );
|
||||
|
||||
RTW_API_INFO( ( " %s ", record->SSID.val ) );
|
||||
RTW_API_INFO( ( "\r\n" ) );
|
||||
}
|
||||
|
||||
static rtw_result_t app_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
{
|
||||
static int ApNum = 0;
|
||||
|
||||
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 */
|
||||
|
||||
RTW_API_INFO( ( "%d\t ", ++ApNum ) );
|
||||
|
||||
print_scan_result(record);
|
||||
} else{
|
||||
ApNum = 0;
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
|
||||
void fATW0(void *arg){
|
||||
if(!arg){
|
||||
printf("[ATW0]Usage: ATW0=SSID\n\r");
|
||||
return;
|
||||
}
|
||||
printf("[ATW0]: _AT_WLAN_SET_SSID_ [%s]\n\r", (char*)arg);
|
||||
strcpy((char *)wifi.ssid.val, (char*)arg);
|
||||
wifi.ssid.len = strlen((char*)arg);
|
||||
}
|
||||
|
||||
void fATW1(void *arg){
|
||||
printf("[ATW1]: _AT_WLAN_SET_PASSPHRASE_ [%s]\n\r", (char*)arg);
|
||||
strcpy((char *)password, (char*)arg);
|
||||
wifi.password = password;
|
||||
wifi.password_len = strlen((char*)arg);
|
||||
|
||||
/*
|
||||
* note:rtw_wx_set_passphrase will clear psecuritypriv->wpa_passphrase when len=64
|
||||
* so psk_derive will return because passphrase[0] == 0, then psk_passphrase
|
||||
* will not be set. Here set psk_passphrase64 to make restore_wifi_info_to_flash working
|
||||
*
|
||||
*/
|
||||
extern unsigned char psk_passphrase64[64 + 1];
|
||||
if (wifi.password_len == 64)
|
||||
strcpy(psk_passphrase64, wifi.password);
|
||||
}
|
||||
|
||||
void fATW2(void *arg){
|
||||
printf("[ATW2]: _AT_WLAN_SET_KEY_ID_ [%s]\n\r", (char*)arg);
|
||||
if((strlen((const char *)arg) != 1 ) || (*(char*)arg <'0' ||*(char*)arg >'3')) {
|
||||
printf("\n\rWrong WEP key id. Must be one of 0,1,2, or 3.");
|
||||
return;
|
||||
}
|
||||
wifi.key_id = atoi((const char *)(arg));
|
||||
}
|
||||
|
||||
void fATW3(void *arg){
|
||||
if(!arg){
|
||||
printf("[ATW3]Usage: ATW3=SSID\n\r");
|
||||
return;
|
||||
}
|
||||
|
||||
ap.ssid.len = strlen((char*)arg);
|
||||
|
||||
if(ap.ssid.len > 32){
|
||||
printf("[ATW3]Error: SSID length can't exceed 32\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy((char *)ap.ssid.val, (char*)arg);
|
||||
|
||||
printf("[ATW3]: _AT_WLAN_AP_SET_SSID_ [%s]\n\r", ap.ssid.val);
|
||||
}
|
||||
|
||||
void fATW4(void *arg){
|
||||
strcpy((char *)password, (char*)arg);
|
||||
ap.password = password;
|
||||
ap.password_len = strlen((char*)arg);
|
||||
printf("[ATW4]: _AT_WLAN_AP_SET_SEC_KEY_ [%s]\n\r", ap.password);
|
||||
}
|
||||
|
||||
void fATW5(void *arg){
|
||||
ap.channel = (unsigned char) atoi((const char *)arg);
|
||||
printf("[ATW5]: _AT_WLAN_AP_SET_CHANNEL_ [channel %d]\n\r", ap.channel);
|
||||
}
|
||||
|
||||
void fATW6(void *arg){
|
||||
u32 mac[ETH_ALEN];
|
||||
u32 i;
|
||||
if(!arg){
|
||||
printf("[ATW6]Usage: ATW6=BSSID\n\r");
|
||||
return;
|
||||
}
|
||||
printf("[ATW6]: _AT_WLAN_SET_BSSID_ [%s]\n\r", (char*)arg);
|
||||
sscanf(arg, MAC_FMT, mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5);
|
||||
for(i = 0; i < ETH_ALEN; i ++)
|
||||
wifi.bssid.octet[i] = (u8)mac[i] & 0xFF;
|
||||
}
|
||||
|
||||
void fATWA(void *arg){
|
||||
#if CONFIG_LWIP_LAYER
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
struct netif * pnetif = &xnetif[0];
|
||||
#endif
|
||||
int timeout = 20;
|
||||
printf("[ATWA]: _AT_WLAN_AP_ACTIVATE_\n\r");
|
||||
if(ap.ssid.val[0] == 0){
|
||||
printf("[ATWA]Error: SSID can't be empty\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.password == NULL){
|
||||
ap.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else{
|
||||
ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
|
||||
#if CONFIG_WEBSERVER
|
||||
//store into flash
|
||||
memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));;
|
||||
memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val));
|
||||
wifi_setting.ssid[ap.ssid.len] = '\0';
|
||||
wifi_setting.security_type = ap.security_type;
|
||||
if(ap.security_type !=0)
|
||||
wifi_setting.security_type = 1;
|
||||
else
|
||||
wifi_setting.security_type = 0;
|
||||
if (ap.password)
|
||||
memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password));
|
||||
else
|
||||
memset(wifi_setting.password, 0, sizeof(wifi_setting.password));;
|
||||
wifi_setting.channel = ap.channel;
|
||||
#if CONFIG_READ_FLASH
|
||||
StoreApInfo();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
|
||||
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
|
||||
netif_set_addr(pnetif, &ipaddr, &netmask,&gw);
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetif->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
#endif
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_AP) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
return;
|
||||
}
|
||||
printf("\n\rStarting AP ...");
|
||||
|
||||
#ifdef CONFIG_WPS_AP
|
||||
wpas_wps_dev_config(pnetif->hwaddr, 1);
|
||||
#endif
|
||||
if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
char essid[33];
|
||||
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) {
|
||||
if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
|
||||
printf("\n\r%s started\n", ap.ssid.val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Start AP timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
#if CONFIG_LWIP_LAYER
|
||||
//LwIP_UseStaticIP(pnetif);
|
||||
dhcps_init(pnetif);
|
||||
#endif
|
||||
|
||||
init_wifi_struct( );
|
||||
}
|
||||
void fATWC(void *arg){
|
||||
int mode, ret;
|
||||
unsigned long tick1 = xTaskGetTickCount();
|
||||
unsigned long tick2, tick3;
|
||||
char empty_bssid[6] = {0}, assoc_by_bssid = 0;
|
||||
|
||||
printf("[ATWC]: _AT_WLAN_JOIN_NET_\n\r");
|
||||
if(memcmp (wifi.bssid.octet, empty_bssid, 6))
|
||||
assoc_by_bssid = 1;
|
||||
else if(wifi.ssid.val[0] == 0){
|
||||
printf("[ATWC]Error: SSID can't be empty\n\r");
|
||||
goto EXIT;
|
||||
}
|
||||
if(wifi.password != NULL){
|
||||
if((wifi.key_id >= 0)&&(wifi.key_id <= 3)) {
|
||||
wifi.security_type = RTW_SECURITY_WEP_PSK;
|
||||
}
|
||||
else{
|
||||
wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
}
|
||||
else{
|
||||
wifi.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
//Check if in AP mode
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
if(mode == IW_MODE_MASTER) {
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
#endif
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_STA) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
if(assoc_by_bssid){
|
||||
printf("\n\rJoining BSS by BSSID "MAC_FMT" ...\n\r", MAC_ARG(wifi.bssid.octet));
|
||||
ret = wifi_connect_bssid(wifi.bssid.octet, (char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password,
|
||||
ETH_ALEN, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
|
||||
} else {
|
||||
printf("\n\rJoining BSS by SSID %s...\n\r", (char*)wifi.ssid.val);
|
||||
ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len,
|
||||
wifi.password_len, wifi.key_id, NULL);
|
||||
}
|
||||
|
||||
if(ret!= RTW_SUCCESS){
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
goto EXIT;
|
||||
}
|
||||
tick2 = xTaskGetTickCount();
|
||||
printf("\r\nConnected after %dms.\n", (tick2-tick1));
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Start DHCPClient */
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
tick3 = xTaskGetTickCount();
|
||||
printf("\r\n\nGot IP after %dms.\n", (tick3-tick1));
|
||||
#endif
|
||||
printf("\n\r");
|
||||
EXIT:
|
||||
init_wifi_struct( );
|
||||
}
|
||||
|
||||
void fATWD(void *arg){
|
||||
int timeout = 20;
|
||||
char essid[33];
|
||||
printf("[ATWD]: _AT_WLAN_DISC_NET_\n\r");
|
||||
printf("\n\rDeassociating AP ...");
|
||||
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
|
||||
printf("\n\rWIFI disconnected");
|
||||
return;
|
||||
}
|
||||
|
||||
if(wifi_disconnect() < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) {
|
||||
printf("\n\rWIFI disconnected");
|
||||
break;
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Deassoc timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
printf("\n\r");
|
||||
init_wifi_struct( );
|
||||
}
|
||||
|
||||
void fATWS(void *arg){
|
||||
char buf[32] = {0};
|
||||
u8 *channel_list = NULL;
|
||||
u8 *pscan_config = NULL;
|
||||
int num_channel = 0;
|
||||
int i, argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWS]: _AT_WLAN_SCAN_\n\r");
|
||||
if(arg){
|
||||
strcpy(buf, arg);
|
||||
argc = parse_param(buf, argv);
|
||||
if(argc < 2)
|
||||
goto exit;
|
||||
num_channel = atoi(argv[1]);
|
||||
channel_list = (u8*)malloc(num_channel);
|
||||
if(!channel_list){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for channel list\n\r");
|
||||
goto exit;
|
||||
}
|
||||
pscan_config = (u8*)malloc(num_channel);
|
||||
if(!pscan_config){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for pscan_config\n\r");
|
||||
goto exit;
|
||||
}
|
||||
//parse command channel list
|
||||
for(i = 2; i <= argc -1 ; i++){
|
||||
*(channel_list + i - 2) = (u8)atoi(argv[i]);
|
||||
*(pscan_config + i - 2) = PSCAN_ENABLE;
|
||||
}
|
||||
|
||||
if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){
|
||||
printf("[ATWS]ERROR: wifi set partial scan channel fail\n\r");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if(wifi_scan_networks(app_scan_result_handler, NULL ) != RTW_SUCCESS){
|
||||
printf("[ATWS]ERROR: wifi scan failed\n\r");
|
||||
goto exit;
|
||||
}
|
||||
exit:
|
||||
if(arg && channel_list)
|
||||
free(channel_list);
|
||||
}
|
||||
|
||||
#if SCAN_WITH_SSID
|
||||
void fATWs(void *arg){
|
||||
char buf[32] = {0};
|
||||
u8 *channel_list = NULL;
|
||||
int scan_buf_len = 500;
|
||||
int num_channel = 0;
|
||||
int i, argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_ [%s]\n\r", (char*)wifi.ssid.val);
|
||||
if(arg){
|
||||
strcpy(buf, arg);
|
||||
argc = parse_param(buf, argv);
|
||||
if(argc == 2){
|
||||
scan_buf_len = atoi(argv[1]);
|
||||
}else if(argc > 2){
|
||||
num_channel = atoi(argv[1]);
|
||||
channel_list = (u8*)malloc(num_channel);
|
||||
if(!channel_list){
|
||||
printf("[ATWS]ERROR: Can't malloc memory for channel list\n\r");
|
||||
goto exit;
|
||||
}
|
||||
//parse command channel list
|
||||
for(i = 2; i <= argc -1 ; i++){
|
||||
*(channel_list + i - 2) = (u8)atoi(argv[i]);
|
||||
}
|
||||
|
||||
if(wifi_set_pscan_chan(channel_list, num_channel) < 0){
|
||||
printf("[ATWS]ERROR: wifi set partial scan channel fail\n\r");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
printf("[ATWs]For Scan all channel Usage: ATWs=BUFFER_LENGTH\n\r");
|
||||
printf("[ATWs]For Scan partial channel Usage: ATWs=num_channels[channel_num1, ...]\n\r");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(wifi_scan_networks_with_ssid(NULL, &scan_buf_len, wifi.ssid.val, wifi.ssid.len) != RTW_SUCCESS){
|
||||
printf("[ATWS]ERROR: wifi scan failed\n\r");
|
||||
}
|
||||
exit:
|
||||
if(arg && channel_list)
|
||||
free(channel_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWR(void *arg){
|
||||
int rssi = 0;
|
||||
printf("[ATWR]: _AT_WLAN_GET_RSSI_\n\r");
|
||||
wifi_get_rssi(&rssi);
|
||||
printf("\n\rwifi_get_rssi: rssi = %d", rssi);
|
||||
printf("\n\r");
|
||||
}
|
||||
|
||||
void fATWP(void *arg){
|
||||
unsigned int parm = atoi((const char *)(arg));
|
||||
printf("[ATWP]: _AT_WLAN_POWER_[%s]\n\r", parm?"ON":"OFF");
|
||||
if(parm == 1){
|
||||
if(wifi_on(RTW_MODE_STA)<0){
|
||||
printf("\n\rERROR: Wifi on failed!\n");
|
||||
}
|
||||
}
|
||||
else if(parm == 0)
|
||||
{
|
||||
#if CONFIG_WEBSERVER
|
||||
stop_web_server();
|
||||
#endif
|
||||
wifi_off();
|
||||
}
|
||||
else
|
||||
printf("[ATWP]Usage: ATWP=0/1\n\r");
|
||||
}
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
void fATWB(void *arg)
|
||||
{
|
||||
int timeout = 20;//, mode;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
struct netif * pnetiff = (struct netif *)&xnetif[1];
|
||||
#endif
|
||||
printf("[ATWB](_AT_WLAN_AP_STA_ACTIVATE_)\n\r");
|
||||
if(ap.ssid.val[0] == 0){
|
||||
printf("[ATWB]Error: SSID can't be empty\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.channel > 14){
|
||||
printf("[ATWB]Error:bad channel! channel is from 1 to 14\n\r");
|
||||
return;
|
||||
}
|
||||
if(ap.password == NULL){
|
||||
ap.security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
else{
|
||||
ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
#endif
|
||||
|
||||
wifi_off();
|
||||
vTaskDelay(20);
|
||||
if (wifi_on(RTW_MODE_STA_AP) < 0){
|
||||
printf("\n\rERROR: Wifi on failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n\rStarting AP ...");
|
||||
if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) {
|
||||
printf("\n\rERROR: Operation failed!");
|
||||
return;
|
||||
}
|
||||
while(1) {
|
||||
char essid[33];
|
||||
|
||||
if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
|
||||
if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) {
|
||||
printf("\n\r%s started\n", ap.ssid.val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(timeout == 0) {
|
||||
printf("\n\rERROR: Start AP timeout!");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(1 * configTICK_RATE_HZ);
|
||||
timeout --;
|
||||
}
|
||||
#if CONFIG_LWIP_LAYER
|
||||
LwIP_UseStaticIP(&xnetif[1]);
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetiff->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
dhcps_init(pnetiff);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWI(void *arg){
|
||||
int count, argc = 0;
|
||||
char buf[32] = {0};
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWI]: _AT_WLAN_PING_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWI]Usage: ATWI=xxxx.xxxx.xxxx.xxxx[y/loop]\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy(buf, arg);
|
||||
argv[0] = "ping";
|
||||
argc = parse_param(buf, argv);
|
||||
printf("[ATWI]Target address: %s\n\r", argv[1]);
|
||||
if(argc == 2){
|
||||
printf("[ATWI]Repeat Count: 5\n\r");
|
||||
do_ping_call(argv[1], 0, 5); //Not loop, count=5
|
||||
}else{
|
||||
if(strcmp(argv[2], "loop") == 0){
|
||||
printf("[ATWI]Repeat Count: %s\n\r", "loop");
|
||||
do_ping_call(argv[1], 1, 0); //loop, no count
|
||||
}
|
||||
else{
|
||||
count = atoi(argv[2]);
|
||||
printf("[ATWI]Repeat Count: %d\n\r", count);
|
||||
do_ping_call(argv[1], 0, count); //Not loop, with count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BSD_TCP
|
||||
void fATWT(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWT]: _AT_WLAN_TCP_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWT]Usage: ATWT=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWT=[-s/s] or ATWT=[stop]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "tcp";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_tcp(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATWT]Usage: ATWT=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWT=[-s/s] or ATWT=[stop]\n\r");
|
||||
}
|
||||
|
||||
void fATWU(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWU]: _AT_WLAN_UDP_TEST_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWU]Usage: ATWU=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWU=[-s/s] or ATWU=[stop]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "ucp";
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_udp(argc, argv);
|
||||
}
|
||||
else
|
||||
printf("[ATWU]Usage: ATWU=[-c/c,xxxx.xxxx.xxxx.xxxx,buf_len,count] or ATWU=[-s/s] or ATWU=[stop]\n\r");
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWM(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
argv[0] = "wifi_promisc";
|
||||
printf("[ATWM]: _AT_WLAN_PROMISC_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWM]Usage: ATWM=DURATION_SECONDS[with_len]");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_promisc(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
void fATWL(void *arg){
|
||||
int argc;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWL]: _AT_WLAN_SSL_CLIENT_\n\r");
|
||||
argv[0] = "ssl_client";
|
||||
if(!arg){
|
||||
printf("ATWL=SSL_SERVER_HOST[SRP_USER_NAME,SRP_PASSWORD]\n\r");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_ssl_client(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_WEBSERVER
|
||||
void fATWE(void *arg){
|
||||
printf("[ATWE]: _AT_WLAN_START_WEB_SERVER_\n\r");
|
||||
start_web_server();
|
||||
}
|
||||
#endif
|
||||
|
||||
void fATWQ(void *arg){
|
||||
int argc=0;
|
||||
char *argv[2] = {0};
|
||||
printf("[ATWQ]: _AT_WLAN_SIMPLE_CONFIG_\n\r");
|
||||
argv[argc++] = "wifi_simple_config";
|
||||
if(arg){
|
||||
argv[argc++] = arg;
|
||||
}
|
||||
cmd_simple_config(argc, argv);
|
||||
}
|
||||
#if CONFIG_ENABLE_WPS
|
||||
void fATWW(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWW]: _AT_WLAN_WPS_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWW]Usage: ATWW=pbc/pin\n\r");
|
||||
return;
|
||||
}
|
||||
argv[argc++] = "wifi_wps";
|
||||
argv[argc++] = arg;
|
||||
cmd_wps(argc, argv);
|
||||
}
|
||||
#endif
|
||||
void fATWw(void *arg){
|
||||
#ifdef CONFIG_WPS_AP
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWw]: _AT_WLAN_AP_WPS_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWw]Usage: ATWw=pbc/pin\n\r");
|
||||
return;
|
||||
}
|
||||
argv[argc++] = "wifi_ap_wps";
|
||||
argv[argc++] = arg;
|
||||
cmd_ap_wps(argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_ENABLE_P2P
|
||||
void fATWG(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWa]: _AT_WLAN_P2P_START_\n\r");
|
||||
argv[argc++] = "p2p_start";
|
||||
cmd_wifi_p2p_start(argc, argv);
|
||||
}
|
||||
void fATWH(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWb]: _AT_WLAN_P2P_STOP_\n\r");
|
||||
argv[argc++] = "p2p_stop";
|
||||
cmd_wifi_p2p_stop(argc, argv);
|
||||
}
|
||||
void fATWJ(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWc]: _AT_WLAN_P2P_CONNECT_\n\r");
|
||||
argv[0] = "p2p_connect";
|
||||
if(!arg){
|
||||
printf("ATWc=[DEST_MAC,pbc/pin]\n\r");
|
||||
return;
|
||||
}
|
||||
if((argc = parse_param(arg, argv)) > 1){
|
||||
cmd_p2p_connect(argc, argv);
|
||||
}
|
||||
}
|
||||
void fATWK(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWd]: _AT_WLAN_P2P_DISCONNECT_\n\r");
|
||||
argv[argc++] = "p2p_disconnect";
|
||||
cmd_p2p_disconnect(argc, argv);
|
||||
}
|
||||
void fATWN(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWe]: _AT_WLAN_P2P_INFO_\n\r");
|
||||
argv[argc++] = "p2p_info";
|
||||
cmd_p2p_info(argc, argv);
|
||||
}
|
||||
void fATWF(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[4];
|
||||
printf("[ATWf]: _AT_WLAN_P2P_FIND_\n\r");
|
||||
argv[argc++] = "p2p_find";
|
||||
cmd_p2p_find(argc, argv);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_OTA_UPDATE
|
||||
void fATWO(void *arg){
|
||||
int argc = 0;
|
||||
char *argv[MAX_ARGC] = {0};
|
||||
printf("[ATWO]: _AT_WLAN_OTA_UPDATE_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n\r");
|
||||
return;
|
||||
}
|
||||
argv[0] = "update";
|
||||
if((argc = parse_param(arg, argv)) != 3){
|
||||
printf("[ATWO]Usage: ATWO=IP[PORT] or ATWO= REPOSITORY[FILE_PATH]\n\r");
|
||||
return;
|
||||
}
|
||||
cmd_update(argc, argv);
|
||||
}
|
||||
#endif
|
||||
void fATWx(void *arg){
|
||||
int i = 0;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
u8 *mac = LwIP_GetMAC(&xnetif[0]);
|
||||
u8 *ip = LwIP_GetIP(&xnetif[0]);
|
||||
u8 *gw = LwIP_GetGW(&xnetif[0]);
|
||||
#endif
|
||||
u8 *ifname[2] = {WLAN0_NAME,WLAN1_NAME};
|
||||
rtw_wifi_setting_t setting;
|
||||
printf("[ATW?]: _AT_WLAN_INFO_\n\r");
|
||||
|
||||
for(i=0;i<NET_IF_NUM;i++){
|
||||
if(rltk_wlan_running(i)){
|
||||
#if CONFIG_LWIP_LAYER
|
||||
mac = LwIP_GetMAC(&xnetif[i]);
|
||||
ip = LwIP_GetIP(&xnetif[i]);
|
||||
gw = LwIP_GetGW(&xnetif[i]);
|
||||
#endif
|
||||
printf("\n\r\nWIFI %s Status: Running", ifname[i]);
|
||||
printf("\n\r==============================");
|
||||
|
||||
rltk_wlan_statistic(i);
|
||||
|
||||
wifi_get_setting((const char*)ifname[i],&setting);
|
||||
wifi_show_setting((const char*)ifname[i],&setting);
|
||||
#if CONFIG_LWIP_LAYER
|
||||
printf("\n\rInterface (%s)", ifname[i]);
|
||||
printf("\n\r==============================");
|
||||
printf("\n\r\tMAC => %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ;
|
||||
printf("\n\r\tIP => %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
printf("\n\r\tGW => %d.%d.%d.%d\n\r", gw[0], gw[1], gw[2], gw[3]);
|
||||
#endif
|
||||
if(setting.mode == RTW_MODE_AP || i == 1)
|
||||
{
|
||||
int client_number;
|
||||
struct {
|
||||
int count;
|
||||
rtw_mac_t mac_list[3];
|
||||
} client_info;
|
||||
|
||||
client_info.count = 3;
|
||||
wifi_get_associated_client_list(&client_info, sizeof(client_info));
|
||||
|
||||
printf("\n\rAssociated Client List:");
|
||||
printf("\n\r==============================");
|
||||
|
||||
if(client_info.count == 0)
|
||||
printf("\n\rClient Num: 0\n\r", client_info.count);
|
||||
else
|
||||
{
|
||||
printf("\n\rClient Num: %d", client_info.count);
|
||||
for( client_number=0; client_number < client_info.count; client_number++ )
|
||||
{
|
||||
printf("\n\rClient %d:", client_number + 1);
|
||||
printf("\n\r\tMAC => "MAC_FMT"",
|
||||
MAC_ARG(client_info.mac_list[client_number].octet));
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)
|
||||
{
|
||||
signed char pcWriteBuffer[1024];
|
||||
vTaskList((char*)pcWriteBuffer);
|
||||
printf("\n\rTask List: \n\r%s", pcWriteBuffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void fATWZ(void *arg){
|
||||
char buf[32] = {0};
|
||||
char *copy = buf;
|
||||
int i = 0;
|
||||
int len = 0;
|
||||
printf("[ATWZ]: _AT_WLAN_IWPRIV_\n\r");
|
||||
if(!arg){
|
||||
printf("[ATWZ]Usage: ATWZ=COMMAND[PARAMETERS]\n\r");
|
||||
return;
|
||||
}
|
||||
strcpy(copy, arg);
|
||||
len = strlen(copy);
|
||||
do{
|
||||
if((*(copy+i)=='['))
|
||||
*(copy+i)=' ';
|
||||
if((*(copy+i)==']')||(*(copy+i)=='\0')){
|
||||
*(copy+i)='\0';
|
||||
break;
|
||||
}
|
||||
}while((i++) < len);
|
||||
wext_private_command(WLAN0_NAME, copy, 1);
|
||||
}
|
||||
|
||||
void print_wlan_help(void *arg){
|
||||
printf("\n\rWLAN AT COMMAND SET:");
|
||||
printf("\n\r==============================");
|
||||
printf("\n\r1. Wlan Scan for Network Access Point");
|
||||
printf("\n\r # ATWS");
|
||||
printf("\n\r2. Connect to an AES AP");
|
||||
printf("\n\r # ATW0=SSID");
|
||||
printf("\n\r # ATW1=PASSPHRASE");
|
||||
printf("\n\r # ATWC");
|
||||
printf("\n\r3. Create an AES AP");
|
||||
printf("\n\r # ATW3=SSID");
|
||||
printf("\n\r # ATW4=PASSPHRASE");
|
||||
printf("\n\r # ATW5=CHANNEL");
|
||||
printf("\n\r # ATWA");
|
||||
printf("\n\r4. Ping");
|
||||
printf("\n\r # ATWI=xxx.xxx.xxx.xxx");
|
||||
}
|
||||
|
||||
log_item_t at_wifi_items[ ] = {
|
||||
{"ATW0", fATW0,},
|
||||
{"ATW1", fATW1,},
|
||||
{"ATW2", fATW2,},
|
||||
{"ATW3", fATW3,},
|
||||
{"ATW4", fATW4,},
|
||||
{"ATW5", fATW5,},
|
||||
{"ATW6", fATW6,},
|
||||
{"ATWA", fATWA,},
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
{"ATWB", fATWB,},
|
||||
#endif
|
||||
{"ATWC", fATWC,},
|
||||
{"ATWD", fATWD,},
|
||||
{"ATWP", fATWP,},
|
||||
{"ATWR", fATWR,},
|
||||
{"ATWS", fATWS,},
|
||||
#if SCAN_WITH_SSID
|
||||
{"ATWs", fATWs,},
|
||||
#endif
|
||||
{"ATWM", fATWM,},
|
||||
{"ATWZ", fATWZ,},
|
||||
#if CONFIG_OTA_UPDATE
|
||||
{"ATWO", fATWO,},
|
||||
#endif
|
||||
#if CONFIG_WEBSERVER
|
||||
{"ATWE", fATWE,},
|
||||
#endif
|
||||
#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
|
||||
{"ATWQ", fATWQ,},
|
||||
#endif
|
||||
#ifdef CONFIG_WPS
|
||||
#if CONFIG_ENABLE_WPS
|
||||
{"ATWW", fATWW,},
|
||||
#endif
|
||||
{"ATWw", fATWw,}, //wps registrar for softap
|
||||
#if CONFIG_ENABLE_P2P
|
||||
{"ATWG", fATWG,}, //p2p start
|
||||
{"ATWH", fATWH,}, //p2p stop
|
||||
{"ATWJ", fATWJ,}, //p2p connect
|
||||
{"ATWK", fATWK,}, //p2p disconnect
|
||||
{"ATWN", fATWN,}, //p2p info
|
||||
{"ATWF", fATWF,}, //p2p find
|
||||
#endif
|
||||
#endif
|
||||
#if CONFIG_SSL_CLIENT
|
||||
{"ATWL", fATWL,},
|
||||
#endif
|
||||
#if CONFIG_LWIP_LAYER
|
||||
{"ATWI", fATWI,},
|
||||
#if CONFIG_BSD_TCP
|
||||
{"ATWT", fATWT,},
|
||||
{"ATWU", fATWU,},
|
||||
#endif
|
||||
#endif
|
||||
{"ATW?", fATWx,},
|
||||
{"ATW+ABC", fATWx,}
|
||||
};
|
||||
|
||||
void at_wifi_init(void)
|
||||
{
|
||||
init_wifi_struct();
|
||||
log_service_add_table(at_wifi_items, sizeof(at_wifi_items)/sizeof(at_wifi_items[0]));
|
||||
}
|
||||
|
||||
log_module_init(at_wifi_init);
|
||||
|
||||
#endif // end of #if CONFIG_WLAN
|
||||
#endif //end of #if SUPPORT_LOG_SERVICE
|
67
component/common/api/at_cmd/atcmd_wifi.h
Normal file
67
component/common/api/at_cmd/atcmd_wifi.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef __ATCMD_WIFI_H__
|
||||
#define __ATCMD_WIFI_H__
|
||||
#include "main.h"
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
/* Give default value if not defined */
|
||||
#ifndef NET_IF_NUM
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#define NET_IF_NUM 2
|
||||
#else
|
||||
#define NET_IF_NUM 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef IP_ADDR0
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef NETMASK_ADDR0
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef GW_ADDR0
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef AP_IP_ADDR0
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef AP_NETMASK_ADDR0
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef AP_GW_ADDR0
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
#endif
|
323
component/common/api/at_cmd/log_service.c
Normal file
323
component/common/api/at_cmd/log_service.c
Normal file
|
@ -0,0 +1,323 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "FreeRTOS.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "log_service.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "main.h"
|
||||
#include "wifi_util.h"
|
||||
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
//======================================================
|
||||
struct list_head log_hash[ATC_INDEX_NUM];
|
||||
|
||||
extern void at_wifi_init(void);
|
||||
extern void at_fs_init(void);
|
||||
extern void at_sys_init(void);
|
||||
//extern void at_app_init(void);
|
||||
char log_buf[LOG_SERVICE_BUFLEN];
|
||||
#if CONFIG_LOG_HISTORY
|
||||
char log_history[LOG_HISTORY_LEN][LOG_SERVICE_BUFLEN];
|
||||
static unsigned int log_history_count = 0;
|
||||
#endif
|
||||
xSemaphoreHandle log_rx_interrupt_sema = NULL;
|
||||
extern xSemaphoreHandle uart_rx_interrupt_sema;
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
#pragma section=".data.log_init"
|
||||
|
||||
unsigned int __log_init_begin__;
|
||||
unsigned int __log_init_end__;
|
||||
#elif defined ( __CC_ARM )
|
||||
//#pragma section=".data.log_init"
|
||||
log_init_t* __log_init_begin__;
|
||||
log_init_t* __log_init_end__;
|
||||
log_init_t log_init_table[] = {
|
||||
at_wifi_init,
|
||||
at_fs_init,
|
||||
at_sys_init
|
||||
// at_app_init
|
||||
};
|
||||
#else
|
||||
#error "not implement, add to linker script"
|
||||
extern unsigned int __log_init_begin__;
|
||||
extern unsigned int __log_init_end__;
|
||||
#endif
|
||||
|
||||
//======================================================
|
||||
int hash_index(char *str)
|
||||
{
|
||||
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
|
||||
unsigned int hash = 0;
|
||||
|
||||
while (*str)
|
||||
{
|
||||
hash = hash * seed + (*str++);
|
||||
}
|
||||
|
||||
return (hash & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void log_add_new_command(log_item_t *new)
|
||||
{
|
||||
int index = hash_index(new->log_cmd)%ATC_INDEX_NUM;
|
||||
|
||||
list_add(&new->node, &log_hash[index]);
|
||||
}
|
||||
void start_log_service(void);
|
||||
void log_service_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
log_init_t *log_init_table;
|
||||
__log_init_begin__ = (unsigned int)__section_begin(".data.log_init");
|
||||
__log_init_end__ = (unsigned int)__section_end(".data.log_init");
|
||||
log_init_table = (log_init_t *)__log_init_begin__;
|
||||
#elif defined(__CC_ARM)
|
||||
__log_init_begin__ = log_init_table;
|
||||
__log_init_end__ = log_init_table + sizeof(log_init_table);
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
|
||||
for(i=0;i<ATC_INDEX_NUM;i++)
|
||||
INIT_LIST_HEAD(&log_hash[i]);
|
||||
|
||||
for(i=0;i<(__log_init_end__-__log_init_begin__)/sizeof(log_init_t); i++)
|
||||
log_init_table[i]();
|
||||
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(log_rx_interrupt_sema);
|
||||
xSemaphoreTake(log_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
start_log_service();
|
||||
}
|
||||
|
||||
//sizeof(log_items)/sizeof(log_items[0])
|
||||
void log_service_add_table(log_item_t *tbl, int len)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<len;i++)
|
||||
log_add_new_command(&tbl[i]);
|
||||
}
|
||||
|
||||
void* log_action(char *cmd)
|
||||
{
|
||||
int search_cnt=0;
|
||||
int index = hash_index(cmd)%ATC_INDEX_NUM;
|
||||
struct list_head *head = &log_hash[index];
|
||||
struct list_head *iterator;
|
||||
log_item_t *item;
|
||||
void *act = NULL;
|
||||
|
||||
list_for_each(iterator, head) {
|
||||
item = list_entry(iterator, log_item_t, node);
|
||||
search_cnt++;
|
||||
if( strcmp(item->log_cmd, cmd) == 0){
|
||||
//printf("%s match %s, search cnt %d\n\r", cmd, item->log_cmd, search_cnt);
|
||||
act = (void*)item->at_act;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
void* log_handler(char *cmd)
|
||||
{
|
||||
log_act_t action=NULL;
|
||||
char buf[100] = {0};
|
||||
char *copy=buf;
|
||||
char *token = NULL;
|
||||
char *param = NULL;
|
||||
char tok[5] = {0};//'\0'
|
||||
#if CONFIG_LOG_HISTORY
|
||||
strcpy(log_history[((log_history_count++)%LOG_HISTORY_LEN)], log_buf);
|
||||
#endif
|
||||
strcpy(copy, cmd);
|
||||
//token = _strsep(©, "=");
|
||||
token = strtok(copy, "=");
|
||||
if(token && (strlen(token) <= 4))
|
||||
strcpy(tok, token);
|
||||
else{
|
||||
//printf("\n\rAT Cmd format error!\n");
|
||||
return NULL;
|
||||
};
|
||||
//printf(" Command %s \n\r ", tok);
|
||||
param = strtok(NULL, NULL);
|
||||
//printf(" Param %s \n\r", param);
|
||||
action = (log_act_t)log_action(tok);
|
||||
|
||||
if(action){
|
||||
action(param);
|
||||
}
|
||||
return (void*)action;
|
||||
|
||||
}
|
||||
|
||||
int parse_param(char *buf, char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
while((argc < MAX_ARGC) && (*buf != '\0')) {
|
||||
while((*buf == '[')||(*buf == ' '))
|
||||
buf ++;
|
||||
if((*buf == ']')||(*buf == '\0'))
|
||||
break;
|
||||
argv[argc] = buf;
|
||||
argc ++;
|
||||
buf ++;
|
||||
|
||||
while((*buf != ',')&&(*buf != '[')&&(*buf != ']')&&(*buf != '\0'))
|
||||
buf ++;
|
||||
|
||||
while((*buf == ',')||(*buf == '[')||(*buf == ']')) {
|
||||
*buf = '\0';
|
||||
buf ++;
|
||||
}
|
||||
}
|
||||
return argc;
|
||||
}
|
||||
|
||||
void at_set_debug_level(unsigned char newDbgLevel)
|
||||
{
|
||||
gDbgLevel = newDbgLevel;
|
||||
}
|
||||
|
||||
void at_set_debug_mask(unsigned int newDbgFlag)
|
||||
{
|
||||
gDbgFlag = newDbgFlag;
|
||||
}
|
||||
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
extern char uart_buf[64];
|
||||
void legency_interactive_handler(unsigned char argc, unsigned char **argv)
|
||||
{
|
||||
#if 0 //defined(CONFIG_PLATFORM_8195A)
|
||||
if(argc<1)
|
||||
{
|
||||
DiagPrintf("Wrong argument number!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DiagPrintf("Wlan Normal Mode\n");
|
||||
|
||||
WlanNormal( argc, argv);
|
||||
#else
|
||||
strncpy(uart_buf, log_buf, 63);//uart_buf[64]
|
||||
xSemaphoreGive(uart_rx_interrupt_sema);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
#ifndef WLAN1_NAME
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#endif
|
||||
int mp_commnad_handler(char *cmd)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char *token = NULL;
|
||||
|
||||
strcpy(buf, cmd);
|
||||
token = strtok(buf, " ");
|
||||
if(token && (strcmp(buf, "iwpriv") == 0)){
|
||||
token = strtok(NULL, "");
|
||||
wext_private_command(WLAN0_NAME, token, 1);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
void print_help_msg(void){
|
||||
#if CONFIG_WLAN
|
||||
extern void print_wlan_help(void);
|
||||
print_wlan_help();
|
||||
#endif
|
||||
//add other help message print here
|
||||
}
|
||||
|
||||
int print_help_handler(char *cmd){
|
||||
if(strcmp(cmd, "help") == 0){
|
||||
print_help_msg();
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void log_service(void *param)
|
||||
{
|
||||
printf("\n\rStart LOG SERVICE MODE\n\r");
|
||||
printf("\n\r# ");
|
||||
while(1){
|
||||
while(xSemaphoreTake(log_rx_interrupt_sema, portMAX_DELAY) != pdTRUE);
|
||||
if(log_handler((char *)log_buf) == NULL){
|
||||
#if CONFIG_WLAN
|
||||
if(mp_commnad_handler((char *)log_buf) < 0)
|
||||
#endif
|
||||
{
|
||||
#if SUPPORT_INTERACTIVE_MODE
|
||||
print_help_handler((char *)log_buf);
|
||||
legency_interactive_handler(NULL, NULL);
|
||||
continue;
|
||||
#else
|
||||
if(print_help_handler((char *)log_buf) < 0){
|
||||
printf("\n\runknown command '%s'", log_buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
log_buf[0] = '\0';
|
||||
printf("\n\r[MEM] After do cmd, available heap %d\n\r", xPortGetFreeHeapSize());
|
||||
printf("\r\n\n# ");
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
release_wakelock(WAKELOCK_LOGUART);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#define STACKSIZE 1280
|
||||
void start_log_service(void)
|
||||
{
|
||||
if(xTaskCreate(log_service, (char const*)"log_service", STACKSIZE, NULL, tskIDLE_PRIORITY + 5, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed", __FUNCTION__);
|
||||
}
|
||||
void fAT_exit(void *arg){
|
||||
printf("\n\rLeave LOG SERVICE");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
#if CONFIG_LOG_HISTORY
|
||||
void fAT_log(void *arg){
|
||||
int i = 0;
|
||||
printf("[AT]log history:\n\n\r");
|
||||
if(log_history_count > LOG_HISTORY_LEN){
|
||||
for(i=0; i<4; i++)
|
||||
printf(" %s\n\r", log_history[((log_history_count+i)%LOG_HISTORY_LEN)]);
|
||||
}
|
||||
else{
|
||||
for(i=0; i<(log_history_count-1); i++)
|
||||
printf(" %s\n\r", log_history[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
log_item_t at_log_items[ ] = {
|
||||
{"AT--", fAT_exit,},
|
||||
#if CONFIG_LOG_HISTORY
|
||||
{"AT??", fAT_log,},
|
||||
#endif
|
||||
{"ATxx", fAT_exit,}
|
||||
};
|
||||
void at_log_init(void)
|
||||
{
|
||||
log_service_add_table(at_log_items, sizeof(at_log_items)/sizeof(at_log_items[0]));
|
||||
}
|
||||
log_module_init(at_log_init);
|
||||
#endif
|
95
component/common/api/at_cmd/log_service.h
Normal file
95
component/common/api/at_cmd/log_service.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
#ifndef LOG_SERVICE_H
|
||||
#define LOG_SERVICE_H
|
||||
|
||||
#include "dlist.h"
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform_opts.h"
|
||||
#endif
|
||||
|
||||
#ifdef __ICCARM__
|
||||
#define STRINGIFY(s) #s
|
||||
#define SECTION(_name) _Pragma( STRINGIFY(location=##_name##))
|
||||
#define log_module_init(fn) \
|
||||
SECTION(".data.log_init") __root static void* log_##fn = (void*)fn
|
||||
#elif defined(__CC_ARM)
|
||||
#define log_module_init(fn) \
|
||||
static void* log_##fn __attribute__((section(".data.log_init"))) = (void*)fn;
|
||||
#define DiagPrintf printf
|
||||
#else
|
||||
#error "not implement"
|
||||
#endif
|
||||
|
||||
#define ATC_INDEX_NUM 32
|
||||
|
||||
#ifndef SUPPORT_LOG_SERVICE
|
||||
#define SUPPORT_LOG_SERVICE 1
|
||||
#endif
|
||||
|
||||
#if SUPPORT_LOG_SERVICE
|
||||
|
||||
//LOG_SERVICE_BUFLEN: default, only 63 bytes could be used for keeping input
|
||||
// cmd, the last byte is for string end ('\0').
|
||||
#ifndef LOG_SERVICE_BUFLEN
|
||||
#define LOG_SERVICE_BUFLEN 64
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_HISTORY
|
||||
#define CONFIG_LOG_HISTORY 0
|
||||
#if CONFIG_LOG_HISTORY
|
||||
#define LOG_HISTORY_LEN 5
|
||||
#endif
|
||||
#endif //#ifndef CONFIG_LOG_HISTORY
|
||||
|
||||
#ifndef MAX_ARGC
|
||||
#define MAX_ARGC 6
|
||||
#endif
|
||||
|
||||
#define AT_BIT(n) (1<<n)
|
||||
#define AT_FLAG_DUMP AT_BIT(0)
|
||||
#define AT_FLAG_EDIT AT_BIT(1)
|
||||
#define AT_FLAG_ADC AT_BIT(2)
|
||||
#define AT_FLAG_GPIO AT_BIT(3)
|
||||
#define AT_FLAG_OTA AT_BIT(4)
|
||||
#define AT_FLAG_NFC AT_BIT(5)
|
||||
#define AT_FLAG_OS AT_BIT(6)
|
||||
|
||||
enum{
|
||||
AT_DBG_OFF = 0,
|
||||
AT_DBG_ALWAYS,
|
||||
AT_DBG_ERROR,
|
||||
AT_DBG_WARNING,
|
||||
AT_DBG_INFO
|
||||
};
|
||||
|
||||
static unsigned char gDbgLevel = AT_DBG_ERROR;
|
||||
static unsigned int gDbgFlag = 0xFFFFFFFF;
|
||||
|
||||
#define AT_PRINTK(fmt, args...) printf(fmt"\r\n",## args)
|
||||
#define AT_DBG_MSG(flag, level, fmt, args...) \
|
||||
do{ \
|
||||
if(((flag) & gDbgFlag) && (level <= gDbgLevel)){ \
|
||||
AT_PRINTK(fmt,## args); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
#define SUPPORT_INTERACTIVE_MODE 0
|
||||
#endif //#ifndef SUPPORT_INTERACTIVE_MODE
|
||||
#endif
|
||||
|
||||
typedef void (*log_init_t)(void);
|
||||
typedef void (*log_act_t)(void*);
|
||||
typedef struct _at_command_item_{
|
||||
char *log_cmd;
|
||||
log_act_t at_act;
|
||||
struct list_head node;
|
||||
}log_item_t;
|
||||
|
||||
void log_service_add_table(log_item_t *tbl, int len);
|
||||
int parse_param(char *buf, char **argv);
|
||||
|
||||
#endif
|
354
component/common/api/lwip_netconf.c
Normal file
354
component/common/api/lwip_netconf.c
Normal file
|
@ -0,0 +1,354 @@
|
|||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "ethernetif.h"
|
||||
#include "main.h"
|
||||
#include "lwip_netconf.h"
|
||||
#include "wifi_ind.h"
|
||||
#if defined(STM32F2XX)
|
||||
#include "stm322xg_eval_lcd.h"
|
||||
#elif defined(STM32F4XX)
|
||||
#include "stm324xg_eval_lcd.h"
|
||||
#endif
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
/* Give default value if not defined */
|
||||
#ifndef NET_IF_NUM
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#define NET_IF_NUM 2
|
||||
#else
|
||||
#define NET_IF_NUM 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef IP_ADDR0
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef NETMASK_ADDR0
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef GW_ADDR0
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#ifndef AP_IP_ADDR0
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
#endif
|
||||
|
||||
/*NETMASK*/
|
||||
#ifndef AP_NETMASK_ADDR0
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
#endif
|
||||
|
||||
/*Gateway Address*/
|
||||
#ifndef AP_GW_ADDR0
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
#endif
|
||||
|
||||
_WEAK void user_wifi_beacon_hdl( char* buf, int buf_len, int flags, void* userdata) {
|
||||
//printf("Beacon!\n");
|
||||
}
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define MAX_DHCP_TRIES 5
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
struct netif xnetif[NET_IF_NUM]; /* network interface structure */
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initializes the lwIP stack
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void LwIP_Init(void)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
int8_t idx = 0;
|
||||
/* Create tcp_ip stack thread */
|
||||
tcpip_init( NULL, NULL );
|
||||
|
||||
/* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
|
||||
struct ip_addr *netmask, struct ip_addr *gw,
|
||||
void *state, err_t (* init)(struct netif *netif),
|
||||
err_t (* input)(struct pbuf *p, struct netif *netif))
|
||||
|
||||
Adds your network interface to the netif_list. Allocate a struct
|
||||
netif and pass a pointer to this structure as the first argument.
|
||||
Give pointers to cleared ip_addr structures when using DHCP,
|
||||
or fill them with sane numbers otherwise. The state pointer may be NULL.
|
||||
|
||||
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){
|
||||
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{
|
||||
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);
|
||||
}
|
||||
xnetif[idx].name[0] = 'r';
|
||||
xnetif[idx].name[1] = '0'+idx;
|
||||
netif_add(&xnetif[idx], &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input);
|
||||
}
|
||||
|
||||
/* 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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LwIP_DHCP_Process_Handle
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
uint32_t IPaddress;
|
||||
uint8_t iptab[4];
|
||||
uint8_t DHCP_state;
|
||||
int mscnt = 0;
|
||||
struct netif *pnetif = NULL;
|
||||
|
||||
DHCP_state = dhcp_state;
|
||||
|
||||
if(idx > 1)
|
||||
idx = 1;
|
||||
pnetif = &xnetif[idx];
|
||||
if(DHCP_state == 0){
|
||||
pnetif->ip_addr.addr = 0;
|
||||
pnetif->netmask.addr = 0;
|
||||
pnetif->gw.addr = 0;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
//printf("\n\r ========DHCP_state:%d============\n\r",DHCP_state);
|
||||
switch (DHCP_state)
|
||||
{
|
||||
case DHCP_START:
|
||||
{
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, user_wifi_beacon_hdl);
|
||||
dhcp_start(pnetif);
|
||||
IPaddress = 0;
|
||||
DHCP_state = DHCP_WAIT_ADDRESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case DHCP_WAIT_ADDRESS:
|
||||
{
|
||||
/* Read the new IP address */
|
||||
IPaddress = pnetif->ip_addr.addr;
|
||||
|
||||
if (IPaddress!=0)
|
||||
{
|
||||
DHCP_state = DHCP_ADDRESS_ASSIGNED;
|
||||
|
||||
wifi_reg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, user_wifi_beacon_hdl, NULL);
|
||||
|
||||
|
||||
/* Stop DHCP */
|
||||
dhcp_stop(pnetif);
|
||||
|
||||
iptab[0] = (uint8_t)(IPaddress >> 24);
|
||||
iptab[1] = (uint8_t)(IPaddress >> 16);
|
||||
iptab[2] = (uint8_t)(IPaddress >> 8);
|
||||
iptab[3] = (uint8_t)(IPaddress);
|
||||
printf("\n\rIP address : %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
|
||||
return DHCP_ADDRESS_ASSIGNED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* DHCP timeout */
|
||||
if (pnetif->dhcp->tries > MAX_DHCP_TRIES)
|
||||
{
|
||||
DHCP_state = DHCP_TIMEOUT;
|
||||
|
||||
/* Stop DHCP */
|
||||
dhcp_stop(pnetif);
|
||||
|
||||
/* Static address used */
|
||||
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);
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
|
||||
iptab[0] = IP_ADDR3;
|
||||
iptab[1] = IP_ADDR2;
|
||||
iptab[2] = IP_ADDR1;
|
||||
iptab[3] = IP_ADDR0;
|
||||
printf("\n\rDHCP timeout");
|
||||
printf("\n\rStatic IP address : %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
|
||||
|
||||
return DHCP_TIMEOUT;
|
||||
}else
|
||||
{
|
||||
//sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
vTaskDelay(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000)
|
||||
{
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DHCP_RELEASE_IP:
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, user_wifi_beacon_hdl);
|
||||
printf("\n\rLwIP_DHCP: Release ip");
|
||||
dhcp_release_unicast(pnetif);
|
||||
return DHCP_RELEASE_IP;
|
||||
case DHCP_STOP:
|
||||
wifi_unreg_event_handler(WIFI_EVENT_BEACON_AFTER_DHCP, user_wifi_beacon_hdl);
|
||||
printf("\n\rLwIP_DHCP: dhcp stop.");
|
||||
dhcp_stop(pnetif);
|
||||
return DHCP_STOP;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetMAC(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) (pnetif->hwaddr);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetIP(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->ip_addr);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetGW(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->gw);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetMASK(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->netmask);
|
||||
}
|
||||
|
||||
uint8_t* LwIP_GetBC(struct netif *pnetif)
|
||||
{
|
||||
return (uint8_t *) &(pnetif->dhcp->offered_bc_addr);
|
||||
}
|
||||
|
||||
#if LWIP_DNS
|
||||
void LwIP_GetDNS(struct ip_addr* dns)
|
||||
{
|
||||
*dns = dns_getserver(0);
|
||||
}
|
||||
|
||||
void LwIP_SetDNS(struct ip_addr* dns)
|
||||
{
|
||||
dns_setserver(0, dns);
|
||||
}
|
||||
#endif
|
||||
void LwIP_UseStaticIP(struct netif *pnetif)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
/* Static address used */
|
||||
if(pnetif->name[1] == '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{
|
||||
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);
|
||||
}
|
||||
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
}
|
||||
#if LWIP_AUTOIP
|
||||
#include <lwip/autoip.h>
|
||||
|
||||
void LwIP_AUTOIP(struct netif *pnetif)
|
||||
{
|
||||
uint8_t *ip = LwIP_GetIP(pnetif);
|
||||
|
||||
autoip_start(pnetif);
|
||||
|
||||
while((pnetif->autoip->state == AUTOIP_STATE_PROBING) || (pnetif->autoip->state == AUTOIP_STATE_ANNOUNCING)) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
|
||||
if(*((uint32_t *) ip) == 0) {
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
printf("AUTOIP timeout\n");
|
||||
|
||||
/* Static address used */
|
||||
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);
|
||||
netif_set_addr(pnetif, &ipaddr , &netmask, &gw);
|
||||
printf("Static IP address : %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
else {
|
||||
printf("\nLink-local address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
void LwIP_AUTOIP_IPv6(struct netif *pnetif)
|
||||
{
|
||||
uint8_t *ipv6 = (uint8_t *) &(pnetif->ip6_addr[0].addr[0]);
|
||||
|
||||
netif_create_ip6_linklocal_address(pnetif, 1);
|
||||
netif_ip6_addr_set_state(pnetif, 0, IP6_ADDR_TENTATIVE);
|
||||
printf("\nIPv6 link-local address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
|
||||
ipv6[0], ipv6[1], ipv6[2], ipv6[3], ipv6[4], ipv6[5], ipv6[6], ipv6[7],
|
||||
ipv6[8], ipv6[9], ipv6[10], ipv6[11], ipv6[12], ipv6[13], ipv6[14], ipv6[15]);
|
||||
}
|
||||
#endif
|
74
component/common/api/lwip_netconf.h
Normal file
74
component/common/api/lwip_netconf.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file netconf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief This file contains all the functions prototypes for the netconf.c
|
||||
* file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __NETCONF_H
|
||||
#define __NETCONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tcpip.h"
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <platform/platform_stdlib.h>
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
DHCP_START=0,
|
||||
DHCP_WAIT_ADDRESS,
|
||||
DHCP_ADDRESS_ASSIGNED,
|
||||
DHCP_RELEASE_IP,
|
||||
DHCP_STOP,
|
||||
DHCP_TIMEOUT
|
||||
} DHCP_State_TypeDef;
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void LwIP_Init(void);
|
||||
uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state);
|
||||
unsigned char* LwIP_GetMAC(struct netif *pnetif);
|
||||
unsigned char* LwIP_GetIP(struct netif *pnetif);
|
||||
unsigned char* LwIP_GetGW(struct netif *pnetif);
|
||||
uint8_t* LwIP_GetMASK(struct netif *pnetif);
|
||||
uint8_t* LwIP_GetBC(struct netif *pnetif);
|
||||
#if LWIP_DNS
|
||||
void LwIP_GetDNS(struct ip_addr* dns);
|
||||
void LwIP_SetDNS(struct ip_addr* dns);
|
||||
#endif
|
||||
void LwIP_UseStaticIP(struct netif *pnetif);
|
||||
#if LWIP_AUTOIP
|
||||
void LwIP_AUTOIP(struct netif *pnetif);
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
void LwIP_AUTOIP_IPv6(struct netif *pnetif);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETCONF_H */
|
||||
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
236
component/common/api/network/include/lwipopts.h
Normal file
236
component/common/api/network/include/lwipopts.h
Normal file
|
@ -0,0 +1,236 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file lwipopts.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief lwIP Options Configuration.
|
||||
* This file is based on Utilities\lwip_v1.3.2\src\include\lwip\opt.h
|
||||
* and contains the lwIP configuration for the STM32F2x7 demonstration.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
/**
|
||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||
* critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
/* Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
|
||||
should be used instead */
|
||||
#define LWIP_COMPAT_MUTEX 1
|
||||
|
||||
#define ETHARP_TRUST_IP_MAC 0
|
||||
#define IP_REASSEMBLY 1
|
||||
#define IP_FRAG 1
|
||||
#define ARP_QUEUEING 0
|
||||
|
||||
/**
|
||||
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
|
||||
* use lwIP facilities.
|
||||
*/
|
||||
#define NO_SYS 0
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||
byte alignment -> define MEM_ALIGNMENT to 2. */
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
#define MEM_SIZE (5*1024)
|
||||
|
||||
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
||||
sends a lot of data out of ROM (or other static memory), this
|
||||
should be set high. */
|
||||
#define MEMP_NUM_PBUF 100
|
||||
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
|
||||
per active UDP "connection". */
|
||||
#define MEMP_NUM_UDP_PCB 6
|
||||
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB 10
|
||||
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 5
|
||||
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
|
||||
segments. */
|
||||
#define MEMP_NUM_TCP_SEG 20
|
||||
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
|
||||
timeouts. */
|
||||
#define MEMP_NUM_SYS_TIMEOUT 10
|
||||
|
||||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#define PBUF_POOL_SIZE 20
|
||||
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
#define PBUF_POOL_BUFSIZE 500
|
||||
|
||||
|
||||
/* ---------- TCP options ---------- */
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_TTL 255
|
||||
|
||||
/* Controls if TCP should queue segments that arrive out of
|
||||
order. Define to 0 if your device is low on memory. */
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
|
||||
/* TCP Maximum segment size. */
|
||||
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#define TCP_SND_BUF (5*TCP_MSS)
|
||||
|
||||
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
|
||||
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
|
||||
|
||||
#define TCP_SND_QUEUELEN (4* TCP_SND_BUF/TCP_MSS)
|
||||
|
||||
/* TCP receive window. */
|
||||
#define TCP_WND (2*TCP_MSS)
|
||||
|
||||
|
||||
/* ---------- ICMP options ---------- */
|
||||
#define LWIP_ICMP 1
|
||||
|
||||
/* ---------- ARP options ----------- */
|
||||
#define LWIP_ARP 1
|
||||
|
||||
/* ---------- DHCP options ---------- */
|
||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
||||
turning this on does currently not work. */
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
|
||||
/* ---------- UDP options ---------- */
|
||||
#define LWIP_UDP 1
|
||||
#define UDP_TTL 255
|
||||
|
||||
|
||||
/* ---------- UPNP options --------- */
|
||||
#define LWIP_UPNP 0
|
||||
|
||||
/* Support Multicast */
|
||||
#define LWIP_IGMP 0
|
||||
#define LWIP_RAND() rand()
|
||||
|
||||
#define LWIP_TCP_DELAY_DISABLE 0
|
||||
|
||||
/* ---------- Statistics options ---------- */
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_PROVIDE_ERRNO 1
|
||||
|
||||
|
||||
/*
|
||||
--------------------------------------
|
||||
---------- Checksum options ----------
|
||||
--------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
The STM32F2x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
|
||||
- To use this feature let the following define uncommented.
|
||||
- To disable it and process by CPU comment the the checksum.
|
||||
*/
|
||||
//Do checksum by lwip - WLAN nic does not support Checksum offload
|
||||
//#define CHECKSUM_BY_HARDWARE
|
||||
|
||||
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 0
|
||||
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 0
|
||||
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 0
|
||||
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 0
|
||||
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 0
|
||||
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 0
|
||||
#else
|
||||
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 1
|
||||
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 1
|
||||
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 1
|
||||
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 1
|
||||
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 1
|
||||
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------
|
||||
---------- Sequential layer options ----------
|
||||
----------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
|
||||
*/
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Socket options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
|
||||
*/
|
||||
#define LWIP_SOCKET 1
|
||||
|
||||
/*
|
||||
-----------------------------------
|
||||
---------- DEBUG options ----------
|
||||
-----------------------------------
|
||||
*/
|
||||
|
||||
#define LWIP_DEBUG 0
|
||||
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- OS options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
#define TCPIP_THREAD_STACKSIZE 1000
|
||||
#define TCPIP_MBOX_SIZE 5
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 2000
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 2000
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 2000
|
||||
#define DEFAULT_THREAD_STACKSIZE 500
|
||||
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
|
||||
|
||||
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
68
component/common/api/network/include/main.h
Normal file
68
component/common/api/network/include/main.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <autoconf.h>
|
||||
|
||||
#define CONFIG_WLAN 1
|
||||
|
||||
|
||||
/* Header file declaration*/
|
||||
void wlan_network();
|
||||
|
||||
|
||||
/* Interactive Mode */
|
||||
#define SERIAL_DEBUG_RX 1
|
||||
#if defined(__ICCARM__)
|
||||
static
|
||||
#endif
|
||||
char uart_buf[64];
|
||||
|
||||
|
||||
/* WLAN and Netork */
|
||||
#define STA_MODE_SSID "ap" /* Set SSID here */
|
||||
#define AP_MODE_SSID "wlan_ap_ssid" /* Set SSID here */
|
||||
#define AP_DEFAULT_CH 6
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#define WLAN1_NAME "wlan1"
|
||||
#define WPA_PASSPHRASE "1234567890" /* Max 32 cahracters */
|
||||
#define WEP40_KEY {0x12, 0x34, 0x56, 0x78, 0x90}
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#define IP_ADDR0 192
|
||||
#define IP_ADDR1 168
|
||||
#define IP_ADDR2 1
|
||||
#define IP_ADDR3 80
|
||||
|
||||
/*NETMASK*/
|
||||
#define NETMASK_ADDR0 255
|
||||
#define NETMASK_ADDR1 255
|
||||
#define NETMASK_ADDR2 255
|
||||
#define NETMASK_ADDR3 0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define GW_ADDR0 192
|
||||
#define GW_ADDR1 168
|
||||
#define GW_ADDR2 1
|
||||
#define GW_ADDR3 1
|
||||
|
||||
/*******************************************/
|
||||
|
||||
/*Static IP ADDRESS*/
|
||||
#define AP_IP_ADDR0 192
|
||||
#define AP_IP_ADDR1 168
|
||||
#define AP_IP_ADDR2 43
|
||||
#define AP_IP_ADDR3 1
|
||||
|
||||
/*NETMASK*/
|
||||
#define AP_NETMASK_ADDR0 255
|
||||
#define AP_NETMASK_ADDR1 255
|
||||
#define AP_NETMASK_ADDR2 255
|
||||
#define AP_NETMASK_ADDR3 0
|
||||
|
||||
/*Gateway Address*/
|
||||
#define AP_GW_ADDR0 192
|
||||
#define AP_GW_ADDR1 168
|
||||
#define AP_GW_ADDR2 43
|
||||
#define AP_GW_ADDR3 1
|
||||
|
||||
#endif
|
21
component/common/api/network/include/main_test.h
Normal file
21
component/common/api/network/include/main_test.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#ifndef __MAIN_TEST_H
|
||||
#define __MAIN_TEST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported test functions ------------------------------------------------------- */
|
||||
void do_ping_test(char *ip, int size, int count, int interval);
|
||||
void do_ping_call(char *ip, int loop, int count);
|
||||
void interactive_question(char *question, char *choice, char *buf, int buf_size);
|
||||
void start_interactive_mode(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __MAIN_TEST_H
|
||||
|
||||
//----------------------------------------------------------------------------//
|
50
component/common/api/network/include/netconf.h
Normal file
50
component/common/api/network/include/netconf.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file netconf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 07-October-2011
|
||||
* @brief This file contains all the functions prototypes for the netconf.c
|
||||
* file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __NETCONF_H
|
||||
#define __NETCONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO: remove this file
|
||||
#include "lwip_netconf.h"
|
||||
#if 0
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void LwIP_Init(void);
|
||||
void LwIP_DHCP(void);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETCONF_H */
|
||||
|
||||
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
8
component/common/api/network/include/rtl8195a_it.h
Normal file
8
component/common/api/network/include/rtl8195a_it.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
#ifndef __RTL8195A_IT_H_
|
||||
#define __RTL8195A_IT_H_
|
||||
|
||||
|
||||
int irq_alloc_wlan(void *contex);
|
||||
|
||||
#endif //__RTL8195A_IT_H_
|
47
component/common/api/network/include/util.h
Normal file
47
component/common/api/network/include/util.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "wifi_util.h"
|
||||
#if 0
|
||||
typedef enum _WIFI_EVENT_INDICATE{
|
||||
WIFI_EVENT_CONNECT = 0,
|
||||
WIFI_EVENT_DISCONNECT = 1,
|
||||
WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
|
||||
}WIFI_EVENT_INDICATE;
|
||||
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid);
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
|
||||
int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
|
||||
int wext_get_enc_ext(const char *ifname, __u16 *alg);
|
||||
int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase);
|
||||
int wext_disconnect(const char *ifname);
|
||||
int wext_set_mode(const char *ifname, int mode);
|
||||
int wext_get_mode(const char *ifname, int *mode);
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_country(const char *ifname, char *country_code);
|
||||
int wext_get_rssi(const char *ifname, int *rssi);
|
||||
int wext_set_channel(const char *ifname, __u8 ch);
|
||||
int wext_get_channel(const char *ifname, __u8 *ch);
|
||||
int wext_set_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_mp_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_wifi_priv(const char *ifname, int argc, char **argv);
|
||||
void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
|
||||
#endif
|
||||
|
||||
#define wext_handshake_done rltk_wlan_handshake_done
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UTIL_H */
|
88
component/common/api/network/include/wificonf.h
Normal file
88
component/common/api/network/include/wificonf.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#ifndef __WIFICONF_H
|
||||
#define __WIFICONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
|
||||
typedef enum _WIFI_SECURITY_TYPE{
|
||||
WIFI_SECURITY_OPEN = 0,
|
||||
WIFI_SECURITY_WEP,
|
||||
WIFI_SECURITY_WPA,
|
||||
WIFI_SECURITY_WPA2
|
||||
}WIFI_SECURITY_TYPE;
|
||||
|
||||
typedef enum _WIFI_COUNTRY_CODE{
|
||||
WIFI_COUNTRY_US = 0,
|
||||
WIFI_COUNTRY_EU,
|
||||
WIFI_COUNTRY_JP,
|
||||
WIFI_COUNTRY_CN
|
||||
}WIFI_COUNTRY_CODE;
|
||||
|
||||
typedef enum _WIFI_MODE_TYPE{
|
||||
WIFI_MODE_STA = 0,
|
||||
WIFI_MODE_AP
|
||||
}WIFI_MODE_TYPE;
|
||||
|
||||
typedef enum _WIFI_LINK_STATUS{
|
||||
WIFI_LINK_DISCONNECTED = 0,
|
||||
WIFI_LINK_CONNECTED
|
||||
}WIFI_LINK_STATUS;
|
||||
|
||||
typedef struct _WIFI_AP{
|
||||
unsigned char *ssid;
|
||||
WIFI_SECURITY_TYPE security_type;
|
||||
unsigned char *password;
|
||||
int ssid_len;
|
||||
int password_len;
|
||||
int channel;
|
||||
}WIFI_AP;
|
||||
|
||||
typedef struct _WIFI_NETWORK{
|
||||
unsigned char *ssid;
|
||||
WIFI_SECURITY_TYPE security_type;
|
||||
unsigned char *password;
|
||||
int ssid_len;
|
||||
int password_len;
|
||||
int key_id;
|
||||
}WIFI_NETWORK;
|
||||
|
||||
typedef struct _WIFI_SETTING{
|
||||
WIFI_MODE_TYPE mode;
|
||||
unsigned char ssid[33];
|
||||
unsigned char channel;
|
||||
WIFI_SECURITY_TYPE security_type;
|
||||
unsigned char password[33];
|
||||
}WIFI_SETTING;
|
||||
|
||||
typedef enum _WIFI_NETWORK_MODE {
|
||||
WIFI_NETWORK_B = 1,
|
||||
WIFI_NETWORK_BG = 3,
|
||||
WIFI_NETWORK_BGN = 11
|
||||
} WIFI_NETWORK_MODE;
|
||||
|
||||
int wifi_connect(WIFI_NETWORK *pNetwork);
|
||||
int wifi_disconnect(void);
|
||||
WIFI_LINK_STATUS wifi_get_connect_status(WIFI_NETWORK *pWifi);
|
||||
int wifi_set_country(WIFI_COUNTRY_CODE country_code);
|
||||
int wifi_get_rssi(int *pRSSI);
|
||||
int wifi_rf_on(void);
|
||||
int wifi_rf_off(void);
|
||||
int wifi_active_ap(WIFI_AP *pAP);
|
||||
int wifi_scan(char *buf, int buf_len);
|
||||
int wifi_get_setting(WIFI_SETTING *pSetting);
|
||||
int wifi_show_setting(WIFI_SETTING *pSetting);
|
||||
int wifi_set_network_mode(WIFI_NETWORK_MODE mode);
|
||||
void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __WIFICONF_H
|
||||
|
||||
//----------------------------------------------------------------------------//
|
136
component/common/api/network/src/ping_test.c
Normal file
136
component/common/api/network/src/ping_test.c
Normal file
|
@ -0,0 +1,136 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/raw.h>
|
||||
#include <lwip/icmp.h>
|
||||
#include <lwip/inet_chksum.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include "diag.h"
|
||||
|
||||
//#define PING_IP "192.168.0.1"
|
||||
#define PING_IP "192.168.159.1"
|
||||
#define PING_TO 1000
|
||||
#define PING_ID 0xABCD
|
||||
#define BUF_SIZE 200
|
||||
#define STACKSIZE 1024
|
||||
|
||||
static unsigned short ping_seq = 0;
|
||||
static int infinite_loop, ping_count, data_size, ping_interval, ping_call;
|
||||
static char ping_ip[16];
|
||||
|
||||
static void generate_ping_echo(unsigned char *buf, int size)
|
||||
{
|
||||
int i;
|
||||
struct icmp_echo_hdr *pecho;
|
||||
|
||||
for(i = 0; i < size; i ++) {
|
||||
buf[sizeof(struct icmp_echo_hdr) + i] = (unsigned char) i;
|
||||
}
|
||||
|
||||
pecho = (struct icmp_echo_hdr *) buf;
|
||||
ICMPH_TYPE_SET(pecho, ICMP_ECHO);
|
||||
ICMPH_CODE_SET(pecho, 0);
|
||||
pecho->chksum = 0;
|
||||
pecho->id = PING_ID;
|
||||
pecho->seqno = htons(++ ping_seq);
|
||||
|
||||
//Checksum includes icmp header and data. Need to calculate after fill up icmp header
|
||||
pecho->chksum = inet_chksum(pecho, sizeof(struct icmp_echo_hdr) + size);
|
||||
}
|
||||
|
||||
void ping_test(void *param)
|
||||
//void ping_test()
|
||||
{
|
||||
int i, ping_socket;
|
||||
int pint_timeout = PING_TO;
|
||||
struct sockaddr_in to_addr, from_addr;
|
||||
int from_addr_len;
|
||||
int ping_size, reply_size;
|
||||
unsigned char ping_buf[BUF_SIZE], reply_buf[BUF_SIZE];
|
||||
unsigned int ping_time, reply_time;
|
||||
struct ip_hdr *iphdr;
|
||||
struct icmp_echo_hdr *pecho;
|
||||
|
||||
//Ping size = icmp header(8 bytes) + data size
|
||||
ping_size = sizeof(struct icmp_echo_hdr) + data_size;
|
||||
printf("\n\r[%s] PING %s %d(%d) bytes of data\n", __FUNCTION__, ping_ip, data_size, sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr) + data_size);
|
||||
|
||||
for(i = 0; (i < ping_count) || (infinite_loop == 1); i ++) {
|
||||
ping_socket = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
|
||||
setsockopt(ping_socket, SOL_SOCKET, SO_RCVTIMEO, &pint_timeout, sizeof(pint_timeout));
|
||||
|
||||
to_addr.sin_len = sizeof(to_addr);
|
||||
to_addr.sin_family = AF_INET;
|
||||
to_addr.sin_addr.s_addr = inet_addr(ping_ip);
|
||||
|
||||
generate_ping_echo(ping_buf, data_size);
|
||||
sendto(ping_socket, ping_buf, ping_size, 0, (struct sockaddr *) &to_addr, sizeof(to_addr));
|
||||
|
||||
ping_time = xTaskGetTickCount();
|
||||
if((reply_size = recvfrom(ping_socket, reply_buf, sizeof(reply_buf), 0, (struct sockaddr *) &from_addr, (socklen_t *) &from_addr_len))
|
||||
>= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
|
||||
|
||||
reply_time = xTaskGetTickCount();
|
||||
iphdr = (struct ip_hdr *)reply_buf;
|
||||
pecho = (struct icmp_echo_hdr *)(reply_buf + (IPH_HL(iphdr) * 4));
|
||||
|
||||
if((pecho->id == PING_ID) && (pecho->seqno == htons(ping_seq))) {
|
||||
printf("\n\r[%s] %d bytes from %s: icmp_seq=%d time=%d ms", __FUNCTION__, reply_size - sizeof(struct ip_hdr), inet_ntoa(from_addr.sin_addr), htons(pecho->seqno), (reply_time - ping_time) * portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("\n\r[%s] Request timeout for icmp_seq %d\n", __FUNCTION__, ping_seq);
|
||||
|
||||
close(ping_socket);
|
||||
vTaskDelay(ping_interval * configTICK_RATE_HZ);
|
||||
}
|
||||
|
||||
if(!ping_call)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void do_ping_call(char *ip, int loop, int count)
|
||||
{
|
||||
ping_call = 1;
|
||||
ping_seq = 0;
|
||||
data_size = 120;
|
||||
ping_interval = 1;
|
||||
infinite_loop = loop;
|
||||
ping_count = count;
|
||||
strcpy(ping_ip, ip);
|
||||
|
||||
ping_test(NULL);
|
||||
}
|
||||
|
||||
void do_ping_test(char *ip, int size, int count, int interval)
|
||||
{
|
||||
if((sizeof(struct icmp_echo_hdr) + size) > BUF_SIZE) {
|
||||
printf("\n\r%s BUF_SIZE(%d) is too small", __FUNCTION__, BUF_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(ip == NULL)
|
||||
strcpy(ping_ip, PING_IP);
|
||||
else
|
||||
strcpy(ping_ip, ip);
|
||||
|
||||
ping_call = 0;
|
||||
ping_seq = 0;
|
||||
data_size = size;
|
||||
ping_interval = interval;
|
||||
|
||||
if(count == 0) {
|
||||
infinite_loop = 1;
|
||||
ping_count = 0;
|
||||
}
|
||||
else {
|
||||
infinite_loop = 0;
|
||||
ping_count = count;
|
||||
}
|
||||
|
||||
if(xTaskCreate(ping_test, ((const signed char*)"ping_test"), STACKSIZE, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed", __FUNCTION__);
|
||||
}
|
110
component/common/api/network/src/rtl8195a_it.c
Normal file
110
component/common/api/network/src/rtl8195a_it.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
#include "rtl8195a.h"
|
||||
#include <main.h>
|
||||
#include "rtl8195a_it.h"
|
||||
|
||||
/* os dependent*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
|
||||
|
||||
#include <diag.h>
|
||||
#define printf DiagPrintf
|
||||
|
||||
/*-----------------------------Global Variable ---------------------*/
|
||||
//#ifdef CONFIG_WLAN
|
||||
//#ifdef CONFIG_ISR_THREAD_MODE_INTERRUPT
|
||||
extern xSemaphoreHandle *pExportWlanIrqSemaphore;
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_WLAN
|
||||
#ifdef CONFIG_ISR_THREAD_MODE_INTERRUPT
|
||||
|
||||
//TODO: chris
|
||||
#define IRQ_HANDLED 1
|
||||
#define IRQ_NONE 0
|
||||
|
||||
int wlan_Interrupt (
|
||||
IN VOID* Data
|
||||
)
|
||||
{
|
||||
#if 1
|
||||
|
||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
printf("wlan interrupt\n");
|
||||
/* This semaphore is initialized once wlan interrupt handler thread is created and initialized*/
|
||||
if(!pExportWlanIrqSemaphore)
|
||||
{
|
||||
printf("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
xSemaphoreGiveFromISR( *pExportWlanIrqSemaphore, &xHigherPriorityTaskWoken );
|
||||
|
||||
printf("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
/* Switch tasks if necessary. */
|
||||
if( xHigherPriorityTaskWoken != pdFALSE )
|
||||
{
|
||||
printf("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
return IRQ_HANDLED;
|
||||
#else
|
||||
struct dvobj_priv *dvobj = (struct dvobj_priv *)Data;
|
||||
_adapter *adapter = dvobj->if1;
|
||||
DBG_8192C("Dma isr\n");
|
||||
|
||||
if (dvobj->irq_enabled == 0) {
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
DBG_871X("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
if(rtw_hal_interrupt_handler(adapter) == _FAIL)
|
||||
return IRQ_HANDLED;
|
||||
//return IRQ_NONE;
|
||||
DBG_871X("%s(%d)\n", __FUNCTION__, __LINE__);
|
||||
return IRQ_HANDLED;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
lextra_bus_dma_Interrupt (
|
||||
IN VOID* Data
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* This function register interrupt handler and is called by wlan driver
|
||||
* Return 0 if success, Others if fail
|
||||
*/
|
||||
|
||||
int irq_alloc_wlan(void *contex)
|
||||
{
|
||||
int ret = 0;
|
||||
IRQ_HANDLE IrqHandle = {0};
|
||||
|
||||
printf("Register Interrupt\n");
|
||||
IrqHandle.Data = (u32) (contex);
|
||||
IrqHandle.IrqNum = WL_DMA_IRQ;
|
||||
IrqHandle.IrqFun = (IRQ_FUN)wlan_Interrupt;
|
||||
//IrqHandle.IrqFun = (IRQ_FUN)lextra_bus_dma_Interrupt;
|
||||
IrqHandle.Priority = 0;
|
||||
|
||||
InterruptRegister(&IrqHandle);
|
||||
InterruptEn(&IrqHandle);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
65
component/common/api/network/src/wlan_network.c
Normal file
65
component/common/api/network/src/wlan_network.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Hello World
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "main_test.h"
|
||||
#include "wifi_conf.h"
|
||||
#include "wlan_intf.h"
|
||||
#include "lwip_netconf.h"
|
||||
#include "wifi_constants.h"
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#ifndef CONFIG_INIT_NET
|
||||
#define CONFIG_INIT_NET 1
|
||||
#endif
|
||||
#ifndef CONFIG_INTERACTIVE_MODE
|
||||
#define CONFIG_INTERACTIVE_MODE 1
|
||||
#endif
|
||||
|
||||
#define STACKSIZE (512 + 768)
|
||||
|
||||
xSemaphoreHandle uart_rx_interrupt_sema = NULL;
|
||||
|
||||
void init_thread(void *param)
|
||||
{
|
||||
|
||||
#if CONFIG_INIT_NET
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Initilaize the LwIP stack */
|
||||
LwIP_Init();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
wifi_on(RTW_MODE_STA);
|
||||
|
||||
printf("\n\r%s(%d), Available heap 0x%x", __FUNCTION__, __LINE__, xPortGetFreeHeapSize());
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
/* Kill init thread after all init tasks done */
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void wlan_network()
|
||||
{
|
||||
if(xTaskCreate(init_thread, ((const char*)"init"), STACKSIZE, NULL, tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
250
component/common/api/platform/dlist.h
Normal file
250
component/common/api/platform/dlist.h
Normal file
|
@ -0,0 +1,250 @@
|
|||
#ifndef __LIST_H
|
||||
#define __LIST_H
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#ifndef inline
|
||||
#define inline __inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This file is from Linux Kernel (include/linux/list.h)
|
||||
* and modified by simply removing hardware prefetching of list items.
|
||||
* Here by copyright, credits attributed to wherever they belong.
|
||||
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = (void *) 0;
|
||||
entry->prev = (void *) 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
|
||||
#endif
|
145
component/common/api/platform/platform_stdlib.h
Normal file
145
component/common/api/platform/platform_stdlib.h
Normal file
|
@ -0,0 +1,145 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2014 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __PLATFORM_STDLIB_H__
|
||||
#define __PLATFORM_STDLIB_H__
|
||||
|
||||
#define USE_CLIB_PATCH 0
|
||||
#if defined (__GNUC__)
|
||||
#define USE_RTL_ROM_CLIB 0
|
||||
#else
|
||||
#define USE_RTL_ROM_CLIB 1
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#if defined (__IARSTDLIB__)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "diag.h"
|
||||
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "diag.h"
|
||||
#include "strproc.h"
|
||||
#include "basic_types.h"
|
||||
#include "hal_misc.h"
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#include "rtl_lib.h"
|
||||
#endif
|
||||
|
||||
#undef printf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#undef atoi
|
||||
#undef memcmp
|
||||
#undef memcpy
|
||||
#undef memset
|
||||
#undef strcmp
|
||||
#undef strcpy
|
||||
#undef strlen
|
||||
#undef strncmp
|
||||
#undef strncpy
|
||||
#undef strsep
|
||||
#undef strtok
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#undef memchr
|
||||
#undef memmove
|
||||
#undef strcat
|
||||
#undef strchr
|
||||
#undef strncat
|
||||
#undef strstr
|
||||
#endif
|
||||
|
||||
#if USE_RTL_ROM_CLIB
|
||||
#define printf rtl_printf
|
||||
#define sprintf rtl_sprintf
|
||||
#define snprintf rtl_snprintf
|
||||
#define memchr rtl_memchr
|
||||
#define memcmp rtl_memcmp
|
||||
#define memcpy rtl_memcpy
|
||||
#define memmove rtl_memmove
|
||||
#define memset rtl_memset
|
||||
#define strcat rtl_strcat
|
||||
#define strchr rtl_strchr
|
||||
#define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2)
|
||||
#define strcpy rtl_strcpy
|
||||
#define strlen(str) rtl_strlen((const char *)str)
|
||||
#define strncat rtl_strncat
|
||||
#define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n)
|
||||
#define strncpy rtl_strncpy
|
||||
#define strstr rtl_strstr
|
||||
#define strsep rtl_strsep
|
||||
#define strtok rtl_strtok
|
||||
#else
|
||||
#if USE_CLIB_PATCH
|
||||
extern int DiagSscanfPatch(const char *buf, const char *fmt, ...);
|
||||
extern char* DiagStrtokPatch(char *str, const char* delim);
|
||||
extern char* DiagStrstrPatch(char *string, char *substring);
|
||||
extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...);
|
||||
extern u32 DiagPrintfPatch(const char *fmt, ...);
|
||||
extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...);
|
||||
#define printf DiagPrintfPatch
|
||||
#define sprintf DiagSPrintfPatch
|
||||
#define snprintf DiagSnPrintfPatch
|
||||
#define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b))
|
||||
#define strtok DiagStrtokPatch
|
||||
#else
|
||||
#define printf DiagPrintf
|
||||
#define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg)
|
||||
#if defined (__GNUC__)
|
||||
#define snprintf DiagSnPrintf // NULL function
|
||||
#define strstr(str1, str2) prvStrStr(str1, str2) // NULL function
|
||||
#endif
|
||||
#define strtok(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
#define memcmp(dst, src, sz) _memcmp(dst, src, sz)
|
||||
#define memcpy(dst, src, sz) _memcpy(dst, src, sz)
|
||||
#define memset(dst, val, sz) _memset(dst, val, sz)
|
||||
#define strchr(s, c) _strchr(s, c) // for B-cut ROM
|
||||
#define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2)
|
||||
#define strcpy(dest, src) _strcpy(dest, src)
|
||||
#define strlen(str) prvStrLen((const unsigned char *) str)
|
||||
#define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt)
|
||||
#define strncpy(dest, src, count) _strncpy(dest, src, count)
|
||||
#define strsep(str, delim) _strsep(str, delim)
|
||||
#endif
|
||||
|
||||
#define atoi(str) prvAtoi(str)
|
||||
#define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM
|
||||
|
||||
#if USE_CLIB_PATCH
|
||||
#undef sscanf
|
||||
#define sscanf DiagSscanfPatch
|
||||
#else
|
||||
#if defined (__GNUC__)
|
||||
#undef sscanf
|
||||
#define sscanf _sscanf
|
||||
#endif
|
||||
#endif
|
||||
#endif // defined (__IARSTDLIB__)
|
||||
|
||||
//
|
||||
// memory management
|
||||
//
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
|
||||
#elif defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL) || defined(STM32F10X_XL)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif //__PLATFORM_STDLIB_H__
|
846
component/common/api/platform/stdlib_patch.c
Normal file
846
component/common/api/platform/stdlib_patch.c
Normal file
|
@ -0,0 +1,846 @@
|
|||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#define DiagPutChar HalSerialPutcRtl8195a
|
||||
|
||||
|
||||
|
||||
#define u32 unsigned int
|
||||
#define IN
|
||||
#define u8 unsigned char
|
||||
#define s16 signed short int
|
||||
#define u16 unsigned short int
|
||||
typedef signed int s32;
|
||||
typedef unsigned char bool;
|
||||
typedef unsigned long long u64;
|
||||
typedef signed long long s64;
|
||||
#define SIZE_T unsigned int
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define in_range(c, lo, up) ((u8)c >= lo && (u8)c <= up)
|
||||
#define isprint(c) in_range(c, 0x20, 0x7f)
|
||||
#define isdigit(c) in_range(c, '0', '9')
|
||||
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
|
||||
#define islower(c) in_range(c, 'a', 'z')
|
||||
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == ',')
|
||||
#define ULLONG_MAX (~0ULL)
|
||||
#define USHRT_MAX ((u16)(~0U))
|
||||
#define KSTRTOX_OVERFLOW (1U << 31)
|
||||
#define SHRT_MAX ((s16)(USHRT_MAX>>1))
|
||||
|
||||
static inline char _tolower(const char c)
|
||||
{
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
|
||||
extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
|
||||
extern s64 div_s64(s64 dividend, s32 divisor);
|
||||
extern inline char _tolower(const char c);
|
||||
extern u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder);
|
||||
extern u64 div_u64(u64 dividend, u32 divisor);
|
||||
extern unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p);
|
||||
extern const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
|
||||
extern char *skip_spaces(const char *str);
|
||||
extern int skip_atoi(const char **s);
|
||||
|
||||
|
||||
static unsigned long long simple_strtoull_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
unsigned long long result;
|
||||
unsigned int rv;
|
||||
|
||||
cp = _parse_integer_fixup_radix(cp, &base);
|
||||
rv = _parse_integer(cp, base, &result);
|
||||
|
||||
|
||||
//troy delete
|
||||
/* FIXME */
|
||||
// cp += (rv & ~KSTRTOX_OVERFLOW);
|
||||
// if(endp)
|
||||
// *endp = (char *)cp;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static long long simple_strtoll_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoull_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
static unsigned long simple_strtoul_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
return simple_strtoull_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
static long simple_strtol_patch(const char *cp, char **endp, unsigned int base)
|
||||
{
|
||||
if(*cp == '-')
|
||||
return -simple_strtoul_patch(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoul_patch(cp, endp, base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int judge_digit_width(const char *str)
|
||||
{
|
||||
|
||||
int width = 0;
|
||||
while(isxdigit(*str)) {
|
||||
width++;
|
||||
str++;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
static int _vsscanf_patch(const char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
const char *str = buf;
|
||||
char *next;
|
||||
char digit;
|
||||
int num = 0;
|
||||
int i =0;
|
||||
u8 qualifier;
|
||||
unsigned int base;
|
||||
union {
|
||||
long long s;
|
||||
unsigned long long u;
|
||||
} val;
|
||||
s16 field_width;
|
||||
bool is_sign;
|
||||
|
||||
char str_store[20] = {0};
|
||||
|
||||
|
||||
|
||||
while(*fmt) {
|
||||
/* skip any white space in format */
|
||||
/* white space in format matchs any amount of
|
||||
* white space, including none, in the input.
|
||||
*/
|
||||
if(isspace(*fmt)) {
|
||||
fmt = skip_spaces(++fmt);
|
||||
str = skip_spaces(str);
|
||||
}
|
||||
|
||||
/* anything that is not a conversion must match exactly */
|
||||
if(*fmt != '%' && *fmt) {
|
||||
if(*fmt++ != *str++) {
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
++fmt;
|
||||
|
||||
/* skip this conversion.
|
||||
* advance both strings to next white space
|
||||
*/
|
||||
if(*fmt == '*') {
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(!isspace(*fmt) && *fmt != '%' && *fmt)
|
||||
fmt++;
|
||||
|
||||
while(!isspace(*str) && *str)
|
||||
str++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
|
||||
if(isdigit(*fmt)) {
|
||||
|
||||
field_width = skip_atoi(&fmt);
|
||||
|
||||
|
||||
|
||||
if(field_width <= 0) {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get conversion qualifier */
|
||||
qualifier = -1;
|
||||
|
||||
if(*fmt == 'h' || _tolower(*fmt) == 'l' ||
|
||||
_tolower(*fmt) == 'z') {
|
||||
qualifier = *fmt++;
|
||||
|
||||
if(qualifier == *fmt) {
|
||||
if(qualifier == 'h') {
|
||||
qualifier = 'H';
|
||||
fmt++;
|
||||
} else if(qualifier == 'l') {
|
||||
qualifier = 'L';
|
||||
fmt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!*fmt) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(*fmt == 'n') {
|
||||
/* return number of characters read so far */
|
||||
*va_arg(args, int *) = str - buf;
|
||||
++fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!*str) {
|
||||
break;
|
||||
}
|
||||
|
||||
base = 10;
|
||||
is_sign = 0;
|
||||
|
||||
switch(*fmt++) {
|
||||
case 'c': {
|
||||
char *s = (char *)va_arg(args, char*);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = 1;
|
||||
|
||||
do {
|
||||
*s++ = *str++;
|
||||
} while(--field_width > 0 && *str);
|
||||
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 's': {
|
||||
char *s = (char *)va_arg(args, char *);
|
||||
|
||||
if(field_width == -1)
|
||||
field_width = SHRT_MAX;
|
||||
|
||||
/* first, skip leading white space in buffer */
|
||||
str = skip_spaces(str);
|
||||
|
||||
/* now copy until next white space */
|
||||
while(*str && !isspace(*str) && field_width--) {
|
||||
*s++ = *str++;
|
||||
}
|
||||
|
||||
*s = '\0';
|
||||
num++;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
base = 0;
|
||||
|
||||
case 'd':
|
||||
is_sign = 1;
|
||||
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
case '%':
|
||||
|
||||
/* looking for '%' in str */
|
||||
if(*str++ != '%') {
|
||||
return num;
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
default:
|
||||
/* invalid format; stop here */
|
||||
return num;
|
||||
}
|
||||
|
||||
/* have some sort of integer conversion.
|
||||
* first, skip white space in buffer.
|
||||
*/
|
||||
str = skip_spaces(str);
|
||||
|
||||
digit = *str;
|
||||
|
||||
if(is_sign && digit == '-')
|
||||
digit = *(str + 1);
|
||||
|
||||
if(!digit
|
||||
|| (base == 16 && !isxdigit(digit))
|
||||
|| (base == 10 && !isdigit(digit))
|
||||
|| (base == 8 && (!isdigit(digit) || digit > '7'))
|
||||
|| (base == 0 && !isdigit(digit))) {
|
||||
break;
|
||||
}
|
||||
|
||||
//here problem *******************************************
|
||||
|
||||
|
||||
|
||||
//troy add ,fix support %2d, but not support %d
|
||||
if(field_width <= 0) {
|
||||
|
||||
field_width = judge_digit_width(str);
|
||||
}
|
||||
|
||||
|
||||
/////troy add, fix str passed inwidth wrong
|
||||
for(i = 0; i<field_width ;i++)
|
||||
str_store[i] = str[i];
|
||||
|
||||
next = (char*)str + field_width;
|
||||
|
||||
|
||||
|
||||
if(is_sign) {
|
||||
val.s = qualifier != 'L' ?
|
||||
simple_strtol_patch(str_store, &next, base) :
|
||||
simple_strtoll_patch(str_store, &next, base);
|
||||
} else {
|
||||
val.u = qualifier != 'L' ?
|
||||
simple_strtoul_patch(str_store, &next, base) :
|
||||
simple_strtoull_patch(str_store, &next, base);
|
||||
}
|
||||
|
||||
|
||||
////troy add
|
||||
for(i = 0; i<20 ;i++)
|
||||
str_store[i] = 0;
|
||||
|
||||
|
||||
//判断转换的字符串的宽度是否大于 %2d
|
||||
if(field_width > 0 && next - str > field_width) {
|
||||
if(base == 0)
|
||||
_parse_integer_fixup_radix(str, &base);
|
||||
|
||||
while(next - str > field_width) {
|
||||
if(is_sign) {
|
||||
val.s = div_s64(val.s, base);
|
||||
} else {
|
||||
val.u = div_u64(val.u, base);
|
||||
}
|
||||
|
||||
--next;
|
||||
}
|
||||
}
|
||||
|
||||
switch(qualifier) {
|
||||
case 'H': /* that's 'hh' in format */
|
||||
if(is_sign)
|
||||
*va_arg(args, signed char *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned char *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
if(is_sign)
|
||||
*va_arg(args, short *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned short *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
if(is_sign)
|
||||
*va_arg(args, long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
if(is_sign)
|
||||
*va_arg(args, long long *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned long long *) = val.u;
|
||||
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
case 'z':
|
||||
*va_arg(args, size_t *) = val.u;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(is_sign)
|
||||
*va_arg(args, int *) = val.s;
|
||||
else
|
||||
*va_arg(args, unsigned int *) = val.u;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
num++;
|
||||
|
||||
if(!next) {
|
||||
break;
|
||||
}
|
||||
|
||||
str = next;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
int DiagSscanfPatch(const char *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i = _vsscanf_patch(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char* DiagStrtokPatch(char *str, const char* delim) {
|
||||
static char* _buffer;
|
||||
if(str != NULL) _buffer = str;
|
||||
if(_buffer[0] == '\0') return NULL;
|
||||
|
||||
char *ret = _buffer, *b;
|
||||
const char *d;
|
||||
|
||||
for(b = _buffer; *b !='\0'; b++) {
|
||||
for(d = delim; *d != '\0'; d++) {
|
||||
if(*b == *d) {
|
||||
*b = '\0';
|
||||
_buffer = b+1;
|
||||
|
||||
// skip the beginning delimiters
|
||||
if(b == ret) {
|
||||
ret++;
|
||||
continue;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
char *DiagStrstrPatch(char *string, char *substring)
|
||||
{
|
||||
register char *a, *b;
|
||||
|
||||
/* First scan quickly through the two strings looking for a
|
||||
* single-character match. When it's found, then compare the
|
||||
* rest of the substring.
|
||||
*/
|
||||
|
||||
b = substring;
|
||||
if (*b == 0) {
|
||||
return string;
|
||||
}
|
||||
for ( ; *string != 0; string += 1) {
|
||||
if (*string != *b) {
|
||||
continue;
|
||||
}
|
||||
a = string;
|
||||
while (1) {
|
||||
if (*b == 0) {
|
||||
return string;
|
||||
}
|
||||
if (*a++ != *b++) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b = substring;
|
||||
}
|
||||
return (char *) 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...)
|
||||
{
|
||||
|
||||
va_list ap;
|
||||
char *p, *s, *buf_end = NULL;
|
||||
const int *dp = ((const int *)&fmt)+1;
|
||||
|
||||
if(buf == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
va_start(ap, fmt);
|
||||
s = buf;
|
||||
buf_end = size? (buf + size):(char*)~0;
|
||||
for ( ; *fmt != '\0'; ++fmt) {
|
||||
|
||||
if (*fmt != '%') {
|
||||
*s++ = *fmt;
|
||||
if(s >= buf_end){
|
||||
goto Exit;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*++fmt == 's') {
|
||||
for (p = (char *)*dp++; *p != '\0'; p++){
|
||||
*s++ = *p;
|
||||
|
||||
if(s >= buf_end){
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if ((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if ((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
if ((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
for (width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
if ((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
if (alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
while (h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
|
||||
if (shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
for ( ; shift >= 0; shift -= 4)
|
||||
*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
else if (*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
|
||||
|
||||
if (i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
p = q; /* save beginning of digits */
|
||||
|
||||
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while (i);
|
||||
|
||||
|
||||
for ( ; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
while (--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if (*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
/* now output the saved string */
|
||||
for (p = tmp; p < q; ++p){
|
||||
*s++ = *p;
|
||||
if(s >= buf_end){
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
if (buf)
|
||||
*s = '\0';
|
||||
|
||||
va_end(ap);
|
||||
return(s-buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
static int VSprintfPatch(char *buf, const char *fmt, const int *dp)
|
||||
{
|
||||
char *p, *s;
|
||||
s = buf;
|
||||
for ( ; *fmt != '\0'; ++fmt) {
|
||||
if (*fmt != '%') {
|
||||
buf ? *s++ = *fmt : DiagPutChar(*fmt);
|
||||
continue;
|
||||
}
|
||||
if (*++fmt == 's') {
|
||||
for (p = (char *)*dp++; *p != '\0'; p++)
|
||||
buf ? *s++ = *p : DiagPutChar(*p);
|
||||
}
|
||||
else { /* Length of item is bounded */
|
||||
char tmp[20], *q = tmp;
|
||||
int alt = 0;
|
||||
int shift = 0;// = 12;
|
||||
const long *lpforchk = (const long *)dp;
|
||||
|
||||
if ((*lpforchk) < 0x10) {
|
||||
shift = 0;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
|
||||
shift = 4;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
|
||||
shift = 8;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
|
||||
shift = 12;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
|
||||
shift = 16;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
|
||||
shift = 20;
|
||||
}
|
||||
else if (((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
|
||||
shift = 24;
|
||||
}
|
||||
else if ((*lpforchk) >= 0x10000000) {
|
||||
shift = 28;
|
||||
}
|
||||
else {
|
||||
shift = 28;
|
||||
}
|
||||
|
||||
#if 1 //wei patch for %02x
|
||||
if ((*fmt >= '0') && (*fmt <= '9'))
|
||||
{
|
||||
int width;
|
||||
unsigned char fch = *fmt;
|
||||
for (width=0; (fch>='0') && (fch<='9'); fch=*++fmt)
|
||||
{ width = width * 10 + fch - '0';
|
||||
}
|
||||
shift=(width-1)*4;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Before each format q points to tmp buffer
|
||||
* After each format q points past end of item
|
||||
*/
|
||||
|
||||
if ((*fmt == 'x')||(*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
|
||||
/* With x86 gcc, sizeof(long) == sizeof(int) */
|
||||
const long *lp = (const long *)dp;
|
||||
long h = *lp++;
|
||||
int hex_count = 0;
|
||||
unsigned long h_back = h;
|
||||
int ncase = (*fmt & 0x20);
|
||||
dp = (const int *)lp;
|
||||
if((*fmt == 'p') || (*fmt == 'P'))
|
||||
alt=1;
|
||||
if (alt) {
|
||||
*q++ = '0';
|
||||
*q++ = 'X' | ncase;
|
||||
}
|
||||
//hback 是实际得到的数据,hex_count是统计数据的HEX字符个数
|
||||
while (h_back) {
|
||||
hex_count += (h_back & 0xF) ? 1 : 0;
|
||||
h_back = h_back >> 4;
|
||||
}
|
||||
//这里修复 example: 字符有4个,但是用了%02x导致字符被截断的情况
|
||||
if (shift < (hex_count - 1)*4)
|
||||
shift = (hex_count - 1)*4;
|
||||
//printf("(%d,%d)", hex_count, shift);
|
||||
|
||||
for ( ; shift >= 0; shift -= 4) {
|
||||
|
||||
*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
|
||||
}
|
||||
|
||||
}
|
||||
else if (*fmt == 'd') {
|
||||
int i = *dp++;
|
||||
char *r;
|
||||
int digit_space = 0;
|
||||
if (i < 0) {
|
||||
*q++ = '-';
|
||||
i = -i;
|
||||
digit_space++;
|
||||
}
|
||||
p = q; /* save beginning of digits */
|
||||
do {
|
||||
*q++ = '0' + (i % 10);
|
||||
i /= 10;
|
||||
digit_space++;
|
||||
} while (i);
|
||||
//这里修复 example:用了%08d后,在数字前面没有0的情况
|
||||
for ( ; shift >= 0; shift -= 4) {
|
||||
|
||||
if(digit_space-- > 0) {
|
||||
; //do nothing
|
||||
} else {
|
||||
*q++ = '0';
|
||||
}
|
||||
}
|
||||
/* reverse digits, stop in middle */
|
||||
r = q; /* don't alter q */
|
||||
while (--r > p) {
|
||||
i = *r;
|
||||
*r = *p;
|
||||
*p++ = i;
|
||||
}
|
||||
}
|
||||
else if (*fmt == 'c')
|
||||
*q++ = *dp++;
|
||||
else
|
||||
*q++ = *fmt;
|
||||
/* now output the saved string */
|
||||
for (p = tmp; p < q; ++p){
|
||||
buf ? *s++ = *p : DiagPutChar(*p);
|
||||
if ((*p) == '\n') {
|
||||
DiagPutChar('\r');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf)
|
||||
*s = '\0';
|
||||
return (s - buf);
|
||||
}
|
||||
|
||||
|
||||
u32 DiagPrintfPatch(
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
(void)VSprintfPatch(0, fmt, ((const int *)&fmt)+1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 DiagSPrintfPatch(
|
||||
IN u8 *buf,
|
||||
IN const char *fmt, ...
|
||||
)
|
||||
{
|
||||
(void)VSprintfPatch((char*)buf, fmt, ((const int *)&fmt)+1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
578
component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
Normal file
578
component/common/api/wifi/rtw_wpa_supplicant/src/utils/os.h
Normal file
|
@ -0,0 +1,578 @@
|
|||
/*
|
||||
* OS specific functions
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef OS_H
|
||||
#define OS_H
|
||||
|
||||
//#include "basic_types.h"
|
||||
#include <autoconf.h>
|
||||
#include "osdep_service.h"
|
||||
#include "utils/rom/rom_wps_os.h"
|
||||
|
||||
typedef void* xqueue_handle_t;
|
||||
|
||||
typedef long os_time_t;
|
||||
|
||||
typedef _timer os_timer;
|
||||
|
||||
/**
|
||||
* os_sleep - Sleep (sec, usec)
|
||||
* @sec: Number of seconds to sleep
|
||||
* @usec: Number of microseconds to sleep
|
||||
*/
|
||||
void os_sleep(os_time_t sec, os_time_t usec);
|
||||
|
||||
struct os_time {
|
||||
os_time_t sec;
|
||||
os_time_t usec;
|
||||
};
|
||||
|
||||
struct os_reltime {
|
||||
os_time_t sec;
|
||||
os_time_t usec;
|
||||
};
|
||||
|
||||
/**
|
||||
* os_get_time - Get current time (sec, usec)
|
||||
* @t: Pointer to buffer for the time
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_time(struct os_time *t);
|
||||
|
||||
int os_get_reltime(struct os_reltime *t);
|
||||
/* Helper macros for handling struct os_time */
|
||||
/* (&timeout->time, &tmp->time) */
|
||||
#define os_time_before(a, b) \
|
||||
((a)->sec < (b)->sec || \
|
||||
((a)->sec == (b)->sec && (a)->usec < (b)->usec))
|
||||
|
||||
#define os_time_sub(a, b, res) do { \
|
||||
(res)->sec = (a)->sec - (b)->sec; \
|
||||
(res)->usec = (a)->usec - (b)->usec; \
|
||||
if ((res)->usec < 0) { \
|
||||
(res)->sec--; \
|
||||
(res)->usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* os_mktime - Convert broken-down time into seconds since 1970-01-01
|
||||
* @year: Four digit year
|
||||
* @month: Month (1 .. 12)
|
||||
* @day: Day of month (1 .. 31)
|
||||
* @hour: Hour (0 .. 23)
|
||||
* @min: Minute (0 .. 59)
|
||||
* @sec: Second (0 .. 60)
|
||||
* @t: Buffer for returning calendar time representation (seconds since
|
||||
* 1970-01-01 00:00:00)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
|
||||
* which is used by POSIX mktime().
|
||||
*/
|
||||
int os_mktime(int year, int month, int day, int hour, int min, int sec,
|
||||
os_time_t *t);
|
||||
|
||||
struct os_tm {
|
||||
int sec; /* 0..59 or 60 for leap seconds */
|
||||
int min; /* 0..59 */
|
||||
int hour; /* 0..23 */
|
||||
int day; /* 1..31 */
|
||||
int month; /* 1..12 */
|
||||
int year; /* Four digit year */
|
||||
};
|
||||
|
||||
int os_gmtime(os_time_t t, struct os_tm *tm);
|
||||
|
||||
/* Helpers for handling struct os_time */
|
||||
|
||||
/* Helpers for handling struct os_reltime */
|
||||
|
||||
static inline int os_reltime_before(struct os_reltime *a,
|
||||
struct os_reltime *b)
|
||||
{
|
||||
return os_time_before(a,b);
|
||||
}
|
||||
|
||||
|
||||
static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
|
||||
struct os_reltime *res)
|
||||
{
|
||||
os_time_sub(a,b,res);
|
||||
}
|
||||
|
||||
|
||||
static inline void os_reltime_age(struct os_reltime *start,
|
||||
struct os_reltime *age)
|
||||
{
|
||||
struct os_reltime now;
|
||||
|
||||
os_get_time((struct os_time *)&now);
|
||||
os_reltime_sub(&now, start, age);
|
||||
}
|
||||
|
||||
|
||||
static inline int os_reltime_expired(struct os_reltime *now,
|
||||
struct os_reltime *ts,
|
||||
os_time_t timeout_secs)
|
||||
{
|
||||
struct os_reltime age;
|
||||
|
||||
os_reltime_sub(now, ts, &age);
|
||||
return (age.sec > timeout_secs) ||
|
||||
(age.sec == timeout_secs && age.usec > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* os_daemonize - Run in the background (detach from the controlling terminal)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_daemonize(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_daemonize_terminate - Stop running in the background (remove pid file)
|
||||
* @pid_file: File name to write the process ID to or %NULL to skip this
|
||||
*/
|
||||
void os_daemonize_terminate(const char *pid_file);
|
||||
|
||||
/**
|
||||
* os_get_random - Get cryptographically strong pseudo random data
|
||||
* @buf: Buffer for pseudo random data
|
||||
* @len: Length of the buffer
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int os_get_random(unsigned char *buf, size_t len);
|
||||
|
||||
/**
|
||||
* os_random - Get pseudo random value (not necessarily very strong)
|
||||
* Returns: Pseudo random value
|
||||
*/
|
||||
unsigned long os_random(void);
|
||||
|
||||
/**
|
||||
* os_rel2abs_path - Get an absolute path for a file
|
||||
* @rel_path: Relative path to a file
|
||||
* Returns: Absolute path for the file or %NULL on failure
|
||||
*
|
||||
* This function tries to convert a relative path of a file to an absolute path
|
||||
* in order for the file to be found even if current working directory has
|
||||
* changed. The returned value is allocated and caller is responsible for
|
||||
* freeing it. It is acceptable to just return the same path in an allocated
|
||||
* buffer, e.g., return strdup(rel_path). This function is only used to find
|
||||
* configuration files when os_daemonize() may have changed the current working
|
||||
* directory and relative path would be pointing to a different location.
|
||||
*/
|
||||
char * os_rel2abs_path(const char *rel_path);
|
||||
|
||||
/**
|
||||
* os_program_init - Program initialization (called at start)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is called when a programs starts. If there are any OS specific
|
||||
* processing that is needed, it can be placed here. It is also acceptable to
|
||||
* just return 0 if not special processing is needed.
|
||||
*/
|
||||
int os_program_init(void);
|
||||
|
||||
/**
|
||||
* os_program_deinit - Program deinitialization (called just before exit)
|
||||
*
|
||||
* This function is called just before a program exists. If there are any OS
|
||||
* specific processing, e.g., freeing resourced allocated in os_program_init(),
|
||||
* it should be done here. It is also acceptable for this function to do
|
||||
* nothing.
|
||||
*/
|
||||
void os_program_deinit(void);
|
||||
|
||||
/**
|
||||
* os_setenv - Set environment variable
|
||||
* @name: Name of the variable
|
||||
* @value: Value to set to the variable
|
||||
* @overwrite: Whether existing variable should be overwritten
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_setenv(const char *name, const char *value, int overwrite);
|
||||
|
||||
/**
|
||||
* os_unsetenv - Delete environent variable
|
||||
* @name: Name of the variable
|
||||
* Returns: 0 on success, -1 on error
|
||||
*
|
||||
* This function is only used for wpa_cli action scripts. OS wrapper does not
|
||||
* need to implement this if such functionality is not needed.
|
||||
*/
|
||||
int os_unsetenv(const char *name);
|
||||
|
||||
/**
|
||||
* os_readfile - Read a file to an allocated memory buffer
|
||||
* @name: Name of the file to read
|
||||
* @len: For returning the length of the allocated buffer
|
||||
* Returns: Pointer to the allocated buffer or %NULL on failure
|
||||
*
|
||||
* This function allocates memory and reads the given file to this buffer. Both
|
||||
* binary and text files can be read with this function. The caller is
|
||||
* responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
char * os_readfile(const char *name, size_t *len);
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* os_zalloc - Allocate and zero memory
|
||||
* @size: Number of bytes to allocate
|
||||
* Returns: Pointer to allocated and zeroed memory or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
void * os_zalloc(size_t size);
|
||||
|
||||
/**
|
||||
* os_calloc - Allocate and zero memory for an array
|
||||
* @nmemb: Number of members in the array
|
||||
* @size: Number of bytes in each member
|
||||
* Returns: Pointer to allocated and zeroed memory or %NULL on failure
|
||||
*
|
||||
* This function can be used as a wrapper for os_zalloc(nmemb * size) when an
|
||||
* allocation is used for an array. The main benefit over os_zalloc() is in
|
||||
* having an extra check to catch integer overflows in multiplication.
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
static inline void * os_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
if (size && nmemb > (~(size_t) 0) / size)
|
||||
return NULL;
|
||||
return os_zalloc(nmemb * size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The following functions are wrapper for standard ANSI C or POSIX functions.
|
||||
* By default, they are just defined to use the standard function name and no
|
||||
* os_*.c implementation is needed for them. This avoids extra function calls
|
||||
* by allowing the C pre-processor take care of the function name mapping.
|
||||
*
|
||||
* If the target system uses a C library that does not provide these functions,
|
||||
* build_config.h can be used to define the wrappers to use a different
|
||||
* function name. This can be done on function-by-function basis since the
|
||||
* defines here are only used if build_config.h does not define the os_* name.
|
||||
* If needed, os_*.c file can be used to implement the functions that are not
|
||||
* included in the C library on the target system. Alternatively,
|
||||
* OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
|
||||
* these functions need to be implemented in os_*.c file for the target system.
|
||||
*/
|
||||
|
||||
#ifdef OS_NO_C_LIB_DEFINES
|
||||
|
||||
/**
|
||||
* os_malloc - Allocate dynamic memory
|
||||
* @size: Size of the buffer to allocate
|
||||
* Returns: Allocated buffer or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
void * os_malloc(size_t size);
|
||||
|
||||
/**
|
||||
* os_realloc - Re-allocate dynamic memory
|
||||
* @ptr: Old buffer from os_malloc() or os_realloc()
|
||||
* @size: Size of the new buffer
|
||||
* Returns: Allocated buffer or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
* If re-allocation fails, %NULL is returned and the original buffer (ptr) is
|
||||
* not freed and caller is still responsible for freeing it.
|
||||
*/
|
||||
void * os_realloc(void *ptr, size_t size);
|
||||
|
||||
/**
|
||||
* os_free - Free dynamic memory
|
||||
* @ptr: Old buffer from os_malloc() or os_realloc(); can be %NULL
|
||||
*/
|
||||
void os_free(void *ptr);
|
||||
|
||||
/**
|
||||
* os_memcpy - Copy memory area
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Number of bytes to copy
|
||||
* Returns: dest
|
||||
*
|
||||
* The memory areas src and dst must not overlap. os_memmove() can be used with
|
||||
* overlapping memory.
|
||||
*/
|
||||
void * os_memcpy(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_memmove - Copy memory area
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Number of bytes to copy
|
||||
* Returns: dest
|
||||
*
|
||||
* The memory areas src and dst may overlap.
|
||||
*/
|
||||
void *os_memmove(void *dest, const void *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_memset - Fill memory with a constant byte
|
||||
* @s: Memory area to be filled
|
||||
* @c: Constant byte
|
||||
* @n: Number of bytes started from s to fill with c
|
||||
* Returns: s
|
||||
*/
|
||||
void *os_memset(void *s, int c, size_t n);
|
||||
|
||||
/**
|
||||
* os_memcmp - Compare memory areas
|
||||
* @s1: First buffer
|
||||
* @s2: Second buffer
|
||||
* @n: Maximum numbers of octets to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strdup - Duplicate a string
|
||||
* @s: Source string
|
||||
* Returns: Allocated buffer with the string copied into it or %NULL on failure
|
||||
*
|
||||
* Caller is responsible for freeing the returned buffer with os_free().
|
||||
*/
|
||||
char *os_strdup(const char *s);
|
||||
|
||||
/**
|
||||
* os_strlen - Calculate the length of a string
|
||||
* @s: '\0' terminated string
|
||||
* Returns: Number of characters in s (not counting the '\0' terminator)
|
||||
*/
|
||||
size_t os_strlen(const char *s);
|
||||
|
||||
/**
|
||||
* os_strcasecmp - Compare two strings ignoring case
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greatred than s2
|
||||
*/
|
||||
int os_strcasecmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* os_strncasecmp - Compare two strings ignoring case
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* @n: Maximum numbers of characters to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strchr - Locate the first occurrence of a character in string
|
||||
* @s: String
|
||||
* @c: Character to search for
|
||||
* Returns: Pointer to the matched character or %NULL if not found
|
||||
*/
|
||||
char *os_strchr(const char *s, int c);
|
||||
|
||||
/**
|
||||
* os_strrchr - Locate the last occurrence of a character in string
|
||||
* @s: String
|
||||
* @c: Character to search for
|
||||
* Returns: Pointer to the matched character or %NULL if not found
|
||||
*/
|
||||
char *os_strrchr(const char *s, int c);
|
||||
|
||||
/**
|
||||
* os_strcmp - Compare two strings
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greatred than s2
|
||||
*/
|
||||
int os_strcmp(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* os_strncmp - Compare two strings
|
||||
* @s1: First string
|
||||
* @s2: Second string
|
||||
* @n: Maximum numbers of characters to compare
|
||||
* Returns: An integer less than, equal to, or greater than zero if s1 is
|
||||
* found to be less than, to match, or be greater than s2. Only first n
|
||||
* characters will be compared.
|
||||
*/
|
||||
int os_strncmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/**
|
||||
* os_strncpy - Copy a string
|
||||
* @dest: Destination
|
||||
* @src: Source
|
||||
* @n: Maximum number of characters to copy
|
||||
* Returns: dest
|
||||
*/
|
||||
char *os_strncpy(char *dest, const char *src, size_t n);
|
||||
|
||||
/**
|
||||
* os_strstr - Locate a substring
|
||||
* @haystack: String (haystack) to search from
|
||||
* @needle: Needle to search from haystack
|
||||
* Returns: Pointer to the beginning of the substring or %NULL if not found
|
||||
*/
|
||||
char *os_strstr(const char *haystack, const char *needle);
|
||||
|
||||
/**
|
||||
* os_snprintf - Print to a memory buffer
|
||||
* @str: Memory buffer to print into
|
||||
* @size: Maximum length of the str buffer
|
||||
* @format: printf format
|
||||
* Returns: Number of characters printed (not including trailing '\0').
|
||||
*
|
||||
* If the output buffer is truncated, number of characters which would have
|
||||
* been written is returned. Since some C libraries return -1 in such a case,
|
||||
* the caller must be prepared on that value, too, to indicate truncation.
|
||||
*
|
||||
* Note: Some C library implementations of snprintf() may not guarantee null
|
||||
* termination in case the output is truncated. The OS wrapper function of
|
||||
* os_snprintf() should provide this guarantee, i.e., to null terminate the
|
||||
* output buffer if a C library version of the function is used and if that
|
||||
* function does not guarantee null termination.
|
||||
*
|
||||
* If the target system does not include snprintf(), see, e.g.,
|
||||
* http://www.ijs.si/software/snprintf/ for an example of a portable
|
||||
* implementation of snprintf.
|
||||
*/
|
||||
int os_snprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
#else /* OS_NO_C_LIB_DEFINES */
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
u8* os_malloc(u32 sz);
|
||||
void os_mfree(u8 *pbuf, u32 sz);
|
||||
#ifndef os_free
|
||||
#define os_free(p, sz) os_mfree(((u8*)(p)), (sz))
|
||||
#endif
|
||||
#else
|
||||
#ifndef os_malloc
|
||||
#define os_malloc(sz) _rtw_malloc(sz)
|
||||
#endif
|
||||
#ifndef os_free
|
||||
#define os_free(p, sz) _rtw_mfree(((u8*)(p)), (sz))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
extern void *os_zalloc(size_t size);
|
||||
extern char *os_strdup(const char *string_copy_from);
|
||||
|
||||
#ifndef os_sleep
|
||||
#define os_sleep(s, us) rtw_mdelay_os((s)*1000 + (us)/1000)
|
||||
#endif
|
||||
#ifndef os_memcpy
|
||||
#define os_memcpy(d, s, n) rtw_memcpy((void*)(d), ((void*)(s)), (n))
|
||||
#endif
|
||||
#ifndef os_memmove
|
||||
#define os_memmove(d, s, n) memmove((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_memset
|
||||
#define os_memset(pbuf, c, sz) rtw_memset(pbuf, c, sz)
|
||||
#endif
|
||||
#ifndef os_memcmp
|
||||
#define os_memcmp(s1, s2, n) rtw_memcmp(((void*)(s1)), ((void*)(s2)), (n))
|
||||
#endif
|
||||
#ifndef os_memcmp_p2p
|
||||
#define os_memcmp_p2p(s1, s2, n) memcmp((s1), (s2), (n))
|
||||
#endif
|
||||
#ifndef os_get_random_bytes
|
||||
#define os_get_random_bytes(d,sz) rtw_get_random_bytes(((void*)(d)), (sz))
|
||||
#endif
|
||||
#ifndef os_strlen
|
||||
#define os_strlen(s) strlen(s)
|
||||
#endif
|
||||
#ifndef os_strcasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
|
||||
#else
|
||||
#define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_strncasecmp
|
||||
#ifdef _MSC_VER
|
||||
#define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
|
||||
#else
|
||||
#define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef os_init_timer
|
||||
#define os_init_timer(t, p, f, x, n) rtw_init_timer((t), (p), (f), (x), (n))
|
||||
#endif
|
||||
#ifndef os_set_timer
|
||||
#define os_set_timer(t, d) rtw_set_timer((t), (d))
|
||||
#endif
|
||||
#ifndef os_cancel_timer
|
||||
#define os_cancel_timer(t) rtw_cancel_timer(t)
|
||||
#endif
|
||||
#ifndef os_del_timer
|
||||
#define os_del_timer(t) rtw_del_timer(t)
|
||||
#endif
|
||||
#ifndef os_atoi
|
||||
#define os_atoi(s) rtw_atoi(s)
|
||||
#endif
|
||||
|
||||
#ifndef os_strchr
|
||||
#define os_strchr(s, c) strchr((s), (c))
|
||||
#endif
|
||||
#ifndef os_strcmp
|
||||
#define os_strcmp(s1, s2) strcmp((s1), (s2))
|
||||
#endif
|
||||
#ifndef os_strncmp
|
||||
#define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
|
||||
#endif
|
||||
#ifndef os_strncpy
|
||||
#define os_strncpy(d, s, n) strncpy((d), (s), (n))
|
||||
#endif
|
||||
#ifndef os_strrchr
|
||||
#define os_strrchr(s, c) strrchr((s), (c))
|
||||
#endif
|
||||
#ifndef os_strstr
|
||||
#define os_strstr(h, n) strstr((h), (n))
|
||||
#endif
|
||||
|
||||
#ifndef os_snprintf
|
||||
#ifdef _MSC_VER
|
||||
#define os_snprintf _snprintf
|
||||
#else
|
||||
#define os_snprintf snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* OS_NO_C_LIB_DEFINES */
|
||||
|
||||
|
||||
static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
|
||||
{
|
||||
if (size && nmemb > (~(size_t) 0) / size)
|
||||
return NULL;
|
||||
return os_realloc(ptr, nmemb * size, nmemb * size);
|
||||
}
|
||||
|
||||
void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize) ;
|
||||
|
||||
int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait);
|
||||
|
||||
void os_xqueue_delete(xqueue_handle_t xQueue );
|
||||
|
||||
int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait);
|
||||
|
||||
|
||||
#endif /* OS_H */
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* OS specific functions for UNIX/POSIX systems
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
#include <autoconf.h>
|
||||
|
||||
#ifdef CONFIG_WPS
|
||||
#include "utils/os.h"
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
_list wpa_mem_table;
|
||||
int wpa_mem_used_num;
|
||||
//int wpa_mem_used_size;
|
||||
#endif
|
||||
extern int min_free_heap_size;
|
||||
u8* os_malloc(u32 sz)
|
||||
{
|
||||
int free_heap_size = rtw_getFreeHeapSize();
|
||||
u8 *pbuf = _rtw_malloc(sz);
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
add_mem_usage(&wpa_mem_table, pbuf, sz, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
|
||||
#else
|
||||
add_mem_usage(NULL, pbuf, sz, NULL, MEM_MONITOR_FLAG_WPAS);
|
||||
#endif
|
||||
if(min_free_heap_size > free_heap_size)
|
||||
min_free_heap_size = free_heap_size;
|
||||
return pbuf;
|
||||
}
|
||||
|
||||
void os_mfree(u8 *pbuf, u32 sz)
|
||||
{
|
||||
_rtw_mfree(pbuf, sz);
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
del_mem_usage(&wpa_mem_table, pbuf, &wpa_mem_used_num, MEM_MONITOR_FLAG_WPAS);
|
||||
#else
|
||||
del_mem_usage(NULL, pbuf, NULL, MEM_MONITOR_FLAG_WPAS);
|
||||
#endif
|
||||
}
|
||||
#endif//CONFIG_MEM_MONITOR
|
||||
|
||||
#endif// !defined(CONFIG_PLATFORM_8195A)
|
||||
|
||||
#ifndef OS_NO_C_LIB_DEFINES
|
||||
char *os_strdup(const char *string_copy_from)
|
||||
{
|
||||
char *string_copy_to = NULL;
|
||||
string_copy_to = os_zalloc(strlen(string_copy_from) + 1);
|
||||
os_memcpy((void *)string_copy_to, string_copy_from, strlen(string_copy_from));
|
||||
string_copy_to[strlen(string_copy_from)] = '\0';
|
||||
return string_copy_to;
|
||||
}
|
||||
#endif
|
||||
|
||||
int os_get_random(unsigned char *buf, size_t len)
|
||||
{
|
||||
//TODO implement it
|
||||
rtw_get_random_bytes(buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_get_time(struct os_time *t){
|
||||
unsigned int tt = rtw_get_current_time();
|
||||
t->sec = (os_time_t) (tt / 1000);
|
||||
t->usec = (os_time_t) (tt % 1000)*1000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int os_get_reltime(struct os_reltime *t){
|
||||
os_get_time((struct os_time *)t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *os_xqueue_create(unsigned long uxQueueLength, unsigned long uxItemSize)
|
||||
{
|
||||
return xQueueCreate( uxQueueLength, uxItemSize );
|
||||
}
|
||||
|
||||
int os_xqueue_receive(xqueue_handle_t xQueue, void * const pvBuffer, unsigned long xSecsToWait)
|
||||
{
|
||||
return xQueueReceive((xQueueHandle)xQueue, pvBuffer, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
|
||||
}
|
||||
|
||||
void os_xqueue_delete(xqueue_handle_t xQueue )
|
||||
{
|
||||
vQueueDelete((xQueueHandle)xQueue);
|
||||
}
|
||||
|
||||
int os_xqueue_send(xqueue_handle_t xQueue, const void * const pvItemToQueue, unsigned long xSecsToWait)
|
||||
{
|
||||
return xQueueSendToBack((xQueueHandle)xQueue, pvItemToQueue, (portTickType)(xSecsToWait*configTICK_RATE_HZ));
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* OS specific functions
|
||||
* Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef ROM_WPS_OS_H
|
||||
#define ROM_WPS_OS_H
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
|
||||
#include <rom_wlan_ram_map.h>
|
||||
extern struct _rom_wlan_ram_map rom_wlan_ram_map;
|
||||
#define os_malloc(sz) rom_wlan_ram_map.rtw_malloc(sz)
|
||||
#define os_free(p, sz) rom_wlan_ram_map.rtw_mfree(((u8*)(p)), (sz))
|
||||
|
||||
#endif
|
||||
|
||||
extern u8 *WPS_realloc(u8 *old_buf, u32 old_sz, u32 new_sz);
|
||||
#define os_realloc(p, os, ns) WPS_realloc(((u8*)(p)),(os),(ns))
|
||||
|
||||
#endif /* ROM_WPS_OS_H */
|
319
component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
Normal file
319
component/common/api/wifi/rtw_wpa_supplicant/src/wps/wps_defs.h
Normal file
|
@ -0,0 +1,319 @@
|
|||
|
||||
/*
|
||||
* Wi-Fi Protected Setup - message definitions
|
||||
* Copyright (c) 2008, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#ifndef WPS_DEFS_H
|
||||
#define WPS_DEFS_H
|
||||
|
||||
|
||||
/* Diffie-Hellman 1536-bit MODP Group; RFC 3526, Group 5 */
|
||||
#define WPS_DH_GROUP (5)
|
||||
|
||||
#define WPS_UUID_LEN (16)
|
||||
#define WPS_NONCE_LEN (16)
|
||||
#define WPS_AUTHENTICATOR_LEN (8)
|
||||
#define WPS_AUTHKEY_LEN (32)
|
||||
#define WPS_KEYWRAPKEY_LEN (16)
|
||||
#define WPS_EMSK_LEN (32)
|
||||
#define WPS_PSK_LEN (16)
|
||||
#define WPS_SECRET_NONCE_LEN (16)
|
||||
#define WPS_HASH_LEN (32)
|
||||
#define WPS_KWA_LEN (8)
|
||||
#define WPS_MGMTAUTHKEY_LEN (32)
|
||||
#define WPS_MGMTENCKEY_LEN (16)
|
||||
#define WPS_MGMT_KEY_ID_LEN (16)
|
||||
#define WPS_OOB_DEVICE_PASSWORD_MIN_LEN (16)
|
||||
#define WPS_OOB_DEVICE_PASSWORD_LEN (32)
|
||||
#define WPS_OOB_PUBKEY_HASH_LEN (20)
|
||||
|
||||
/* Attribute Types */
|
||||
enum wps_attribute {
|
||||
ATTR_AP_CHANNEL = 0x1001,
|
||||
ATTR_ASSOC_STATE = 0x1002,
|
||||
ATTR_AUTH_TYPE = 0x1003,
|
||||
ATTR_AUTH_TYPE_FLAGS = 0x1004,
|
||||
ATTR_AUTHENTICATOR = 0x1005,
|
||||
ATTR_CONFIG_METHODS = 0x1008,
|
||||
ATTR_CONFIG_ERROR = 0x1009,
|
||||
ATTR_CONFIRM_URL4 = 0x100a,
|
||||
ATTR_CONFIRM_URL6 = 0x100b,
|
||||
ATTR_CONN_TYPE = 0x100c,
|
||||
ATTR_CONN_TYPE_FLAGS = 0x100d,
|
||||
ATTR_CRED = 0x100e,
|
||||
ATTR_ENCR_TYPE = 0x100f,
|
||||
ATTR_ENCR_TYPE_FLAGS = 0x1010,
|
||||
ATTR_DEV_NAME = 0x1011,
|
||||
ATTR_DEV_PASSWORD_ID = 0x1012,
|
||||
ATTR_E_HASH1 = 0x1014,
|
||||
ATTR_E_HASH2 = 0x1015,
|
||||
ATTR_E_SNONCE1 = 0x1016,
|
||||
ATTR_E_SNONCE2 = 0x1017,
|
||||
ATTR_ENCR_SETTINGS = 0x1018,
|
||||
ATTR_ENROLLEE_NONCE = 0x101a,
|
||||
ATTR_FEATURE_ID = 0x101b,
|
||||
ATTR_IDENTITY = 0x101c,
|
||||
ATTR_IDENTITY_PROOF = 0x101d,
|
||||
ATTR_KEY_WRAP_AUTH = 0x101e,
|
||||
ATTR_KEY_ID = 0x101f,
|
||||
ATTR_MAC_ADDR = 0x1020,
|
||||
ATTR_MANUFACTURER = 0x1021,
|
||||
ATTR_MSG_TYPE = 0x1022,
|
||||
ATTR_MODEL_NAME = 0x1023,
|
||||
ATTR_MODEL_NUMBER = 0x1024,
|
||||
ATTR_NETWORK_INDEX = 0x1026,
|
||||
ATTR_NETWORK_KEY = 0x1027,
|
||||
ATTR_NETWORK_KEY_INDEX = 0x1028,
|
||||
ATTR_NEW_DEVICE_NAME = 0x1029,
|
||||
ATTR_NEW_PASSWORD = 0x102a,
|
||||
ATTR_OOB_DEVICE_PASSWORD = 0x102c,
|
||||
ATTR_OS_VERSION = 0x102d,
|
||||
ATTR_POWER_LEVEL = 0x102f,
|
||||
ATTR_PSK_CURRENT = 0x1030,
|
||||
ATTR_PSK_MAX = 0x1031,
|
||||
ATTR_PUBLIC_KEY = 0x1032,
|
||||
ATTR_RADIO_ENABLE = 0x1033,
|
||||
ATTR_REBOOT = 0x1034,
|
||||
ATTR_REGISTRAR_CURRENT = 0x1035,
|
||||
ATTR_REGISTRAR_ESTABLISHED = 0x1036,
|
||||
ATTR_REGISTRAR_LIST = 0x1037,
|
||||
ATTR_REGISTRAR_MAX = 0x1038,
|
||||
ATTR_REGISTRAR_NONCE = 0x1039,
|
||||
ATTR_REQUEST_TYPE = 0x103a,
|
||||
ATTR_RESPONSE_TYPE = 0x103b,
|
||||
ATTR_RF_BANDS = 0x103c,
|
||||
ATTR_R_HASH1 = 0x103d,
|
||||
ATTR_R_HASH2 = 0x103e,
|
||||
ATTR_R_SNONCE1 = 0x103f,
|
||||
ATTR_R_SNONCE2 = 0x1040,
|
||||
ATTR_SELECTED_REGISTRAR = 0x1041,
|
||||
ATTR_SERIAL_NUMBER = 0x1042,
|
||||
ATTR_WPS_STATE = 0x1044,
|
||||
ATTR_SSID = 0x1045,
|
||||
ATTR_TOTAL_NETWORKS = 0x1046,
|
||||
ATTR_UUID_E = 0x1047,
|
||||
ATTR_UUID_R = 0x1048,
|
||||
ATTR_VENDOR_EXT = 0x1049,
|
||||
ATTR_VERSION = 0x104a,
|
||||
ATTR_X509_CERT_REQ = 0x104b,
|
||||
ATTR_X509_CERT = 0x104c,
|
||||
ATTR_EAP_IDENTITY = 0x104d,
|
||||
ATTR_MSG_COUNTER = 0x104e,
|
||||
ATTR_PUBKEY_HASH = 0x104f,
|
||||
ATTR_REKEY_KEY = 0x1050,
|
||||
ATTR_KEY_LIFETIME = 0x1051,
|
||||
ATTR_PERMITTED_CFG_METHODS = 0x1052,
|
||||
ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053,
|
||||
ATTR_PRIMARY_DEV_TYPE = 0x1054,
|
||||
ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055,
|
||||
ATTR_PORTABLE_DEV = 0x1056,
|
||||
ATTR_AP_SETUP_LOCKED = 0x1057,
|
||||
ATTR_APPLICATION_EXT = 0x1058,
|
||||
ATTR_EAP_TYPE = 0x1059,
|
||||
ATTR_IV = 0x1060,
|
||||
ATTR_KEY_PROVIDED_AUTO = 0x1061,
|
||||
ATTR_802_1X_ENABLED = 0x1062,
|
||||
ATTR_APPSESSIONKEY = 0x1063,
|
||||
ATTR_WEPTRANSMITKEY = 0x1064,
|
||||
ATTR_REQUESTED_DEV_TYPE = 0x106a,
|
||||
ATTR_EXTENSIBILITY_TEST = 0x10fa /* _NOT_ defined in the spec */
|
||||
};
|
||||
|
||||
#define WPS_VENDOR_ID_WFA 14122
|
||||
|
||||
/* WFA Vendor Extension subelements */
|
||||
enum {
|
||||
WFA_ELEM_VERSION2 = 0x00,
|
||||
WFA_ELEM_AUTHORIZEDMACS = 0x01,
|
||||
WFA_ELEM_NETWORK_KEY_SHAREABLE = 0x02,
|
||||
WFA_ELEM_REQUEST_TO_ENROLL = 0x03,
|
||||
WFA_ELEM_SETTINGS_DELAY_TIME = 0x04
|
||||
};
|
||||
|
||||
/* Device Password ID */
|
||||
enum wps_dev_password_id {
|
||||
DEV_PW_DEFAULT = 0x0000,
|
||||
DEV_PW_USER_SPECIFIED = 0x0001,
|
||||
DEV_PW_MACHINE_SPECIFIED = 0x0002,
|
||||
DEV_PW_REKEY = 0x0003,
|
||||
DEV_PW_PUSHBUTTON = 0x0004,
|
||||
DEV_PW_REGISTRAR_SPECIFIED = 0x0005
|
||||
};
|
||||
|
||||
/* Message Type */
|
||||
enum wps_msg_type {
|
||||
WPS_START = 0x00,
|
||||
WPS_Beacon = 0x01,
|
||||
WPS_ProbeRequest = 0x02,
|
||||
WPS_ProbeResponse = 0x03,
|
||||
WPS_M1 = 0x04,
|
||||
WPS_M2 = 0x05,
|
||||
WPS_M2D = 0x06,
|
||||
WPS_M3 = 0x07,
|
||||
WPS_M4 = 0x08,
|
||||
WPS_M5 = 0x09,
|
||||
WPS_M6 = 0x0a,
|
||||
WPS_M7 = 0x0b,
|
||||
WPS_M8 = 0x0c,
|
||||
WPS_WSC_ACK = 0x0d,
|
||||
WPS_WSC_NACK = 0x0e,
|
||||
WPS_WSC_DONE = 0x0f
|
||||
};
|
||||
|
||||
/* Authentication Type Flags */
|
||||
#define WPS_AUTH_OPEN 0x0001
|
||||
#define WPS_AUTH_WPAPSK 0x0002
|
||||
#define WPS_AUTH_SHARED 0x0004
|
||||
#define WPS_AUTH_WPA 0x0008
|
||||
#define WPS_AUTH_WPA2 0x0010
|
||||
#define WPS_AUTH_WPA2PSK 0x0020
|
||||
#define WPS_AUTH_TYPES (WPS_AUTH_OPEN | WPS_AUTH_WPAPSK | WPS_AUTH_SHARED | \
|
||||
WPS_AUTH_WPA | WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)
|
||||
|
||||
/* Encryption Type Flags */
|
||||
#define WPS_ENCR_NONE 0x0001
|
||||
#define WPS_ENCR_WEP 0x0002
|
||||
#define WPS_ENCR_TKIP 0x0004
|
||||
#define WPS_ENCR_AES 0x0008
|
||||
#define WPS_ENCR_TYPES (WPS_ENCR_NONE | WPS_ENCR_WEP | WPS_ENCR_TKIP | \
|
||||
WPS_ENCR_AES)
|
||||
|
||||
/* Configuration Error */
|
||||
enum wps_config_error {
|
||||
WPS_CFG_NO_ERROR = 0,
|
||||
WPS_CFG_OOB_IFACE_READ_ERROR = 1,
|
||||
WPS_CFG_DECRYPTION_CRC_FAILURE = 2,
|
||||
WPS_CFG_24_CHAN_NOT_SUPPORTED = 3,
|
||||
WPS_CFG_50_CHAN_NOT_SUPPORTED = 4,
|
||||
WPS_CFG_SIGNAL_TOO_WEAK = 5,
|
||||
WPS_CFG_NETWORK_AUTH_FAILURE = 6,
|
||||
WPS_CFG_NETWORK_ASSOC_FAILURE = 7,
|
||||
WPS_CFG_NO_DHCP_RESPONSE = 8,
|
||||
WPS_CFG_FAILED_DHCP_CONFIG = 9,
|
||||
WPS_CFG_IP_ADDR_CONFLICT = 10,
|
||||
WPS_CFG_NO_CONN_TO_REGISTRAR = 11,
|
||||
WPS_CFG_MULTIPLE_PBC_DETECTED = 12,
|
||||
WPS_CFG_ROGUE_SUSPECTED = 13,
|
||||
WPS_CFG_DEVICE_BUSY = 14,
|
||||
WPS_CFG_SETUP_LOCKED = 15,
|
||||
WPS_CFG_MSG_TIMEOUT = 16,
|
||||
WPS_CFG_REG_SESS_TIMEOUT = 17,
|
||||
WPS_CFG_DEV_PASSWORD_AUTH_FAILURE = 18
|
||||
};
|
||||
|
||||
/* RF Bands */
|
||||
#define WPS_RF_24GHZ (0x01)
|
||||
#define WPS_RF_50GHZ (0x02)
|
||||
|
||||
/* Config Methods */
|
||||
#define WPS_CONFIG_USBA (0x0001)
|
||||
#define WPS_CONFIG_ETHERNET (0x0002)
|
||||
#define WPS_CONFIG_LABEL (0x0004)
|
||||
#define WPS_CONFIG_DISPLAY (0x0008)
|
||||
#define WPS_CONFIG_EXT_NFC_TOKEN (0x0010)
|
||||
#define WPS_CONFIG_INT_NFC_TOKEN (0x0020)
|
||||
#define WPS_CONFIG_NFC_INTERFACE (0x0040)
|
||||
#define WPS_CONFIG_PUSHBUTTON (0x0080)
|
||||
#define WPS_CONFIG_KEYPAD (0x0100)
|
||||
|
||||
#ifdef CONFIG_WPS2
|
||||
#define WPS_CONFIG_VIRT_PUSHBUTTON (0x0280)
|
||||
#define WPS_CONFIG_PHY_PUSHBUTTON (0x0480)
|
||||
#define WPS_CONFIG_VIRT_DISPLAY (0x2008)
|
||||
#define WPS_CONFIG_PHY_DISPLAY (0x4008)
|
||||
#endif /* CONFIG_WPS2 */
|
||||
|
||||
/* Connection Type Flags */
|
||||
#define WPS_CONN_ESS (0x01)
|
||||
#define WPS_CONN_IBSS (0x02)
|
||||
|
||||
/* Wi-Fi Protected Setup State */
|
||||
enum wps_state {
|
||||
WPS_STATE_NOT_CONFIGURED = 1,
|
||||
WPS_STATE_CONFIGURED = 2
|
||||
};
|
||||
|
||||
/* Association State */
|
||||
enum wps_assoc_state {
|
||||
WPS_ASSOC_NOT_ASSOC = 0,
|
||||
WPS_ASSOC_CONN_SUCCESS = 1,
|
||||
WPS_ASSOC_CFG_FAILURE = 2,
|
||||
WPS_ASSOC_FAILURE = 3,
|
||||
WPS_ASSOC_IP_FAILURE = 4
|
||||
};
|
||||
|
||||
|
||||
#define WPS_DEV_OUI_WFA (0x0050f204)
|
||||
|
||||
enum wps_dev_categ {
|
||||
WPS_DEV_COMPUTER = 1,
|
||||
WPS_DEV_INPUT = 2,
|
||||
WPS_DEV_PRINTER = 3,
|
||||
WPS_DEV_CAMERA = 4,
|
||||
WPS_DEV_STORAGE = 5,
|
||||
WPS_DEV_NETWORK_INFRA = 6,
|
||||
WPS_DEV_DISPLAY = 7,
|
||||
WPS_DEV_MULTIMEDIA = 8,
|
||||
WPS_DEV_GAMING = 9,
|
||||
WPS_DEV_PHONE = 10
|
||||
};
|
||||
|
||||
enum wps_dev_subcateg {
|
||||
WPS_DEV_COMPUTER_PC = 1,
|
||||
WPS_DEV_COMPUTER_SERVER = 2,
|
||||
WPS_DEV_COMPUTER_MEDIA_CENTER = 3,
|
||||
|
||||
WPS_DEV_PRINTER_PRINTER = 1,
|
||||
WPS_DEV_PRINTER_SCANNER = 2,
|
||||
|
||||
WPS_DEV_CAMERA_DIGITAL_STILL_CAMERA = 1,
|
||||
|
||||
WPS_DEV_STORAGE_NAS = 1,
|
||||
|
||||
WPS_DEV_NETWORK_INFRA_AP = 1,
|
||||
WPS_DEV_NETWORK_INFRA_ROUTER = 2,
|
||||
WPS_DEV_NETWORK_INFRA_SWITCH = 3,
|
||||
|
||||
WPS_DEV_DISPLAY_TV = 1,
|
||||
WPS_DEV_DISPLAY_PICTURE_FRAME = 2,
|
||||
WPS_DEV_DISPLAY_PROJECTOR = 3,
|
||||
|
||||
WPS_DEV_MULTIMEDIA_DAR = 1,
|
||||
WPS_DEV_MULTIMEDIA_PVR = 2,
|
||||
WPS_DEV_MULTIMEDIA_MCX = 3,
|
||||
|
||||
WPS_DEV_GAMING_XBOX = 1,
|
||||
WPS_DEV_GAMING_XBOX360 = 2,
|
||||
WPS_DEV_GAMING_PLAYSTATION = 3,
|
||||
|
||||
WPS_DEV_PHONE_WINDOWS_MOBILE = 1
|
||||
};
|
||||
|
||||
|
||||
/* Request Type */
|
||||
enum wps_request_type {
|
||||
WPS_REQ_ENROLLEE_INFO = 0,
|
||||
WPS_REQ_ENROLLEE = 1,
|
||||
WPS_REQ_REGISTRAR = 2,
|
||||
WPS_REQ_WLAN_MANAGER_REGISTRAR = 3
|
||||
};
|
||||
|
||||
/* Response Type */
|
||||
enum wps_response_type {
|
||||
WPS_RESP_ENROLLEE_INFO = 0,
|
||||
WPS_RESP_ENROLLEE = 1,
|
||||
WPS_RESP_REGISTRAR = 2,
|
||||
WPS_RESP_AP = 3
|
||||
};
|
||||
|
||||
/* Walk Time for push button configuration (in seconds) */
|
||||
#define WPS_PBC_WALK_TIME (120)
|
||||
|
||||
#define WPS_MAX_AUTHORIZED_MACS (5)
|
||||
|
||||
#endif /* WPS_DEFS_H */
|
||||
|
|
@ -0,0 +1,528 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "queue.h"
|
||||
#include "utils/os.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
#include "wifi/wifi_conf.h"
|
||||
#include "wps/wps_defs.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
/**
|
||||
* struct wps_credential - WPS Credential
|
||||
* @ssid: SSID
|
||||
* @ssid_len: Length of SSID
|
||||
* @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
|
||||
* @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
|
||||
* @key_idx: Key index
|
||||
* @key: Key
|
||||
* @key_len: Key length in octets
|
||||
* @mac_addr: MAC address of the Credential receiver
|
||||
* @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
|
||||
* this may be %NULL, if not used
|
||||
* @cred_attr_len: Length of cred_attr in octets
|
||||
* @ap_channel: AP channel
|
||||
*/
|
||||
struct dev_credential {
|
||||
u8 ssid[32];
|
||||
size_t ssid_len;
|
||||
u16 auth_type;
|
||||
u16 encr_type;
|
||||
u8 key_idx;
|
||||
u8 key[65];
|
||||
size_t key_len;
|
||||
u8 mac_addr[6];
|
||||
const u8 *cred_attr;
|
||||
size_t cred_attr_len;
|
||||
u16 ap_channel;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *target_ssid;
|
||||
u16 config_method;
|
||||
_sema scan_sema;
|
||||
int isoverlap;
|
||||
} internal_wps_scan_handler_arg_t;
|
||||
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#ifndef ENABLE
|
||||
#define ENABLE (1)
|
||||
#endif
|
||||
#ifndef DISABLE
|
||||
#define DISABLE (0)
|
||||
#endif
|
||||
#define STACKSIZE 512
|
||||
|
||||
|
||||
//static xSemaphoreHandle wps_reconnect_semaphore;
|
||||
//static struct _WIFI_NETWORK wifi_get_from_certificate = {0};
|
||||
|
||||
#define WPS_AUTH_TYPE_OPEN (0x0001)
|
||||
#define WPS_AUTH_TYPE_WPA_PERSONAL (0x0002)
|
||||
#define WPS_AUTH_TYPE_WPA_ENTERPRISE (0x0008)
|
||||
#define WPS_AUTH_TYPE_WPA2_PERSONAL (0x0010)
|
||||
#define WPS_AUTH_TYPE_WPA2_ENTERPRISE (0x0020)
|
||||
|
||||
#define WIFI_LINK_DISCONNECTED (0)
|
||||
#define WIFI_LINK_CONNECTED (1)
|
||||
#define SCAN_BUFFER_LENGTH (4096)
|
||||
|
||||
|
||||
#ifdef CONFIG_WPS
|
||||
#if CONFIG_ENABLE_WPS
|
||||
xqueue_handle_t queue_for_credential;
|
||||
char wps_pin_code[32];
|
||||
u16 config_method;
|
||||
u8 wps_password_id;
|
||||
|
||||
void wps_check_and_show_connection_info(void)
|
||||
{
|
||||
rtw_wifi_setting_t setting;
|
||||
#if CONFIG_LWIP_LAYER
|
||||
/* Start DHCP Client */
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
#endif
|
||||
wifi_get_setting(WLAN0_NAME, &setting);
|
||||
wifi_show_setting(WLAN0_NAME, &setting);
|
||||
}
|
||||
|
||||
static void wps_config_wifi_setting(rtw_network_info_t *wifi, struct dev_credential *dev_cred)
|
||||
{
|
||||
printf("\r\nwps_config_wifi_setting\n");
|
||||
//memcpy((void *)wifi->ssid, (void *)dev_cred->ssid, dev_cred->ssid_len);
|
||||
strcpy((char*)wifi->ssid.val, (char*)&dev_cred->ssid[0]);
|
||||
printf("\r\nwps_wifi.ssid = %s\n", wifi->ssid.val);
|
||||
wifi->ssid.len = dev_cred->ssid_len;
|
||||
printf("\r\nwps_wifi.ssid_len = %d\n", wifi->ssid.len);
|
||||
|
||||
switch(dev_cred->auth_type) {
|
||||
case WPS_AUTH_TYPE_OPEN :
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_OPEN\n");
|
||||
wifi->security_type = RTW_SECURITY_OPEN;
|
||||
break;
|
||||
case WPS_AUTH_TYPE_WPA_PERSONAL :
|
||||
case WPS_AUTH_TYPE_WPA_ENTERPRISE :
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_WPA_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA_AES_PSK;
|
||||
break;
|
||||
case WPS_AUTH_TYPE_WPA2_PERSONAL :
|
||||
case WPS_AUTH_TYPE_WPA2_ENTERPRISE :
|
||||
printf("\r\nsecurity_type = RTW_SECURITY_WPA2_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\r\nwps_wifi.security_type = %d\n", wifi->security_type);
|
||||
|
||||
//memcpy(wifi->password, dev_cred->key, dev_cred->key_len);
|
||||
wifi->password = dev_cred->key;
|
||||
printf("\r\nwps_wifi.password = %s\n", wifi->password);
|
||||
wifi->password_len = dev_cred->key_len;
|
||||
printf("\r\nwps_wifi.password_len = %d", wifi->password_len);
|
||||
//xSemaphoreGive(wps_reconnect_semaphore);
|
||||
//printf("\r\nrelease wps_reconnect_semaphore");
|
||||
}
|
||||
|
||||
static void wps_connect_to_AP_by_certificate(rtw_network_info_t *wifi)
|
||||
{
|
||||
#define RETRY_COUNT 3
|
||||
int retry_count = RETRY_COUNT, ret;
|
||||
|
||||
printf("\r\n=============== wifi_certificate_info ===============\n");
|
||||
printf("\r\nwps_wifi.ssid = %s\n", wifi->ssid.val);
|
||||
printf("\r\nsecurity_type = %d\n", wifi->security_type);
|
||||
printf("\r\nwps_wifi.password = %s\n", wifi->password);
|
||||
printf("\r\nssid_len = %d\n", wifi->ssid.len);
|
||||
printf("\r\npassword_len = %d\n", wifi->password_len);
|
||||
while (1) {
|
||||
ret = wifi_connect((char*)wifi->ssid.val,
|
||||
wifi->security_type,
|
||||
(char*)wifi->password,
|
||||
wifi->ssid.len,
|
||||
wifi->password_len,
|
||||
wifi->key_id,
|
||||
NULL);
|
||||
if (ret == RTW_SUCCESS) {
|
||||
if(retry_count == RETRY_COUNT)
|
||||
rtw_msleep_os(1000); //When start wps with OPEN AP, AP will send a disassociate frame after STA connected, need reconnect here.
|
||||
if(RTW_SUCCESS == wifi_is_ready_to_transceive(RTW_STA_INTERFACE)){
|
||||
//printf("\r\n[WPS]Ready to tranceive!!\n");
|
||||
wps_check_and_show_connection_info();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (retry_count == 0) {
|
||||
printf("\r\n[WPS]Join bss failed\n");
|
||||
break;
|
||||
}
|
||||
retry_count --;
|
||||
}
|
||||
}
|
||||
|
||||
static int wps_connect_to_AP_by_open_system(char *target_ssid)
|
||||
{
|
||||
int retry_count = 3, ret;
|
||||
|
||||
if (target_ssid != NULL) {
|
||||
rtw_msleep_os(500); //wait scan complete.
|
||||
while (1) {
|
||||
ret = wifi_connect(target_ssid,
|
||||
RTW_SECURITY_OPEN,
|
||||
NULL,
|
||||
strlen(target_ssid),
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
if (ret == RTW_SUCCESS) {
|
||||
//wps_check_and_show_connection_info();
|
||||
break;
|
||||
}
|
||||
if (retry_count == 0) {
|
||||
printf("\r\n[WPS]Join bss failed\n");
|
||||
return -1;
|
||||
}
|
||||
retry_count --;
|
||||
}
|
||||
//
|
||||
} else {
|
||||
printf("\r\n[WPS]Target SSID is NULL\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void process_wps_scan_result( rtw_scan_result_t* record, void * user_data )
|
||||
{
|
||||
internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)user_data;
|
||||
|
||||
if (record->wps_type != 0xff) {
|
||||
if (wps_arg->config_method == WPS_CONFIG_PUSHBUTTON) {
|
||||
if (record->wps_type == 0x04) {
|
||||
wps_password_id = record->wps_type;
|
||||
if (++wps_arg->isoverlap == 0) {
|
||||
memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
|
||||
wps_arg->target_ssid[record->SSID.len] = '\0';
|
||||
printf("\r\n[pbc]Record first triger wps AP = %s\n", wps_arg->target_ssid);
|
||||
}
|
||||
}
|
||||
} else if (wps_arg->config_method == WPS_CONFIG_DISPLAY) {
|
||||
if (record->wps_type == 0x00) {
|
||||
wps_arg->isoverlap = 0;
|
||||
wps_password_id = record->wps_type;
|
||||
memcpy(&wps_arg->target_ssid[0], record->SSID.val, record->SSID.len);
|
||||
wps_arg->target_ssid[record->SSID.len] = '\0';
|
||||
printf("\r\n[pin]find out first triger wps AP = %s\n", wps_arg->target_ssid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rtw_result_t wps_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
{
|
||||
internal_wps_scan_handler_arg_t *wps_arg = (internal_wps_scan_handler_arg_t *)malloced_scan_result->user_data;
|
||||
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 */
|
||||
|
||||
process_wps_scan_result(record, malloced_scan_result->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\r\nWPS scan done!\r\n");
|
||||
rtw_up_sema(&wps_arg->scan_sema);
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int wps_find_out_triger_wps_AP(char *target_ssid, u16 config_method)
|
||||
{
|
||||
internal_wps_scan_handler_arg_t wps_arg = {0};
|
||||
|
||||
wps_password_id = 0xFF;
|
||||
|
||||
wps_arg.isoverlap = -1;
|
||||
wps_arg.config_method = config_method;
|
||||
wps_arg.target_ssid = target_ssid;
|
||||
rtw_init_sema(&wps_arg.scan_sema, 0);
|
||||
if(wps_arg.scan_sema == NULL) return RTW_ERROR;
|
||||
|
||||
if(wifi_scan_networks(wps_scan_result_handler, &wps_arg ) != RTW_SUCCESS){
|
||||
printf("\n\rERROR: wifi scan failed");
|
||||
goto exit;
|
||||
}
|
||||
if(rtw_down_timeout_sema(&wps_arg.scan_sema, SCAN_LONGEST_WAIT_TIME) == RTW_FALSE){
|
||||
printf("\r\nWPS scan done early!\r\n");
|
||||
}
|
||||
|
||||
exit:
|
||||
rtw_free_sema(&wps_arg.scan_sema);
|
||||
|
||||
return wps_arg.isoverlap;
|
||||
}
|
||||
extern void wpas_wps_notify_wps_finish_hdl(char *buf, int buf_len, int flags, void *userdata);
|
||||
extern void wpas_wsc_eapol_recvd_hdl(char *buf, int buf_len, int flags, void* handler_user_data);
|
||||
int wps_start(u16 wps_config, char *pin, u8 channel, char *ssid)
|
||||
{
|
||||
struct dev_credential dev_cred;
|
||||
rtw_network_info_t wifi = {0};
|
||||
char target_ssid[64];
|
||||
int is_overlap = -1;
|
||||
u32 start_time = rtw_get_current_time();
|
||||
int ret = 0;
|
||||
|
||||
memset(&dev_cred, 0, sizeof(struct dev_credential));
|
||||
memset(target_ssid, 0, 64);
|
||||
if((wps_config != WPS_CONFIG_PUSHBUTTON)
|
||||
&& (wps_config != WPS_CONFIG_DISPLAY)
|
||||
&& (wps_config != WPS_CONFIG_KEYPAD)){
|
||||
printf("\n\rWPS: Wps method(%d) is wrong. Not triger WPS.\n", wps_config);
|
||||
return -1;
|
||||
}
|
||||
config_method = wps_config;
|
||||
|
||||
if(wps_config == WPS_CONFIG_DISPLAY
|
||||
|| wps_config == WPS_CONFIG_KEYPAD) {
|
||||
if(pin)
|
||||
strcpy(wps_pin_code, pin);
|
||||
else{
|
||||
printf("\n\rWPS: PIN is NULL. Not triger WPS.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ssid) {
|
||||
while (1) {
|
||||
unsigned int current_time = rtw_get_current_time();
|
||||
if (rtw_systime_to_sec(current_time - start_time) < 120) {
|
||||
is_overlap = wps_find_out_triger_wps_AP(&target_ssid[0], wps_config);
|
||||
if ((is_overlap == 0) || (is_overlap > 0))
|
||||
break;
|
||||
} else {
|
||||
printf("\r\nWPS: WPS Walking Time Out\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_overlap > 0) {
|
||||
printf("\r\nWPS: WPS session overlap. Not triger WPS.\n");
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
rtw_memcpy(target_ssid, ssid, strlen(ssid));
|
||||
}
|
||||
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
queue_for_credential = os_xqueue_create(1, sizeof(struct dev_credential));
|
||||
if(!queue_for_credential)
|
||||
return -1;
|
||||
|
||||
wifi_reg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wps_notify_wps_finish_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl, NULL);
|
||||
|
||||
wifi_set_wps_phase(ENABLE);
|
||||
ret = wps_connect_to_AP_by_open_system(target_ssid);
|
||||
if(ret < 0){
|
||||
printf("\n\rWPS: WPS Fail!!\n");
|
||||
goto exit;
|
||||
}
|
||||
os_xqueue_receive(queue_for_credential, &dev_cred, 120);
|
||||
if (dev_cred.ssid[0] != 0 && dev_cred.ssid_len <= 32) {
|
||||
wps_config_wifi_setting(&wifi, &dev_cred);
|
||||
wifi_set_wps_phase(DISABLE);
|
||||
wps_connect_to_AP_by_certificate(&wifi);
|
||||
goto exit1;
|
||||
} else {
|
||||
printf("\n\rWPS: WPS FAIL!!!\n");
|
||||
}
|
||||
exit:
|
||||
wifi_set_wps_phase(DISABLE);
|
||||
exit1:
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
|
||||
wifi_unreg_event_handler(WIFI_EVENT_WPS_FINISH, wpas_wps_notify_wps_finish_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_EAPOL_RECVD, wpas_wsc_eapol_recvd_hdl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_WPS_AP
|
||||
int ap_wps_start(u16 wps_config, char *pin)
|
||||
{
|
||||
u8 authorized_mac[ETH_ALEN];
|
||||
int ret = 0;
|
||||
u32 pin_val = 0;
|
||||
|
||||
printf("\n\rWPS-AP: wps_config(%x).\n", wps_config);
|
||||
if((wps_config != WPS_CONFIG_PUSHBUTTON)
|
||||
&& (wps_config != WPS_CONFIG_DISPLAY)
|
||||
&& (wps_config != WPS_CONFIG_KEYPAD)){
|
||||
printf("\n\rWPS-AP: Wps method(%d) is wrong. Not triger WPS.\n", wps_config);
|
||||
return -1;
|
||||
}
|
||||
config_method = wps_config;
|
||||
if(wps_config == WPS_CONFIG_DISPLAY
|
||||
|| wps_config == WPS_CONFIG_KEYPAD) {
|
||||
if(pin)
|
||||
strcpy(wps_pin_code, pin);
|
||||
else{
|
||||
printf("\n\rWPS-AP: PIN is NULL. Not triger WPS.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (queue_for_credential != NULL) {
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
}
|
||||
|
||||
queue_for_credential = os_xqueue_create(1, sizeof(authorized_mac));
|
||||
if(!queue_for_credential)
|
||||
return -1;
|
||||
|
||||
wifi_set_wps_phase(1);
|
||||
|
||||
if(wps_config == WPS_CONFIG_KEYPAD)
|
||||
{
|
||||
pin_val = atoi(pin);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS-AP: Enter pin code is unvalid.");
|
||||
goto exit;
|
||||
}
|
||||
ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
|
||||
}
|
||||
else if(wps_config == WPS_CONFIG_DISPLAY)
|
||||
ret = wpas_wps_registrar_add_pin((unsigned char const*)pin, strlen(pin));
|
||||
else
|
||||
ret = wpas_wps_registrar_button_pushed();
|
||||
|
||||
if(ret<0)
|
||||
goto exit;
|
||||
|
||||
printf("\n\rWPS-AP: wait for STA connect!\n");
|
||||
os_xqueue_receive(queue_for_credential, authorized_mac, 120); //max wait 2min
|
||||
|
||||
if(!wpas_wps_registrar_check_done())
|
||||
{
|
||||
ret = -1;
|
||||
wpas_wps_registrar_wps_cancel();
|
||||
}
|
||||
|
||||
exit:
|
||||
wifi_set_wps_phase(0);
|
||||
os_xqueue_delete(queue_for_credential);
|
||||
queue_for_credential = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif //CONFIG_WPS_AP
|
||||
|
||||
void wps_judge_staion_disconnect(void)
|
||||
{
|
||||
int mode = 0;
|
||||
unsigned char ssid[33];
|
||||
|
||||
wext_get_mode(WLAN0_NAME, &mode);
|
||||
|
||||
switch(mode) {
|
||||
case IW_MODE_MASTER: //In AP mode
|
||||
rltk_wlan_deinit();
|
||||
rltk_wlan_init(0,RTW_MODE_STA);
|
||||
rltk_wlan_start(0);
|
||||
break;
|
||||
case IW_MODE_INFRA: //In STA mode
|
||||
if(wext_get_ssid(WLAN0_NAME, ssid) > 0)
|
||||
wifi_disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_wps(int argc, char **argv)
|
||||
{
|
||||
wps_judge_staion_disconnect();
|
||||
|
||||
if((argc == 2 || argc == 3 ) && (argv[1] != NULL)){
|
||||
if(strcmp(argv[1],"pin") == 0){
|
||||
unsigned int pin_val = 0;
|
||||
/* start pin */
|
||||
if(argc == 2){
|
||||
char device_pin[10];
|
||||
pin_val = wps_generate_pin();
|
||||
sprintf(device_pin, "%08d", pin_val);
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: %s\n\r", device_pin);
|
||||
wps_start(WPS_CONFIG_DISPLAY, (char*)device_pin, 0, NULL);
|
||||
}else{
|
||||
pin_val = atoi(argv[2]);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS: Device pin code is invalid. Not triger WPS.\n");
|
||||
return;
|
||||
}
|
||||
printf("\n\rWPS: Start WPS PIN Keypad.\n\r");
|
||||
wps_start(WPS_CONFIG_KEYPAD, argv[2], 0, NULL);
|
||||
}
|
||||
}else if(strcmp(argv[1],"pbc") == 0){
|
||||
/* start pbc */
|
||||
printf("\n\rWPS: Start WPS PBC.\n\r");
|
||||
wps_start(WPS_CONFIG_PUSHBUTTON, NULL, 0, NULL);
|
||||
}else{
|
||||
printf("\n\rWPS: Wps Method is wrong. Not triger WPS.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_WPS_AP
|
||||
/*
|
||||
cmd_ap_wps for AP WSC setting. command style:
|
||||
cmd_ap_wps pbc or cmd_ap_wps pin 12345678
|
||||
*/
|
||||
void cmd_ap_wps(int argc, char **argv)
|
||||
{
|
||||
if(rltk_wlan_running(WLAN1_IDX)){
|
||||
printf("\n\rNot support con-current softAP WSC!\n\r");
|
||||
return;
|
||||
}
|
||||
|
||||
if((argc == 2 || argc == 3) && (argv[1] != NULL)) {
|
||||
if (strcmp(argv[1],"pin") == 0 ) {
|
||||
unsigned int pin_val = 0;
|
||||
if(argc == 3){
|
||||
pin_val = atoi(argv[2]);
|
||||
if (!wps_pin_valid(pin_val)) {
|
||||
printf("\n\rWPS-AP: Device pin code is invalid. Not trigger WPS.\n\r");
|
||||
return;
|
||||
}
|
||||
printf("\n\rWPS-AP: Start AP WPS PIN Keypad.\n");
|
||||
ap_wps_start(WPS_CONFIG_KEYPAD, argv[2]);
|
||||
}else{
|
||||
char device_pin[10];
|
||||
pin_val = wps_generate_pin();
|
||||
sprintf(device_pin, "%08d", pin_val);
|
||||
printf("\n\rWPS: Start WPS PIN Display. PIN: %s\n\r", device_pin);
|
||||
ap_wps_start(WPS_CONFIG_DISPLAY, (char*)device_pin);
|
||||
}
|
||||
}else if (strcmp(argv[1],"pbc") == 0) {
|
||||
printf("\n\rWPS-AP: Start AP WPS PBC\n");
|
||||
ap_wps_start(WPS_CONFIG_PUSHBUTTON, NULL);
|
||||
}else{
|
||||
printf("\n\rWPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
printf("\n\rWPS-AP Usage:\"wifi_ap_wps pin [pin_code]\" or \"wifi_ap_wps pbc\"\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif //CONFIG_WPS_AP
|
||||
#endif //CONFIG_ENABLE_WPS
|
||||
#endif //#ifdef CONFIG_WPS
|
1609
component/common/api/wifi/wifi_conf.c
Normal file
1609
component/common/api/wifi/wifi_conf.c
Normal file
File diff suppressed because it is too large
Load diff
612
component/common/api/wifi/wifi_conf.h
Normal file
612
component/common/api/wifi/wifi_conf.h
Normal file
|
@ -0,0 +1,612 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#ifndef __WIFI_API_H
|
||||
#define __WIFI_API_H
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
#include "wifi_util.h"
|
||||
#include "wifi_ind.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************
|
||||
* Macros
|
||||
******************************************************/
|
||||
|
||||
#define RTW_ENABLE_API_INFO
|
||||
|
||||
#ifdef RTW_ENABLE_API_INFO
|
||||
#define RTW_API_INFO(args) do {printf args;} while(0)
|
||||
#else
|
||||
#define RTW_API_INFO(args)
|
||||
#endif
|
||||
|
||||
#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
|
||||
#define CMP_MAC( a, b ) (((a[0])==(b[0]))&& \
|
||||
((a[1])==(b[1]))&& \
|
||||
((a[2])==(b[2]))&& \
|
||||
((a[3])==(b[3]))&& \
|
||||
((a[4])==(b[4]))&& \
|
||||
((a[5])==(b[5])))
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
#define SCAN_LONGEST_WAIT_TIME (4500)
|
||||
|
||||
|
||||
#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
|
||||
#define PSCAN_ENABLE 0x01 //enable for partial channel scan
|
||||
#define PSCAN_FAST_SURVEY 0x02 //set to select scan time to FAST_SURVEY_TO, otherwise SURVEY_TO
|
||||
|
||||
|
||||
/******************************************************
|
||||
* Type Definitions
|
||||
******************************************************/
|
||||
|
||||
/** Scan result callback function pointer type
|
||||
*
|
||||
* @param result_ptr : A pointer to the pointer that indicates where to put the next scan result
|
||||
* @param user_data : User provided data
|
||||
*/
|
||||
typedef void (*rtw_scan_result_callback_t)( rtw_scan_result_t** result_ptr, void* user_data );
|
||||
typedef rtw_result_t (*rtw_scan_result_handler_t)( rtw_scan_handler_result_t* malloced_scan_result );
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
typedef enum _WIFI_LINK_STATUS{
|
||||
WIFI_LINK_DISCONNECTED = 0,
|
||||
WIFI_LINK_CONNECTED
|
||||
}WIFI_LINK_STATUS;
|
||||
|
||||
typedef struct {
|
||||
char *buf;
|
||||
int buf_len;
|
||||
} scan_buf_arg;
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
typedef struct internal_scan_handler{
|
||||
rtw_scan_result_t** pap_details;
|
||||
rtw_scan_result_t * ap_details;
|
||||
int scan_cnt;
|
||||
rtw_bool_t scan_complete;
|
||||
unsigned char max_ap_size;
|
||||
rtw_scan_result_handler_t gscan_result_handler;
|
||||
#if SCAN_USE_SEMAPHORE
|
||||
void *scan_semaphore;
|
||||
#else
|
||||
int scan_running;
|
||||
#endif
|
||||
void* user_data;
|
||||
unsigned int scan_start_time;
|
||||
} internal_scan_handler_t;
|
||||
|
||||
typedef struct {
|
||||
rtw_network_info_t network_info;
|
||||
void *join_sema;
|
||||
} internal_join_result_t;
|
||||
|
||||
/******************************************************
|
||||
* Function Declarations
|
||||
******************************************************/
|
||||
/**
|
||||
* Initialises Realtek WiFi API System
|
||||
*
|
||||
* - Initialises the required parts of the software platform
|
||||
* i.e. worker, event registering, semaphore, etc.
|
||||
*
|
||||
* - Initialises the RTW API thread which handles the asynchronous event
|
||||
*
|
||||
* @return RTW_SUCCESS if initialization is successful, RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_manager_init(void);
|
||||
|
||||
/** Joins a Wi-Fi network
|
||||
*
|
||||
* Scans for, associates and authenticates with a Wi-Fi network.
|
||||
* On successful return, the system is ready to send data packets.
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type:
|
||||
* - RTW_SECURITY_OPEN - Open Security
|
||||
* - RTW_SECURITY_WEP_PSK - WEP Security with open authentication
|
||||
* - RTW_SECURITY_WEP_SHARED - WEP Security with shared authentication
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher
|
||||
* - RTW_SECURITY_WPA2_TKIP_PSK - WPA2 Security using TKIP cipher
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers
|
||||
* @param[in] password : A byte array containing either the
|
||||
* cleartext security key for WPA/WPA2
|
||||
* secured networks, or a pointer to
|
||||
* an array of rtw_wep_key_t
|
||||
* structures for WEP secured networks
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] key_id : The index of the wep key.
|
||||
* @param[in] semaphore : A user provided semaphore that is flagged when the join is complete
|
||||
*
|
||||
* @return RTW_SUCCESS : when the system is joined and ready
|
||||
* to send data packets
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_connect(
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int key_id,
|
||||
void *semaphore);
|
||||
|
||||
int wifi_connect_bssid(
|
||||
unsigned char bssid[ETH_ALEN],
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int bssid_len,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int key_id,
|
||||
void *semaphore);
|
||||
|
||||
/** Disassociates from a Wi-Fi network.
|
||||
*
|
||||
* @return RTW_SUCCESS : On successful disassociation from
|
||||
* the AP
|
||||
* RTW_ERROR : If an error occurred
|
||||
*/
|
||||
int wifi_disconnect(void);
|
||||
|
||||
/** Check if the interface specified is up.
|
||||
*
|
||||
* @return RTW_TRUE : If it's up
|
||||
* RTW_FALSE : If it's not
|
||||
*/
|
||||
int wifi_is_up(rtw_interface_t interface);
|
||||
|
||||
/** Determines if a particular interface is ready to transceive ethernet packets
|
||||
*
|
||||
* @param Radio interface to check, options are
|
||||
* RTW_STA_INTERFACE, RTW_AP_INTERFACE
|
||||
* @return RTW_SUCCESS : if the interface is ready to
|
||||
* transceive ethernet packets
|
||||
* @return RTW_NOTFOUND : no AP with a matching SSID was
|
||||
* found
|
||||
* @return RTW_NOT_AUTHENTICATED: a matching AP was found but
|
||||
* it won't let you
|
||||
* authenticate. This can
|
||||
* occur if this device is
|
||||
* in the block list on the
|
||||
* AP.
|
||||
* @return RTW_NOT_KEYED: the device has authenticated and
|
||||
* associated but has not completed
|
||||
* the key exchange. This can occur
|
||||
* if the passphrase is incorrect.
|
||||
* @return RTW_ERROR : if the interface is not ready to
|
||||
* transceive ethernet packets
|
||||
*/
|
||||
int wifi_is_ready_to_transceive(rtw_interface_t interface);
|
||||
|
||||
/** ----------------------------------------------------------------------
|
||||
* WARNING : This function is for internal use only!
|
||||
* ----------------------------------------------------------------------
|
||||
* This function sets the current Media Access Control (MAC) address of the
|
||||
* 802.11 device.
|
||||
*
|
||||
* @param[in] mac Wi-Fi MAC address
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_mac_address(char * mac);
|
||||
|
||||
/** Retrieves the current Media Access Control (MAC) address
|
||||
* (or Ethernet hardware address) of the 802.11 device
|
||||
*
|
||||
* @param mac Pointer to a variable that the current MAC address will be written to
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_get_mac_address(char * mac);
|
||||
|
||||
/** Enables powersave mode
|
||||
*
|
||||
* @return @ref rtw_result_t
|
||||
*/
|
||||
int wifi_enable_powersave(void);
|
||||
|
||||
/** Disables 802.11 power save mode
|
||||
*
|
||||
* @return RTW_SUCCESS : if power save mode was successfully
|
||||
* disabled
|
||||
* RTW_ERROR : if power save mode was not successfully
|
||||
* disabled
|
||||
*/
|
||||
int wifi_disable_powersave(void);
|
||||
|
||||
/** Gets the tx power in index units
|
||||
*
|
||||
* @param dbm : The variable to receive the tx power in index.
|
||||
*
|
||||
* @return RTW_SUCCESS : if successful
|
||||
* RTW_ERROR : if not successful
|
||||
*/
|
||||
int wifi_get_txpower(int *poweridx);
|
||||
|
||||
/** Sets the tx power in index units
|
||||
*
|
||||
* @param dbm : The desired tx power in index.
|
||||
*
|
||||
* @return RTW_SUCCESS : if tx power was successfully set
|
||||
* RTW_ERROR : if tx power was not successfully set
|
||||
*/
|
||||
int wifi_set_txpower(int poweridx);
|
||||
|
||||
/** Get the associated clients with SoftAP
|
||||
*
|
||||
* @param client_list_buffer : the location where the client
|
||||
* list will be stored
|
||||
* @param buffer_length : the buffer length.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully get
|
||||
* RTW_ERROR : if result was not successfully get
|
||||
*/
|
||||
int wifi_get_associated_client_list(void * client_list_buffer, unsigned short buffer_length);
|
||||
|
||||
/** Get the SoftAP information
|
||||
*
|
||||
* @param ap_info : the location where the AP info will be
|
||||
* stored
|
||||
* @param security : the security type.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully get
|
||||
* RTW_ERROR : if result was not successfully get
|
||||
*/
|
||||
int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security);
|
||||
|
||||
/** Set the country code to driver to determine the channel set
|
||||
*
|
||||
* @param country_code : the country code.
|
||||
*
|
||||
* @return RTW_SUCCESS : if result was successfully set
|
||||
* RTW_ERROR : if result was not successfully set
|
||||
*/
|
||||
int wifi_set_country(rtw_country_code_t country_code);
|
||||
|
||||
/** Retrieve the latest RSSI value
|
||||
*
|
||||
* @param rssi: The location where the RSSI value will be stored
|
||||
*
|
||||
* @return RTW_SUCCESS : if the RSSI was succesfully retrieved
|
||||
* RTW_ERROR : if the RSSI was not retrieved
|
||||
*/
|
||||
int wifi_get_rssi(int *pRSSI);
|
||||
|
||||
/** Set the current channel on STA interface
|
||||
*
|
||||
* @param channel : The desired channel
|
||||
*
|
||||
* @return RTW_SUCCESS : if the channel was successfully set
|
||||
* RTW_ERROR : if the channel was not successfully
|
||||
* set
|
||||
*/
|
||||
int wifi_set_channel(int channel);
|
||||
|
||||
/** Get the current channel on STA interface
|
||||
*
|
||||
* @param channel : A pointer to the variable where the
|
||||
* channel value will be written
|
||||
*
|
||||
* @return RTW_SUCCESS : if the channel was successfully read
|
||||
* RTW_ERROR : if the channel was not successfully
|
||||
* read
|
||||
*/
|
||||
int wifi_get_channel(int *channel);
|
||||
|
||||
/** Registers interest in a multicast address
|
||||
* Once a multicast address has been registered, all packets detected on the
|
||||
* medium destined for that address are forwarded to the host.
|
||||
* Otherwise they are ignored.
|
||||
*
|
||||
* @param mac: Ethernet MAC address
|
||||
*
|
||||
* @return RTW_SUCCESS : if the address was registered
|
||||
* successfully
|
||||
* RTW_ERROR : if the address was not registered
|
||||
*/
|
||||
int wifi_register_multicast_address(rtw_mac_t *mac);
|
||||
|
||||
/** Unregisters interest in a multicast address
|
||||
* Once a multicast address has been unregistered, all packets detected on the
|
||||
* medium destined for that address are ignored.
|
||||
*
|
||||
* @param mac: Ethernet MAC address
|
||||
*
|
||||
* @return RTW_SUCCESS : if the address was unregistered
|
||||
* successfully
|
||||
* RTW_ERROR : if the address was not unregistered
|
||||
*/
|
||||
int wifi_unregister_multicast_address(rtw_mac_t *mac);
|
||||
|
||||
int wifi_rf_on(void);
|
||||
int wifi_rf_off(void);
|
||||
|
||||
/** Turn on the Wi-Fi device
|
||||
*
|
||||
* - Bring the Wireless interface "Up"
|
||||
* - Initialises the driver thread which arbitrates access
|
||||
* to the SDIO/SPI bus
|
||||
*
|
||||
* @param mode: wifi work mode
|
||||
*
|
||||
* @return RTW_SUCCESS : if the WiFi chip was initialised
|
||||
* successfully
|
||||
* RTW_ERROR : if the WiFi chip was not initialised
|
||||
* successfully
|
||||
*/
|
||||
int wifi_on(rtw_mode_t mode);
|
||||
|
||||
/**
|
||||
* Turn off the Wi-Fi device
|
||||
*
|
||||
* - Bring the Wireless interface "Down"
|
||||
* - De-Initialises the driver thread which arbitrates access
|
||||
* to the SDIO/SPI bus
|
||||
*
|
||||
* @return RTW_SUCCESS if deinitialization is successful,
|
||||
* RTW_ERROR otherwise
|
||||
*/
|
||||
int wifi_off(void);
|
||||
|
||||
/** Starts an infrastructure WiFi network
|
||||
*
|
||||
* @warning If a STA interface is active when this function is called, the softAP will\n
|
||||
* start on the same channel as the STA. It will NOT use the channel provided!
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing
|
||||
* the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type: \n
|
||||
* - RTW_SECURITY_OPEN - Open Security \n
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
|
||||
* - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
|
||||
* @param[in] password : A byte array containing the cleartext
|
||||
* security key for the network
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] channel : 802.11 channel number
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully creates an AP
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_start_ap(
|
||||
char *ssid,
|
||||
rtw_security_t security_type,
|
||||
char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int channel);
|
||||
|
||||
/** Initiates a scan to search for 802.11 networks.
|
||||
*
|
||||
* The scan progressively accumulates results over time, and
|
||||
* may take between 1 and 3 seconds to complete. The results of
|
||||
* the scan will be individually provided to the callback
|
||||
* function. Note: The callback function will be executed in
|
||||
* the context of the RTW thread.
|
||||
*
|
||||
* @param[in] scan_type : Specifies whether the scan should
|
||||
* be Active, Passive or scan Prohibited channels
|
||||
* @param[in] bss_type : Specifies whether the scan should
|
||||
* search for Infrastructure
|
||||
* networks (those using an Access
|
||||
* Point), Ad-hoc networks, or both
|
||||
* types.
|
||||
* @param callback[in] : the callback function which will
|
||||
* receive and process the result data.
|
||||
* @param result_ptr[in] : a pointer to a pointer to a result
|
||||
* storage structure.
|
||||
* @param user_data[in] : user specific data that will be
|
||||
* passed directly to the callback function
|
||||
*
|
||||
* @note : When scanning specific channels, devices with a
|
||||
* strong signal strength on nearby channels may be
|
||||
* detected
|
||||
* @note : Callback must not use blocking functions, since it is
|
||||
* called from the context of the RTW thread.
|
||||
* @note : The callback, result_ptr and user_data variables will
|
||||
* be referenced after the function returns. Those
|
||||
* variables must remain valid until the scan is
|
||||
* complete.
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_scan(rtw_scan_type_t scan_type,
|
||||
rtw_bss_type_t bss_type,
|
||||
void* result_ptr);
|
||||
|
||||
/** Initiates a scan to search for 802.11 networks, a higher
|
||||
* level API based on wifi_scan to simplify the scan
|
||||
* operation.
|
||||
*
|
||||
* The scan results will be list by the order of RSSI.
|
||||
* It may demand hundreds bytes memory during scan
|
||||
* processing according to the quantity of AP nearby.
|
||||
*
|
||||
* @param results_handler[in] : the callback function which
|
||||
* will receive and process the result data.
|
||||
* @param user_data[in] : user specific data that will be
|
||||
* passed directly to the callback function
|
||||
*
|
||||
* @note : Callback must not use blocking functions, since it is
|
||||
* called from the context of the RTW thread.
|
||||
* @note : The callback, user_data variables will
|
||||
* be referenced after the function returns. Those
|
||||
* variables must remain valid until the scan is
|
||||
* complete.
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_data);
|
||||
int wifi_scan_networks_with_ssid(rtw_scan_result_handler_t results_handler, void* user_data, char* ssid, int ssid_len);
|
||||
|
||||
/** Set the partical scan
|
||||
*
|
||||
* @param channel_list[in] : the channel set the scan will
|
||||
* stay on
|
||||
* @param pscan_config[in] : the pscan_config of the channel set
|
||||
*
|
||||
* @param length[in] : the channel list length
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length);
|
||||
|
||||
/** Get the network information
|
||||
*
|
||||
* @param ifname[in] : the name of the interface we are care
|
||||
* @param pSetting[in] : the location where the network
|
||||
* information will be stored
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_get_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
|
||||
|
||||
/** Show the network information
|
||||
*
|
||||
* @param ifname[in] : the name of the interface we are care
|
||||
* @param pSetting[in] : the location where the network
|
||||
* information was stored
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_show_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
|
||||
|
||||
/** Set the network mode according to the data rate it's
|
||||
* supported
|
||||
*
|
||||
* @param mode[in] : the network mode
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_network_mode(rtw_network_mode_t mode);
|
||||
|
||||
/** Set the chip to worke in the promisc mode
|
||||
*
|
||||
* @param enabled[in] : enabled can be set 0, 1 and 2. if enabled is zero, disable the promisc, else enable the promisc.
|
||||
* 0 means disable the promisc
|
||||
* 1 means enable the promisc
|
||||
* 2 means enable the promisc special for length is used
|
||||
* @param callback[in] : the callback function which will
|
||||
* receive and process the netowork data.
|
||||
* @param len_used[in] : specify if the the promisc length is
|
||||
* used.
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used);
|
||||
|
||||
/** Set the wps phase
|
||||
*
|
||||
* @param is_trigger_wps[in] : to trigger wps function or not
|
||||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_set_wps_phase(unsigned char is_trigger_wps);
|
||||
|
||||
/** Restarts an infrastructure WiFi network
|
||||
*
|
||||
* @warning If a STA interface is active when this function is called, the softAP will\n
|
||||
* start on the same channel as the STA. It will NOT use the channel provided!
|
||||
*
|
||||
* @param[in] ssid : A null terminated string containing
|
||||
* the SSID name of the network to join
|
||||
* @param[in] security_type : Authentication type: \n
|
||||
* - RTW_SECURITY_OPEN - Open Security \n
|
||||
* - RTW_SECURITY_WPA_TKIP_PSK - WPA Security \n
|
||||
* - RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher \n
|
||||
* - RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers \n
|
||||
* - WEP security is NOT IMPLEMENTED. It is NOT SECURE! \n
|
||||
* @param[in] password : A byte array containing the cleartext
|
||||
* security key for the network
|
||||
* @param[in] ssid_len : The length of the SSID in
|
||||
* bytes.
|
||||
* @param[in] password_len : The length of the security_key in
|
||||
* bytes.
|
||||
* @param[in] channel : 802.11 channel number
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully creates an AP
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
int wifi_restart_ap(
|
||||
unsigned char *ssid,
|
||||
rtw_security_t security_type,
|
||||
unsigned char *password,
|
||||
int ssid_len,
|
||||
int password_len,
|
||||
int channel);
|
||||
|
||||
|
||||
int wifi_set_autoreconnect(__u8 mode);
|
||||
int wifi_get_autoreconnect(__u8 *mode);
|
||||
int wifi_get_last_error( );
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
#ifndef BIT
|
||||
#define BIT(x) ((__u32)1 << (x))
|
||||
#endif
|
||||
|
||||
#ifndef _CUSTOM_IE_TYPE_
|
||||
#define _CUSTOM_IE_TYPE_
|
||||
enum CUSTOM_IE_TYPE{
|
||||
PROBE_REQ = BIT(0),
|
||||
PROBE_RSP = BIT(1),
|
||||
BEACON = BIT(2),
|
||||
};
|
||||
#endif /* _CUSTOM_IE_TYPE_ */
|
||||
|
||||
/* ie format
|
||||
* +-----------+--------+-----------------------+
|
||||
* |element ID | length | content in length byte|
|
||||
* +-----------+--------+-----------------------+
|
||||
*
|
||||
* type: refer to CUSTOM_IE_TYPE
|
||||
*/
|
||||
#ifndef _CUS_IE_
|
||||
#define _CUS_IE_
|
||||
typedef struct _cus_ie{
|
||||
__u8 *ie;
|
||||
__u8 type;
|
||||
}cus_ie, *p_cus_ie;
|
||||
#endif /* _CUS_IE_ */
|
||||
|
||||
int wifi_add_custom_ie(void *cus_ie, int ie_num);
|
||||
|
||||
int wifi_update_custom_ie(void *cus_ie, int ie_index);
|
||||
|
||||
int wifi_del_custom_ie(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PROMISC
|
||||
void wifi_init_packet_filter(void);
|
||||
int wifi_add_packet_filter(unsigned char filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule);
|
||||
int wifi_enable_packet_filter(unsigned char filter_id);
|
||||
int wifi_disable_packet_filter(unsigned char filter_id);
|
||||
int wifi_remove_packet_filter(unsigned char filter_id);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __WIFI_API_H
|
||||
|
||||
//----------------------------------------------------------------------------//
|
236
component/common/api/wifi/wifi_ind.c
Normal file
236
component/common/api/wifi/wifi_ind.c
Normal file
|
@ -0,0 +1,236 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#include "wifi/wifi_ind.h"
|
||||
#include "wifi/wifi_conf.h"
|
||||
#include "osdep_service.h"
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
|
||||
#define WIFI_INDICATE_MSG 0
|
||||
#define WIFI_MANAGER_STACKSIZE 128
|
||||
#define WIFI_MANAGER_PRIORITY (5)
|
||||
#define WIFI_MANAGER_PRIO 2
|
||||
|
||||
#define INDICATE_USE_THREAD 0
|
||||
#define WIFI_EVENT_MAX_ROW 3
|
||||
/******************************************************
|
||||
* Globals
|
||||
******************************************************/
|
||||
|
||||
static event_list_elem_t event_callback_list[WIFI_EVENT_MAX][WIFI_EVENT_MAX_ROW];
|
||||
#if INDICATE_USE_THREAD
|
||||
static rtw_worker_thread_t wifi_worker_thread;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
#if INDICATE_USE_THREAD
|
||||
static rtw_result_t rtw_send_event_to_worker(int event_cmd, char *buf, int buf_len, int flags)
|
||||
{
|
||||
rtw_event_message_t message;
|
||||
int i;
|
||||
rtw_result_t ret = RTW_SUCCESS;
|
||||
|
||||
if(event_cmd >= WIFI_EVENT_MAX)
|
||||
return RTW_BADARG;
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmd][i].handler == NULL)
|
||||
continue;
|
||||
|
||||
message.function = (event_handler_t)event_callback_list[event_cmd][i].handler;
|
||||
message.buf = buf;
|
||||
message.buf_len = buf_len;
|
||||
message.flags = flags;
|
||||
message.user_data = event_callback_list[event_cmd][i].handler_user_data;
|
||||
|
||||
ret = rtw_push_to_xqueue(&wifi_worker_thread->event_queue, &message, 0);
|
||||
if(ret != RTW_SUCCESS)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static rtw_result_t rtw_indicate_event_handle(int event_cmd, char *buf, int buf_len, int flags)
|
||||
{
|
||||
rtw_event_handler_t handle = NULL;
|
||||
int i;
|
||||
|
||||
if(event_cmd >= WIFI_EVENT_MAX)
|
||||
return RTW_BADARG;
|
||||
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
handle = event_callback_list[event_cmd][i].handler;
|
||||
if(handle == NULL)
|
||||
continue;
|
||||
handle(buf, buf_len, flags, event_callback_list[event_cmd][i].handler_user_data);
|
||||
}
|
||||
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
void wifi_indication( WIFI_EVENT_INDICATE event, char *buf, int buf_len, int flags)
|
||||
{
|
||||
//
|
||||
// If upper layer application triggers additional operations on receiving of wext_wlan_indicate,
|
||||
// please strictly check current stack size usage (by using uxTaskGetStackHighWaterMark() )
|
||||
// , and tries not to share the same stack with wlan driver if remaining stack space is
|
||||
// not available for the following operations.
|
||||
// ex: using semaphore to notice another thread.
|
||||
switch(event)
|
||||
{
|
||||
case WIFI_EVENT_DISCONNECT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r %s():Disconnection indication received", __FUNCTION__);
|
||||
#endif
|
||||
#if CONFIG_INIC_EN
|
||||
inic_indicate_event(WIFI_LINK_DISCONNECTED);
|
||||
#endif//CONFIG_INIC_EN
|
||||
break;
|
||||
case WIFI_EVENT_CONNECT:
|
||||
// For WPA/WPA2 mode, indication of connection does not mean data can be
|
||||
// correctly transmitted or received. Data can be correctly transmitted or
|
||||
// received only when 4-way handshake is done.
|
||||
// Please check WIFI_EVENT_FOURWAY_HANDSHAKE_DONE event
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
// Sample: return mac address
|
||||
if(buf != NULL && buf_len == 6)
|
||||
{
|
||||
printf("\n\r%s():Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x", __FUNCTION__,
|
||||
buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_INIC_EN
|
||||
inic_indicate_event(WIFI_LINK_CONNECTED);
|
||||
#endif//CONFIG_INIC_EN
|
||||
break;
|
||||
case WIFI_EVENT_FOURWAY_HANDSHAKE_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
if(buf != NULL)
|
||||
{
|
||||
if(buf_len == strlen(IW_EXT_STR_FOURWAY_DONE))
|
||||
printf("\n\r%s():%s", __FUNCTION__, buf);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_RESULT_REPORT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SCAN_DONE\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_RECONNECTION_FAIL:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
if(buf != NULL){
|
||||
if(buf_len == strlen(IW_EXT_STR_RECONNECTION_FAIL))
|
||||
printf("\n\r%s", buf);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_NO_NETWORK:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_NO_NETWORK\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#ifdef CONFIG_P2P_NEW
|
||||
case WIFI_EVENT_SEND_ACTION_DONE:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_SEND_ACTION_DONE\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_RX_MGNT:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_RX_MGNT\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STA_ASSOC:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_STA_ASSOC\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISASSOC:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_STA_DISASSOC\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#endif //CONFIG_P2P_NEW
|
||||
#ifdef CONFIG_WPS
|
||||
case WIFI_EVENT_WPS_FINISH:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_WPS_FINISH\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_EAPOL_RECVD:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_EAPOL_RECVD\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case WIFI_EVENT_BEACON_AFTER_DHCP:
|
||||
#if(WIFI_INDICATE_MSG==1)
|
||||
printf("\n\r%s(): WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#if INDICATE_USE_THREAD
|
||||
rtw_send_event_to_worker(event, buf, buf_len, flags);
|
||||
#else
|
||||
rtw_indicate_event_handle(event, buf, buf_len, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data)
|
||||
{
|
||||
int i = 0;
|
||||
if(event_cmds < WIFI_EVENT_MAX){
|
||||
for(i=0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmds][i].handler == NULL){
|
||||
event_callback_list[event_cmds][i].handler = handler_func;
|
||||
event_callback_list[event_cmds][i].handler_user_data = handler_user_data;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_unreg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func)
|
||||
{
|
||||
int i;
|
||||
if(event_cmds < WIFI_EVENT_MAX){
|
||||
for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){
|
||||
if(event_callback_list[event_cmds][i].handler == handler_func){
|
||||
event_callback_list[event_cmds][i].handler = NULL;
|
||||
event_callback_list[event_cmds][i].handler_user_data = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_event_callback_list(){
|
||||
memset(event_callback_list, 0, sizeof(event_callback_list));
|
||||
}
|
||||
|
||||
int wifi_manager_init()
|
||||
{
|
||||
#if INDICATE_USE_THREAD
|
||||
rtw_create_worker_thread(&wifi_worker_thread,
|
||||
WIFI_MANAGER_PRIORITY,
|
||||
WIFI_MANAGER_STACKSIZE,
|
||||
WIFI_MANAGER_PRIO);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rtw_wifi_manager_deinit()
|
||||
{
|
||||
#if INDICATE_USE_THREAD
|
||||
rtw_delete_worker_thread(&wifi_worker_thread);
|
||||
#endif
|
||||
}
|
||||
|
52
component/common/api/wifi/wifi_ind.h
Normal file
52
component/common/api/wifi/wifi_ind.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef _WIFI_INDICATE_H
|
||||
#define _WIFI_INDICATE_H
|
||||
#include "wifi_conf.h"
|
||||
|
||||
typedef enum _WIFI_EVENT_INDICATE{
|
||||
WIFI_EVENT_CONNECT = 0,
|
||||
WIFI_EVENT_DISCONNECT = 1,
|
||||
WIFI_EVENT_FOURWAY_HANDSHAKE_DONE = 2,
|
||||
WIFI_EVENT_SCAN_RESULT_REPORT = 3,
|
||||
WIFI_EVENT_SCAN_DONE = 4,
|
||||
WIFI_EVENT_RECONNECTION_FAIL = 5,
|
||||
WIFI_EVENT_SEND_ACTION_DONE = 6,
|
||||
WIFI_EVENT_RX_MGNT = 7,
|
||||
WIFI_EVENT_STA_ASSOC = 8,
|
||||
WIFI_EVENT_STA_DISASSOC = 9,
|
||||
WIFI_EVENT_WPS_FINISH = 10,
|
||||
WIFI_EVENT_EAPOL_RECVD = 11,
|
||||
WIFI_EVENT_NO_NETWORK = 12,
|
||||
WIFI_EVENT_BEACON_AFTER_DHCP = 13,
|
||||
WIFI_EVENT_MAX,
|
||||
}WIFI_EVENT_INDICATE;
|
||||
|
||||
typedef void (*rtw_event_handler_t)(char *buf, int buf_len, int flags, void* handler_user_data );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// WIFI_EVENT_INDICATE event_cmd;
|
||||
rtw_event_handler_t handler;
|
||||
void* handler_user_data;
|
||||
} 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);
|
||||
/** Register the event listener
|
||||
*
|
||||
* @param[in] event_cmds : The event command number indicated
|
||||
* @param[in] handler_func : the callback function which will
|
||||
* receive and process the event
|
||||
* @param[in] handler_user_data : user specific data that will be
|
||||
* passed directly to the callback function
|
||||
*
|
||||
* @note : Set the same event_cmds with empty handler_func will
|
||||
* unregister the event_cmds
|
||||
*
|
||||
* @return RTW_SUCCESS : if successfully registers the event
|
||||
* RTW_ERROR : if an error occurred
|
||||
*/
|
||||
extern void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data);
|
||||
extern void wifi_unreg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func);
|
||||
|
||||
#endif //_WIFI_INDICATE_H
|
||||
|
333
component/common/api/wifi/wifi_promisc.c
Normal file
333
component/common/api/wifi/wifi_promisc.c
Normal file
|
@ -0,0 +1,333 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "tcpip.h"
|
||||
#include "wifi/wifi_conf.h"
|
||||
|
||||
#ifndef CONFIG_WLAN
|
||||
#define CONFIG_WLAN 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
struct eth_frame {
|
||||
struct eth_frame *prev;
|
||||
struct eth_frame *next;
|
||||
unsigned char da[6];
|
||||
unsigned char sa[6];
|
||||
unsigned int len;
|
||||
unsigned char type;
|
||||
};
|
||||
|
||||
struct eth_buffer {
|
||||
struct eth_frame *head;
|
||||
struct eth_frame *tail;
|
||||
};
|
||||
|
||||
static struct eth_buffer eth_buffer;
|
||||
|
||||
#ifdef CONFIG_PROMISC
|
||||
#define MAX_PACKET_FILTER_INFO 5
|
||||
#define FILTER_ID_INIT_VALUE 10
|
||||
rtw_packet_filter_info_t paff_array[MAX_PACKET_FILTER_INFO]={0, 0, 0, 0, 0};
|
||||
static u8 packet_filter_enable_num = 0;
|
||||
|
||||
void promisc_init_packet_filter()
|
||||
{
|
||||
int i = 0;
|
||||
for(i=0; i<MAX_PACKET_FILTER_INFO; i++){
|
||||
paff_array[i].filter_id = FILTER_ID_INIT_VALUE;
|
||||
paff_array[i].enable = 0;
|
||||
paff_array[i].patt.mask_size = 0;
|
||||
paff_array[i].rule = RTW_POSITIVE_MATCHING;
|
||||
paff_array[i].patt.mask = NULL;
|
||||
paff_array[i].patt.pattern = NULL;
|
||||
}
|
||||
packet_filter_enable_num = 0;
|
||||
}
|
||||
|
||||
int promisc_add_packet_filter(u8 filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == FILTER_ID_INIT_VALUE){
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].filter_id = filter_id;
|
||||
|
||||
paff_array[i].patt.offset= patt->offset;
|
||||
paff_array[i].patt.mask_size = patt->mask_size;
|
||||
paff_array[i].patt.mask = pvPortMalloc(patt->mask_size);
|
||||
memcpy(paff_array[i].patt.mask, patt->mask, patt->mask_size);
|
||||
paff_array[i].patt.pattern= pvPortMalloc(patt->mask_size);
|
||||
memcpy(paff_array[i].patt.pattern, patt->pattern, patt->mask_size);
|
||||
|
||||
paff_array[i].rule = rule;
|
||||
paff_array[i].enable = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_enable_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].enable = 1;
|
||||
packet_filter_enable_num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_disable_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].enable = 0;
|
||||
packet_filter_enable_num--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int promisc_remove_packet_filter(u8 filter_id)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < MAX_PACKET_FILTER_INFO){
|
||||
if(paff_array[i].filter_id == filter_id)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i == MAX_PACKET_FILTER_INFO)
|
||||
return -1;
|
||||
|
||||
paff_array[i].filter_id = FILTER_ID_INIT_VALUE;
|
||||
paff_array[i].enable = 0;
|
||||
paff_array[i].patt.mask_size = 0;
|
||||
paff_array[i].rule = 0;
|
||||
if(paff_array[i].patt.mask){
|
||||
vPortFree(paff_array[i].patt.mask);
|
||||
paff_array[i].patt.mask = NULL;
|
||||
}
|
||||
|
||||
if(paff_array[i].patt.pattern){
|
||||
vPortFree(paff_array[i].patt.pattern);
|
||||
paff_array[i].patt.pattern = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make callback simple to prevent latency to wlan rx when promiscuous mode */
|
||||
static void promisc_callback(unsigned char *buf, unsigned int len, void* userdata)
|
||||
{
|
||||
struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
|
||||
|
||||
if(frame) {
|
||||
frame->prev = NULL;
|
||||
frame->next = NULL;
|
||||
memcpy(frame->da, buf, 6);
|
||||
memcpy(frame->sa, buf+6, 6);
|
||||
frame->len = len;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.tail) {
|
||||
eth_buffer.tail->next = frame;
|
||||
frame->prev = eth_buffer.tail;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = frame;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
|
||||
struct eth_frame* retrieve_frame(void)
|
||||
{
|
||||
struct eth_frame *frame = NULL;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.head) {
|
||||
frame = eth_buffer.head;
|
||||
|
||||
if(eth_buffer.head->next) {
|
||||
eth_buffer.head = eth_buffer.head->next;
|
||||
eth_buffer.head->prev = NULL;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
static void promisc_test(int duration, unsigned char len_used)
|
||||
{
|
||||
int ch;
|
||||
unsigned int start_time;
|
||||
struct eth_frame *frame;
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
|
||||
wifi_enter_promisc_mode();
|
||||
wifi_set_promisc(RTW_PROMISC_ENABLE, promisc_callback, len_used);
|
||||
|
||||
for(ch = 1; ch <= 13; ch ++) {
|
||||
if(wifi_set_channel(ch) == 0)
|
||||
printf("\n\n\rSwitch to channel(%d)", ch);
|
||||
|
||||
start_time = xTaskGetTickCount();
|
||||
|
||||
while(1) {
|
||||
unsigned int current_time = xTaskGetTickCount();
|
||||
|
||||
if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
|
||||
frame = retrieve_frame();
|
||||
|
||||
if(frame) {
|
||||
int i;
|
||||
printf("\n\rDA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->da[i]);
|
||||
printf(", SA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->sa[i]);
|
||||
printf(", len=%d", frame->len);
|
||||
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
else
|
||||
vTaskDelay(1); //delay 1 tick
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
|
||||
|
||||
while((frame = retrieve_frame()) != NULL)
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
|
||||
static void promisc_callback_all(unsigned char *buf, unsigned int len, void* userdata)
|
||||
{
|
||||
struct eth_frame *frame = (struct eth_frame *) pvPortMalloc(sizeof(struct eth_frame));
|
||||
|
||||
if(frame) {
|
||||
frame->prev = NULL;
|
||||
frame->next = NULL;
|
||||
memcpy(frame->da, buf+4, 6);
|
||||
memcpy(frame->sa, buf+10, 6);
|
||||
frame->len = len;
|
||||
frame->type = *buf;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
|
||||
if(eth_buffer.tail) {
|
||||
eth_buffer.tail->next = frame;
|
||||
frame->prev = eth_buffer.tail;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
else {
|
||||
eth_buffer.head = frame;
|
||||
eth_buffer.tail = frame;
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
static void promisc_test_all(int duration, unsigned char len_used)
|
||||
{
|
||||
int ch;
|
||||
unsigned int start_time;
|
||||
struct eth_frame *frame;
|
||||
eth_buffer.head = NULL;
|
||||
eth_buffer.tail = NULL;
|
||||
|
||||
wifi_enter_promisc_mode();
|
||||
wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used);
|
||||
|
||||
for(ch = 1; ch <= 13; ch ++) {
|
||||
if(wifi_set_channel(ch) == 0)
|
||||
printf("\n\n\rSwitch to channel(%d)", ch);
|
||||
|
||||
start_time = xTaskGetTickCount();
|
||||
|
||||
while(1) {
|
||||
unsigned int current_time = xTaskGetTickCount();
|
||||
|
||||
if((current_time - start_time) < (duration * configTICK_RATE_HZ)) {
|
||||
frame = retrieve_frame();
|
||||
|
||||
if(frame) {
|
||||
int i;
|
||||
printf("\n\rTYPE: 0x%x, ", frame->type);
|
||||
printf("DA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->da[i]);
|
||||
printf(", SA:");
|
||||
for(i = 0; i < 6; i ++)
|
||||
printf(" %02x", frame->sa[i]);
|
||||
printf(", len=%d", frame->len);
|
||||
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
else
|
||||
vTaskDelay(1); //delay 1 tick
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
|
||||
|
||||
while((frame = retrieve_frame()) != NULL)
|
||||
vPortFree((void *) frame);
|
||||
}
|
||||
|
||||
void cmd_promisc(int argc, char **argv)
|
||||
{
|
||||
int duration;
|
||||
#ifdef CONFIG_PROMISC
|
||||
wifi_init_packet_filter();
|
||||
#endif
|
||||
if((argc == 2) && ((duration = atoi(argv[1])) > 0))
|
||||
//promisc_test(duration, 0);
|
||||
promisc_test_all(duration, 0);
|
||||
else if((argc == 3) && ((duration = atoi(argv[1])) > 0) && (strcmp(argv[2], "with_len") == 0))
|
||||
promisc_test(duration, 1);
|
||||
else
|
||||
printf("\n\rUsage: %s DURATION_SECONDS [with_len]", argv[0]);
|
||||
}
|
||||
#endif //#if CONFIG_WLAN
|
602
component/common/api/wifi/wifi_simple_config.c
Normal file
602
component/common/api/wifi/wifi_simple_config.c
Normal file
|
@ -0,0 +1,602 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "udp.h"
|
||||
#include <sockets.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <osdep_service.h>
|
||||
#include "platform_stdlib.h"
|
||||
|
||||
#define STACKSIZE 512
|
||||
|
||||
|
||||
#if CONFIG_WLAN
|
||||
#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
|
||||
#include "wifi/wifi_conf.h"
|
||||
int is_promisc_callback_unlock = 0;
|
||||
static int is_fixed_channel;
|
||||
int fixed_channel_num;
|
||||
unsigned char g_ssid[32];
|
||||
int g_ssid_len;
|
||||
extern unsigned char g_bssid[];
|
||||
extern unsigned char g_security_mode;
|
||||
extern int promisc_get_fixed_channel( void *, u8 *, int* );
|
||||
struct pattern_test_ops;
|
||||
struct rtk_test_sc;
|
||||
|
||||
typedef int (*sc_test_check_pattern_call_back)(struct pattern_test_ops *pp, struct rtk_test_sc *pSc);
|
||||
typedef int (*sc_test_get_cipher_info_call_back)(struct pattern_test_ops *pp, struct rtk_test_sc *pSc);
|
||||
typedef int (*sc_test_generate_key_call_back)(struct pattern_test_ops *pp, struct rtk_test_sc *pSc);
|
||||
typedef int (*sc_test_decode_profile_call_back)(struct pattern_test_ops *pp, struct rtk_test_sc *pSc);
|
||||
typedef int (*sc_test_get_tlv_info_call_back)(struct pattern_test_ops *pp, struct rtk_test_sc *pSc);
|
||||
|
||||
struct pattern_test_ops {
|
||||
unsigned int index;
|
||||
unsigned flag;
|
||||
unsigned char name[64];
|
||||
sc_test_check_pattern_call_back check_pattern;
|
||||
sc_test_get_cipher_info_call_back get_cipher_info;
|
||||
sc_test_generate_key_call_back generate_key;
|
||||
sc_test_decode_profile_call_back decode_profile;
|
||||
sc_test_get_tlv_info_call_back get_tlv_info;
|
||||
};
|
||||
|
||||
|
||||
struct rtk_test_sc {
|
||||
int pattern_type;
|
||||
unsigned char smac[6]; /* the source mac of the profile packet, it maybe the Phone MAC */
|
||||
unsigned char dmac[6]; /* the destination mac, it is the DUT wlan MAC for send ack packet */
|
||||
unsigned char ssid[32];
|
||||
unsigned char password[65];
|
||||
unsigned int ip_addr;
|
||||
unsigned char sync_pkt[9][6]; /* parser syn start */
|
||||
unsigned char profile_pkt[256][6];
|
||||
unsigned int profile_pkt_len;
|
||||
unsigned char plain_buf[256];
|
||||
unsigned int plain_len;
|
||||
unsigned char key_buf[32]; /* kek */
|
||||
unsigned int key_len;
|
||||
unsigned char crypt_buf[256];
|
||||
unsigned int crypt_len;
|
||||
int pattern_index; /* pattern start index */
|
||||
struct pattern_ops *pattern[64]; /* pattern array */
|
||||
int max_pattern_num; /* total register pattern num */
|
||||
unsigned char pin[65];
|
||||
unsigned char default_pin[65];
|
||||
unsigned char have_pin;
|
||||
unsigned short device_type;
|
||||
unsigned char device_name[64];
|
||||
};
|
||||
|
||||
enum sc_result {
|
||||
SC_ERROR = -1, /* default error code*/
|
||||
SC_NO_CONTROLLER_FOUND = 1, /* cannot get sta(controller) in the air which starts a simple config session */
|
||||
SC_CONTROLLER_INFO_PARSE_FAIL, /* cannot parse the sta's info */
|
||||
SC_TARGET_CHANNEL_SCAN_FAIL, /* cannot scan the target channel */
|
||||
SC_JOIN_BSS_FAIL, /* fail to connect to target ap */
|
||||
SC_DHCP_FAIL, /* fail to get ip address from target ap */
|
||||
/* fail to create udp socket to send info to controller. note that client isolation
|
||||
must be turned off in ap. we cannot know if ap has configured this */
|
||||
SC_UDP_SOCKET_CREATE_FAIL,
|
||||
SC_SUCCESS, /* default success code */
|
||||
|
||||
};
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct ack_msg {
|
||||
PACK_STRUCT_FIELD(u8_t flag);
|
||||
PACK_STRUCT_FIELD(u16_t length);
|
||||
PACK_STRUCT_FIELD(u8_t smac[6]);
|
||||
PACK_STRUCT_FIELD(u8_t status);
|
||||
PACK_STRUCT_FIELD(u16_t device_type);
|
||||
PACK_STRUCT_FIELD(u32_t device_ip);
|
||||
PACK_STRUCT_FIELD(u8_t device_name[64]);
|
||||
};PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MULCAST_PORT (8864)
|
||||
|
||||
#define WIFI_LINK_CONNECTED (1)
|
||||
|
||||
#define SCAN_BUFFER_LENGTH (1024)
|
||||
|
||||
#ifndef WLAN0_NAME
|
||||
#define WLAN0_NAME "wlan0"
|
||||
#endif
|
||||
|
||||
int simple_config_result;
|
||||
static struct ack_msg *ack_content;
|
||||
static struct rtk_test_sc *backup_sc_ctx;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
void SC_set_ack_content()
|
||||
{
|
||||
memset(ack_content, 0, sizeof(struct ack_msg));
|
||||
ack_content->flag = 0x20;
|
||||
ack_content->length = htons(sizeof(struct ack_msg)-3);
|
||||
memcpy(ack_content->smac, xnetif[0].hwaddr, 6);
|
||||
ack_content->status = 0;
|
||||
ack_content->device_type = 0;
|
||||
ack_content->device_ip = xnetif[0].ip_addr.addr;
|
||||
memset(ack_content->device_name, 0, 64);
|
||||
}
|
||||
|
||||
int SC_send_simple_config_ack()
|
||||
{
|
||||
|
||||
int ack_transmit_round, ack_num_each_sec;
|
||||
int ack_socket;
|
||||
//int sended_data = 0;
|
||||
struct sockaddr_in to_addr;
|
||||
|
||||
SC_set_ack_content();
|
||||
|
||||
ack_socket = socket(PF_INET, SOCK_DGRAM, IP_PROTO_UDP);
|
||||
if (ack_socket == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FD_ZERO(&to_addr);
|
||||
to_addr.sin_family = AF_INET;
|
||||
to_addr.sin_port = htons(8864);
|
||||
to_addr.sin_addr.s_addr = (backup_sc_ctx->ip_addr);
|
||||
|
||||
for (ack_transmit_round = 0;ack_transmit_round < 10; ack_transmit_round++) {
|
||||
for (ack_num_each_sec = 0;ack_num_each_sec < 20; ack_num_each_sec++) {
|
||||
//sended_data =
|
||||
sendto(ack_socket, (unsigned char *)ack_content, sizeof(struct ack_msg), 0, (struct sockaddr *) &to_addr, sizeof(struct sockaddr));
|
||||
//printf("\r\nAlready send %d bytes data\n", sended_data);
|
||||
vTaskDelay(50); /* delay 50 ms */
|
||||
}
|
||||
}
|
||||
close(ack_socket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int SC_check_and_show_connection_info(void)
|
||||
{
|
||||
rtw_wifi_setting_t setting;
|
||||
int ret = -1;
|
||||
|
||||
/* If not rise priority, LwIP DHCP may timeout */
|
||||
vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 3);
|
||||
/* Start DHCP Client */
|
||||
ret = LwIP_DHCP(0, DHCP_START);
|
||||
vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 1);
|
||||
|
||||
wifi_get_setting(WLAN0_NAME, &setting);
|
||||
wifi_show_setting(WLAN0_NAME, &setting);
|
||||
|
||||
if (ret == DHCP_ADDRESS_ASSIGNED)
|
||||
return SC_SUCCESS;
|
||||
else
|
||||
return SC_DHCP_FAIL;
|
||||
}
|
||||
|
||||
static void check_and_set_security_in_connection(rtw_security_t security_mode, rtw_network_info_t *wifi)
|
||||
{
|
||||
|
||||
if (security_mode == RTW_SECURITY_WPA2_AES_PSK) {
|
||||
printf("\r\nwifi->security_type = RTW_SECURITY_WPA2_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
} else if (security_mode == RTW_SECURITY_WEP_PSK) {
|
||||
printf("\r\nwifi->security_type = RTW_SECURITY_WEP_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WEP_PSK;
|
||||
wifi->key_id = 0;
|
||||
} else if (security_mode == RTW_SECURITY_WPA_AES_PSK) {
|
||||
printf("\r\nwifi->security_type = RTW_SECURITY_WPA_AES_PSK\n");
|
||||
wifi->security_type = RTW_SECURITY_WPA_AES_PSK;
|
||||
} else {
|
||||
printf("\r\nwifi->security_type = RTW_SECURITY_OPEN\n");
|
||||
wifi->security_type = RTW_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_connection_info_from_profile(rtw_security_t security_mode, rtw_network_info_t *wifi)
|
||||
{
|
||||
|
||||
printf("\r\n======= Connection Information =======\n");
|
||||
check_and_set_security_in_connection(security_mode, wifi);
|
||||
|
||||
wifi->password = backup_sc_ctx->password;
|
||||
wifi->password_len = (int)strlen((char const *)backup_sc_ctx->password);
|
||||
|
||||
if ( g_ssid_len > 0 && g_ssid_len < 33){
|
||||
wifi->ssid.len = g_ssid_len;
|
||||
rtw_memcpy(wifi->ssid.val, g_ssid, wifi->ssid.len);
|
||||
}else if(strlen(backup_sc_ctx->ssid) > 0 && strlen(backup_sc_ctx->ssid) < 33){
|
||||
wifi->ssid.len = strlen(backup_sc_ctx->ssid);
|
||||
rtw_memcpy(wifi->ssid.val, backup_sc_ctx->ssid, wifi->ssid.len);
|
||||
}else{
|
||||
printf("\r\n SSID is NULL or SSID length is over 32!!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(wifi->security_type == RTW_SECURITY_WEP_PSK)
|
||||
{
|
||||
if(wifi->password_len == 10)
|
||||
{
|
||||
u32 p[5];
|
||||
u8 pwd[6], i = 0;
|
||||
sscanf((const char*)backup_sc_ctx->password, "%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4]);
|
||||
for(i=0; i< 5; i++)
|
||||
pwd[i] = (u8)p[i];
|
||||
pwd[5] = '\0';
|
||||
memset(backup_sc_ctx->password, 0, 65);
|
||||
strcpy((char*)backup_sc_ctx->password, (char*)pwd);
|
||||
wifi->password_len = 5;
|
||||
}else if(wifi->password_len == 26){
|
||||
u32 p[13];
|
||||
u8 pwd[14], i = 0;
|
||||
sscanf((const char*)backup_sc_ctx->password, "%02x%02x%02x%02x%02x%02x%02x"\
|
||||
"%02x%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3], &p[4],\
|
||||
&p[5], &p[6], &p[7], &p[8], &p[9], &p[10], &p[11], &p[12]);
|
||||
for(i=0; i< 13; i++)
|
||||
pwd[i] = (u8)p[i];
|
||||
pwd[13] = '\0';
|
||||
memset(backup_sc_ctx->password, 0, 64);
|
||||
strcpy((char*)backup_sc_ctx->password, (char*)pwd);
|
||||
wifi->password_len = 13;
|
||||
}
|
||||
}
|
||||
printf("\r\nwifi.password = %s\n", wifi->password);
|
||||
printf("\r\nwifi.password_len = %d\n", wifi->password_len);
|
||||
printf("\r\nwifi.ssid = %s\n", wifi->ssid.val);
|
||||
printf("\r\nwifi.ssid_len = %d\n", wifi->ssid.len);
|
||||
printf("\r\nwifi.channel = %d\n", fixed_channel_num);
|
||||
printf("\r\n===== start to connect target AP =====\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SC_connect_to_AP(void)
|
||||
{
|
||||
int ret = SC_ERROR;
|
||||
u8 scan_channel;
|
||||
u8 pscan_config;
|
||||
int retry = 3;
|
||||
rtw_security_t security_mode;
|
||||
rtw_network_info_t wifi = {0};
|
||||
if(!(fixed_channel_num == 0)){
|
||||
scan_channel = fixed_channel_num;
|
||||
}
|
||||
pscan_config = PSCAN_ENABLE;
|
||||
switch(g_security_mode){
|
||||
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:
|
||||
printf("\r\n unknow security mode,connect fail!");
|
||||
return ret;
|
||||
}
|
||||
g_security_mode = 0xff;//clear it
|
||||
|
||||
if (-1 == get_connection_info_from_profile(security_mode, &wifi)) {
|
||||
ret = SC_CONTROLLER_INFO_PARSE_FAIL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if(wifi_set_pscan_chan(&scan_channel, &pscan_config, 1) < 0){
|
||||
printf("\n\rERROR: wifi set partial scan channel fail");
|
||||
ret = SC_TARGET_CHANNEL_SCAN_FAIL;
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
ret = wifi_connect((char*)wifi.ssid.val,
|
||||
wifi.security_type,
|
||||
(char*)wifi.password,
|
||||
wifi.ssid.len,
|
||||
wifi.password_len,
|
||||
wifi.key_id,
|
||||
NULL);
|
||||
#else
|
||||
ret = wifi_connect_bssid(g_bssid,
|
||||
(char*)wifi.ssid.val,
|
||||
wifi.security_type,
|
||||
(char*)wifi.password,
|
||||
6,
|
||||
wifi.ssid.len,
|
||||
wifi.password_len,
|
||||
wifi.key_id,
|
||||
NULL);
|
||||
#endif
|
||||
if (ret == RTW_SUCCESS) {
|
||||
ret = SC_check_and_show_connection_info();
|
||||
break;
|
||||
}
|
||||
|
||||
if (retry == 0) {
|
||||
ret = SC_JOIN_BSS_FAIL;
|
||||
break;
|
||||
}
|
||||
retry --;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* Make callback one by one to wlan rx when promiscuous mode */
|
||||
extern int rtk_start_parse_packet(unsigned char *da, unsigned char *sa, int len, void *user_data, struct rtk_test_sc *backup_sc_ctx);
|
||||
void simple_config_callback(unsigned char *buf, unsigned int len, void* userdata)
|
||||
{
|
||||
unsigned char * da = buf;
|
||||
unsigned char * sa = buf + ETH_ALEN;
|
||||
taskENTER_CRITICAL();
|
||||
if (is_promisc_callback_unlock == 1) {
|
||||
simple_config_result = rtk_start_parse_packet(da, sa, len, userdata, backup_sc_ctx);
|
||||
//printf("\r\nresult in callback function = %d\n",simple_config_result);
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
}
|
||||
|
||||
static unsigned int simple_config_cmd_start_time;
|
||||
static unsigned int simple_config_cmd_current_time;
|
||||
extern int simple_config_status;
|
||||
extern void rtk_restart_simple_config(void);
|
||||
|
||||
extern int rtk_sc_init(char *custom_pin_code);
|
||||
extern void rtk_sc_deinit(void);
|
||||
|
||||
int init_test_data(char *custom_pin_code)
|
||||
{
|
||||
#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
|
||||
is_promisc_callback_unlock = 1;
|
||||
is_fixed_channel = 0;
|
||||
fixed_channel_num = 0;
|
||||
simple_config_result = 0;
|
||||
rtw_memset(g_ssid, 0, 32);
|
||||
g_ssid_len = 0;
|
||||
simple_config_cmd_start_time = xTaskGetTickCount();
|
||||
|
||||
if (ack_content != NULL) {
|
||||
vPortFree(ack_content);
|
||||
ack_content = NULL;
|
||||
}
|
||||
ack_content = pvPortMalloc(sizeof(struct ack_msg));
|
||||
if (!ack_content) {
|
||||
printf("\n\rrtk_sc_init fail by allocate ack\n");
|
||||
}
|
||||
memset(ack_content, 0, sizeof(struct ack_msg));
|
||||
|
||||
|
||||
if(custom_pin_code) {
|
||||
backup_sc_ctx = pvPortMalloc(sizeof(struct rtk_test_sc));
|
||||
if (!backup_sc_ctx) {
|
||||
printf("\n\r[Mem]malloc SC context fail\n");
|
||||
} else {
|
||||
memset(backup_sc_ctx, 0, sizeof(struct rtk_test_sc));
|
||||
if (rtk_sc_init(custom_pin_code) < 0) {
|
||||
printf("\n\rRtk_sc_init fail\n");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else{
|
||||
backup_sc_ctx = pvPortMalloc(sizeof(struct rtk_test_sc));
|
||||
if (!backup_sc_ctx) {
|
||||
printf("\n\r[Mem]malloc SC context fail\n");
|
||||
} else {
|
||||
memset(backup_sc_ctx, 0, sizeof(struct rtk_test_sc));
|
||||
if (rtk_sc_init(NULL) < 0){
|
||||
printf("\n\rRtk_sc_init fail\n");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
printf("\n\rPlatform no include simple config now\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
void deinit_test_data(){
|
||||
#if (CONFIG_INCLUDE_SIMPLE_CONFIG)
|
||||
rtk_sc_deinit();
|
||||
if (backup_sc_ctx != NULL) {
|
||||
vPortFree(backup_sc_ctx);
|
||||
backup_sc_ctx = NULL;
|
||||
}
|
||||
if (ack_content != NULL) {
|
||||
vPortFree(ack_content);
|
||||
ack_content = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int simple_config_test(void)
|
||||
{
|
||||
int channel = 1;
|
||||
int ret = SC_SUCCESS;
|
||||
unsigned int start_time;
|
||||
int is_need_connect_to_AP = 0;
|
||||
int fix_channel = 0;
|
||||
int delta_time = 0;
|
||||
wifi_set_promisc(RTW_PROMISC_ENABLE, simple_config_callback, 1);
|
||||
start_time = xTaskGetTickCount();
|
||||
printf("\n\r");
|
||||
wifi_set_channel(channel);
|
||||
while (1) {
|
||||
vTaskDelay(50); //delay 0.5s to release CPU usage
|
||||
simple_config_cmd_current_time = xTaskGetTickCount();
|
||||
if (simple_config_cmd_current_time - simple_config_cmd_start_time < ((120 + delta_time)*configTICK_RATE_HZ)) {
|
||||
unsigned int current_time = xTaskGetTickCount();
|
||||
if (((current_time - start_time)*1000 /configTICK_RATE_HZ < 100)
|
||||
|| (is_fixed_channel == 1)) {
|
||||
if((is_fixed_channel == 0)&&(!((fix_channel = promisc_get_fixed_channel(g_bssid,g_ssid,&g_ssid_len))== 0))){
|
||||
//printf("\r\n in simple_config_test fix channel = %d ",fix_channel);
|
||||
is_fixed_channel = 1;
|
||||
fixed_channel_num = fix_channel;
|
||||
wifi_set_channel(fix_channel);
|
||||
}
|
||||
if (simple_config_result == 1) {
|
||||
is_need_connect_to_AP = 1;
|
||||
is_fixed_channel = 0;
|
||||
break;
|
||||
}
|
||||
if (simple_config_result == -1) {
|
||||
printf("\r\nsimple_config_test restart for result = -1");
|
||||
delta_time = 60;
|
||||
wifi_set_channel(1);
|
||||
is_need_connect_to_AP = 0;
|
||||
is_fixed_channel = 0;
|
||||
fixed_channel_num = 0;
|
||||
memset(g_ssid, 0, 32);
|
||||
g_ssid_len = 0;
|
||||
simple_config_result = 0;
|
||||
g_security_mode = 0xff;
|
||||
rtk_restart_simple_config();
|
||||
}
|
||||
if (simple_config_result == -2) {
|
||||
printf("\n\rThe APP or client must have pin!\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
channel++;
|
||||
if ((1 <= channel) && (channel <= 13)) {
|
||||
if (wifi_set_channel(channel) == 0) {
|
||||
start_time = xTaskGetTickCount();
|
||||
printf("\n\rSwitch to channel(%d)\n", channel);
|
||||
}
|
||||
} else {
|
||||
channel = 1;
|
||||
if (wifi_set_channel(channel) == 0) {
|
||||
start_time = xTaskGetTickCount();
|
||||
printf("\n\rSwitch to channel(%d)\n", channel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
ret = SC_NO_CONTROLLER_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0);
|
||||
if (is_need_connect_to_AP == 1) {
|
||||
int tmp_res = SC_connect_to_AP();
|
||||
if (SC_SUCCESS == tmp_res) {
|
||||
if(-1 == SC_send_simple_config_ack())
|
||||
ret = SC_UDP_SOCKET_CREATE_FAIL;
|
||||
} else {
|
||||
return tmp_res;
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = SC_NO_CONTROLLER_FOUND;
|
||||
}
|
||||
|
||||
deinit_test_data();
|
||||
return ret;
|
||||
}
|
||||
|
||||
//Filter packet da[] = {0x01, 0x00, 0x5e}
|
||||
#define MASK_SIZE 3
|
||||
void filter_add_enable(){
|
||||
u8 mask[MASK_SIZE]={0xFF,0xFF,0xFF};
|
||||
u8 pattern[MASK_SIZE]={0x01,0x00,0x5e};
|
||||
|
||||
rtw_packet_filter_pattern_t packet_filter;
|
||||
rtw_packet_filter_rule_e rule;
|
||||
|
||||
packet_filter.offset = 0;
|
||||
packet_filter.mask_size = 3;
|
||||
packet_filter.mask = mask;
|
||||
packet_filter.pattern = pattern;
|
||||
rule = RTW_POSITIVE_MATCHING;
|
||||
|
||||
wifi_init_packet_filter();
|
||||
wifi_add_packet_filter(1, &packet_filter,rule);
|
||||
wifi_enable_packet_filter(1);
|
||||
}
|
||||
void remove_filter(){
|
||||
wifi_disable_packet_filter(1);
|
||||
wifi_remove_packet_filter(1);
|
||||
}
|
||||
|
||||
void print_simple_config_result(enum sc_result sc_code)
|
||||
{
|
||||
printf("\r\n");
|
||||
switch (sc_code) {
|
||||
case SC_NO_CONTROLLER_FOUND:
|
||||
printf("Simple Config timeout!! Can't get Ap profile. Please try again\n");
|
||||
break;
|
||||
case SC_CONTROLLER_INFO_PARSE_FAIL:
|
||||
printf("Simple Config fail, cannot parse target ap info from controller\n");
|
||||
break;
|
||||
case SC_TARGET_CHANNEL_SCAN_FAIL:
|
||||
printf("Simple Config cannot scan the target channel\n");
|
||||
break;
|
||||
case SC_JOIN_BSS_FAIL:
|
||||
printf("Simple Config Join bss failed\n");
|
||||
break;
|
||||
case SC_DHCP_FAIL:
|
||||
printf("Simple Config fail, cannot get dhcp ip address\n");
|
||||
break;
|
||||
case SC_UDP_SOCKET_CREATE_FAIL:
|
||||
printf("Simple Config Ack socket create fail!!!\n");
|
||||
break;
|
||||
case SC_SUCCESS:
|
||||
printf("Simple Config success\n");
|
||||
break;
|
||||
|
||||
case SC_ERROR:
|
||||
default:
|
||||
printf("unknown error when simple config!\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //CONFIG_INCLUDE_SIMPLE_CONFIG
|
||||
|
||||
void cmd_simple_config(int argc, char **argv){
|
||||
#if CONFIG_INCLUDE_SIMPLE_CONFIG
|
||||
char *custom_pin_code = NULL;
|
||||
int ret = SC_ERROR;
|
||||
|
||||
if(argc > 2){
|
||||
printf("\n\rInput Error!");
|
||||
}
|
||||
|
||||
if(argc == 2)
|
||||
custom_pin_code = (argv[1]);
|
||||
|
||||
wifi_enter_promisc_mode();
|
||||
if(init_test_data(custom_pin_code) == 0){
|
||||
filter_add_enable();
|
||||
ret = simple_config_test();
|
||||
print_simple_config_result(ret);
|
||||
remove_filter();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif //#if CONFIG_WLAN
|
933
component/common/api/wifi/wifi_util.c
Normal file
933
component/common/api/wifi/wifi_util.c
Normal file
|
@ -0,0 +1,933 @@
|
|||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include <wifi/wifi_ind.h>
|
||||
#include <osdep_service.h>
|
||||
|
||||
int iw_ioctl(const char * ifname, unsigned long request, struct iwreq * pwrq)
|
||||
{
|
||||
memcpy(pwrq->ifr_name, ifname, 5);
|
||||
return rltk_wlan_control(request, (void *) pwrq);
|
||||
}
|
||||
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.essid.pointer = ssid;
|
||||
iwr.u.essid.length = 32;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWESSID, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWESSID] ssid = NULL, not connected"); //do not use perror
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = iwr.u.essid.length;
|
||||
if (ret > 32)
|
||||
ret = 32;
|
||||
/* Some drivers include nul termination in the SSID, so let's
|
||||
* remove it here before further processing. WE-21 changes this
|
||||
* to explicitly require the length _not_ to include nul
|
||||
* termination. */
|
||||
if (ret > 0 && ssid[ret - 1] == '\0')
|
||||
ret--;
|
||||
ssid[ret] = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.essid.pointer = (void *) ssid;
|
||||
iwr.u.essid.length = ssid_len;
|
||||
iwr.u.essid.flags = (ssid_len != 0);
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWESSID, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWESSID] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_bssid(const char *ifname, const __u8 *bssid)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
|
||||
memcpy(iwr.u.ap_addr.sa_data, bssid, ETH_ALEN);
|
||||
|
||||
if(bssid[ETH_ALEN]=='#' && bssid[ETH_ALEN + 1]=='@'){
|
||||
memcpy(iwr.u.ap_addr.sa_data + ETH_ALEN, bssid + ETH_ALEN, 6);
|
||||
}
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWAP, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWAP] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int is_broadcast_ether_addr(const unsigned char *addr)
|
||||
{
|
||||
return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
|
||||
}
|
||||
|
||||
int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.param.flags = idx & IW_AUTH_INDEX;
|
||||
iwr.u.param.value = value;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWAUTH, &iwr) < 0) {
|
||||
printf("\n\rWEXT: SIOCSIWAUTH(param %d value 0x%x) failed)", idx, value);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
struct iw_encode_ext *ext;
|
||||
|
||||
ext = (struct iw_encode_ext *) malloc(sizeof(struct iw_encode_ext) + key_len);
|
||||
if (ext == NULL)
|
||||
return -1;
|
||||
else
|
||||
memset(ext, 0, sizeof(struct iw_encode_ext) + key_len);
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.encoding.flags = key_idx + 1;
|
||||
iwr.u.encoding.flags |= IW_ENCODE_TEMP;
|
||||
iwr.u.encoding.pointer = ext;
|
||||
iwr.u.encoding.length = sizeof(struct iw_encode_ext) + key_len;
|
||||
|
||||
if (alg == IW_ENCODE_DISABLED)
|
||||
iwr.u.encoding.flags |= IW_ENCODE_DISABLED;
|
||||
|
||||
if (addr == NULL || is_broadcast_ether_addr(addr))
|
||||
ext->ext_flags |= IW_ENCODE_EXT_GROUP_KEY;
|
||||
|
||||
if (set_tx)
|
||||
ext->ext_flags |= IW_ENCODE_EXT_SET_TX_KEY;
|
||||
|
||||
ext->addr.sa_family = ARPHRD_ETHER;
|
||||
|
||||
if (addr)
|
||||
memcpy(ext->addr.sa_data, addr, ETH_ALEN);
|
||||
else
|
||||
memset(ext->addr.sa_data, 0xff, ETH_ALEN);
|
||||
|
||||
if (key && key_len) {
|
||||
memcpy(ext->key, key, key_len);
|
||||
ext->key_len = key_len;
|
||||
}
|
||||
|
||||
ext->alg = alg;
|
||||
|
||||
if (seq && seq_len) {
|
||||
ext->ext_flags |= IW_ENCODE_EXT_RX_SEQ_VALID;
|
||||
memcpy(ext->rx_seq, seq, seq_len);
|
||||
}
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWENCODEEXT, &iwr) < 0) {
|
||||
ret = -2;
|
||||
printf("\n\rioctl[SIOCSIWENCODEEXT] set key fail");
|
||||
}
|
||||
|
||||
if(ext != NULL)
|
||||
free(ext);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
struct iw_encode_ext *ext;
|
||||
|
||||
ext = (struct iw_encode_ext *) malloc(sizeof(struct iw_encode_ext) + 16);
|
||||
if (ext == NULL)
|
||||
return -1;
|
||||
else
|
||||
memset(ext, 0, sizeof(struct iw_encode_ext) + 16);
|
||||
|
||||
iwr.u.encoding.pointer = ext;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWENCODEEXT, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWENCODEEXT] error");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*alg = ext->alg;
|
||||
if(key_idx)
|
||||
*key_idx = (__u8)iwr.u.encoding.flags;
|
||||
if(passphrase)
|
||||
memcpy(passphrase, ext->key, ext->key_len);
|
||||
}
|
||||
|
||||
if(ext != NULL)
|
||||
free(ext);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.passphrase.pointer = (void *) passphrase;
|
||||
iwr.u.passphrase.length = passphrase_len;
|
||||
iwr.u.passphrase.flags = (passphrase_len != 0);
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWPRIVPASSPHRASE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWESSID+0x1f] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.passphrase.pointer = (void *) passphrase;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWPRIVPASSPHRASE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWPRIVPASSPHRASE] error");
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
ret = iwr.u.passphrase.length;
|
||||
passphrase[ret] = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int wext_disconnect(const char *ifname)
|
||||
{
|
||||
int ret = 0;
|
||||
const __u8 null_bssid[ETH_ALEN] = {0, 0, 0, 0, 0, 1}; //set the last to 1 since driver will filter the mac with all 0x00 or 0xff
|
||||
|
||||
if (wext_set_bssid(ifname, null_bssid) < 0){
|
||||
printf("\n\rWEXT: Failed to set bogus BSSID to disconnect");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_mac_address(const char *ifname, char * mac)
|
||||
{
|
||||
char buf[13+17+1];
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 13+17, "write_mac %s", mac);
|
||||
return wext_private_command(ifname, buf, 0);
|
||||
}
|
||||
|
||||
int wext_get_mac_address(const char *ifname, char * mac)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[32];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
rtw_memcpy(buf, "read_mac", 8);
|
||||
ret = wext_private_command_with_retval(ifname, buf, buf, 32);
|
||||
strcpy(mac, buf);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int wext_enable_powersave(const char *ifname)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("pm_set");
|
||||
para = pvPortMalloc(24);
|
||||
|
||||
snprintf((char*)para, cmd_len, "pm_set");
|
||||
*(para+cmd_len) = 1; //ips=1;
|
||||
*(para+cmd_len+1) = 1;//lps=1
|
||||
|
||||
iwr.u.essid.pointer = para;
|
||||
iwr.u.essid.length = cmd_len + 2;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_disable_powersave(const char *ifname)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("pm_set");
|
||||
para = pvPortMalloc(24);
|
||||
|
||||
snprintf((char*)para, cmd_len, "pm_set");
|
||||
*(para+cmd_len) = 0; //ips=0;
|
||||
*(para+cmd_len+1) = 0;//lps=0
|
||||
|
||||
iwr.u.essid.pointer = para;
|
||||
iwr.u.essid.length = cmd_len + 2;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
int wext_get_txpower(const char *ifname, int *poweridx)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[11];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
rtw_memcpy(buf, "txpower", 11);
|
||||
ret = wext_private_command_with_retval(ifname, buf, buf, 11);
|
||||
sscanf(buf, "%d", poweridx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_txpower(const char *ifname, int poweridx)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[24];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 24, "txpower patha=%d", poweridx);
|
||||
ret = wext_private_command(ifname, buf, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, uint16_t buffer_length)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[25];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 25, "get_client_list %x", client_list_buffer);
|
||||
ret = wext_private_command(ifname, buf, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[24];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 24, "get_ap_info %x", ap_info);
|
||||
ret = wext_private_command(ifname, buf, 0);
|
||||
|
||||
snprintf(buf, 24, "get_security");
|
||||
ret = wext_private_command_with_retval(ifname, buf, buf, 24);
|
||||
sscanf(buf, "%d", security);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int wext_set_mode(const char *ifname, int mode)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.mode = mode;
|
||||
if (iw_ioctl(ifname, SIOCSIWMODE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWMODE] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_mode(const char *ifname, int *mode)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWMODE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWMODE] error");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
*mode = iwr.u.mode;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.essid.pointer = (void *) ssid;
|
||||
iwr.u.essid.length = ssid_len;
|
||||
iwr.u.essid.flags = (ssid_len != 0);
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWPRIVAPESSID, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWPRIVAPESSID] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_country(const char *ifname, char *country_code)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
|
||||
iwr.u.data.pointer = country_code;
|
||||
if (iw_ioctl(ifname, SIOCSIWPRIVCOUNTRY, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWPRIVCOUNTRY] error");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_rssi(const char *ifname, int *rssi)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWSENS, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWSENS] error");
|
||||
ret = -1;
|
||||
} else {
|
||||
*rssi = 0 - iwr.u.sens.value;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int i =0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
//Format of para:function_name num_channel chan1... pscan_config1 ...
|
||||
para = pvPortMalloc((length + length + 1) + 12);//size:num_chan + num_time + length + function_name
|
||||
//Cmd
|
||||
snprintf((char*)para, 12, "PartialScan");
|
||||
//length
|
||||
*(para+12) = length;
|
||||
for(i = 0; i < length; i++){
|
||||
*(para + 13 + i)= *(ch + i);
|
||||
*((__u16*) (para + 13 + length + i))= *(pscan_config + i);
|
||||
}
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = (length + length + 1) + 12;
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_set_pscan_channel():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
}
|
||||
int wext_set_channel(const char *ifname, __u8 ch)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.freq.m = 0;
|
||||
iwr.u.freq.e = 0;
|
||||
iwr.u.freq.i = ch;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCSIWFREQ, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWFREQ] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_channel(const char *ifname, __u8 *ch)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
|
||||
if (iw_ioctl(ifname, SIOCGIWFREQ, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWFREQ] error");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
*ch = iwr.u.freq.i;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[32];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 32, "reg_multicast "MAC_FMT, MAC_ARG(mac->octet));
|
||||
ret = wext_private_command(ifname, buf, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[35];
|
||||
|
||||
rtw_memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, 35, "reg_multicast -d "MAC_FMT, MAC_ARG(mac->octet));
|
||||
ret = wext_private_command(ifname, buf, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
#if 0 //for scan_with_ssid
|
||||
if(buf)
|
||||
memset(buf, 0, buf_len);
|
||||
#endif
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.flags = flags;
|
||||
iwr.u.data.length = buf_len;
|
||||
if (iw_ioctl(ifname, SIOCSIWSCAN, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWSCAN] error");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_scan(const char *ifname, char *buf, __u16 buf_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.length = buf_len;
|
||||
if (iw_ioctl(ifname, SIOCGIWSCAN, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCGIWSCAN] error");
|
||||
ret = -1;
|
||||
}else
|
||||
ret = iwr.u.data.flags;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0, buf_size;
|
||||
char *buf;
|
||||
|
||||
buf_size = 128;
|
||||
if(strlen(cmd) >= buf_size)
|
||||
buf_size = strlen(cmd) + 1; // 1 : '\0'
|
||||
buf = (char*)pvPortMalloc(buf_size);
|
||||
if(!buf){
|
||||
printf("\n\rWEXT: Can't malloc memory");
|
||||
return -1;
|
||||
}
|
||||
memset(buf, 0, buf_size);
|
||||
strcpy(buf, cmd);
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.length = buf_size;
|
||||
iwr.u.data.flags = 0;
|
||||
|
||||
if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
|
||||
printf("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
|
||||
}
|
||||
if(ret_buf){
|
||||
if(ret_len > iwr.u.data.length)
|
||||
ret_len = iwr.u.data.length;
|
||||
rtw_memcpy(ret_buf, (char *) iwr.u.data.pointer, ret_len);
|
||||
}
|
||||
vPortFree(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_private_command(const char *ifname, char *cmd, int show_msg)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0, buf_size;
|
||||
char *buf;
|
||||
|
||||
buf_size = 2048; // 2048 for efuse_get realmap
|
||||
if(strlen(cmd) >= buf_size)
|
||||
buf_size = strlen(cmd) + 1; // 1 : '\0'
|
||||
buf = (char*)pvPortMalloc(buf_size);
|
||||
if(!buf){
|
||||
printf("\n\rWEXT: Can't malloc memory");
|
||||
return -1;
|
||||
}
|
||||
memset(buf, 0, buf_size);
|
||||
strcpy(buf, cmd);
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.length = buf_size;
|
||||
iwr.u.data.flags = 0;
|
||||
|
||||
if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) {
|
||||
printf("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret);
|
||||
}
|
||||
if (show_msg && iwr.u.data.length) {
|
||||
if(iwr.u.data.length > buf_size)
|
||||
printf("\n\rWEXT: Malloc memory is not enough");
|
||||
printf("\n\rPrivate Message: %s", (char *) iwr.u.data.pointer);
|
||||
}
|
||||
vPortFree(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra)
|
||||
{
|
||||
unsigned char null_mac[6] = {0};
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case SIOCGIWAP:
|
||||
if(wrqu->ap_addr.sa_family == ARPHRD_ETHER)
|
||||
{
|
||||
if(!memcmp(wrqu->ap_addr.sa_data, null_mac, sizeof(null_mac)))
|
||||
wifi_indication(WIFI_EVENT_DISCONNECT, NULL, 0, 0);
|
||||
else
|
||||
wifi_indication(WIFI_EVENT_CONNECT, wrqu->ap_addr.sa_data, sizeof(null_mac), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case IWEVCUSTOM:
|
||||
if(extra)
|
||||
{
|
||||
if(!memcmp(IW_EXT_STR_FOURWAY_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE)))
|
||||
wifi_indication(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE), 0);
|
||||
else if(!memcmp(IW_EXT_STR_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL)))
|
||||
wifi_indication(WIFI_EVENT_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL), 0);
|
||||
else if(!memcmp(IW_EVT_STR_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK)))
|
||||
wifi_indication(WIFI_EVENT_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK), 0);
|
||||
#ifdef CONFIG_P2P_NEW
|
||||
else if(!memcmp(IW_EVT_STR_STA_ASSOC, extra, strlen(IW_EVT_STR_STA_ASSOC)))
|
||||
wifi_indication(WIFI_EVENT_STA_ASSOC, wrqu->data.pointer, wrqu->data.length, 0);
|
||||
else if(!memcmp(IW_EVT_STR_STA_DISASSOC, extra, strlen(IW_EVT_STR_STA_DISASSOC)))
|
||||
wifi_indication(WIFI_EVENT_STA_DISASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0);
|
||||
else if(!memcmp(IW_EVT_STR_SEND_ACTION_DONE, extra, strlen(IW_EVT_STR_SEND_ACTION_DONE)))
|
||||
wifi_indication(WIFI_EVENT_SEND_ACTION_DONE, NULL, 0, wrqu->data.flags);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case SIOCGIWSCAN:
|
||||
if(wrqu->data.pointer == NULL)
|
||||
wifi_indication(WIFI_EVENT_SCAN_DONE, wrqu->data.pointer, 0, 0);
|
||||
else
|
||||
wifi_indication(WIFI_EVENT_SCAN_RESULT_REPORT, wrqu->data.pointer, 0, 0);
|
||||
break;
|
||||
#ifdef CONFIG_P2P_NEW
|
||||
case IWEVMGNTRECV:
|
||||
wifi_indication(WIFI_EVENT_RX_MGNT, wrqu->data.pointer, wrqu->data.length, wrqu->data.flags);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef CONFIG_P2P_NEW
|
||||
int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.length = buf_len;
|
||||
iwr.u.data.flags = flags;
|
||||
if (iw_ioctl(ifname, SIOCSIWMGNTSEND, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWMGNTSEND] error");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.data.pointer = buf;
|
||||
iwr.u.data.length = buf_len;
|
||||
iwr.u.data.flags = flags;
|
||||
if (iw_ioctl(ifname, SIOCSIWGENIE, &iwr) < 0) {
|
||||
printf("\n\rioctl[SIOCSIWGENIE] error");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_autoreconnect(const char *ifname, __u8 mode)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("SetAutoRecnt");
|
||||
para = pvPortMalloc((1) + cmd_len);//size:para_len+cmd_len
|
||||
//Cmd
|
||||
snprintf((char*)para, cmd_len, "SetAutoRecnt");
|
||||
//length
|
||||
*(para+cmd_len) = mode; //para
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = (1) + cmd_len;
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_get_autoreconnect(const char *ifname, __u8 *mode)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("GetAutoRecnt");
|
||||
//para = pvPortMalloc((1) + cmd_len);//size:para_len+cmd_len
|
||||
para = pvPortMalloc(cmd_len);//size:para_len+cmd_len
|
||||
//Cmd
|
||||
snprintf((char*)para, cmd_len, "GetAutoRecnt");
|
||||
//length
|
||||
//*(para+cmd_len) = *mode; //para
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
//iwr.u.data.length = (1) + cmd_len;
|
||||
iwr.u.data.length = cmd_len;
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
*mode = *(__u8 *)(iwr.u.data.pointer);
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
int wext_add_custom_ie(const char *ifname, void *cus_ie, int ie_num)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
if(ie_num <= 0 || !cus_ie){
|
||||
printf("\n\rwext_add_custom_ie():wrong parameter");
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("SetCusIE");
|
||||
para = pvPortMalloc((4)* 2 + cmd_len);//size:addr len+cmd_len
|
||||
//Cmd
|
||||
snprintf(para, cmd_len, "SetCusIE");
|
||||
//addr length
|
||||
*(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr
|
||||
//ie_num
|
||||
*(__u32 *)(para + cmd_len + 4) = ie_num; //num of ie
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_add_custom_ie():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
vPortFree(para);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
if(ie_index <= 0 || !cus_ie){
|
||||
printf("\n\rwext_update_custom_ie():wrong parameter");
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("UpdateIE");
|
||||
para = pvPortMalloc((4)* 2 + cmd_len);//size:addr len+cmd_len
|
||||
//Cmd
|
||||
snprintf(para, cmd_len, "UpdateIE");
|
||||
//addr length
|
||||
*(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr
|
||||
//ie_index
|
||||
*(__u32 *)(para + cmd_len + 4) = ie_index; //num of ie
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = (4)* 2 + cmd_len;// 2 input
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_update_custom_ie():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
vPortFree(para);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int wext_del_custom_ie(const char *ifname)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("DelIE");
|
||||
para = pvPortMalloc(cmd_len);//size:addr len+cmd_len
|
||||
//Cmd
|
||||
snprintf(para, cmd_len, "DelIE");
|
||||
|
||||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = cmd_len;
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_del_custom_ie():ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
vPortFree(para);
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AP_MODE
|
||||
int wext_enable_forwarding(const char *ifname)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("forwarding_set");
|
||||
para = pvPortMalloc(cmd_len + 1);
|
||||
|
||||
// forwarding_set 1
|
||||
snprintf((char *) para, cmd_len, "forwarding_set");
|
||||
*(para + cmd_len) = '1';
|
||||
|
||||
iwr.u.essid.pointer = para;
|
||||
iwr.u.essid.length = cmd_len + 1;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_enable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_disable_forwarding(const char *ifname)
|
||||
{
|
||||
struct iwreq iwr;
|
||||
int ret = 0;
|
||||
__u8 *para = NULL;
|
||||
int cmd_len = 0;
|
||||
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
cmd_len = sizeof("forwarding_set");
|
||||
para = pvPortMalloc(cmd_len + 1);
|
||||
|
||||
// forwarding_set 0
|
||||
snprintf((char *) para, cmd_len, "forwarding_set");
|
||||
*(para + cmd_len) = '0';
|
||||
|
||||
iwr.u.essid.pointer = para;
|
||||
iwr.u.essid.length = cmd_len + 1;
|
||||
|
||||
if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) {
|
||||
printf("\n\rwext_disable_forwarding(): ioctl[SIOCDEVPRIVATE] error");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
vPortFree(para);
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif
|
64
component/common/api/wifi/wifi_util.h
Normal file
64
component/common/api/wifi/wifi_util.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
#include <wifi_constants.h>
|
||||
#include "wifi_structures.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid);
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value);
|
||||
int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len);
|
||||
int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase);
|
||||
int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len);
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase);
|
||||
int wext_disconnect(const char *ifname);
|
||||
int wext_set_mode(const char *ifname, int mode);
|
||||
int wext_get_mode(const char *ifname, int *mode);
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len);
|
||||
int wext_set_country(const char *ifname, char *country_code);
|
||||
int wext_get_rssi(const char *ifname, int *rssi);
|
||||
int wext_set_channel(const char *ifname, __u8 ch);
|
||||
int wext_get_channel(const char *ifname, __u8 *ch);
|
||||
int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac);
|
||||
int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac);
|
||||
int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
int wext_get_scan(const char *ifname, char *buf, __u16 buf_len);
|
||||
int wext_set_mac_address(const char *ifname, char * mac);
|
||||
int wext_get_mac_address(const char *ifname, char * mac);
|
||||
int wext_enable_powersave(const char *ifname);
|
||||
int wext_disable_powersave(const char *ifname);
|
||||
int wext_get_txpower(const char *ifname, int *poweridx);
|
||||
int wext_set_txpower(const char *ifname, int poweridx);
|
||||
int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, __u16 buffer_length);
|
||||
int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security);
|
||||
int wext_mp_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_private_command(const char *ifname, char *cmd, int show_msg);
|
||||
int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len);
|
||||
void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra);
|
||||
int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length);
|
||||
int wext_set_autoreconnect(const char *ifname, __u8 mode);
|
||||
int wext_get_autoreconnect(const char *ifname, __u8 *mode);
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
int wext_add_custom_ie(const char *ifname, void * cus_ie, int ie_num);
|
||||
int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index);
|
||||
int wext_del_custom_ie(const char *ifname);
|
||||
#endif
|
||||
|
||||
#define wext_handshake_done rltk_wlan_handshake_done
|
||||
|
||||
#ifdef CONFIG_P2P_NEW
|
||||
int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
#endif
|
||||
int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UTIL_H */
|
41
component/common/api/wifi_interactive_ext.h
Normal file
41
component/common/api/wifi_interactive_ext.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#define CONFIG_EXTERN_TEST 0
|
||||
#define CONFIG_EXTERN_HW 0
|
||||
#define CONFIG_EXTERN_CLOUD 0
|
||||
#define CONFIG_TTCP 0
|
||||
|
||||
/* External Function */
|
||||
#if CONFIG_EXTERN_TEST
|
||||
extern void cmd_tcpecho(int argc, char **argv);
|
||||
#endif
|
||||
#if CONFIG_EXTERN_HW
|
||||
extern void cmd_led(int argc, char **argv);
|
||||
extern void cmd_tmp75(int argc, char **argv);
|
||||
#endif
|
||||
#if CONFIG_EXTERN_CLOUD
|
||||
extern void cmd_cloud(int argc, char **argv);
|
||||
extern void cmd_reboot(int argc, char **argv);
|
||||
extern void cmd_config(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#if CONFIG_TTCP
|
||||
extern void cmd_ttcp(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
static const cmd_entry ext_cmd_table[] = {
|
||||
#if CONFIG_EXTERN_TEST
|
||||
{"tcpecho", cmd_tcpecho},
|
||||
#endif
|
||||
#if CONFIG_EXTERN_HW
|
||||
{"led", cmd_led},
|
||||
{"tmp75", cmd_tmp75},
|
||||
#endif
|
||||
#if CONFIG_EXTERN_CLOUD
|
||||
{"cloud", cmd_cloud},
|
||||
{"reboot", cmd_reboot},
|
||||
{"config", cmd_config},
|
||||
#endif
|
||||
#if CONFIG_TTCP
|
||||
{"ttcp", cmd_ttcp},
|
||||
#endif
|
||||
{"", NULL}
|
||||
};
|
1237
component/common/api/wifi_interactive_mode.c
Normal file
1237
component/common/api/wifi_interactive_mode.c
Normal file
File diff suppressed because it is too large
Load diff
23
component/common/application/google/google_nest.h
Normal file
23
component/common/application/google/google_nest.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef GOOGLENEST_H
|
||||
#define GOOGLENEST_H
|
||||
|
||||
#include <polarssl/ssl.h>
|
||||
|
||||
typedef struct {
|
||||
int socket;
|
||||
char *host;
|
||||
ssl_context ssl;
|
||||
} googlenest_context;
|
||||
|
||||
int gn_connect(googlenest_context *googlenest, char *host, int port);
|
||||
void gn_close(googlenest_context *googlenest);
|
||||
int gn_put(googlenest_context *googlenest, char *uri, char *content);
|
||||
int gn_patch(googlenest_context *googlenest, char *uri, char *content);
|
||||
int gn_post(googlenest_context *googlenest, char *uri, char *content, unsigned char *out_buffer, size_t out_len);
|
||||
int gn_get(googlenest_context *googlenest, char *uri, unsigned char *out_buffer, size_t out_len);
|
||||
int gn_delete(googlenest_context *googlenest, char *uri);
|
||||
int gn_stream(googlenest_context *googlenest, char *uri);
|
||||
void google_retrieve_data_hook_callback(void (*callback)(char *));
|
||||
|
||||
#endif
|
||||
|
1549
component/common/application/uart_adapter/uart_adapter.c
Normal file
1549
component/common/application/uart_adapter/uart_adapter.c
Normal file
File diff suppressed because it is too large
Load diff
166
component/common/application/uart_adapter/uart_adapter.h
Normal file
166
component/common/application/uart_adapter/uart_adapter.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
#include <platform/platform_stdlib.h>
|
||||
#include "gpio_api.h" // mbed
|
||||
#include "gpio_irq_api.h" // mbed
|
||||
/******************************************************
|
||||
* Macros
|
||||
******************************************************/
|
||||
#define UA_ERROR 0
|
||||
#define UA_WARNING 1
|
||||
#define UA_INFO 2
|
||||
#define UA_DEBUG 3
|
||||
#define UA_NONE 0xFF
|
||||
#define UA_DEBUG_LEVEL UA_INFO
|
||||
|
||||
#define UA_UART_THREAD_PRIORITY 5
|
||||
#define UA_UART_THREAD_STACKSIZE 512
|
||||
|
||||
#if (UA_DEBUG_LEVEL== UA_NONE)
|
||||
#define ua_printf(level, fmt, arg...)
|
||||
#else
|
||||
#define ua_printf(level, fmt, arg...) \
|
||||
do {\
|
||||
if (level <= UA_DEBUG_LEVEL) {\
|
||||
if (level <= UA_ERROR) {\
|
||||
printf("\r\nERROR: " fmt, ##arg);\
|
||||
} \
|
||||
else {\
|
||||
printf("\r\n"fmt, ##arg);\
|
||||
} \
|
||||
}\
|
||||
}while(0)
|
||||
#endif
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
typedef enum
|
||||
{
|
||||
UART_CTRL_MODE_SET_REQ = 0,
|
||||
UART_CTRL_MODE_SET_RSP = 1,
|
||||
UART_CTRL_MODE_GET_REQ = 2,
|
||||
UART_CTRL_MODE_GET_RSP = 3,
|
||||
}ua_ctrl_mode_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_CTRL_TYPE_BAUD_RATE = 0x01,
|
||||
UART_CTRL_TYPE_WORD_LEN = 0x02,
|
||||
UART_CTRL_TYPE_PARITY = 0x04,
|
||||
UART_CTRL_TYPE_STOP_BIT = 0x08,
|
||||
UART_CTRL_TYPE_FLOW_CTRL = 0x10,
|
||||
}ua_ctrl_type_t;
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
typedef long time_t;
|
||||
|
||||
typedef struct _uartadapter_timeval_st{
|
||||
long tv_sec; //秒
|
||||
long tv_hmsec; //百毫秒
|
||||
}UARTTHROUGH_TIMEVAL_st;
|
||||
|
||||
//获取网络DHCP参数时存储返回的IP,MAC,GW,MASK,DNS等
|
||||
typedef struct _ua_net_para {
|
||||
char dhcp;
|
||||
char ip[16]; // such as string "192.168.1.1"
|
||||
char gate[16];
|
||||
char mask[16];
|
||||
char dns[16];
|
||||
char mac[16]; // such as string "7E0000001111"
|
||||
char broadcastip[16];
|
||||
} ua_net_para_st;
|
||||
|
||||
//softAP模式时存储搜索到的 AP列表信息
|
||||
typedef struct _ua_ApList_str
|
||||
{
|
||||
char ssid[32];
|
||||
char ApPower; // min:0, max:100
|
||||
char channel;
|
||||
char encryption;
|
||||
}ua_ApList_str;
|
||||
|
||||
//softAP模式时存储搜索到的 AP列表信息
|
||||
typedef struct _ua_UwtPara_str
|
||||
{
|
||||
char ApNum; //AP number
|
||||
ua_ApList_str * ApList;
|
||||
} ua_UwtPara_str;
|
||||
|
||||
|
||||
//获取UART配置信息时,存储获得的串口配置信息
|
||||
typedef struct _ua_uart_get_str
|
||||
{
|
||||
int BaudRate; //The baud rate
|
||||
char number; //The number of data bits
|
||||
char parity; //The parity(0: none, 1:odd, 2:evn, default:0)
|
||||
char StopBits; //The number of stop bits
|
||||
char FlowControl; //support flow control is 1
|
||||
}ua_uart_get_str;
|
||||
//配置UART参数时,存储相关的配置信息
|
||||
typedef struct _ua_uart_set_str
|
||||
{
|
||||
char UartName[8]; // the name of uart
|
||||
int BaudRate; //The baud rate
|
||||
char number; //The number of data bits
|
||||
char parity; //The parity(default NONE)
|
||||
char StopBits; //The number of stop bits
|
||||
char FlowControl; //support flow control is 1
|
||||
}ua_uart_set_str;
|
||||
|
||||
|
||||
|
||||
//启动wifi连接时存储WIFI的配置信息
|
||||
typedef struct _ua_network_InitTypeDef_st
|
||||
{
|
||||
char wifi_mode; // SoftAp(0)station(1)
|
||||
char wifi_ssid[32];
|
||||
char wifi_key[32];
|
||||
char local_ip_addr[16];
|
||||
char net_mask[16];
|
||||
char gateway_ip_addr[16];
|
||||
char dnsServer_ip_addr[16];
|
||||
char dhcpMode; // disable(0), client mode(1), server mode(2)
|
||||
char address_pool_start[16];
|
||||
char address_pool_end[16];
|
||||
int wifi_retry_interval;//sta reconnect interval, ms
|
||||
char channel;
|
||||
char encryption;
|
||||
} ua_network_InitTypeDef_st;
|
||||
|
||||
#pragma pack(1)
|
||||
struct ua_ieee80211_frame
|
||||
{
|
||||
unsigned char i_fc[2];
|
||||
unsigned char i_dur[2];
|
||||
unsigned char i_addr1[6];
|
||||
unsigned char i_addr2[6];
|
||||
unsigned char i_addr3[6];
|
||||
unsigned char i_seq[2];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
//extern void uartadapter_netcallback(ua_net_para_st *pnet);
|
||||
//extern void uartadapter_wifistatushandler(int status);
|
||||
extern int uartadapter_init();
|
||||
//extern void uartadapter_deinit();
|
||||
//extern void uartadapter_wifipoweron(void);
|
||||
//extern void uartadapter_wifipoweroff(void);
|
||||
|
||||
//extern int uartadapter_startnetwork(ua_network_InitTypeDef_st* pNetworkInitPara);
|
||||
//extern void uartadapter_wifidisconnect (void);
|
||||
extern int uartadapter_getnetpara(ua_net_para_st * pnetpara);
|
||||
|
||||
//extern int uartadapter_sethostname(char* name);
|
||||
|
||||
extern int uartadapter_readuart(int fd, void *read_buf, size_t size);
|
||||
void uartadapter_tcp_data_fd_handler();
|
||||
extern void uartadapter_tcpsend(char *buffer, int size, u8 isctrl);
|
||||
//extern void uartadapter_test(void *param);
|
||||
//extern void uartadapter_tcp_control_server_handler(void *param);
|
||||
//extern void uartadapter_tcp_data_server_handler(void *param);
|
||||
//extern void uartadapter_gpio_irq (uint32_t id, gpio_irq_event event);
|
||||
void example_uart_adapter_init();
|
||||
extern void cmd_uart_adapter(int argc, char **argv);
|
||||
//#define cmd_uart_adapter cmd_ua
|
||||
|
347
component/common/drivers/wlan/realtek/include/autoconf.h
Normal file
347
component/common/drivers/wlan/realtek/include/autoconf.h
Normal file
|
@ -0,0 +1,347 @@
|
|||
#ifndef WLANCONFIG_H
|
||||
#define WLANCONFIG_H
|
||||
|
||||
/*
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform_opts.h"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_PLATFORM_AMEBA_X
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define PLATFORM_FREERTOS 1
|
||||
#define CONFIG_GSPI_HCI
|
||||
#else
|
||||
#define CONFIG_LX_HCI
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_INIC_EN
|
||||
#define CONFIG_INIC_EN 0 //For iNIC project
|
||||
#if CONFIG_INIC_EN
|
||||
#define CONFIG_LWIP_LAYER 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CONFIG_LITTLE_ENDIAN
|
||||
#define CONFIG_80211N_HT
|
||||
//#define CONFIG_RECV_REORDERING_CTRL
|
||||
#define RTW_NOTCH_FILTER 0
|
||||
#define CONFIG_EMBEDDED_FWIMG 1
|
||||
#define CONFIG_PHY_SETTING_WITH_ODM
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_ODM_REFRESH_RAMASK
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define HAL_BB_ENABLE 1
|
||||
#define HAL_RF_ENABLE 1
|
||||
#endif
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* Patch when dynamic mechanism is not ready */
|
||||
//#define CONFIG_DM_PATCH
|
||||
#endif
|
||||
|
||||
//#define CONFIG_DEBUG
|
||||
//#define CONFIG_DEBUG_RTL871X
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_MEM_MONITOR MEM_MONITOR_SIMPLE
|
||||
#define WLAN_INTF_DBG 0
|
||||
#define CONFIG_DEBUG_DYNAMIC
|
||||
//#define DBG_TX 1
|
||||
//#define DBG_XMIT_BUF 1
|
||||
//#define DBG_XMIT_BUF_EXT 1
|
||||
#define DBG_TX_DROP_FRAME
|
||||
/* For DM debug*/
|
||||
#define DBG_PWR_TRACKING 0
|
||||
#define DBG_PWR_INDEX 0
|
||||
#define DBG_DM_RA 0
|
||||
#define DBG_DM_DIG 0
|
||||
#else
|
||||
#define CONFIG_MEM_MONITOR MEM_MONITOR_LEAK
|
||||
//#define CONFIG_TRACE_SKB
|
||||
//#define WLAN_INTF_DBG
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
//#define CONFIG_DONT_CARE_TP
|
||||
//#define CONFIG_MEMORY_ACCESS_ALIGNED
|
||||
#define CONFIG_POWER_SAVING
|
||||
#ifdef CONFIG_POWER_SAVING
|
||||
#define CONFIG_LPS
|
||||
#define CONFIG_IPS
|
||||
//#define CONFIG_LPS_LCLK
|
||||
#define CONFIG_WAIT_PS_ACK
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_USE_TCM_HEAP 1 /* USE TCM HEAP */
|
||||
#endif
|
||||
#define CONFIG_RECV_TASKLET_THREAD
|
||||
#define CONFIG_XMIT_TASKLET_THREAD
|
||||
#else
|
||||
#define CONFIG_XMIT_THREAD_MODE
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
//#define CONFIG_RECV_THREAD_MODE /* Wlan IRQ Polling Mode*/
|
||||
//#define CONFIG_ISR_THREAD_MODE_POLLING /* Wlan IRQ Polling Mode*/
|
||||
|
||||
//1 Chris
|
||||
#ifndef CONFIG_SDIO_HCI
|
||||
#define CONFIG_ISR_THREAD_MODE_INTERRUPT /* Wlan IRQ Interrupt Mode*/
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ISR_THREAD_MODE_POLLING) && defined(CONFIG_ISR_THREAD_MODE_INTERRUPT)
|
||||
#error "CONFIG_ISR_THREAD_MODE_POLLING and CONFIG_ISR_THREAD_MODE_INTERRUPT are mutually exclusive. "
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* CRC DMEM optimized mode consume 1k less SRM memory consumption */
|
||||
#define CRC_IMPLEMENTATION_MODE CRC_IMPLEMENTATION_DMEM_OPTIMIZED
|
||||
#endif
|
||||
|
||||
/* AES DMEM optimized mode comsume 10k less memory compare to
|
||||
IMEM optimized mode AES_IMPLEMENTATION_IMEM_OPTIMIZED */
|
||||
#define AES_IMPLEMENTATION_MODE AES_IMPLEMENTATION_DMEM_OPTIMIZED
|
||||
|
||||
#define USE_SKB_AS_XMITBUF 1
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_XMIT_EXTBUFF 1
|
||||
#else
|
||||
#define USE_XMIT_EXTBUFF 0
|
||||
#endif
|
||||
#define USE_MUTEX_FOR_SPINLOCK 1
|
||||
#define SUPPORT_5G_CHANNEL 0
|
||||
#define SUPPORT_FAKE_EFUSE 0
|
||||
|
||||
#define CONFIG_AUTO_RECONNECT 1
|
||||
#define ENABLE_HWPDN_PIN
|
||||
#define SUPPORT_SCAN_BUF 1
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define BE_I_CUT 1
|
||||
#endif
|
||||
|
||||
/* For WPA2 */
|
||||
#define CONFIG_INCLUDE_WPA_PSK
|
||||
#ifdef CONFIG_INCLUDE_WPA_PSK
|
||||
#define CONFIG_MULTIPLE_WPA_STA
|
||||
//#define CONFIG_WPA2_PREAUTH
|
||||
#define PSK_SUPPORT_TKIP 1
|
||||
#endif
|
||||
|
||||
/* For promiscuous mode */
|
||||
#define CONFIG_PROMISC
|
||||
|
||||
#define PROMISC_DENY_PAIRWISE 0
|
||||
|
||||
/* For Simple Link */
|
||||
#ifndef CONFIG_INCLUDE_SIMPLE_CONFIG
|
||||
//#define CONFIG_INCLUDE_SIMPLE_CONFIG 1
|
||||
#endif
|
||||
|
||||
// for probe request with custom vendor specific IE
|
||||
#define CONFIG_CUSTOM_IE
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
/* For multicast */
|
||||
#define CONFIG_MULTICAST
|
||||
#endif
|
||||
|
||||
/* For STA+AP Concurrent MODE */
|
||||
#if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_CONCURRENT_MODE
|
||||
#endif
|
||||
#ifdef CONFIG_CONCURRENT_MODE
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#define CONFIG_RUNTIME_PORT_SWITCH
|
||||
#endif
|
||||
#define NET_IF_NUM 2
|
||||
#else
|
||||
#define NET_IF_NUM 1
|
||||
#endif
|
||||
|
||||
|
||||
/* For WPS and P2P */
|
||||
#ifndef CONFIG_WPS
|
||||
#define CONFIG_WPS
|
||||
#if defined(CONFIG_WPS)
|
||||
#define CONFIG_ENABLE_WPS 1
|
||||
#endif
|
||||
#if 0//def CONFIG_WPS
|
||||
#define CONFIG_WPS_AP
|
||||
#define CONFIG_P2P_NEW
|
||||
#if (!defined(SUPPORT_SCAN_BUF)||!defined(CONFIG_WPS_AP)) && defined(CONFIG_P2P_NEW)
|
||||
#error "If CONFIG_P2P_NEW, need to SUPPORT_SCAN_BUF"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_NEW_SIGNAL_STAT_PROCESS
|
||||
#endif
|
||||
|
||||
/* For AP_MODE */
|
||||
#define CONFIG_AP_MODE
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define AP_STA_NUM 3 //2014/10/27 modify to 3
|
||||
#define USE_DEDICATED_BCN_TX 0
|
||||
#if USE_DEDICATED_BCN_TX
|
||||
#error "WLAN driver for Ameba should not enable USE_DEDICATED_BCN_TX"
|
||||
#endif
|
||||
#else
|
||||
extern unsigned int g_ap_sta_num;
|
||||
#define AP_STA_NUM g_ap_sta_num
|
||||
#endif
|
||||
#ifdef CONFIG_AP_MODE
|
||||
#define CONFIG_NATIVEAP_MLME
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_INTERRUPT_BASED_TXBCN
|
||||
#endif
|
||||
#ifdef CONFIG_INTERRUPT_BASED_TXBCN
|
||||
//#define CONFIG_INTERRUPT_BASED_TXBCN_EARLY_INT
|
||||
#define CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR
|
||||
#endif
|
||||
// #define CONFIG_GK_REKEY
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_DEDICATED_BCN_TX 1
|
||||
#endif
|
||||
#else
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define USE_DEDICATED_BCN_TX 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_AP_MODE) && defined(CONFIG_GK_REKEY) && !defined(CONFIG_MULTIPLE_WPA_STA)
|
||||
#error "If CONFIG_GK_REKEY when CONFIG_AP_MODE, need to CONFIG_MULTIPLE_WPA_STA"
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if !defined(CONFIG_AP_MODE) && defined(CONFIG_CONCURRENT_MODE)
|
||||
#error "If CONFIG_CONCURRENT_MODEE, need to CONFIG_AP_MODE"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For efuse or flash config */
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_RW_PHYSICAL_EFUSE 1
|
||||
#define CONFIG_HIDE_PROTECT_EFUSE 1
|
||||
#define CONFIG_ADAPTOR_INFO_CACHING_FLASH 1
|
||||
#define CHECK_FLASH_VALID_MASK 1
|
||||
/* For K-free */
|
||||
#if !defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_RF_GAIN_OFFSET
|
||||
#endif
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
/* For MP_MODE */
|
||||
//#define CONFIG_MP_INCLUDED
|
||||
#ifdef CONFIG_MP_INCLUDED
|
||||
#define MP_DRIVER 1
|
||||
#define CONFIG_MP_IWPRIV_SUPPORT
|
||||
// #define HAL_EFUSE_MEMORY
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define MP_REG_TEST
|
||||
#define MP_DISABLE_SDR
|
||||
#endif
|
||||
#else
|
||||
#define MP_DRIVER 0
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
//Control wifi mcu function
|
||||
#define CONFIG_LITTLE_WIFI_MCU_FUNCTION_THREAD
|
||||
#define CONFIG_ODM_REFRESH_RAMASK
|
||||
#endif
|
||||
#endif // #ifdef CONFIG_MP_INCLUDED
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#if defined(CONFIG_PLATFORM_8195A)
|
||||
#define CONFIG_RTL8195A
|
||||
#endif
|
||||
#if defined(CONFIG_PLATFORM_8711B)
|
||||
#define CONFIG_RTL8711B
|
||||
#endif
|
||||
#else
|
||||
#define CONFIG_RTL8188E
|
||||
#endif
|
||||
#define RTL8192C_SUPPORT 0
|
||||
#define RTL8192CE_SUPPORT 0
|
||||
#define RTL8192CU_SUPPORT 0
|
||||
#define RTL8192D_SUPPORT 0
|
||||
#define RTL8192DE_SUPPORT 0
|
||||
#define RTL8192DU_SUPPORT 0
|
||||
#define RTL8723A_SUPPORT 0
|
||||
#define RTL8723AU_SUPPORT 0
|
||||
#define RTL8723AS_SUPPORT 0
|
||||
#define RTL8192E_SUPPORT 0
|
||||
#define RTL8812A_SUPPORT 0
|
||||
#define RTL8821A_SUPPORT 0
|
||||
#define RTL8723B_SUPPORT 0
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define RTL8195A_SUPPORT 1
|
||||
#define RTL8188E_SUPPORT 0
|
||||
#else
|
||||
#define RTL8188E_SUPPORT 1
|
||||
#define RTL8195A_SUPPORT 0
|
||||
#endif
|
||||
#define TEST_CHIP_SUPPORT 0
|
||||
|
||||
#define RTL8188E_FOR_TEST_CHIP 0
|
||||
#define RTL8188E_FPGA_TRUE_PHY_VERIFICATION 0
|
||||
#define DBG 0
|
||||
|
||||
/* For DM support */
|
||||
#define RATE_ADAPTIVE_SUPPORT 1
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define CONFIG_RTW_ADAPTIVITY_EN 0
|
||||
#define CONFIG_POWER_TRAINING_WIL 0 // in RA
|
||||
#else
|
||||
#define CONFIG_RTW_ADAPTIVITY_EN 1
|
||||
#define POWER_BY_RATE_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PLATFORM_AMEBA_X)
|
||||
#define RTL8195A_FOR_TEST_CHIP 0
|
||||
|
||||
//#define CONFIG_WIFI_TEST 1
|
||||
//#define CONFIG_MAC_LOOPBACK_DRIVER 1
|
||||
//#define CONFIG_WLAN_HAL_TEST 1
|
||||
//#define SKB_PRE_ALLOCATE_TX 1
|
||||
#define SKB_PRE_ALLOCATE_RX 1
|
||||
#define TX_CHECK_DSEC_ALWAYS 1
|
||||
#define EXCHANGE_LUBUX_RX_SKB 0
|
||||
#define CONFIG_DBG_DISABLE_RDU_INTERRUPT
|
||||
//#define CONFIG_WLAN_HAL_RX_TASK
|
||||
|
||||
//Enable mac loopback for test mode (Ameba)
|
||||
//#define ENABLE_MAC_LB_FOR_TEST_MODE // for test mode
|
||||
#ifdef ENABLE_MAC_LB_FOR_TEST_MODE
|
||||
#define CONFIG_SUDO_PHY_SETTING
|
||||
#define INT_HANDLE_IN_ISR 1
|
||||
#define CONFIG_LWIP_LAYER 0
|
||||
#define CONFIG_WLAN_HAL_TEST
|
||||
#define CONFIG_WLAN_HAL_RX_TASK
|
||||
#define CONFIG_MAC_LOOPBACK_DRIVER_RTL8195A 1
|
||||
//#define CONFIG_TWO_MAC_TEST_MODE
|
||||
#define DISABLE_BB_RF 1
|
||||
#else
|
||||
//#define CONFIG_TWO_MAC_DRIVER //for mornal driver; two mac
|
||||
#ifdef CONFIG_TWO_MAC_DRIVER
|
||||
#define CONFIG_SUDO_PHY_SETTING
|
||||
#define DISABLE_BB_RF 1
|
||||
#else
|
||||
#define HAL_MAC_ENABLE 1
|
||||
#define HAL_BB_ENABLE 1
|
||||
#define HAL_RF_ENABLE 1
|
||||
#define DISABLE_BB_RF 0
|
||||
#endif
|
||||
//#define INT_HANDLE_IN_ISR 1
|
||||
#endif
|
||||
#endif // CONFIG_PLATFORM_AMEBA_X
|
||||
|
||||
#ifndef CONFIG_LWIP_LAYER
|
||||
#define CONFIG_LWIP_LAYER 1
|
||||
#endif
|
||||
#define CONFIG_MAC_ADDRESS 0
|
||||
//fast reconnection
|
||||
//#define CONFIG_FAST_RECONNECTION 1
|
||||
#endif //WLANCONFIG_H
|
106
component/common/drivers/wlan/realtek/include/drv_conf.h
Normal file
106
component/common/drivers/wlan/realtek/include/drv_conf.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __DRV_CONF_H__
|
||||
#define __DRV_CONF_H__
|
||||
|
||||
#include "autoconf.h"
|
||||
#if (RTL8195A_SUPPORT==1)
|
||||
#include "platform_autoconf.h"
|
||||
#endif
|
||||
|
||||
#if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
|
||||
|
||||
#error "Shall be Linux or Windows, but not both!\n"
|
||||
|
||||
#endif
|
||||
|
||||
//Older Android kernel doesn't has CONFIG_ANDROID defined,
|
||||
//add this to force CONFIG_ANDROID defined
|
||||
#ifdef CONFIG_PLATFORM_ANDROID
|
||||
#define CONFIG_ANDROID
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ANDROID
|
||||
//Some Android build will restart the UI while non-printable ascii is passed
|
||||
//between java and c/c++ layer (JNI). We force CONFIG_VALIDATE_SSID
|
||||
//for Android here. If you are sure there is no risk on your system about this,
|
||||
//mask this macro define to support non-printable ascii ssid.
|
||||
//#define CONFIG_VALIDATE_SSID
|
||||
#ifdef CONFIG_PLATFORM_ARM_SUNxI
|
||||
#ifdef CONFIG_VALIDATE_SSID
|
||||
#undef CONFIG_VALIDATE_SSID
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Android expect dbm as the rx signal strength unit
|
||||
#define CONFIG_SIGNAL_DISPLAY_DBM
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_HAS_EARLYSUSPEND) && defined (CONFIG_RESUME_IN_WORKQUEUE)
|
||||
#warning "You have CONFIG_HAS_EARLYSUSPEND enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically"
|
||||
#undef CONFIG_RESUME_IN_WORKQUEUE
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ANDROID_POWER) && defined (CONFIG_RESUME_IN_WORKQUEUE)
|
||||
#warning "You have CONFIG_ANDROID_POWER enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically"
|
||||
#undef CONFIG_RESUME_IN_WORKQUEUE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RESUME_IN_WORKQUEUE //this can be removed, because there is no case for this...
|
||||
#if !defined( CONFIG_WAKELOCK) && !defined(CONFIG_ANDROID_POWER)
|
||||
#error "enable CONFIG_RESUME_IN_WORKQUEUE without CONFIG_WAKELOCK or CONFIG_ANDROID_POWER will suffer from the danger of wifi's unfunctionality..."
|
||||
#error "If you still want to enable CONFIG_RESUME_IN_WORKQUEUE in this case, mask this preprossor checking and GOOD LUCK..."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//About USB VENDOR REQ
|
||||
#if defined(CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX)
|
||||
#warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC automatically"
|
||||
#define CONFIG_USB_VENDOR_REQ_MUTEX
|
||||
#endif
|
||||
#if defined(CONFIG_VENDOR_REQ_RETRY) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX)
|
||||
#warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_VENDOR_REQ_RETRY automatically"
|
||||
#define CONFIG_USB_VENDOR_REQ_MUTEX
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_EN
|
||||
#define CONFIG_RTW_ADAPTIVITY_EN 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_MODE
|
||||
#define CONFIG_RTW_ADAPTIVITY_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_DML
|
||||
#define CONFIG_RTW_ADAPTIVITY_DML 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_ADAPTIVITY_DC_BACKOFF
|
||||
#define CONFIG_RTW_ADAPTIVITY_DC_BACKOFF 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_RTW_NHM_EN
|
||||
#define CONFIG_RTW_NHM_EN 0
|
||||
#endif
|
||||
|
||||
//#include <rtl871x_byteorder.h>
|
||||
|
||||
#endif // __DRV_CONF_H__
|
||||
|
221
component/common/drivers/wlan/realtek/include/wifi_constants.h
Normal file
221
component/common/drivers/wlan/realtek/include/wifi_constants.h
Normal file
|
@ -0,0 +1,221 @@
|
|||
#ifndef _WIFI_CONSTANTS_H
|
||||
#define _WIFI_CONSTANTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WEP_ENABLED 0x0001
|
||||
#define TKIP_ENABLED 0x0002
|
||||
#define AES_ENABLED 0x0004
|
||||
#define WSEC_SWFLAG 0x0008
|
||||
|
||||
#define SHARED_ENABLED 0x00008000
|
||||
#define WPA_SECURITY 0x00200000
|
||||
#define WPA2_SECURITY 0x00400000
|
||||
#define WPS_ENABLED 0x10000000
|
||||
|
||||
#define RTW_MAX_PSK_LEN (64)
|
||||
#define RTW_MIN_PSK_LEN (8)
|
||||
|
||||
#define MCSSET_LEN 16
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RTW_SUCCESS = 0, /**< Success */
|
||||
RTW_PENDING = 1, /**< Pending */
|
||||
RTW_TIMEOUT = 2, /**< Timeout */
|
||||
RTW_PARTIAL_RESULTS = 3, /**< Partial results */
|
||||
RTW_INVALID_KEY = 4, /**< Invalid key */
|
||||
RTW_DOES_NOT_EXIST = 5, /**< Does not exist */
|
||||
RTW_NOT_AUTHENTICATED = 6, /**< Not authenticated */
|
||||
RTW_NOT_KEYED = 7, /**< Not keyed */
|
||||
RTW_IOCTL_FAIL = 8, /**< IOCTL fail */
|
||||
RTW_BUFFER_UNAVAILABLE_TEMPORARY = 9, /**< Buffer unavailable temporarily */
|
||||
RTW_BUFFER_UNAVAILABLE_PERMANENT = 10, /**< Buffer unavailable permanently */
|
||||
RTW_WPS_PBC_OVERLAP = 11, /**< WPS PBC overlap */
|
||||
RTW_CONNECTION_LOST = 12, /**< Connection lost */
|
||||
|
||||
RTW_ERROR = -1, /**< Generic Error */
|
||||
RTW_BADARG = -2, /**< Bad Argument */
|
||||
RTW_BADOPTION = -3, /**< Bad option */
|
||||
RTW_NOTUP = -4, /**< Not up */
|
||||
RTW_NOTDOWN = -5, /**< Not down */
|
||||
RTW_NOTAP = -6, /**< Not AP */
|
||||
RTW_NOTSTA = -7, /**< Not STA */
|
||||
RTW_BADKEYIDX = -8, /**< BAD Key Index */
|
||||
RTW_RADIOOFF = -9, /**< Radio Off */
|
||||
RTW_NOTBANDLOCKED = -10, /**< Not band locked */
|
||||
RTW_NOCLK = -11, /**< No Clock */
|
||||
RTW_BADRATESET = -12, /**< BAD Rate valueset */
|
||||
RTW_BADBAND = -13, /**< BAD Band */
|
||||
RTW_BUFTOOSHORT = -14, /**< Buffer too short */
|
||||
RTW_BUFTOOLONG = -15, /**< Buffer too long */
|
||||
RTW_BUSY = -16, /**< Busy */
|
||||
RTW_NOTASSOCIATED = -17, /**< Not Associated */
|
||||
RTW_BADSSIDLEN = -18, /**< Bad SSID len */
|
||||
RTW_OUTOFRANGECHAN = -19, /**< Out of Range Channel */
|
||||
RTW_BADCHAN = -20, /**< Bad Channel */
|
||||
RTW_BADADDR = -21, /**< Bad Address */
|
||||
RTW_NORESOURCE = -22, /**< Not Enough Resources */
|
||||
RTW_UNSUPPORTED = -23, /**< Unsupported */
|
||||
RTW_BADLEN = -24, /**< Bad length */
|
||||
RTW_NOTREADY = -25, /**< Not Ready */
|
||||
RTW_EPERM = -26, /**< Not Permitted */
|
||||
RTW_NOMEM = -27, /**< No Memory */
|
||||
RTW_ASSOCIATED = -28, /**< Associated */
|
||||
RTW_RANGE = -29, /**< Not In Range */
|
||||
RTW_NOTFOUND = -30, /**< Not Found */
|
||||
RTW_WME_NOT_ENABLED = -31, /**< WME Not Enabled */
|
||||
RTW_TSPEC_NOTFOUND = -32, /**< TSPEC Not Found */
|
||||
RTW_ACM_NOTSUPPORTED = -33, /**< ACM Not Supported */
|
||||
RTW_NOT_WME_ASSOCIATION = -34, /**< Not WME Association */
|
||||
RTW_SDIO_ERROR = -35, /**< SDIO Bus Error */
|
||||
RTW_WLAN_DOWN = -36, /**< WLAN Not Accessible */
|
||||
RTW_BAD_VERSION = -37, /**< Incorrect version */
|
||||
RTW_TXFAIL = -38, /**< TX failure */
|
||||
RTW_RXFAIL = -39, /**< RX failure */
|
||||
RTW_NODEVICE = -40, /**< Device not present */
|
||||
RTW_UNFINISHED = -41, /**< To be finished */
|
||||
RTW_NONRESIDENT = -42, /**< access to nonresident overlay */
|
||||
RTW_DISABLED = -43 /**< Disabled in this build */
|
||||
} rtw_result_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SECURITY_OPEN = 0, /**< Open security */
|
||||
RTW_SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
|
||||
RTW_SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
|
||||
RTW_SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
|
||||
RTW_SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
|
||||
RTW_SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
|
||||
RTW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
|
||||
RTW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
|
||||
|
||||
RTW_SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
|
||||
RTW_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
|
||||
|
||||
RTW_SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
|
||||
|
||||
RTW_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force rtw_security_t type to 32 bits */
|
||||
} rtw_security_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_ENCRYPTION_UNKNOWN = 0,
|
||||
RTW_ENCRYPTION_OPEN = 1,
|
||||
RTW_ENCRYPTION_WEP40 = 2,
|
||||
RTW_ENCRYPTION_WPA_TKIP = 3,
|
||||
RTW_ENCRYPTION_WPA_AES = 4,
|
||||
RTW_ENCRYPTION_WPA2_TKIP = 5,
|
||||
RTW_ENCRYPTION_WPA2_AES = 6,
|
||||
RTW_ENCRYPTION_WPA2_MIXED = 7,
|
||||
RTW_ENCRYPTION_WEP104 = 9,
|
||||
RTW_ENCRYPTION_UNDEF = 0xFF,
|
||||
} rtw_encryption_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_FALSE = 0,
|
||||
RTW_TRUE = 1
|
||||
} rtw_bool_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_802_11_BAND_5GHZ = 0, /**< Denotes 5GHz radio band */
|
||||
RTW_802_11_BAND_2_4GHZ = 1 /**< Denotes 2.4GHz radio band */
|
||||
} rtw_802_11_band_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_COUNTRY_US = 0,
|
||||
RTW_COUNTRY_EU,
|
||||
RTW_COUNTRY_JP,
|
||||
RTW_COUNTRY_CN
|
||||
}rtw_country_code_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_MODE_NONE = 0,
|
||||
RTW_MODE_STA,
|
||||
RTW_MODE_AP,
|
||||
RTW_MODE_STA_AP,
|
||||
RTW_MODE_PROMISC,
|
||||
RTW_MODE_P2P
|
||||
}rtw_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_FULL = 0,
|
||||
RTW_SCAN_SOCIAL,
|
||||
RTW_SCAN_ONE
|
||||
}rtw_scan_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_LINK_DISCONNECTED = 0,
|
||||
RTW_LINK_CONNECTED
|
||||
} rtw_link_status_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_TYPE_ACTIVE = 0x00, /**< Actively scan a network by sending 802.11 probe(s) */
|
||||
RTW_SCAN_TYPE_PASSIVE = 0x01, /**< Passively scan a network by listening for beacons from APs */
|
||||
RTW_SCAN_TYPE_PROHIBITED_CHANNELS = 0x04 /**< Passively scan on channels not enabled by the country code */
|
||||
} rtw_scan_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_BSS_TYPE_INFRASTRUCTURE = 0, /**< Denotes infrastructure network */
|
||||
RTW_BSS_TYPE_ADHOC = 1, /**< Denotes an 802.11 ad-hoc IBSS network */
|
||||
RTW_BSS_TYPE_ANY = 2, /**< Denotes either infrastructure or ad-hoc network */
|
||||
|
||||
RTW_BSS_TYPE_UNKNOWN = -1 /**< May be returned by scan function if BSS type is unknown. Do not pass this to the Join function */
|
||||
} rtw_bss_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_SCAN_COMMAMD = 0x01
|
||||
} rtw_scan_command_t;
|
||||
|
||||
typedef enum{
|
||||
COMMAND1 = 0x01
|
||||
}rtw_command_type;
|
||||
|
||||
typedef enum {
|
||||
RTW_WPS_TYPE_DEFAULT = 0x0000,
|
||||
RTW_WPS_TYPE_USER_SPECIFIED = 0x0001,
|
||||
RTW_WPS_TYPE_MACHINE_SPECIFIED = 0x0002,
|
||||
RTW_WPS_TYPE_REKEY = 0x0003,
|
||||
RTW_WPS_TYPE_PUSHBUTTON = 0x0004,
|
||||
RTW_WPS_TYPE_REGISTRAR_SPECIFIED = 0x0005,
|
||||
RTW_WPS_TYPE_NONE = 0x0006
|
||||
} rtw_wps_type_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_NETWORK_B = 1,
|
||||
RTW_NETWORK_BG = 3,
|
||||
RTW_NETWORK_BGN = 11
|
||||
} rtw_network_mode_t;
|
||||
|
||||
typedef enum {
|
||||
RTW_STA_INTERFACE = 0, /**< STA or Client Interface */
|
||||
RTW_AP_INTERFACE = 1, /**< softAP Interface */
|
||||
} rtw_interface_t;
|
||||
|
||||
/**
|
||||
* Enumeration of packet filter rules
|
||||
*/
|
||||
typedef enum {
|
||||
RTW_POSITIVE_MATCHING = 0, /**< Specifies that a filter should match a given pattern */
|
||||
RTW_NEGATIVE_MATCHING = 1 /**< Specifies that a filter should NOT match a given pattern */
|
||||
} rtw_packet_filter_rule_e;
|
||||
|
||||
typedef enum {
|
||||
RTW_PROMISC_DISABLE = 0, /**< disable the promisc */
|
||||
RTW_PROMISC_ENABLE = 1, /**< enable the promisc */
|
||||
RTW_PROMISC_ENABLE_1 = 2, /**< enable the promisc special for length is used */
|
||||
RTW_PROMISC_ENABLE_2 = 3, /**< fetch all packets*/
|
||||
} rtw_rcr_level_t;
|
||||
|
||||
typedef enum{
|
||||
RTW_NO_ERROR = 0,
|
||||
RTW_NONE_NETWORK = 1,
|
||||
RTW_CONNECT_FAIL = 2,
|
||||
RTW_WRONG_PASSWORD = 3 ,
|
||||
RTW_DHCP_FAIL = 4,
|
||||
}rtw_connect_error_flag_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _WIFI_CONSTANTS_H */
|
134
component/common/drivers/wlan/realtek/include/wifi_structures.h
Normal file
134
component/common/drivers/wlan/realtek/include/wifi_structures.h
Normal file
|
@ -0,0 +1,134 @@
|
|||
#ifndef _WIFI_STRUCTURES_H
|
||||
#define _WIFI_STRUCTURES_H
|
||||
|
||||
//#include <freertos/freertos_service.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct rtw_ssid {
|
||||
unsigned char len; /**< SSID length */
|
||||
unsigned char val[33]; /**< SSID name (AP name) */
|
||||
} rtw_ssid_t;
|
||||
|
||||
typedef struct rtw_mac {
|
||||
unsigned char octet[6]; /**< Unique 6-byte MAC address */
|
||||
} rtw_mac_t;
|
||||
|
||||
typedef struct rtw_ap_info {
|
||||
rtw_ssid_t ssid;
|
||||
rtw_security_t security_type;
|
||||
unsigned char *password;
|
||||
int password_len;
|
||||
int channel;
|
||||
}rtw_ap_info_t;
|
||||
|
||||
typedef struct rtw_network_info {
|
||||
rtw_ssid_t ssid;
|
||||
rtw_mac_t bssid;
|
||||
rtw_security_t security_type;
|
||||
unsigned char *password;
|
||||
int password_len;
|
||||
int key_id;
|
||||
}rtw_network_info_t;
|
||||
|
||||
typedef struct rtw_scan_result {
|
||||
rtw_ssid_t SSID; /**< Service Set Identification (i.e. Name of Access Point) */
|
||||
rtw_mac_t BSSID; /**< Basic Service Set Identification (i.e. MAC address of Access Point) */
|
||||
signed short signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
|
||||
rtw_bss_type_t bss_type; /**< Network type */
|
||||
rtw_security_t security; /**< Security type */
|
||||
rtw_wps_type_t wps_type; /**< WPS type */
|
||||
unsigned char channel; /**< Radio channel that the AP beacon was received on */
|
||||
rtw_802_11_band_t band; /**< Radio band */
|
||||
} rtw_scan_result_t;
|
||||
|
||||
typedef struct rtw_scan_handler_result {
|
||||
rtw_scan_result_t ap_details;
|
||||
rtw_bool_t scan_complete;
|
||||
void* user_data;
|
||||
|
||||
} rtw_scan_handler_result_t;
|
||||
|
||||
typedef struct rtw_wifi_setting {
|
||||
rtw_mode_t mode;
|
||||
unsigned char ssid[33];
|
||||
unsigned char channel;
|
||||
rtw_security_t security_type;
|
||||
unsigned char password[65];
|
||||
unsigned char key_idx;
|
||||
}rtw_wifi_setting_t;
|
||||
|
||||
typedef struct rtw_wifi_config {
|
||||
unsigned int boot_mode;
|
||||
unsigned char ssid[32];
|
||||
unsigned char ssid_len;
|
||||
unsigned char security_type;
|
||||
unsigned char password[65];
|
||||
unsigned char password_len;
|
||||
unsigned char channel;
|
||||
} rtw_wifi_config_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int count; /**< Number of MAC addresses in the list */
|
||||
rtw_mac_t mac_list[1]; /**< Variable length array of MAC addresses */
|
||||
} rtw_maclist_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int version; /* version field */
|
||||
unsigned int length; /* byte length of data in this record, */
|
||||
/* starting at version and including IEs */
|
||||
rtw_mac_t BSSID;
|
||||
unsigned short beacon_period; /* units are Kusec */
|
||||
unsigned short capability; /* Capability information */
|
||||
unsigned char SSID_len;
|
||||
unsigned char SSID[32];
|
||||
unsigned char channel;
|
||||
// struct {
|
||||
// uint32_t count; /* # rates in this set */
|
||||
// uint8_t rates[16]; /* rates in 500kbps units w/hi bit set if basic */
|
||||
// } rateset; /* supported rates */
|
||||
// rtw_chanspec_t chanspec; /* chanspec for bss */
|
||||
unsigned short atim_window; /* units are Kusec */
|
||||
unsigned char dtim_period; /* DTIM period */
|
||||
signed short RSSI; /* receive signal strength (in dBm) */
|
||||
|
||||
unsigned char n_cap; /* BSS is 802.11N Capable */
|
||||
unsigned int nbss_cap; /* 802.11N BSS Capabilities (based on HT_CAP_*) */
|
||||
unsigned char basic_mcs[MCSSET_LEN]; /* 802.11N BSS required MCS set */
|
||||
|
||||
unsigned short ie_offset; /* offset at which IEs start, from beginning */
|
||||
unsigned int ie_length; /* byte length of Information Elements */
|
||||
} rtw_bss_info_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short offset; /**< Offset in bytes to start filtering (referenced to the start of the ethernet packet) */
|
||||
unsigned short mask_size; /**< Size of the mask in bytes */
|
||||
unsigned char* mask; /**< Pattern mask bytes to be ANDed with the pattern eg. "\xff00" (must be in network byte order) */
|
||||
unsigned char* pattern; /**< Pattern bytes used to filter eg. "\x0800" (must be in network byte order) */
|
||||
} rtw_packet_filter_pattern_t;
|
||||
|
||||
typedef struct ieee80211_frame_info{
|
||||
unsigned short i_fc;
|
||||
unsigned short i_dur;
|
||||
unsigned char i_addr1[6];
|
||||
unsigned char i_addr2[6];
|
||||
unsigned char i_addr3[6];
|
||||
unsigned short i_seq;
|
||||
unsigned char bssid[6];
|
||||
unsigned char encrypt;
|
||||
}ieee80211_frame_info_t;
|
||||
|
||||
typedef struct {
|
||||
char filter_id;
|
||||
rtw_packet_filter_pattern_t patt;
|
||||
rtw_packet_filter_rule_e rule;
|
||||
unsigned char enable;
|
||||
}rtw_packet_filter_info_t;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _WIFI_STRUCTURES_H */
|
|
@ -0,0 +1,285 @@
|
|||
#ifndef _FREERTOS_SERVICE_H_
|
||||
#define _FREERTOS_SERVICE_H_
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Include Files
|
||||
//----- ------------------------------------------------------------------
|
||||
#include "wireless.h"
|
||||
|
||||
// --------------------------------------------
|
||||
// Platform dependent include file
|
||||
// --------------------------------------------
|
||||
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
|
||||
#include "platform/platform_stdlib.h"
|
||||
extern VOID RtlUdelayOS(u32 us);
|
||||
#else
|
||||
// other MCU may use standard library
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI) || defined(CONFIG_LX_HCI)
|
||||
/* For SPI interface transfer and us delay implementation */
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
#include <rtwlan_bsp.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// Platform dependent type define
|
||||
// --------------------------------------------
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef signed char s8;
|
||||
typedef signed short s16;
|
||||
typedef signed int s32;
|
||||
typedef signed long long s64;
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned int uint;
|
||||
typedef signed int sint;
|
||||
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#define IN
|
||||
#define OUT
|
||||
#define VOID void
|
||||
#define NDIS_OID uint
|
||||
#define NDIS_STATUS uint
|
||||
#ifndef PVOID
|
||||
typedef void * PVOID;
|
||||
#endif
|
||||
|
||||
typedef unsigned int __kernel_size_t;
|
||||
typedef int __kernel_ssize_t;
|
||||
typedef __kernel_size_t SIZE_T;
|
||||
typedef __kernel_ssize_t SSIZE_T;
|
||||
|
||||
#endif //CONFIG_PLATFORM_8195A
|
||||
|
||||
#define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
|
||||
|
||||
// os types
|
||||
typedef char osdepCHAR;
|
||||
typedef float osdepFLOAT;
|
||||
typedef double osdepDOUBLE;
|
||||
typedef long osdepLONG;
|
||||
typedef short osdepSHORT;
|
||||
typedef unsigned long osdepSTACK_TYPE;
|
||||
typedef long osdepBASE_TYPE;
|
||||
typedef unsigned long osdepTickType;
|
||||
|
||||
typedef void* _timerHandle;
|
||||
typedef void* _sema;
|
||||
typedef void* _mutex;
|
||||
typedef void* _lock;
|
||||
typedef void* _queueHandle;
|
||||
typedef void* _xqueue;
|
||||
typedef struct timer_list _timer;
|
||||
|
||||
typedef struct sk_buff _pkt;
|
||||
typedef unsigned char _buffer;
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
struct __queue {
|
||||
struct list_head queue;
|
||||
_lock lock;
|
||||
};
|
||||
|
||||
typedef struct __queue _queue;
|
||||
typedef struct list_head _list;
|
||||
typedef unsigned long _irqL;
|
||||
|
||||
typedef void* _thread_hdl_;
|
||||
typedef void thread_return;
|
||||
typedef void* thread_context;
|
||||
|
||||
#define ATOMIC_T atomic_t
|
||||
#define HZ configTICK_RATE_HZ
|
||||
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
/* emulate a modern version */
|
||||
#define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 17)
|
||||
|
||||
static __inline _list *get_next(_list *list)
|
||||
{
|
||||
return list->next;
|
||||
}
|
||||
|
||||
static __inline _list *get_list_head(_queue *queue)
|
||||
{
|
||||
return (&(queue->queue));
|
||||
}
|
||||
|
||||
#define LIST_CONTAINOR(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr)))
|
||||
#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
|
||||
|
||||
#define TASK_PRORITY_LOW 1
|
||||
#define TASK_PRORITY_MIDDLE 2
|
||||
#define TASK_PRORITY_HIGH 3
|
||||
#define TASK_PRORITY_SUPER 4
|
||||
|
||||
#define TIMER_MAX_DELAY 0xFFFFFFFF
|
||||
|
||||
// rtl8195a uses receive_tasklet for wps
|
||||
// 8189em uses interrupt_thread for wps
|
||||
#if defined(CONFIG_WPS)
|
||||
#define RECV_STACK_FOR_WPS 448//512//384 //Change to 512 for WPS (IAR STM32) stack overflow
|
||||
#else
|
||||
#define RECV_STACK_FOR_WPS 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define XMIT_STACKSIZE 192 //256
|
||||
#define CMD_STACKSIZE 384 //512
|
||||
#else
|
||||
#define XMIT_STACKSIZE 256
|
||||
#define CMD_STACKSIZE 512 //1024
|
||||
#endif //CONFIG_DONT_CARE_TP
|
||||
|
||||
#ifdef CONFIG_PLATFORM_8195A
|
||||
#define RECV_STACKSIZE 256
|
||||
#else //CONFIG_PLATFORM_8195A
|
||||
#ifdef CONFIG_INCLUDE_WPA_PSK
|
||||
#if PSK_SUPPORT_TKIP
|
||||
#define RECV_STACKSIZE (512 + 256 + 128 + RECV_STACK_FOR_WPS)
|
||||
#else
|
||||
#define RECV_STACKSIZE (512 + 256 + RECV_STACK_FOR_WPS )
|
||||
#endif
|
||||
#else
|
||||
#define RECV_STACKSIZE (512 + 256 + RECV_STACK_FOR_WPS) //Can be reduced
|
||||
#endif
|
||||
#endif //CONFIG_PLATFORM_8195A
|
||||
|
||||
#define XMIT_TASKLET_STACKSIZE 256
|
||||
#define RECV_TASKLET_STACKSIZE (1024 + RECV_STACK_FOR_WPS)
|
||||
#define SDIOXMIT_STACKSIZE 256
|
||||
|
||||
|
||||
struct rtw_netdev_priv_indicator {
|
||||
void *priv;
|
||||
u32 sizeof_priv;
|
||||
};
|
||||
|
||||
#define rtw_netdev_priv(netdev) ( ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv )
|
||||
|
||||
#define ADPT_FMT "%s"
|
||||
#define ADPT_ARG(adapter) adapter->pnetdev->name
|
||||
#define FUNC_NDEV_FMT "%s"
|
||||
#define FUNC_NDEV_ARG(ndev) __func__
|
||||
#define FUNC_ADPT_FMT "%s(%s)"
|
||||
#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
|
||||
|
||||
void save_and_cli(void);
|
||||
void restore_flags(void);
|
||||
void cli(void);
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Common Definition
|
||||
//----- ------------------------------------------------------------------
|
||||
|
||||
#define __init
|
||||
#define __exit
|
||||
#define __devinit
|
||||
#define __devexit
|
||||
|
||||
#define KERN_ERR
|
||||
#define KERN_INFO
|
||||
#define KERN_NOTICE
|
||||
|
||||
#define GFP_KERNEL 1
|
||||
#define GFP_ATOMIC 1
|
||||
|
||||
#define SET_MODULE_OWNER(some_struct) do { } while (0)
|
||||
#define SET_NETDEV_DEV(dev, obj) do { } while (0)
|
||||
#define register_netdev(dev) (0)
|
||||
#define unregister_netdev(dev) do { } while (0)
|
||||
#define netif_queue_stopped(dev) (0)
|
||||
#define netif_wake_queue(dev) do { } while (0)
|
||||
#define printk printf
|
||||
|
||||
#define DBG_ERR(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
|
||||
#if WLAN_INTF_DBG
|
||||
#define DBG_TRACE(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
|
||||
#define DBG_INFO(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args)
|
||||
#else
|
||||
#define DBG_TRACE(fmt, args...)
|
||||
#define DBG_INFO(fmt, args...)
|
||||
#endif
|
||||
#define HALT() do { cli(); for(;;);} while(0)
|
||||
#define ASSERT(x) do { \
|
||||
if((x) == 0) \
|
||||
printf("\n\rAssert(" #x ") failed on line %d in file %s", __LINE__, __FILE__); \
|
||||
HALT(); \
|
||||
} while(0)
|
||||
|
||||
#undef DBG_ASSERT
|
||||
#define DBG_ASSERT(x, msg) do { \
|
||||
if((x) == 0) \
|
||||
printf("\n\r%s, Assert(" #x ") failed on line %d in file %s", msg, __LINE__, __FILE__); \
|
||||
} while(0)
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Atomic Operation
|
||||
//----- ------------------------------------------------------------------
|
||||
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) // for 8195A, it is defined in ..system../basic_types.h
|
||||
typedef struct { volatile int counter; } atomic_t;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* atomic_read - read atomic variable
|
||||
* @v: pointer of type atomic_t
|
||||
*
|
||||
* Atomically reads the value of @v. Note that the guaranteed
|
||||
* useful range of an atomic_t is only 24 bits.
|
||||
*/
|
||||
#define atomic_read(v) ((v)->counter)
|
||||
|
||||
/*
|
||||
* atomic_set - set atomic variable
|
||||
* @v: pointer of type atomic_t
|
||||
* @i: required value
|
||||
*
|
||||
* Atomically sets the value of @v to @i. Note that the guaranteed
|
||||
* useful range of an atomic_t is only 24 bits.
|
||||
*/
|
||||
#define atomic_set(v,i) ((v)->counter = (i))
|
||||
|
||||
/*
|
||||
* These inlines deal with timer wrapping correctly. You are
|
||||
* strongly encouraged to use them
|
||||
* 1. Because people otherwise forget
|
||||
* 2. Because if the timer wrap changes in future you wont have to
|
||||
* alter your driver code.
|
||||
*
|
||||
* time_after(a,b) returns true if the time a is after time b.
|
||||
*
|
||||
* Do this with "<0" and ">=0" to only test the sign of the result. A
|
||||
* good compiler would generate better code (and a really good compiler
|
||||
* wouldn't care). Gcc is currently neither.
|
||||
*/
|
||||
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
|
||||
#define time_before(a,b) time_after(b,a)
|
||||
|
||||
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
||||
#define time_before_eq(a,b) time_after_eq(b,a)
|
||||
|
||||
|
||||
extern void rtw_init_listhead(_list *list);
|
||||
extern u32 rtw_is_list_empty(_list *phead);
|
||||
extern void rtw_list_insert_head(_list *plist, _list *phead);
|
||||
extern void rtw_list_insert_tail(_list *plist, _list *phead);
|
||||
extern void rtw_list_delete(_list *plist);
|
||||
|
||||
#endif /* _FREERTOS_SERVICE_H_ */
|
|
@ -0,0 +1,432 @@
|
|||
#ifndef __WRAPPER_H__
|
||||
#define __WRAPPER_H__
|
||||
/**************************************************************************
|
||||
* Wrapper provide a linux-like interface
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
************************************************************************/
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Include Files
|
||||
//----- ------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "wireless.h"
|
||||
#include <skbuff.h>
|
||||
#include "freertos_service.h"
|
||||
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Linled List
|
||||
//----- ------------------------------------------------------------------
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
// struct list_head {
|
||||
// struct list_head *next, *prev;
|
||||
// };
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline void __list_add(struct list_head * new,
|
||||
struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline void __list_del(struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
||||
*/
|
||||
static __inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static __inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static __inline int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static __inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
|
||||
if (first != list) {
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
}
|
||||
|
||||
void list_add(struct list_head *new, struct list_head *head);
|
||||
void list_add_tail(struct list_head *new, struct list_head *head);
|
||||
|
||||
extern void save_and_cli(void);
|
||||
extern void restore_flags(void);
|
||||
//----- ------------------------------------------------------------------
|
||||
// SKB Operation
|
||||
//----- ------------------------------------------------------------------
|
||||
|
||||
#define SMP_CACHE_BYTES 4
|
||||
#define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & ~(SMP_CACHE_BYTES - 1))
|
||||
|
||||
// Consideration for SKB size
|
||||
// Tx: [INTF_CMD][TX_DESC][WLAN_HDR][QoS][IV][SNAP][Data][MIC][ICV][INTF_STATUS]
|
||||
// Since SKB is used to accept ethernet packet from upper layer, SKB length of WLAN_MAX_ETHFRM_LEN
|
||||
// (= 1514) is enough. But since SKB is also used to get spi receive packet, overall buffer space
|
||||
// should be taken into consideration.
|
||||
// RX: [INTF_CMD][RX_DESC][Drv_Info][WLAN_HDR][QoS][IV][SNAP][Data][MIC][ICV][CRC][INTF_STATUS]
|
||||
//
|
||||
// 32: Driver_Info that carry phy related information for each packets. Required only for receive case.
|
||||
// WLAN_MAX_ETHFRM_LEN : May not be required because WLAN_HEADER +SNAP can totally
|
||||
// cover ethernet header. Keep in only for safety.
|
||||
//
|
||||
// **Notes** SDIO requires 512 blocks r/w, so 512*4 = 2048 is required.
|
||||
// 2003/12/26. The value is reduced from 2048 to 1658 for GSPI
|
||||
// 2014/02/05. The value is 1650 for 8195A LX_BUS
|
||||
#define SKB_RESERVED_FOR_SAFETY 0
|
||||
#define SKB_WLAN_TX_EXTRA_LEN (TXDESC_SIZE + WLAN_HDR_A4_QOS_LEN + WLAN_MAX_IV_LEN + WLAN_SNAP_HEADER - WLAN_ETHHDR_LEN)
|
||||
#define RX_DRIVER_INFO 32
|
||||
|
||||
#if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI)
|
||||
#define HAL_INTERFACE_OVERHEAD_SKB_DATA 12 //HAL_INTERFACE_CMD (4) + HAL_INTERFACE_STATUS (8)
|
||||
#elif defined(CONFIG_LX_HCI)
|
||||
#define HAL_INTERFACE_OVERHEAD_SKB_DATA 0
|
||||
#endif
|
||||
|
||||
#if defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI || defined(CONFIG_LX_HCI)
|
||||
#if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B)
|
||||
#if defined(CONFIG_MP_INCLUDED)
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_LIMIT ((WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN + 511) / 512) // 4, for lxbus
|
||||
#else
|
||||
#define MAX_RX_PKT_LIMIT ((WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN + 511) / 512) // 4, for lxbus
|
||||
#endif
|
||||
#define MAX_RX_PKT_SIZE MAX_RX_PKT_LIMIT*512 // MAX_SKB_BUF_SIZE = 0+32+40+512*4+0 = 2120
|
||||
#else
|
||||
#define MAX_RX_PKT_LIMIT 4 // MAX_SKB_BUF_SIZE = 0+32+40+64+1514+0 = 1650
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN
|
||||
#else
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_RX_ETHFRM_LEN
|
||||
#else
|
||||
#define MAX_RX_PKT_SIZE WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_ETHFRM_LEN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
#define MAX_TX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
WLAN_MAX_PROTOCOL_OVERHEAD + WLAN_MAX_TX_ETHFRM_LEN +\
|
||||
SKB_RESERVED_FOR_SAFETY)
|
||||
#define MAX_RX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
MAX_RX_PKT_SIZE +\
|
||||
SKB_RESERVED_FOR_SAFETY)
|
||||
#else
|
||||
#define MAX_SKB_BUF_SIZE (HAL_INTERFACE_OVERHEAD_SKB_DATA+RX_DRIVER_INFO+\
|
||||
((TXDESC_SIZE>RXDESC_SIZE)? TXDESC_SIZE:RXDESC_SIZE) +\
|
||||
MAX_RX_PKT_SIZE +\
|
||||
SKB_RESERVED_FOR_SAFETY)
|
||||
#endif
|
||||
#else
|
||||
#define MAX_SKB_BUF_SIZE 2048
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
struct sk_buff_head {
|
||||
struct list_head *next, *prev;
|
||||
u32 qlen;
|
||||
};
|
||||
|
||||
struct sk_buff {
|
||||
/* These two members must be first. */
|
||||
struct sk_buff *next; /* Next buffer in list */
|
||||
struct sk_buff *prev; /* Previous buffer in list */
|
||||
|
||||
struct sk_buff_head *list; /* List we are on */
|
||||
unsigned char *head; /* Head of buffer */
|
||||
unsigned char *data; /* Data head pointer */
|
||||
unsigned char *tail; /* Tail pointer */
|
||||
unsigned char *end; /* End pointer */
|
||||
struct net_device *dev; /* Device we arrived on/are leaving by */
|
||||
unsigned int len; /* Length of actual data */
|
||||
};
|
||||
|
||||
/**
|
||||
* skb_put - add data to a buffer
|
||||
* @skb: buffer to use
|
||||
* @len: amount of data to add
|
||||
*
|
||||
* This function extends the used data area of the buffer. If this would
|
||||
* exceed the total buffer size the kernel will panic. A pointer to the
|
||||
* first byte of the extra data is returned.
|
||||
*/
|
||||
|
||||
static __inline__ unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
unsigned char *tmp=skb->tail;
|
||||
skb->tail+=len;
|
||||
skb->len+=len;
|
||||
if(skb->tail>skb->end) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
skb->len-=len;
|
||||
skb->data = (unsigned char *)(((unsigned int)skb->data) + len);
|
||||
|
||||
return skb->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_reserve - adjust headroom
|
||||
* @skb: buffer to alter
|
||||
* @len: bytes to move
|
||||
*
|
||||
* Increase the headroom of an empty &sk_buff by reducing the tail
|
||||
* room. This is only allowed for an empty buffer.
|
||||
*/
|
||||
|
||||
static __inline__ void skb_reserve(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
skb->data+=len;
|
||||
skb->tail+=len;
|
||||
}
|
||||
|
||||
static __inline__ void skb_queue_head_init(struct sk_buff_head *list)
|
||||
{
|
||||
list->prev = (struct list_head *)list;
|
||||
list->next = (struct list_head *)list;
|
||||
list->qlen = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* __skb_queue_tail - queue a buffer at the list tail
|
||||
* @list: list to use
|
||||
* @newsk: buffer to queue
|
||||
*
|
||||
* Queue a buffer at the end of a list. This function takes no locks
|
||||
* and you must therefore hold required locks before calling it.
|
||||
*
|
||||
* A buffer cannot be placed on two lists at the same time.
|
||||
*/
|
||||
|
||||
static __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
|
||||
{
|
||||
struct sk_buff *prev, *next;
|
||||
|
||||
newsk->list = list;
|
||||
list->qlen++;
|
||||
next = (struct sk_buff *)list;
|
||||
prev = next->prev;
|
||||
newsk->next = next;
|
||||
newsk->prev = prev;
|
||||
next->prev = newsk;
|
||||
prev->next = newsk;
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_queue_tail - queue a buffer at the list tail
|
||||
* @list: list to use
|
||||
* @newsk: buffer to queue
|
||||
*
|
||||
* Queue a buffer at the tail of the list. This function takes the
|
||||
* list lock and can be used safely with other locking &sk_buff functions
|
||||
* safely.
|
||||
*
|
||||
* A buffer cannot be placed on two lists at the same time.
|
||||
*/
|
||||
|
||||
static __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
|
||||
{
|
||||
save_and_cli();
|
||||
__skb_queue_tail(list, newsk);
|
||||
restore_flags();
|
||||
}
|
||||
|
||||
static __inline__ void skb_assign_buf(struct sk_buff *skb, unsigned char *buf, unsigned int len)
|
||||
{
|
||||
skb->head = buf;
|
||||
skb->data = buf;
|
||||
skb->tail = buf;
|
||||
skb->end = buf + len;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *skb_tail_pointer(const struct sk_buff *skb)
|
||||
{
|
||||
return skb->tail;
|
||||
}
|
||||
|
||||
static __inline__ void skb_reset_tail_pointer(struct sk_buff *skb)
|
||||
{
|
||||
skb->tail = skb->data;
|
||||
}
|
||||
|
||||
static __inline__ void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
|
||||
{
|
||||
skb->tail = skb->data + offset;
|
||||
}
|
||||
|
||||
static __inline__ unsigned char *skb_end_pointer(const struct sk_buff *skb)
|
||||
{
|
||||
return skb->end;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* External functions
|
||||
*/
|
||||
struct net_device;
|
||||
extern void kfree_skb_chk_key(struct sk_buff *skb, struct net_device *root_dev);
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
extern void show_skb(void);
|
||||
extern int _set_skb_list_flag(struct sk_buff *skb, unsigned int queueflag);
|
||||
extern void dump_skb_list(void);
|
||||
#define set_skb_list_flag(skb, queueflag) \
|
||||
(\
|
||||
_set_skb_list_flag((skb), queueflag), \
|
||||
(skb) ? (skb)->funcname[(skb)->list_idx] = __FUNCTION__:NULL \
|
||||
)
|
||||
extern int _clear_skb_list_flag(struct sk_buff *skb, unsigned int queueflag);
|
||||
#define clear_skb_list_flag(skb, queueflag) \
|
||||
(\
|
||||
_clear_skb_list_flag((skb), queueflag), \
|
||||
(skb) ? (skb)->funcname[(skb)->list_idx] = __FUNCTION__ : NULL \
|
||||
)
|
||||
#define dev_kfree_skb_any(trx, holder, skb) \
|
||||
do{\
|
||||
clear_skb_list_flag(skb, SKBLIST_##trx##holder##_MASK);\
|
||||
set_skb_list_flag(skb, SKBLIST_POOL);\
|
||||
kfree_skb_chk_key(skb, skb->dev);\
|
||||
}while (0)
|
||||
#else
|
||||
#define dev_kfree_skb_any(skb) kfree_skb_chk_key(skb, skb->dev)
|
||||
#endif
|
||||
extern struct sk_buff *dev_alloc_skb(unsigned int length, unsigned int reserve_len);
|
||||
extern struct sk_buff *skb_clone(struct sk_buff *skb, int gfp_mask);
|
||||
extern struct sk_buff *skb_copy(const struct sk_buff *skb, int gfp_mask, unsigned int reserve_len);
|
||||
extern unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Device structure
|
||||
//----- ------------------------------------------------------------------
|
||||
struct net_device_stats {
|
||||
unsigned long rx_packets; /* total packets received */
|
||||
unsigned long tx_packets; /* total packets transmitted */
|
||||
unsigned long rx_dropped; /* no space in linux buffers */
|
||||
unsigned long tx_dropped; /* no space available in linux */
|
||||
unsigned long rx_bytes; /* total bytes received */
|
||||
unsigned long tx_bytes; /* total bytes transmitted */
|
||||
};
|
||||
|
||||
struct net_device {
|
||||
char name[16];
|
||||
void *priv; /* pointer to private data */
|
||||
unsigned char dev_addr[6]; /* set during bootup */
|
||||
int (*init)(void);
|
||||
int (*open)(struct net_device *dev);
|
||||
int (*stop)(struct net_device *dev);
|
||||
int (*hard_start_xmit)(struct sk_buff *skb, struct net_device *dev);
|
||||
int (*do_ioctl)(struct net_device *dev, struct iwreq *ifr, int cmd);
|
||||
struct net_device_stats* (*get_stats)(struct net_device *dev);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct net_device *dev; /* Binding wlan driver netdev */
|
||||
void *skb; /* pending Rx packet */
|
||||
unsigned int tx_busy;
|
||||
unsigned int rx_busy;
|
||||
unsigned char enable;
|
||||
unsigned char mac[6];
|
||||
} Rltk_wlan_t;
|
||||
|
||||
#define netdev_priv(dev) dev->priv
|
||||
|
||||
extern struct net_device *alloc_etherdev(int sizeof_priv);
|
||||
void free_netdev(struct net_device *dev);
|
||||
int dev_alloc_name(struct net_device *net_dev, const char *ifname);
|
||||
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Timer Operation
|
||||
//----- ------------------------------------------------------------------
|
||||
void init_timer(struct timer_list *timer);
|
||||
void mod_timer(struct timer_list *timer, u32 delay_time_ms);
|
||||
void cancel_timer_ex(struct timer_list * timer);
|
||||
void del_timer_sync(struct timer_list * timer);
|
||||
void init_timer_wrapper(void);
|
||||
void deinit_timer_wrapper(void);
|
||||
|
||||
#endif //__WRAPPER_H__
|
||||
|
||||
|
||||
|
222
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.c
Normal file
222
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.c
Normal file
|
@ -0,0 +1,222 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
//#define _LWIP_INTF_C_
|
||||
|
||||
#include <autoconf.h>
|
||||
#include <lwip_intf.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <ethernetif.h>
|
||||
#include <osdep_service.h>
|
||||
#include <wifi/wifi_util.h>
|
||||
//----- ------------------------------------------------------------------
|
||||
// External Reference
|
||||
//----- ------------------------------------------------------------------
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
extern struct netif xnetif[]; //LWIP netif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* rltk_wlan_set_netif_info - set netif hw address and register dev pointer to netif device
|
||||
* @idx_wlan: netif index
|
||||
* 0 for STA only or SoftAP only or STA in STA+SoftAP concurrent mode,
|
||||
* 1 for SoftAP in STA+SoftAP concurrent mode
|
||||
* @dev: register netdev pointer to LWIP. Reserved.
|
||||
* @dev_addr: set netif hw address
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6);
|
||||
xnetif[idx_wlan].state = dev;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* rltk_wlan_send - send IP packets to WLAN. Called by low_level_output().
|
||||
* @idx: netif index
|
||||
* @sg_list: data buffer list
|
||||
* @sg_len: size of each data buffer
|
||||
* @total_len: total data len
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len)
|
||||
{
|
||||
struct eth_drv_sg *last_sg;
|
||||
struct sk_buff *skb = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if(idx == -1){
|
||||
DBG_ERR("netif is DOWN");
|
||||
return -1;
|
||||
}
|
||||
DBG_TRACE("%s is called", __FUNCTION__);
|
||||
|
||||
save_and_cli();
|
||||
if(rltk_wlan_check_isup(idx))
|
||||
rltk_wlan_tx_inc(idx);
|
||||
else {
|
||||
DBG_ERR("netif is DOWN");
|
||||
restore_flags();
|
||||
return -1;
|
||||
}
|
||||
restore_flags();
|
||||
|
||||
skb = rltk_wlan_alloc_skb(total_len);
|
||||
if (skb == NULL) {
|
||||
DBG_ERR("rltk_wlan_alloc_skb() for data len=%d failed!", total_len);
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
rtw_memcpy(skb->tail, (void *)(sg_list->buf), sg_list->len);
|
||||
skb_put(skb, sg_list->len);
|
||||
}
|
||||
|
||||
rltk_wlan_send_skb(idx, skb);
|
||||
|
||||
exit:
|
||||
save_and_cli();
|
||||
rltk_wlan_tx_dec(idx);
|
||||
restore_flags();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* rltk_wlan_recv - indicate packets to LWIP. Called by ethernetif_recv().
|
||||
* @idx: netif index
|
||||
* @sg_list: data buffer list
|
||||
* @sg_len: size of each data buffer
|
||||
*
|
||||
* Return Value: None
|
||||
*/
|
||||
void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len)
|
||||
{
|
||||
struct eth_drv_sg *last_sg;
|
||||
struct sk_buff *skb;
|
||||
|
||||
DBG_TRACE("%s is called", __FUNCTION__);
|
||||
if(idx == -1){
|
||||
DBG_ERR("skb is NULL");
|
||||
return;
|
||||
}
|
||||
skb = rltk_wlan_get_recv_skb(idx);
|
||||
DBG_ASSERT(skb, "No pending rx skb");
|
||||
|
||||
for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) {
|
||||
if (sg_list->buf != 0) {
|
||||
rtw_memcpy((void *)(sg_list->buf), skb->data, sg_list->len);
|
||||
skb_pull(skb, sg_list->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int netif_is_valid_IP(int idx, unsigned char *ip_dest)
|
||||
{
|
||||
#if CONFIG_LWIP_LAYER == 1
|
||||
struct netif * pnetif = &xnetif[idx];
|
||||
struct ip_addr addr = { 0 };
|
||||
#ifdef CONFIG_MEMORY_ACCESS_ALIGNED
|
||||
unsigned int temp;
|
||||
memcpy(&temp, ip_dest, sizeof(unsigned int));
|
||||
u32_t *ip_dest_addr = &temp;
|
||||
#else
|
||||
u32_t *ip_dest_addr = (u32_t*)ip_dest;
|
||||
#endif
|
||||
addr.addr = *ip_dest_addr;
|
||||
|
||||
if(pnetif->ip_addr.addr == 0)
|
||||
return 1;
|
||||
|
||||
if(ip_addr_ismulticast(&addr) || ip_addr_isbroadcast(&addr,pnetif)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
//if(ip_addr_netcmp(&(pnetif->ip_addr), &addr, &(pnetif->netmask))) //addr&netmask
|
||||
// return 1;
|
||||
|
||||
if(ip_addr_cmp(&(pnetif->ip_addr),&addr))
|
||||
return 1;
|
||||
|
||||
DBG_TRACE("invalid IP: %d.%d.%d.%d ",ip_dest[0],ip_dest[1],ip_dest[2],ip_dest[3]);
|
||||
#endif
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
if(pnetif->flags & NETIF_FLAG_IPSWITCH)
|
||||
return 1;
|
||||
else
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int netif_get_idx(struct netif* pnetif)
|
||||
{
|
||||
#if CONFIG_LWIP_LAYER == 1
|
||||
int idx = pnetif - xnetif;
|
||||
|
||||
switch(idx) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned char *netif_get_hwaddr(int idx_wlan)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
return xnetif[idx_wlan].hwaddr;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_rx(int idx, unsigned int len)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
ethernetif_recv(&xnetif[idx], len);
|
||||
#endif
|
||||
#if (CONFIG_INIC_EN == 1)
|
||||
inic_netif_rx(idx, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_post_sleep_processing(void)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
lwip_POST_SLEEP_PROCESSING(); //For FreeRTOS tickless to enable Lwip ARP timer when leaving IPS - Alex Fang
|
||||
#endif
|
||||
}
|
||||
|
||||
void netif_pre_sleep_processing(void)
|
||||
{
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
lwip_PRE_SLEEP_PROCESSING();
|
||||
#endif
|
||||
}
|
||||
|
56
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.h
Normal file
56
component/common/drivers/wlan/realtek/src/osdep/lwip_intf.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef __LWIP_INTF_H__
|
||||
#define __LWIP_INTF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <wireless.h>
|
||||
#include <skbuff.h>
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Ethernet Buffer
|
||||
//----- ------------------------------------------------------------------
|
||||
struct eth_drv_sg {
|
||||
unsigned int buf;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
#define MAX_ETH_DRV_SG 32
|
||||
#define MAX_ETH_MSG 1540
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Wlan Interface Provided
|
||||
//----- ------------------------------------------------------------------
|
||||
unsigned char rltk_wlan_check_isup(int idx);
|
||||
void rltk_wlan_tx_inc(int idx);
|
||||
void rltk_wlan_tx_dec(int idx);
|
||||
struct sk_buff * rltk_wlan_get_recv_skb(int idx);
|
||||
struct sk_buff * rltk_wlan_alloc_skb(unsigned int total_len);
|
||||
void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr);
|
||||
void rltk_wlan_send_skb(int idx, struct sk_buff *skb); //struct sk_buff as defined above comment line
|
||||
int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len);
|
||||
void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len);
|
||||
unsigned char rltk_wlan_running(unsigned char idx); // interface is up. 0: interface is down
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Network Interface provided
|
||||
//----- ------------------------------------------------------------------
|
||||
struct netif;
|
||||
int netif_is_valid_IP(int idx,unsigned char * ip_dest);
|
||||
int netif_get_idx(struct netif *pnetif);
|
||||
unsigned char *netif_get_hwaddr(int idx_wlan);
|
||||
void netif_rx(int idx, unsigned int len);
|
||||
void netif_post_sleep_processing(void);
|
||||
void netif_pre_sleep_processing(void);
|
||||
#if (CONFIG_LWIP_LAYER == 1)
|
||||
extern void ethernetif_recv(struct netif *netif, int total_len);
|
||||
extern void lwip_PRE_SLEEP_PROCESSING(void);
|
||||
extern void lwip_POST_SLEEP_PROCESSING(void);
|
||||
#endif //CONFIG_LWIP_LAYER == 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //#ifndef __LWIP_INTF_H__
|
523
component/common/drivers/wlan/realtek/src/osdep/osdep_service.h
Normal file
523
component/common/drivers/wlan/realtek/src/osdep/osdep_service.h
Normal file
|
@ -0,0 +1,523 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __OSDEP_SERVICE_H_
|
||||
#define __OSDEP_SERVICE_H_
|
||||
|
||||
/* Define compilor specific symbol */
|
||||
//
|
||||
// inline function
|
||||
//
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#define __inline__ inline
|
||||
#define __inline inline
|
||||
#define __inline_definition //In dialect C99, inline means that a function's definition is provided
|
||||
//only for inlining, and that there is another definition
|
||||
//(without inline) somewhere else in the program.
|
||||
//That means that this program is incomplete, because if
|
||||
//add isn't inlined (for example, when compiling without optimization),
|
||||
//then main will have an unresolved reference to that other definition.
|
||||
|
||||
// Do not inline function is the function body is defined .c file and this
|
||||
// function will be called somewhere else, otherwise there is compile error
|
||||
#elif defined ( __CC_ARM )
|
||||
#define __inline__ __inline //__linine__ is not supported in keil compilor, use __inline instead
|
||||
#define inline __inline
|
||||
#define __inline_definition // for dialect C99
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __inline__ inline
|
||||
#define __inline inline
|
||||
#define __inline_definition inline
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <drv_conf.h>
|
||||
#if defined( PLATFORM_FREERTOS)
|
||||
#include "freertos/freertos_service.h"
|
||||
#elif defined( PLATFORM_ECOS)
|
||||
#include "ecos/ecos_service.h"
|
||||
#endif
|
||||
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
|
||||
#define RTW_MAX_DELAY 0xFFFFFFFF
|
||||
#define RTW_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
struct timer_list {
|
||||
_timerHandle timer_hdl;
|
||||
unsigned long data;
|
||||
void (*function)(void *);
|
||||
};
|
||||
|
||||
typedef thread_return (*thread_func_t)(thread_context context);
|
||||
typedef void (*TIMER_FUN)(void *context);
|
||||
typedef int (*event_handler_t)(char *buf, int buf_len, int flags, void *user_data);
|
||||
|
||||
#define CONFIG_THREAD_COMM_SEMA
|
||||
struct task_struct {
|
||||
const char *task_name;
|
||||
_thread_hdl_ task; /* I: workqueue thread */
|
||||
|
||||
#ifdef CONFIG_THREAD_COMM_SIGNAL
|
||||
const char *name; /* I: workqueue thread name */
|
||||
u32 queue_num; /* total signal num */
|
||||
u32 cur_queue_num; /* cur signal num should < queue_num */
|
||||
#elif defined(CONFIG_THREAD_COMM_SEMA)
|
||||
_sema wakeup_sema;
|
||||
_sema terminate_sema;
|
||||
// _queue work_queue; //TODO
|
||||
#endif
|
||||
u32 blocked;
|
||||
u32 callback_running;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
_xqueue event_queue;
|
||||
struct task_struct thread;
|
||||
}rtw_worker_thread_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
event_handler_t function;
|
||||
char *buf;
|
||||
int buf_len;
|
||||
int flags;
|
||||
void *user_data;
|
||||
} rtw_event_message_t;
|
||||
|
||||
struct worker_timer_entry {
|
||||
struct list_head list;
|
||||
_timerHandle timer_hdl;
|
||||
rtw_event_message_t message;
|
||||
rtw_worker_thread_t *worker_thread;
|
||||
u32 timeout;
|
||||
};
|
||||
#ifdef CONFIG_THREAD_COMM_SIGNAL
|
||||
struct work_struct;
|
||||
typedef void (*work_func_t)(void *context);
|
||||
struct work_struct {
|
||||
_list list;
|
||||
u32 data;
|
||||
work_func_t func;
|
||||
void *context;
|
||||
struct task_struct *used_wq;
|
||||
};
|
||||
|
||||
struct delayed_work {
|
||||
struct work_struct work;
|
||||
struct timer_list timer;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
//----- ------------------------------------------------------------------
|
||||
// Memory Monitor
|
||||
//----- ------------------------------------------------------------------
|
||||
#define MEM_MONITOR_SIMPLE 0x1
|
||||
#define MEM_MONITOR_LEAK 0x2
|
||||
|
||||
#define MEM_MONITOR_FLAG_WIFI_DRV 0x1
|
||||
#define MEM_MONITOR_FLAG_WPAS 0x2
|
||||
#if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK
|
||||
struct mem_entry {
|
||||
struct list_head list;
|
||||
int size;
|
||||
void *ptr;
|
||||
};
|
||||
#endif
|
||||
|
||||
void init_mem_monitor(_list *pmem_table, int *used_num);
|
||||
void deinit_mem_monitor(_list *pmem_table, int *used_num);
|
||||
void add_mem_usage(_list *pmem_table, void *ptr, int size, int *used_num, int flag);
|
||||
void del_mem_usage(_list *pmem_table, void *ptr, int *used_num, int flag);
|
||||
int get_mem_usage(_list *pmem_table);
|
||||
#endif
|
||||
|
||||
/*********************************** OSDEP API *****************************************/
|
||||
u8* _rtw_vmalloc(u32 sz);
|
||||
u8* _rtw_zvmalloc(u32 sz);
|
||||
void _rtw_vmfree(u8 *pbuf, u32 sz);
|
||||
u8* _rtw_zmalloc(u32 sz);
|
||||
u8* _rtw_malloc(u32 sz);
|
||||
void _rtw_mfree(u8 *pbuf, u32 sz);
|
||||
#ifdef CONFIG_MEM_MONITOR
|
||||
u8* rtw_vmalloc(u32 sz);
|
||||
u8* rtw_zvmalloc(u32 sz);
|
||||
void rtw_vmfree(u8 *pbuf, u32 sz);
|
||||
u8* rtw_zmalloc(u32 sz);
|
||||
u8* rtw_malloc(u32 sz);
|
||||
void rtw_mfree(u8 *pbuf, u32 sz);
|
||||
#else
|
||||
#define rtw_vmalloc _rtw_vmalloc
|
||||
#define rtw_zvmalloc _rtw_zvmalloc
|
||||
#define rtw_vmfree _rtw_vmfree
|
||||
#define rtw_zmalloc _rtw_zmalloc
|
||||
#define rtw_malloc _rtw_malloc
|
||||
#define rtw_mfree _rtw_mfree
|
||||
#endif
|
||||
#define rtw_free(buf) rtw_mfree((u8 *)buf, 0)
|
||||
void* rtw_malloc2d(int h, int w, int size);
|
||||
void rtw_mfree2d(void *pbuf, int h, int w, int size);
|
||||
void rtw_memcpy(void* dst, void* src, u32 sz);
|
||||
int rtw_memcmp(void *dst, void *src, u32 sz);
|
||||
void rtw_memset(void *pbuf, int c, u32 sz);
|
||||
|
||||
void rtw_init_listhead(_list *list);
|
||||
u32 rtw_is_list_empty(_list *phead);
|
||||
void rtw_list_insert_head(_list *plist, _list *phead);
|
||||
void rtw_list_insert_tail(_list *plist, _list *phead);
|
||||
void rtw_list_delete(_list *plist);
|
||||
|
||||
void rtw_init_sema(_sema *sema, int init_val);
|
||||
void rtw_free_sema(_sema *sema);
|
||||
void rtw_up_sema(_sema *sema);
|
||||
u32 rtw_down_sema(_sema *sema);
|
||||
u32 rtw_down_timeout_sema(_sema *sema, u32 timeout);
|
||||
void rtw_mutex_init(_mutex *pmutex);
|
||||
void rtw_mutex_free(_mutex *pmutex);
|
||||
void rtw_mutex_put(_mutex *pmutex);
|
||||
void rtw_mutex_get(_mutex *pmutex);
|
||||
void rtw_enter_critical(_lock *plock, _irqL *pirqL);
|
||||
void rtw_exit_critical(_lock *plock, _irqL *pirqL);
|
||||
void rtw_enter_critical_bh(_lock *plock, _irqL *pirqL);
|
||||
void rtw_exit_critical_bh(_lock *plock, _irqL *pirqL);
|
||||
int rtw_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL);
|
||||
void rtw_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL);
|
||||
void rtw_spinlock_init(_lock *plock);
|
||||
void rtw_spinlock_free(_lock *plock);
|
||||
void rtw_spinlock_init(_lock *plock);
|
||||
void rtw_spinlock_free(_lock *plock);
|
||||
void rtw_spin_lock(_lock *plock);
|
||||
void rtw_spin_unlock(_lock *plock);
|
||||
void rtw_spinlock_irqsave(_lock *plock, _irqL *irqL);
|
||||
void rtw_spinunlock_irqsave(_lock *plock, _irqL *irqL);
|
||||
|
||||
rtw_result_t rtw_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages );
|
||||
rtw_result_t rtw_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms );
|
||||
rtw_result_t rtw_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms );
|
||||
rtw_result_t rtw_deinit_xqueue( _xqueue* queue );
|
||||
|
||||
void rtw_init_queue(_queue *pqueue);
|
||||
void rtw_deinit_queue(_queue *pqueue);
|
||||
u32 rtw_is_queue_empty(_queue *pqueue);
|
||||
u32 rtw_queue_empty(_queue *pqueue);
|
||||
u32 rtw_end_of_queue_search(_list *queue, _list *pelement);
|
||||
_list* rtw_get_queue_head(_queue *queue);
|
||||
|
||||
u32 rtw_get_current_time(void);
|
||||
u32 rtw_systime_to_ms(u32 systime);
|
||||
u32 rtw_systime_to_sec(u32 systime);
|
||||
u32 rtw_ms_to_systime(u32 ms);
|
||||
u32 rtw_sec_to_systime(u32 sec);
|
||||
s32 rtw_get_passing_time_ms(u32 start);
|
||||
s32 rtw_get_time_interval_ms(u32 start, u32 end);
|
||||
|
||||
void rtw_msleep_os(int ms);
|
||||
void rtw_usleep_os(int us);
|
||||
u32 rtw_atoi(u8* s);
|
||||
void rtw_mdelay_os(int ms);
|
||||
void rtw_udelay_os(int us);
|
||||
void rtw_yield_os(void);
|
||||
|
||||
void rtw_init_timer(_timer *ptimer, void *adapter, TIMER_FUN pfunc,void* cntx, const char *name);
|
||||
void rtw_set_timer(_timer *ptimer,u32 delay_time);
|
||||
u8 rtw_cancel_timer(_timer *ptimer);
|
||||
void rtw_del_timer(_timer *ptimer);
|
||||
|
||||
//Atomic integer operations
|
||||
void ATOMIC_SET(ATOMIC_T *v, int i);
|
||||
int ATOMIC_READ(ATOMIC_T *v);
|
||||
void ATOMIC_ADD(ATOMIC_T *v, int i);
|
||||
void ATOMIC_SUB(ATOMIC_T *v, int i);
|
||||
void ATOMIC_INC(ATOMIC_T *v);
|
||||
void ATOMIC_DEC(ATOMIC_T *v);
|
||||
int ATOMIC_ADD_RETURN(ATOMIC_T *v, int i);
|
||||
int ATOMIC_SUB_RETURN(ATOMIC_T *v, int i);
|
||||
int ATOMIC_INC_RETURN(ATOMIC_T *v);
|
||||
int ATOMIC_DEC_RETURN(ATOMIC_T *v);
|
||||
int ATOMIC_DEC_AND_TEST(ATOMIC_T *v);
|
||||
|
||||
u64 rtw_modular64(u64 x, u64 y);
|
||||
int rtw_get_random_bytes(void* dst, u32 size);
|
||||
u32 rtw_getFreeHeapSize(void);
|
||||
void flush_signals_thread(void);
|
||||
|
||||
/*********************************** Thread related *****************************************/
|
||||
int rtw_create_task(struct task_struct *task, const char *name, u32 stack_size, u32 priority, thread_func_t func, void *thctx);
|
||||
void rtw_delete_task(struct task_struct * task);
|
||||
void rtw_wakeup_task(struct task_struct *task);
|
||||
rtw_result_t rtw_create_worker_thread( rtw_worker_thread_t* worker_thread, u8 priority, u32 stack_size, u32 event_queue_size );
|
||||
rtw_result_t rtw_delete_worker_thread( rtw_worker_thread_t* worker_thread );
|
||||
|
||||
#if 0 //TODO
|
||||
void rtw_init_delayed_work(struct delayed_work *dwork, work_func_t func, const char *name);
|
||||
void rtw_deinit_delayed_work(struct delayed_work *dwork);
|
||||
int rtw_queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, u32 delay, void* context);
|
||||
BOOLEAN rtw_cancel_delayed_work(struct delayed_work *dwork);
|
||||
#endif
|
||||
|
||||
void rtw_thread_enter(char *name);
|
||||
void rtw_thread_exit(void);
|
||||
#ifdef PLATFORM_LINUX
|
||||
#define rtw_warn_on(condition) WARN_ON(condition)
|
||||
#else
|
||||
#define rtw_warn_on(condition) do {} while (0)
|
||||
#endif
|
||||
|
||||
/*********************************** Timer related *****************************************/
|
||||
_timerHandle rtw_timerCreate( const signed char *pcTimerName,
|
||||
osdepTickType xTimerPeriodInTicks,
|
||||
u32 uxAutoReload,
|
||||
void * pvTimerID,
|
||||
TIMER_FUN pxCallbackFunction );
|
||||
u32 rtw_timerDelete( _timerHandle xTimer,
|
||||
osdepTickType xBlockTime );
|
||||
u32 rtw_timerIsTimerActive( _timerHandle xTimer );
|
||||
u32 rtw_timerStop( _timerHandle xTimer,
|
||||
osdepTickType xBlockTime );
|
||||
u32 rtw_timerChangePeriod( _timerHandle xTimer,
|
||||
osdepTickType xNewPeriod,
|
||||
osdepTickType xBlockTime );
|
||||
|
||||
/*********************************** OSDEP API end *****************************************/
|
||||
#define LIST_CONTAINOR(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr)))
|
||||
|
||||
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
|
||||
#define time_before(a,b) time_after(b,a)
|
||||
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
||||
#define time_before_eq(a,b) time_after_eq(b,a)
|
||||
|
||||
#define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
|
||||
#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
|
||||
|
||||
__inline static u32 _RND4(u32 sz)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__inline static u32 _RND8(u32 sz)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__inline static u32 _RND128(u32 sz)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__inline static u32 _RND256(u32 sz)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__inline static u32 _RND512(u32 sz)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__inline static u32 bitshift(u32 bitmask)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i <= 31; i++)
|
||||
if (((bitmask>>i) & 0x1) == 1) break;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Macros for handling unaligned memory accesses */
|
||||
|
||||
#define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
|
||||
#define RTW_PUT_BE16(a, val) \
|
||||
do { \
|
||||
(a)[0] = ((u16) (val)) >> 8; \
|
||||
(a)[1] = ((u16) (val)) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
|
||||
#define RTW_PUT_LE16(a, val) \
|
||||
do { \
|
||||
(a)[1] = ((u16) (val)) >> 8; \
|
||||
(a)[0] = ((u16) (val)) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
|
||||
((u32) (a)[2]))
|
||||
#define RTW_PUT_BE24(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[2] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
|
||||
(((u32) (a)[2]) << 8) | ((u32) (a)[3]))
|
||||
#define RTW_PUT_BE32(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[3] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_LE32(a) ((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \
|
||||
(((u32) (a)[1]) << 8) | ((u32) (a)[0]))
|
||||
#define RTW_PUT_LE32(a, val) \
|
||||
do { \
|
||||
(a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \
|
||||
(a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
||||
(a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
||||
(a)[0] = (u8) (((u32) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \
|
||||
(((u64) (a)[2]) << 40) | (((u64) (a)[3]) << 32) | \
|
||||
(((u64) (a)[4]) << 24) | (((u64) (a)[5]) << 16) | \
|
||||
(((u64) (a)[6]) << 8) | ((u64) (a)[7]))
|
||||
#define RTW_PUT_BE64(a, val) \
|
||||
do { \
|
||||
(a)[0] = (u8) (((u64) (val)) >> 56); \
|
||||
(a)[1] = (u8) (((u64) (val)) >> 48); \
|
||||
(a)[2] = (u8) (((u64) (val)) >> 40); \
|
||||
(a)[3] = (u8) (((u64) (val)) >> 32); \
|
||||
(a)[4] = (u8) (((u64) (val)) >> 24); \
|
||||
(a)[5] = (u8) (((u64) (val)) >> 16); \
|
||||
(a)[6] = (u8) (((u64) (val)) >> 8); \
|
||||
(a)[7] = (u8) (((u64) (val)) & 0xff); \
|
||||
} while (0)
|
||||
|
||||
#define RTW_GET_LE64(a) ((((u64) (a)[7]) << 56) | (((u64) (a)[6]) << 48) | \
|
||||
(((u64) (a)[5]) << 40) | (((u64) (a)[4]) << 32) | \
|
||||
(((u64) (a)[3]) << 24) | (((u64) (a)[2]) << 16) | \
|
||||
(((u64) (a)[1]) << 8) | ((u64) (a)[0]))
|
||||
|
||||
struct osdep_service_ops {
|
||||
u8* (*rtw_vmalloc)(u32 sz);
|
||||
u8* (*rtw_zvmalloc)(u32 sz);
|
||||
void (*rtw_vmfree)(u8 *pbuf, u32 sz);
|
||||
u8* (*rtw_malloc)(u32 sz);
|
||||
u8* (*rtw_zmalloc)(u32 sz);
|
||||
void (*rtw_mfree)(u8 *pbuf, u32 sz);
|
||||
void (*rtw_memcpy)(void* dst, void* src, u32 sz);
|
||||
int (*rtw_memcmp)(void *dst, void *src, u32 sz);
|
||||
void (*rtw_memset)(void *pbuf, int c, u32 sz);
|
||||
void (*rtw_init_sema)(_sema *sema, int init_val);
|
||||
void (*rtw_free_sema)(_sema *sema);
|
||||
void (*rtw_up_sema)(_sema *sema);
|
||||
u32 (*rtw_down_timeout_sema)(_sema *sema, u32 timeout);
|
||||
void (*rtw_mutex_init)(_mutex *pmutex);
|
||||
void (*rtw_mutex_free)(_mutex *pmutex);
|
||||
void (*rtw_mutex_get)(_mutex *pmutex);
|
||||
void (*rtw_mutex_put)(_mutex *pmutex);
|
||||
void (*rtw_enter_critical)(_lock *plock, _irqL *pirqL);
|
||||
void (*rtw_exit_critical)(_lock *plock, _irqL *pirqL);
|
||||
void (*rtw_enter_critical_bh)(_lock *plock, _irqL *pirqL);
|
||||
void (*rtw_exit_critical_bh)(_lock *plock, _irqL *pirqL);
|
||||
int (*rtw_enter_critical_mutex)(_mutex *pmutex, _irqL *pirqL);
|
||||
void (*rtw_exit_critical_mutex)(_mutex *pmutex, _irqL *pirqL);
|
||||
void (*rtw_spinlock_init)(_lock *plock);
|
||||
void (*rtw_spinlock_free)(_lock *plock);
|
||||
void (*rtw_spin_lock)(_lock *plock);
|
||||
void (*rtw_spin_unlock)(_lock *plock);
|
||||
void (*rtw_spinlock_irqsave)(_lock *plock, _irqL *irqL);
|
||||
void (*rtw_spinunlock_irqsave)(_lock *plock, _irqL *irqL);
|
||||
int (*rtw_init_xqueue)( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages );
|
||||
int (*rtw_push_to_xqueue)( _xqueue* queue, void* message, u32 timeout_ms );
|
||||
int (*rtw_pop_from_xqueue)( _xqueue* queue, void* message, u32 timeout_ms );
|
||||
int (*rtw_deinit_xqueue)( _xqueue* queue );
|
||||
u32 (*rtw_get_current_time)(void);
|
||||
u32 (*rtw_systime_to_ms)(u32 systime);
|
||||
u32 (*rtw_systime_to_sec)(u32 systime);
|
||||
u32 (*rtw_ms_to_systime)(u32 ms);
|
||||
u32 (*rtw_sec_to_systime)(u32 sec);
|
||||
void (*rtw_msleep_os)(int ms);
|
||||
void (*rtw_usleep_os)(int us);
|
||||
void (*rtw_mdelay_os)(int ms);
|
||||
void (*rtw_udelay_os)(int us);
|
||||
void (*rtw_yield_os)(void);
|
||||
void (*rtw_init_timer)(_timer *ptimer, void *adapter, TIMER_FUN pfunc,void* cntx, const char *name);
|
||||
void (*rtw_set_timer)(_timer *ptimer,u32 delay_time);
|
||||
u8 (*rtw_cancel_timer)(_timer *ptimer);
|
||||
void (*rtw_del_timer)(_timer *ptimer);
|
||||
void (*ATOMIC_SET)(ATOMIC_T *v, int i);
|
||||
int (*ATOMIC_READ)(ATOMIC_T *v);
|
||||
void (*ATOMIC_ADD)(ATOMIC_T *v, int i);
|
||||
void (*ATOMIC_SUB)(ATOMIC_T *v, int i);
|
||||
void (*ATOMIC_INC)(ATOMIC_T *v);
|
||||
void (*ATOMIC_DEC)(ATOMIC_T *v);
|
||||
int (*ATOMIC_ADD_RETURN)(ATOMIC_T *v, int i);
|
||||
int (*ATOMIC_SUB_RETURN)(ATOMIC_T *v, int i);
|
||||
int (*ATOMIC_INC_RETURN)(ATOMIC_T *v);
|
||||
int (*ATOMIC_DEC_RETURN)(ATOMIC_T *v);
|
||||
u64 (*rtw_modular64)(u64 x, u64 y);
|
||||
int (*rtw_get_random_bytes)(void* dst, u32 size);
|
||||
u32 (*rtw_getFreeHeapSize)(void);
|
||||
int (*rtw_create_task)(struct task_struct *task, const char *name, u32 stack_size, u32 priority, thread_func_t func, void *thctx);
|
||||
void (*rtw_delete_task)(struct task_struct *task);
|
||||
void (*rtw_wakeup_task)(struct task_struct *task);
|
||||
|
||||
#if 0 //TODO
|
||||
void (*rtw_init_delayed_work)(struct delayed_work *dwork, work_func_t func, const char *name);
|
||||
void (*rtw_deinit_delayed_work)(struct delayed_work *dwork);
|
||||
int (*rtw_queue_delayed_work)(struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay, void* context);
|
||||
BOOLEAN (*rtw_cancel_delayed_work)(struct delayed_work *dwork);
|
||||
#endif
|
||||
void (*rtw_thread_enter)(char *name);
|
||||
void (*rtw_thread_exit)(void);
|
||||
_timerHandle (*rtw_timerCreate)( const signed char *pcTimerName,
|
||||
osdepTickType xTimerPeriodInTicks,
|
||||
u32 uxAutoReload,
|
||||
void * pvTimerID,
|
||||
TIMER_FUN pxCallbackFunction );
|
||||
u32 (*rtw_timerDelete)( _timerHandle xTimer,
|
||||
osdepTickType xBlockTime );
|
||||
u32 (*rtw_timerIsTimerActive)( _timerHandle xTimer );
|
||||
u32 (*rtw_timerStop)( _timerHandle xTimer,
|
||||
osdepTickType xBlockTime );
|
||||
u32 (*rtw_timerChangePeriod)( _timerHandle xTimer,
|
||||
osdepTickType xNewPeriod,
|
||||
osdepTickType xBlockTime );
|
||||
};
|
||||
/*********************************** OSDEP API end *****************************************/
|
||||
|
||||
|
||||
#endif //#ifndef __OSDEP_SERVICE_H_
|
54
component/common/drivers/wlan/realtek/src/osdep/skbuff.h
Normal file
54
component/common/drivers/wlan/realtek/src/osdep/skbuff.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef __SKBUFF_H__
|
||||
#define __SKBUFF_H__
|
||||
|
||||
struct sk_buff_head {
|
||||
struct list_head *next, *prev;
|
||||
unsigned int qlen;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
#define TRACE_SKB_DEPTH 8
|
||||
#endif
|
||||
|
||||
struct sk_buff {
|
||||
/* These two members must be first. */
|
||||
struct sk_buff *next; /* Next buffer in list */
|
||||
struct sk_buff *prev; /* Previous buffer in list */
|
||||
|
||||
struct sk_buff_head *list; /* List we are on */
|
||||
unsigned char *head; /* Head of buffer */
|
||||
unsigned char *data; /* Data head pointer */
|
||||
unsigned char *tail; /* Tail pointer */
|
||||
unsigned char *end; /* End pointer */
|
||||
void *dev; /* Device we arrived on/are leaving by */
|
||||
unsigned int len; /* Length of actual data */
|
||||
#ifdef CONFIG_TRACE_SKB
|
||||
unsigned int liston[TRACE_SKB_DEPTH]; /* Trace the Lists we went through */
|
||||
const char *funcname[TRACE_SKB_DEPTH];
|
||||
unsigned int list_idx; /* Trace the List we are on */
|
||||
#endif
|
||||
};
|
||||
|
||||
unsigned char *skb_put(struct sk_buff *skb, unsigned int len);
|
||||
unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);
|
||||
void skb_reserve(struct sk_buff *skb, unsigned int len);
|
||||
void skb_assign_buf(struct sk_buff *skb, unsigned char *buf, unsigned int len);
|
||||
unsigned char *skb_tail_pointer(const struct sk_buff *skb);
|
||||
void skb_set_tail_pointer(struct sk_buff *skb, const int offset);
|
||||
unsigned char *skb_end_pointer(const struct sk_buff *skb);
|
||||
|
||||
void init_skb_pool(void);
|
||||
void init_skb_data_pool(void);
|
||||
|
||||
#ifndef CONFIG_DONT_CARE_TP
|
||||
struct sk_buff *dev_alloc_skb(unsigned int length, unsigned int reserve_len);
|
||||
#else
|
||||
struct sk_buff *dev_alloc_tx_skb(unsigned int length, unsigned int reserve_len);
|
||||
struct sk_buff *dev_alloc_rx_skb(unsigned int length, unsigned int reserve_len);
|
||||
#define dev_alloc_skb dev_alloc_tx_skb
|
||||
#endif
|
||||
void kfree_skb(struct sk_buff *skb);
|
||||
|
||||
|
||||
#endif //__SKBUFF_H__
|
||||
|
1206
component/common/drivers/wlan/realtek/src/osdep/wireless.h
Normal file
1206
component/common/drivers/wlan/realtek/src/osdep/wireless.h
Normal file
File diff suppressed because it is too large
Load diff
66
component/common/drivers/wlan/realtek/src/osdep/wlan_intf.h
Normal file
66
component/common/drivers/wlan/realtek/src/osdep/wlan_intf.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef __WLAN_INTF_H__
|
||||
#define __WLAN_INTF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <autoconf.h>
|
||||
|
||||
#include <wireless.h>
|
||||
#include "wifi_constants.h"
|
||||
|
||||
#ifndef WLAN0_IDX
|
||||
#define WLAN0_IDX 0
|
||||
#endif
|
||||
#ifndef WLAN1_IDX
|
||||
#define WLAN1_IDX 1
|
||||
#endif
|
||||
#ifndef WLAN_UNDEF
|
||||
#define WLAN_UNDEF -1
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
/*
|
||||
struct sk_buff {
|
||||
// These two members must be first.
|
||||
struct sk_buff *next; // Next buffer in list
|
||||
struct sk_buff *prev; // Previous buffer in list
|
||||
|
||||
struct sk_buff_head *list; // List we are on
|
||||
unsigned char *head; // Head of buffer
|
||||
unsigned char *data; // Data head pointer
|
||||
unsigned char *tail; // Tail pointer
|
||||
unsigned char *end; //End pointer
|
||||
struct net_device *dev; //Device we arrived on/are leaving by
|
||||
unsigned int len; // Length of actual data
|
||||
};
|
||||
*/
|
||||
/************************************************************/
|
||||
|
||||
//----- ------------------------------------------------------------------
|
||||
// Wlan Interface opened for upper layer
|
||||
//----- ------------------------------------------------------------------
|
||||
int rltk_wlan_init(int idx_wlan, rtw_mode_t mode); //return 0: success. -1:fail
|
||||
void rltk_wlan_deinit(void);
|
||||
void rltk_wlan_start(int idx_wlan);
|
||||
void rltk_wlan_statistic(unsigned char idx);
|
||||
unsigned char rltk_wlan_running(unsigned char idx); // interface is up. 0: interface is down
|
||||
int rltk_wlan_control(unsigned long cmd, void *data);
|
||||
int rltk_wlan_handshake_done(void);
|
||||
int rltk_wlan_rf_on(void);
|
||||
int rltk_wlan_rf_off(void);
|
||||
int rltk_wlan_check_bus(void);
|
||||
int rltk_wlan_wireless_mode(unsigned char mode);
|
||||
int rltk_wlan_set_wps_phase(unsigned char is_trigger_wps);
|
||||
int rtw_ps_enable(int enable);
|
||||
void rltk_wlan_pre_sleep_processing(void);
|
||||
void rltk_wlan_post_sleep_processing(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //#ifndef __WLAN_INTF_H__
|
84
component/common/example/cJSON/cJSON_example.c
Normal file
84
component/common/example/cJSON/cJSON_example.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include "cmsis_os.h"
|
||||
#include <cJSON.h>
|
||||
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
|
||||
/* The data structure for this example
|
||||
|
||||
{
|
||||
"Motion_Sensor" : "i",
|
||||
"Light" : {
|
||||
"Red" : "0",
|
||||
"Green" : "0",
|
||||
"Blue" : "0",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
static void gen_json_data(int i, int r, int g, int b)
|
||||
{
|
||||
|
||||
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
|
||||
cJSON *IOTJSObject = NULL, *colorJSObject = NULL;
|
||||
char *iot_json = NULL;
|
||||
|
||||
if((IOTJSObject = cJSON_CreateObject()) != NULL) {
|
||||
|
||||
cJSON_AddItemToObject(IOTJSObject, "Motion_Sensor", cJSON_CreateNumber(i));
|
||||
cJSON_AddItemToObject(IOTJSObject, "Light", colorJSObject = cJSON_CreateObject());
|
||||
|
||||
cJSON_AddItemToObject(colorJSObject, "Red", cJSON_CreateNumber(r));
|
||||
cJSON_AddItemToObject(colorJSObject, "Green", cJSON_CreateNumber(g));
|
||||
cJSON_AddItemToObject(colorJSObject, "Blue", cJSON_CreateNumber(b));
|
||||
|
||||
iot_json = cJSON_Print(IOTJSObject);
|
||||
cJSON_Delete(IOTJSObject);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void handle_json_data(char *iot_json)
|
||||
{
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
|
||||
cJSON *IOTJSObject, *sensorJSObject, *lightJSObject, *redJSObject, *greenJSObject, *blueJSObject;
|
||||
int sensor_data, red, green, blue;
|
||||
|
||||
if((IOTJSObject = cJSON_Parse(iot_json)) != NULL) {
|
||||
sensorJSObject = cJSON_GetObjectItem(IOTJSObject, "Motion_Sensor");
|
||||
if(sensorJSObject)
|
||||
sensor_data = sensorJSObject->valueint;
|
||||
|
||||
lightJSObject = cJSON_GetObjectItem(IOTJSObject, "Light");
|
||||
|
||||
if(lightJSObject){
|
||||
redJSObject = cJSON_GetObjectItem(lightJSObject, "Red");
|
||||
greenJSObject = cJSON_GetObjectItem(lightJSObject, "Green");
|
||||
blueJSObject = cJSON_GetObjectItem(lightJSObject, "Blue");
|
||||
|
||||
if(redJSObject)
|
||||
red = redJSObject->valueint;
|
||||
if(greenJSObject)
|
||||
green = greenJSObject->valueint;
|
||||
if(blueJSObject)
|
||||
blue = blueJSObject->valueint;
|
||||
}
|
||||
|
||||
cJSON_Delete(IOTJSObject);
|
||||
}
|
||||
}
|
59
component/common/example/example_entry.c
Normal file
59
component/common/example/example_entry.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_MDNS
|
||||
#include <mdns/example_mdns.h>
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_MCAST
|
||||
#include <mcast/example_mcast.h>
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_GOOGLE_NEST
|
||||
#include <googlenest/example_google.h>
|
||||
#define FromDevice 1
|
||||
#define ToDevice 2
|
||||
#define TYPE "ToDevice"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#include <wlan_fast_connect/example_wlan_fast_connect.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
Preprocessor of example
|
||||
*/
|
||||
void pre_example_entry(void)
|
||||
{
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
example_wlan_fast_connect();
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ADAPTER
|
||||
example_uart_adapter_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
All of the examples are disabled by default for code size consideration
|
||||
The configuration is enabled in platform_opts.h
|
||||
*/
|
||||
void example_entry(void)
|
||||
{
|
||||
#if (CONFIG_EXAMPLE_MDNS && !CONFIG_EXAMPLE_UART_ADAPTER)
|
||||
example_mdns();
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_MCAST
|
||||
example_mcast();
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_GOOGLE_NEST
|
||||
example_google(TYPE);
|
||||
#endif
|
||||
}
|
8
component/common/example/example_entry.h
Normal file
8
component/common/example/example_entry.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __EXAMPLE_ENTRY_H__
|
||||
#define __EXAMPLE_ENTRY_H__
|
||||
|
||||
|
||||
void example_entry(void);
|
||||
void pre_example_entry(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_ENTRY_H__
|
38
component/common/example/googlenest/example.html
Normal file
38
component/common/example/googlenest/example.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.firebase.com/js/client/2.1.1/firebase.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Realtek Google Nest API example</h1>
|
||||
<hr />
|
||||
|
||||
|
||||
<h3 style="text-align:center;margin-left:auto;margin-right:auto;">Data To Device</h3>
|
||||
|
||||
<h4>Input the value of RGB to change the state of light:</h4>
|
||||
<p>Red <input type="text" id="redInput" placeholder="Red" />
|
||||
Green <input type="text" id="greenInput" placeholder="Green" />
|
||||
Blue <input type="text" id="blueInput" placeholder="Blue" />
|
||||
<input type="button" value="submit" name="submit" onClick="submit()" />
|
||||
</p>
|
||||
|
||||
<script>
|
||||
var myDataRef = new Firebase('https://your_firebase_address.firebaseio.com/light');
|
||||
function submit()
|
||||
{
|
||||
var red = $('#redInput').val();
|
||||
var green = $('#greenInput').val();
|
||||
var blue = $('#blueInput').val();
|
||||
myDataRef.set({
|
||||
Red: red,
|
||||
Green: green,
|
||||
Blue: blue
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
185
component/common/example/googlenest/example_google.c
Normal file
185
component/common/example/googlenest/example_google.c
Normal file
|
@ -0,0 +1,185 @@
|
|||
#include "cmsis_os.h"
|
||||
#include "diag.h"
|
||||
#include "wifi_conf.h"
|
||||
#include "wifi_ind.h"
|
||||
#include "google_nest.h"
|
||||
|
||||
|
||||
#include <googlenest/example_google.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
osThreadId google_thread_id;
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
|
||||
void google_data_retrieve(char *response_buf);
|
||||
|
||||
void google_data_retrieve(char *response_buf) {
|
||||
//printf("\r\n\r\n\r\nResponse_buf:\r\n%s\r\n", response_buf);
|
||||
char *event = NULL;
|
||||
char *delims = "\n";
|
||||
char *data = NULL, *backup = NULL;
|
||||
char *info = NULL;
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
event = strtok_r(response_buf, delims, &backup);
|
||||
data = strtok_r( NULL, delims, &backup );
|
||||
|
||||
if (!strncmp(data, "data: ", strlen("data: "))){
|
||||
info = data + strlen("data: ");
|
||||
if(info != NULL){
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
cJSON *infoJSObject, *pathJSObject, *dataJSObject;
|
||||
cJSON *redJSObject, *greenJSObject, *blueJSObject;
|
||||
char *red, *green, *blue;
|
||||
|
||||
|
||||
if((infoJSObject = cJSON_Parse(info)) != NULL) {
|
||||
pathJSObject = cJSON_GetObjectItem(infoJSObject, "path");
|
||||
dataJSObject = cJSON_GetObjectItem(infoJSObject, "data");
|
||||
if(dataJSObject != NULL) {
|
||||
|
||||
redJSObject = cJSON_GetObjectItem(dataJSObject, "Red");
|
||||
greenJSObject = cJSON_GetObjectItem(dataJSObject, "Green");
|
||||
blueJSObject = cJSON_GetObjectItem(dataJSObject, "Blue");
|
||||
|
||||
if(redJSObject)
|
||||
red = redJSObject->valuestring;
|
||||
|
||||
if(greenJSObject)
|
||||
green = greenJSObject->valuestring;
|
||||
|
||||
if(blueJSObject)
|
||||
blue = blueJSObject->valuestring;
|
||||
|
||||
printf("\n\rThe latest RGB information: RGB(%s, %s, %s)\n\r", red, green, blue);
|
||||
|
||||
cJSON_Delete(dataJSObject);
|
||||
}
|
||||
cJSON_Delete(infoJSObject);
|
||||
}
|
||||
else
|
||||
printf("\r\nCannot parse the message to JSON!\r\n");
|
||||
|
||||
}
|
||||
else
|
||||
printf("\r\n This is the keep alive message or cannot get the information!\r\n");
|
||||
}
|
||||
else
|
||||
printf("\r\nData structure may wrong!\r\n");
|
||||
}
|
||||
|
||||
|
||||
void gn_todevice_start(void) {
|
||||
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = HOST_ADDR;
|
||||
char *googlenest_uri = "light.json";
|
||||
|
||||
printf("\r\nStart connecting to Google Nest Server...\r\n");
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
|
||||
reconnect:
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
printf("\r\n Connection is OK!\r\n");
|
||||
|
||||
google_retrieve_data_hook_callback(google_data_retrieve);
|
||||
if(gn_stream(&googlenest, googlenest_uri) != 0){
|
||||
printf("\r\n Connection is fail! \r\n Start Reconnecting...\r\n");
|
||||
goto reconnect;
|
||||
}
|
||||
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
else{
|
||||
printf("\r\n Connection is fail! \r\n\r\n\r\n\r\nStart Reconnecting...\r\n");
|
||||
goto reconnect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void gn_fromdevice_start(void) {
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_uri = "MotionSensor.json";
|
||||
cJSON_Hooks memoryHook;
|
||||
int j = 0;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
printf("\r\nStart connecting to Google Nest Server!\r\n");
|
||||
|
||||
while(1) {
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, HOST_ADDR, GN_PORT) == 0) {
|
||||
cJSON *MSJSObject;
|
||||
char *data;
|
||||
|
||||
if((MSJSObject = cJSON_CreateObject()) != NULL) {
|
||||
cJSON_AddItemToObject(MSJSObject, "MotionSenser", cJSON_CreateNumber(j++));
|
||||
data = cJSON_Print(MSJSObject);
|
||||
cJSON_Delete(MSJSObject);
|
||||
}
|
||||
|
||||
if(gn_put(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\n\rUpdate the Motion Sensor's data to %d\n\r", (j-1));
|
||||
free(data);
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
else{
|
||||
printf("\n\rConnection failed!\n\r");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(5 * configTICK_RATE_HZ);
|
||||
}
|
||||
}
|
||||
|
||||
void gn_fromdevice_task(void *arg) {
|
||||
int i;
|
||||
|
||||
printf("\n\r\n\r\n\r\n\r<<<<<<Waiting for 2 mins to connect Wi-Fi>>>>>>>\n\r\n\r\n\r\n\r");
|
||||
for (i = 0; i<120; i++)
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
gn_fromdevice_start();
|
||||
}
|
||||
|
||||
void gn_todevice_task(void *arg) {
|
||||
int i;
|
||||
|
||||
printf("\n\r\n\r\n\r\n\r<<<<<<Waiting for 2 mins to connect Wi-Fi>>>>>>>\n\r\n\r\n\r\n\r");
|
||||
for (i = 0; i<120; i++)
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
gn_todevice_start();
|
||||
}
|
||||
|
||||
void example_google(char *type) {
|
||||
|
||||
|
||||
if(strcmp(type, "FromDevice") == 0){
|
||||
osThreadDef_t google_thread;
|
||||
google_thread.instances = 1;
|
||||
google_thread.name = "google thread";
|
||||
google_thread.stacksize = 4096;
|
||||
google_thread.pthread = (os_pthread)gn_fromdevice_task;
|
||||
google_thread.tpriority = tskIDLE_PRIORITY+6;
|
||||
google_thread_id = osThreadCreate(&google_thread, NULL);
|
||||
}
|
||||
else if(strcmp(type, "ToDevice") == 0){
|
||||
osThreadDef_t google_thread;
|
||||
google_thread.instances = 1;
|
||||
google_thread.name = "google thread";
|
||||
google_thread.stacksize = 4096;
|
||||
google_thread.pthread = (os_pthread)gn_todevice_task;
|
||||
google_thread.tpriority = tskIDLE_PRIORITY+6;
|
||||
google_thread_id = osThreadCreate(&google_thread, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
10
component/common/example/googlenest/example_google.h
Normal file
10
component/common/example/googlenest/example_google.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef GOOGLE_THREAD_H
|
||||
#define GOOGLE_THREAD_H
|
||||
|
||||
#define HOST_ADDR "your_firebase_address.firebaseio.com"
|
||||
#define GN_PORT 443
|
||||
|
||||
void example_google(char *type);
|
||||
|
||||
|
||||
#endif
|
98
component/common/example/mcast/example_mcast.c
Normal file
98
component/common/example/mcast/example_mcast.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
extern struct netif xnetif[];
|
||||
|
||||
static void example_mcast_thread(void *param)
|
||||
{
|
||||
#if LWIP_IGMP
|
||||
int err = 0;
|
||||
int socket = -1;
|
||||
char *group_ip = "224.0.0.251";
|
||||
uint16_t port = 5353;
|
||||
|
||||
// Set NETIF_FLAG_IGMP flag for netif which should process IGMP messages
|
||||
xnetif[0].flags |= NETIF_FLAG_IGMP;
|
||||
|
||||
if((socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
printf("ERROR: socket - AF_INET, SOCK_DGRAM\n");
|
||||
err = -1;
|
||||
}
|
||||
|
||||
// Add multicast group membership on this interface
|
||||
if(err == 0) {
|
||||
struct ip_mreq imr;
|
||||
imr.imr_multiaddr.s_addr = inet_addr(group_ip);
|
||||
imr.imr_interface.s_addr = INADDR_ANY;
|
||||
err = setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(imr));
|
||||
if(err < 0) printf("ERROR: setsockopt - IP_ADD_MEMBERSHIP\n");
|
||||
}
|
||||
|
||||
// Specify outgoing interface too
|
||||
if(err == 0) {
|
||||
struct in_addr intfAddr;
|
||||
intfAddr.s_addr = INADDR_ANY;
|
||||
err = setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, &intfAddr, sizeof(struct in_addr));
|
||||
if(err < 0) printf("ERROR: setsockopt - IP_MULTICAST_IF\n");
|
||||
}
|
||||
|
||||
// And start listening for packets
|
||||
if(err == 0) {
|
||||
struct sockaddr_in bindAddr;
|
||||
bindAddr.sin_family = AF_INET;
|
||||
bindAddr.sin_port = htons(port);
|
||||
bindAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
err = bind(socket, (struct sockaddr *) &bindAddr, sizeof(bindAddr));
|
||||
if(err < 0) printf("ERROR: bind\n");
|
||||
}
|
||||
|
||||
if(err == 0) {
|
||||
unsigned char packet[1024];
|
||||
|
||||
while(1) {
|
||||
// Receive multicast
|
||||
int packetLen;
|
||||
struct sockaddr from;
|
||||
struct sockaddr_in *from_sin = (struct sockaddr_in*) &from;
|
||||
socklen_t fromLen = sizeof(from);
|
||||
|
||||
if((packetLen = recvfrom(socket, &packet, sizeof(packet), 0, &from, &fromLen)) >= 0) {
|
||||
uint8_t *ip = (uint8_t *) &from_sin->sin_addr.s_addr;
|
||||
uint16_t from_port = ntohs(from_sin->sin_port);
|
||||
printf("recvfrom - %d bytes from %d.%d.%d.%d:%d\n", packetLen, ip[0], ip[1], ip[2], ip[3], from_port);
|
||||
}
|
||||
|
||||
// Send multicast
|
||||
if(packetLen > 0) {
|
||||
int sendLen;
|
||||
struct sockaddr to;
|
||||
struct sockaddr_in *to_sin = (struct sockaddr_in*) &to;
|
||||
to_sin->sin_family = AF_INET;
|
||||
to_sin->sin_port = htons(port);
|
||||
to_sin->sin_addr.s_addr = inet_addr(group_ip);
|
||||
|
||||
if((sendLen = sendto(socket, packet, packetLen, 0, &to, sizeof(struct sockaddr))) < 0)
|
||||
printf("ERROR: sendto %s\n", group_ip);
|
||||
else
|
||||
printf("sendto - %d bytes to %s:%d\n", sendLen, group_ip, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(socket != -1) {
|
||||
close(socket);
|
||||
}
|
||||
#else
|
||||
printf("\nSHOULD ENABLE LWIP_IGMP\n");
|
||||
#endif
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_mcast(void)
|
||||
{
|
||||
if(xTaskCreate(example_mcast_thread, ((const char*)"example_mcast_thread"), 2048, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
6
component/common/example/mcast/example_mcast.h
Normal file
6
component/common/example/mcast/example_mcast.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_MCAST_H
|
||||
#define EXAMPLE_MCAST_H
|
||||
|
||||
void example_mcast(void);
|
||||
|
||||
#endif /* EXAMPLE_MCAST_H */
|
17
component/common/example/mcast/readme.txt
Normal file
17
component/common/example/mcast/readme.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
LWIP MULTICAST EXAMPLE
|
||||
|
||||
Description:
|
||||
Join multicast group of 224.0.0.251 and listen on port 5353.
|
||||
Send packet with the content of received packet to multicast group of 224.0.0.251.
|
||||
|
||||
Configuration:
|
||||
[lwipopts.h]
|
||||
#define LWIP_UDP 1
|
||||
#define LWIP_IGMP 1
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_MCAST 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A multicast example thread will be started automatically when booting.
|
||||
|
55
component/common/example/mdns/example_mdns.c
Normal file
55
component/common/example/mdns/example_mdns.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <mDNS/mDNS.h>
|
||||
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
extern struct netif xnetif[];
|
||||
|
||||
static void example_mdns_thread(void *param)
|
||||
{
|
||||
DNSServiceRef dnsServiceRef = NULL;
|
||||
TXTRecordRef txtRecord;
|
||||
unsigned char txt_buf[100]; // use fixed buffer for text record to prevent malloc/free
|
||||
|
||||
// Delay to wait for IP by DHCP
|
||||
vTaskDelay(10000);
|
||||
|
||||
printf("\nmDNS Init\n");
|
||||
if(mDNSResponderInit() == 0) {
|
||||
printf("mDNS Register service\n");
|
||||
TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
|
||||
TXTRecordSetValue(&txtRecord, "text1", strlen("text1_content"), "text1_content");
|
||||
TXTRecordSetValue(&txtRecord, "text2", strlen("text2_content"), "text2_content");
|
||||
dnsServiceRef = mDNSRegisterService("ameba", "_service1._tcp", "local", 5000, &txtRecord);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
printf("wait for 30s ... \n");
|
||||
vTaskDelay(30*1000);
|
||||
|
||||
printf("mDNS Update service\n");
|
||||
TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
|
||||
TXTRecordSetValue(&txtRecord, "text1", strlen("text1_content_new"), "text1_content_new");
|
||||
mDNSUpdateService(dnsServiceRef, &txtRecord);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
printf("wait for 30s ... \n");
|
||||
vTaskDelay(30*1000);
|
||||
|
||||
if(dnsServiceRef)
|
||||
mDNSDeregisterService(dnsServiceRef);
|
||||
|
||||
// deregister service before mdns deinit is not necessary
|
||||
// mDNS deinit will also deregister all services
|
||||
printf("mDNS Deinit\n");
|
||||
mDNSResponderDeinit();
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_mdns(void)
|
||||
{
|
||||
if(xTaskCreate(example_mdns_thread, ((const char*)"example_mdns_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
6
component/common/example/mdns/example_mdns.h
Normal file
6
component/common/example/mdns/example_mdns.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_MDNS_H
|
||||
#define EXAMPLE_MDNS_H
|
||||
|
||||
void example_mdns(void);
|
||||
|
||||
#endif /* EXAMPLE_MDNS_H */
|
|
@ -0,0 +1,125 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/** @file
|
||||
|
||||
This example demonstrate how to implement wifi fast reconnection
|
||||
**/
|
||||
#include <platform_opts.h>
|
||||
#include <wlan_fast_connect/example_wlan_fast_connect.h>
|
||||
|
||||
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "flash_api.h"
|
||||
|
||||
write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
extern void fATW0(void *arg);
|
||||
extern void fATW1(void *arg);
|
||||
extern void fATW2(void *arg);
|
||||
extern void fATWC(void *arg);
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* wifi connection indication trigger this function to save current
|
||||
* wifi profile in flash
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
|
||||
int wlan_wrtie_reconnect_data_to_flash(uint8_t *data, uint32_t len)
|
||||
{
|
||||
flash_t flash;
|
||||
uint8_t read_data [FAST_RECONNECT_DATA_LEN];
|
||||
if(!data)
|
||||
return -1;
|
||||
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, FAST_RECONNECT_DATA_LEN, (uint8_t *) read_data);
|
||||
|
||||
//wirte it to flash if different content: SSID, Passphrase, Channel
|
||||
if(memcmp((void *)data, (void *)read_data, NDIS_802_11_LENGTH_SSID) ||
|
||||
memcmp((void *)(data + NDIS_802_11_LENGTH_SSID + 4), (void *)(read_data + NDIS_802_11_LENGTH_SSID + 4), 32) ||
|
||||
memcmp((void *)(data + NDIS_802_11_LENGTH_SSID + 4 + 32 + A_SHA_DIGEST_LEN * 2), (void *)(read_data + NDIS_802_11_LENGTH_SSID + 4 + 32 + A_SHA_DIGEST_LEN * 2), 4)){
|
||||
printf("\r\n %s():not the same ssid/passphrase/channel, need to flash it", __func__);
|
||||
|
||||
flash_erase_sector(&flash, FAST_RECONNECT_DATA);
|
||||
flash_stream_write(&flash, FAST_RECONNECT_DATA, len, (uint8_t *) data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* After wifi init done, waln driver call this function to check whether
|
||||
* auto-connect is required.
|
||||
*
|
||||
* This function read previous saved wlan profile in flash and execute connection.
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
int wlan_init_done_callback()
|
||||
{
|
||||
flash_t flash;
|
||||
uint8_t *data;
|
||||
uint32_t channel;
|
||||
uint8_t pscan_config;
|
||||
char key_id;
|
||||
|
||||
data = (uint8_t *)rtw_zmalloc(FAST_RECONNECT_DATA_LEN);
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, FAST_RECONNECT_DATA_LEN, (uint8_t *)data);
|
||||
if(*((uint32_t *) data) != ~0x0){
|
||||
memcpy(psk_essid, (uint8_t *)data, NDIS_802_11_LENGTH_SSID + 4);
|
||||
memcpy(psk_passphrase, (uint8_t *)data + NDIS_802_11_LENGTH_SSID + 4, (IW_PASSPHRASE_MAX_SIZE + 1));
|
||||
memcpy(wpa_global_PSK, (uint8_t *)data + NDIS_802_11_LENGTH_SSID + 4 + (IW_PASSPHRASE_MAX_SIZE + 1), A_SHA_DIGEST_LEN * 2);
|
||||
memcpy(&channel, (uint8_t *)data + NDIS_802_11_LENGTH_SSID + 4 + (IW_PASSPHRASE_MAX_SIZE + 1) + A_SHA_DIGEST_LEN * 2, 4);
|
||||
sprintf(&key_id,"%d",(channel >> 28));
|
||||
channel &= 0xff;
|
||||
pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY;
|
||||
//set partial scan for entering to listen beacon quickly
|
||||
wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
|
||||
|
||||
#ifdef CONFIG_AUTO_RECONNECT
|
||||
wifi_set_autoreconnect(1);
|
||||
#endif
|
||||
//set wifi connect
|
||||
//open mode
|
||||
if(!strlen((char*)psk_passphrase)){
|
||||
fATW0((char*)psk_essid);
|
||||
}
|
||||
//wep mode
|
||||
else if( strlen((char*)psk_passphrase) == 5 || strlen((char*)psk_passphrase) == 13){
|
||||
fATW0((char*)psk_essid);
|
||||
fATW1((char*)psk_passphrase);
|
||||
fATW2(&key_id);
|
||||
}
|
||||
//WPA/WPA2
|
||||
else{
|
||||
fATW0((char*)psk_essid);
|
||||
fATW1((char*)psk_passphrase);
|
||||
}
|
||||
fATWC(NULL);
|
||||
}
|
||||
if(data)
|
||||
rtw_mfree(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void example_wlan_fast_connect()
|
||||
{
|
||||
// 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_wrtie_reconnect_data_to_flash;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
||||
#define __EXAMPLE_FAST_RECONNECTION_H__
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
|
||||
#define IW_PASSPHRASE_MAX_SIZE 64
|
||||
#define FAST_RECONNECT_DATA (0xC0000 - 0x1000)
|
||||
#define NDIS_802_11_LENGTH_SSID 32
|
||||
#define A_SHA_DIGEST_LEN 20
|
||||
#define FAST_RECONNECT_DATA_LEN (NDIS_802_11_LENGTH_SSID+4 +(IW_PASSPHRASE_MAX_SIZE + 1)+ A_SHA_DIGEST_LEN * 2 + 4)
|
||||
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
|
||||
//Variable
|
||||
extern unsigned char psk_essid[NET_IF_NUM][NDIS_802_11_LENGTH_SSID+4];
|
||||
extern unsigned char psk_passphrase[NET_IF_NUM][IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
extern unsigned char wpa_global_PSK[NET_IF_NUM][A_SHA_DIGEST_LEN * 2];
|
||||
extern unsigned char psk_passphrase64[IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
|
||||
//Function
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
void example_wlan_fast_connect(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
66
component/common/mbed/api/error.h
Normal file
66
component/common/mbed/api/error.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ERROR_H
|
||||
#define MBED_ERROR_H
|
||||
|
||||
/** To generate a fatal compile-time error, you can use the pre-processor #error directive.
|
||||
*
|
||||
* @code
|
||||
* #error "That shouldn't have happened!"
|
||||
* @endcode
|
||||
*
|
||||
* If the compiler evaluates this line, it will report the error and stop the compile.
|
||||
*
|
||||
* For example, you could use this to check some user-defined compile-time variables:
|
||||
*
|
||||
* @code
|
||||
* #define NUM_PORTS 7
|
||||
* #if (NUM_PORTS > 4)
|
||||
* #error "NUM_PORTS must be less than 4"
|
||||
* #endif
|
||||
* @endcode
|
||||
*
|
||||
* Reporting Run-Time Errors:
|
||||
* To generate a fatal run-time error, you can use the mbed error() function.
|
||||
*
|
||||
* @code
|
||||
* error("That shouldn't have happened!");
|
||||
* @endcode
|
||||
*
|
||||
* If the mbed running the program executes this function, it will print the
|
||||
* message via the USB serial port, and then die with the blue lights of death!
|
||||
*
|
||||
* The message can use printf-style formatting, so you can report variables in the
|
||||
* message too. For example, you could use this to check a run-time condition:
|
||||
*
|
||||
* @code
|
||||
* if(x >= 5) {
|
||||
* error("expected x to be less than 5, but got %d", x);
|
||||
* }
|
||||
* #endcode
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void error(const char* format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
50
component/common/mbed/api/mbed_assert.h
Normal file
50
component/common/mbed/api/mbed_assert.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ASSERT_H
|
||||
#define MBED_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Internal mbed assert function which is invoked when MBED_ASSERT macro failes.
|
||||
* This function is active only if NDEBUG is not defined prior to including this
|
||||
* assert header file.
|
||||
* In case of MBED_ASSERT failing condition, the assertation message is printed
|
||||
* to stderr and mbed_die() is called.
|
||||
* @param expr Expresion to be checked.
|
||||
* @param file File where assertation failed.
|
||||
* @param line Failing assertation line number.
|
||||
*/
|
||||
void mbed_assert_internal(const char *expr, const char *file, int line);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define MBED_ASSERT(expr) ((void)0)
|
||||
|
||||
#else
|
||||
#define MBED_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
mbed_assert_internal(#expr, __FILE__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif
|
66
component/common/mbed/api/wait_api.h
Normal file
66
component/common/mbed/api/wait_api.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_WAIT_API_H
|
||||
#define MBED_WAIT_API_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Generic wait functions.
|
||||
*
|
||||
* These provide simple NOP type wait capabilities.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* DigitalOut heartbeat(LED1);
|
||||
*
|
||||
* int main() {
|
||||
* while (1) {
|
||||
* heartbeat = 1;
|
||||
* wait(0.5);
|
||||
* heartbeat = 0;
|
||||
* wait(0.5);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
/** Waits for a number of seconds, with microsecond resolution (within
|
||||
* the accuracy of single precision floating point).
|
||||
*
|
||||
* @param s number of seconds to wait
|
||||
*/
|
||||
void wait(float s);
|
||||
|
||||
/** Waits a number of milliseconds.
|
||||
*
|
||||
* @param ms the whole number of milliseconds to wait
|
||||
*/
|
||||
void wait_ms(int ms);
|
||||
|
||||
/** Waits a number of microseconds.
|
||||
*
|
||||
* @param us the whole number of microseconds to wait
|
||||
*/
|
||||
void wait_us(int us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
0
component/common/mbed/common/.gitkeep
Normal file
0
component/common/mbed/common/.gitkeep
Normal file
52
component/common/mbed/common/Makefile
Normal file
52
component/common/mbed/common/Makefile
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
include $(MAKE_INCLUDE_GEN)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
MODULE_IFLAGS = -I../
|
||||
|
||||
#*****************************************************************************#
|
||||
# Object FILE LIST #
|
||||
#*****************************************************************************#
|
||||
OBJS =
|
||||
OBJS_ROM =
|
||||
OBJS_RAM =
|
||||
ifeq ($(CONFIG_TIMER_MODULE),y)
|
||||
OBJS += us_ticker_api.o wait_api.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_BUILD_RAM),y)
|
||||
OBJS = $(OBJS_RAM)
|
||||
else ifeq ($(CONFIG_RELEASE_BUILD_RAM_ALL),y)
|
||||
OBJS += $(OBJS_RAM)
|
||||
else ifeq ($(CONFIG_RELEASE_BUILD_LIBRARIES),y)
|
||||
OBJS = $(CSRC_ROM)
|
||||
else ifeq ($(CONFIG_NORMAL_BUILD),y)
|
||||
OBJS += $(CSRC_ROM)
|
||||
OBJS += $(CSRC_RAM)
|
||||
endif
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO GENERATE TARGETS #
|
||||
#*****************************************************************************#
|
||||
|
||||
# Define the Rules to build the core targets
|
||||
all: CORE_TARGETS COPY_RAM_OBJS
|
||||
|
||||
#*****************************************************************************#
|
||||
# GENERATE OBJECT FILE
|
||||
#*****************************************************************************#
|
||||
CORE_TARGETS: $(OBJS)
|
||||
|
||||
|
||||
#*****************************************************************************#
|
||||
# RULES TO CLEAN TARGETS #
|
||||
#*****************************************************************************#
|
||||
clean:
|
||||
$(REMOVE) *.o
|
||||
$(REMOVE) *.i
|
||||
$(REMOVE) *.s
|
||||
$(REMOVE) *.d
|
||||
|
||||
-include $(DEPS)
|
118
component/common/mbed/common/us_ticker_api.c
Normal file
118
component/common/mbed/common/us_ticker_api.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include "us_ticker_api.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
static ticker_event_handler event_handler;
|
||||
static ticker_event_t *head = NULL;
|
||||
|
||||
void us_ticker_set_handler(ticker_event_handler handler) {
|
||||
us_ticker_init();
|
||||
|
||||
event_handler = handler;
|
||||
}
|
||||
|
||||
void us_ticker_irq_handler(void) {
|
||||
us_ticker_clear_interrupt();
|
||||
|
||||
/* Go through all the pending TimerEvents */
|
||||
while (1) {
|
||||
if (head == NULL) {
|
||||
// There are no more TimerEvents left, so disable matches.
|
||||
us_ticker_disable_interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int)(head->timestamp - us_ticker_read()) <= 0) {
|
||||
// This event was in the past:
|
||||
// point to the following one and execute its handler
|
||||
ticker_event_t *p = head;
|
||||
head = head->next;
|
||||
if (event_handler != NULL) {
|
||||
event_handler(p->id); // NOTE: the handler can set new events
|
||||
}
|
||||
/* Note: We continue back to examining the head because calling the
|
||||
* event handler may have altered the chain of pending events. */
|
||||
} else {
|
||||
// This event and the following ones in the list are in the future:
|
||||
// set it as next interrupt and return
|
||||
us_ticker_set_interrupt(head->timestamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
|
||||
/* disable interrupts for the duration of the function */
|
||||
__disable_irq();
|
||||
|
||||
// initialise our data
|
||||
obj->timestamp = timestamp;
|
||||
obj->id = id;
|
||||
|
||||
/* Go through the list until we either reach the end, or find
|
||||
an element this should come before (which is possibly the
|
||||
head). */
|
||||
ticker_event_t *prev = NULL, *p = head;
|
||||
while (p != NULL) {
|
||||
/* check if we come before p */
|
||||
if ((int)(timestamp - p->timestamp) <= 0) {
|
||||
break;
|
||||
}
|
||||
/* go to the next element */
|
||||
prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
/* if prev is NULL we're at the head */
|
||||
if (prev == NULL) {
|
||||
head = obj;
|
||||
us_ticker_set_interrupt(timestamp);
|
||||
} else {
|
||||
prev->next = obj;
|
||||
}
|
||||
/* if we're at the end p will be NULL, which is correct */
|
||||
obj->next = p;
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void us_ticker_remove_event(ticker_event_t *obj) {
|
||||
__disable_irq();
|
||||
|
||||
// remove this object from the list
|
||||
if (head == obj) {
|
||||
// first in the list, so just drop me
|
||||
head = obj->next;
|
||||
if (head == NULL) {
|
||||
us_ticker_disable_interrupt();
|
||||
} else {
|
||||
us_ticker_set_interrupt(head->timestamp);
|
||||
}
|
||||
} else {
|
||||
// find the object before me, then drop me
|
||||
ticker_event_t* p = head;
|
||||
while (p != NULL) {
|
||||
if (p->next == obj) {
|
||||
p->next = obj->next;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
}
|
30
component/common/mbed/common/wait_api.c
Normal file
30
component/common/mbed/common/wait_api.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "wait_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
void wait(float s) {
|
||||
wait_us((int)(s * 1000000.0f));
|
||||
}
|
||||
|
||||
void wait_ms(int ms) {
|
||||
wait_us(ms * 1000);
|
||||
}
|
||||
|
||||
void wait_us(int us) {
|
||||
uint32_t start = us_ticker_read();
|
||||
while ((us_ticker_read() - start) < (uint32_t)us);
|
||||
}
|
39
component/common/mbed/hal/analogin_api.h
Normal file
39
component/common/mbed/hal/analogin_api.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ANALOGIN_API_H
|
||||
#define MBED_ANALOGIN_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_ANALOGIN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct analogin_s analogin_t;
|
||||
|
||||
void analogin_init (analogin_t *obj, PinName pin);
|
||||
float analogin_read (analogin_t *obj);
|
||||
uint16_t analogin_read_u16(analogin_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
42
component/common/mbed/hal/analogout_api.h
Normal file
42
component/common/mbed/hal/analogout_api.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ANALOGOUT_API_H
|
||||
#define MBED_ANALOGOUT_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_ANALOGOUT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct dac_s dac_t;
|
||||
|
||||
void analogout_init (dac_t *obj, PinName pin);
|
||||
void analogout_free (dac_t *obj);
|
||||
void analogout_write (dac_t *obj, float value);
|
||||
void analogout_write_u16(dac_t *obj, uint16_t value);
|
||||
float analogout_read (dac_t *obj);
|
||||
uint16_t analogout_read_u16 (dac_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
80
component/common/mbed/hal/can_api.h
Normal file
80
component/common/mbed/hal/can_api.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CAN_API_H
|
||||
#define MBED_CAN_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_CAN
|
||||
|
||||
#include "PinNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
#include "can_helper.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
IRQ_RX,
|
||||
IRQ_TX,
|
||||
IRQ_ERROR,
|
||||
IRQ_OVERRUN,
|
||||
IRQ_WAKEUP,
|
||||
IRQ_PASSIVE,
|
||||
IRQ_ARB,
|
||||
IRQ_BUS,
|
||||
IRQ_READY
|
||||
} CanIrqType;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MODE_RESET,
|
||||
MODE_NORMAL,
|
||||
MODE_SILENT,
|
||||
MODE_TEST_GLOBAL,
|
||||
MODE_TEST_LOCAL,
|
||||
MODE_TEST_SILENT
|
||||
} CanMode;
|
||||
|
||||
typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
|
||||
|
||||
typedef struct can_s can_t;
|
||||
|
||||
void can_init (can_t *obj, PinName rd, PinName td);
|
||||
void can_free (can_t *obj);
|
||||
int can_frequency(can_t *obj, int hz);
|
||||
|
||||
void can_irq_init (can_t *obj, can_irq_handler handler, uint32_t id);
|
||||
void can_irq_free (can_t *obj);
|
||||
void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable);
|
||||
|
||||
int can_write (can_t *obj, CAN_Message, int cc);
|
||||
int can_read (can_t *obj, CAN_Message *msg, int handle);
|
||||
int can_mode (can_t *obj, CanMode mode);
|
||||
int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle);
|
||||
void can_reset (can_t *obj);
|
||||
unsigned char can_rderror (can_t *obj);
|
||||
unsigned char can_tderror (can_t *obj);
|
||||
void can_monitor (can_t *obj, int silent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // MBED_CAN_API_H
|
||||
|
||||
#endif
|
63
component/common/mbed/hal/ethernet_api.h
Normal file
63
component/common/mbed/hal/ethernet_api.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ETHERNET_API_H
|
||||
#define MBED_ETHERNET_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_ETHERNET
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Connection constants
|
||||
|
||||
int ethernet_init(void);
|
||||
void ethernet_free(void);
|
||||
|
||||
// write size bytes from data to ethernet buffer
|
||||
// return num bytes written
|
||||
// or -1 if size is too big
|
||||
int ethernet_write(const char *data, int size);
|
||||
|
||||
// send ethernet write buffer, returning the packet size sent
|
||||
int ethernet_send(void);
|
||||
|
||||
// recieve from ethernet buffer, returning packet size, or 0 if no packet
|
||||
int ethernet_receive(void);
|
||||
|
||||
// read size bytes in to data, return actual num bytes read (0..size)
|
||||
// if data == NULL, throw the bytes away
|
||||
int ethernet_read(char *data, int size);
|
||||
|
||||
// get the ethernet address
|
||||
void ethernet_address(char *mac);
|
||||
|
||||
// see if the link is up
|
||||
int ethernet_link(void);
|
||||
|
||||
// force link settings
|
||||
void ethernet_set_link(int speed, int duplex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
51
component/common/mbed/hal/gpio_api.h
Normal file
51
component/common/mbed/hal/gpio_api.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_GPIO_API_H
|
||||
#define MBED_GPIO_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Set the given pin as GPIO
|
||||
* @param pin The pin to be set as GPIO
|
||||
* @return The GPIO port mask for this pin
|
||||
**/
|
||||
uint32_t gpio_set(PinName pin);
|
||||
|
||||
/* GPIO object */
|
||||
void gpio_init(gpio_t *obj, PinName pin);
|
||||
|
||||
void gpio_mode (gpio_t *obj, PinMode mode);
|
||||
void gpio_dir (gpio_t *obj, PinDirection direction);
|
||||
|
||||
void gpio_write(gpio_t *obj, int value);
|
||||
int gpio_read (gpio_t *obj);
|
||||
|
||||
// the following set of functions are generic and are implemented in the common gpio.c file
|
||||
void gpio_init_in(gpio_t* gpio, PinName pin);
|
||||
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode);
|
||||
void gpio_init_out(gpio_t* gpio, PinName pin);
|
||||
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value);
|
||||
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
47
component/common/mbed/hal/gpio_irq_api.h
Normal file
47
component/common/mbed/hal/gpio_irq_api.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_GPIO_IRQ_API_H
|
||||
#define MBED_GPIO_IRQ_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
IRQ_NONE,
|
||||
IRQ_RISE,
|
||||
IRQ_FALL
|
||||
} gpio_irq_event;
|
||||
|
||||
typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event);
|
||||
|
||||
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id);
|
||||
void gpio_irq_free(gpio_irq_t *obj);
|
||||
void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable);
|
||||
void gpio_irq_enable(gpio_irq_t *obj);
|
||||
void gpio_irq_disable(gpio_irq_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
58
component/common/mbed/hal/i2c_api.h
Normal file
58
component/common/mbed/hal/i2c_api.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_I2C_API_H
|
||||
#define MBED_I2C_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_I2C
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct i2c_s i2c_t;
|
||||
|
||||
enum {
|
||||
I2C_ERROR_NO_SLAVE = -1,
|
||||
I2C_ERROR_BUS_BUSY = -2
|
||||
};
|
||||
|
||||
void i2c_init (i2c_t *obj, PinName sda, PinName scl);
|
||||
void i2c_frequency (i2c_t *obj, int hz);
|
||||
int i2c_start (i2c_t *obj);
|
||||
int i2c_stop (i2c_t *obj);
|
||||
int i2c_read (i2c_t *obj, int address, char *data, int length, int stop);
|
||||
int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop);
|
||||
void i2c_reset (i2c_t *obj);
|
||||
int i2c_byte_read (i2c_t *obj, int last);
|
||||
int i2c_byte_write (i2c_t *obj, int data);
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
void i2c_slave_mode (i2c_t *obj, int enable_slave);
|
||||
int i2c_slave_receive(i2c_t *obj);
|
||||
int i2c_slave_read (i2c_t *obj, char *data, int length);
|
||||
int i2c_slave_write (i2c_t *obj, const char *data, int length);
|
||||
void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
43
component/common/mbed/hal/pinmap.h
Normal file
43
component/common/mbed/hal/pinmap.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PINMAP_H
|
||||
#define MBED_PINMAP_H
|
||||
|
||||
#include "PinNames.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
PinName pin;
|
||||
int peripheral;
|
||||
int function;
|
||||
} PinMap;
|
||||
|
||||
void pin_function(PinName pin, int function);
|
||||
void pin_mode (PinName pin, PinMode mode);
|
||||
|
||||
uint32_t pinmap_peripheral(PinName pin, const PinMap* map);
|
||||
uint32_t pinmap_merge (uint32_t a, uint32_t b);
|
||||
void pinmap_pinout (PinName pin, const PinMap *map);
|
||||
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
42
component/common/mbed/hal/port_api.h
Normal file
42
component/common/mbed/hal/port_api.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PORTMAP_H
|
||||
#define MBED_PORTMAP_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_PORTIN || DEVICE_PORTOUT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct port_s port_t;
|
||||
|
||||
PinName port_pin(PortName port, int pin_n);
|
||||
|
||||
void port_init (port_t *obj, PortName port, int mask, PinDirection dir);
|
||||
void port_mode (port_t *obj, PinMode mode);
|
||||
void port_dir (port_t *obj, PinDirection dir);
|
||||
void port_write(port_t *obj, int value);
|
||||
int port_read (port_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
49
component/common/mbed/hal/pwmout_api.h
Normal file
49
component/common/mbed/hal/pwmout_api.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PWMOUT_API_H
|
||||
#define MBED_PWMOUT_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_PWMOUT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct pwmout_s pwmout_t;
|
||||
|
||||
void pwmout_init (pwmout_t* obj, PinName pin);
|
||||
void pwmout_free (pwmout_t* obj);
|
||||
|
||||
void pwmout_write (pwmout_t* obj, float percent);
|
||||
float pwmout_read (pwmout_t* obj);
|
||||
|
||||
void pwmout_period (pwmout_t* obj, float seconds);
|
||||
void pwmout_period_ms (pwmout_t* obj, int ms);
|
||||
void pwmout_period_us (pwmout_t* obj, int us);
|
||||
|
||||
void pwmout_pulsewidth (pwmout_t* obj, float seconds);
|
||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms);
|
||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
42
component/common/mbed/hal/rtc_api.h
Normal file
42
component/common/mbed/hal/rtc_api.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_RTC_API_H
|
||||
#define MBED_RTC_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_RTC
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void rtc_init(void);
|
||||
void rtc_free(void);
|
||||
int rtc_isenabled(void);
|
||||
|
||||
time_t rtc_read(void);
|
||||
void rtc_write(time_t t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
78
component/common/mbed/hal/serial_api.h
Normal file
78
component/common/mbed/hal/serial_api.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SERIAL_API_H
|
||||
#define MBED_SERIAL_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ParityNone = 0,
|
||||
ParityOdd = 1,
|
||||
ParityEven = 2,
|
||||
ParityForced1 = 3,
|
||||
ParityForced0 = 4
|
||||
} SerialParity;
|
||||
|
||||
typedef enum {
|
||||
RxIrq,
|
||||
TxIrq
|
||||
} SerialIrq;
|
||||
|
||||
typedef enum {
|
||||
FlowControlNone,
|
||||
FlowControlRTS,
|
||||
FlowControlCTS,
|
||||
FlowControlRTSCTS
|
||||
} FlowControl;
|
||||
|
||||
typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event);
|
||||
|
||||
typedef struct serial_s serial_t;
|
||||
|
||||
void serial_init (serial_t *obj, PinName tx, PinName rx);
|
||||
void serial_free (serial_t *obj);
|
||||
void serial_baud (serial_t *obj, int baudrate);
|
||||
void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
|
||||
|
||||
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);
|
||||
void serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable);
|
||||
|
||||
int serial_getc (serial_t *obj);
|
||||
void serial_putc (serial_t *obj, int c);
|
||||
int serial_readable (serial_t *obj);
|
||||
int serial_writable (serial_t *obj);
|
||||
void serial_clear (serial_t *obj);
|
||||
|
||||
void serial_break_set (serial_t *obj);
|
||||
void serial_break_clear(serial_t *obj);
|
||||
|
||||
void serial_pinout_tx(PinName tx);
|
||||
|
||||
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
64
component/common/mbed/hal/sleep_api.h
Normal file
64
component/common/mbed/hal/sleep_api.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SLEEP_API_H
|
||||
#define MBED_SLEEP_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SLEEP
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Send the microcontroller to sleep
|
||||
*
|
||||
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
|
||||
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
|
||||
* dynamic power used by the processor, memory systems and buses. The processor, peripheral and
|
||||
* memory state are maintained, and the peripherals continue to work and can generate interrupts.
|
||||
*
|
||||
* The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
|
||||
*
|
||||
* @note
|
||||
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
|
||||
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
|
||||
* able to access the LocalFileSystem
|
||||
*/
|
||||
void sleep(void);
|
||||
|
||||
/** Send the microcontroller to deep sleep
|
||||
*
|
||||
* This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode
|
||||
* has the same sleep features as sleep plus it powers down peripherals and clocks. All state
|
||||
* is still maintained.
|
||||
*
|
||||
* The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
|
||||
*
|
||||
* @note
|
||||
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
|
||||
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
|
||||
* able to access the LocalFileSystem
|
||||
*/
|
||||
void deepsleep(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
73
component/common/mbed/hal/spi_api.h
Normal file
73
component/common/mbed/hal/spi_api.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SPI_API_H
|
||||
#define MBED_SPI_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SPI_DMA_RX_EN (1<<0)
|
||||
#define SPI_DMA_TX_EN (1<<1)
|
||||
|
||||
//#define SPI_SCLK_IDLE_LOW 0 // the SCLK is Low when SPI is inactive
|
||||
//#define SPI_SCLK_IDLE_HIGH 2 // the SCLK is High when SPI is inactive
|
||||
enum {
|
||||
SPI_SCLK_IDLE_LOW=0, // the SCLK is Low when SPI is inactive
|
||||
SPI_SCLK_IDLE_HIGH=2 // the SCLK is High when SPI is inactive
|
||||
};
|
||||
|
||||
//#define SPI_CS_TOGGLE_EVERY_FRAME 0 // the CS toggle every frame
|
||||
//#define SPI_CS_TOGGLE_START_STOP 1 // the CS toggle at start and stop
|
||||
enum {
|
||||
SPI_CS_TOGGLE_EVERY_FRAME=0, // the CS toggle every frame
|
||||
SPI_CS_TOGGLE_START_STOP=1 // the CS toggle at start and stop
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
CS_0 = 0,
|
||||
CS_1 = 1,
|
||||
CS_2 = 2,
|
||||
CS_3 = 3,
|
||||
CS_4 = 4,
|
||||
CS_5 = 5,
|
||||
CS_6 = 6,
|
||||
CS_7 = 7
|
||||
}ChipSelect;
|
||||
|
||||
typedef struct spi_s spi_t;
|
||||
|
||||
void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel);
|
||||
void spi_free (spi_t *obj);
|
||||
void spi_format (spi_t *obj, int bits, int mode, int slave);
|
||||
void spi_frequency (spi_t *obj, int hz);
|
||||
int spi_master_write (spi_t *obj, int value);
|
||||
int spi_slave_receive(spi_t *obj);
|
||||
int spi_slave_read (spi_t *obj);
|
||||
void spi_slave_write (spi_t *obj, int value);
|
||||
int spi_busy (spi_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
51
component/common/mbed/hal/us_ticker_api.h
Normal file
51
component/common/mbed/hal/us_ticker_api.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_US_TICKER_API_H
|
||||
#define MBED_US_TICKER_API_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint64_t timestamp_t;
|
||||
|
||||
uint32_t us_ticker_read(void);
|
||||
|
||||
typedef void (*ticker_event_handler)(uint32_t id);
|
||||
void us_ticker_set_handler(ticker_event_handler handler);
|
||||
|
||||
typedef struct ticker_event_s {
|
||||
timestamp_t timestamp;
|
||||
uint32_t id;
|
||||
struct ticker_event_s *next;
|
||||
} ticker_event_t;
|
||||
|
||||
void us_ticker_init(void);
|
||||
void us_ticker_set_interrupt(timestamp_t timestamp);
|
||||
void us_ticker_disable_interrupt(void);
|
||||
void us_ticker_clear_interrupt(void);
|
||||
void us_ticker_irq_handler(void);
|
||||
|
||||
void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
|
||||
void us_ticker_remove_event(ticker_event_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
42
component/common/mbed/hal_ext/dma_api.h
Normal file
42
component/common/mbed/hal_ext/dma_api.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_GDMA_API_H
|
||||
#define MBED_GDMA_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct gdma_s {
|
||||
HAL_GDMA_OBJ gdma_obj;
|
||||
uint8_t gdma_allocated;
|
||||
};
|
||||
|
||||
typedef struct gdma_s gdma_t;
|
||||
|
||||
typedef void (*dma_irq_handler)(uint32_t id);
|
||||
|
||||
void dma_memcpy_init(gdma_t *dma_obj, dma_irq_handler handler, uint32_t id);
|
||||
void dma_memcpy_deinit(gdma_t *dma_obj);
|
||||
void dma_memcpy(gdma_t *dma_obj, void *dst, void* src, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // end of "#define MBED_GDMA_API_H"
|
45
component/common/mbed/hal_ext/flash_api.h
Normal file
45
component/common/mbed/hal_ext/flash_api.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, Realtek Semiconductor Corp.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef MBED_EXT_FLASH_API_EXT_H
|
||||
#define MBED_EXT_FLASH_API_EXT_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct flash_s flash_t;
|
||||
|
||||
/**
|
||||
* global data structure
|
||||
*/
|
||||
extern flash_t flash;
|
||||
|
||||
enum {
|
||||
FLASH_COMPLETE = 0,
|
||||
FLASH_ERROR_2 = 1,
|
||||
};
|
||||
|
||||
//void flash_init (flash_t *obj);
|
||||
void flash_erase_sector (flash_t *obj, uint32_t address);
|
||||
int flash_read_word (flash_t *obj, uint32_t address, uint32_t * data);
|
||||
int flash_write_word (flash_t *obj, uint32_t address, uint32_t data);
|
||||
int flash_stream_read (flash_t *obj, uint32_t address, uint32_t len, uint8_t * data);
|
||||
int flash_stream_write (flash_t *obj, uint32_t address, uint32_t len, uint8_t * data);
|
||||
void flash_write_protect (flash_t *obj, uint32_t protect);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
76
component/common/mbed/hal_ext/i2s_api.h
Normal file
76
component/common/mbed/hal_ext/i2s_api.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2015, Realtek Semiconductor Corp.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef MBED_EXT_I2S_API_EXT_H
|
||||
#define MBED_EXT_I2S_API_EXT_H
|
||||
|
||||
#include "device.h"
|
||||
#include "rtl8195a.h"
|
||||
#include "hal_i2s.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
SR_8KHZ = I2S_SR_8KHZ,
|
||||
SR_16KHZ = I2S_SR_16KHZ,
|
||||
SR_24KHZ = I2S_SR_24KHZ,
|
||||
SR_32KHZ = I2S_SR_32KHZ,
|
||||
SR_48KHZ = I2S_SR_48KHZ,
|
||||
SR_96KHZ = I2S_SR_96KHZ,
|
||||
SR_7p35KHZ = I2S_SR_7p35KHZ,
|
||||
SR_11p02KHZ = I2S_SR_11p02KHZ,
|
||||
SR_22p05KHZ = I2S_SR_22p05KHZ,
|
||||
SR_29p4KHZ = I2S_SR_29p4KHZ,
|
||||
SR_44p1KHZ = I2S_SR_44p1KHZ,
|
||||
SR_88p2KHZ = I2S_SR_88p2KHZ
|
||||
};
|
||||
|
||||
enum {
|
||||
CH_STEREO = I2S_CH_STEREO,
|
||||
CH_MONO = I2S_CH_MONO
|
||||
};
|
||||
|
||||
enum {
|
||||
WL_16b = I2S_WL_16,
|
||||
WL_24b = I2S_WL_24
|
||||
};
|
||||
|
||||
enum {
|
||||
I2S_DIR_RX = I2S_ONLY_RX, // Rx Only
|
||||
I2S_DIR_TX = I2S_ONLY_TX, // Tx Only
|
||||
I2S_DIR_TXRX = I2S_TXRX // Tx & Rx (BiDirection)
|
||||
};
|
||||
|
||||
typedef void (*i2s_irq_handler)(uint32_t id, char *pbuf);
|
||||
|
||||
typedef struct i2s_s i2s_t;
|
||||
|
||||
void i2s_init(i2s_t *obj, PinName sck, PinName ws, PinName sd);
|
||||
void i2s_set_dma_buffer(i2s_t *obj, char *tx_buf, char *rx_buf,
|
||||
uint32_t page_num, uint32_t page_size);
|
||||
void i2s_tx_irq_handler(i2s_t *obj, i2s_irq_handler handler, uint32_t id);
|
||||
void i2s_rx_irq_handler(i2s_t *obj, i2s_irq_handler handler, uint32_t id);
|
||||
void i2s_set_direction(i2s_t *obj, int trx_type);
|
||||
void i2s_set_param(i2s_t *obj, int channel_num, int rate, int word_len);
|
||||
void i2s_deinit(i2s_t *obj);
|
||||
int* i2s_get_tx_page(i2s_t *obj);
|
||||
void i2s_send_page(i2s_t *obj, uint32_t *pbuf);
|
||||
void i2s_recv_page(i2s_t *obj);
|
||||
void i2s_enable(i2s_t *obj);
|
||||
void i2s_disable(i2s_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
70
component/common/mbed/hal_ext/nfc_api.h
Normal file
70
component/common/mbed/hal_ext/nfc_api.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_NFC_API_H
|
||||
#define MBED_NFC_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NFCTAGLENGTH 36 // maximum 36*4=144 bytes
|
||||
#define NFC_MAX_CACHE_PAGE_NUM 36 // maximum 36*4=144 bytes
|
||||
|
||||
typedef enum _NFC_STATUS_ {
|
||||
NFC_OK = 0,
|
||||
NFC_ERROR = -1
|
||||
}NFC_STATUS, *PNFC_STATUS;
|
||||
|
||||
typedef enum _NFC_PWR_STATUS_ {
|
||||
NFC_PWR_DISABLE = 0,
|
||||
NFC_PWR_RUNNING = 1,
|
||||
NFC_PWR_SLEEP0 = 2,
|
||||
NFC_PWR_SLEEP1 = 3,
|
||||
NFC_PWR_DOWN = 4,
|
||||
NFC_PWR_ERROR = -1
|
||||
}NFC_PWR_STATUS, *PNFC_PWR_STATUS;
|
||||
|
||||
typedef enum _NFC_EVENT_ {
|
||||
NFC_EV_READER_PRESENT = (1<<0),
|
||||
NFC_EV_READ = (1<<1),
|
||||
NFC_EV_WRITE = (1<<2),
|
||||
NFC_EV_ERR = (1<<3),
|
||||
NFC_EV_CACHE_READ = (1<<4)
|
||||
}NFC_EVENT, *PNFC_EVENT;
|
||||
|
||||
typedef struct nfctag_s nfctag_t;
|
||||
|
||||
typedef void (*nfc_read_cb)(void *arg, void *buf, unsigned int page);
|
||||
typedef void(*nfc_write_cb)(void *arg, unsigned int page, uint32_t pgdat);
|
||||
typedef void(*nfc_event_cb)(void *arg, unsigned int event);
|
||||
typedef void(*nfc_cache_read_cb)(void *arg, void *buf, unsigned int page);
|
||||
|
||||
int nfc_init(nfctag_t *obj, uint32_t *pg_init_val);
|
||||
void nfc_read(nfctag_t *obj, nfc_read_cb handler, void *arg);
|
||||
void nfc_write(nfctag_t *obj, nfc_write_cb handler, void *arg);
|
||||
void nfc_event(nfctag_t *obj, nfc_event_cb handler, void *arg, unsigned int event_mask);
|
||||
int nfc_power(nfctag_t *obj, int pwr_mode, int wake_event);
|
||||
int nfc_cache_write(nfctag_t *obj, uint32_t *tbuf, unsigned int spage, unsigned int pg_num);
|
||||
int nfc_cache_raed(nfctag_t *obj, nfc_cache_read_cb handler, void *arg, unsigned int start_pg);
|
||||
int nfc_status(nfctag_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
42
component/common/mbed/hal_ext/serial_ex_api.h
Normal file
42
component/common/mbed/hal_ext/serial_ex_api.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SERIAL_EX_API_H
|
||||
#define MBED_SERIAL_EX_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void serial_send_comp_handler(serial_t *obj, void *handler, uint32_t id);
|
||||
void serial_recv_comp_handler(serial_t *obj, void *handler, uint32_t id);
|
||||
int32_t serial_recv_stream (serial_t *obj, char *prxbuf, uint32_t len);
|
||||
int32_t serial_send_stream (serial_t *obj, char *ptxbuf, uint32_t len);
|
||||
int32_t serial_recv_stream_dma (serial_t *obj, char *prxbuf, uint32_t len);
|
||||
int32_t serial_send_stream_dma (serial_t *obj, char *ptxbuf, uint32_t len);
|
||||
int32_t serial_send_stream_abort (serial_t *obj);
|
||||
int32_t serial_recv_stream_abort (serial_t *obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef MBED_SERIAL_EX_API_H
|
97
component/common/mbed/hal_ext/sleep_ex_api.h
Normal file
97
component/common/mbed/hal_ext/sleep_ex_api.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SLEEP_EX_API_H
|
||||
#define MBED_SLEEP_EX_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SLEEP
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Sleep Eake Up event, the User application also
|
||||
need to config the peripheral to trigger wake up event */
|
||||
#define SLEEP_WAKEUP_BY_STIMER (SLP_STIMER) // wake up by system timer
|
||||
#define SLEEP_WAKEUP_BY_GTIMER (SLP_GTIMER) // wake up by General purpose timer timeout
|
||||
#define SLEEP_WAKEUP_BY_GPIO_INT (SLP_GPIO) // wake up by GPIO Port A[7:0] Interrupt
|
||||
#define SLEEP_WAKEUP_BY_WLAN (SLP_WL) // wake up by WLan event
|
||||
#define SLEEP_WAKEUP_BY_NFC (SLP_NFC) // wake up by NFC event
|
||||
#define SLEEP_WAKEUP_BY_SDIO (SLP_SDIO) // wake up by SDIO event
|
||||
#define SLEEP_WAKEUP_BY_USB (SLP_USB) // wake up by USB event
|
||||
|
||||
// Deep Standby Wakeup event
|
||||
#define STANDBY_WAKEUP_BY_STIMER (BIT0) // wake up by system timer
|
||||
#define STANDBY_WAKEUP_BY_NFC (BIT1) // wake up by NFC event
|
||||
//#define SLEEP_WAKEUP_BY_DS_TIMER (BIT2) // The timer to wakeup from Deep Sleep timer
|
||||
// Do not modify these definition, or need to modify the code also.
|
||||
#define STANDBY_WAKEUP_BY_PA5 (BIT4) // GPIO Port A[5]
|
||||
#define STANDBY_WAKEUP_BY_PC7 (BIT5) // GPIO Port C[7]
|
||||
#define STANDBY_WAKEUP_BY_PD5 (BIT6) // GPIO Port D[5]
|
||||
#define STANDBY_WAKEUP_BY_PE3 (BIT7) // GPIO Port E[3]
|
||||
|
||||
// Deep Sleep Wakeup event
|
||||
#define DSLEEP_WAKEUP_BY_TIMER (DS_TIMER33)
|
||||
#define DSLEEP_WAKEUP_BY_GPIO (DS_GPIO) // GPIO Port B[1]
|
||||
|
||||
typedef struct _SLEEP_WKUP_EVENT_ {
|
||||
u8 wakeup_event; // Wake up event: Timer, NFC, GPIO
|
||||
u8 gpio_option; // GPIO Wakeup setting: [3:0]: Pin 3~0 enable, [7:4]: pin3~0 active high/low
|
||||
u32 timer_duration; // the sleep duration and then wakeup
|
||||
} SLEEP_WAKEUP_EVENT, *PSLEEP_WAKEUP_EVENT;
|
||||
/** Send the microcontroller to sleep
|
||||
*
|
||||
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
|
||||
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
|
||||
* dynamic power used by the processor, memory systems and buses. The processor, peripheral and
|
||||
* memory state are maintained, and the peripherals continue to work and can generate interrupts.
|
||||
*
|
||||
* The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
|
||||
*
|
||||
* @note
|
||||
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
|
||||
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
|
||||
* able to access the LocalFileSystem
|
||||
*/
|
||||
void sleep_ex(uint32_t wakeup_event, uint32_t sleep_duration);
|
||||
|
||||
void standby_wakeup_event_add(uint32_t wakeup_event, uint32_t sleep_duration_ms, uint32_t gpio_active);
|
||||
void standby_wakeup_event_del(uint32_t wakeup_event);
|
||||
void deepstandby_ex(void);
|
||||
|
||||
/** Send the microcontroller to deep sleep
|
||||
*
|
||||
* This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode
|
||||
* has the same sleep features as sleep plus it powers down peripherals and clocks. All state
|
||||
* is still maintained.
|
||||
*
|
||||
* The processor can only be woken up by an external interrupt on a pin or a timer.
|
||||
*
|
||||
* @note
|
||||
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
|
||||
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
|
||||
* able to access the LocalFileSystem
|
||||
*/
|
||||
void deepsleep_ex(uint32_t wakeup_event, uint32_t sleep_duration);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
58
component/common/mbed/hal_ext/spi_ex_api.h
Normal file
58
component/common/mbed/hal_ext/spi_ex_api.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SPI_EXT_API_H
|
||||
#define MBED_SPI_EXT_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SPI_STATE_READY 0x00
|
||||
#define SPI_STATE_RX_BUSY (1<<1)
|
||||
#define SPI_STATE_TX_BUSY (1<<2)
|
||||
|
||||
typedef enum {
|
||||
SpiRxIrq,
|
||||
SpiTxIrq
|
||||
} SpiIrq;
|
||||
|
||||
typedef void (*spi_irq_handler)(uint32_t id, SpiIrq event);
|
||||
|
||||
void spi_irq_hook(spi_t *obj, spi_irq_handler handler, uint32_t id);
|
||||
int32_t spi_slave_read_stream(spi_t *obj, char *rx_buffer, uint32_t length);
|
||||
int32_t spi_slave_write_stream(spi_t *obj, char *tx_buffer, uint32_t length);
|
||||
int32_t spi_master_read_stream(spi_t *obj, char *rx_buffer, uint32_t length);
|
||||
int32_t spi_master_write_stream(spi_t *obj, char *tx_buffer, uint32_t length);
|
||||
int32_t spi_master_write_read_stream(spi_t *obj, char *tx_buffer,
|
||||
char *rx_buffer, uint32_t length);
|
||||
#ifdef CONFIG_GDMA_EN
|
||||
int32_t spi_slave_read_stream_dma(spi_t *obj, char *rx_buffer, uint32_t length);
|
||||
int32_t spi_slave_write_stream_dma(spi_t *obj, char *tx_buffer, uint32_t length);
|
||||
int32_t spi_master_read_stream_dma(spi_t *obj, char *rx_buffer, uint32_t length);
|
||||
int32_t spi_master_write_stream_dma(spi_t *obj, char *tx_buffer, uint32_t length);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
50
component/common/mbed/hal_ext/sys_api.h
Normal file
50
component/common/mbed/hal_ext/sys_api.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_WATCHDOG_API_H
|
||||
#define MBED_WATCHDOG_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Turn off the JTAG function
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*/
|
||||
void sys_jtag_off(void);
|
||||
void sys_clear_ota_signature(void);
|
||||
void sys_recover_ota_signature(void);
|
||||
void sys_log_uart_on(void);
|
||||
void sys_log_uart_off(void);
|
||||
void sys_adc_calibration(u8 write, u16 *offset, u16 *gain);
|
||||
|
||||
/**
|
||||
* @brief system software reset
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*/
|
||||
void sys_reset(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
61
component/common/mbed/hal_ext/wdt_api.h
Normal file
61
component/common/mbed/hal_ext/wdt_api.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_WATCHDOG_API_H
|
||||
#define MBED_WATCHDOG_API_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*wdt_irq_handler)(uint32_t id);
|
||||
|
||||
/** Initial the watch dog time setting
|
||||
*
|
||||
* This function will initial and enable the watchdog timer with a given timeout value.
|
||||
* When the watchdog timer timeout event is triggered, the system will be reset. User also can
|
||||
* register a callback function to handle the watchdog timer timeout event.
|
||||
*/
|
||||
void watchdog_init(uint32_t timeout_ms);
|
||||
|
||||
/** Start the watchdog counting
|
||||
*
|
||||
* This function will active the watchdog timer down counting. When the watchdog timer count down
|
||||
* to 0, a callback function will be called or the system will be reset.
|
||||
*/
|
||||
void watchdog_start(void);
|
||||
|
||||
/** Stop the watchdog counting
|
||||
*
|
||||
* This function will stop the watchdog timer down counting. If a user application aware a
|
||||
* procedure may takes too long and cause the watchdog timer timeout, the application use this
|
||||
* function to stop the watchdog timer to prevent the watchdog timer timeout.
|
||||
*/
|
||||
void watchdog_stop(void);
|
||||
|
||||
/** Refresh the watchdog counting
|
||||
*
|
||||
* This function will reload the watchdog timer counting value. Usually a application do the watchdog
|
||||
* timer reflash in the main loop to prevent the watchdog timer timeout.
|
||||
*/
|
||||
void watchdog_refresh(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
14
component/common/mbed/targets/cmsis/rtl8195a
Normal file
14
component/common/mbed/targets/cmsis/rtl8195a
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* mbed Microcontroller Library - CMSIS
|
||||
* Copyright (C) 2009-2011 ARM Limited. All rights reserved.
|
||||
*
|
||||
* A generic CMSIS include header, pulling in RTL8195A specifics
|
||||
*/
|
||||
|
||||
#ifndef MBED_CMSIS_H
|
||||
#define MBED_CMSIS_H
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <hal_platform.h>
|
||||
|
||||
#endif
|
||||
|
94
component/common/mbed/targets/hal/rtl8195a/PeripheralNames.h
Normal file
94
component/common/mbed/targets/hal/rtl8195a/PeripheralNames.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PERIPHERALNAMES_H
|
||||
#define MBED_PERIPHERALNAMES_H
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
typedef enum {
|
||||
UART_1 = (int)USART1_BASE,
|
||||
UART_2 = (int)USART2_BASE,
|
||||
UART_3 = (int)USART3_BASE,
|
||||
UART_4 = (int)UART4_BASE,
|
||||
UART_5 = (int)UART5_BASE,
|
||||
UART_6 = (int)USART6_BASE
|
||||
} UARTName;
|
||||
|
||||
typedef enum {
|
||||
ADC0_0 = 0,
|
||||
ADC0_1,
|
||||
ADC0_2,
|
||||
ADC0_3,
|
||||
ADC0_4,
|
||||
ADC0_5,
|
||||
ADC0_6,
|
||||
ADC0_7,
|
||||
ADC0_8,
|
||||
ADC0_9,
|
||||
ADC0_10,
|
||||
ADC0_11,
|
||||
ADC0_12,
|
||||
ADC0_13,
|
||||
ADC0_14,
|
||||
ADC0_15
|
||||
} ADCName;
|
||||
|
||||
typedef enum {
|
||||
DAC_0 = 0,
|
||||
DAC_1
|
||||
} DACName;
|
||||
|
||||
typedef enum {
|
||||
SPI_1 = (int)SPI1_BASE,
|
||||
SPI_2 = (int)SPI2_BASE,
|
||||
SPI_3 = (int)SPI3_BASE,
|
||||
} SPIName;
|
||||
|
||||
typedef enum {
|
||||
I2C_1 = (int)I2C1_BASE,
|
||||
I2C_2 = (int)I2C2_BASE,
|
||||
I2C_3 = (int)I2C3_BASE
|
||||
} I2CName;
|
||||
|
||||
typedef enum {
|
||||
PWM_1 = 1,
|
||||
PWM_2,
|
||||
PWM_3,
|
||||
PWM_4,
|
||||
PWM_5,
|
||||
PWM_6
|
||||
} PWMName;
|
||||
|
||||
typedef enum {
|
||||
CAN_1 = (int)CAN1_BASE,
|
||||
CAN_2 = (int)CAN2_BASE
|
||||
} CANName;
|
||||
#endif
|
||||
|
||||
#define STDIO_UART_TX PA_6
|
||||
#define STDIO_UART_RX PA_7
|
||||
#define STDIO_UART UART0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
212
component/common/mbed/targets/hal/rtl8195a/PinNames.h
Normal file
212
component/common/mbed/targets/hal/rtl8195a/PinNames.h
Normal file
|
@ -0,0 +1,212 @@
|
|||
|
||||
#ifndef _PINNAMES_H_
|
||||
#define _PINNAMES_H_
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
PORT_A = 0,
|
||||
PORT_B = 1,
|
||||
PORT_C = 2,
|
||||
PORT_D = 3,
|
||||
PORT_E = 4,
|
||||
PORT_F = 5,
|
||||
PORT_G = 6,
|
||||
PORT_H = 7,
|
||||
PORT_I = 8,
|
||||
PORT_J = 9,
|
||||
PORT_K = 10,
|
||||
|
||||
PORT_V = 11,
|
||||
PORT_MAX
|
||||
} GPIO_PORT;
|
||||
|
||||
#define RTL_PIN_PERI(FUN, IDX, SEL) ((int)(((FUN) << 8) | ((IDX)<<4) | (SEL)))
|
||||
#define RTL_PIN_FUNC(FUN, SEL) ((int)(((FUN) << 7) | (SEL)))
|
||||
#define RTL_GET_PERI_SEL(peri) ((int)((peri)&0x0F))
|
||||
#define RTL_GET_PERI_IDX(peri) ((int)(((peri) >> 4)&0x0F))
|
||||
|
||||
typedef enum {
|
||||
PIN_INPUT=0,
|
||||
PIN_OUTPUT
|
||||
} PinDirection;
|
||||
|
||||
typedef enum {
|
||||
PA_0 = (PORT_A<<4|0),
|
||||
PA_1 = (PORT_A<<4|1),
|
||||
PA_2 = (PORT_A<<4|2),
|
||||
PA_3 = (PORT_A<<4|3),
|
||||
PA_4 = (PORT_A<<4|4),
|
||||
PA_5 = (PORT_A<<4|5),
|
||||
PA_6 = (PORT_A<<4|6),
|
||||
PA_7 = (PORT_A<<4|7),
|
||||
|
||||
PB_0 = (PORT_B<<4|0),
|
||||
PB_1 = (PORT_B<<4|1),
|
||||
PB_2 = (PORT_B<<4|2),
|
||||
PB_3 = (PORT_B<<4|3),
|
||||
PB_4 = (PORT_B<<4|4),
|
||||
PB_5 = (PORT_B<<4|5),
|
||||
PB_6 = (PORT_B<<4|6),
|
||||
PB_7 = (PORT_B<<4|7),
|
||||
|
||||
PC_0 = (PORT_C<<4|0),
|
||||
PC_1 = (PORT_C<<4|1),
|
||||
PC_2 = (PORT_C<<4|2),
|
||||
PC_3 = (PORT_C<<4|3),
|
||||
PC_4 = (PORT_C<<4|4),
|
||||
PC_5 = (PORT_C<<4|5),
|
||||
PC_6 = (PORT_C<<4|6),
|
||||
PC_7 = (PORT_C<<4|7),
|
||||
PC_8 = (PORT_C<<4|8),
|
||||
PC_9 = (PORT_C<<4|9),
|
||||
|
||||
PD_0 = (PORT_D<<4|0),
|
||||
PD_1 = (PORT_D<<4|1),
|
||||
PD_2 = (PORT_D<<4|2),
|
||||
PD_3 = (PORT_D<<4|3),
|
||||
PD_4 = (PORT_D<<4|4),
|
||||
PD_5 = (PORT_D<<4|5),
|
||||
PD_6 = (PORT_D<<4|6),
|
||||
PD_7 = (PORT_D<<4|7),
|
||||
PD_8 = (PORT_D<<4|8),
|
||||
PD_9 = (PORT_D<<4|9),
|
||||
|
||||
PE_0 = (PORT_E<<4|0),
|
||||
PE_1 = (PORT_E<<4|1),
|
||||
PE_2 = (PORT_E<<4|2),
|
||||
PE_3 = (PORT_E<<4|3),
|
||||
PE_4 = (PORT_E<<4|4),
|
||||
PE_5 = (PORT_E<<4|5),
|
||||
PE_6 = (PORT_E<<4|6),
|
||||
PE_7 = (PORT_E<<4|7),
|
||||
PE_8 = (PORT_E<<4|8),
|
||||
PE_9 = (PORT_E<<4|9),
|
||||
PE_A = (PORT_E<<4|10),
|
||||
|
||||
PF_0 = (PORT_F<<4|0),
|
||||
PF_1 = (PORT_F<<4|1),
|
||||
PF_2 = (PORT_F<<4|2),
|
||||
PF_3 = (PORT_F<<4|3),
|
||||
PF_4 = (PORT_F<<4|4),
|
||||
PF_5 = (PORT_F<<4|5),
|
||||
// PF_6 = (PORT_F<<4|6),
|
||||
// PF_7 = (PORT_F<<4|7),
|
||||
|
||||
PG_0 = (PORT_G<<4|0),
|
||||
PG_1 = (PORT_G<<4|1),
|
||||
PG_2 = (PORT_G<<4|2),
|
||||
PG_3 = (PORT_G<<4|3),
|
||||
PG_4 = (PORT_G<<4|4),
|
||||
PG_5 = (PORT_G<<4|5),
|
||||
PG_6 = (PORT_G<<4|6),
|
||||
PG_7 = (PORT_G<<4|7),
|
||||
|
||||
PH_0 = (PORT_H<<4|0),
|
||||
PH_1 = (PORT_H<<4|1),
|
||||
PH_2 = (PORT_H<<4|2),
|
||||
PH_3 = (PORT_H<<4|3),
|
||||
PH_4 = (PORT_H<<4|4),
|
||||
PH_5 = (PORT_H<<4|5),
|
||||
PH_6 = (PORT_H<<4|6),
|
||||
PH_7 = (PORT_H<<4|7),
|
||||
|
||||
PI_0 = (PORT_I<<4|0),
|
||||
PI_1 = (PORT_I<<4|1),
|
||||
PI_2 = (PORT_I<<4|2),
|
||||
PI_3 = (PORT_I<<4|3),
|
||||
PI_4 = (PORT_I<<4|4),
|
||||
PI_5 = (PORT_I<<4|5),
|
||||
PI_6 = (PORT_I<<4|6),
|
||||
PI_7 = (PORT_I<<4|7),
|
||||
|
||||
PJ_0 = (PORT_J<<4|0),
|
||||
PJ_1 = (PORT_J<<4|1),
|
||||
PJ_2 = (PORT_J<<4|2),
|
||||
PJ_3 = (PORT_J<<4|3),
|
||||
PJ_4 = (PORT_J<<4|4),
|
||||
PJ_5 = (PORT_J<<4|5),
|
||||
PJ_6 = (PORT_J<<4|6),
|
||||
// PJ_7 = (PORT_J<<4|7),
|
||||
|
||||
PK_0 = (PORT_K<<4|0),
|
||||
PK_1 = (PORT_K<<4|1),
|
||||
PK_2 = (PORT_K<<4|2),
|
||||
PK_3 = (PORT_K<<4|3),
|
||||
PK_4 = (PORT_K<<4|4),
|
||||
PK_5 = (PORT_K<<4|5),
|
||||
PK_6 = (PORT_K<<4|6),
|
||||
// PK_7 = (PORT_K<<4|7),
|
||||
|
||||
AD_1 = (PORT_V<<4|1),
|
||||
AD_2 = (PORT_V<<4|2),
|
||||
AD_3 = (PORT_V<<4|3),
|
||||
|
||||
// Arduino connector namings
|
||||
/*
|
||||
A0 = PA_0,
|
||||
A1 = PA_1,
|
||||
A2 = PA_4,
|
||||
A3 = PB_0,
|
||||
A4 = PC_1,
|
||||
A5 = PC_0,
|
||||
D0 = PA_3,
|
||||
D1 = PA_2,
|
||||
D2 = PA_10,
|
||||
D3 = PB_3,
|
||||
D4 = PB_5,
|
||||
D5 = PB_4,
|
||||
D6 = PB_10,
|
||||
D7 = PA_8,
|
||||
D8 = PA_9,
|
||||
D9 = PC_7,
|
||||
D10 = PB_6,
|
||||
D11 = PA_7,
|
||||
D12 = PA_6,
|
||||
D13 = PA_5,
|
||||
D14 = PB_9,
|
||||
D15 = PB_8,
|
||||
*/
|
||||
|
||||
// Generic signals namings
|
||||
LED1 = PB_4,
|
||||
LED2 = PB_5,
|
||||
LED3 = PB_6,
|
||||
LED4 = PB_7,
|
||||
USER_BUTTON = PA_3,
|
||||
SERIAL_TX = PA_7,
|
||||
SERIAL_RX = PA_6,
|
||||
USBTX = PA_7,
|
||||
USBRX = PA_6,
|
||||
I2C_SCL = PC_5,
|
||||
I2C_SDA = PC_4,
|
||||
SPI_MOSI = PC_2,
|
||||
SPI_MISO = PC_3,
|
||||
SPI_SCK = PC_1,
|
||||
SPI_CS = PC_0,
|
||||
PWM_OUT = PD_4,
|
||||
|
||||
// Not connected
|
||||
NC = (uint32_t)0xFFFFFFFF
|
||||
} PinName;
|
||||
|
||||
typedef enum {
|
||||
PullNone = 0,
|
||||
PullUp = 1,
|
||||
PullDown = 2,
|
||||
OpenDrain = 3,
|
||||
PullDefault = PullNone
|
||||
} PinMode;
|
||||
|
||||
#define PORT_NUM(pin) (((uint32_t)(pin) >> 4) & 0xF)
|
||||
#define PIN_NUM(pin) ((uint32_t)(pin) & 0xF)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
38
component/common/mbed/targets/hal/rtl8195a/PortNames.h
Normal file
38
component/common/mbed/targets/hal/rtl8195a/PortNames.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PORTNAMES_H
|
||||
#define MBED_PORTNAMES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
PortA = 0,
|
||||
PortB = 1,
|
||||
PortC = 2,
|
||||
PortD = 3,
|
||||
PortE = 4,
|
||||
PortF = 5,
|
||||
PortG = 6,
|
||||
PortH = 7,
|
||||
PortI = 8
|
||||
} PortName;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue