diff --git a/ChangeLog b/ChangeLog index 9747c8c..df43c45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +R2406: +====== +- fix mDNS regression caused by IDF update + R2404: ====== - revert to IDF v5.1.1 (ESP32), due to console hang diff --git a/components/netsvc/udns.cpp b/components/netsvc/udns.cpp index ad76e95..91d107e 100644 --- a/components/netsvc/udns.cpp +++ b/components/netsvc/udns.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023, Thomas Maier-Komor + * Copyright (C) 2021-2024, Thomas Maier-Komor * Atrium Firmware Package for ESP * * This program is free software: you can redistribute it and/or modify @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -67,6 +68,7 @@ #define TYPE_HINFO 13 #define TYPE_TXT 16 #define TYPE_ADDR6 28 +#define CACHE_FLUSH 0x8000 #define SIZEOF_ANSWER 10 #define SIZEOF_HEADER 12 @@ -455,18 +457,16 @@ static int parseAnswer(struct pbuf *p, size_t off, const ip_addr_t *sender) } ip_addr_t ip = IPADDR4_INIT(0); char ipstr[64]; - // why mask bit 15? -// if (((a.rr_class & 0x7fff) == TYPE_ADDR) && (a.rdlen == 4)) { - if ((a.rr_class == TYPE_ADDR) && (a.rdlen == 4)) { + // mask bit 15, as it is the cache-flush-flag + if (((a.rr_class & 0x7fff) == TYPE_ADDR) && (a.rdlen == 4)) { if (4 != pbuf_copy_partial(p,ip_2_ip4(&ip),a.rdlen,off)) { log_devel(TAG,"copy1 failed"); return -off; } log_devel(TAG,"IPv4 %s",ip2str_r(&ip,ipstr,sizeof(ipstr))); -#if defined CONFIG_LWIP_IPV6 //|| defined ESP32 - // why mask bit 15? -// } else if (((a.rr_class & 0x7fff) == TYPE_ADDR) && (a.rdlen == 16)) { - } else if ((a.rr_class == TYPE_ADDR) && (a.rdlen == 16)) { +#if defined CONFIG_LWIP_IPV6 + // mask bit 15, as it is the cache-flush-flag + } else if (((a.rr_class & 0x7fff) == TYPE_ADDR) && (a.rdlen == 16)) { if (16 != pbuf_copy_partial(p,ip_2_ip6(&ip),a.rdlen,off)) { log_devel(TAG,"copy2 %d@0x%x failed",a.rdlen,off); return -off; @@ -477,7 +477,7 @@ static int parseAnswer(struct pbuf *p, size_t off, const ip_addr_t *sender) log_dbug(TAG,"ignoring PTR"); return off+a.rdlen; } else { - log_hex(TAG,&a,sizeof(a),"ignoring class 0x%x, len %d",a.rr_class,a.rdlen); + log_hex(TAG,&a,sizeof(a),"ignoring class 0x%x, len %d",a.rr_class&0x7fff,a.rdlen); return off+a.rdlen; } off += a.rdlen; @@ -518,8 +518,8 @@ static inline void sendOwnIp(uint8_t *q, uint16_t ql, uint16_t id, const ip_addr pkt += 7; Answert a; a.rr_type = htons(TYPE_ADDR); - a.rr_class = htons(CLASS_INET); - a.ttl = htonl(10000); + a.rr_class = htons(CLASS_INET|CACHE_FLUSH); + a.ttl = htonl(120); a.rdlen = htons(4); memcpy(pkt,&a,SIZEOF_ANSWER); pkt += SIZEOF_ANSWER; @@ -555,7 +555,7 @@ static inline void sendOwnIp(uint8_t *q, uint16_t ql, uint16_t id, const ip_addr static inline void sendOwnIp6(uint8_t *q, uint16_t ql, uint16_t id, const ip_addr_t *qip, uint16_t port) { -#if defined CONFIG_LWIP_IPV6 || defined CONFIG_IDF_TARGET_ESP32 || defined CONFIG_IDF_TARGET_ESP32S2 || defined CONFIG_IDF_TARGET_ESP32S3 || defined CONFIG_IDF_TARGET_ESP32C3 +#if defined CONFIG_LWIP_IPV6 // caller ensures: Ctx != 0, State == mdns_up if (ip6_addr_isany_val(IP6G)) return; @@ -741,6 +741,8 @@ static int parseQuestion(struct pbuf *p, size_t qoff, uint16_t id, const ip_addr qtype = ntohs(qtype); qclass = ntohs(qclass); log_devel(TAG,"question %d/%d: %s",qtype,qclass,hname); + if (0 == id) + id = ++Id; if ( ((qclass == CLASS_INET) && (0 == strcmp(hname,Hostname))) || ((0 == memcmp(hname,Hostname,HostnameLen)) && (0 == memcmp(hname+HostnameLen,".local",7)))) { log_devel(TAG,"question for this host"); @@ -779,12 +781,12 @@ static int skipQuestion(struct pbuf *p, size_t off) static void recv_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *ip, u16_t port) { -// log_hex(TAG,p->payload,p->len,"packet from %s",ip2str(ip)); if (Modules[0] || Modules[TAG]) { char ipstr[40]; if (ip) ip2str_r(ip,ipstr,sizeof(ipstr)); log_direct(ll_debug,TAG,"packet from %s",ip ? ipstr : ""); + //log_hex(TAG,p->payload,p->len,"packet from %s",ipstr); } Header h; if (p->len < sizeof(h)) { @@ -1030,6 +1032,7 @@ static err_t sendSelfQuery() assert(p->len == p->tot_len); bzero(p->payload,SIZEOF_HEADER); Header *hdr = (Header *)p->payload; + hdr->id = Id++; hdr->qcnt = htons(1); uint8_t *pkt = (uint8_t*)p->payload; size_t off = SIZEOF_HEADER; @@ -1165,13 +1168,22 @@ static void wifi_down(void *) static inline void mdns_init_fn(void *) { -#if 0 +#if IDF_VERSION >= 50 + esp_netif_t *nif = 0; + while (0 != (nif = esp_netif_next(nif))) { + esp_netif_ip_info_t ipconfig; + if (esp_err_t e = esp_netif_get_ip_info(nif,&ipconfig)) { + log_warn(TAG,"unable to get ip info for interface %p: %s",nif,esp_err_to_name(e)); + } else { + IP4.addr = ipconfig.ip.addr; + } + } +#else tcpip_adapter_ip_info_t ipconfig; assert(Mtx); - if (ESP_OK == tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipconfig)) { + if (ESP_OK == tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipconfig)) if (0 != ipconfig.ip.addr) IP4 = ipconfig.ip; - } #endif #if LWIP_IPV6 if (MPCB6 == 0) { @@ -1197,7 +1209,18 @@ static inline void mdns_init_fn(void *) IP_ADDR4(&mdns,224,0,0,251); if (err_t e = udp_connect(MPCB,&mdns,MDNS_PORT)) log_warn(TAG,"connect 224.0.0.251: %s",strlwiperr(e)); -#if 0 +#if IDF_VERSION >= 50 + esp_netif_t *nif = 0; + while (0 != (nif = esp_netif_next(nif))) { + esp_netif_ip_info_t ipconfig; + if (esp_err_t e = esp_netif_get_ip_info(nif,&ipconfig)) { + log_warn(TAG,"unable to get ip info for interface %p: %s",nif,esp_err_to_name(e)); + } else if (err_t e = igmp_joingroup((const ip4_addr_t*)&ipconfig.ip,ip_2_ip4(&mdns))) + log_warn(TAG,"unable to join MDNS group: %d",e); + else + log_dbug(TAG,"initialized MDNS"); + } +#else if (err_t e = igmp_joingroup(&ipconfig.ip,ip_2_ip4(&mdns))) log_warn(TAG,"unable to join MDNS group: %d",e); else diff --git a/main/console.cpp b/main/console.cpp index 6482994..8396fa2 100644 --- a/main/console.cpp +++ b/main/console.cpp @@ -123,8 +123,7 @@ extern "C" { void console_setup() { #ifdef CONFIG_USB_DIAGLOG - if (!HWConf.system().usb_diag()) - UsbDiag = 0; + UsbDiag = HWConf.system().usb_diag(); #endif uart_console_setup(); jtag_console_setup(); diff --git a/main/screen.cpp b/main/screen.cpp index b55e8e2..6d439c4 100644 --- a/main/screen.cpp +++ b/main/screen.cpp @@ -133,7 +133,7 @@ static bool mode_enabled(const char *mode) } -static const char *env_title(const char *path) +static inline const char *env_title(const char *path) { const auto &envs = Config.screen().envs(); #if 0 // compiler bug on ESP32-S3 @@ -141,8 +141,8 @@ static const char *env_title(const char *path) #else size_t n = envs.size(); for (int i = 0; i < n; ++i) { -#endif const auto &e = envs[i]; +#endif if (0 == strcmp(path,e.path().c_str())) { const auto &t = e.title(); if (!t.empty()) diff --git a/main/shell.cpp b/main/shell.cpp index dff8f00..3849709 100644 --- a/main/shell.cpp +++ b/main/shell.cpp @@ -2398,12 +2398,9 @@ static void print_ipinfo(Terminal &t, esp_netif_t *itf, esp_netif_ip_info_t *i) if (ESP_OK == esp_netif_get_mac(itf,mac)) t.printf("\tmac : %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); - esp_netif_ip_info_t ipconfig; - if (ESP_OK == esp_netif_get_ip_info(itf,&ipconfig)) { - ip4addr_ntoa_r((ip4_addr_t *)&i->ip.addr,ipstr,sizeof(ipstr)); - ip4addr_ntoa_r((ip4_addr_t *)&i->gw.addr,gwstr,sizeof(gwstr)); - t.printf("\tipv4 : %s/%d, gw: %s, %s\n",ipstr,m,gwstr,esp_netif_is_netif_up(itf) ? "up":"down"); - } + ip4addr_ntoa_r((ip4_addr_t *)&i->ip.addr,ipstr,sizeof(ipstr)); + ip4addr_ntoa_r((ip4_addr_t *)&i->gw.addr,gwstr,sizeof(gwstr)); + t.printf("\tipv4 : %s/%d, gw: %s, %s\n",ipstr,m,gwstr,esp_netif_is_netif_up(itf) ? "up":"down"); #if defined CONFIG_LWIP_IPV6 esp_ip6_addr_t ip6; if (ESP_OK == esp_netif_get_ip6_linklocal(itf,&ip6)) { @@ -2437,12 +2434,11 @@ static const char *ifconfig(Terminal &term, int argc, const char *args[]) return "Invalid number of arguments."; } #if IDF_VERSION >= 50 - esp_netif_t *nif = esp_netif_next(0); - while (nif) { + esp_netif_t *nif = 0; + while (0 != (nif = esp_netif_next(nif))) { esp_netif_ip_info_t ipconfig; if (ESP_OK == esp_netif_get_ip_info(nif,&ipconfig)) print_ipinfo(term, nif, &ipconfig); - nif = esp_netif_next(nif); } #else tcpip_adapter_ip_info_t ipconfig; diff --git a/main/startup.cpp b/main/startup.cpp index ea24607..79d3a17 100644 --- a/main/startup.cpp +++ b/main/startup.cpp @@ -334,9 +334,7 @@ void app_main() #endif fs_init(); -#ifdef CONFIG_UART_CONSOLE console_setup(); -#endif verify_heap(); event_start();