introduce dns
This commit is contained in:
parent
3e1a7946c2
commit
8894036679
@ -125,6 +125,7 @@ C_INCLUDES = \
|
|||||||
-Ilibmbus \
|
-Ilibmbus \
|
||||||
-IUser/Inc \
|
-IUser/Inc \
|
||||||
-IioLibrary_Driver/Internet/DHCP \
|
-IioLibrary_Driver/Internet/DHCP \
|
||||||
|
-IioLibrary_Driver/Internet/DNS \
|
||||||
-IioLibrary_Driver/Ethernet \
|
-IioLibrary_Driver/Ethernet \
|
||||||
-ICore/Inc \
|
-ICore/Inc \
|
||||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
int wizInit();
|
int wizInit();
|
||||||
bool isNetworkAvailable();
|
bool isNetworkAvailable();
|
||||||
uint8_t* wizGetIPAddress();
|
uint8_t* wizGetIPAddress();
|
||||||
|
bool wizDnsQuery(char *name, uint8_t *ip);
|
||||||
|
|
||||||
#endif // _WIZHELPER_H_
|
#endif // _WIZHELPER_H_
|
@ -92,6 +92,11 @@ void mqttCommHandler(void *handle) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
coloredMsg(LOG_GREEN, false, "mqch, resolving broker name");
|
||||||
|
if (! wizDnsQuery("mqttbroker", brokerAddress)) {
|
||||||
|
coloredMsg(LOG_GREEN, false, "mqch, query for broker address failed, going to error state");
|
||||||
|
state = 255;
|
||||||
|
}
|
||||||
coloredMsg(LOG_GREEN, false, "mqch, connecting to broker ");
|
coloredMsg(LOG_GREEN, false, "mqch, connecting to broker ");
|
||||||
bool res = mqttConnect(&mqttClient, brokerAddress, 1883, "mbv3gw-client", NULL, NULL, NULL, 0, false, NULL, false);
|
bool res = mqttConnect(&mqttClient, brokerAddress, 1883, "mbv3gw-client", NULL, NULL, NULL, 0, false, NULL, false);
|
||||||
coloredMsg(LOG_GREEN, false, "mqch, mqttConnect returns %d", res);
|
coloredMsg(LOG_GREEN, false, "mqch, mqttConnect returns %d", res);
|
||||||
|
@ -8,3 +8,4 @@ const uint8_t DHCP_SOCK = 0;
|
|||||||
const uint8_t MQTT_SOCK = 1;
|
const uint8_t MQTT_SOCK = 1;
|
||||||
const uint8_t CMD_SOCK = 2;
|
const uint8_t CMD_SOCK = 2;
|
||||||
const uint8_t SYSLOG_SOCK = 3;
|
const uint8_t SYSLOG_SOCK = 3;
|
||||||
|
const uint8_t DNS_SOCK = 4;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <dhcp.h>
|
#include <dhcp.h>
|
||||||
#include <show.h>
|
#include <show.h>
|
||||||
#include <oled.h>
|
#include <oled.h>
|
||||||
|
#include <dns.h>
|
||||||
|
|
||||||
wiz_NetInfo netInfo = {
|
wiz_NetInfo netInfo = {
|
||||||
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
||||||
@ -20,7 +21,11 @@ wiz_NetInfo netInfo = {
|
|||||||
#define DHCP_BUFFER_SIZE 2048
|
#define DHCP_BUFFER_SIZE 2048
|
||||||
static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
|
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 DHCP_SOCK;
|
||||||
|
extern const uint8_t DNS_SOCK;
|
||||||
|
|
||||||
static bool networkAvailable = false;
|
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) {
|
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 uint8_t lastStablePhyLink = 255;
|
||||||
static bool dhcpInitialized = false;
|
static bool dhcpInitialized = false;
|
||||||
|
|
||||||
@ -153,6 +173,7 @@ static void wizPhyLinkHandler(void *handle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wizInit() {
|
int wizInit() {
|
||||||
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
||||||
wizReset(true);
|
wizReset(true);
|
||||||
@ -196,6 +217,7 @@ int wizInit() {
|
|||||||
res = ctlwizchip(CW_GET_ID, (void*) buf);
|
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]);
|
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);
|
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||||
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
||||||
|
@ -84,6 +84,7 @@ cat $MAKEFILE_BAK | \
|
|||||||
sed -e 's,\(C_SOURCES = \\\),\1\n'"$SRC_EXT"' \\,' | \
|
sed -e 's,\(C_SOURCES = \\\),\1\n'"$SRC_EXT"' \\,' | \
|
||||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Ethernet \\,' | \
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Ethernet \\,' | \
|
||||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DHCP \\,' | \
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DHCP \\,' | \
|
||||||
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DNS \\,' | \
|
||||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' | \
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' | \
|
||||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ilibmbus \\,' | \
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ilibmbus \\,' | \
|
||||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ipubsubc/src \\,' | \
|
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ipubsubc/src \\,' | \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user