esp_netif.h 30 KB

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