forked from xuos/xiuos
support adapter_ethernet and hfa21 device
This commit is contained in:
parent
3f13410d96
commit
7b82f2a60b
|
@ -19,6 +19,7 @@ extern int AdapterFrameworkInit(void);
|
||||||
extern int Adapter4GInit(void);
|
extern int Adapter4GInit(void);
|
||||||
extern int AdapterBlueToothInit(void);
|
extern int AdapterBlueToothInit(void);
|
||||||
extern int AdapterWifiInit(void);
|
extern int AdapterWifiInit(void);
|
||||||
|
extern int AdapterEthernetInit(void);
|
||||||
extern int AdapterZigbeeInit(void);
|
extern int AdapterZigbeeInit(void);
|
||||||
|
|
||||||
extern int D124VoiceInit(void);
|
extern int D124VoiceInit(void);
|
||||||
|
@ -92,16 +93,19 @@ static struct InitDesc sensor_desc[] =
|
||||||
static struct InitDesc connection_desc[] =
|
static struct InitDesc connection_desc[] =
|
||||||
{
|
{
|
||||||
#ifdef CONNECTION_ADAPTER_4G
|
#ifdef CONNECTION_ADAPTER_4G
|
||||||
{ "4G adpter", Adapter4GInit},
|
{ "4G adapter", Adapter4GInit},
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
||||||
{ "zigbee adpter", AdapterZigbeeInit},
|
{ "zigbee adapter", AdapterZigbeeInit},
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONNECTION_ADAPTER_BLUETOOTH
|
#ifdef CONNECTION_ADAPTER_BLUETOOTH
|
||||||
{ "BlueTooth adpter", AdapterBlueToothInit},
|
{ "bluetooth adapter", AdapterBlueToothInit},
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONNECTION_ADAPTER_WIFI
|
#ifdef CONNECTION_ADAPTER_WIFI
|
||||||
{ "Wifi adpter", AdapterWifiInit},
|
{ "wifi adapter", AdapterWifiInit},
|
||||||
|
#endif
|
||||||
|
#ifdef CONNECTION_ADAPTER_ETHERNET
|
||||||
|
{ "ethernet adapter", AdapterEthernetInit},
|
||||||
#endif
|
#endif
|
||||||
{ "NULL", NULL },
|
{ "NULL", NULL },
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,10 +117,10 @@ int ParseATReply(char *str, const char *format, ...)
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 ATSprintf(int fd, const char *format, va_list params)
|
void ATSprintf(int fd, const char *format, va_list params)
|
||||||
{
|
{
|
||||||
last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params);
|
last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params);
|
||||||
printf("ATSprintf send %s len %u\n",send_buf, last_cmd_len);
|
printf("AT send %s len %u\n",send_buf, last_cmd_len);
|
||||||
PrivWrite(fd, send_buf, last_cmd_len);
|
PrivWrite(fd, send_buf, last_cmd_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
||||||
{
|
{
|
||||||
if (agent == NULL) {
|
if (agent == NULL) {
|
||||||
printf("ATAgent is null");
|
printf("ATAgent is null");
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec abstime;
|
struct timespec abstime;
|
||||||
|
@ -145,7 +145,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
||||||
|
|
||||||
va_list params;
|
va_list params;
|
||||||
uint32 cmd_size = 0;
|
uint32 cmd_size = 0;
|
||||||
uint32 result = EOK;
|
uint32 result = 0;
|
||||||
const char *cmd = NULL;
|
const char *cmd = NULL;
|
||||||
PrivMutexObtain(&agent->lock);
|
PrivMutexObtain(&agent->lock);
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
||||||
va_start(params, cmd_expr);
|
va_start(params, cmd_expr);
|
||||||
ATSprintf(agent->fd, cmd_expr, params);
|
ATSprintf(agent->fd, cmd_expr, params);
|
||||||
va_end(params);
|
va_end(params);
|
||||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != EOK) {
|
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != 0) {
|
||||||
result = -ETIMEOUT;
|
result = -ETIMEOUT;
|
||||||
goto __out;
|
goto __out;
|
||||||
}
|
}
|
||||||
|
@ -220,35 +220,35 @@ char *GetReplyText(ATReplyType reply)
|
||||||
int AtSetReplyLrEnd(ATAgentType agent, char enable)
|
int AtSetReplyLrEnd(ATAgentType agent, char enable)
|
||||||
{
|
{
|
||||||
if (!agent) {
|
if (!agent) {
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
agent->reply_lr_end = enable;
|
agent->reply_lr_end = enable;
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch)
|
int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch)
|
||||||
{
|
{
|
||||||
if (!agent) {
|
if (!agent) {
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
agent->reply_end_last_char = last_ch;
|
agent->reply_end_last_char = last_ch;
|
||||||
agent->reply_end_char = end_ch;
|
agent->reply_end_char = end_ch;
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AtSetReplyCharNum(ATAgentType agent, unsigned int num)
|
int AtSetReplyCharNum(ATAgentType agent, unsigned int num)
|
||||||
{
|
{
|
||||||
if (!agent) {
|
if (!agent) {
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
agent->reply_char_num = num;
|
agent->reply_char_num = num;
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EntmSend(ATAgentType agent, const char *data, int len)
|
int EntmSend(ATAgentType agent, const char *data, int len)
|
||||||
|
@ -262,7 +262,7 @@ int EntmSend(ATAgentType agent, const char *data, int len)
|
||||||
|
|
||||||
PrivWrite(agent->fd, send_buf, len + 2);
|
PrivWrite(agent->fd, send_buf, len + 2);
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||||
|
@ -276,13 +276,13 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||||
PrivTaskDelay(1000);
|
PrivTaskDelay(1000);
|
||||||
|
|
||||||
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivMutexObtain(&agent->lock);
|
PrivMutexObtain(&agent->lock);
|
||||||
|
|
||||||
if (buffer_len < agent->entm_recv_len) {
|
if (buffer_len < agent->entm_recv_len) {
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("EntmRecv once len %u.\n", agent->entm_recv_len);
|
printf("EntmRecv once len %u.\n", agent->entm_recv_len);
|
||||||
|
@ -295,7 +295,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||||
|
|
||||||
PrivMutexAbandon(&agent->lock);
|
PrivMutexAbandon(&agent->lock);
|
||||||
|
|
||||||
return EOK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetCompleteATReply(ATAgentType agent)
|
static int GetCompleteATReply(ATAgentType agent)
|
||||||
|
@ -347,7 +347,7 @@ static int GetCompleteATReply(ATAgentType agent)
|
||||||
printf("read line failed. The line data length is out of buffer size(%d)!", agent->maintain_max);
|
printf("read line failed. The line data length is out of buffer size(%d)!", agent->maintain_max);
|
||||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||||
agent->maintain_len = 0;
|
agent->maintain_len = 0;
|
||||||
return -ERROR;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("GetCompleteATReply done\n");
|
printf("GetCompleteATReply done\n");
|
||||||
break;
|
break;
|
||||||
|
@ -371,7 +371,6 @@ ATAgentType GetATAgent(const char *agent_name)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int DeleteATAgent(ATAgentType agent)
|
static int DeleteATAgent(ATAgentType agent)
|
||||||
{
|
{
|
||||||
if (agent->lock) {
|
if (agent->lock) {
|
||||||
|
@ -426,13 +425,12 @@ static void *ATAgentReceiveProcess(void *param)
|
||||||
|
|
||||||
static int ATAgentInit(ATAgentType agent)
|
static int ATAgentInit(ATAgentType agent)
|
||||||
{
|
{
|
||||||
int result = EOK;
|
int result = 0;
|
||||||
UtaskType at_utask;
|
|
||||||
|
|
||||||
agent->maintain_len = 0;
|
agent->maintain_len = 0;
|
||||||
agent->maintain_buffer = (char *)PrivMalloc(agent->maintain_max);
|
agent->maintain_buffer = (char *)PrivMalloc(agent->maintain_max);
|
||||||
|
|
||||||
if (agent->maintain_buffer == NONE) {
|
if (agent->maintain_buffer == NULL) {
|
||||||
printf("ATAgentInit malloc maintain_buffer error\n");
|
printf("ATAgentInit malloc maintain_buffer error\n");
|
||||||
goto __out;
|
goto __out;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +466,7 @@ static int ATAgentInit(ATAgentType agent)
|
||||||
|
|
||||||
__out:
|
__out:
|
||||||
DeleteATAgent(agent);
|
DeleteATAgent(agent);
|
||||||
result = -ERROR;
|
result = -1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -476,9 +474,9 @@ __out:
|
||||||
int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int result = EOK;
|
int result = 0;
|
||||||
int open_result = EOK;
|
int open_result = 0;
|
||||||
struct ATAgent *agent = NONE;
|
struct ATAgent *agent = NULL;
|
||||||
|
|
||||||
if (GetATAgent(agent_name) != NULL) {
|
if (GetATAgent(agent_name) != NULL) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -490,7 +488,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||||
|
|
||||||
if (i >= AT_AGENT_MAX) {
|
if (i >= AT_AGENT_MAX) {
|
||||||
printf("agent buffer(%d) is full.", AT_AGENT_MAX);
|
printf("agent buffer(%d) is full.", AT_AGENT_MAX);
|
||||||
result = -ERROR;
|
result = -1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,7 +501,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||||
agent->maintain_max = maintain_max;
|
agent->maintain_max = maintain_max;
|
||||||
|
|
||||||
result = ATAgentInit(agent);
|
result = ATAgentInit(agent);
|
||||||
if (result == EOK) {
|
if (result == 0) {
|
||||||
PrivTaskStartup(&agent->at_handler);
|
PrivTaskStartup(&agent->at_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
config ADAPTER_HFA21_ETHERNET
|
||||||
|
help
|
||||||
|
Please check HFA21 can only work for adapter_wifi or adapter_ethernet in the meantime!
|
||||||
|
bool "Using ethernet adapter device HFA21"
|
||||||
|
default n
|
||||||
|
|
||||||
|
if ADAPTER_HFA21_ETHERNET
|
||||||
|
source "$APP_DIR/Framework/connection/ethernet/hfa21_ethernet/Kconfig"
|
||||||
|
endif
|
|
@ -1,3 +1,7 @@
|
||||||
SRC_FILES := adapter_ethernet.c
|
SRC_FILES := adapter_ethernet.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ADAPTER_HFA21_ETHERNET),y)
|
||||||
|
SRC_DIR += hfa21_ethernet
|
||||||
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -15,5 +15,112 @@
|
||||||
* @brief Implement the connection ethernet adapter function
|
* @brief Implement the connection ethernet adapter function
|
||||||
* @version 1.1
|
* @version 1.1
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2021.06.25
|
* @date 2021.10.15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <adapter.h>
|
||||||
|
|
||||||
|
#ifdef ADAPTER_HFA21_ETHERNET
|
||||||
|
extern AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ADAPTER_ETHERNET_NAME "ethernet"
|
||||||
|
|
||||||
|
static int AdapterEthernetRegister(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
strncpy(adapter->name, ADAPTER_ETHERNET_NAME, NAME_NUM_MAX);
|
||||||
|
|
||||||
|
adapter->net_protocol = IP_PROTOCOL;
|
||||||
|
adapter->adapter_status = UNREGISTERED;
|
||||||
|
|
||||||
|
ret = AdapterDeviceRegister(adapter);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("AdapterEthernet register error\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AdapterEthernetInit(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||||
|
if (!adapter) {
|
||||||
|
printf("AdapterEthernetInit malloc error\n");
|
||||||
|
free(adapter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(adapter, 0, sizeof(struct Adapter));
|
||||||
|
|
||||||
|
ret = AdapterEthernetRegister(adapter);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("AdapterEthernetInit register ethernet adapter error\n");
|
||||||
|
free(adapter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ADAPTER_HFA21_ETHERNET
|
||||||
|
AdapterProductInfoType product_info = Hfa21EthernetAttach(adapter);
|
||||||
|
if (!product_info) {
|
||||||
|
printf("AdapterEthernetInit hfa21 attach error\n");
|
||||||
|
free(adapter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter->product_info_flag = 1;
|
||||||
|
adapter->info = product_info;
|
||||||
|
adapter->done = product_info->model_done;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************ethernet TEST*********************/
|
||||||
|
int AdapterEthernetTest(void)
|
||||||
|
{
|
||||||
|
int baud_rate = BAUD_RATE_57600;
|
||||||
|
|
||||||
|
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_ETHERNET_NAME);
|
||||||
|
|
||||||
|
#ifdef ADAPTER_HFA21_ETHERNET
|
||||||
|
|
||||||
|
char ethernet_recv_msg[128] = {0};
|
||||||
|
int i, len = 0;
|
||||||
|
const char *ethernet_msg = "Adapter Ethernet Test";
|
||||||
|
|
||||||
|
AdapterDeviceOpen(adapter);
|
||||||
|
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||||
|
|
||||||
|
AdapterDeviceSetUp(adapter);
|
||||||
|
|
||||||
|
const char *ip = "10.10.100.50";
|
||||||
|
const char *port = "12345";
|
||||||
|
enum NetRoleType net_role = SERVER;//CLIENT
|
||||||
|
enum IpType ip_type = IPV4;
|
||||||
|
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||||
|
|
||||||
|
printf("ready to test data transfer\n");
|
||||||
|
|
||||||
|
len = strlen(ethernet_msg);
|
||||||
|
for (i = 0;i < 10; i ++) {
|
||||||
|
printf("AdapterEthernetTest send %s\n", ethernet_msg);
|
||||||
|
AdapterDeviceSend(adapter, ethernet_msg, len);
|
||||||
|
PrivTaskDelay(4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
AdapterDeviceRecv(adapter, ethernet_recv_msg, 128);
|
||||||
|
printf("AdapterEthernetTest recv %s\n", ethernet_recv_msg);
|
||||||
|
memset(ethernet_recv_msg, 0, 128);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterEthernetTest, AdapterEthernetTest, show adapter ethernet information);
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
config ADAPTER_ETHERNET_HFA21
|
||||||
|
string "HFA21 ETHERNET adapter name"
|
||||||
|
default "hfa21_ethernet"
|
||||||
|
|
||||||
|
if ADD_XIUOS_FETURES
|
||||||
|
|
||||||
|
config ADAPTER_HFA21_DRIVER_EXTUART
|
||||||
|
bool "Using extra uart to support ethernet"
|
||||||
|
default n
|
||||||
|
|
||||||
|
config ADAPTER_HFA21_DRIVER
|
||||||
|
string "HFA21 device uart driver path"
|
||||||
|
default "/dev/usart3_dev3"
|
||||||
|
depends on !ADAPTER_HFA21_DRIVER_EXTUART
|
||||||
|
|
||||||
|
if ADAPTER_HFA21_DRIVER_EXTUART
|
||||||
|
config ADAPTER_HFA21_DRIVER
|
||||||
|
string "HFA21 device extra uart driver path"
|
||||||
|
default "/dev/extuart_dev6"
|
||||||
|
|
||||||
|
config ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||||
|
int "if HFA21 device using extuart, choose port"
|
||||||
|
default "6"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ADD_NUTTX_FETURES
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ADD_RTTHREAD_FETURES
|
||||||
|
|
||||||
|
endif
|
|
@ -0,0 +1,3 @@
|
||||||
|
SRC_FILES := hfa21_ethernet.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,453 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file hfa21_ethernet.c
|
||||||
|
* @brief Implement the connection ethernet adapter function, using HFA21 device
|
||||||
|
* @version 1.1
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021.10.15
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <adapter.h>
|
||||||
|
#include <at_agent.h>
|
||||||
|
|
||||||
|
#define HFA21_ETHERNET_AT_CMD "+++"
|
||||||
|
#define HFA21_ETHERNET_AT_CONFIRM_CMD "a"
|
||||||
|
#define HFA21_ETHERNET_AT_FCLR_CMD "AT+FCLR\r"
|
||||||
|
#define HFA21_ETHERNET_AT_FEPHY_CMD "AT+FEPHY=on\r"
|
||||||
|
#define HFA21_ETHERNET_AT_ENABLE_WANN_CMD "AT+FVEW=enable\r"
|
||||||
|
#define HFA21_ETHERNET_AT_DISABLE_WANN_CMD "AT+FVEW=disable\r"
|
||||||
|
#define HFA21_ETHERNET_AT_RELD_CMD "AT+RELD\r"
|
||||||
|
#define HFA21_ETHERNET_AT_WMODE_CMD "AT+WMODE\r"
|
||||||
|
#define HFA21_ETHERNET_AT_WANN_CMD "AT+WANN\r"
|
||||||
|
#define HFA21_ETHERNET_AT_SET_WANN_CMD "AT+WANN=%s,%s,%s,%s\r"
|
||||||
|
#define HFA21_ETHERNET_AT_PING_CMD "AT+PING=%s\r"
|
||||||
|
#define HFA21_ETHERNET_AT_NETP_CMD "AT+NETP=%s,%s,%s,%s\r"
|
||||||
|
#define HFA21_ETHERNET_AT_REBOOT_CMD "AT+Z\r"
|
||||||
|
|
||||||
|
#define HFA21_ETHERNET_OK_REPLY "+ok"
|
||||||
|
|
||||||
|
static int Hfa21EthernetSetDown(struct Adapter *adapter_at);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: enter AT command mode
|
||||||
|
* @param at_agent - ethernet device agent pointer
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetInitAtCmd(ATAgentType at_agent)
|
||||||
|
{
|
||||||
|
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CMD);
|
||||||
|
PrivTaskDelay(100);
|
||||||
|
|
||||||
|
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CONFIRM_CMD);
|
||||||
|
PrivTaskDelay(500);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Open HFA21 uart function
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @return success: 0, failure: -1
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetOpen(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
/*step1: open hfa21 serial port*/
|
||||||
|
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
||||||
|
if (adapter->fd < 0) {
|
||||||
|
printf("Hfa21EthernetOpen get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*step2: init AT agent*/
|
||||||
|
if (!adapter->agent) {
|
||||||
|
char *agent_name = "ethernet_uart_client";
|
||||||
|
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||||
|
printf("at agent init failed !\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ATAgentType at_agent = GetATAgent(agent_name);
|
||||||
|
|
||||||
|
adapter->agent = at_agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
ADAPTER_DEBUG("Hfa21Ethernet open done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Close HFA21 ethernet and uart function
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetClose(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
return Hfa21EthernetSetDown(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: send data to adapter
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @param data - data buffer
|
||||||
|
* @param data - data length
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetSend(struct Adapter *adapter, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
if (adapter->agent) {
|
||||||
|
EntmSend(adapter->agent, (const char *)data, len);
|
||||||
|
}else {
|
||||||
|
printf("Hfa21EthernetSend can not find agent!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: receive data from adapter
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @param data - data buffer
|
||||||
|
* @param data - data length
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (adapter->agent) {
|
||||||
|
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
||||||
|
} else {
|
||||||
|
printf("Hfa21EthernetReceive can not find agent!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: connnect Ethernet to internet
|
||||||
|
* @param adapter - Ethernet device pointer
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetSetUp(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
AtSetReplyLrEnd(adapter->agent, 1);
|
||||||
|
|
||||||
|
/* wait hfa21 device startup finish */
|
||||||
|
PrivTaskDelay(5000);
|
||||||
|
|
||||||
|
/*Step1 : enter AT mode*/
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
PrivTaskDelay(1000);
|
||||||
|
|
||||||
|
/*Step2 : FCLR reboot*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FCLR_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivTaskDelay(10000);
|
||||||
|
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
/*Step3 : FEPHY enable phy function*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FEPHY_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step4 : FVEW disable WANN function, ethernet work at LANN mode*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_DISABLE_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step5 : RELD enable F-AT cmd*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_RELD_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivTaskDelay(10000);
|
||||||
|
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
/*Step6 : AT+WMODE check work mode, AP or STA*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WMODE_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step7 : AT+WANN check if get ip、netmask、gateway*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step8 : AT+Z reboot hfa21 device*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivTaskDelay(10000);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
Hfa21EthernetSetDown(adapter);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: disconnnect ethernet from internet
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @return success: 0
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetSetDown(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_FCLR_CMD);
|
||||||
|
PrivTaskDelay(20000);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: set ethernet ip/gateway/netmask address(in sta mode) working at WANN mode
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @param ip - ip address
|
||||||
|
* @param gateway - gateway address
|
||||||
|
* @param netmask - netmask address
|
||||||
|
* @return success: 0, failure: -ENOMEMORY or -1
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
uint8_t hfa21_ethernet_cmd[64];
|
||||||
|
|
||||||
|
/*Step1 : enter AT mode*/
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
/*Step2 : set mode、ip、netmask and gateway*/
|
||||||
|
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||||
|
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_SET_WANN_CMD, "DHCP", ip, netmask, gateway);
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step3 : AT+WANN check if set ip、netmask、gateway successfully*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step4 : AT+Z reboot hfa21 device*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivTaskDelay(10000);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
Hfa21EthernetSetDown(adapter);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: ethernet ping function
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @param destination - domain name or ip address
|
||||||
|
* @return success: 0, failure: -1
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetPing(struct Adapter *adapter, const char *destination)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
char *ping_result = (char *) PrivCalloc(1, 17);
|
||||||
|
char *dst = (char *) PrivCalloc(1, 17);
|
||||||
|
|
||||||
|
strcpy(dst, destination);
|
||||||
|
strcat(dst, "\r");
|
||||||
|
|
||||||
|
printf("Hfa21EthernetPing [%s]\n", dst);
|
||||||
|
|
||||||
|
/*Step1 : enter AT mode*/
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
/*Step2 : ping dst ip address*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_PING_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step3 : AT+Z reboot hfa21 device*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
Hfa21EthernetSetDown(adapter);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: ethernet connect function
|
||||||
|
* @param adapter - ethernet device pointer
|
||||||
|
* @param net_role - net role, CLIENT or SERVER
|
||||||
|
* @param ip - ip address
|
||||||
|
* @param port - port num
|
||||||
|
* @param ip_type - ip type, IPV4 or IPV6
|
||||||
|
* @return success: 0, failure: -1
|
||||||
|
*/
|
||||||
|
static int Hfa21EthernetConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
char hfa21_ethernet_cmd[128];
|
||||||
|
char net_role_string[6] = {0};
|
||||||
|
|
||||||
|
/*Step1 : enter AT mode*/
|
||||||
|
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
|
if (CLIENT == net_role) {
|
||||||
|
strcpy(net_role_string, "CLIENT");
|
||||||
|
} else if (SERVER == net_role) {
|
||||||
|
strcpy(net_role_string, "SERVER");
|
||||||
|
} else {
|
||||||
|
printf("Hfa21EthernetConnect do not support %d net type\n", net_role);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IPV4 == ip_type) {
|
||||||
|
/*to do*/
|
||||||
|
} else if (IPV6 == ip_type) {
|
||||||
|
/*to do*/
|
||||||
|
} else {
|
||||||
|
printf("Hfa21EthernetConnect do not support %d ip type\n", ip_type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Step2 : create tcp connect*/
|
||||||
|
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||||
|
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_NETP_CMD, "TCP", net_role_string, port, ip);
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter->net_role = net_role;
|
||||||
|
|
||||||
|
/*Step3 : AT+Z reboot hfa21 device*/
|
||||||
|
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||||
|
if (ret < 0) {
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivTaskDelay(10000);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
Hfa21EthernetSetDown(adapter);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Hfa21EthernetIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||||
|
{
|
||||||
|
if (OPE_INT != cmd) {
|
||||||
|
printf("Hfa21EthernetIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t baud_rate = *((uint32_t *)args);
|
||||||
|
|
||||||
|
struct SerialDataCfg serial_cfg;
|
||||||
|
memset(&serial_cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||||
|
serial_cfg.serial_baud_rate = baud_rate;
|
||||||
|
serial_cfg.serial_data_bits = DATA_BITS_8;
|
||||||
|
serial_cfg.serial_stop_bits = STOP_BITS_1;
|
||||||
|
serial_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||||
|
serial_cfg.serial_parity_mode = PARITY_NONE;
|
||||||
|
serial_cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||||
|
serial_cfg.serial_invert_mode = NRZ_NORMAL;
|
||||||
|
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||||
|
serial_cfg.ext_uart_no = ADAPTER_HFA21_DRIVER_EXT_PORT;
|
||||||
|
serial_cfg.port_configure = PORT_CFG_INIT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct PrivIoctlCfg ioctl_cfg;
|
||||||
|
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||||
|
ioctl_cfg.args = &serial_cfg;
|
||||||
|
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||||
|
|
||||||
|
printf("Hfa21EthernetIoctl success\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct IpProtocolDone hfa21_ethernet_done =
|
||||||
|
{
|
||||||
|
.open = Hfa21EthernetOpen,
|
||||||
|
.close = Hfa21EthernetClose,
|
||||||
|
.ioctl = Hfa21EthernetIoctl,
|
||||||
|
.setup = Hfa21EthernetSetUp,
|
||||||
|
.setdown = Hfa21EthernetSetDown,
|
||||||
|
.setaddr = Hfa21EthernetSetAddr,
|
||||||
|
.setdns = NULL,
|
||||||
|
.setdhcp = NULL,
|
||||||
|
.ping = Hfa21EthernetPing,
|
||||||
|
.netstat = NULL,
|
||||||
|
.connect = Hfa21EthernetConnect,
|
||||||
|
.send = Hfa21EthernetSend,
|
||||||
|
.recv = Hfa21EthernetReceive,
|
||||||
|
.disconnect = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Register ethernet device hfa21
|
||||||
|
* @return success: product_info, failure: NULL
|
||||||
|
*/
|
||||||
|
AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter)
|
||||||
|
{
|
||||||
|
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||||
|
if (!product_info) {
|
||||||
|
printf("Hfa21EthernetAttach Attach malloc product_info error\n");
|
||||||
|
PrivFree(product_info);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(product_info->model_name, ADAPTER_ETHERNET_HFA21);
|
||||||
|
|
||||||
|
product_info->model_done = (void *)&hfa21_ethernet_done;
|
||||||
|
|
||||||
|
return product_info;
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
config ADAPTER_HFA21_WIFI
|
config ADAPTER_HFA21_WIFI
|
||||||
|
help
|
||||||
|
Please check HFA21 can only work for adapter_wifi or adapter_ethernet in the meantime!
|
||||||
bool "Using wifi adapter device HFA21"
|
bool "Using wifi adapter device HFA21"
|
||||||
default y
|
default n
|
||||||
|
|
||||||
if ADAPTER_HFA21_WIFI
|
if ADAPTER_HFA21_WIFI
|
||||||
source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig"
|
source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <bus_pin.h>
|
#include <bus_pin.h>
|
||||||
|
|
||||||
#ifdef ADAPTER_HFA21_WIFI
|
#ifdef ADAPTER_HFA21_WIFI
|
||||||
extern AdapterProductInfoType Hfa21Attach(struct Adapter *adapter);
|
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ADAPTER_WIFI_NAME "wifi"
|
#define ADAPTER_WIFI_NAME "wifi"
|
||||||
|
@ -66,7 +66,7 @@ int AdapterWifiInit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ADAPTER_HFA21_WIFI
|
#ifdef ADAPTER_HFA21_WIFI
|
||||||
AdapterProductInfoType product_info = Hfa21Attach(adapter);
|
AdapterProductInfoType product_info = Hfa21WifiAttach(adapter);
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("AdapterWifiInit hfa21 attach error\n");
|
printf("AdapterWifiInit hfa21 attach error\n");
|
||||||
free(adapter);
|
free(adapter);
|
||||||
|
@ -167,7 +167,3 @@ int AdapterWifiTest(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information);
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file hfa21.c
|
* @file hfa21_wifi.c
|
||||||
* @brief Implement the connection wifi adapter function, using HFA21 device
|
* @brief Implement the connection wifi adapter function, using HFA21 device
|
||||||
* @version 1.1
|
* @version 1.1
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
|
@ -23,14 +23,14 @@
|
||||||
|
|
||||||
#define LEN_PARA_BUF 128
|
#define LEN_PARA_BUF 128
|
||||||
|
|
||||||
static int Hfa21SetDown(struct Adapter *adapter_at);
|
static int Hfa21WifiSetDown(struct Adapter *adapter_at);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: enter AT command mode
|
* @description: enter AT command mode
|
||||||
* @param at_agent - wifi device agent pointer
|
* @param at_agent - wifi device agent pointer
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21InitAtCmd(ATAgentType at_agent)
|
static int Hfa21WifiInitAtCmd(ATAgentType at_agent)
|
||||||
{
|
{
|
||||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++");
|
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++");
|
||||||
PrivTaskDelay(100);
|
PrivTaskDelay(100);
|
||||||
|
@ -46,12 +46,12 @@ static int Hfa21InitAtCmd(ATAgentType at_agent)
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: EOK, failure: ENOMEMORY
|
||||||
*/
|
*/
|
||||||
static int Hfa21Open(struct Adapter *adapter)
|
static int Hfa21WifiOpen(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
/*step1: open ec200t serial port*/
|
/*step1: open hfa21 serial port*/
|
||||||
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
||||||
if (adapter->fd < 0) {
|
if (adapter->fd < 0) {
|
||||||
printf("Hfa21Open get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
printf("Hfa21WifiOpen get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ static int Hfa21Open(struct Adapter *adapter)
|
||||||
adapter->agent = at_agent;
|
adapter->agent = at_agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADAPTER_DEBUG("Hfa21 open done\n");
|
ADAPTER_DEBUG("Hfa21Wifi open done\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -77,25 +77,25 @@ static int Hfa21Open(struct Adapter *adapter)
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21Close(struct Adapter *adapter)
|
static int Hfa21WifiClose(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
return Hfa21SetDown(adapter);
|
return Hfa21WifiSetDown(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: send data to adapter
|
* @description: send data to adapter
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param data - data bufferd
|
* @param data - data buffer
|
||||||
* @param data - data length
|
* @param data - data length
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21Send(struct Adapter *adapter, const void *data, size_t len)
|
static int Hfa21WifiSend(struct Adapter *adapter, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
x_err_t result = EOK;
|
x_err_t result = EOK;
|
||||||
if (adapter->agent) {
|
if (adapter->agent) {
|
||||||
EntmSend(adapter->agent, (const char *)data, len);
|
EntmSend(adapter->agent, (const char *)data, len);
|
||||||
}else {
|
}else {
|
||||||
printf("Can not find agent \n");
|
printf("Hfa21WifiSend can not find agent!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
__exit:
|
__exit:
|
||||||
|
@ -106,11 +106,11 @@ __exit:
|
||||||
/**
|
/**
|
||||||
* @description: receive data from adapter
|
* @description: receive data from adapter
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param data - data bufferd
|
* @param data - data buffer
|
||||||
* @param data - data length
|
* @param data - data length
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21Receive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
static int Hfa21WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||||
{
|
{
|
||||||
x_err_t result = EOK;
|
x_err_t result = EOK;
|
||||||
printf("hfa21 receive waiting ... \n");
|
printf("hfa21 receive waiting ... \n");
|
||||||
|
@ -118,7 +118,7 @@ static int Hfa21Receive(struct Adapter *adapter, void *rev_buffer, size_t buffer
|
||||||
if (adapter->agent) {
|
if (adapter->agent) {
|
||||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
||||||
} else {
|
} else {
|
||||||
printf("Can not find agent \n");
|
printf("Hfa21WifiReceive can not find agent!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
__exit:
|
__exit:
|
||||||
|
@ -131,26 +131,25 @@ __exit:
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21SetUp(struct Adapter *adapter)
|
static int Hfa21WifiSetUp(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
||||||
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
||||||
char cmd[LEN_PARA_BUF];
|
char cmd[LEN_PARA_BUF];
|
||||||
|
|
||||||
//struct at_device_esp8266 *esp8266 = (struct at_device_esp8266 *) device->UserData;
|
|
||||||
struct ATAgent *agent = adapter->agent;
|
struct ATAgent *agent = adapter->agent;
|
||||||
|
|
||||||
/* wait hfa21 device startup finish */
|
/* wait hfa21 device startup finish */
|
||||||
PrivTaskDelay(5000);
|
PrivTaskDelay(5000);
|
||||||
|
|
||||||
Hfa21InitAtCmd(agent);
|
Hfa21WifiInitAtCmd(agent);
|
||||||
|
|
||||||
memset(cmd,0,sizeof(cmd));
|
memset(cmd,0,sizeof(cmd));
|
||||||
strcpy(cmd,"AT+FCLR\r");
|
strcpy(cmd,"AT+FCLR\r");
|
||||||
ATOrderSend(agent, REPLY_TIME_OUT, NULL, cmd);
|
ATOrderSend(agent, REPLY_TIME_OUT, NULL, cmd);
|
||||||
PrivTaskDelay(20000);
|
PrivTaskDelay(20000);
|
||||||
|
|
||||||
Hfa21InitAtCmd(agent);
|
Hfa21WifiInitAtCmd(agent);
|
||||||
|
|
||||||
memset(cmd,0,sizeof(cmd));
|
memset(cmd,0,sizeof(cmd));
|
||||||
strcpy(cmd,"AT+WSSSID=");
|
strcpy(cmd,"AT+WSSSID=");
|
||||||
|
@ -184,9 +183,9 @@ static int Hfa21SetUp(struct Adapter *adapter)
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK
|
* @return success: EOK
|
||||||
*/
|
*/
|
||||||
static int Hfa21SetDown(struct Adapter *adapter)
|
static int Hfa21WifiSetDown(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
Hfa21InitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+FCLR\r");
|
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+FCLR\r");
|
||||||
PrivTaskDelay(20000);
|
PrivTaskDelay(20000);
|
||||||
|
@ -202,7 +201,7 @@ static int Hfa21SetDown(struct Adapter *adapter)
|
||||||
* @param netmask - netmask address
|
* @param netmask - netmask address
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: EOK, failure: ENOMEMORY
|
||||||
*/
|
*/
|
||||||
static int Hfa21SetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||||
{
|
{
|
||||||
#define HFA21_SET_ADDR_EXPRESSION "+ok=%[^,],%[^,],%[^,],%[^,]\r"
|
#define HFA21_SET_ADDR_EXPRESSION "+ok=%[^,],%[^,],%[^,],%[^,]\r"
|
||||||
char *dhcp_mode =NULL;
|
char *dhcp_mode =NULL;
|
||||||
|
@ -215,7 +214,7 @@ static int Hfa21SetAddr(struct Adapter *adapter, const char *ip, const char *gat
|
||||||
gw_str = (char *) PrivCalloc(1, 17);
|
gw_str = (char *) PrivCalloc(1, 17);
|
||||||
mask_str = (char *) PrivCalloc(1, 17);
|
mask_str = (char *) PrivCalloc(1, 17);
|
||||||
|
|
||||||
Hfa21InitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
x_err_t result = EOK;
|
x_err_t result = EOK;
|
||||||
|
|
||||||
|
@ -251,12 +250,12 @@ __exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: ping
|
* @description: wifi ping function
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @param destination - domain name or ip address
|
* @param destination - domain name or ip address
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: EOK, failure: ENOMEMORY
|
||||||
*/
|
*/
|
||||||
static int Hfa21Ping(struct Adapter *adapter, const char *destination)
|
static int Hfa21WifiPing(struct Adapter *adapter, const char *destination)
|
||||||
{
|
{
|
||||||
char *ping_result = NONE;
|
char *ping_result = NONE;
|
||||||
char *dst = NONE;
|
char *dst = NONE;
|
||||||
|
@ -265,7 +264,7 @@ static int Hfa21Ping(struct Adapter *adapter, const char *destination)
|
||||||
strcpy(dst, destination);
|
strcpy(dst, destination);
|
||||||
strcat(dst, "\r");
|
strcat(dst, "\r");
|
||||||
|
|
||||||
Hfa21InitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
uint32 result = EOK;
|
uint32 result = EOK;
|
||||||
|
|
||||||
|
@ -301,11 +300,11 @@ __exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: display network configuration
|
* @description: display wifi network configuration
|
||||||
* @param adapter - wifi device pointer
|
* @param adapter - wifi device pointer
|
||||||
* @return success: EOK, failure: ENOMEMORY
|
* @return success: EOK, failure: ENOMEMORY
|
||||||
*/
|
*/
|
||||||
static int Hfa21Netstat(struct Adapter *adapter)
|
static int Hfa21WifiNetstat(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
#define HFA21_NETSTAT_RESP_SIZE 320
|
#define HFA21_NETSTAT_RESP_SIZE 320
|
||||||
#define HFA21_NETSTAT_TYPE_SIZE 10
|
#define HFA21_NETSTAT_TYPE_SIZE 10
|
||||||
|
@ -400,7 +399,16 @@ __exit:
|
||||||
PrivFree(work_mode);
|
PrivFree(work_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
/**
|
||||||
|
* @description: wifi connect function
|
||||||
|
* @param adapter - wifi device pointer
|
||||||
|
* @param net_role - net role, CLIENT or SERVER
|
||||||
|
* @param ip - ip address
|
||||||
|
* @param port - port num
|
||||||
|
* @param ip_type - ip type, IPV4 or IPV6
|
||||||
|
* @return success: 0, failure: -1
|
||||||
|
*/
|
||||||
|
static int Hfa21WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||||
{
|
{
|
||||||
int result = EOK;
|
int result = EOK;
|
||||||
ATReplyType reply = NONE;
|
ATReplyType reply = NONE;
|
||||||
|
@ -413,7 +421,7 @@ static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, cons
|
||||||
return ENOMEMORY;
|
return ENOMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hfa21InitAtCmd(adapter->agent);
|
Hfa21WifiInitAtCmd(adapter->agent);
|
||||||
|
|
||||||
memset(cmd,0,sizeof(cmd));
|
memset(cmd,0,sizeof(cmd));
|
||||||
strcpy(cmd,"AT+NETP=TCP,");
|
strcpy(cmd,"AT+NETP=TCP,");
|
||||||
|
@ -446,10 +454,10 @@ __exit:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Hfa21Ioctl(struct Adapter *adapter, int cmd, void *args)
|
static int Hfa21WifiIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||||
{
|
{
|
||||||
if (OPE_INT != cmd) {
|
if (OPE_INT != cmd) {
|
||||||
printf("Hfa21Ioctl only support OPE_INT, do not support %d\n", cmd);
|
printf("Hfa21WifiIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,25 +481,25 @@ static int Hfa21Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||||
ioctl_cfg.args = &serial_cfg;
|
ioctl_cfg.args = &serial_cfg;
|
||||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||||
printf("Hfa21Ioctl success\n");
|
printf("Hfa21WifiIoctl success\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct IpProtocolDone hfa21_done =
|
static const struct IpProtocolDone hfa21_wifi_done =
|
||||||
{
|
{
|
||||||
.open = Hfa21Open,
|
.open = Hfa21WifiOpen,
|
||||||
.close = Hfa21Close,
|
.close = Hfa21WifiClose,
|
||||||
.ioctl = Hfa21Ioctl,
|
.ioctl = Hfa21WifiIoctl,
|
||||||
.setup = Hfa21SetUp,
|
.setup = Hfa21WifiSetUp,
|
||||||
.setdown = Hfa21SetDown,
|
.setdown = Hfa21WifiSetDown,
|
||||||
.setaddr = Hfa21SetAddr,
|
.setaddr = Hfa21WifiSetAddr,
|
||||||
.setdns = NULL,
|
.setdns = NULL,
|
||||||
.setdhcp = NULL,
|
.setdhcp = NULL,
|
||||||
.ping = Hfa21Ping,
|
.ping = Hfa21WifiPing,
|
||||||
.netstat = Hfa21Netstat,
|
.netstat = Hfa21WifiNetstat,
|
||||||
.connect = Hfa21Connect,
|
.connect = Hfa21WifiConnect,
|
||||||
.send = Hfa21Send,
|
.send = Hfa21WifiSend,
|
||||||
.recv = Hfa21Receive,
|
.recv = Hfa21WifiReceive,
|
||||||
.disconnect = NULL,
|
.disconnect = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -499,18 +507,18 @@ static const struct IpProtocolDone hfa21_done =
|
||||||
* @description: Register wifi device hfa21
|
* @description: Register wifi device hfa21
|
||||||
* @return success: EOK, failure: ERROR
|
* @return success: EOK, failure: ERROR
|
||||||
*/
|
*/
|
||||||
AdapterProductInfoType Hfa21Attach(struct Adapter *adapter)
|
AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("Hfa21Attach Attach malloc product_info error\n");
|
printf("Hfa21WifiAttach Attach malloc product_info error\n");
|
||||||
PrivFree(product_info);
|
PrivFree(product_info);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(product_info->model_name, ADAPTER_WIFI_HFA21);
|
strcpy(product_info->model_name, ADAPTER_WIFI_HFA21);
|
||||||
|
|
||||||
product_info->model_done = (void *)&hfa21_done;
|
product_info->model_done = (void *)&hfa21_wifi_done;
|
||||||
|
|
||||||
return product_info;
|
return product_info;
|
||||||
}
|
}
|
Loading…
Reference in New Issue