esp_netif.h 31 KB

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