introduce dns
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include <dhcp.h>
|
||||
#include <show.h>
|
||||
#include <oled.h>
|
||||
#include <dns.h>
|
||||
|
||||
wiz_NetInfo netInfo = {
|
||||
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
||||
@ -20,7 +21,11 @@ wiz_NetInfo netInfo = {
|
||||
#define DHCP_BUFFER_SIZE 2048
|
||||
static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
|
||||
|
||||
#define DNS_BUFFER_SIZE MAX_DNS_BUF_SIZE
|
||||
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
|
||||
|
||||
extern const uint8_t DHCP_SOCK;
|
||||
extern const uint8_t DNS_SOCK;
|
||||
|
||||
static bool networkAvailable = false;
|
||||
|
||||
@ -109,7 +114,22 @@ static void wizDHCPHandler(void *handle) {
|
||||
}
|
||||
}
|
||||
|
||||
bool wizDnsQuery(char *name, uint8_t *ip) {
|
||||
bool retCode = false;
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, querying for %s", name);
|
||||
int8_t res = DNS_run(netInfo.dns, (uint8_t*) name, ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, DNS_run returns %d", res);
|
||||
retCode = (res == 1);
|
||||
if (retCode) {
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, got address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static void wizPhyLinkHandler(void *handle) {
|
||||
// this handler is anyhow called with a 1s period, so we reuse it for the DNS timer
|
||||
DNS_time_handler();
|
||||
|
||||
static uint8_t lastStablePhyLink = 255;
|
||||
static bool dhcpInitialized = false;
|
||||
|
||||
@ -153,6 +173,7 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int wizInit() {
|
||||
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
||||
wizReset(true);
|
||||
@ -196,6 +217,7 @@ int wizInit() {
|
||||
res = ctlwizchip(CW_GET_ID, (void*) buf);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
|
||||
DNS_init(DNS_SOCK, dnsBuffer);
|
||||
|
||||
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
||||
|
Reference in New Issue
Block a user