-
Notifications
You must be signed in to change notification settings - Fork 7.2k
/
esp_netif.h
916 lines (821 loc) · 29.1 KB
/
esp_netif.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
// Copyright 2019 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_NETIF_H_
#define _ESP_NETIF_H_
#include <stdint.h>
#include "sdkconfig.h"
#include "esp_wifi_types.h"
#include "esp_netif_ip_addr.h"
#include "esp_netif_types.h"
#include "esp_netif_defaults.h"
#if CONFIG_ETH_ENABLED
#include "esp_eth_netif_glue.h"
#endif
//
// Note: tcpip_adapter legacy API has to be included by default to provide full compatibility
// for applications that used tcpip_adapter API without explicit inclusion of tcpip_adapter.h
//
#if CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER
#define _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
#include "tcpip_adapter.h"
#undef _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
#endif // CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup ESP_NETIF_INIT_API ESP-NETIF Initialization API
* @brief Initialization and deinitialization of underlying TCP/IP stack and esp-netif instances
*
*/
/** @addtogroup ESP_NETIF_INIT_API
* @{
*/
/**
* @brief Initialize the underlying TCP/IP stack
*
* @return
* - ESP_OK on success
* - ESP_FAIL if initializing failed
* @note This function should be called exactly once from application code, when the application starts up.
*/
esp_err_t esp_netif_init(void);
/**
* @brief Deinitialize the esp-netif component (and the underlying TCP/IP stack)
*
* Note: Deinitialization is not supported yet
*
* @return
* - ESP_ERR_INVALID_STATE if esp_netif not initialized
* - ESP_ERR_NOT_SUPPORTED otherwise
*/
esp_err_t esp_netif_deinit(void);
/**
* @brief Creates an instance of new esp-netif object based on provided config
*
* @param[in] esp_netif_config pointer esp-netif configuration
*
* @return
* - pointer to esp-netif object on success
* - NULL otherwise
*/
esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config);
/**
* @brief Destroys the esp_netif object
*
* @param[in] esp_netif pointer to the object to be deleted
*/
void esp_netif_destroy(esp_netif_t *esp_netif);
/**
* @brief Configures driver related options of esp_netif object
*
* @param[inout] esp_netif pointer to the object to be configured
* @param[in] driver_config pointer esp-netif io driver related configuration
* @return
* - ESP_OK on success
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS if invalid parameters provided
*
*/
esp_err_t esp_netif_set_driver_config(esp_netif_t *esp_netif,
const esp_netif_driver_ifconfig_t *driver_config);
/**
* @brief Attaches esp_netif instance to the io driver handle
*
* Calling this function enables connecting specific esp_netif object
* with already initialized io driver to update esp_netif object with driver
* specific configuration (i.e. calls post_attach callback, which typically
* sets io driver callbacks to esp_netif instance and starts the driver)
*
* @param[inout] esp_netif pointer to esp_netif object to be attached
* @param[in] driver_handle pointer to the driver handle
* @return
* - ESP_OK on success
* - ESP_ERR_ESP_NETIF_DRIVER_ATTACH_FAILED if driver's pot_attach callback failed
*/
esp_err_t esp_netif_attach(esp_netif_t *esp_netif, esp_netif_iodriver_handle driver_handle);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_DATA_IO_API ESP-NETIF Input Output API
* @brief Input and Output functions to pass data packets from communication media (IO driver)
* to TCP/IP stack.
*
* These functions are usually not directly called from user code, but installed, or registered
* as callbacks in either IO driver on one hand or TCP/IP stack on the other. More specifically
* esp_netif_receive is typically called from io driver on reception callback to input the packets
* to TCP/IP stack. Similarly esp_netif_transmit is called from the TCP/IP stack whenever
* a packet ought to output to the communication media.
*
* @note These IO functions are registerd (installed) automatically for default interfaces
* (interfaces with the keys such as WIFI_STA_DEF, WIFI_AP_DEF, ETH_DEF). Custom interface
* has to register these IO functions when creating interface using @ref esp_netif_new
*
*/
/** @addtogroup ESP_NETIF_DATA_IO_API
* @{
*/
/**
* @brief Passes the raw packets from communication media to the appropriate TCP/IP stack
*
* This function is called from the configured (peripheral) driver layer.
* The data are then forwarded as frames to the TCP/IP stack.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] buffer Received data
* @param[in] len Length of the data frame
* @param[in] eb Pointer to internal buffer (used in Wi-Fi driver)
*
* @return
* - ESP_OK
*/
esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_LIFECYCLE ESP-NETIF Lifecycle control
* @brief These APIS define basic building blocks to control network interface lifecycle, i.e.
* start, stop, set_up or set_down. These functions can be directly used as event handlers
* registered to follow the events from communication media.
*/
/** @addtogroup ESP_NETIF_LIFECYCLE
* @{
*/
/**
* @brief Default building block for network interface action upon IO driver start event
* Creates network interface, if AUTOUP enabled turns the interface on,
* if DHCPS enabled starts dhcp server
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_start(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IO driver stop event
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_stop(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IO driver connected event
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_connected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IO driver disconnected event
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_disconnected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon network got IP event
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_got_ip(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IPv6 multicast group join
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_join_ip6_multicast_group(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IPv6 multicast group leave
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_leave_ip6_multicast_group(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IPv6 address added by the underlying stack
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_add_ip6_address(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @brief Default building block for network interface action upon IPv6 address removed by the underlying stack
*
* @note This API can be directly used as event handler
*
* @param[in] esp_netif Handle to esp-netif instance
* @param base
* @param event_id
* @param data
*/
void esp_netif_action_remove_ip6_address(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_GET_SET ESP-NETIF Runtime configuration
* @brief Getters and setters for various TCP/IP related parameters
*/
/** @addtogroup ESP_NETIF_GET_SET
* @{
*/
/**
* @brief Set the mac address for the interface instance
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] mac Desired mac address for the related network interface
* @return
* - ESP_OK - success
* - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
* - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface
*/
esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[]);
/**
* @brief Get the mac address for the interface instance
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] mac Resultant mac address for the related network interface
* @return
* - ESP_OK - success
* - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
* - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface
*/
esp_err_t esp_netif_get_mac(esp_netif_t *esp_netif, uint8_t mac[]);
/**
* @brief Set the hostname of an interface
*
* The configured hostname overrides the default configuration value CONFIG_LWIP_LOCAL_HOSTNAME.
* Please note that when the hostname is altered after interface started/connected the changes
* would only be reflected once the interface restarts/reconnects
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] hostname New hostname for the interface. Maximum length 32 bytes.
*
* @return
* - ESP_OK - success
* - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
*/
esp_err_t esp_netif_set_hostname(esp_netif_t *esp_netif, const char *hostname);
/**
* @brief Get interface hostname.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] hostname Returns a pointer to the hostname. May be NULL if no hostname is set. If set non-NULL, pointer remains valid (and string may change if the hostname changes).
*
* @return
* - ESP_OK - success
* - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
*/
esp_err_t esp_netif_get_hostname(esp_netif_t *esp_netif, const char **hostname);
/**
* @brief Test if supplied interface is up or down
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - true - Interface is up
* - false - Interface is down
*/
bool esp_netif_is_netif_up(esp_netif_t *esp_netif);
/**
* @brief Get interface's IP address information
*
* If the interface is up, IP information is read directly from the TCP/IP stack.
* If the interface is down, IP information is read from a copy kept in the ESP-NETIF instance
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] ip_info If successful, IP information will be returned in this argument.
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
*/
esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
/**
* @brief Get interface's old IP information
*
* Returns an "old" IP address previously stored for the interface when the valid IP changed.
*
* If the IP lost timer has expired (meaning the interface was down for longer than the configured interval)
* then the old IP information will be zero.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] ip_info If successful, IP information will be returned in this argument.
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
*/
esp_err_t esp_netif_get_old_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
/**
* @brief Set interface's IP address information
*
* This function is mainly used to set a static IP on an interface.
*
* If the interface is up, the new IP information is set directly in the TCP/IP stack.
*
* The copy of IP information kept in the ESP-NETIF instance is also updated (this
* copy is returned if the IP is queried while the interface is still down.)
*
* @note DHCP client/server must be stopped (if enabled for this interface) before setting new IP information.
*
* @note Calling this interface for may generate a SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] ip_info IP information to set on the specified interface
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED If DHCP server or client is still running
*/
esp_err_t esp_netif_set_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info);
/**
* @brief Set interface old IP information
*
* This function is called from the DHCP client (if enabled), before a new IP is set.
* It is also called from the default handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events.
*
* Calling this function stores the previously configured IP, which can be used to determine if the IP changes in the future.
*
* If the interface is disconnected or down for too long, the "IP lost timer" will expire (after the configured interval) and set the old IP information to zero.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] ip_info Store the old IP information for the specified interface
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
*/
esp_err_t esp_netif_set_old_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info);
/**
* @brief Get net interface index from network stack implementation
*
* @note This index could be used in `setsockopt()` to bind socket with multicast interface
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* implementation specific index of interface represented with supplied esp_netif
*/
int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif);
/**
* @brief Get net interface name from network stack implementation
*
* @note This name could be used in `setsockopt()` to bind socket with appropriate interface
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] name Interface name as specified in underlying TCP/IP stack. Note that the
* actual name will be copied to the specified buffer, which must be allocated to hold
* maximum interface name size (6 characters for lwIP)
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
*/
esp_err_t esp_netif_get_netif_impl_name(esp_netif_t *esp_netif, char* name);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_NET_DHCP ESP-NETIF DHCP Settings
* @brief Network stack related interface to DHCP client and server
*/
/** @addtogroup ESP_NETIF_NET_DHCP
* @{
*/
/**
* @brief Set or Get DHCP server option
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
* @param[in] opt_id Option index to get or set, must be one of the supported enum values.
* @param[inout] opt_val Pointer to the option parameter.
* @param[in] opt_len Length of the option parameter.
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
*/
esp_err_t
esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_op, esp_netif_dhcp_option_id_t opt_id,
void *opt_val, uint32_t opt_len);
/**
* @brief Set or Get DHCP client option
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
* @param[in] opt_id Option index to get or set, must be one of the supported enum values.
* @param[inout] opt_val Pointer to the option parameter.
* @param[in] opt_len Length of the option parameter.
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
*/
esp_err_t
esp_netif_dhcpc_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_op, esp_netif_dhcp_option_id_t opt_id,
void *opt_val, uint32_t opt_len);
/**
* @brief Start DHCP client (only if enabled in interface object)
*
* @note The default event handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events call this function.
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
* - ESP_ERR_ESP_NETIF_DHCPC_START_FAILED
*/
esp_err_t esp_netif_dhcpc_start(esp_netif_t *esp_netif);
/**
* @brief Stop DHCP client (only if enabled in interface object)
*
* @note Calling action_netif_stop() will also stop the DHCP Client if it is running.
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
* - ESP_ERR_ESP_NETIF_IF_NOT_READY
*/
esp_err_t esp_netif_dhcpc_stop(esp_netif_t *esp_netif);
/**
* @brief Get DHCP client status
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] status If successful, the status of DHCP client will be returned in this argument.
*
* @return
* - ESP_OK
*/
esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
/**
* @brief Get DHCP Server status
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] status If successful, the status of the DHCP server will be returned in this argument.
*
* @return
* - ESP_OK
*/
esp_err_t esp_netif_dhcps_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
/**
* @brief Start DHCP server (only if enabled in interface object)
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
*/
esp_err_t esp_netif_dhcps_start(esp_netif_t *esp_netif);
/**
* @brief Stop DHCP server (only if enabled in interface object)
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
* - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
* - ESP_ERR_ESP_NETIF_IF_NOT_READY
*/
esp_err_t esp_netif_dhcps_stop(esp_netif_t *esp_netif);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_NET_DNS ESP-NETIF DNS Settings
* @brief Network stack related interface to NDS
*/
/** @addtogroup ESP_NETIF_NET_DNS
* @{
*/
/**
* @brief Set DNS Server information
*
* This function behaves differently if DHCP server or client is enabled
*
* If DHCP client is enabled, main and backup DNS servers will be updated automatically
* from the DHCP lease if the relevant DHCP options are set. Fallback DNS Server is never updated from the DHCP lease
* and is designed to be set via this API.
* If DHCP client is disabled, all DNS server types can be set via this API only.
*
* If DHCP server is enabled, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option
* to DHCP clients (Wi-Fi stations).
* - The default Main DNS server is typically the IP of the Wi-Fi AP interface itself.
* - This function can override it by setting server type ESP_NETIF_DNS_MAIN.
* - Other DNS Server types are not supported for the Wi-Fi AP interface.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] type Type of DNS Server to set: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK
* @param[in] dns DNS Server address to set
*
* @return
* - ESP_OK on success
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params
*/
esp_err_t esp_netif_set_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns);
/**
* @brief Get DNS Server information
*
* Return the currently configured DNS Server address for the specified interface and Server type.
*
* This may be result of a previous call to esp_netif_set_dns_info(). If the interface's DHCP client is enabled,
* the Main or Backup DNS Server may be set by the current DHCP lease.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[in] type Type of DNS Server to get: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK
* @param[out] dns DNS Server result is written here on success
*
* @return
* - ESP_OK on success
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params
*/
esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_NET_IP ESP-NETIF IP address related interface
* @brief Network stack related interface to IP
*/
/** @addtogroup ESP_NETIF_NET_IP
* @{
*/
#if CONFIG_LWIP_IPV6
/**
* @brief Create interface link-local IPv6 address
*
* Cause the TCP/IP stack to create a link-local IPv6 address for the specified interface.
*
* This function also registers a callback for the specified interface, so that if the link-local address becomes
* verified as the preferred address then a SYSTEM_EVENT_GOT_IP6 event will be sent.
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return
* - ESP_OK
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
*/
esp_err_t esp_netif_create_ip6_linklocal(esp_netif_t *esp_netif);
/**
* @brief Get interface link-local IPv6 address
*
* If the specified interface is up and a preferred link-local IPv6 address
* has been created for the interface, return a copy of it.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] if_ip6 IPv6 information will be returned in this argument if successful.
*
* @return
* - ESP_OK
* - ESP_FAIL If interface is down, does not have a link-local IPv6 address,
* or the link-local IPv6 address is not a preferred address.
*/
esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
/**
* @brief Get interface global IPv6 address
*
* If the specified interface is up and a preferred global IPv6 address
* has been created for the interface, return a copy of it.
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] if_ip6 IPv6 information will be returned in this argument if successful.
*
* @return
* - ESP_OK
* - ESP_FAIL If interface is down, does not have a global IPv6 address,
* or the global IPv6 address is not a preferred address.
*/
esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
/**
* @brief Get all IPv6 addresses of the specified interface
*
* @param[in] esp_netif Handle to esp-netif instance
* @param[out] if_ip6 Array of IPv6 addresses will be copied to the argument
*
* @return
* number of returned IPv6 addresses
*/
int esp_netif_get_all_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[]);
#endif
/**
* @brief Sets IPv4 address to the specified octets
*
* @param[out] addr IP address to be set
* @param a the first octet (127 for IP 127.0.0.1)
* @param b
* @param c
* @param d
*/
void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d);
/**
* @brief Converts numeric IP address into decimal dotted ASCII representation.
*
* @param addr ip address in network order to convert
* @param buf target buffer where the string is stored
* @param buflen length of buf
* @return either pointer to buf which now holds the ASCII
* representation of addr or NULL if buf was too small
*/
char *esp_ip4addr_ntoa(const esp_ip4_addr_t *addr, char *buf, int buflen);
/**
* @brief Ascii internet address interpretation routine
* The value returned is in network order.
*
* @param addr IP address in ascii representation (e.g. "127.0.0.1")
* @return ip address in network order
*/
uint32_t esp_ip4addr_aton(const char *addr);
/**
* @brief Converts Ascii internet IPv4 address into esp_ip4_addr_t
*
* @param[in] src IPv4 address in ascii representation (e.g. "127.0.0.1")
* @param[out] dst Address of the target esp_ip4_addr_t structure to receive converted address
* @return
* - ESP_OK on success
* - ESP_FAIL if conversion failed
* - ESP_ERR_INVALID_ARG if invalid parameter is passed into
*/
esp_err_t esp_netif_str_to_ip4(const char *src, esp_ip4_addr_t *dst);
/**
* @brief Converts Ascii internet IPv6 address into esp_ip4_addr_t
* Zeros in the IP address can be stripped or completely ommited: "2001:db8:85a3:0:0:0:2:1" or "2001:db8::2:1")
*
* @param[in] src IPv6 address in ascii representation (e.g. ""2001:0db8:85a3:0000:0000:0000:0002:0001")
* @param[out] dst Address of the target esp_ip6_addr_t structure to receive converted address
* @return
* - ESP_OK on success
* - ESP_FAIL if conversion failed
* - ESP_ERR_INVALID_ARG if invalid parameter is passed into
*/
esp_err_t esp_netif_str_to_ip6(const char *src, esp_ip6_addr_t *dst);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_CONVERT ESP-NETIF Conversion utilities
* @brief ESP-NETIF conversion utilities to related keys, flags, implementation handle
*/
/** @addtogroup ESP_NETIF_CONVERT
* @{
*/
/**
* @brief Gets media driver handle for this esp-netif instance
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return opaque pointer of related IO driver
*/
esp_netif_iodriver_handle esp_netif_get_io_driver(esp_netif_t *esp_netif);
/**
* @brief Searches over a list of created objects to find an instance with supplied if key
*
* @param if_key Textual description of network interface
*
* @return Handle to esp-netif instance
*/
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key);
/**
* @brief Returns configured flags for this interface
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return Configuration flags
*/
esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif);
/**
* @brief Returns configured interface key for this esp-netif instance
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return Textual description of related interface
*/
const char *esp_netif_get_ifkey(esp_netif_t *esp_netif);
/**
* @brief Returns configured interface type for this esp-netif instance
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return Enumerated type of this interface, such as station, AP, ethernet
*/
const char *esp_netif_get_desc(esp_netif_t *esp_netif);
/**
* @brief Returns configured routing priority number
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return Integer representing the instance's route-prio, or -1 if invalid paramters
*/
int esp_netif_get_route_prio(esp_netif_t *esp_netif);
/**
* @brief Returns configured event for this esp-netif instance and supplied event type
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @param event_type (either get or lost IP)
*
* @return specific event id which is configured to be raised if the interface lost or acquired IP address
* -1 if supplied event_type is not known
*/
int32_t esp_netif_get_event_id(esp_netif_t *esp_netif, esp_netif_ip_event_type_t event_type);
/**
* @}
*/
/**
* @defgroup ESP_NETIF_LIST ESP-NETIF List of interfaces
* @brief APIs to enumerate all registered interfaces
*/
/** @addtogroup ESP_NETIF_LIST
* @{
*/
/**
* @brief Iterates over list of interfaces. Returns first netif if NULL given as parameter
*
* @param[in] esp_netif Handle to esp-netif instance
*
* @return First netif from the list if supplied parameter is NULL, next one otherwise
*/
esp_netif_t *esp_netif_next(esp_netif_t *esp_netif);
/**
* @brief Returns number of registered esp_netif objects
*
* @return Number of esp_netifs
*/
size_t esp_netif_get_nr_of_ifs(void);
/**
* @brief increase the reference counter of net stack buffer
*
* @param[in] netstack_buf the net stack buffer
*
*/
void esp_netif_netstack_buf_ref(void *netstack_buf);
/**
* @brief free the netstack buffer
*
* @param[in] netstack_buf the net stack buffer
*
*/
void esp_netif_netstack_buf_free(void *netstack_buf);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* _ESP_NETIF_H_ */