introduce dns

This commit is contained in:
Wolfgang Hottgenroth 2020-11-27 12:28:56 +01:00
parent 3e1a7946c2
commit 8894036679
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
6 changed files with 32 additions and 1 deletions

View File

@ -125,6 +125,7 @@ C_INCLUDES = \
-Ilibmbus \
-IUser/Inc \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Internet/DNS \
-IioLibrary_Driver/Ethernet \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \

View File

@ -4,9 +4,10 @@
#include <stdbool.h>
#include <stdint.h>
int wizInit();
bool isNetworkAvailable();
uint8_t* wizGetIPAddress();
bool wizDnsQuery(char *name, uint8_t *ip);
#endif // _WIZHELPER_H_

View File

@ -92,6 +92,11 @@ void mqttCommHandler(void *handle) {
break;
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 ");
bool res = mqttConnect(&mqttClient, brokerAddress, 1883, "mbv3gw-client", NULL, NULL, NULL, 0, false, NULL, false);
coloredMsg(LOG_GREEN, false, "mqch, mqttConnect returns %d", res);

View File

@ -8,3 +8,4 @@ const uint8_t DHCP_SOCK = 0;
const uint8_t MQTT_SOCK = 1;
const uint8_t CMD_SOCK = 2;
const uint8_t SYSLOG_SOCK = 3;
const uint8_t DNS_SOCK = 4;

View File

@ -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");

View File

@ -84,6 +84,7 @@ cat $MAKEFILE_BAK | \
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/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-Ilibmbus \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ipubsubc/src \\,' | \