From 8c8218f878609af4719252d16ac0f42bccd9ba5b Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Mar 2021 19:37:18 +0000 Subject: add mdns responder --- app/Makefile | 3 ++- app/lwip/lwipopts.h | 5 +++++ app/lwip_glue.c | 12 ++++++++++++ app/project.h | 1 + app/steth.c | 8 ++++++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Makefile b/app/Makefile index 50ac75f..224f182 100644 --- a/app/Makefile +++ b/app/Makefile @@ -47,7 +47,8 @@ LWIP_API= \ LWIP_APPS= \ $(LWIPDIR)/apps/http/fs.c \ - $(LWIPDIR)/apps/http/httpd.c + $(LWIPDIR)/apps/http/httpd.c \ + $(MDNSFILES) # $(LWIPDIR)/apps/http/http_client.c \ diff --git a/app/lwip/lwipopts.h b/app/lwip/lwipopts.h index 7adba9c..b3e37c7 100644 --- a/app/lwip/lwipopts.h +++ b/app/lwip/lwipopts.h @@ -36,6 +36,8 @@ #define LWIP_TIMERS 1 +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NUM_NETIF_CLIENT_DATA 1 #if 0 #define SYS_DEBUG LWIP_DBG_ON @@ -215,6 +217,9 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums #define LWIP_HTTPD_FILE_STATE 0 #define LWIP_HTTPD_CGI 1 +#define LWIP_IGMP 1 +#define LWIP_MDNS_RESPONDER 1 + /* diff --git a/app/lwip_glue.c b/app/lwip_glue.c index b4370a2..d2dc4b5 100644 --- a/app/lwip_glue.c +++ b/app/lwip_glue.c @@ -14,6 +14,14 @@ void dispatch_lwip (void) } +static void if_status_changed (struct netif *netif) +{ + mdns_resp_netif_settings_changed (netif); +} + + + + void start_lwip (void) { @@ -22,6 +30,7 @@ void start_lwip (void) netif_add (&if0, NULL, NULL, NULL, NULL, steth_lwip_init, ethernet_input); + netif_set_status_callback (&if0, if_status_changed); /* Registers the default network interface.*/ netif_set_default (&if0); @@ -33,6 +42,9 @@ void start_lwip (void) httpd_init(); cgi_init(); + + mdns_resp_init(); + mdns_resp_add_netif (&if0, "clock", 5); } static sys_prot_t ethernet_irq_enabled = 1; diff --git a/app/project.h b/app/project.h index c2f9a56..9c1c6f1 100644 --- a/app/project.h +++ b/app/project.h @@ -56,6 +56,7 @@ #include #include +#include #include "time_fn.h" diff --git a/app/steth.c b/app/steth.c index 9245d17..b31bfe3 100644 --- a/app/steth.c +++ b/app/steth.c @@ -327,7 +327,7 @@ steth_lwip_init (struct netif *netif) netif->mtu = 1500; /* device capabilities */ - netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP; return ERR_OK; } @@ -338,7 +338,7 @@ static void my_eth_init (uint8_t phy, enum eth_clk clock) ETH_MACCR = ETH_MACCR_CSTF | ETH_MACCR_FES | ETH_MACCR_DM | ETH_MACCR_APCS | ETH_MACCR_RD; - ETH_MACFFR = ETH_MACFFR_RA | ETH_MACFFR_PM; + ETH_MACFFR = ETH_MACFFR_RA | ETH_MACFFR_PM | ETH_MACFFR_PAM; ETH_MACHTHR = 0; /* pass all frames */ ETH_MACHTLR = 0; ETH_MACFCR = (0x100 << ETH_MACFCR_PT_SHIFT); @@ -508,6 +508,7 @@ void steth_slow_tick (void) ETH_MACCR |= ETH_MACCR_RD; running = 0; + dhcp_stop (&if0); netif_set_link_down (&if0); } @@ -555,7 +556,10 @@ void steth_slow_tick (void) printf ("starting nic\r\n"); running++; + netif_set_link_up (&if0); + dhcp_start (&if0); + mdns_resp_restart (&if0); } // printf("end slow tick\r\n"); -- cgit v1.2.3