提交 88a13e30 编写于 作者: S shilei.yu 提交者: Cheng Li

update wifi driver

上级 e9b2b1ec
......@@ -6,6 +6,7 @@
#include "rda59xx_wifi_include.h"
#include "hal/wifi.h"
#include "lwip/ip4_addr.h"
#include "lwip/inet.h"
typedef enum {
SCAN_NORMAL,
......@@ -204,7 +205,7 @@ static int get_ip_stat(hal_wifi_module_t *m,
rda59xx_bss_info bss_info;
unsigned int state = 0;
state = rda59xx_get_module_state();
if ((wifi_type == HAL_WIFI_MODE_STATION) && (state & STATE_STA)){
if ((wifi_type == STATION) && (state & STATE_STA)){
rda59xx_sta_get_bss_info(&bss_info);
ip4addr_aton(out_net_para->ip, &(bss_info.ipaddr));
ip4addr_aton(out_net_para->mask, &(bss_info.mask));
......@@ -319,6 +320,32 @@ static void start_monitor(hal_wifi_module_t *m)
filter_backup = 0x27e77;
}
static int start_ap(hal_wifi_module_t *m, const char *ssid, const char *passwd, int interval, int hide)
{
rda59xx_ap_info aws_ap_info;
memset((void*)&aws_ap_info, 0, sizeof(rda59xx_ap_info));
strncpy(aws_ap_info.ssid, ssid, sizeof(aws_ap_info.ssid));
strncpy(aws_ap_info.pw, passwd, sizeof(aws_ap_info.pw));
aws_ap_info.channel = 6;
aws_ap_info.hidden = hide;
aws_ap_info.beacon = interval;
aws_ap_info.dhcps=inet_addr("10.10.100.1");
aws_ap_info.dhcpe=inet_addr("10.10.100.255");
aws_ap_info.ip=inet_addr("10.10.100.1");
aws_ap_info.gateway=inet_addr("10.10.100.1");
aws_ap_info.netmask=inet_addr("255.255.255.0");
return rda59xx_ap_enable(&aws_ap_info);
}
static int stop_ap(hal_wifi_module_t *m)
{
return rda59xx_ap_disable();
}
static void stop_monitor(hal_wifi_module_t *m)
{
rda59xx_sniffer_disable();
......
......@@ -12,14 +12,14 @@
#define ENCRYPT_WEP BIT4
typedef enum {
DAEMON_SCAN,
DAEMON_STA_CONNECT,
DAEMON_STA_DISCONNECT,
DAEMON_STA_RECONNECT,
DAEMON_AP_ENABLE,
DAEMON_AP_DISABLE,
DAEMON_SNIFFER_ENABLE,
DAEMON_SNIFFER_DISABLE,
DAEMON_SCAN = 0,
DAEMON_STA_CONNECT = 1,
DAEMON_STA_DISCONNECT = 2,
DAEMON_STA_RECONNECT = 3,
DAEMON_AP_ENABLE = 10,
DAEMON_AP_DISABLE = 11,
DAEMON_SNIFFER_ENABLE = 21,
DAEMON_SNIFFER_DISABLE = 22,
}DAEMON_MSG;
typedef enum {
......@@ -35,7 +35,7 @@ typedef enum {
ERR_AUTH = -3,
ERR_CONNECTION = -4,
ERR_DHCP = -5,
}ERR_TYPE;
}RDA_ERR_TYPE;
typedef enum {
DISCONNECT_ACTIVE = 1,
......@@ -60,8 +60,8 @@ typedef void (*wifi_event_cb_t)(WIFI_EVENT evt, void* info);
#define STATE_SNIFFER BIT1
#define STATE_STA BIT2
#define STATE_STA_RC BIT3
#define STATE_AP BIT3
#define STATE_P2P BIT4
#define STATE_AP BIT4
#define STATE_P2P BIT5
extern r_s32 rda59xx_wifi_init();
extern r_s32 rda59xx_wifi_set_event_cb(wifi_event_cb_t cb);
......
......@@ -6,12 +6,15 @@
#include "lwip/ip_addr.h"
extern const ip_addr_t * rda59xx_get_netif_ip(struct netif *netif);
extern r_void rda59xx_add_dns_addr(struct netif *netif);
extern r_void rda59xx_netif_input(struct netif *netif, r_u8 *data, r_u32 len);
extern r_void rda59xx_sta_netif_init(struct netif *netif);
extern r_void rda59xx_ap_netif_init(struct netif *netif);
extern r_void rda59xx_sta_netif_link_failed();
extern r_void rda59xx_netif_link_down(r_u32 netif);
extern r_void rda59xx_netif_link_up(r_u32 netif);
extern r_void rda59xx_netif_down(r_u32 netif);
extern r_void rda59xx_netif_up(r_u32 netif);
#endif /* _RDA59XX_LWIP_H */
......@@ -95,6 +95,7 @@ enum ELEMENTID_T{
ICTEXT = 16, /* Challenge Text */
IERPINFO = 42, /* ERP Information */
IEXSUPRATES = 50, /* Extended Supported Rates */
HTPARAMS = 61, /* HT Info Element */
IWAPI = 68
};
......@@ -102,7 +103,8 @@ enum COUNTRY_CODE_T
{
JP = 0,
NA = 1,
EU = 2
EU = 2,
CHONE = 0x10
};
/* Scan type parameter for scan request */
......
......@@ -142,6 +142,7 @@ typedef struct {
r_u8 channel;
r_u8 scan_mode;
r_u8 scan_time;
r_u8 country_code;
}rda59xx_scan_info;
extern r_void rda59xx_set_country_code(r_u8 c_code);
......@@ -184,7 +185,7 @@ typedef struct {
} rda59xx_bss_info;
extern r_s32 rda59xx_get_joined_AP(rda59xx_scan_result *bss);
extern void rda5981_set_auth_timeout(r_u8 timeout_enable);
/****************************************ap************************************************/
typedef struct {
r_u8 mac[ETH_ALEN];
......@@ -196,6 +197,8 @@ typedef struct{
r_u8 pw[MAX_PW_LEN];
r_u8 channel;
r_u8 secure;
r_u8 hidden;
r_u16 beacon;
r_u32 ip;
r_u32 netmask;
r_u32 gateway;
......@@ -204,7 +207,7 @@ typedef struct{
}rda59xx_ap_info;
extern r_u32 rda59xx_get_ap_join_info(rda59xx_apsta_info_t *buf, const r_u32 len);
extern r_void rda59xx_set_AP_link_num(r_u8 num);
extern r_void rda59xx_set_AP_white_list(r_u32 flag, r_u8 *mac);
#endif /* _RDA59XX_WIFI_INCLUDE_H_ */
......
......@@ -3,6 +3,7 @@
#include "rda59xx_daemon.h"
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "lwip/inet.h"
#include "lwip/tcpip.h"
#include "maclib_task.h"
#include "rda59xx_lwip.h"
......@@ -32,9 +33,11 @@ r_u32 rda_hut_dump = 0;
#define SCAN_TIMES 10
#define RECONN_TIMES 3
#define DAEMON_MAILQ_SIZE 10
static bool rda_lwip_tcpip_init_flag = false;
static sys_sem_t rda_lwip_tcpip_inited;
r_void *daemon_queue = NULL;
r_u32 module_state = STATE_DSIABLE;
unsigned char g_airkiss_connect_flag = 0;
static rda59xx_sta_info r_sta_info;
static rda59xx_bss_info r_bss_info;
static rda59xx_ap_info r_ap_info;
......@@ -47,6 +50,11 @@ struct netif lwip_ap_netif;
extern int sniffer_cb(void *data, unsigned short data_len);
extern unsigned int filter_backup;
static void rda59xx_lwip_tcpip_init_irq(void *eh)
{
sys_sem_signal(&rda_lwip_tcpip_inited);
rda_lwip_tcpip_init_flag = true;
}
r_s32 rda59xx_send_wland_msg(rda_msg *msg, r_u32 wait_time)
{
......@@ -116,7 +124,6 @@ r_u32 rda59xx_get_module_state()
return module_state;
}
r_void rda59xx_sta_get_bss_info(rda59xx_bss_info *bss_info)
{
r_memcpy(bss_info, &r_bss_info, sizeof(rda59xx_bss_info));
......@@ -126,17 +133,25 @@ r_void rda59xx_sta_get_bss_info(rda59xx_bss_info *bss_info)
static r_s32 rda59xx_sta_init(struct netif *netif)
{
static r_u32 init_flag = 0;
int netif_no = 0;
if(init_flag == 1)
return R_NOERR;
//rda_netif.netif_no = 0;
sys_sem_new(&lwip_sta_netif_linked, 0);
sys_sem_new(&lwip_sta_netif_has_addr, 0);
if(rda_lwip_tcpip_init_flag == false){
sys_sem_new(&rda_lwip_tcpip_inited, 0);
tcpip_init(rda59xx_lwip_tcpip_init_irq, NULL);
sys_arch_sem_wait(&rda_lwip_tcpip_inited, 0);
}
r_memset(&lwip_sta_netif, 0, sizeof(struct netif));
if (!netif_add(&lwip_sta_netif,
#if LWIP_IPV4
0, 0, 0,
#endif
NULL, rda59xx_sta_netif_init, tcpip_input)) {
(void *)&netif_no, rda59xx_sta_netif_init, tcpip_input)) {
return ERR_DEVICE;
}
init_flag = 1;
......@@ -146,16 +161,25 @@ static r_s32 rda59xx_sta_init(struct netif *netif)
static r_s32 rda59xx_ap_init(struct netif *netif)
{
static r_u32 init_flag = 0;
if(init_flag == 1)
return R_NOERR;
int netif_no = 1;
//rda_netif.netif_no = 1;
sys_sem_new(&lwip_ap_netif_linked, 0);
if(rda_lwip_tcpip_init_flag == false){
sys_sem_new(&rda_lwip_tcpip_inited, 0);
tcpip_init(rda59xx_lwip_tcpip_init_irq, NULL);
sys_arch_sem_wait(&rda_lwip_tcpip_inited, 0);
}
r_memset(&lwip_ap_netif, 0, sizeof(struct netif));
if (!netif_add(&lwip_ap_netif,
#if LWIP_IPV4
0, 0, 0,
#endif
NULL, rda59xx_ap_netif_init, tcpip_input)) {
(void *)&netif_no, rda59xx_ap_netif_init, tcpip_input)) {
return ERR_DEVICE;
}
......@@ -175,12 +199,22 @@ static r_s32 rda59xx_sta_disconnect_internal()
netif_set_down(&lwip_sta_netif);
msg.type = RDA59XX_WLAND_STA_DISCONNECT;
res = rda59xx_send_wland_msg(&msg, 1000);
res = rda59xx_send_wland_msg(&msg, RDA_WAIT_FOREVER);
if(res != R_NOERR){
WIFISTACK_PRINT("Send disconnect cmd failed!\r\n");
return R_ERR;
}
#if LWIP_IPV4
char *ip_zero = "0.0.0.0";
ip4_addr_t ip_init;
inet_aton(ip_zero, &ip_init);
netif_set_ipaddr(&lwip_sta_netif, &ip_init);
#endif
sys_sem_free(&lwip_sta_netif_has_addr);
sys_sem_new(&lwip_sta_netif_has_addr, 0);
return res;
}
......@@ -197,12 +231,14 @@ r_s32 rda59xx_sta_disconnect()
static r_s32 rda59xx_sta_connect_internal(rda59xx_sta_info *sta_info)
{
r_s32 res = R_NOERR, res_t = R_NOERR;
r_u8 reconn = 0, scan_times = 0, scan_res = 0, msg_type = 0;
r_u8 reconn = 0, scan_times = 0, scan_res = 0;
r_s32 index = 0;
rda_msg msg;
rda59xx_scan_info r_scan_info;
rda59xx_scan_result ap;
r_u16 timeout_val = (g_airkiss_connect_flag) ? 10000 : 6000;
WIFISTACK_PRINT("rda59xx_sta_connect_internal!\r\n");
r_memcpy(&r_sta_info, sta_info, sizeof(rda59xx_sta_info));
//scan
......@@ -213,9 +249,11 @@ static r_s32 rda59xx_sta_connect_internal(rda59xx_sta_info *sta_info)
r_scan_info.SSID_len = r_strlen(r_sta_info.ssid);
rda59xx_del_scan_all_result();
while (scan_times++ < SCAN_TIMES) {
WIFISTACK_PRINT("scan_times=%d\r\n",scan_times);
scan_res = rda59xx_scan_internal(&r_scan_info);
index = rda59xx_get_scan_result_special(&ap, r_sta_info.ssid, r_sta_info.bssid, r_sta_info.channel);
if(index != R_ERR) {
WIFISTACK_PRINT("find the special AP\r\n");
break;
}
}
......@@ -230,42 +268,50 @@ static r_s32 rda59xx_sta_connect_internal(rda59xx_sta_info *sta_info)
msg.arg1 = (r_u32)(&r_sta_info);
msg.arg2 = (r_u32)&ap;
res = rda_queue_send(wland_queue, (r_u32)&msg, 2000);
if(res != R_NOERR){
WIFISTACK_PRINT("Send connect cmd failed!\r\n");
return ERR_SEND_MSG;
}
if (!netif_is_link_up(&lwip_sta_netif)) {
res_t = sys_arch_sem_wait(&lwip_sta_netif_linked, 6000);
res_t = sys_arch_sem_wait(&lwip_sta_netif_linked, timeout_val);
if (res_t == SYS_ARCH_TIMEOUT) {
WIFISTACK_PRINT("sta linkup SYS_ARCH_TIMEOUT!\r\n");
res = ERR_CONNECTION;
goto reconn;
}
if(!netif_is_link_up(&lwip_sta_netif)){
WIFISTACK_PRINT("sta linkup ERR_AUTH!\r\n");
res = ERR_AUTH;
goto reconn;
}
}
netif_set_up(&lwip_sta_netif);
if (r_sta_info.dhcp) {
WIFISTACK_PRINT("dhcp\r\n");
res_t = dhcp_start(&lwip_sta_netif);
if (res_t) {
WIFISTACK_PRINT("ERR_DHCP!\r\n");
res = ERR_DHCP;
goto reconn;
}
}else{
} else {
netif_set_addr(&lwip_sta_netif, &(r_sta_info.ip), &(r_sta_info.netmask), &(r_sta_info.gateway));
}
if (!rda59xx_get_netif_ip(&lwip_sta_netif)) {
res_t = sys_arch_sem_wait(&lwip_sta_netif_has_addr, 10000);
if (res_t == SYS_ARCH_TIMEOUT) {
WIFISTACK_PRINT("sta has addr SYS_ARCH_TIMEOUT!\r\n");
res = ERR_DHCP;
}
}
//rda59xx_add_dns_addr(&lwip_sta_netif);
reconn:
if(res == R_NOERR){
WIFISTACK_PRINT("Connect successful!\r\n");
......@@ -276,12 +322,14 @@ reconn:
r_bss_info.gateway = lwip_sta_netif.gw.addr;
r_memcpy(&r_bss_info.dns1, dns_getserver(0), sizeof(r_u32));
r_memcpy(&r_bss_info.dns2, dns_getserver(1), sizeof(r_u32));
WIFISTACK_PRINT("Sta got ip successful!\r\n");
wifi_event_cb(EVENT_STA_CONNECTTED, NULL);
wifi_event_cb(EVENT_STA_GOT_IP, NULL);
break;
}else{
rda59xx_sta_disconnect_internal();
if(++reconn > RECONN_TIMES){
if(++reconn > RECONN_TIMES){
WIFISTACK_PRINT("reconn times=%d\r\n",reconn);
//r_memset(&r_sta_info, 0, sizeof(rda59xx_sta_info));
wifi_event_cb(EVENT_STA_CONNECT_FAIL, NULL);
break;
......@@ -297,6 +345,8 @@ reconn:
r_s32 rda59xx_sta_connect(rda59xx_sta_info *sta_info)
{
rda_msg msg;
WIFISTACK_PRINT("rda59xx_sta_connect!\r\n");
msg.type = DAEMON_STA_CONNECT;
msg.arg1 = (r_u32)sta_info;
rda59xx_send_daemon_msg(&msg, RDA_WAIT_FOREVER);
......@@ -307,25 +357,26 @@ r_s32 rda59xx_sta_get_ip(r_u32 ip_addr)
{
if(module_state & STATE_STA)
r_memcpy(ip_addr, &r_bss_info.ipaddr, sizeof(r_u32));
return 0;
return 0;
}
static r_s32 rda59xx_ap_enable_internal(rda59xx_ap_info *ap_info)
{
rda_msg msg;
r_s32 res = R_NOERR;
r_memcpy(&r_ap_info, ap_info, sizeof(rda59xx_ap_info));
r_memcpy(&r_ap_info, ap_info, sizeof(rda59xx_ap_info));
res = rda59xx_ap_init(&lwip_ap_netif);
netif_set_addr(&lwip_ap_netif, (ip_addr_t *)&(r_ap_info.ip), (ip_addr_t *)&(r_ap_info.netmask), (ip_addr_t *)&(r_ap_info.gateway));
msg.type = RDA59XX_WLAND_AP_START;
msg.arg1 = (r_u32)&r_ap_info;
rda_queue_send(wland_queue, (r_u32)&msg, RDA_WAIT_FOREVER);
if (!netif_is_link_up(&lwip_ap_netif)) {
res = sys_arch_sem_wait(&lwip_ap_netif_linked, 6000);
if (res == SYS_ARCH_TIMEOUT) {
WIFISTACK_PRINT("SYS_ARCH_TIMEOUT,ret ERR_CONNECTION = -4\r\n");
return ERR_CONNECTION;
}
}
......@@ -352,9 +403,9 @@ static r_s32 rda59xx_ap_disable_internal()
r_s32 res = R_NOERR;
netif_set_down(&lwip_ap_netif);
netif_set_link_down(&lwip_ap_netif);
msg.type = RDA59XX_WLAND_AP_STOP;
rda59xx_send_wland_msg(&msg, 1000);
rda59xx_send_wland_msg(&msg, RDA_WAIT_FOREVER);
dhcps_deinit();
return res;
......@@ -406,6 +457,7 @@ static r_void rda59xx_daemon(r_void *arg)
while(1){
rda_queue_recv(daemon_queue, (r_u32)&msg, RDA_WAIT_FOREVER);
WIFISTACK_PRINT("daemon_q=%d,daemon_queue_msg_type=%d,module_state=0x%x\r\n",daemon_queue,msg.type,module_state);
if((msg.type != DAEMON_SCAN) && (msg.type != DAEMON_STA_RECONNECT) && (module_state & STATE_STA_RC) && \
!((msg.type == DAEMON_STA_DISCONNECT) && (msg.arg1 == DISCONNECT_PASSIVE))){
WIFISTACK_PRINT("set stop_reconnect!\r\n");
......@@ -437,7 +489,19 @@ static r_void rda59xx_daemon(r_void *arg)
break;
case DAEMON_SCAN:
WIFISTACK_PRINT("DAEMON_SCAN!\r\n");
r_u32 monitor_restore_scan = 0;
if(module_state & STATE_SNIFFER){
module_state &= ~(STATE_SNIFFER);
rda59xx_sniffer_disable_internal();
monitor_restore_scan = 1;
}
res = rda59xx_scan_internal((rda59xx_scan_info *)msg.arg1);
if(monitor_restore_scan == 1){
rda59xx_sniffer_enable_internal(sniffer_cb);
rda59xx_sniffer_set_filter(1, 1, filter_backup);
module_state |= STATE_SNIFFER;
monitor_restore_scan = 0;
}
rda_sem_release((r_void *)msg.arg3);
break;
case DAEMON_STA_CONNECT:
......@@ -446,12 +510,14 @@ static r_void rda59xx_daemon(r_void *arg)
WIFISTACK_PRINT("STA has been connected!\r\n");
rda_sem_release((r_void *)msg.arg3);
break;
}
}
/*
if(module_state & STATE_AP){
rda59xx_ap_disable_internal();
module_state &= ~(STATE_AP);
r_memset(&r_ap_info, 0, sizeof(rda59xx_ap_info));
}
}
*/
res = rda59xx_sta_connect_internal((rda59xx_sta_info*)msg.arg1);
if(res == R_NOERR)
module_state |= STATE_STA;
......@@ -477,6 +543,7 @@ static r_void rda59xx_daemon(r_void *arg)
rda59xx_sniffer_disable_internal();
monitor_restore = 1;
}
//rda59xx_netif_down(0);
msg.type = DAEMON_STA_RECONNECT;
res = rda_queue_send(daemon_queue, (r_u32)&msg, 1000);
module_state |= STATE_STA_RC;
......@@ -517,6 +584,7 @@ static r_void rda59xx_daemon(r_void *arg)
break;
}
res = rda59xx_ap_enable_internal((rda59xx_ap_info*)msg.arg1);
module_state |= STATE_AP;
rda_sem_release((r_void *)msg.arg3);
break;
case DAEMON_AP_DISABLE:
......@@ -528,6 +596,7 @@ static r_void rda59xx_daemon(r_void *arg)
}
r_memset(&r_ap_info, 0, sizeof(rda59xx_ap_info));
res = rda59xx_ap_disable_internal();
module_state &= ~(STATE_AP);
rda_sem_release((r_void *)msg.arg3);
break;
default:
......@@ -539,20 +608,24 @@ static r_void rda59xx_daemon(r_void *arg)
r_s32 rda59xx_wifi_init()
{
static r_u32 init_flag = 0;
static r_u32 init_flag = 0, thread_init_flag = 0;
if(init_flag == 1)
return R_NOERR;
daemon_queue = rda_queue_create(DAEMON_MAILQ_SIZE, sizeof(rda_msg));
WIFISTACK_PRINT("wifi_init,daemon_q=%d,dae_q is null=%d\r\n",daemon_queue,daemon_queue == NULL ? 1: 0);
module_state = STATE_INIT;
rda59xx_set_cb_queue(daemon_queue);
rda59xx_sta_init(&lwip_sta_netif);
tcpip_init(NULL, NULL);
maclib_init();
//tcpip_init(NULL, NULL);
//maclib_init();
if(thread_init_flag == 0){
rda_thread_new("maclib_thread", maclib_task, NULL, 512*8, AOS_DEFAULT_APP_PRI);
rda_thread_new("wland_thread", rda59xx_wland_task, NULL, 512*8, AOS_DEFAULT_APP_PRI);
rda_thread_new("daemon_thread", rda59xx_daemon, NULL, 512*5, AOS_DEFAULT_APP_PRI);
rda_msleep(100);//wait for maclib_task running
/* Allow the PHY task to detect the initial link state and set up the proper flags */
rda_msleep(100);//wait for maclib_task running
thread_init_flag = 1;
}
wland_sta_init();
rda59xx_filter_multicast(0);
rda59xx_set_channel(6);
......
......@@ -16,12 +16,57 @@ const ip_addr_t * rda59xx_get_netif_ip(struct netif *netif)
}
if (!ip4_addr_isany(netif_ip4_addr(netif))) {
return netif_ip_addr4(netif);;
return netif_ip_addr4(netif);
}
return NULL;
}
void rda59xx_add_dns_addr(struct netif *netif)
{
// Do nothing if not brought up
const ip_addr_t *ip_addr = rda59xx_get_netif_ip(netif);
if(!ip_addr)
return;
// Check for existing dns server
for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) {
const ip_addr_t *dns_ip_addr = dns_getserver(numdns);
if (!ip_addr_isany(dns_ip_addr)) {
return;
}
}
if (IP_IS_V4(ip_addr)) {
/* 8.8.8.8 google */
ip_addr_t ipv4_dns_addr = IPADDR4_INIT(0x08080808);
dns_setserver(0, &ipv4_dns_addr);
}
}
/** \brief Low level init of the MAC and PHY.
*
* \param[in] netif Pointer to LWIP netif structure
*/
static err_t rda59xx_low_level_init(struct netif *netif)
{
static int init_flag = 0;
if(init_flag == 0){
//wland_reg_func();
maclib_init();
init_flag = 1;
}
return ERR_OK;
}
/**
* This function is the ethernet packet send function. It calls
* etharp_output after checking link status.
*
* \param[in] netif the lwip network interface structure for this enetif
* \param[in] q Pointer to pbug to send
* \param[in] ipaddr IP address
* \return ERR_OK or error code
*/
static err_t rda59xx_etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
{
/* Only send packet is link is up */
......@@ -31,6 +76,14 @@ static err_t rda59xx_etharp_output(struct netif *netif, struct pbuf *q, const ip
return ERR_CONN;
}
/** \brief Low level output of a packet. Never call this from an
* interrupt context, as it may block until TX descriptors
* become available.
*
* \param[in] netif the lwip network interface structure for this netif
* \param[in] p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* \return ERR_OK if the packet could be sent or an err_t value if the packet couldn't be sent
*/
static err_t rda59xx_low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
......@@ -90,6 +143,13 @@ static err_t rda59xx_low_level_output(struct netif *netif, struct pbuf *p)
return ERR_BUF;
}
/** \brief Allocates a pbuf and returns the data from the incoming packet.
*
* \param[in] netif the lwip network interface structure
* \param[in] idx index of packet to be read
* \return a pbuf filled with the received packet (including MAC header)
*/
static struct pbuf *rda59xx_low_level_input(struct netif *netif, u8_t *data, u32_t len)
{
struct pbuf *p, *q;
......@@ -162,11 +222,18 @@ static struct pbuf *rda59xx_low_level_input(struct netif *netif, u8_t *data, u32
return p;
}
/** \brief Attempt to read a packet from the EMAC interface.
*
* \param[in] netif the lwip network interface structure
* \param[in] idx index of packet to be read
*/
void rda59xx_netif_input(struct netif *netif, u8_t *data, u32_t len)
{
struct eth_hdr *ethhdr;
struct pbuf *p;
LWIP_DEBUGF(NETIF_DEBUG, ("rda59xx_netif_input\r\n"));
/* move received packet into a new pbuf */
p = rda59xx_low_level_input(netif, data, len);
if (p == NULL) {
......@@ -189,6 +256,7 @@ void rda59xx_netif_input(struct netif *netif, u8_t *data, u32_t len)
/* Free buffer */
pbuf_free(p);
}
LWIP_DEBUGF(NETIF_DEBUG, ("rda5991h_enetif_input: IP input ok\n"));
break;
default:
......@@ -247,6 +315,9 @@ static void rda59xx_sta_netif_status_irq(struct netif *lwip_netif)
err_t rda59xx_sta_netif_init(struct netif *netif)
{
err_t err;
LWIP_ASSERT("netif != NULL", (netif != NULL));
netif->name[0] = 's';
netif->name[1] = 't';
#if LWIP_NETIF_HOSTNAME
......@@ -264,9 +335,12 @@ err_t rda59xx_sta_netif_init(struct netif *netif)
/* device capabilities */
// TODOETH: check if the flags are correct below
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
err = rda59xx_low_level_init(netif);
if (err != ERR_OK)
return err;
netif->output = rda59xx_etharp_output;
netif->linkoutput = rda59xx_low_level_output;
netif_set_link_callback(&lwip_sta_netif, rda59xx_sta_netif_link_irq);
netif_set_status_callback(&lwip_sta_netif, rda59xx_sta_netif_status_irq);
netif_set_default(&lwip_sta_netif);
......@@ -283,6 +357,9 @@ static void rda59xx_ap_netif_link_irq(struct netif *lwip_netif)
err_t rda59xx_ap_netif_init(struct netif *netif)
{
err_t err;
LWIP_ASSERT("netif != NULL", (netif != NULL));
netif->name[0] = 'a';
netif->name[1] = 'p';
#if LWIP_NETIF_HOSTNAME
......@@ -300,14 +377,31 @@ err_t rda59xx_ap_netif_init(struct netif *netif)
/* device capabilities */
// TODOETH: check if the flags are correct below
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
err = rda59xx_low_level_init(netif);
if (err != ERR_OK)
return err;
netif->output = rda59xx_etharp_output;
netif->linkoutput = rda59xx_low_level_output;
netif_set_link_callback(&lwip_ap_netif, rda59xx_ap_netif_link_irq);
if(netif_default == NULL)
netif_set_default(&lwip_ap_netif);
return ERR_OK;
}
void rda59xx_netif_down(int netif)
{
if(netif == 0)
netif_set_down(&lwip_sta_netif);
else
netif_set_down(&lwip_ap_netif);
}
void rda59xx_netif_up(int netif)
{
if(netif == 0)
netif_set_up(&lwip_sta_netif);
else
netif_set_up(&lwip_ap_netif);
}
......@@ -83,7 +83,8 @@ r_s32 rda_alarm_start(r_void *handle, r_u32 timeout_ms)
{
r_s32 ret;
if(NULL != handle) {
ret = aos_timer_change((aos_timer_t *)handle, timeout_ms);
//ret = aos_timer_change((aos_timer_t *)handle, timeout_ms);
ret = krhino_timer_change(((aos_timer_t *)handle)->hdl, krhino_ms_to_ticks(timeout_ms), 0);
if(ret != 0)
return ERR;
return aos_timer_start((aos_timer_t *)handle);
......@@ -213,7 +214,7 @@ r_s32 rda_queue_recv(r_void *handler, r_u32 msg, r_u32 millisec)
{
rda_queue_handle *r_handler = (rda_queue_handle*)handler;
r_s32 size;
if(aos_queue_recv((aos_queue_t *)(r_handler->queue), millisec, (r_void*)msg, &size) == 0)
if(aos_queue_recv((aos_queue_t *)(r_handler->queue), millisec, (r_void*)msg, &size) != 0)
return ERR;
else
return NO_ERR;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册