wificfg: support mDNS on the softAP interface.

This commit is contained in:
Our Air Quality 2017-12-12 12:12:12 +11:00
parent 4c1dc2d60b
commit bf708d3fd3
3 changed files with 42 additions and 13 deletions

View file

@ -80,6 +80,9 @@
"<dt><label for=\"dns_en\">DNS enabled</label></dt>" "<dt><label for=\"dns_en\">DNS enabled</label></dt>"
"<dd><input id=\"dns_en\" type=\"checkbox\" name=\"ap_dns\" value=\"1\" ", "<dd><input id=\"dns_en\" type=\"checkbox\" name=\"ap_dns\" value=\"1\" ",
" /></dd>" " /></dd>"
"<dt><label for=\"dns_en\">mDNS enabled</label></dt>"
"<dd><input id=\"dns_en\" type=\"checkbox\" name=\"ap_mdns\" value=\"1\" ",
" /></dd>"
"</dl>" "</dl>"
"<center><input type=\"reset\">&nbsp;<input type=\"submit\" value=\"Save\"></center>" "<center><input type=\"reset\">&nbsp;<input type=\"submit\" value=\"Save\"></center>"
"</fieldset>" "</fieldset>"

View file

@ -60,7 +60,7 @@
"pattern=\"(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)_*(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)_*){3}\" " "pattern=\"(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)_*(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)_*){3}\" "
"name=\"sta_gateway\" placeholder=\"192.168.1.1\" value=\"", "name=\"sta_gateway\" placeholder=\"192.168.1.1\" value=\"",
"\"></dd>" "\"></dd>"
"<dt><label for=\"mdns\">Enable mDNS</label></dt>" "<dt><label for=\"mdns\">mDNS enabled</label></dt>"
"<dd><input id=\"mdns\" type=\"checkbox\" name=\"sta_mdns\" value=\"1\" ", "<dd><input id=\"mdns\" type=\"checkbox\" name=\"sta_mdns\" value=\"1\" ",
" /></dd>" " /></dd>"
"</dl>" "</dl>"

View file

