esp_netif.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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. * @brief Default building block for network interface action upon IPv6 multicast group join
  214. *
  215. * @note This API can be directly used as event handler
  216. *
  217. * @param[in] esp_netif Handle to esp-netif instance
  218. * @param base
  219. * @param event_id
  220. * @param data
  221. */
  222. void esp_netif_action_join_ip6_multicast_group(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
  223. /**
  224. * @brief Default building block for network interface action upon IPv6 multicast group leave
  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_leave_ip6_multicast_group(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 IPv6 address added by the underlying stack
  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_add_ip6_address(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 IPv6 address removed by the underlying stack
  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_remove_ip6_address(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
  256. /**
  257. * @}
  258. */
  259. /**
  260. * @defgroup ESP_NETIF_GET_SET ESP-NETIF Runtime configuration
  261. * @brief Getters and setters for various TCP/IP related parameters
  262. */
  263. /** @addtogroup ESP_NETIF_GET_SET
  264. * @{
  265. */
  266. /**
  267. * @brief Set the mac address for the interface instance
  268. * @param[in] esp_netif Handle to esp-netif instance
  269. * @param[in] mac Desired mac address for the related network interface
  270. * @return
  271. * - ESP_OK - success
  272. * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
  273. * - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface
  274. */
  275. esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[]);
  276. /**
  277. * @brief Get the mac address for the interface instance
  278. * @param[in] esp_netif Handle to esp-netif instance
  279. * @param[out] mac Resultant mac address for the related network interface
  280. * @return
  281. * - ESP_OK - success
  282. * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
  283. * - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface
  284. */
  285. esp_err_t esp_netif_get_mac(esp_netif_t *esp_netif, uint8_t mac[]);
  286. /**
  287. * @brief Set the hostname of an interface
  288. *
  289. * The configured hostname overrides the default configuration value CONFIG_LWIP_LOCAL_HOSTNAME.
  290. * Please note that when the hostname is altered after interface started/connected the changes
  291. * would only be reflected once the interface restarts/reconnects
  292. *
  293. * @param[in] esp_netif Handle to esp-netif instance
  294. * @param[in] hostname New hostname for the interface. Maximum length 32 bytes.
  295. *
  296. * @return
  297. * - ESP_OK - success
  298. * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
  299. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
  300. */
  301. esp_err_t esp_netif_set_hostname(esp_netif_t *esp_netif, const char *hostname);
  302. /**
  303. * @brief Get interface hostname.
  304. *
  305. * @param[in] esp_netif Handle to esp-netif instance
  306. * @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).
  307. *
  308. * @return
  309. * - ESP_OK - success
  310. * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error
  311. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
  312. */
  313. esp_err_t esp_netif_get_hostname(esp_netif_t *esp_netif, const char **hostname);
  314. /**
  315. * @brief Test if supplied interface is up or down
  316. *
  317. * @param[in] esp_netif Handle to esp-netif instance
  318. *
  319. * @return
  320. * - true - Interface is up
  321. * - false - Interface is down
  322. */
  323. bool esp_netif_is_netif_up(esp_netif_t *esp_netif);
  324. /**
  325. * @brief Get interface's IP address information
  326. *
  327. * If the interface is up, IP information is read directly from the TCP/IP stack.
  328. * If the interface is down, IP information is read from a copy kept in the ESP-NETIF instance
  329. *
  330. * @param[in] esp_netif Handle to esp-netif instance
  331. * @param[out] ip_info If successful, IP information will be returned in this argument.
  332. *
  333. * @return
  334. * - ESP_OK
  335. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  336. */
  337. esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
  338. /**
  339. * @brief Get interface's old IP information
  340. *
  341. * Returns an "old" IP address previously stored for the interface when the valid IP changed.
  342. *
  343. * If the IP lost timer has expired (meaning the interface was down for longer than the configured interval)
  344. * then the old IP information will be zero.
  345. *
  346. * @param[in] esp_netif Handle to esp-netif instance
  347. * @param[out] ip_info If successful, IP information will be returned in this argument.
  348. *
  349. * @return
  350. * - ESP_OK
  351. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  352. */
  353. esp_err_t esp_netif_get_old_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
  354. /**
  355. * @brief Set interface's IP address information
  356. *
  357. * This function is mainly used to set a static IP on an interface.
  358. *
  359. * If the interface is up, the new IP information is set directly in the TCP/IP stack.
  360. *
  361. * The copy of IP information kept in the ESP-NETIF instance is also updated (this
  362. * copy is returned if the IP is queried while the interface is still down.)
  363. *
  364. * @note DHCP client/server must be stopped (if enabled for this interface) before setting new IP information.
  365. *
  366. * @note Calling this interface for may generate a SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event.
  367. *
  368. * @param[in] esp_netif Handle to esp-netif instance
  369. * @param[in] ip_info IP information to set on the specified interface
  370. *
  371. * @return
  372. * - ESP_OK
  373. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  374. * - ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED If DHCP server or client is still running
  375. */
  376. esp_err_t esp_netif_set_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info);
  377. /**
  378. * @brief Set interface old IP information
  379. *
  380. * This function is called from the DHCP client (if enabled), before a new IP is set.
  381. * It is also called from the default handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events.
  382. *
  383. * Calling this function stores the previously configured IP, which can be used to determine if the IP changes in the future.
  384. *
  385. * 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.
  386. *
  387. * @param[in] esp_netif Handle to esp-netif instance
  388. * @param[in] ip_info Store the old IP information for the specified interface
  389. *
  390. * @return
  391. * - ESP_OK
  392. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  393. */
  394. esp_err_t esp_netif_set_old_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info);
  395. /**
  396. * @brief Get net interface index from network stack implementation
  397. *
  398. * @note This index could be used in `setsockopt()` to bind socket with multicast interface
  399. *
  400. * @param[in] esp_netif Handle to esp-netif instance
  401. *
  402. * @return
  403. * implementation specific index of interface represented with supplied esp_netif
  404. */
  405. int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif);
  406. /**
  407. * @brief Get net interface name from network stack implementation
  408. *
  409. * @note This name could be used in `setsockopt()` to bind socket with appropriate interface
  410. *
  411. * @param[in] esp_netif Handle to esp-netif instance
  412. * @param[out] name Interface name as specified in underlying TCP/IP stack. Note that the
  413. * actual name will be copied to the specified buffer, which must be allocated to hold
  414. * maximum interface name size (6 characters for lwIP)
  415. *
  416. * @return
  417. * - ESP_OK
  418. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  419. */
  420. esp_err_t esp_netif_get_netif_impl_name(esp_netif_t *esp_netif, char* name);
  421. /**
  422. * @}
  423. */
  424. /**
  425. * @defgroup ESP_NETIF_NET_DHCP ESP-NETIF DHCP Settings
  426. * @brief Network stack related interface to DHCP client and server
  427. */
  428. /** @addtogroup ESP_NETIF_NET_DHCP
  429. * @{
  430. */
  431. /**
  432. * @brief Set or Get DHCP server option
  433. *
  434. * @param[in] esp_netif Handle to esp-netif instance
  435. * @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
  436. * @param[in] opt_id Option index to get or set, must be one of the supported enum values.
  437. * @param[inout] opt_val Pointer to the option parameter.
  438. * @param[in] opt_len Length of the option parameter.
  439. *
  440. * @return
  441. * - ESP_OK
  442. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  443. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
  444. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
  445. */
  446. esp_err_t
  447. 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,
  448. void *opt_val, uint32_t opt_len);
  449. /**
  450. * @brief Set or Get DHCP client option
  451. *
  452. * @param[in] esp_netif Handle to esp-netif instance
  453. * @param[in] opt_op ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
  454. * @param[in] opt_id Option index to get or set, must be one of the supported enum values.
  455. * @param[inout] opt_val Pointer to the option parameter.
  456. * @param[in] opt_len Length of the option parameter.
  457. *
  458. * @return
  459. * - ESP_OK
  460. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  461. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
  462. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
  463. */
  464. esp_err_t
  465. 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,
  466. void *opt_val, uint32_t opt_len);
  467. /**
  468. * @brief Start DHCP client (only if enabled in interface object)
  469. *
  470. * @note The default event handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events call this function.
  471. *
  472. * @param[in] esp_netif Handle to esp-netif instance
  473. *
  474. * @return
  475. * - ESP_OK
  476. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  477. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
  478. * - ESP_ERR_ESP_NETIF_DHCPC_START_FAILED
  479. */
  480. esp_err_t esp_netif_dhcpc_start(esp_netif_t *esp_netif);
  481. /**
  482. * @brief Stop DHCP client (only if enabled in interface object)
  483. *
  484. * @note Calling action_netif_stop() will also stop the DHCP Client if it is running.
  485. *
  486. * @param[in] esp_netif Handle to esp-netif instance
  487. *
  488. * @return
  489. * - ESP_OK
  490. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  491. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
  492. * - ESP_ERR_ESP_NETIF_IF_NOT_READY
  493. */
  494. esp_err_t esp_netif_dhcpc_stop(esp_netif_t *esp_netif);
  495. /**
  496. * @brief Get DHCP client status
  497. *
  498. * @param[in] esp_netif Handle to esp-netif instance
  499. * @param[out] status If successful, the status of DHCP client will be returned in this argument.
  500. *
  501. * @return
  502. * - ESP_OK
  503. */
  504. esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
  505. /**
  506. * @brief Get DHCP Server status
  507. *
  508. * @param[in] esp_netif Handle to esp-netif instance
  509. * @param[out] status If successful, the status of the DHCP server will be returned in this argument.
  510. *
  511. * @return
  512. * - ESP_OK
  513. */
  514. esp_err_t esp_netif_dhcps_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
  515. /**
  516. * @brief Start DHCP server (only if enabled in interface object)
  517. *
  518. * @param[in] esp_netif Handle to esp-netif instance
  519. *
  520. * @return
  521. * - ESP_OK
  522. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  523. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED
  524. */
  525. esp_err_t esp_netif_dhcps_start(esp_netif_t *esp_netif);
  526. /**
  527. * @brief Stop DHCP server (only if enabled in interface object)
  528. *
  529. * @param[in] esp_netif Handle to esp-netif instance
  530. *
  531. * @return
  532. * - ESP_OK
  533. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  534. * - ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
  535. * - ESP_ERR_ESP_NETIF_IF_NOT_READY
  536. */
  537. esp_err_t esp_netif_dhcps_stop(esp_netif_t *esp_netif);
  538. /**
  539. * @}
  540. */
  541. /**
  542. * @defgroup ESP_NETIF_NET_DNS ESP-NETIF DNS Settings
  543. * @brief Network stack related interface to NDS
  544. */
  545. /** @addtogroup ESP_NETIF_NET_DNS
  546. * @{
  547. */
  548. /**
  549. * @brief Set DNS Server information
  550. *
  551. * This function behaves differently if DHCP server or client is enabled
  552. *
  553. * If DHCP client is enabled, main and backup DNS servers will be updated automatically
  554. * from the DHCP lease if the relevant DHCP options are set. Fallback DNS Server is never updated from the DHCP lease
  555. * and is designed to be set via this API.
  556. * If DHCP client is disabled, all DNS server types can be set via this API only.
  557. *
  558. * If DHCP server is enabled, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option
  559. * to DHCP clients (Wi-Fi stations).
  560. * - The default Main DNS server is typically the IP of the Wi-Fi AP interface itself.
  561. * - This function can override it by setting server type ESP_NETIF_DNS_MAIN.
  562. * - Other DNS Server types are not supported for the Wi-Fi AP interface.
  563. *
  564. * @param[in] esp_netif Handle to esp-netif instance
  565. * @param[in] type Type of DNS Server to set: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK
  566. * @param[in] dns DNS Server address to set
  567. *
  568. * @return
  569. * - ESP_OK on success
  570. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params
  571. */
  572. 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);
  573. /**
  574. * @brief Get DNS Server information
  575. *
  576. * Return the currently configured DNS Server address for the specified interface and Server type.
  577. *
  578. * This may be result of a previous call to esp_netif_set_dns_info(). If the interface's DHCP client is enabled,
  579. * the Main or Backup DNS Server may be set by the current DHCP lease.
  580. *
  581. * @param[in] esp_netif Handle to esp-netif instance
  582. * @param[in] type Type of DNS Server to get: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK
  583. * @param[out] dns DNS Server result is written here on success
  584. *
  585. * @return
  586. * - ESP_OK on success
  587. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params
  588. */
  589. 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);
  590. /**
  591. * @}
  592. */
  593. /**
  594. * @defgroup ESP_NETIF_NET_IP ESP-NETIF IP address related interface
  595. * @brief Network stack related interface to IP
  596. */
  597. /** @addtogroup ESP_NETIF_NET_IP
  598. * @{
  599. */
  600. #if CONFIG_LWIP_IPV6
  601. /**
  602. * @brief Create interface link-local IPv6 address
  603. *
  604. * Cause the TCP/IP stack to create a link-local IPv6 address for the specified interface.
  605. *
  606. * This function also registers a callback for the specified interface, so that if the link-local address becomes
  607. * verified as the preferred address then a SYSTEM_EVENT_GOT_IP6 event will be sent.
  608. *
  609. * @param[in] esp_netif Handle to esp-netif instance
  610. *
  611. * @return
  612. * - ESP_OK
  613. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  614. */
  615. esp_err_t esp_netif_create_ip6_linklocal(esp_netif_t *esp_netif);
  616. /**
  617. * @brief Get interface link-local IPv6 address
  618. *
  619. * If the specified interface is up and a preferred link-local IPv6 address
  620. * has been created for the interface, return a copy of it.
  621. *
  622. * @param[in] esp_netif Handle to esp-netif instance
  623. * @param[out] if_ip6 IPv6 information will be returned in this argument if successful.
  624. *
  625. * @return
  626. * - ESP_OK
  627. * - ESP_FAIL If interface is down, does not have a link-local IPv6 address,
  628. * or the link-local IPv6 address is not a preferred address.
  629. */
  630. esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
  631. /**
  632. * @brief Get interface global IPv6 address
  633. *
  634. * If the specified interface is up and a preferred global IPv6 address
  635. * has been created for the interface, return a copy of it.
  636. *
  637. * @param[in] esp_netif Handle to esp-netif instance
  638. * @param[out] if_ip6 IPv6 information will be returned in this argument if successful.
  639. *
  640. * @return
  641. * - ESP_OK
  642. * - ESP_FAIL If interface is down, does not have a global IPv6 address,
  643. * or the global IPv6 address is not a preferred address.
  644. */
  645. esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
  646. /**
  647. * @brief Get all IPv6 addresses of the specified interface
  648. *
  649. * @param[in] esp_netif Handle to esp-netif instance
  650. * @param[out] if_ip6 Array of IPv6 addresses will be copied to the argument
  651. *
  652. * @return
  653. * number of returned IPv6 addresses
  654. */
  655. int esp_netif_get_all_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[]);
  656. #endif
  657. /**
  658. * @brief Sets IPv4 address to the specified octets
  659. *
  660. * @param[out] addr IP address to be set
  661. * @param a the first octet (127 for IP 127.0.0.1)
  662. * @param b
  663. * @param c
  664. * @param d
  665. */
  666. void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d);
  667. /**
  668. * @brief Converts numeric IP address into decimal dotted ASCII representation.
  669. *
  670. * @param addr ip address in network order to convert
  671. * @param buf target buffer where the string is stored
  672. * @param buflen length of buf
  673. * @return either pointer to buf which now holds the ASCII
  674. * representation of addr or NULL if buf was too small
  675. */
  676. char *esp_ip4addr_ntoa(const esp_ip4_addr_t *addr, char *buf, int buflen);
  677. /**
  678. * @brief Ascii internet address interpretation routine
  679. * The value returned is in network order.
  680. *
  681. * @param addr IP address in ascii representation (e.g. "127.0.0.1")
  682. * @return ip address in network order
  683. */
  684. uint32_t esp_ip4addr_aton(const char *addr);
  685. /**
  686. * @brief Converts Ascii internet IPv4 address into esp_ip4_addr_t
  687. *
  688. * @param[in] src IPv4 address in ascii representation (e.g. "127.0.0.1")
  689. * @param[out] dst Address of the target esp_ip4_addr_t structure to receive converted address
  690. * @return
  691. * - ESP_OK on success
  692. * - ESP_FAIL if conversion failed
  693. * - ESP_ERR_INVALID_ARG if invalid parameter is passed into
  694. */
  695. esp_err_t esp_netif_str_to_ip4(const char *src, esp_ip4_addr_t *dst);
  696. /**
  697. * @brief Converts Ascii internet IPv6 address into esp_ip4_addr_t
  698. * Zeros in the IP address can be stripped or completely ommited: "2001:db8:85a3:0:0:0:2:1" or "2001:db8::2:1")
  699. *
  700. * @param[in] src IPv6 address in ascii representation (e.g. ""2001:0db8:85a3:0000:0000:0000:0002:0001")
  701. * @param[out] dst Address of the target esp_ip6_addr_t structure to receive converted address
  702. * @return
  703. * - ESP_OK on success
  704. * - ESP_FAIL if conversion failed
  705. * - ESP_ERR_INVALID_ARG if invalid parameter is passed into
  706. */
  707. esp_err_t esp_netif_str_to_ip6(const char *src, esp_ip6_addr_t *dst);
  708. /**
  709. * @}
  710. */
  711. /**
  712. * @defgroup ESP_NETIF_CONVERT ESP-NETIF Conversion utilities
  713. * @brief ESP-NETIF conversion utilities to related keys, flags, implementation handle
  714. */
  715. /** @addtogroup ESP_NETIF_CONVERT
  716. * @{
  717. */
  718. /**
  719. * @brief Gets media driver handle for this esp-netif instance
  720. *
  721. * @param[in] esp_netif Handle to esp-netif instance
  722. *
  723. * @return opaque pointer of related IO driver
  724. */
  725. esp_netif_iodriver_handle esp_netif_get_io_driver(esp_netif_t *esp_netif);
  726. /**
  727. * @brief Searches over a list of created objects to find an instance with supplied if key
  728. *
  729. * @param if_key Textual description of network interface
  730. *
  731. * @return Handle to esp-netif instance
  732. */
  733. esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key);
  734. /**
  735. * @brief Returns configured flags for this interface
  736. *
  737. * @param[in] esp_netif Handle to esp-netif instance
  738. *
  739. * @return Configuration flags
  740. */
  741. esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif);
  742. /**
  743. * @brief Returns configured interface key for this esp-netif instance
  744. *
  745. * @param[in] esp_netif Handle to esp-netif instance
  746. *
  747. * @return Textual description of related interface
  748. */
  749. const char *esp_netif_get_ifkey(esp_netif_t *esp_netif);
  750. /**
  751. * @brief Returns configured interface type for this esp-netif instance
  752. *
  753. * @param[in] esp_netif Handle to esp-netif instance
  754. *
  755. * @return Enumerated type of this interface, such as station, AP, ethernet
  756. */
  757. const char *esp_netif_get_desc(esp_netif_t *esp_netif);
  758. /**
  759. * @brief Returns configured routing priority number
  760. *
  761. * @param[in] esp_netif Handle to esp-netif instance
  762. *
  763. * @return Integer representing the instance's route-prio, or -1 if invalid paramters
  764. */
  765. int esp_netif_get_route_prio(esp_netif_t *esp_netif);
  766. /**
  767. * @brief Returns configured event for this esp-netif instance and supplied event type
  768. *
  769. * @param[in] esp_netif Handle to esp-netif instance
  770. *
  771. * @param event_type (either get or lost IP)
  772. *
  773. * @return specific event id which is configured to be raised if the interface lost or acquired IP address
  774. * -1 if supplied event_type is not known
  775. */
  776. int32_t esp_netif_get_event_id(esp_netif_t *esp_netif, esp_netif_ip_event_type_t event_type);
  777. /**
  778. * @}
  779. */
  780. /**
  781. * @defgroup ESP_NETIF_LIST ESP-NETIF List of interfaces
  782. * @brief APIs to enumerate all registered interfaces
  783. */
  784. /** @addtogroup ESP_NETIF_LIST
  785. * @{
  786. */
  787. /**
  788. * @brief Iterates over list of interfaces. Returns first netif if NULL given as parameter
  789. *
  790. * @param[in] esp_netif Handle to esp-netif instance
  791. *
  792. * @return First netif from the list if supplied parameter is NULL, next one otherwise
  793. */
  794. esp_netif_t *esp_netif_next(esp_netif_t *esp_netif);
  795. /**
  796. * @brief Returns number of registered esp_netif objects
  797. *
  798. * @return Number of esp_netifs
  799. */
  800. size_t esp_netif_get_nr_of_ifs(void);
  801. /**
  802. * @brief increase the reference counter of net stack buffer
  803. *
  804. * @param[in] netstack_buf the net stack buffer
  805. *
  806. */
  807. void esp_netif_netstack_buf_ref(void *netstack_buf);
  808. /**
  809. * @brief free the netstack buffer
  810. *
  811. * @param[in] netstack_buf the net stack buffer
  812. *
  813. */
  814. void esp_netif_netstack_buf_free(void *netstack_buf);
  815. /**
  816. * @}
  817. */
  818. #ifdef __cplusplus
  819. }
  820. #endif
  821. #endif /* _ESP_NETIF_H_ */