mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-30 06:59:02 +08:00
Merge branch 'feature/mdns_feature' into 'master'
Sync mDNS function from ESP-IDF See merge request sdk/ESP8266_RTOS_SDK!215
This commit is contained in:
9
components/mdns/CMakeLists.txt
Normal file
9
components/mdns/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
set(COMPONENT_SRCS "src/mdns.c"
|
||||
"src/mdns_console.c"
|
||||
"src/mdns_networking.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "include")
|
||||
set(COMPONENT_PRIV_INCLUDEDIRS "private_include")
|
||||
set(COMPONENT_REQUIRES lwip mbedtls console tcpip_adapter)
|
||||
|
||||
register_component()
|
||||
|
21
components/mdns/Kconfig
Normal file
21
components/mdns/Kconfig
Normal file
@ -0,0 +1,21 @@
|
||||
menu "mDNS"
|
||||
|
||||
config ENABLE_MDNS
|
||||
bool "Enable mDNS"
|
||||
default n
|
||||
select LWIP_IPV6
|
||||
help
|
||||
Enable this option and then mDNS is to be used.
|
||||
|
||||
config MDNS_MAX_SERVICES
|
||||
int "Max number of services"
|
||||
range 1 64
|
||||
default 10
|
||||
depends on ENABLE_MDNS
|
||||
help
|
||||
Services take up a certain amount of memory, and allowing fewer
|
||||
services to be open at the same time conserves memory. Specify
|
||||
the maximum amount of services here. The valid value is from 1
|
||||
to 64.
|
||||
|
||||
endmenu
|
6
components/mdns/component.mk
Normal file
6
components/mdns/component.mk
Normal file
@ -0,0 +1,6 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := private_include
|
||||
|
||||
ifdef CONFIG_ENABLE_MDNS
|
||||
COMPONENT_SRCDIRS := src
|
||||
endif
|
362
components/mdns/include/mdns.h
Normal file
362
components/mdns/include/mdns.h
Normal file
@ -0,0 +1,362 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef ESP_MDNS_H_
|
||||
#define ESP_MDNS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <tcpip_adapter.h>
|
||||
#include "esp_event.h"
|
||||
|
||||
#define MDNS_TYPE_A 0x0001
|
||||
#define MDNS_TYPE_PTR 0x000C
|
||||
#define MDNS_TYPE_TXT 0x0010
|
||||
#define MDNS_TYPE_AAAA 0x001C
|
||||
#define MDNS_TYPE_SRV 0x0021
|
||||
#define MDNS_TYPE_OPT 0x0029
|
||||
#define MDNS_TYPE_NSEC 0x002F
|
||||
#define MDNS_TYPE_ANY 0x00FF
|
||||
|
||||
/**
|
||||
* @brief mDNS enum to specify the ip_protocol type
|
||||
*/
|
||||
typedef enum {
|
||||
MDNS_IP_PROTOCOL_V4,
|
||||
MDNS_IP_PROTOCOL_V6,
|
||||
MDNS_IP_PROTOCOL_MAX
|
||||
} mdns_ip_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief mDNS basic text item structure
|
||||
* Used in mdns_service_add()
|
||||
*/
|
||||
typedef struct {
|
||||
char * key; /*!< item key name */
|
||||
char * value; /*!< item value string */
|
||||
} mdns_txt_item_t;
|
||||
|
||||
/**
|
||||
* @brief mDNS query linked list IP item
|
||||
*/
|
||||
typedef struct mdns_ip_addr_s {
|
||||
ip_addr_t addr; /*!< IP address */
|
||||
struct mdns_ip_addr_s * next; /*!< next IP, or NULL for the last IP in the list */
|
||||
} mdns_ip_addr_t;
|
||||
|
||||
/**
|
||||
* @brief mDNS query result structure
|
||||
*/
|
||||
typedef struct mdns_result_s {
|
||||
struct mdns_result_s * next; /*!< next result, or NULL for the last result in the list */
|
||||
|
||||
tcpip_adapter_if_t tcpip_if; /*!< interface on which the result came (AP/STA/ETH) */
|
||||
mdns_ip_protocol_t ip_protocol; /*!< ip_protocol type of the interface (v4/v6) */
|
||||
// PTR
|
||||
char * instance_name; /*!< instance name */
|
||||
// SRV
|
||||
char * hostname; /*!< hostname */
|
||||
uint16_t port; /*!< service port */
|
||||
// TXT
|
||||
mdns_txt_item_t * txt; /*!< txt record */
|
||||
size_t txt_count; /*!< number of txt items */
|
||||
// A and AAAA
|
||||
mdns_ip_addr_t * addr; /*!< linked list of IP addreses found */
|
||||
} mdns_result_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize mDNS on given interface
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG when bad tcpip_if is given
|
||||
* - ESP_ERR_INVALID_STATE when the network returned error
|
||||
* - ESP_ERR_NO_MEM on memory error
|
||||
* - ESP_ERR_WIFI_NOT_INIT when WiFi is not initialized by eps_wifi_init
|
||||
*/
|
||||
esp_err_t mdns_init();
|
||||
|
||||
/**
|
||||
* @brief Stop and free mDNS server
|
||||
*
|
||||
*/
|
||||
void mdns_free();
|
||||
|
||||
/**
|
||||
* @brief Set the hostname for mDNS server
|
||||
* required if you want to advertise services
|
||||
*
|
||||
* @param hostname Hostname to set
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_hostname_set(const char * hostname);
|
||||
|
||||
/**
|
||||
* @brief Set the default instance name for mDNS server
|
||||
*
|
||||
* @param instance_name Instance name to set
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_instance_name_set(const char * instance_name);
|
||||
|
||||
/**
|
||||
* @brief Add service to mDNS server
|
||||
*
|
||||
* @param instance_name instance name to set. If NULL,
|
||||
* global instance name or hostname will be used
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param port service port
|
||||
* @param num_items number of items in TXT data
|
||||
* @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_service_add(const char * instance_name, const char * service_type, const char * proto, uint16_t port, mdns_txt_item_t txt[], size_t num_items);
|
||||
|
||||
/**
|
||||
* @brief Remove service from mDNS server
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
* - ESP_FAIL unknown error
|
||||
*/
|
||||
esp_err_t mdns_service_remove(const char * service_type, const char * proto);
|
||||
|
||||
/**
|
||||
* @brief Set instance name for service
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param instance_name instance name to set
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_service_instance_name_set(const char * service_type, const char * proto, const char * instance_name);
|
||||
|
||||
/**
|
||||
* @brief Set service port
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param port service port
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
*/
|
||||
esp_err_t mdns_service_port_set(const char * service_type, const char * proto, uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief Replace all TXT items for service
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param num_items number of items in TXT data
|
||||
* @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_service_txt_set(const char * service_type, const char * proto, mdns_txt_item_t txt[], uint8_t num_items);
|
||||
|
||||
/**
|
||||
* @brief Set/Add TXT item for service TXT record
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param key the key that you want to add/update
|
||||
* @param value the new value of the key
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_service_txt_item_set(const char * service_type, const char * proto, const char * key, const char * value);
|
||||
|
||||
/**
|
||||
* @brief Remove TXT item for service TXT record
|
||||
*
|
||||
* @param service_type service type (_http, _ftp, etc)
|
||||
* @param proto service protocol (_tcp, _udp)
|
||||
* @param key the key that you want to remove
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_NOT_FOUND Service not found
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
*/
|
||||
esp_err_t mdns_service_txt_item_remove(const char * service_type, const char * proto, const char * key);
|
||||
|
||||
/**
|
||||
* @brief Remove and free all services from mDNS server
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t mdns_service_remove_all();
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for host or service
|
||||
* All following query methods are derived from this one
|
||||
*
|
||||
* @param name service instance or host name (NULL for PTR queries)
|
||||
* @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
|
||||
* @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
|
||||
* @param type type of query (MDNS_TYPE_*)
|
||||
* @param timeout time in milliseconds to wait for answers.
|
||||
* @param max_results maximum results to be collected
|
||||
* @param results pointer to the results of the query
|
||||
* results must be freed using mdns_query_results_free below
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG timeout was not given
|
||||
*/
|
||||
esp_err_t mdns_query(const char * name, const char * service_type, const char * proto, uint16_t type, uint32_t timeout, size_t max_results, mdns_result_t ** results);
|
||||
|
||||
/**
|
||||
* @brief Free query results
|
||||
*
|
||||
* @param results linked list of results to be freed
|
||||
*/
|
||||
void mdns_query_results_free(mdns_result_t * results);
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for service
|
||||
*
|
||||
* @param service_type service type (_http, _arduino, _ftp etc.)
|
||||
* @param proto service protocol (_tcp, _udp, etc.)
|
||||
* @param timeout time in milliseconds to wait for answer.
|
||||
* @param max_results maximum results to be collected
|
||||
* @param results pointer to the results of the query
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
*/
|
||||
esp_err_t mdns_query_ptr(const char * service_type, const char * proto, uint32_t timeout, size_t max_results, mdns_result_t ** results);
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for SRV record
|
||||
*
|
||||
* @param instance_name service instance name
|
||||
* @param service_type service type (_http, _arduino, _ftp etc.)
|
||||
* @param proto service protocol (_tcp, _udp, etc.)
|
||||
* @param timeout time in milliseconds to wait for answer.
|
||||
* @param result pointer to the result of the query
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
*/
|
||||
esp_err_t mdns_query_srv(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for TXT record
|
||||
*
|
||||
* @param instance_name service instance name
|
||||
* @param service_type service type (_http, _arduino, _ftp etc.)
|
||||
* @param proto service protocol (_tcp, _udp, etc.)
|
||||
* @param timeout time in milliseconds to wait for answer.
|
||||
* @param result pointer to the result of the query
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
*/
|
||||
esp_err_t mdns_query_txt(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for A record
|
||||
*
|
||||
* @param host_name host name to look for
|
||||
* @param timeout time in milliseconds to wait for answer.
|
||||
* @param addr pointer to the resulting IP4 address
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
*/
|
||||
esp_err_t mdns_query_a(const char * host_name, uint32_t timeout, ip4_addr_t * addr);
|
||||
|
||||
/**
|
||||
* @brief Query mDNS for A record
|
||||
*
|
||||
* @param host_name host name to look for
|
||||
* @param timeout time in milliseconds to wait for answer. If 0, max_results needs to be defined
|
||||
* @param addr pointer to the resulting IP6 address
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_STATE mDNS is not running
|
||||
* - ESP_ERR_NO_MEM memory error
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
*/
|
||||
esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, ip6_addr_t * addr);
|
||||
|
||||
/**
|
||||
* @brief System event handler
|
||||
* This method controls the service state on all active interfaces and applications are required
|
||||
* to call it from the system event handler for normal operation of mDNS service.
|
||||
*
|
||||
* @param ctx The system event context
|
||||
* @param event The system event
|
||||
*/
|
||||
esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ESP_MDNS_H_ */
|
22
components/mdns/include/mdns_console.h
Normal file
22
components/mdns/include/mdns_console.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef _MDNS_CONSOLE_H_
|
||||
#define _MDNS_CONSOLE_H_
|
||||
|
||||
/**
|
||||
* @brief Register MDNS functions with the console component
|
||||
*/
|
||||
void mdns_console_register();
|
||||
|
||||
#endif /* _MDNS_CONSOLE_H_ */
|
51
components/mdns/private_include/mdns_networking.h
Normal file
51
components/mdns/private_include/mdns_networking.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef ESP_MDNS_NETWORKING_H_
|
||||
#define ESP_MDNS_NETWORKING_H_
|
||||
|
||||
/*
|
||||
* MDNS Server Networking -- private include
|
||||
*
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/mld6.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "mdns.h"
|
||||
#include "mdns_private.h"
|
||||
|
||||
/**
|
||||
* @brief Queue RX packet action
|
||||
*/
|
||||
esp_err_t _mdns_send_rx_action(mdns_rx_packet_t * packet);
|
||||
|
||||
/**
|
||||
* @brief Start PCB
|
||||
*/
|
||||
esp_err_t _mdns_pcb_init(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol);
|
||||
|
||||
/**
|
||||
* @brief Stop PCB
|
||||
*/
|
||||
esp_err_t _mdns_pcb_deinit(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol);
|
||||
|
||||
/**
|
||||
* @brief send packet over UDP
|
||||
*
|
||||
* @param server The server
|
||||
* @param data byte array containing the packet data
|
||||
* @param len length of the packet data
|
||||
*
|
||||
* @return length of sent packet or 0 on error
|
||||
*/
|
||||
size_t _mdns_udp_pcb_write(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, const ip_addr_t *ip, uint16_t port, uint8_t * data, size_t len);
|
||||
|
||||
#endif /* ESP_MDNS_NETWORKING_H_ */
|
390
components/mdns/private_include/mdns_private.h
Normal file
390
components/mdns/private_include/mdns_private.h
Normal file
@ -0,0 +1,390 @@
|
||||
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef MDNS_PRIVATE_H_
|
||||
#define MDNS_PRIVATE_H_
|
||||
|
||||
//#define MDNS_ENABLE_DEBUG
|
||||
|
||||
#ifdef MDNS_ENABLE_DEBUG
|
||||
#define _mdns_dbg_printf(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/** The maximum number of services */
|
||||
#define MDNS_MAX_SERVICES CONFIG_MDNS_MAX_SERVICES
|
||||
|
||||
#define MDNS_ANSWER_PTR_TTL 4500
|
||||
#define MDNS_ANSWER_TXT_TTL 4500
|
||||
#define MDNS_ANSWER_SRV_TTL 120
|
||||
#define MDNS_ANSWER_A_TTL 120
|
||||
#define MDNS_ANSWER_AAAA_TTL 120
|
||||
|
||||
#define MDNS_FLAGS_AUTHORITATIVE 0x8400
|
||||
#define MDNS_FLAGS_DISTRIBUTED 0x0200
|
||||
|
||||
#define MDNS_NAME_REF 0xC000
|
||||
|
||||
//custom type! only used by this implementation
|
||||
//to help manage service discovery handling
|
||||
#define MDNS_TYPE_SDPTR 0x0032
|
||||
|
||||
#define MDNS_CLASS_IN 0x0001
|
||||
#define MDNS_CLASS_ANY 0x00FF
|
||||
#define MDNS_CLASS_IN_FLUSH_CACHE 0x8001
|
||||
|
||||
#define MDNS_ANSWER_ALL 0x3F
|
||||
#define MDNS_ANSWER_PTR 0x08
|
||||
#define MDNS_ANSWER_TXT 0x04
|
||||
#define MDNS_ANSWER_SRV 0x02
|
||||
#define MDNS_ANSWER_A 0x01
|
||||
#define MDNS_ANSWER_AAAA 0x10
|
||||
#define MDNS_ANSWER_NSEC 0x20
|
||||
#define MDNS_ANSWER_SDPTR 0x80
|
||||
|
||||
#define MDNS_SERVICE_PORT 5353 // UDP port that the server runs on
|
||||
#define MDNS_SERVICE_STACK_DEPTH 4096 // Stack size for the service thread
|
||||
#define MDNS_PACKET_QUEUE_LEN 16 // Maximum packets that can be queued for parsing
|
||||
#define MDNS_ACTION_QUEUE_LEN 16 // Maximum actions pending to the server
|
||||
#define MDNS_TXT_MAX_LEN 1024 // Maximum string length of text data in TXT record
|
||||
#define MDNS_NAME_MAX_LEN 64 // Maximum string length of hostname, instance, service and proto
|
||||
#define MDNS_NAME_BUF_LEN (MDNS_NAME_MAX_LEN+1) // Maximum char buffer size to hold hostname, instance, service or proto
|
||||
#define MDNS_MAX_PACKET_SIZE 1460 // Maximum size of mDNS outgoing packet
|
||||
|
||||
#define MDNS_HEAD_LEN 12
|
||||
#define MDNS_HEAD_ID_OFFSET 0
|
||||
#define MDNS_HEAD_FLAGS_OFFSET 2
|
||||
#define MDNS_HEAD_QUESTIONS_OFFSET 4
|
||||
#define MDNS_HEAD_ANSWERS_OFFSET 6
|
||||
#define MDNS_HEAD_SERVERS_OFFSET 8
|
||||
#define MDNS_HEAD_ADDITIONAL_OFFSET 10
|
||||
|
||||
#define MDNS_TYPE_OFFSET 0
|
||||
#define MDNS_CLASS_OFFSET 2
|
||||
#define MDNS_TTL_OFFSET 4
|
||||
#define MDNS_LEN_OFFSET 8
|
||||
#define MDNS_DATA_OFFSET 10
|
||||
|
||||
#define MDNS_SRV_PRIORITY_OFFSET 0
|
||||
#define MDNS_SRV_WEIGHT_OFFSET 2
|
||||
#define MDNS_SRV_PORT_OFFSET 4
|
||||
#define MDNS_SRV_FQDN_OFFSET 6
|
||||
|
||||
#define MDNS_TIMER_PERIOD_US 100000
|
||||
|
||||
#define MDNS_SERVICE_LOCK() xSemaphoreTake(_mdns_service_semaphore, portMAX_DELAY)
|
||||
#define MDNS_SERVICE_UNLOCK() xSemaphoreGive(_mdns_service_semaphore)
|
||||
|
||||
#define queueToEnd(type, queue, item) \
|
||||
if (!queue) { \
|
||||
queue = item; \
|
||||
} else { \
|
||||
type * _q = queue; \
|
||||
while (_q->next) { _q = _q->next; } \
|
||||
_q->next = item; \
|
||||
}
|
||||
|
||||
#define queueDetach(type, queue, item) \
|
||||
if (queue) { \
|
||||
if (queue == item) { \
|
||||
queue = queue->next; \
|
||||
} else { \
|
||||
type * _q = queue; \
|
||||
while (_q->next && _q->next != item) { \
|
||||
_q = _q->next; \
|
||||
} \
|
||||
if (_q->next == item) { \
|
||||
_q->next = item->next; \
|
||||
item->next = NULL; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define queueFree(type, queue) while (queue) { type * _q = queue; queue = queue->next; free(_q); }
|
||||
|
||||
#define PCB_STATE_IS_PROBING(s) (s->state > PCB_OFF && s->state < PCB_ANNOUNCE_1)
|
||||
#define PCB_STATE_IS_ANNOUNCING(s) (s->state > PCB_PROBE_3 && s->state < PCB_RUNNING)
|
||||
#define PCB_STATE_IS_RUNNING(s) (s->state == PCB_RUNNING)
|
||||
|
||||
#define MDNS_SEARCH_LOCK() xSemaphoreTake(_mdns_server->search.lock, portMAX_DELAY)
|
||||
#define MDNS_SEARCH_UNLOCK() xSemaphoreGive(_mdns_server->search.lock)
|
||||
|
||||
|
||||
typedef enum {
|
||||
PCB_OFF, PCB_DUP, PCB_INIT,
|
||||
PCB_PROBE_1, PCB_PROBE_2, PCB_PROBE_3,
|
||||
PCB_ANNOUNCE_1, PCB_ANNOUNCE_2, PCB_ANNOUNCE_3,
|
||||
PCB_RUNNING
|
||||
} mdns_pcb_state_t;
|
||||
|
||||
typedef enum {
|
||||
MDNS_ANSWER, MDNS_NS, MDNS_EXTRA
|
||||
} mdns_parsed_recort_type_t;
|
||||
|
||||
typedef enum {
|
||||
ACTION_SYSTEM_EVENT,
|
||||
ACTION_HOSTNAME_SET,
|
||||
ACTION_INSTANCE_SET,
|
||||
ACTION_SERVICE_ADD,
|
||||
ACTION_SERVICE_DEL,
|
||||
ACTION_SERVICE_INSTANCE_SET,
|
||||
ACTION_SERVICE_PORT_SET,
|
||||
ACTION_SERVICE_TXT_REPLACE,
|
||||
ACTION_SERVICE_TXT_SET,
|
||||
ACTION_SERVICE_TXT_DEL,
|
||||
ACTION_SERVICES_CLEAR,
|
||||
ACTION_SEARCH_ADD,
|
||||
ACTION_SEARCH_SEND,
|
||||
ACTION_SEARCH_END,
|
||||
ACTION_TX_HANDLE,
|
||||
ACTION_RX_HANDLE,
|
||||
ACTION_TASK_STOP,
|
||||
ACTION_MAX
|
||||
} mdns_action_type_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16_t id;
|
||||
union {
|
||||
struct {
|
||||
uint16_t qr :1;
|
||||
uint16_t opCode :4;
|
||||
uint16_t aa :1;
|
||||
uint16_t tc :1;
|
||||
uint16_t rd :1;
|
||||
uint16_t ra :1;
|
||||
uint16_t z :1;
|
||||
uint16_t ad :1;
|
||||
uint16_t cd :1;
|
||||
uint16_t rCode :4;//response/error code
|
||||
};
|
||||
uint16_t value;
|
||||
} flags;
|
||||
uint16_t questions; //QDCOUNT
|
||||
uint16_t answers; //ANCOUNT
|
||||
uint16_t servers; //NSCOUNT
|
||||
uint16_t additional;//ARCOUNT
|
||||
} mdns_header_t;
|
||||
|
||||
typedef struct {
|
||||
char host[MDNS_NAME_BUF_LEN];
|
||||
char service[MDNS_NAME_BUF_LEN];
|
||||
char proto[MDNS_NAME_BUF_LEN];
|
||||
char domain[MDNS_NAME_BUF_LEN];
|
||||
uint8_t parts;
|
||||
uint8_t sub;
|
||||
} mdns_name_t;
|
||||
|
||||
typedef struct mdns_parsed_question_s {
|
||||
struct mdns_parsed_question_s * next;
|
||||
uint16_t type;
|
||||
bool unicast;
|
||||
char * host;
|
||||
char * service;
|
||||
char * proto;
|
||||
char * domain;
|
||||
} mdns_parsed_question_t;
|
||||
|
||||
typedef struct mdns_parsed_record_s {
|
||||
struct mdns_parsed_record_s * next;
|
||||
mdns_parsed_recort_type_t record_type;
|
||||
uint16_t type;
|
||||
uint16_t clas;
|
||||
uint8_t flush;
|
||||
uint32_t ttl;
|
||||
char * host;
|
||||
char * service;
|
||||
char * proto;
|
||||
char * domain;
|
||||
uint16_t data_len;
|
||||
uint8_t *data;
|
||||
} mdns_parsed_record_t;
|
||||
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t tcpip_if;
|
||||
mdns_ip_protocol_t ip_protocol;
|
||||
//struct udp_pcb *pcb;
|
||||
ip_addr_t src;
|
||||
uint16_t src_port;
|
||||
uint8_t multicast;
|
||||
uint8_t authoritative;
|
||||
uint8_t probe;
|
||||
uint8_t discovery;
|
||||
uint8_t distributed;
|
||||
mdns_parsed_question_t * questions;
|
||||
mdns_parsed_record_t * records;
|
||||
} mdns_parsed_packet_t;
|
||||
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t tcpip_if;
|
||||
mdns_ip_protocol_t ip_protocol;
|
||||
struct pbuf *pb;
|
||||
ip_addr_t src;
|
||||
ip_addr_t dest;
|
||||
uint16_t src_port;
|
||||
uint8_t multicast;
|
||||
} mdns_rx_packet_t;
|
||||
|
||||
typedef struct mdns_txt_linked_item_s {
|
||||
const char * key; /*!< item key name */
|
||||
const char * value; /*!< item value string */
|
||||
struct mdns_txt_linked_item_s * next; /*!< next result, or NULL for the last result in the list */
|
||||
} mdns_txt_linked_item_t;
|
||||
|
||||
typedef struct {
|
||||
const char * instance;
|
||||
const char * service;
|
||||
const char * proto;
|
||||
uint16_t priority;
|
||||
uint16_t weight;
|
||||
uint16_t port;
|
||||
mdns_txt_linked_item_t * txt;
|
||||
} mdns_service_t;
|
||||
|
||||
typedef struct mdns_srv_item_s {
|
||||
struct mdns_srv_item_s * next;
|
||||
mdns_service_t * service;
|
||||
} mdns_srv_item_t;
|
||||
|
||||
typedef struct mdns_out_question_s {
|
||||
struct mdns_out_question_s * next;
|
||||
uint16_t type;
|
||||
uint8_t unicast;
|
||||
const char * host;
|
||||
const char * service;
|
||||
const char * proto;
|
||||
const char * domain;
|
||||
} mdns_out_question_t;
|
||||
|
||||
typedef struct mdns_out_answer_s {
|
||||
struct mdns_out_answer_s * next;
|
||||
uint16_t type;
|
||||
uint8_t bye;
|
||||
uint8_t flush;
|
||||
mdns_service_t * service;
|
||||
const char * custom_instance;
|
||||
const char * custom_service;
|
||||
const char * custom_proto;
|
||||
} mdns_out_answer_t;
|
||||
|
||||
typedef struct mdns_tx_packet_s {
|
||||
struct mdns_tx_packet_s * next;
|
||||
uint32_t send_at;
|
||||
tcpip_adapter_if_t tcpip_if;
|
||||
mdns_ip_protocol_t ip_protocol;
|
||||
ip_addr_t dst;
|
||||
uint16_t port;
|
||||
uint16_t flags;
|
||||
uint8_t distributed;
|
||||
mdns_out_question_t * questions;
|
||||
mdns_out_answer_t * answers;
|
||||
mdns_out_answer_t * servers;
|
||||
mdns_out_answer_t * additional;
|
||||
} mdns_tx_packet_t;
|
||||
|
||||
typedef struct {
|
||||
mdns_pcb_state_t state;
|
||||
struct udp_pcb * pcb;
|
||||
mdns_srv_item_t ** probe_services;
|
||||
uint8_t probe_services_len;
|
||||
uint8_t probe_ip;
|
||||
uint8_t probe_running;
|
||||
uint16_t failed_probes;
|
||||
} mdns_pcb_t;
|
||||
|
||||
typedef enum {
|
||||
SEARCH_OFF,
|
||||
SEARCH_INIT,
|
||||
SEARCH_RUNNING,
|
||||
SEARCH_MAX
|
||||
} mdns_search_once_state_t;
|
||||
|
||||
typedef struct mdns_search_once_s {
|
||||
struct mdns_search_once_s * next;
|
||||
|
||||
mdns_search_once_state_t state;
|
||||
uint32_t started_at;
|
||||
uint32_t sent_at;
|
||||
uint32_t timeout;
|
||||
SemaphoreHandle_t lock;
|
||||
uint16_t type;
|
||||
uint8_t max_results;
|
||||
uint8_t num_results;
|
||||
char * instance;
|
||||
char * service;
|
||||
char * proto;
|
||||
mdns_result_t * result;
|
||||
} mdns_search_once_t;
|
||||
|
||||
typedef struct mdns_server_s {
|
||||
struct {
|
||||
mdns_pcb_t pcbs[MDNS_IP_PROTOCOL_MAX];
|
||||
} interfaces[TCPIP_ADAPTER_IF_MAX];
|
||||
const char * hostname;
|
||||
const char * instance;
|
||||
mdns_srv_item_t * services;
|
||||
SemaphoreHandle_t lock;
|
||||
QueueHandle_t action_queue;
|
||||
mdns_tx_packet_t * tx_queue_head;
|
||||
mdns_search_once_t * search_once;
|
||||
esp_timer_handle_t timer_handle;
|
||||
} mdns_server_t;
|
||||
|
||||
typedef struct {
|
||||
mdns_action_type_t type;
|
||||
union {
|
||||
char * hostname;
|
||||
char * instance;
|
||||
struct {
|
||||
system_event_id_t event_id;
|
||||
tcpip_adapter_if_t interface;
|
||||
} sys_event;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
} srv_add;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
} srv_del;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
char * instance;
|
||||
} srv_instance;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
uint16_t port;
|
||||
} srv_port;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
mdns_txt_linked_item_t * txt;
|
||||
} srv_txt_replace;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
char * key;
|
||||
char * value;
|
||||
} srv_txt_set;
|
||||
struct {
|
||||
mdns_srv_item_t * service;
|
||||
char * key;
|
||||
} srv_txt_del;
|
||||
struct {
|
||||
mdns_search_once_t * search;
|
||||
} search_add;
|
||||
struct {
|
||||
mdns_tx_packet_t * packet;
|
||||
} tx_handle;
|
||||
struct {
|
||||
mdns_rx_packet_t * packet;
|
||||
} rx_handle;
|
||||
} data;
|
||||
} mdns_action_t;
|
||||
|
||||
#endif /* MDNS_PRIVATE_H_ */
|
4786
components/mdns/src/mdns.c
Normal file
4786
components/mdns/src/mdns.c
Normal file
File diff suppressed because it is too large
Load Diff
1061
components/mdns/src/mdns_console.c
Normal file
1061
components/mdns/src/mdns_console.c
Normal file
File diff suppressed because it is too large
Load Diff
308
components/mdns/src/mdns_networking.c
Normal file
308
components/mdns/src/mdns_networking.c
Normal file
@ -0,0 +1,308 @@
|
||||
|
||||
/*
|
||||
* MDNS Server Networking
|
||||
*
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "mdns_networking.h"
|
||||
|
||||
|
||||
extern mdns_server_t * _mdns_server;
|
||||
|
||||
/*
|
||||
* MDNS Server Networking
|
||||
*
|
||||
*/
|
||||
|
||||
static struct udp_pcb * _pcb_main = NULL;
|
||||
|
||||
static void _udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *pb, const ip_addr_t *raddr, uint16_t rport);
|
||||
|
||||
/**
|
||||
* @brief Low level UDP PCB Initialize
|
||||
*/
|
||||
static esp_err_t _udp_pcb_main_init()
|
||||
{
|
||||
if(_pcb_main) {
|
||||
return ESP_OK;
|
||||
}
|
||||
_pcb_main = udp_new();
|
||||
if (!_pcb_main) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
if (udp_bind(_pcb_main, IP_ANY_TYPE, MDNS_SERVICE_PORT) != 0) {
|
||||
udp_remove(_pcb_main);
|
||||
_pcb_main = NULL;
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
_pcb_main->mcast_ttl = 1;
|
||||
_pcb_main->remote_port = MDNS_SERVICE_PORT;
|
||||
ip_addr_copy(_pcb_main->remote_ip, ip_addr_any_type);
|
||||
udp_recv(_pcb_main, &_udp_recv, _mdns_server);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Low level UDP PCB Free
|
||||
*/
|
||||
static void _udp_pcb_main_deinit()
|
||||
{
|
||||
if(_pcb_main){
|
||||
udp_recv(_pcb_main, NULL, NULL);
|
||||
udp_disconnect(_pcb_main);
|
||||
udp_remove(_pcb_main);
|
||||
_pcb_main = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Low level UDP Multicast membership control
|
||||
*/
|
||||
static esp_err_t _udp_join_group(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, bool join)
|
||||
{
|
||||
struct netif * netif = NULL;
|
||||
void * nif = NULL;
|
||||
esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif);
|
||||
if (err) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
netif = (struct netif *)nif;
|
||||
|
||||
if (ip_protocol == MDNS_IP_PROTOCOL_V4) {
|
||||
ip_addr_t multicast_addr;
|
||||
IP_ADDR4(&multicast_addr, 224, 0, 0, 251);
|
||||
|
||||
if(join){
|
||||
if (igmp_joingroup_netif(netif, (const struct ip4_addr *)&multicast_addr.u_addr.ip4)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (igmp_leavegroup_netif(netif, (const struct ip4_addr *)&multicast_addr.u_addr.ip4)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ip_addr_t multicast_addr = IPADDR6_INIT(0x000002ff, 0, 0, 0xfb000000);
|
||||
|
||||
if(join){
|
||||
if (mld6_joingroup_netif(netif, &(multicast_addr.u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else {
|
||||
if (mld6_leavegroup_netif(netif, &(multicast_addr.u_addr.ip6))) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief the receive callback of the raw udp api. Packets are received here
|
||||
*
|
||||
*/
|
||||
static void _udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *pb, const ip_addr_t *raddr, uint16_t rport)
|
||||
{
|
||||
|
||||
uint8_t i;
|
||||
while (pb != NULL) {
|
||||
struct pbuf * this_pb = pb;
|
||||
pb = pb->next;
|
||||
this_pb->next = NULL;
|
||||
|
||||
mdns_rx_packet_t * packet = (mdns_rx_packet_t *)malloc(sizeof(mdns_rx_packet_t));
|
||||
if (!packet) {
|
||||
//missed packet - no memory
|
||||
pbuf_free(this_pb);
|
||||
continue;
|
||||
}
|
||||
|
||||
packet->tcpip_if = TCPIP_ADAPTER_IF_MAX;
|
||||
packet->pb = this_pb;
|
||||
packet->src_port = rport;
|
||||
memcpy(&packet->src, raddr, sizeof(ip_addr_t));
|
||||
packet->dest.type = packet->src.type;
|
||||
|
||||
if (packet->src.type == IPADDR_TYPE_V4) {
|
||||
packet->ip_protocol = MDNS_IP_PROTOCOL_V4;
|
||||
struct ip_hdr * iphdr = (struct ip_hdr *)(((uint8_t *)(packet->pb->payload)) - UDP_HLEN - IP_HLEN);
|
||||
packet->dest.u_addr.ip4.addr = iphdr->dest.addr;
|
||||
} else {
|
||||
packet->ip_protocol = MDNS_IP_PROTOCOL_V6;
|
||||
struct ip6_hdr * ip6hdr = (struct ip6_hdr *)(((uint8_t *)(packet->pb->payload)) - UDP_HLEN - IP6_HLEN);
|
||||
memcpy(&packet->dest.u_addr.ip6.addr, (uint8_t *)ip6hdr->dest.addr, 16);
|
||||
}
|
||||
packet->multicast = ip_addr_ismulticast(&(packet->dest));
|
||||
|
||||
//lwip does not return the proper pcb if you have more than one for the same multicast address (but different interfaces)
|
||||
struct netif * netif = NULL;
|
||||
void * nif = NULL;
|
||||
struct udp_pcb * pcb = NULL;
|
||||
for (i=0; i<TCPIP_ADAPTER_IF_MAX; i++) {
|
||||
pcb = _mdns_server->interfaces[i].pcbs[packet->ip_protocol].pcb;
|
||||
tcpip_adapter_get_netif (i, &nif);
|
||||
netif = (struct netif *)nif;
|
||||
if (pcb && netif && netif == ip_current_input_netif ()) {
|
||||
if (packet->src.type == IPADDR_TYPE_V4) {
|
||||
if ((packet->src.u_addr.ip4.addr & netif->netmask.u_addr.ip4.addr) != (netif->ip_addr.u_addr.ip4.addr & netif->netmask.u_addr.ip4.addr)) {
|
||||
//packet source is not in the same subnet
|
||||
pcb = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
packet->tcpip_if = i;
|
||||
break;
|
||||
}
|
||||
pcb = NULL;
|
||||
}
|
||||
|
||||
if (!pcb || !_mdns_server || !_mdns_server->action_queue
|
||||
|| _mdns_send_rx_action(packet) != ESP_OK) {
|
||||
pbuf_free(this_pb);
|
||||
free(packet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if any of the interfaces is up
|
||||
*/
|
||||
static bool _udp_pcb_is_in_use(){
|
||||
int i, p;
|
||||
for (i=0; i<TCPIP_ADAPTER_IF_MAX; i++) {
|
||||
for (p=0; p<MDNS_IP_PROTOCOL_MAX; p++) {
|
||||
if(_mdns_server->interfaces[i].pcbs[p].pcb){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop PCB Main code
|
||||
*/
|
||||
static void _udp_pcb_deinit(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
|
||||
{
|
||||
if (!_mdns_server) {
|
||||
return;
|
||||
}
|
||||
mdns_pcb_t * _pcb = &_mdns_server->interfaces[tcpip_if].pcbs[ip_protocol];
|
||||
if (_pcb->pcb) {
|
||||
free(_pcb->probe_services);
|
||||
_pcb->state = PCB_OFF;
|
||||
_pcb->pcb = NULL;
|
||||
_pcb->probe_ip = false;
|
||||
_pcb->probe_services = NULL;
|
||||
_pcb->probe_services_len = 0;
|
||||
_pcb->probe_running = false;
|
||||
_pcb->failed_probes = 0;
|
||||
_udp_join_group(tcpip_if, ip_protocol, false);
|
||||
if(!_udp_pcb_is_in_use()) {
|
||||
_udp_pcb_main_deinit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start PCB Main code
|
||||
*/
|
||||
static esp_err_t _udp_pcb_init(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
|
||||
{
|
||||
if (!_mdns_server || _mdns_server->interfaces[tcpip_if].pcbs[ip_protocol].pcb) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
esp_err_t err = _udp_join_group(tcpip_if, ip_protocol, true);
|
||||
if(err){
|
||||
return err;
|
||||
}
|
||||
|
||||
err = _udp_pcb_main_init();
|
||||
if(err){
|
||||
return err;
|
||||
}
|
||||
|
||||
_mdns_server->interfaces[tcpip_if].pcbs[ip_protocol].pcb = _pcb_main;
|
||||
_mdns_server->interfaces[tcpip_if].pcbs[ip_protocol].failed_probes = 0;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct tcpip_api_call_data call;
|
||||
tcpip_adapter_if_t tcpip_if;
|
||||
mdns_ip_protocol_t ip_protocol;
|
||||
esp_err_t err;
|
||||
} mdns_api_call_t;
|
||||
|
||||
/**
|
||||
* @brief Start PCB from LwIP thread
|
||||
*/
|
||||
static err_t _mdns_pcb_init_api(struct tcpip_api_call_data *api_call_msg)
|
||||
{
|
||||
mdns_api_call_t * msg = (mdns_api_call_t *)api_call_msg;
|
||||
msg->err = _udp_pcb_init(msg->tcpip_if, msg->ip_protocol);
|
||||
return msg->err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop PCB from LwIP thread
|
||||
*/
|
||||
static err_t _mdns_pcb_deinit_api(struct tcpip_api_call_data *api_call_msg)
|
||||
{
|
||||
mdns_api_call_t * msg = (mdns_api_call_t *)api_call_msg;
|
||||
_udp_pcb_deinit(msg->tcpip_if, msg->ip_protocol);
|
||||
msg->err = ESP_OK;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Non-static functions below are
|
||||
* - _mdns prefixed
|
||||
* - commented in mdns_networking.h header
|
||||
*/
|
||||
esp_err_t _mdns_pcb_init(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
|
||||
{
|
||||
mdns_api_call_t msg = {
|
||||
.tcpip_if = tcpip_if,
|
||||
.ip_protocol = ip_protocol
|
||||
};
|
||||
tcpip_api_call(_mdns_pcb_init_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
esp_err_t _mdns_pcb_deinit(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
|
||||
{
|
||||
mdns_api_call_t msg = {
|
||||
.tcpip_if = tcpip_if,
|
||||
.ip_protocol = ip_protocol
|
||||
};
|
||||
tcpip_api_call(_mdns_pcb_deinit_api, (struct tcpip_api_call_data*)&msg);
|
||||
return msg.err;
|
||||
}
|
||||
|
||||
size_t _mdns_udp_pcb_write(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, const ip_addr_t *ip, uint16_t port, uint8_t * data, size_t len)
|
||||
{
|
||||
struct netif * netif = NULL;
|
||||
void * nif = NULL;
|
||||
esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif);
|
||||
netif = (struct netif *)nif;
|
||||
if (err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct pbuf* pbt = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||
if (pbt == NULL) {
|
||||
return 0;
|
||||
}
|
||||
memcpy((uint8_t *)pbt->payload, data, len);
|
||||
|
||||
err = udp_sendto_if (_mdns_server->interfaces[tcpip_if].pcbs[ip_protocol].pcb, pbt, ip, port, netif);
|
||||
pbuf_free(pbt);
|
||||
if (err) {
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
43
components/mdns/test_afl_fuzz_host/Makefile
Normal file
43
components/mdns/test_afl_fuzz_host/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
TEST_NAME=test
|
||||
FUZZ=afl-fuzz
|
||||
COMPONENTS_DIR=../..
|
||||
CFLAGS=-g -DMDNS_TEST_MODE -I. -I.. -I../include -I../private_include -I$(COMPONENTS_DIR)/tcpip_adapter/include -I$(COMPONENTS_DIR)/esp32/include -include esp32_compat.h
|
||||
MDNS_C_DEPENDENCY_INJECTION=-include mdns_di.h
|
||||
ifeq ($(INSTR),off)
|
||||
CC=gcc
|
||||
CFLAGS+=-DINSTR_IS_OFF
|
||||
TEST_NAME=test_sim
|
||||
else
|
||||
CC=afl-clang-fast
|
||||
endif
|
||||
CPP=$(CC)
|
||||
LD=$(CC)
|
||||
OBJECTS=mdns.o esp32_mock.o test.o
|
||||
|
||||
OS := $(shell uname)
|
||||
ifeq ($(OS),Darwin)
|
||||
LDLIBS=
|
||||
else
|
||||
LDLIBS=-lbsd
|
||||
CFLAGS+=-DUSE_BSD_STRING
|
||||
endif
|
||||
|
||||
all: $(TEST_NAME)
|
||||
|
||||
%.o: %.c
|
||||
@echo "[CC] $<"
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
mdns.o: ../mdns.c
|
||||
@echo "[CC] $<"
|
||||
@$(CC) $(CFLAGS) $(MDNS_C_DEPENDENCY_INJECTION) -c $< -o $@
|
||||
|
||||
$(TEST_NAME): $(OBJECTS)
|
||||
@echo "[LD] $@"
|
||||
@$(LD) $(OBJECTS) -o $@ $(LDLIBS)
|
||||
|
||||
fuzz: $(TEST_NAME)
|
||||
@$(FUZZ) -i "in" -o "out" -- ./$(TEST_NAME)
|
||||
|
||||
clean:
|
||||
@rm -rf *.o *.SYM $(TEST_NAME) out
|
58
components/mdns/test_afl_fuzz_host/README.md
Normal file
58
components/mdns/test_afl_fuzz_host/README.md
Normal file
@ -0,0 +1,58 @@
|
||||
## Introduction
|
||||
This test uses [american fuzzy lop](http://lcamtuf.coredump.cx/afl/) to mangle real mdns packets and look for exceptions caused by the parser.
|
||||
|
||||
A few actuall packets are collected and exported as bins in the ```in``` folder, which is then passed as input to AFL when testing. The setup procedure for the test includes all possible services and scenarios that could be used with the given input packets. Output of the parser before fuzzing can be found in [input_packets.txt](input_packets.txt)
|
||||
|
||||
## Installing AFL
|
||||
To run the test yourself, you need to dounload the [latest afl archive](http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz) and extract it to a folder on your computer.
|
||||
|
||||
The rest of the document will refer to that folder as ```PATH_TO_AFL```.
|
||||
|
||||
### Preparation
|
||||
- On Mac, you will need to insall the latest Xcode and llvm support from [Homebrew](https://brew.sh)
|
||||
|
||||
```bash
|
||||
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
brew install --with-clang --with-lld --HEAD llvm
|
||||
export PATH="/usr/local/opt/llvm/bin:$PATH"
|
||||
```
|
||||
|
||||
- On Ubuntu you need the following packages:
|
||||
|
||||
```bash
|
||||
sudo apt-get install make clang llvm libbsd-dev
|
||||
```
|
||||
|
||||
### Compile AFL
|
||||
Compiling AFL is as easy as running make:
|
||||
|
||||
```bash
|
||||
cd [PATH_TO_AFL]
|
||||
make
|
||||
cd llvm_mode/
|
||||
make
|
||||
```
|
||||
|
||||
After successful compilation, you can export the following variables to your shell (you can also add them to your profile if you want to use afl in other projects)
|
||||
|
||||
```bash
|
||||
export AFL_PATH=[PATH_TO_AFL]
|
||||
export PATH="$AFL_PATH:$PATH"
|
||||
```
|
||||
|
||||
## Running the test
|
||||
Apple has a crash reporting service that could interfere with AFLs normal operation. To turn that off, run the following command:
|
||||
|
||||
```bash
|
||||
launchctl unload -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist
|
||||
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist
|
||||
```
|
||||
|
||||
Ubuntu has a similar service. To turn that off, run as root:
|
||||
|
||||
```bash
|
||||
echo core >/proc/sys/kernel/core_pattern
|
||||
```
|
||||
|
||||
After going through all of the requirements above, you can ```cd``` into this test's folder and simply run ```make fuzz```.
|
||||
|
240
components/mdns/test_afl_fuzz_host/esp32_compat.h
Normal file
240
components/mdns/test_afl_fuzz_host/esp32_compat.h
Normal file
@ -0,0 +1,240 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP32_COMPAT_H_
|
||||
#define _ESP32_COMPAT_H_
|
||||
|
||||
#ifdef MDNS_TEST_MODE
|
||||
|
||||
// Not to include
|
||||
#define ESP_MDNS_NETWORKING_H_
|
||||
#define _TCPIP_ADAPTER_H_
|
||||
#define __ESP_EVENT_H__
|
||||
|
||||
|
||||
#ifdef USE_BSD_STRING
|
||||
#include <bsd/string.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define CONFIG_MDNS_MAX_SERVICES 25
|
||||
|
||||
#define ERR_OK 0
|
||||
#define ESP_OK 0
|
||||
#define ESP_FAIL -1
|
||||
|
||||
#define ESP_ERR_NO_MEM 0x101
|
||||
#define ESP_ERR_INVALID_ARG 0x102
|
||||
#define ESP_ERR_INVALID_STATE 0x103
|
||||
#define ESP_ERR_INVALID_SIZE 0x104
|
||||
#define ESP_ERR_NOT_FOUND 0x105
|
||||
#define ESP_ERR_NOT_SUPPORTED 0x106
|
||||
#define ESP_ERR_TIMEOUT 0x107
|
||||
#define ESP_ERR_INVALID_RESPONSE 0x108
|
||||
#define ESP_ERR_INVALID_CRC 0x109
|
||||
|
||||
#define pdTRUE true
|
||||
#define pdFALSE false
|
||||
#define pdPASS ( pdTRUE )
|
||||
#define pdFAIL ( pdFALSE )
|
||||
|
||||
#define portMAX_DELAY 0xFFFFFFFF
|
||||
#define portTICK_PERIOD_MS 1
|
||||
|
||||
#define xSemaphoreTake(s,d)
|
||||
#define xTaskDelete(a)
|
||||
#define vTaskDelete(a) free(a)
|
||||
#define xSemaphoreGive(s)
|
||||
#define _mdns_pcb_init(a,b) true
|
||||
#define _mdns_pcb_deinit(a,b) true
|
||||
#define xSemaphoreCreateMutex() malloc(1)
|
||||
#define vSemaphoreDelete(s) free(s)
|
||||
#define xTaskCreatePinnedToCore(a,b,c,d,e,f,g) *(f) = malloc(1)
|
||||
#define vTaskDelay(m) usleep((m)*0)
|
||||
#define pbuf_free(p) free(p)
|
||||
#define esp_random() (rand()%UINT32_MAX)
|
||||
#define tcpip_adapter_get_ip_info(i,d) true
|
||||
#define tcpip_adapter_dhcpc_get_status(a, b) TCPIP_ADAPTER_DHCP_STARTED
|
||||
#define tcpip_adapter_get_ip6_linklocal(i,d) (ESP_OK)
|
||||
#define tcpip_adapter_get_hostname(i, n) *(n) = "esp32-0123456789AB"
|
||||
|
||||
#define IP4_ADDR(ipaddr, a,b,c,d) \
|
||||
(ipaddr)->addr = ((uint32_t)((d) & 0xff) << 24) | \
|
||||
((uint32_t)((c) & 0xff) << 16) | \
|
||||
((uint32_t)((b) & 0xff) << 8) | \
|
||||
(uint32_t)((a) & 0xff)
|
||||
#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
|
||||
#define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
|
||||
|
||||
#define IPADDR_TYPE_V4 0U
|
||||
#define IPADDR_TYPE_V6 6U
|
||||
#define IPADDR_TYPE_ANY 46U
|
||||
#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
|
||||
#define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \
|
||||
IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0)
|
||||
#define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \
|
||||
IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0)
|
||||
|
||||
#define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
|
||||
|
||||
typedef int32_t esp_err_t;
|
||||
|
||||
typedef void * xSemaphoreHandle;
|
||||
typedef void * SemaphoreHandle_t;
|
||||
typedef void * xQueueHandle;
|
||||
typedef void * QueueHandle_t;
|
||||
typedef void * TaskHandle_t;
|
||||
typedef void * esp_timer_handle_t;
|
||||
typedef uint32_t TickType_t;
|
||||
typedef uint32_t portTickType;
|
||||
|
||||
|
||||
typedef enum {
|
||||
WIFI_MODE_NULL = 0, /**< null mode */
|
||||
WIFI_MODE_STA, /**< WiFi station mode */
|
||||
WIFI_MODE_AP, /**< WiFi soft-AP mode */
|
||||
WIFI_MODE_APSTA, /**< WiFi station + soft-AP mode */
|
||||
WIFI_MODE_MAX
|
||||
} wifi_mode_t;
|
||||
|
||||
/* status of DHCP client or DHCP server */
|
||||
typedef enum {
|
||||
TCPIP_ADAPTER_DHCP_INIT = 0, /**< DHCP client/server in initial state */
|
||||
TCPIP_ADAPTER_DHCP_STARTED, /**< DHCP client/server already been started */
|
||||
TCPIP_ADAPTER_DHCP_STOPPED, /**< DHCP client/server already been stopped */
|
||||
TCPIP_ADAPTER_DHCP_STATUS_MAX
|
||||
} tcpip_adapter_dhcp_status_t;
|
||||
|
||||
typedef enum {
|
||||
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP32 WiFi ready */
|
||||
SYSTEM_EVENT_SCAN_DONE, /**< ESP32 finish scanning AP */
|
||||
SYSTEM_EVENT_STA_START, /**< ESP32 station start */
|
||||
SYSTEM_EVENT_STA_STOP, /**< ESP32 station stop */
|
||||
SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
|
||||
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */
|
||||
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */
|
||||
SYSTEM_EVENT_STA_GOT_IP, /**< ESP32 station got IP from connected AP */
|
||||
SYSTEM_EVENT_STA_LOST_IP, /**< ESP32 station lost IP and the IP is reset to 0 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */
|
||||
SYSTEM_EVENT_AP_START, /**< ESP32 soft-AP start */
|
||||
SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
|
||||
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
|
||||
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
|
||||
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
|
||||
SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
struct udp_pcb {
|
||||
uint8_t dummy;
|
||||
};
|
||||
|
||||
struct ip4_addr {
|
||||
uint32_t addr;
|
||||
};
|
||||
typedef struct ip4_addr ip4_addr_t;
|
||||
|
||||
struct ip6_addr {
|
||||
uint32_t addr[4];
|
||||
};
|
||||
typedef struct ip6_addr ip6_addr_t;
|
||||
|
||||
typedef struct _ip_addr {
|
||||
union {
|
||||
ip6_addr_t ip6;
|
||||
ip4_addr_t ip4;
|
||||
} u_addr;
|
||||
uint8_t type;
|
||||
} ip_addr_t;
|
||||
|
||||
typedef struct {
|
||||
ip4_addr_t ip;
|
||||
ip4_addr_t netmask;
|
||||
ip4_addr_t gw;
|
||||
} tcpip_adapter_ip_info_t;
|
||||
|
||||
// typedef int32_t system_event_id_t;
|
||||
typedef enum {
|
||||
TCPIP_ADAPTER_IF_STA = 0, /**< ESP32 station interface */
|
||||
TCPIP_ADAPTER_IF_AP, /**< ESP32 soft-AP interface */
|
||||
TCPIP_ADAPTER_IF_ETH, /**< ESP32 ethernet interface */
|
||||
TCPIP_ADAPTER_IF_MAX
|
||||
} tcpip_adapter_if_t;
|
||||
|
||||
typedef struct {
|
||||
ip6_addr_t ip;
|
||||
} tcpip_adapter_ip6_info_t;
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t if_index;
|
||||
tcpip_adapter_ip6_info_t ip6_info;
|
||||
} system_event_got_ip6_t;
|
||||
typedef union {
|
||||
system_event_got_ip6_t got_ip6; /**< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
|
||||
} system_event_info_t;
|
||||
|
||||
typedef struct {
|
||||
system_event_id_t event_id; /**< event ID */
|
||||
system_event_info_t event_info; /**< event information */
|
||||
} system_event_t;
|
||||
|
||||
inline esp_err_t esp_wifi_get_mode(wifi_mode_t * mode)
|
||||
{
|
||||
*mode = WIFI_MODE_APSTA;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
struct pbuf {
|
||||
struct pbuf *next;
|
||||
void *payload;
|
||||
uint16_t tot_len;
|
||||
uint16_t len;
|
||||
uint8_t /*pbuf_type*/ type;
|
||||
uint8_t flags;
|
||||
uint16_t ref;
|
||||
};
|
||||
|
||||
#define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
|
||||
#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
|
||||
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
|
||||
#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
|
||||
(dest).addr[1] = (src).addr[1]; \
|
||||
(dest).addr[2] = (src).addr[2]; \
|
||||
(dest).addr[3] = (src).addr[3];}while(0)
|
||||
|
||||
#define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
|
||||
ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
|
||||
ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
|
||||
|
||||
#include "esp32_mock.h"
|
||||
|
||||
uint32_t xTaskGetTickCount();
|
||||
|
||||
|
||||
#endif //MDNS_TEST_MODE
|
||||
|
||||
#endif //_ESP32_COMPAT_H_
|
84
components/mdns/test_afl_fuzz_host/esp32_mock.c
Normal file
84
components/mdns/test_afl_fuzz_host/esp32_mock.c
Normal file
@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "esp32_compat.h"
|
||||
|
||||
void* g_queue;
|
||||
int g_queue_send_shall_fail = 0;
|
||||
int g_size = 0;
|
||||
|
||||
esp_err_t esp_timer_delete(esp_timer_handle_t timer)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_timer_stop(esp_timer_handle_t timer)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_timer_create(const esp_timer_create_args_t* create_args,
|
||||
esp_timer_handle_t* out_handle)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint32_t xTaskGetTickCount()
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
if (gettimeofday(&tv, &tz) == 0) {
|
||||
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Queue mock
|
||||
QueueHandle_t xQueueCreate( uint32_t uxQueueLength, uint32_t uxItemSize )
|
||||
{
|
||||
g_size = uxItemSize;
|
||||
g_queue = malloc((uxQueueLength)*(uxItemSize));
|
||||
return g_queue;
|
||||
}
|
||||
|
||||
|
||||
void vQueueDelete( QueueHandle_t xQueue )
|
||||
{
|
||||
free(xQueue);
|
||||
}
|
||||
|
||||
uint32_t xQueueSend(QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait)
|
||||
{
|
||||
if (g_queue_send_shall_fail)
|
||||
{
|
||||
return pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(xQueue, pvItemToQueue, g_size);
|
||||
return pdPASS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
|
||||
{
|
||||
return pdFALSE;
|
||||
}
|
||||
|
||||
void GetLastItem(void *pvBuffer)
|
||||
{
|
||||
memcpy(pvBuffer, g_queue, g_size);
|
||||
}
|
||||
|
||||
void ForceTaskDelete()
|
||||
{
|
||||
g_queue_send_shall_fail = 1;
|
||||
}
|
45
components/mdns/test_afl_fuzz_host/esp32_mock.h
Normal file
45
components/mdns/test_afl_fuzz_host/esp32_mock.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef ESP32_MOCK_H_
|
||||
#define ESP32_MOCK_H_
|
||||
|
||||
typedef void (*esp_timer_cb_t)(void* arg);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ESP_TIMER_TASK, //!< Callback is called from timer task
|
||||
} esp_timer_dispatch_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
esp_timer_cb_t callback; //!< Function to call when timer expires
|
||||
void* arg; //!< Argument to pass to the callback
|
||||
esp_timer_dispatch_t dispatch_method; //!< Call the callback from task or from ISR
|
||||
const char* name; //!< Timer name, used in esp_timer_dump function
|
||||
} esp_timer_create_args_t;
|
||||
|
||||
esp_err_t esp_timer_delete(esp_timer_handle_t timer);
|
||||
|
||||
esp_err_t esp_timer_stop(esp_timer_handle_t timer);
|
||||
|
||||
esp_err_t esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period);
|
||||
|
||||
esp_err_t esp_timer_create(const esp_timer_create_args_t* create_args,
|
||||
esp_timer_handle_t* out_handle);
|
||||
|
||||
|
||||
// Queue mock
|
||||
QueueHandle_t xQueueCreate( uint32_t uxQueueLength,
|
||||
uint32_t uxItemSize );
|
||||
|
||||
void vQueueDelete( QueueHandle_t xQueue );
|
||||
|
||||
uint32_t xQueueSend(QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait);
|
||||
|
||||
uint32_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait);
|
||||
|
||||
void GetLastItem(void *pvBuffer);
|
||||
|
||||
void ForceTaskDelete();
|
||||
|
||||
#define _mdns_udp_pcb_write(tcpip_if, ip_protocol, ip, port, data, len) len
|
||||
|
||||
#endif /* ESP32_MOCK_H_ */
|
BIN
components/mdns/test_afl_fuzz_host/in/test-14.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-14.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-15.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-15.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-16.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-16.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-28.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-28.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-29.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-29.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-31.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-31.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-53.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-53.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-56.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-56.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-63.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-63.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-83.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-83.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-88.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-88.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-89.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-89.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-95.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-95.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/test-96.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/test-96.bin
Normal file
Binary file not shown.
166
components/mdns/test_afl_fuzz_host/input_packets.txt
Normal file
166
components/mdns/test_afl_fuzz_host/input_packets.txt
Normal file
@ -0,0 +1,166 @@
|
||||
Input: in/test-14.bin
|
||||
Packet Length: 568
|
||||
Questions: 18
|
||||
Q: _airport._tcp.local. PTR IN
|
||||
Q: _http._tcp.local. PTR IN
|
||||
Q: _printer._tcp.local. PTR IN
|
||||
Q: _sub._http._tcp.local. PTR IN
|
||||
Q: _airplay._tcp.local. PTR IN
|
||||
Q: _raop._tcp.local. PTR IN
|
||||
Q: _uscan._tcp.local. PTR IN
|
||||
Q: _uscans._tcp.local. PTR IN
|
||||
Q: _ippusb._tcp.local. PTR IN
|
||||
Q: _scanner._tcp.local. PTR IN
|
||||
Q: _ipp._tcp.local. PTR IN
|
||||
Q: _ipps._tcp.local. PTR IN
|
||||
Q: _pdl-datastream._tcp.local. PTR IN
|
||||
Q: _ptp._tcp.local. PTR IN
|
||||
Q: _sleep-proxy._udp.local. PTR IN
|
||||
Q: 9801A7E58FA1@Hristo's AirPort Express._raop._tcp.local. TXT IN
|
||||
Q: Hristo's AirPort Express._airport._tcp.local. TXT IN
|
||||
Q: Hristo's Time Capsule._airport._tcp.local. TXT IN
|
||||
Answers: 7 + 0
|
||||
A: _airport._tcp.local. PTR IN 2272 [2] Hristo's AirPort Express._airport._tcp.local.
|
||||
A: _airport._tcp.local. PTR IN 2272 [2] Hristo's Time Capsule._airport._tcp.local.
|
||||
A: _http._tcp.local. PTR IN 2535 [23] HP LaserJet CP1025nw._http._tcp.local.
|
||||
A: _printer._tcp.local. PTR IN 2535 [23] HP LaserJet CP1025nw._printer._tcp.local.
|
||||
A: _ipp._tcp.local. PTR IN 2535 [23] HP LaserJet CP1025nw._ipp._tcp.local.
|
||||
A: _pdl-datastream._tcp.local. PTR IN 2535 [23] HP LaserJet CP1025nw._pdl-datastream._tcp.local.
|
||||
A: _sleep-proxy._udp.local. PTR IN 2535 [38] 50-34-10-70.1 Hristo's Time Capsule._sleep-proxy._udp.local.
|
||||
|
||||
Input: in/test-15.bin
|
||||
Packet Length: 524
|
||||
Answers: 3 + 3
|
||||
A: Hristo's AirPort Express._airport._tcp.local. TXT IN FLUSH 4500 [166] waMA=98-01-A7-E5-8F-A1,raMA=98-01-A7-E8-C2-2E,raM2=98-01-A7-E8-C2-2F,raNm=your-ssid,raCh=1,rCh2=52,raSt=0,raNA=1,syFl=0x8A0C,syAP=115,syVs=7.6.8,srcv=76800.1,bjSd=23
|
||||
A: 9801A7E58FA1@Hristo's AirPort Express._raop._tcp.local. TXT IN FLUSH 4500 [134] txtvers=1; ch=2; cn=0,1; et=0,4; sv=false; da=true; sr=44100; ss=16; pw=false; vn=65537; tp=TCP,UDP; vs=105.1; am=AirPort10,115; fv=76800.1; sf=0x1
|
||||
A: _raop._tcp.local. PTR IN 4500 [2] 9801A7E58FA1@Hristo's AirPort Express._raop._tcp.local.
|
||||
A: 9801A7E58FA1@Hristo's AirPort Express._raop._tcp.local. SRV IN FLUSH 120 [32] 5000 Hristos-AirPort-Express.local.
|
||||
A: Hristo's AirPort Express.local. NSEC IN FLUSH 4500 [9] Hristo's AirPort Express._airport._tcp.local. 00 05 00 00 80 00 40
|
||||
A: 9801A7E58FA1@Hristo's AirPort Express.local. NSEC IN FLUSH 4500 [9] 9801A7E58FA1@Hristo's AirPort Express._raop._tcp.local. 00 05 00 00 80 00 40
|
||||
|
||||
Input: in/test-16.bin
|
||||
Packet Length: 254
|
||||
Answers: 1 + 1
|
||||
A: Hristo's Time Capsule._airport._tcp.local. TXT IN FLUSH 4500 [168] waMA=70-73-CB-B4-C9-B3,raMA=70-73-CB-BB-04-E7,raM2=70-73-CB-BB-04-E8,raNm=nbis-test,raCh=11,rCh2=132,raSt=0,raNA=0,syFl=0x820C,syAP=116,syVs=7.6.8,srcv=76800.1,bjSd=30
|
||||
A: Hristo's Time Capsule.local. NSEC IN FLUSH 4500 [9] Hristo's Time Capsule._airport._tcp.local. 00 05 00 00 80 00 40
|
||||
|
||||
Input: in/test-28.bin
|
||||
Packet Length: 62
|
||||
Questions: 1
|
||||
Q: Hristo's Time Capsule._afpovertcp._tcp.local. SRV IN FLUSH
|
||||
|
||||
Input: in/test-29.bin
|
||||
Packet Length: 39
|
||||
Questions: 2
|
||||
Q: minifritz.local. A IN FLUSH
|
||||
Q: minifritz.local. AAAA IN FLUSH
|
||||
|
||||
Input: in/test-31.bin
|
||||
Packet Length: 91
|
||||
Answers: 2 + 1
|
||||
A: minifritz.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:142e:54ff:b8c4:fd09
|
||||
A: minifritz.local. A IN FLUSH 120 [4] 192.168.254.16
|
||||
A: minifritz.local. NSEC IN FLUSH 120 [8] minifritz...local. 00 04 40 00 00 08
|
||||
|
||||
Input: in/test-53.bin
|
||||
Packet Length: 140
|
||||
Questions: 2
|
||||
Q: _smb._tcp.local. PTR IN
|
||||
Q: Sofiya-Ivanovas-MacBook.local. A IN
|
||||
Answers: 2 + 0
|
||||
A: _smb._tcp.local. PTR IN 3061 [29] Sofiya Ivanova’s MacBook._smb._tcp.local.
|
||||
A: _smb._tcp.local. PTR IN 3062 [24] Hristo's Time Capsule._smb._tcp.local.
|
||||
|
||||
Input: in/test-56.bin
|
||||
Packet Length: 262
|
||||
Answers: 2 + 6
|
||||
A: Hristo’s Mac mini._device-info._tcp.local. TXT IN 4500 [28] model=Macmini6,2; osxvers=16
|
||||
A: _smb._tcp.local. PTR IN 4500 [22] Hristo’s Mac mini._smb._tcp.local.
|
||||
A: Hristo’s Mac mini._smb._tcp.local. TXT IN FLUSH 4500 [1]
|
||||
A: Hristo’s Mac mini._smb._tcp.local. SRV IN FLUSH 120 [18] 445 minifritz.local.
|
||||
A: minifritz.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:142e:54ff:b8c4:fd09
|
||||
A: minifritz.local. A IN FLUSH 120 [4] 192.168.254.16
|
||||
A: Hristo’s Mac mini.local. NSEC IN FLUSH 4500 [9] Hristo’s Mac mini._smb._tcp.local. 00 05 00 00 80 00 40
|
||||
A: minifritz.local. NSEC IN FLUSH 120 [8] minifritz...local. 00 04 40 00 00 08
|
||||
|
||||
Input: in/test-63.bin
|
||||
Packet Length: 147
|
||||
Questions: 2
|
||||
Q: _afpovertcp._tcp.local. PTR IN
|
||||
Q: Sofiya-Ivanovas-MacBook.local. A IN
|
||||
Answers: 2 + 0
|
||||
A: _afpovertcp._tcp.local. PTR IN 2881 [29] Sofiya Ivanova’s MacBook._afpovertcp._tcp.local.
|
||||
A: _afpovertcp._tcp.local. PTR IN 2881 [24] Hristo's Time Capsule._afpovertcp._tcp.local.
|
||||
|
||||
Input: in/test-66.bin
|
||||
Packet Length: 269
|
||||
Answers: 2 + 6
|
||||
A: Hristo’s Mac mini._device-info._tcp.local. TXT IN 4500 [28] model=Macmini6,2; osxvers=16
|
||||
A: _afpovertcp._tcp.local. PTR IN 4500 [22] Hristo’s Mac mini._afpovertcp._tcp.local.
|
||||
A: Hristo’s Mac mini._afpovertcp._tcp.local. TXT IN FLUSH 4500 [1]
|
||||
A: Hristo’s Mac mini._afpovertcp._tcp.local. SRV IN FLUSH 120 [18] 548 minifritz.local.
|
||||
A: minifritz.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:142e:54ff:b8c4:fd09
|
||||
A: minifritz.local. A IN FLUSH 120 [4] 192.168.254.16
|
||||
A: Hristo’s Mac mini.local. NSEC IN FLUSH 4500 [9] Hristo’s Mac mini._afpovertcp._tcp.local. 00 05 00 00 80 00 40
|
||||
A: minifritz.local. NSEC IN FLUSH 120 [8] minifritz...local. 00 04 40 00 00 08
|
||||
|
||||
Input: in/test-83.bin
|
||||
Packet Length: 105
|
||||
Answers: 1 + 2
|
||||
A: Sofiya-Ivanovas-MacBook.local. A IN FLUSH 120 [4] 192.168.254.20
|
||||
A: Sofiya-Ivanovas-MacBook.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:021c:b3ff:feb2:72a3
|
||||
A: Sofiya-Ivanovas-MacBook.local. NSEC IN FLUSH 120 [8] Sofiya-Ivanovas-MacBook...local. 00 04 40 00 00 08
|
||||
|
||||
Input: in/test-88.bin
|
||||
Packet Length: 48
|
||||
Questions: 2
|
||||
Q: _rfb._tcp.local. PTR IN
|
||||
Q: _airport._tcp.local. PTR IN
|
||||
|
||||
Input: in/test-89.bin
|
||||
Packet Length: 459
|
||||
Answers: 2 + 7
|
||||
A: _airport._tcp.local. PTR IN 4500 [24] Hristo's Time Capsule._airport._tcp.local.
|
||||
A: Hristo's Time Capsule._device-info._tcp.local. TXT IN 4500 [23] model=TimeCapsule6,116
|
||||
A: Hristos-Time-Capsule.local. A IN FLUSH 120 [4] 192.168.254.49
|
||||
A: Hristo's Time Capsule._airport._tcp.local. TXT IN FLUSH 4500 [168] waMA=70-73-CB-B4-C9-B3,raMA=70-73-CB-BB-04-E7,raM2=70-73-CB-BB-04-E8,raNm=nbis-test,raCh=11,rCh2=132,raSt=0,raNA=0,syFl=0x820C,syAP=116,syVs=7.6.8,srcv=76800.1,bjSd=30
|
||||
A: Hristos-Time-Capsule.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:7273:cbff:feb4:c9b3
|
||||
A: Hristo's Time Capsule._airport._tcp.local. SRV IN FLUSH 120 [8] 5009 Hristos-Time-Capsule.local.
|
||||
A: Hristos-Time-Capsule.local. A IN FLUSH 120 [4] 169.254.23.40
|
||||
A: Hristos-Time-Capsule.local. NSEC IN FLUSH 120 [8] Hristos-Time-Capsule...local. 00 04 40 00 00 08
|
||||
A: Hristo's Time Capsule.local. NSEC IN FLUSH 4500 [9] Hristo's Time Capsule._airport._tcp.local. 00 05 00 00 80 00 40
|
||||
|
||||
Input: in/test-91.bin
|
||||
Packet Length: 279
|
||||
Answers: 2 + 6
|
||||
A: Sofiya Ivanova’s MacBook._device-info._tcp.local. TXT IN 4500 [17] model=Macmini2,1
|
||||
A: _rfb._tcp.local. PTR IN 4500 [29] Sofiya Ivanova’s MacBook._rfb._tcp.local.
|
||||
A: Sofiya Ivanova’s MacBook._rfb._tcp.local. TXT IN FLUSH 4500 [1]
|
||||
A: Sofiya Ivanova’s MacBook._rfb._tcp.local. SRV IN FLUSH 120 [32] 5900 Sofiya-Ivanovas-MacBook.local.
|
||||
A: Sofiya-Ivanovas-MacBook.local. AAAA IN FLUSH 120 [16] fe80:0000:0000:0000:021c:b3ff:feb2:72a3
|
||||
A: Sofiya-Ivanovas-MacBook.local. A IN FLUSH 120 [4] 192.168.254.20
|
||||
A: Sofiya Ivanova’s MacBook.local. NSEC IN FLUSH 4500 [9] Sofiya Ivanova’s MacBook._rfb._tcp.local. 00 05 00 00 80 00 40
|
||||
A: Sofiya-Ivanovas-MacBook.local. NSEC IN FLUSH 120 [8] Sofiya-Ivanovas-MacBook...local. 00 04 40 00 00 08
|
||||
|
||||
Input: in/test-95.bin
|
||||
Packet Length: 286
|
||||
Questions: 3
|
||||
Q: _afpovertcp._tcp.local. PTR IN
|
||||
Q: _smb._tcp.local. PTR IN
|
||||
Q: _adisk._tcp.local. PTR IN
|
||||
Answers: 6 + 0
|
||||
A: _afpovertcp._tcp.local. PTR IN 2353 [29] Sofiya Ivanova’s MacBook._afpovertcp._tcp.local.
|
||||
A: _afpovertcp._tcp.local. PTR IN 3973 [22] Hristo’s Mac mini._afpovertcp._tcp.local.
|
||||
A: _afpovertcp._tcp.local. PTR IN 2353 [24] Hristo's Time Capsule._afpovertcp._tcp.local.
|
||||
A: _smb._tcp.local. PTR IN 2353 [29] Sofiya Ivanova’s MacBook._smb._tcp.local.
|
||||
A: _smb._tcp.local. PTR IN 3792 [22] Hristo’s Mac mini._smb._tcp.local.
|
||||
A: _smb._tcp.local. PTR IN 2353 [24] Hristo's Time Capsule._smb._tcp.local.
|
||||
|
||||
Input: in/test-96.bin
|
||||
Packet Length: 319
|
||||
Answers: 2 + 3
|
||||
A: Hristo's Time Capsule._device-info._tcp.local. TXT IN 4500 [23] model=TimeCapsule6,116
|
||||
A: _adisk._tcp.local. PTR IN 4500 [24] Hristo's Time Capsule._adisk._tcp.local.
|
||||
A: Hristo's Time Capsule._adisk._tcp.local. TXT IN FLUSH 4500 [110] sys=waMA=70:73:CB:B4:C9:B3,adVF=0x1000; dk2=adVF=0x1083,adVN=Capsule,adVU=55fabb8b-a63b-5441-9874-6edb504eb30a
|
||||
A: Hristo's Time Capsule._adisk._tcp.local. SRV IN FLUSH 120 [29] 9 Hristos-Time-Capsule.local.
|
||||
A: Hristo's Time Capsule.local. NSEC IN FLUSH 4500 [9] Hristo's Time Capsule._adisk._tcp.local. 00 05 00 00 80 00 40
|
53
components/mdns/test_afl_fuzz_host/mdns_di.h
Normal file
53
components/mdns/test_afl_fuzz_host/mdns_di.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* MDNS Dependecy injection -- preincluded to inject interface test functions into static variables
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mdns.h"
|
||||
#include "mdns_private.h"
|
||||
|
||||
void (*mdns_test_static_execute_action)(mdns_action_t *) = NULL;
|
||||
mdns_srv_item_t * (*mdns_test_static_mdns_get_service_item)(const char * service, const char * proto) = NULL;
|
||||
mdns_search_once_t * (*mdns_test_static_search_init)(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, uint8_t max_results) = NULL;
|
||||
esp_err_t (*mdns_test_static_send_search_action)(mdns_action_type_t type, mdns_search_once_t * search) = NULL;
|
||||
void (*mdns_test_static_search_free)(mdns_search_once_t * search) = NULL;
|
||||
|
||||
static void _mdns_execute_action(mdns_action_t * action);
|
||||
static mdns_srv_item_t * _mdns_get_service_item(const char * service, const char * proto);
|
||||
static mdns_search_once_t * _mdns_search_init(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, uint8_t max_results);
|
||||
static esp_err_t _mdns_send_search_action(mdns_action_type_t type, mdns_search_once_t * search);
|
||||
static void _mdns_search_free(mdns_search_once_t * search);
|
||||
|
||||
void mdns_test_init_di()
|
||||
{
|
||||
mdns_test_static_execute_action = _mdns_execute_action;
|
||||
mdns_test_static_mdns_get_service_item = _mdns_get_service_item;
|
||||
mdns_test_static_search_init = _mdns_search_init;
|
||||
mdns_test_static_send_search_action = _mdns_send_search_action;
|
||||
mdns_test_static_search_free = _mdns_search_free;
|
||||
}
|
||||
|
||||
void mdns_test_execute_action(void * action)
|
||||
{
|
||||
mdns_test_static_execute_action((mdns_action_t *)action);
|
||||
}
|
||||
|
||||
void mdns_test_search_free(mdns_search_once_t * search)
|
||||
{
|
||||
return mdns_test_static_search_free(search);
|
||||
}
|
||||
|
||||
esp_err_t mdns_test_send_search_action(mdns_action_type_t type, mdns_search_once_t * search)
|
||||
{
|
||||
return mdns_test_static_send_search_action(type, search);
|
||||
}
|
||||
|
||||
mdns_search_once_t * mdns_test_search_init(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, uint8_t max_results)
|
||||
{
|
||||
return mdns_test_static_search_init(name, service, proto, type, timeout, max_results);
|
||||
}
|
||||
|
||||
mdns_srv_item_t * mdns_test_mdns_get_service_item(const char * service, const char * proto)
|
||||
{
|
||||
return mdns_test_static_mdns_get_service_item(service, proto);
|
||||
}
|
228
components/mdns/test_afl_fuzz_host/test.c
Normal file
228
components/mdns/test_afl_fuzz_host/test.c
Normal file
@ -0,0 +1,228 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mdns.h"
|
||||
#include "mdns_private.h"
|
||||
|
||||
//
|
||||
// Global stuctures containing packet payload, search
|
||||
mdns_rx_packet_t g_packet;
|
||||
struct pbuf mypbuf;
|
||||
mdns_search_once_t * search = NULL;
|
||||
|
||||
//
|
||||
// Dependency injected test functions
|
||||
void mdns_test_execute_action(void * action);
|
||||
mdns_srv_item_t * mdns_test_mdns_get_service_item(const char * service, const char * proto);
|
||||
mdns_search_once_t * mdns_test_search_init(const char * name, const char * service, const char * proto, uint16_t type, uint32_t timeout, uint8_t max_results);
|
||||
esp_err_t mdns_test_send_search_action(mdns_action_type_t type, mdns_search_once_t * search);
|
||||
void mdns_test_search_free(mdns_search_once_t * search);
|
||||
void mdns_test_init_di();
|
||||
|
||||
//
|
||||
// mdns function wrappers for mdns setup in test mode
|
||||
static int mdns_test_hostname_set(const char * mdns_hostname)
|
||||
{
|
||||
int ret = mdns_hostname_set(mdns_hostname);
|
||||
mdns_action_t * a = NULL;
|
||||
GetLastItem(&a);
|
||||
mdns_test_execute_action(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mdns_test_service_instance_name_set(const char * service, const char * proto, const char * instance)
|
||||
{
|
||||
int ret = mdns_service_instance_name_set(service, proto, instance);
|
||||
mdns_action_t * a = NULL;
|
||||
GetLastItem(&a);
|
||||
mdns_test_execute_action(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mdns_test_service_txt_set(const char * service, const char * proto, uint8_t num_items, mdns_txt_item_t txt[])
|
||||
{
|
||||
int ret = mdns_service_txt_set(service, proto, txt, num_items);
|
||||
mdns_action_t * a = NULL;
|
||||
GetLastItem(&a);
|
||||
mdns_test_execute_action(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mdns_test_service_add(const char * service_name, const char * proto, uint32_t port)
|
||||
{
|
||||
if (mdns_service_add(NULL, service_name, proto, port, NULL, 0)) {
|
||||
// This is expected failure as the service thread is not running
|
||||
}
|
||||
mdns_action_t * a = NULL;
|
||||
GetLastItem(&a);
|
||||
mdns_test_execute_action(a);
|
||||
|
||||
if (mdns_test_mdns_get_service_item(service_name, proto)==NULL) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static mdns_result_t* mdns_test_query(const char * service_name, const char * proto)
|
||||
{
|
||||
search = mdns_test_search_init(NULL, service_name, proto, MDNS_TYPE_PTR, 3000, 20);
|
||||
if (!search) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_send_search_action(ACTION_SEARCH_ADD, search)) {
|
||||
mdns_test_search_free(search);
|
||||
abort();
|
||||
}
|
||||
|
||||
mdns_action_t * a = NULL;
|
||||
GetLastItem(&a);
|
||||
mdns_test_execute_action(a);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void mdns_test_query_free()
|
||||
{
|
||||
mdns_test_search_free(search);
|
||||
}
|
||||
|
||||
//
|
||||
// function "under test" where afl-mangled packets passed
|
||||
//
|
||||
void mdns_parse_packet(mdns_rx_packet_t * packet);
|
||||
|
||||
//
|
||||
// Test starts here
|
||||
//
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int i;
|
||||
const char * mdns_hostname = "minifritz";
|
||||
const char * mdns_instance = "Hristo's Time Capsule";
|
||||
mdns_txt_item_t arduTxtData[4] = {
|
||||
{"board","esp32"},
|
||||
{"tcp_check","no"},
|
||||
{"ssh_upload","no"},
|
||||
{"auth_upload","no"}
|
||||
};
|
||||
|
||||
const uint8_t mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x32};
|
||||
|
||||
uint8_t buf[1460];
|
||||
char winstance[21+strlen(mdns_hostname)];
|
||||
|
||||
sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", mdns_hostname, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
// Init depencency injected methods
|
||||
mdns_test_init_di();
|
||||
|
||||
if (mdns_init()) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_hostname_set(mdns_hostname)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_service_add("_workstation", "_tcp", 9)) {
|
||||
abort();
|
||||
}
|
||||
if (mdns_test_service_instance_name_set("_workstation", "_tcp", winstance)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_service_add("_arduino", "_tcp", 3232)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_service_txt_set("_arduino", "_tcp", 4, arduTxtData)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_service_add("_http", "_tcp", 80)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mdns_test_service_instance_name_set("_http", "_tcp", "ESP WebServer")) {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (
|
||||
mdns_test_service_add("_afpovertcp", "_tcp", 548)
|
||||
|| mdns_test_service_add("_rfb", "_tcp", 885)
|
||||
|| mdns_test_service_add("_smb", "_tcp", 885)
|
||||
|| mdns_test_service_add("_adisk", "_tcp", 885)
|
||||
|| mdns_test_service_add("_airport", "_tcp", 885)
|
||||
|| mdns_test_service_add("_printer", "_tcp", 885)
|
||||
|| mdns_test_service_add("_airplay", "_tcp", 885)
|
||||
|| mdns_test_service_add("_raop", "_tcp", 885)
|
||||
|| mdns_test_service_add("_uscan", "_tcp", 885)
|
||||
|| mdns_test_service_add("_uscans", "_tcp", 885)
|
||||
|| mdns_test_service_add("_ippusb", "_tcp", 885)
|
||||
|| mdns_test_service_add("_scanner", "_tcp", 885)
|
||||
|| mdns_test_service_add("_ipp", "_tcp", 885)
|
||||
|| mdns_test_service_add("_ipps", "_tcp", 885)
|
||||
|| mdns_test_service_add("_pdl-datastream", "_tcp", 885)
|
||||
|| mdns_test_service_add("_ptp", "_tcp", 885)
|
||||
|| mdns_test_service_add("_sleep-proxy", "_udp", 885))
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
mdns_result_t * results = NULL;
|
||||
FILE *file;
|
||||
size_t nread;
|
||||
|
||||
#ifdef INSTR_IS_OFF
|
||||
size_t len = 1460;
|
||||
memset(buf, 0, 1460);
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("Non-instrumentation mode: please supply a file name created by AFL to reproduce crash\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Note: parameter1 is a file (mangled packet) which caused the crash
|
||||
file = fopen(argv[1], "r");
|
||||
if (file) {
|
||||
len = fread(buf, 1, 1460, file);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
for (i=0; i<1; i++) {
|
||||
#else
|
||||
while (__AFL_LOOP(1000)) {
|
||||
memset(buf, 0, 1460);
|
||||
size_t len = read(0, buf, 1460);
|
||||
#endif
|
||||
mypbuf.payload = buf;
|
||||
mypbuf.len = len;
|
||||
g_packet.pb = &mypbuf;
|
||||
mdns_test_query("_afpovertcp", "_tcp");
|
||||
mdns_parse_packet(&g_packet);
|
||||
}
|
||||
ForceTaskDelete();
|
||||
mdns_free();
|
||||
return 0;
|
||||
}
|
9
examples/protocols/mdns/Makefile
Normal file
9
examples/protocols/mdns/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := mdns-test
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
21
examples/protocols/mdns/README.md
Normal file
21
examples/protocols/mdns/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# mDNS example
|
||||
|
||||
Shows how to use mDNS to advertise lookup services and hosts
|
||||
|
||||
## Example workflow
|
||||
|
||||
- mDNS is initialized with host name and instance name defined through `make menuconfig` and `_http._tcp` service is added to be advertised
|
||||
- WiFi STA is started and trying to connect to the access point defined through `make menuconfig`
|
||||
- The system event handler is used to pass the network events to mDNS so the service is aware when the interface comes up or down
|
||||
- GPIO0 (BOOT Button) is initialized as pulled-up input that can be monitored for button press
|
||||
- Example task is started to check if the button is pressed so it can execute the mDNS queries defined
|
||||
|
||||
## Running the example
|
||||
|
||||
- Run `make menuconfig` to configure the access point's SSID and Password and the default device mDNS host name and instance name
|
||||
- Run `make flash monitor` to build and upload the example to your board and connect to it's serial terminal
|
||||
- Wait for WiFi to connec to your access point
|
||||
- You can now ping the device at `[hostname].local` and browse for `_http._tcp` on the same network to find the advertised service
|
||||
- Pressing the BOOT button will start quring the local network for the predefined in `check_button` hosts and services
|
||||
|
||||
See the README.md file in the upper level 'examples' directory for more information about examples.
|
29
examples/protocols/mdns/main/Kconfig.projbuild
Normal file
29
examples/protocols/mdns/main/Kconfig.projbuild
Normal file
@ -0,0 +1,29 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "myssid"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
Can be left blank if the network has no security set.
|
||||
|
||||
config MDNS_HOSTNAME
|
||||
string "mDNS Hostname"
|
||||
default "esp32-mdns"
|
||||
help
|
||||
mDNS Hostname for example to use
|
||||
|
||||
config MDNS_INSTANCE
|
||||
string "mDNS Instance Name"
|
||||
default "ESP32 with mDNS"
|
||||
help
|
||||
mDNS Instance Name for example to use
|
||||
|
||||
endmenu
|
4
examples/protocols/mdns/main/component.mk
Normal file
4
examples/protocols/mdns/main/component.mk
Normal file
@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
244
examples/protocols/mdns/main/mdns_example_main.c
Executable file
244
examples/protocols/mdns/main/mdns_example_main.c
Executable file
@ -0,0 +1,244 @@
|
||||
/* MDNS-SD Query and advertise Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "mdns.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
/* The examples use simple WiFi configuration that you can set via
|
||||
'make menuconfig'.
|
||||
|
||||
If you'd rather not, just change the below entries to strings with
|
||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
#define EXAMPLE_MDNS_HOSTNAME CONFIG_MDNS_HOSTNAME
|
||||
#define EXAMPLE_MDNS_INSTANCE CONFIG_MDNS_INSTANCE
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event,
|
||||
but we only care about one event - are we connected
|
||||
to the AP with an IP? */
|
||||
const int IP4_CONNECTED_BIT = BIT0;
|
||||
const int IP6_CONNECTED_BIT = BIT1;
|
||||
|
||||
static const char *TAG = "mdns-test";
|
||||
static bool auto_reconnect = true;
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch(event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
/* enable ipv6 */
|
||||
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, IP4_CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STA_GOT_IP6:
|
||||
xEventGroupSetBits(wifi_event_group, IP6_CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
/* This is a workaround as ESP32 WiFi libs don't currently
|
||||
auto-reassociate. */
|
||||
if (auto_reconnect) {
|
||||
esp_wifi_connect();
|
||||
}
|
||||
xEventGroupClearBits(wifi_event_group, IP4_CONNECTED_BIT | IP6_CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mdns_handle_system_event(ctx, event);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_WIFI_SSID,
|
||||
.password = EXAMPLE_WIFI_PASS,
|
||||
},
|
||||
};
|
||||
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
}
|
||||
|
||||
static void initialise_mdns(void)
|
||||
{
|
||||
//initialize mDNS
|
||||
ESP_ERROR_CHECK( mdns_init() );
|
||||
//set mDNS hostname (required if you want to advertise services)
|
||||
ESP_ERROR_CHECK( mdns_hostname_set(EXAMPLE_MDNS_HOSTNAME) );
|
||||
//set default mDNS instance name
|
||||
ESP_ERROR_CHECK( mdns_instance_name_set(EXAMPLE_MDNS_INSTANCE) );
|
||||
|
||||
//structure with TXT records
|
||||
mdns_txt_item_t serviceTxtData[3] = {
|
||||
{"board","esp32"},
|
||||
{"u","user"},
|
||||
{"p","password"}
|
||||
};
|
||||
|
||||
//initialize service
|
||||
ESP_ERROR_CHECK( mdns_service_add("ESP32-WebServer", "_http", "_tcp", 80, serviceTxtData, 3) );
|
||||
//add another TXT item
|
||||
ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") );
|
||||
//change TXT item value
|
||||
ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "u", "admin") );
|
||||
}
|
||||
|
||||
static const char * if_str[] = {"STA", "AP", "ETH", "MAX"};
|
||||
static const char * ip_protocol_str[] = {"V4", "V6", "MAX"};
|
||||
|
||||
static void mdns_print_results(mdns_result_t * results){
|
||||
mdns_result_t * r = results;
|
||||
mdns_ip_addr_t * a = NULL;
|
||||
int i = 1, t;
|
||||
while(r){
|
||||
printf("%d: Interface: %s, Type: %s\n", i++, if_str[r->tcpip_if], ip_protocol_str[r->ip_protocol]);
|
||||
if(r->instance_name){
|
||||
printf(" PTR : %s\n", r->instance_name);
|
||||
}
|
||||
if(r->hostname){
|
||||
printf(" SRV : %s.local:%u\n", r->hostname, r->port);
|
||||
}
|
||||
if(r->txt_count){
|
||||
printf(" TXT : [%u] ", r->txt_count);
|
||||
for(t=0; t<r->txt_count; t++){
|
||||
printf("%s=%s; ", r->txt[t].key, r->txt[t].value);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
a = r->addr;
|
||||
while(a){
|
||||
if(a->addr.type == MDNS_IP_PROTOCOL_V6){
|
||||
printf(" AAAA: " IPV6STR "\n", IPV62STR(a->addr.u_addr.ip6));
|
||||
} else {
|
||||
printf(" A : " IPSTR "\n", IP2STR(&(a->addr.u_addr.ip4)));
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
r = r->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void query_mdns_service(const char * service_name, const char * proto)
|
||||
{
|
||||
ESP_LOGI(TAG, "Query PTR: %s.%s.local", service_name, proto);
|
||||
|
||||
mdns_result_t * results = NULL;
|
||||
esp_err_t err = mdns_query_ptr(service_name, proto, 3000, 20, &results);
|
||||
if(err){
|
||||
ESP_LOGE(TAG, "Query Failed");
|
||||
return;
|
||||
}
|
||||
if(!results){
|
||||
ESP_LOGW(TAG, "No results found!");
|
||||
return;
|
||||
}
|
||||
|
||||
mdns_print_results(results);
|
||||
mdns_query_results_free(results);
|
||||
}
|
||||
|
||||
static void query_mdns_host(const char * host_name)
|
||||
{
|
||||
ESP_LOGI(TAG, "Query A: %s.local", host_name);
|
||||
|
||||
struct ip4_addr addr;
|
||||
addr.addr = 0;
|
||||
|
||||
esp_err_t err = mdns_query_a(host_name, 2000, &addr);
|
||||
if(err){
|
||||
if(err == ESP_ERR_NOT_FOUND){
|
||||
ESP_LOGW(TAG, "Host was not found!");
|
||||
return;
|
||||
}
|
||||
ESP_LOGE(TAG, "Query Failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, IPSTR, IP2STR(&addr));
|
||||
}
|
||||
|
||||
static void initialise_button(void)
|
||||
{
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.pin_bit_mask = 1;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = 1;
|
||||
io_conf.pull_down_en = 0;
|
||||
gpio_config(&io_conf);
|
||||
}
|
||||
|
||||
static void check_button(void)
|
||||
{
|
||||
static bool old_level = true;
|
||||
bool new_level = gpio_get_level(GPIO_NUM_0);
|
||||
if (!new_level && old_level) {
|
||||
query_mdns_host("esp32");
|
||||
query_mdns_service("_arduino", "_tcp");
|
||||
query_mdns_service("_http", "_tcp");
|
||||
query_mdns_service("_printer", "_tcp");
|
||||
query_mdns_service("_ipp", "_tcp");
|
||||
query_mdns_service("_afpovertcp", "_tcp");
|
||||
query_mdns_service("_smb", "_tcp");
|
||||
query_mdns_service("_ftp", "_tcp");
|
||||
query_mdns_service("_nfs", "_tcp");
|
||||
}
|
||||
old_level = new_level;
|
||||
}
|
||||
|
||||
static void mdns_example_task(void *pvParameters)
|
||||
{
|
||||
/* Wait for the callback to set the CONNECTED_BIT in the event group. */
|
||||
xEventGroupWaitBits(wifi_event_group, IP4_CONNECTED_BIT | IP6_CONNECTED_BIT,
|
||||
false, true, portMAX_DELAY);
|
||||
while(1) {
|
||||
check_button();
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
ESP_ERROR_CHECK( nvs_flash_init() );
|
||||
initialise_mdns();
|
||||
initialise_wifi();
|
||||
initialise_button();
|
||||
xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL);
|
||||
}
|
1
examples/protocols/mdns/sdkconfig.defaults
Normal file
1
examples/protocols/mdns/sdkconfig.defaults
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_ENABLE_MDNS=y
|
Reference in New Issue
Block a user