@ -409,6 +409,7 @@ typedef enum {
FORM_NAME_AP_NETMASK, FORM_NAME_AP_NETMASK,
FORM_NAME_AP_DHCP_LEASES, FORM_NAME_AP_DHCP_LEASES,
FORM_NAME_AP_DNS, FORM_NAME_AP_DNS,
FORM_NAME_AP_MDNS,
FORM_NAME_DONE, FORM_NAME_DONE,
FORM_NAME_NONE FORM_NAME_NONE
} form_name; } form_name;
@ -443,6 +444,7 @@ static const struct {
{"ap_netmask", FORM_NAME_AP_NETMASK}, {"ap_netmask", FORM_NAME_AP_NETMASK},
{"ap_dhcp_leases", FORM_NAME_AP_DHCP_LEASES}, {"ap_dhcp_leases", FORM_NAME_AP_DHCP_LEASES},
{"ap_dns", FORM_NAME_AP_DNS}, {"ap_dns", FORM_NAME_AP_DNS},
{"ap_mdns", FORM_NAME_AP_MDNS},
{"done", FORM_NAME_DONE} {"done", FORM_NAME_DONE}
}; };
@ -1198,8 +1200,15 @@ static int handle_wifi_ap(int s, wificfg_method method,
int8_t wifi_ap_dns = 1; int8_t wifi_ap_dns = 1;
sysparam_get_int8("wifi_ap_dns", &wifi_ap_dns); sysparam_get_int8("wifi_ap_dns", &wifi_ap_dns);
if (wifi_ap_dns && wificfg_write_string_chunk(s, "checked", buf, len) < 0) return -1; if (wifi_ap_dns && wificfg_write_string_chunk(s, "checked", buf, len) < 0) return -1;
if (wificfg_write_string_chunk(s, http_wifi_ap_content[18], buf, len) < 0) return -1; if (wificfg_write_string_chunk(s, http_wifi_ap_content[18], buf, len) < 0) return -1;
int8_t wifi_ap_mdns = 1;
sysparam_get_int8("wifi_ap_mdns", &wifi_ap_mdns);
if (wifi_ap_mdns && wificfg_write_string_chunk(s, "checked", buf, len) < 0) return -1;
if (wificfg_write_string_chunk(s, http_wifi_ap_content[19], buf, len) < 0) return -1;
if (wificfg_write_chunk_end(s) < 0) return -1; if (wificfg_write_chunk_end(s) < 0) return -1;
} }
return 0; return 0;
@ -1226,6 +1235,7 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
uint8_t ap_disable_if_sta = 0; uint8_t ap_disable_if_sta = 0;
uint8_t ssid_hidden = 0; uint8_t ssid_hidden = 0;
uint8_t dns_enable = 0; uint8_t dns_enable = 0;
uint8_t mdns_enable = 0;
while (rem > 0) { while (rem > 0) {
ssize_t r = wificfg_form_name_value(s, &valp, &rem, buf, len); ssize_t r = wificfg_form_name_value(s, &valp, &rem, buf, len);
@ -1313,6 +1323,10 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
dns_enable = strtoul(buf, NULL, 10) != 0; dns_enable = strtoul(buf, NULL, 10) != 0;
break; break;
} }
case FORM_NAME_AP_MDNS: {
mdns_enable = strtoul(buf, NULL, 10) != 0;
break;
}
case FORM_NAME_DONE: case FORM_NAME_DONE:
done = true; done = true;
break; break;
@ -1327,6 +1341,7 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
sysparam_set_int8("wifi_ap_disable_if_sta", ap_disable_if_sta); sysparam_set_int8("wifi_ap_disable_if_sta", ap_disable_if_sta);
sysparam_set_int8("wifi_ap_ssid_hidden", ssid_hidden); sysparam_set_int8("wifi_ap_ssid_hidden", ssid_hidden);
sysparam_set_int8("wifi_ap_dns", dns_enable); sysparam_set_int8("wifi_ap_dns", dns_enable);
sysparam_set_int8("wifi_ap_mdns", mdns_enable);
} }
return wificfg_write_string(s, http_redirect_header); return wificfg_write_string(s, http_redirect_header);
@ -1656,10 +1671,8 @@ static void server_task(void *pvParameters)
{ {
char *hostname_local = NULL; char *hostname_local = NULL;
char *hostname = NULL; char *hostname = NULL;
int8_t wifi_sta_mdns = 1;
sysparam_get_string("hostname", &hostname); sysparam_get_string("hostname", &hostname);
sysparam_get_int8("wifi_sta_mdns", &wifi_sta_mdns);
if (hostname) { if (hostname) {
size_t len = strlen(hostname) + 6 + 1; size_t len = strlen(hostname) + 6 + 1;
hostname_local = (char *)malloc(len); hostname_local = (char *)malloc(len);
@ -1667,21 +1680,34 @@ static void server_task(void *pvParameters)
snprintf(hostname_local, len, "%s.local", hostname); snprintf(hostname_local, len, "%s.local", hostname);
} }
struct netif *netif = sdk_system_get_netif(STATION_IF); int8_t wifi_sta_mdns = 1;
if (wifi_sta_mdns && netif) { int8_t wifi_ap_mdns = 1;
sysparam_get_int8("wifi_sta_mdns", &wifi_sta_mdns);
sysparam_get_int8("wifi_ap_mdns", &wifi_ap_mdns);
struct netif *station_netif = sdk_system_get_netif(STATION_IF);
struct netif *softap_netif = sdk_system_get_netif(SOFTAP_IF);
if ((wifi_sta_mdns && station_netif) || (wifi_ap_mdns && softap_netif)) {
#if LWIP_MDNS_RESPONDER
mdns_resp_init();
#endif
#if EXTRAS_MDNS_RESPONDER #if EXTRAS_MDNS_RESPONDER
mdns_init(); mdns_init();
mdns_add_facility(hostname, "_http", NULL, mdns_TCP + mdns_Browsable, 80, 600); mdns_add_facility(hostname, "_http", NULL, mdns_TCP + mdns_Browsable, 80, 600);
#endif #endif
}
#if LWIP_MDNS_RESPONDER #if LWIP_MDNS_RESPONDER
mdns_resp_init(); if (wifi_sta_mdns && station_netif) {
if (netif) { mdns_resp_add_netif(station_netif, hostname, 120);
mdns_resp_add_netif(netif, hostname, 120); mdns_resp_add_service(station_netif, hostname, "_http",
mdns_resp_add_service(netif, hostname, "_http", DNSSD_PROTO_TCP, 80, 3600, NULL, NULL);
}
if (wifi_ap_mdns && softap_netif) {
mdns_resp_add_netif(softap_netif, hostname, 120);
mdns_resp_add_service(softap_netif, hostname, "_http",
DNSSD_PROTO_TCP, 80, 3600, NULL, NULL); DNSSD_PROTO_TCP, 80, 3600, NULL, NULL);
} }
#endif #endif
}
free(hostname); free(hostname);
} }