@@ -38,13 +38,13 @@ typedef struct interfaces {
3838
3939static interfaces_t s_interfaces [MDNS_MAX_INTERFACES ];
4040
41- static struct udp_pcb * _pcb_main = NULL ;
41+ static struct udp_pcb * s_pcb_main = NULL ;
4242
4343static const char * TAG = "mdns_networking" ;
4444
45- static void _udp_recv (void * arg , struct udp_pcb * upcb , struct pbuf * pb , const ip_addr_t * raddr , uint16_t rport );
45+ static void receive (void * arg , struct udp_pcb * upcb , struct pbuf * pb , const ip_addr_t * raddr , uint16_t rport );
4646
47- static esp_err_t _mdns_send_rx_action (mdns_rx_packet_t * packet )
47+ static esp_err_t send_rx_action (mdns_rx_packet_t * packet )
4848{
4949 mdns_action_t * action = NULL ;
5050
@@ -66,44 +66,44 @@ static esp_err_t _mdns_send_rx_action(mdns_rx_packet_t *packet)
6666/**
6767 * @brief Low level UDP PCB Initialize
6868 */
69- static esp_err_t _udp_pcb_main_init (void )
69+ static esp_err_t pcb_init (void )
7070{
71- if (_pcb_main ) {
71+ if (s_pcb_main ) {
7272 return ESP_OK ;
7373 }
74- _pcb_main = udp_new ();
75- if (!_pcb_main ) {
74+ s_pcb_main = udp_new ();
75+ if (!s_pcb_main ) {
7676 return ESP_ERR_NO_MEM ;
7777 }
78- if (udp_bind (_pcb_main , IP_ANY_TYPE , MDNS_SERVICE_PORT ) != 0 ) {
79- udp_remove (_pcb_main );
80- _pcb_main = NULL ;
78+ if (udp_bind (s_pcb_main , IP_ANY_TYPE , MDNS_SERVICE_PORT ) != 0 ) {
79+ udp_remove (s_pcb_main );
80+ s_pcb_main = NULL ;
8181 return ESP_ERR_INVALID_STATE ;
8282 }
83- _pcb_main -> mcast_ttl = 255 ;
84- _pcb_main -> remote_port = MDNS_SERVICE_PORT ;
85- ip_addr_copy (_pcb_main -> remote_ip , * (IP_ANY_TYPE ));
86- udp_recv (_pcb_main , & _udp_recv , NULL );
83+ s_pcb_main -> mcast_ttl = 255 ;
84+ s_pcb_main -> remote_port = MDNS_SERVICE_PORT ;
85+ ip_addr_copy (s_pcb_main -> remote_ip , * (IP_ANY_TYPE ));
86+ udp_recv (s_pcb_main , receive , NULL );
8787 return ESP_OK ;
8888}
8989
9090/**
9191 * @brief Low level UDP PCB Free
9292 */
93- static void _udp_pcb_main_deinit (void )
93+ static void pcb_deinit (void )
9494{
95- if (_pcb_main ) {
96- udp_recv (_pcb_main , NULL , NULL );
97- udp_disconnect (_pcb_main );
98- udp_remove (_pcb_main );
99- _pcb_main = NULL ;
95+ if (s_pcb_main ) {
96+ udp_recv (s_pcb_main , NULL , NULL );
97+ udp_disconnect (s_pcb_main );
98+ udp_remove (s_pcb_main );
99+ s_pcb_main = NULL ;
100100 }
101101}
102102
103103/**
104104 * @brief Low level UDP Multicast membership control
105105 */
106- static esp_err_t _udp_join_group (mdns_if_t if_inx , mdns_ip_protocol_t ip_protocol , bool join )
106+ static esp_err_t join_group (mdns_if_t if_inx , mdns_ip_protocol_t ip_protocol , bool join )
107107{
108108 struct netif * netif = NULL ;
109109 esp_netif_t * tcpip_if = mdns_priv_get_esp_netif (if_inx );
@@ -154,7 +154,7 @@ static esp_err_t _udp_join_group(mdns_if_t if_inx, mdns_ip_protocol_t ip_protoco
154154 * @brief the receive callback of the raw udp api. Packets are received here
155155 *
156156 */
157- static void _udp_recv (void * arg , struct udp_pcb * upcb , struct pbuf * pb , const ip_addr_t * raddr , uint16_t rport )
157+ static void receive (void * arg , struct udp_pcb * upcb , struct pbuf * pb , const ip_addr_t * raddr , uint16_t rport )
158158{
159159
160160 uint8_t i ;
@@ -223,7 +223,7 @@ static void _udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *pb, const ip
223223 }
224224 }
225225
226- if (!found || _mdns_send_rx_action (packet ) != ESP_OK ) {
226+ if (!found || send_rx_action (packet ) != ESP_OK ) {
227227 pbuf_free (this_pb );
228228 mdns_mem_free (packet );
229229 }
@@ -240,7 +240,7 @@ bool mdns_priv_if_ready(mdns_if_t netif, mdns_ip_protocol_t ip_proto)
240240/**
241241 * @brief Check if any of the interfaces is up
242242 */
243- static bool _udp_pcb_is_in_use (void )
243+ static bool is_any_pcb_in_use (void )
244244{
245245 int i , p ;
246246 for (i = 0 ; i < MDNS_MAX_INTERFACES ; i ++ ) {
@@ -256,33 +256,33 @@ static bool _udp_pcb_is_in_use(void)
256256/**
257257 * @brief Stop PCB Main code
258258 */
259- static void _udp_pcb_deinit (mdns_if_t tcpip_if , mdns_ip_protocol_t ip_protocol )
259+ static void pcb_if_deinit (mdns_if_t tcpip_if , mdns_ip_protocol_t ip_protocol )
260260{
261261 s_interfaces [tcpip_if ].proto &= ~(ip_protocol == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6 );
262262 if (s_interfaces [tcpip_if ].proto == 0 ) {
263263 s_interfaces [tcpip_if ].ready = false;
264- _udp_join_group (tcpip_if , ip_protocol , false);
265- if (!_udp_pcb_is_in_use ()) {
266- _udp_pcb_main_deinit ();
264+ join_group (tcpip_if , ip_protocol , false);
265+ if (!is_any_pcb_in_use ()) {
266+ pcb_deinit ();
267267 }
268268 }
269269}
270270
271271/**
272272 * @brief Start PCB Main code
273273 */
274- static esp_err_t _udp_pcb_init (mdns_if_t tcpip_if , mdns_ip_protocol_t ip_protocol )
274+ static esp_err_t pcb_if_init (mdns_if_t tcpip_if , mdns_ip_protocol_t ip_protocol )
275275{
276276 if (mdns_priv_if_ready (tcpip_if , ip_protocol )) {
277277 return ESP_ERR_INVALID_STATE ;
278278 }
279279
280- esp_err_t err = _udp_join_group (tcpip_if , ip_protocol , true);
280+ esp_err_t err = join_group (tcpip_if , ip_protocol , true);
281281 if (err ) {
282282 return err ;
283283 }
284284
285- err = _udp_pcb_main_init ();
285+ err = pcb_init ();
286286 if (err ) {
287287 return err ;
288288 }
@@ -305,20 +305,20 @@ typedef struct {
305305/**
306306 * @brief Start PCB from LwIP thread
307307 */
308- static err_t mdns_priv_if_init_api (struct tcpip_api_call_data * api_call_msg )
308+ static err_t pcb_if_init_lwip (struct tcpip_api_call_data * api_call_msg )
309309{
310310 mdns_api_call_t * msg = (mdns_api_call_t * )api_call_msg ;
311- msg -> err = _udp_pcb_init (msg -> tcpip_if , msg -> ip_protocol ) == ESP_OK ? ERR_OK : ERR_IF ;
312- return msg -> err ;
311+ msg -> err = pcb_if_init (msg -> tcpip_if , msg -> ip_protocol );
312+ return msg -> err == ESP_OK ? ERR_OK : ERR_IF ;
313313}
314314
315315/**
316316 * @brief Stop PCB from LwIP thread
317317 */
318- static err_t mdns_priv_if_deinit_api (struct tcpip_api_call_data * api_call_msg )
318+ static err_t pcb_if_deinit_lwip (struct tcpip_api_call_data * api_call_msg )
319319{
320320 mdns_api_call_t * msg = (mdns_api_call_t * )api_call_msg ;
321- _udp_pcb_deinit (msg -> tcpip_if , msg -> ip_protocol );
321+ pcb_if_deinit (msg -> tcpip_if , msg -> ip_protocol );
322322 msg -> err = ESP_OK ;
323323 return ESP_OK ;
324324}
@@ -334,7 +334,7 @@ esp_err_t mdns_priv_if_init(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
334334 .tcpip_if = tcpip_if ,
335335 .ip_protocol = ip_protocol
336336 };
337- tcpip_api_call (mdns_priv_if_init_api , & msg .call );
337+ tcpip_api_call (pcb_if_init_lwip , & msg .call );
338338 return msg .err ;
339339}
340340
@@ -344,23 +344,23 @@ esp_err_t mdns_priv_if_deinit(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol
344344 .tcpip_if = tcpip_if ,
345345 .ip_protocol = ip_protocol
346346 };
347- tcpip_api_call (mdns_priv_if_deinit_api , & msg .call );
347+ tcpip_api_call (pcb_if_deinit_lwip , & msg .call );
348348 return msg .err ;
349349}
350350
351- static err_t mdns_priv_if_write_api (struct tcpip_api_call_data * api_call_msg )
351+ static err_t write_if_lwip (struct tcpip_api_call_data * api_call_msg )
352352{
353353 void * nif = NULL ;
354354 mdns_api_call_t * msg = (mdns_api_call_t * )api_call_msg ;
355355 nif = esp_netif_get_netif_impl (mdns_priv_get_esp_netif (msg -> tcpip_if ));
356- if (!nif || !mdns_priv_if_ready (msg -> tcpip_if , msg -> ip_protocol ) || _pcb_main == NULL ) {
356+ if (!nif || !mdns_priv_if_ready (msg -> tcpip_if , msg -> ip_protocol ) || s_pcb_main == NULL ) {
357357 pbuf_free (msg -> pbt );
358358 msg -> err = ERR_IF ;
359359 return ERR_IF ;
360360 }
361- esp_err_t err = udp_sendto_if (_pcb_main , msg -> pbt , msg -> ip , msg -> port , (struct netif * )nif );
361+ err_t err = udp_sendto_if (s_pcb_main , msg -> pbt , msg -> ip , msg -> port , (struct netif * )nif );
362362 pbuf_free (msg -> pbt );
363- msg -> err = err ;
363+ msg -> err = err == ERR_OK ? ESP_OK : ESP_FAIL ;
364364 return err ;
365365}
366366
@@ -392,7 +392,7 @@ size_t mdns_priv_if_write(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, co
392392 .ip = & ip_add_copy ,
393393 .port = port
394394 };
395- tcpip_api_call (mdns_priv_if_write_api , & msg .call );
395+ tcpip_api_call (write_if_lwip , & msg .call );
396396
397397 if (msg .err ) {
398398 return 0 ;
0 commit comments