@@ -38,13 +38,13 @@ typedef struct interfaces {
38
38
39
39
static interfaces_t s_interfaces [MDNS_MAX_INTERFACES ];
40
40
41
- static struct udp_pcb * _pcb_main = NULL ;
41
+ static struct udp_pcb * s_pcb_main = NULL ;
42
42
43
43
static const char * TAG = "mdns_networking" ;
44
44
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 );
46
46
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 )
48
48
{
49
49
mdns_action_t * action = NULL ;
50
50
@@ -66,44 +66,44 @@ static esp_err_t _mdns_send_rx_action(mdns_rx_packet_t *packet)
66
66
/**
67
67
* @brief Low level UDP PCB Initialize
68
68
*/
69
- static esp_err_t _udp_pcb_main_init (void )
69
+ static esp_err_t pcb_init (void )
70
70
{
71
- if (_pcb_main ) {
71
+ if (s_pcb_main ) {
72
72
return ESP_OK ;
73
73
}
74
- _pcb_main = udp_new ();
75
- if (!_pcb_main ) {
74
+ s_pcb_main = udp_new ();
75
+ if (!s_pcb_main ) {
76
76
return ESP_ERR_NO_MEM ;
77
77
}
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 ;
81
81
return ESP_ERR_INVALID_STATE ;
82
82
}
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 );
87
87
return ESP_OK ;
88
88
}
89
89
90
90
/**
91
91
* @brief Low level UDP PCB Free
92
92
*/
93
- static void _udp_pcb_main_deinit (void )
93
+ static void pcb_deinit (void )
94
94
{
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 ;
100
100
}
101
101
}
102
102
103
103
/**
104
104
* @brief Low level UDP Multicast membership control
105
105
*/
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 )
107
107
{
108
108
struct netif * netif = NULL ;
109
109
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
154
154
* @brief the receive callback of the raw udp api. Packets are received here
155
155
*
156
156
*/
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 )
158
158
{
159
159
160
160
uint8_t i ;
@@ -223,7 +223,7 @@ static void _udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *pb, const ip
223
223
}
224
224
}
225
225
226
- if (!found || _mdns_send_rx_action (packet ) != ESP_OK ) {
226
+ if (!found || send_rx_action (packet ) != ESP_OK ) {
227
227
pbuf_free (this_pb );
228
228
mdns_mem_free (packet );
229
229
}
@@ -240,7 +240,7 @@ bool mdns_priv_if_ready(mdns_if_t netif, mdns_ip_protocol_t ip_proto)
240
240
/**
241
241
* @brief Check if any of the interfaces is up
242
242
*/
243
- static bool _udp_pcb_is_in_use (void )
243
+ static bool is_any_pcb_in_use (void )
244
244
{
245
245
int i , p ;
246
246
for (i = 0 ; i < MDNS_MAX_INTERFACES ; i ++ ) {
@@ -256,33 +256,33 @@ static bool _udp_pcb_is_in_use(void)
256
256
/**
257
257
* @brief Stop PCB Main code
258
258
*/
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 )
260
260
{
261
261
s_interfaces [tcpip_if ].proto &= ~(ip_protocol == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6 );
262
262
if (s_interfaces [tcpip_if ].proto == 0 ) {
263
263
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 ();
267
267
}
268
268
}
269
269
}
270
270
271
271
/**
272
272
* @brief Start PCB Main code
273
273
*/
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 )
275
275
{
276
276
if (mdns_priv_if_ready (tcpip_if , ip_protocol )) {
277
277
return ESP_ERR_INVALID_STATE ;
278
278
}
279
279
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);
281
281
if (err ) {
282
282
return err ;
283
283
}
284
284
285
- err = _udp_pcb_main_init ();
285
+ err = pcb_init ();
286
286
if (err ) {
287
287
return err ;
288
288
}
@@ -305,20 +305,20 @@ typedef struct {
305
305
/**
306
306
* @brief Start PCB from LwIP thread
307
307
*/
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 )
309
309
{
310
310
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 ;
313
313
}
314
314
315
315
/**
316
316
* @brief Stop PCB from LwIP thread
317
317
*/
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 )
319
319
{
320
320
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 );
322
322
msg -> err = ESP_OK ;
323
323
return ESP_OK ;
324
324
}
@@ -334,7 +334,7 @@ esp_err_t mdns_priv_if_init(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
334
334
.tcpip_if = tcpip_if ,
335
335
.ip_protocol = ip_protocol
336
336
};
337
- tcpip_api_call (mdns_priv_if_init_api , & msg .call );
337
+ tcpip_api_call (pcb_if_init_lwip , & msg .call );
338
338
return msg .err ;
339
339
}
340
340
@@ -344,23 +344,23 @@ esp_err_t mdns_priv_if_deinit(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol
344
344
.tcpip_if = tcpip_if ,
345
345
.ip_protocol = ip_protocol
346
346
};
347
- tcpip_api_call (mdns_priv_if_deinit_api , & msg .call );
347
+ tcpip_api_call (pcb_if_deinit_lwip , & msg .call );
348
348
return msg .err ;
349
349
}
350
350
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 )
352
352
{
353
353
void * nif = NULL ;
354
354
mdns_api_call_t * msg = (mdns_api_call_t * )api_call_msg ;
355
355
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 ) {
357
357
pbuf_free (msg -> pbt );
358
358
msg -> err = ERR_IF ;
359
359
return ERR_IF ;
360
360
}
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 );
362
362
pbuf_free (msg -> pbt );
363
- msg -> err = err ;
363
+ msg -> err = err == ERR_OK ? ESP_OK : ESP_FAIL ;
364
364
return err ;
365
365
}
366
366
@@ -392,7 +392,7 @@ size_t mdns_priv_if_write(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, co
392
392
.ip = & ip_add_copy ,
393
393
.port = port
394
394
};
395
- tcpip_api_call (mdns_priv_if_write_api , & msg .call );
395
+ tcpip_api_call (write_if_lwip , & msg .call );
396
396
397
397
if (msg .err ) {
398
398
return 0 ;
0 commit comments