fix(mdns): im Standalone-Modus am AP-Netif anmelden, genutztes Netif protokollieren
This commit is contained in:
+48
-5
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "wm_include.h"
|
||||
#include "lwip/apps/mdns.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/tcpip.h"
|
||||
|
||||
#include "config/nl_settings.h"
|
||||
@@ -16,6 +17,7 @@
|
||||
#define NL_MDNS_TTL 120
|
||||
|
||||
static bool s_inited;
|
||||
static struct netif *s_nif; /* Netif, an dem Antwortdienst und Dienst haengen */
|
||||
static bool s_netif_added;
|
||||
static bool s_service_added;
|
||||
static char s_name[NL_NAME_LEN];
|
||||
@@ -45,15 +47,52 @@ static void txt_cb(struct mdns_service *service, void *data)
|
||||
add_txt(service, "name", name);
|
||||
}
|
||||
|
||||
/* Das SDK fuehrt zwei Netifs (wm_ethernet.c, Tcpip_stack_init): tls_get_netif() liefert das
|
||||
* der STATION; das des Softap wurde zuerst angelegt und haengt als ->next dahinter (dieselbe
|
||||
* Annahme treffen DHCPS_Start/DNSS_Start im SDK mit nif->next, ethernetif_input() mit
|
||||
* netif->next). Im Standalone-Modus gibt es keine Station, die Antworten muessen ueber das
|
||||
* AP-Netif gehen, sonst haengt der Dienst an einem Netif ohne Adresse und Funkstrecke. */
|
||||
static struct netif *pick_netif(void)
|
||||
{
|
||||
struct netif *sta = tls_get_netif();
|
||||
struct netif *n;
|
||||
|
||||
if (!sta)
|
||||
return NULL;
|
||||
if (!nl_wifi_is_standalone())
|
||||
return sta;
|
||||
/* Erst der bekannte Platz, dann zur Sicherheit die lwip-Kette: das erste Netif mit
|
||||
* IPv4-Adresse, das nicht die Station ist (Loopback gibt es in diesem SDK nicht). */
|
||||
if (sta->next && !ip4_addr_isany_val(*netif_ip4_addr(sta->next)))
|
||||
return sta->next;
|
||||
for (n = netif_list; n != NULL; n = n->next)
|
||||
if (n != sta && !ip4_addr_isany_val(*netif_ip4_addr(n)))
|
||||
return n;
|
||||
return NULL; /* AP-Netif noch ohne Adresse: lieber nichts melden als am falschen Netif */
|
||||
}
|
||||
|
||||
/* tcpip thread */
|
||||
static void announce(void *arg)
|
||||
{
|
||||
struct netif *nif = tls_get_netif();
|
||||
struct netif *nif = pick_netif();
|
||||
bool attempted = false;
|
||||
|
||||
(void)arg;
|
||||
if (!nif)
|
||||
if (!nif) {
|
||||
printf("mdns: no usable netif yet\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Anderes Netif als bisher (Station <-> eigener AP): ein blosses
|
||||
* mdns_resp_netif_settings_changed() wuerde am alten haengen bleiben, denn Antwortdienst
|
||||
* und Dienst sind je Netif angelegt. Also am alten Netif abmelden - remove_netif gibt auch
|
||||
* dessen Dienste und die Multicast-Gruppe frei - und am neuen frisch anmelden. */
|
||||
if (s_netif_added && s_nif != nif) {
|
||||
mdns_resp_remove_netif(s_nif);
|
||||
s_netif_added = false;
|
||||
s_service_added = false;
|
||||
}
|
||||
s_nif = nif;
|
||||
|
||||
if (!s_inited) {
|
||||
mdns_resp_init();
|
||||
@@ -69,9 +108,13 @@ static void announce(void *arg)
|
||||
NL_MDNS_TTL, txt_cb, NULL) == ERR_OK;
|
||||
}
|
||||
|
||||
if (attempted)
|
||||
printf("mdns: %s.local _ninlight._tcp %s\r\n", nl_wifi_hostname(), s_service_added ? "up" : "failed");
|
||||
else
|
||||
if (attempted) {
|
||||
/* Welches Netif benutzt wurde, steht in der Zeile selbst: Zeiger, Namenskuerzel, IPv4. */
|
||||
const ip4_addr_t *ip = netif_ip4_addr(nif);
|
||||
printf("mdns: %s.local _ninlight._tcp %s on %c%c%u %u.%u.%u.%u (%p)\r\n", nl_wifi_hostname(),
|
||||
s_service_added ? "up" : "failed", nif->name[0], nif->name[1], (unsigned)nif->num,
|
||||
ip4_addr1(ip), ip4_addr2(ip), ip4_addr3(ip), ip4_addr4(ip), (void *)nif);
|
||||
} else
|
||||
mdns_resp_netif_settings_changed(nif); /* re-announce: new IP or TXT */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user