esp_netif.h 28 KB

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