mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-07 01:54:26 +01:00
Fixed DNS issue
This commit is contained in:
parent
f8817eec89
commit
d847c381c2
Binary file not shown.
Binary file not shown.
@ -23,6 +23,7 @@
|
|||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
#include "eic.h"
|
#include "eic.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -169,6 +170,8 @@ struct netif* ard_netif = NULL;
|
|||||||
// Network list retrived in the last scanNetwork
|
// Network list retrived in the last scanNetwork
|
||||||
static struct wl_network_t network_list[WL_NETWORKS_LIST_MAXNUM];
|
static struct wl_network_t network_list[WL_NETWORKS_LIST_MAXNUM];
|
||||||
|
|
||||||
|
struct ip_addr _hostIpAddr;
|
||||||
|
|
||||||
void* getTTCP(uint8_t sock)
|
void* getTTCP(uint8_t sock)
|
||||||
{
|
{
|
||||||
if (sock < MAX_SOCK_NUM)
|
if (sock < MAX_SOCK_NUM)
|
||||||
@ -407,7 +410,7 @@ int spi_add_cmd(char _cmd_id, cmd_spi_cb_t cb, cmd_spi_rcb_t rcb, void* ctx,
|
|||||||
|
|
||||||
if (i == ARRAY_SIZE(cmd_spi_list))
|
if (i == ARRAY_SIZE(cmd_spi_list))
|
||||||
{
|
{
|
||||||
WARN("List Commands full!\n");
|
printk("List Commands full!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cmd_spi_list[i].cmd_id = _cmd_id;
|
cmd_spi_list[i].cmd_id = _cmd_id;
|
||||||
@ -762,6 +765,47 @@ cmd_spi_state_t get_reply_ipaddr_cb(char* recv, char* reply, void* ctx, uint16_t
|
|||||||
return SPI_CMD_DONE;
|
return SPI_CMD_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void foundHostByName(const char *name, struct ip_addr *ipaddr, void *callback_arg)
|
||||||
|
{
|
||||||
|
INFO_SPI("foundHostByName: Found Host: name=%s ip=0x%x\n", name, ipaddr->addr);
|
||||||
|
_hostIpAddr.addr = ipaddr->addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int req_reply_host_by_name_cb(int numParam, char* buf, void* ctx) {
|
||||||
|
|
||||||
|
char hostName[DNS_MAX_NAME_LENGTH];
|
||||||
|
tParam* params = (tParam*) buf;
|
||||||
|
|
||||||
|
// HostName
|
||||||
|
if (params->paramLen < DNS_MAX_NAME_LENGTH) {
|
||||||
|
memcpy(hostName, ¶ms->param, params->paramLen);
|
||||||
|
hostName[params->paramLen]='\0';
|
||||||
|
} else {
|
||||||
|
RETURN_ERR(WL_FAILURE)
|
||||||
|
}
|
||||||
|
|
||||||
|
_hostIpAddr.addr = 0;
|
||||||
|
err_t err = dns_gethostbyname(hostName, &_hostIpAddr, foundHostByName, NULL);
|
||||||
|
if (err == ERR_OK)
|
||||||
|
{
|
||||||
|
INFO_SPI("Found Host: name=%s ip=0x%x\n", hostName, _hostIpAddr.addr);
|
||||||
|
RETURN_ERR(WL_SUCCESS)
|
||||||
|
}
|
||||||
|
RETURN_ERR(WL_FAILURE)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_spi_state_t get_reply_host_by_name_cb(char* recv, char* reply, void* ctx, uint16_t* count) {
|
||||||
|
|
||||||
|
CHECK_ARD_NETIF(recv, reply, count);
|
||||||
|
|
||||||
|
CREATE_HEADER_REPLY(reply, recv, 1);
|
||||||
|
|
||||||
|
PUT_LONG_IN_BYTE_NO(_hostIpAddr.addr, reply, 3);
|
||||||
|
|
||||||
|
END_HEADER_REPLY(reply, 8, *count);
|
||||||
|
|
||||||
|
return SPI_CMD_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
cmd_spi_state_t get_reply_mac_cb(char* recv, char* reply, void* ctx, uint16_t* count) {
|
cmd_spi_state_t get_reply_mac_cb(char* recv, char* reply, void* ctx, uint16_t* count) {
|
||||||
|
|
||||||
@ -1231,7 +1275,8 @@ void init_spi_cmds() {
|
|||||||
spi_add_cmd(GET_IDX_ENCT_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_ENCT_CMD, CMD_GET_FLAG);
|
spi_add_cmd(GET_IDX_ENCT_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_ENCT_CMD, CMD_GET_FLAG);
|
||||||
spi_add_cmd(GET_IDX_SSID_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_SSID_CMD, CMD_GET_FLAG);
|
spi_add_cmd(GET_IDX_SSID_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_SSID_CMD, CMD_GET_FLAG);
|
||||||
spi_add_cmd(GET_IDX_RSSI_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_RSSI_CMD, CMD_GET_FLAG);
|
spi_add_cmd(GET_IDX_RSSI_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_RSSI_CMD, CMD_GET_FLAG);
|
||||||
|
spi_add_cmd(REQ_HOST_BY_NAME_CMD, req_reply_host_by_name_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
||||||
|
spi_add_cmd(GET_HOST_BY_NAME_CMD, ack_cmd_cb, get_reply_host_by_name_cb, NULL, CMD_GET_FLAG);
|
||||||
spi_add_cmd(START_SERVER_TCP_CMD, start_server_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
spi_add_cmd(START_SERVER_TCP_CMD, start_server_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
||||||
spi_add_cmd(START_CLIENT_TCP_CMD, start_client_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
spi_add_cmd(START_CLIENT_TCP_CMD, start_client_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
||||||
spi_add_cmd(STOP_CLIENT_TCP_CMD, stop_client_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
spi_add_cmd(STOP_CLIENT_TCP_CMD, stop_client_tcp_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
|
||||||
|
@ -61,6 +61,8 @@ cmd_state_t cmd_statSpi(int argc, char* argv[], void* ctx);
|
|||||||
|
|
||||||
cmd_state_t cmd_resetStatSpi(int argc, char* argv[], void* ctx);
|
cmd_state_t cmd_resetStatSpi(int argc, char* argv[], void* ctx);
|
||||||
|
|
||||||
|
cmd_state_t cmd_gethostbyname(int argc, char* argv[], void* ctx);
|
||||||
|
|
||||||
void showTTCPstatus();
|
void showTTCPstatus();
|
||||||
|
|
||||||
int getSock(void * _ttcp);
|
int getSock(void * _ttcp);
|
||||||
|
@ -232,6 +232,7 @@ static void atcp_conn_err_cb(void *arg, err_t err) {
|
|||||||
int sock = getSock(ttcp);
|
int sock = getSock(ttcp);
|
||||||
if (sock)
|
if (sock)
|
||||||
clearMapSockTcp(sock);
|
clearMapSockTcp(sock);
|
||||||
|
_connected = false;
|
||||||
ard_tcp_done(ttcp, err);
|
ard_tcp_done(ttcp, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "wl_util.h"
|
#include "wl_util.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
extern void showTTCPstatus();
|
extern void showTTCPstatus();
|
||||||
@ -175,6 +176,42 @@ cmd_setpass(int argc, char* argv[], void* ctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _DNS_CMD_
|
||||||
|
void foundHost(const char *name, struct ip_addr *ipaddr, void *callback_arg)
|
||||||
|
{
|
||||||
|
printk("Found Host: name=%s ip=0x%x\n", name, ipaddr->addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
cmd_state_t
|
||||||
|
cmd_gethostbyname(int argc, char* argv[], void* ctx)
|
||||||
|
{
|
||||||
|
const char *usage = "usage: getHost <hostname>\n";
|
||||||
|
char hostname[DNS_MAX_NAME_LENGTH];
|
||||||
|
struct ip_addr _addr;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
printk(usage);
|
||||||
|
return CMD_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = join_argv(hostname, sizeof hostname, argc - 1, argv + 1);
|
||||||
|
if (0 == len) {
|
||||||
|
return CMD_DONE;
|
||||||
|
}
|
||||||
|
err_t err = dns_gethostbyname(hostname, &_addr, foundHost, NULL);
|
||||||
|
if (err == ERR_OK)
|
||||||
|
{
|
||||||
|
printk("Found Host: name=%s ip=0x%x\n", hostname, _addr.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CMD_DONE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -37,11 +37,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
|
||||||
|
#define MAX_CMD_CONSOLE_NUM 9
|
||||||
struct {
|
struct {
|
||||||
cmd_cb_t cb;
|
cmd_cb_t cb;
|
||||||
const char* str;
|
const char* str;
|
||||||
void* ctx;
|
void* ctx;
|
||||||
} cmd_list[16] = { { 0 } };
|
} cmd_list[MAX_CMD_CONSOLE_NUM] = { { 0 } };
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
|
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
|
||||||
|
|
||||||
@ -53,15 +54,15 @@ struct {
|
|||||||
#error
|
#error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CMD_MAX_LEN
|
#ifndef CMD_CONSOLE_MAX_LEN
|
||||||
#define CMD_MAX_LEN 80
|
#define CMD_CONSOLE_MAX_LEN 25
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Bool is_initialized = FALSE;
|
static Bool is_initialized = FALSE;
|
||||||
|
|
||||||
char* console_gets()
|
char* console_gets()
|
||||||
{
|
{
|
||||||
static char buf[CMD_MAX_LEN];
|
static char buf[CMD_CONSOLE_MAX_LEN];
|
||||||
static int pos = 0;
|
static int pos = 0;
|
||||||
int c;
|
int c;
|
||||||
int status;
|
int status;
|
||||||
|
@ -329,7 +329,7 @@
|
|||||||
* LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
|
* LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
|
||||||
* transport.
|
* transport.
|
||||||
*/
|
*/
|
||||||
#define LWIP_DNS 0
|
#define LWIP_DNS 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "lwip/init.h"
|
#include "lwip/init.h"
|
||||||
#include "lwip/dhcp.h"
|
#include "lwip/dhcp.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
#include "lwip/tcp.h"
|
#include "lwip/tcp.h"
|
||||||
#include "netif/etharp.h"
|
#include "netif/etharp.h"
|
||||||
#include "netif/wlif.h"
|
#include "netif/wlif.h"
|
||||||
@ -77,7 +78,7 @@ void fw_download_cb(void* ctx, uint8_t** buf, uint32_t* len)
|
|||||||
|
|
||||||
struct ctx_server {
|
struct ctx_server {
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
uint8_t wl_init_complete;
|
//uint8_t wl_init_complete;
|
||||||
};
|
};
|
||||||
|
|
||||||
// to maintain the word alignment
|
// to maintain the word alignment
|
||||||
@ -87,7 +88,7 @@ struct ctx_server {
|
|||||||
static bool initSpiComplete = false;
|
static bool initSpiComplete = false;
|
||||||
|
|
||||||
// variable used as enable flag for debug prints
|
// variable used as enable flag for debug prints
|
||||||
uint16_t enableDebug = 0;
|
uint16_t enableDebug = 0; //INFO_WARN_FLAG;
|
||||||
uint16_t verboseDebug = 0;
|
uint16_t verboseDebug = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,18 +130,22 @@ dhcp_coarse_tmr_cb(void *ctx)
|
|||||||
dhcp_coarse_tmr();
|
dhcp_coarse_tmr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
dns_tmr_cb(void *ctx)
|
||||||
|
{
|
||||||
|
dns_tmr();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
wl_cm_scan_cb(void* ctx)
|
wl_cm_scan_cb(void* ctx)
|
||||||
{
|
{
|
||||||
struct ctx_server* hs = ctx;
|
|
||||||
|
|
||||||
uint8_t init = hs->wl_init_complete;
|
|
||||||
|
|
||||||
INFO_INIT("Scan networks...[ OK ] %d 0x%x\n", init);
|
|
||||||
|
|
||||||
set_result(WL_SCAN_COMPLETED);
|
set_result(WL_SCAN_COMPLETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +166,9 @@ wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
|
|||||||
|
|
||||||
INFO_INIT("Start DHCP...\n");
|
INFO_INIT("Start DHCP...\n");
|
||||||
dhcp_start(hs->netif);
|
dhcp_start(hs->netif);
|
||||||
|
|
||||||
|
INFO_INIT("Start DNS...\n");
|
||||||
|
dns_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -333,7 +341,9 @@ void initShell()
|
|||||||
console_add_cmd("spiStat", cmd_statSpi, NULL);
|
console_add_cmd("spiStat", cmd_statSpi, NULL);
|
||||||
console_add_cmd("resetSpiStat", cmd_resetStatSpi, NULL);
|
console_add_cmd("resetSpiStat", cmd_resetStatSpi, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef _DNS_CMD_
|
||||||
|
console_add_cmd("getHost", cmd_gethostbyname, NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -363,12 +373,14 @@ wl_init_complete_cb(void* ctx)
|
|||||||
etharp_tmr_cb, hs);
|
etharp_tmr_cb, hs);
|
||||||
timer_sched_timeout_cb(TCP_TMR_INTERVAL, TIMEOUT_PERIODIC,
|
timer_sched_timeout_cb(TCP_TMR_INTERVAL, TIMEOUT_PERIODIC,
|
||||||
tcp_tmr_cb, hs);
|
tcp_tmr_cb, hs);
|
||||||
timer_sched_timeout_cb(DHCP_FINE_TIMER_MSECS, TIMEOUT_PERIODIC,
|
timer_sched_timeout_cb(DHCP_FINE_TIMER_MSECS, TIMEOUT_PERIODIC,
|
||||||
dhcp_fine_tmr_cb, hs);
|
dhcp_fine_tmr_cb, hs);
|
||||||
timer_sched_timeout_cb(DHCP_COARSE_TIMER_MSECS, TIMEOUT_PERIODIC,
|
timer_sched_timeout_cb(DHCP_COARSE_TIMER_MSECS, TIMEOUT_PERIODIC,
|
||||||
dhcp_coarse_tmr_cb, hs);
|
dhcp_coarse_tmr_cb, hs);
|
||||||
|
// timer_sched_timeout_cb(DNS_TMR_INTERVAL, TIMEOUT_PERIODIC,
|
||||||
|
// dns_tmr_cb, NULL);
|
||||||
|
|
||||||
|
|
||||||
initShell();
|
|
||||||
|
|
||||||
if (initSpi())
|
if (initSpi())
|
||||||
WARN("Spi not initialized\n");
|
WARN("Spi not initialized\n");
|
||||||
@ -418,6 +430,8 @@ main(void)
|
|||||||
#else
|
#else
|
||||||
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__);
|
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__);
|
||||||
|
|
||||||
|
initShell();
|
||||||
|
|
||||||
size_t size_ctx_server = sizeof(struct ctx_server)+PAD_CTX_SIZE;
|
size_t size_ctx_server = sizeof(struct ctx_server)+PAD_CTX_SIZE;
|
||||||
hs = calloc(1, size_ctx_server);
|
hs = calloc(1, size_ctx_server);
|
||||||
ASSERT(hs, "out of memory");
|
ASSERT(hs, "out of memory");
|
||||||
|
@ -51,6 +51,8 @@ enum {
|
|||||||
GET_IDX_SSID_CMD = 0x31,
|
GET_IDX_SSID_CMD = 0x31,
|
||||||
GET_IDX_RSSI_CMD = 0x32,
|
GET_IDX_RSSI_CMD = 0x32,
|
||||||
GET_IDX_ENCT_CMD = 0x33,
|
GET_IDX_ENCT_CMD = 0x33,
|
||||||
|
REQ_HOST_BY_NAME_CMD= 0x34,
|
||||||
|
GET_HOST_BY_NAME_CMD= 0x35,
|
||||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||||
|
|
||||||
SEND_DATA_TCP_CMD = 0x44,
|
SEND_DATA_TCP_CMD = 0x44,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user