esp_wifi_internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // Copyright 2015-2016 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. /*
  14. * All the APIs declared here are internal only APIs, it can only be used by
  15. * espressif internal modules, such as SSC, LWIP, TCPIP adapter etc, espressif
  16. * customers are not recommended to use them.
  17. *
  18. * If someone really want to use specified APIs declared in here, please contact
  19. * espressif AE/developer to make sure you know the limitations or risk of
  20. * the API, otherwise you may get unexpected behavior!!!
  21. *
  22. */
  23. #ifndef __ESP_WIFI_INTERNAL_H__
  24. #define __ESP_WIFI_INTERNAL_H__
  25. #include <stdint.h>
  26. #include <stdbool.h>
  27. #include "freertos/FreeRTOS.h"
  28. #include "freertos/queue.h"
  29. #include "rom/queue.h"
  30. #include "esp_err.h"
  31. #include "esp_wifi_types.h"
  32. #include "esp_event.h"
  33. #include "esp_wifi.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. typedef struct {
  38. QueueHandle_t handle; /**< FreeRTOS queue handler */
  39. void *storage; /**< storage for FreeRTOS queue */
  40. } wifi_static_queue_t;
  41. /**
  42. * @brief WiFi log level
  43. *
  44. */
  45. typedef enum {
  46. WIFI_LOG_NONE = 0,
  47. WIFI_LOG_ERROR, /*enabled by default*/
  48. WIFI_LOG_WARNING, /*enabled by default*/
  49. WIFI_LOG_INFO, /*enabled by default*/
  50. WIFI_LOG_DEBUG, /*can be set in menuconfig*/
  51. WIFI_LOG_VERBOSE, /*can be set in menuconfig*/
  52. } wifi_log_level_t;
  53. /**
  54. * @brief WiFi log module definition
  55. *
  56. */
  57. typedef enum {
  58. WIFI_LOG_MODULE_ALL = 0, /*all log modules */
  59. WIFI_LOG_MODULE_WIFI, /*logs related to WiFi*/
  60. WIFI_LOG_MODULE_COEX, /*logs related to WiFi and BT(or BLE) coexist*/
  61. WIFI_LOG_MODULE_MESH, /*logs related to Mesh*/
  62. } wifi_log_module_t;
  63. /**
  64. * @brief WiFi log submodule definition
  65. *
  66. */
  67. #define WIFI_LOG_SUBMODULE_ALL (0) /*all log submodules*/
  68. #define WIFI_LOG_SUBMODULE_INIT (1) /*logs related to initialization*/
  69. #define WIFI_LOG_SUBMODULE_IOCTL (1<<1) /*logs related to API calling*/
  70. #define WIFI_LOG_SUBMODULE_CONN (1<<2) /*logs related to connecting*/
  71. #define WIFI_LOG_SUBMODULE_SCAN (1<<3) /*logs related to scaning*/
  72. /**
  73. * @brief Initialize Wi-Fi Driver
  74. * Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
  75. * WiFi NVS structure among others.
  76. *
  77. * For the most part, you need not call this function directly. It gets called
  78. * from esp_wifi_init().
  79. *
  80. * This function may be called, if you only need to initialize the Wi-Fi driver
  81. * without having to use the network stack on top.
  82. *
  83. * @param config provide WiFi init configuration
  84. *
  85. * @return
  86. * - ESP_OK: succeed
  87. * - ESP_ERR_NO_MEM: out of memory
  88. * - others: refer to error code esp_err.h
  89. */
  90. esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
  91. /**
  92. * @brief get whether the wifi driver is allowed to transmit data or not
  93. *
  94. * @return
  95. * - true : upper layer should stop to transmit data to wifi driver
  96. * - false : upper layer can transmit data to wifi driver
  97. */
  98. bool esp_wifi_internal_tx_is_stop(void);
  99. /**
  100. * @brief free the rx buffer which allocated by wifi driver
  101. *
  102. * @param void* buffer: rx buffer pointer
  103. */
  104. void esp_wifi_internal_free_rx_buffer(void* buffer);
  105. /**
  106. * @brief transmit the buffer via wifi driver
  107. *
  108. * @param wifi_interface_t wifi_if : wifi interface id
  109. * @param void *buffer : the buffer to be tansmit
  110. * @param uint16_t len : the length of buffer
  111. *
  112. * @return
  113. * - ERR_OK : Successfully transmit the buffer to wifi driver
  114. * - ERR_MEM : Out of memory
  115. * - ERR_IF : WiFi driver error
  116. * - ERR_ARG : Invalid argument
  117. */
  118. int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, uint16_t len);
  119. /**
  120. * @brief The WiFi RX callback function
  121. *
  122. * Each time the WiFi need to forward the packets to high layer, the callback function will be called
  123. */
  124. typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
  125. /**
  126. * @brief Set the WiFi RX callback
  127. *
  128. * @attention 1. Currently we support only one RX callback for each interface
  129. *
  130. * @param wifi_interface_t ifx : interface
  131. * @param wifi_rxcb_t fn : WiFi RX callback
  132. *
  133. * @return
  134. * - ESP_OK : succeed
  135. * - others : fail
  136. */
  137. esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
  138. /**
  139. * @brief Notify WIFI driver that the station got ip successfully
  140. *
  141. * @return
  142. * - ESP_OK : succeed
  143. * - others : fail
  144. */
  145. esp_err_t esp_wifi_internal_set_sta_ip(void);
  146. /**
  147. * @brief enable or disable transmitting WiFi MAC frame with fixed rate
  148. *
  149. * @attention 1. If fixed rate is enabled, both management and data frame are transmitted with fixed rate
  150. * @attention 2. Make sure that the receiver is able to receive the frame with the fixed rate if you want the frame to be received
  151. *
  152. * @param ifx : wifi interface
  153. * @param en : false - disable, true - enable
  154. * @param rate : PHY rate
  155. *
  156. * @return
  157. * - ERR_OK : succeed
  158. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  159. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  160. * - ESP_ERR_WIFI_IF : invalid WiFi interface
  161. * - ESP_ERR_INVALID_ARG : invalid rate
  162. * - ESP_ERR_NOT_SUPPORTED : do not support to set fixed rate if TX AMPDU is enabled
  163. */
  164. esp_err_t esp_wifi_internal_set_fix_rate(wifi_interface_t ifx, bool en, wifi_phy_rate_t rate);
  165. /**
  166. * @brief Check the MD5 values of the OS adapter header files in IDF and WiFi library
  167. *
  168. * @attention 1. It is used for internal CI version check
  169. *
  170. * @return
  171. * - ESP_OK : succeed
  172. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  173. */
  174. esp_err_t esp_wifi_internal_osi_funcs_md5_check(const char *md5);
  175. /**
  176. * @brief Check the MD5 values of the crypto types header files in IDF and WiFi library
  177. *
  178. * @attention 1. It is used for internal CI version check
  179. *
  180. * @return
  181. * - ESP_OK : succeed
  182. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  183. */
  184. esp_err_t esp_wifi_internal_crypto_funcs_md5_check(const char *md5);
  185. /**
  186. * @brief Check the MD5 values of the esp_wifi_types.h in IDF and WiFi library
  187. *
  188. * @attention 1. It is used for internal CI version check
  189. *
  190. * @return
  191. * - ESP_OK : succeed
  192. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  193. */
  194. esp_err_t esp_wifi_internal_wifi_type_md5_check(const char *md5);
  195. /**
  196. * @brief Check the MD5 values of the esp_wifi.h in IDF and WiFi library
  197. *
  198. * @attention 1. It is used for internal CI version check
  199. *
  200. * @return
  201. * - ESP_OK : succeed
  202. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  203. */
  204. esp_err_t esp_wifi_internal_esp_wifi_md5_check(const char *md5);
  205. /**
  206. * @brief Allocate a chunk of memory for WiFi driver
  207. *
  208. * @attention This API is not used for DMA memory allocation.
  209. *
  210. * @param size_t size : Size, in bytes, of the amount of memory to allocate
  211. *
  212. * @return A pointer to the memory allocated on success, NULL on failure
  213. */
  214. void *wifi_malloc( size_t size );
  215. /**
  216. * @brief Reallocate a chunk of memory for WiFi driver
  217. *
  218. * @attention This API is not used for DMA memory allocation.
  219. *
  220. * @param void * ptr : Pointer to previously allocated memory, or NULL for a new allocation.
  221. * @param size_t size : Size, in bytes, of the amount of memory to allocate
  222. *
  223. * @return A pointer to the memory allocated on success, NULL on failure
  224. */
  225. void *wifi_realloc( void *ptr, size_t size );
  226. /**
  227. * @brief Callocate memory for WiFi driver
  228. *
  229. * @attention This API is not used for DMA memory allocation.
  230. *
  231. * @param size_t n : Number of continuing chunks of memory to allocate
  232. * @param size_t size : Size, in bytes, of the amount of memory to allocate
  233. *
  234. * @return A pointer to the memory allocated on success, NULL on failure
  235. */
  236. void *wifi_calloc( size_t n, size_t size );
  237. /**
  238. * @brief Update WiFi MAC time
  239. *
  240. * @param uint32_t time_delta : time duration since the WiFi/BT common clock is disabled
  241. *
  242. * @return Always returns ESP_OK
  243. */
  244. typedef esp_err_t (* wifi_mac_time_update_cb_t)( uint32_t time_delta );
  245. /**
  246. * @brief Update WiFi MAC time
  247. *
  248. * @param uint32_t time_delta : time duration since the WiFi/BT common clock is disabled
  249. *
  250. * @return Always returns ESP_OK
  251. */
  252. esp_err_t esp_wifi_internal_update_mac_time( uint32_t time_delta );
  253. /**
  254. * @brief Set current WiFi log level
  255. *
  256. * @param level Log level.
  257. *
  258. * @return
  259. * - ESP_OK: succeed
  260. * - ESP_FAIL: level is invalid
  261. */
  262. esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level);
  263. /**
  264. * @brief Set current log module and submodule
  265. *
  266. * @param module Log module
  267. * @param submodule Log submodule
  268. * @param enable enable or disable
  269. * If module == 0 && enable == 0, all log modules are disabled.
  270. * If module == 0 && enable == 1, all log modules are enabled.
  271. * If submodule == 0 && enable == 0, all log submodules are disabled.
  272. * If submodule == 0 && enable == 1, all log submodules are enabled.
  273. *
  274. * @return
  275. * - ESP_OK: succeed
  276. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  277. * - ESP_ERR_WIFI_ARG: invalid argument
  278. */
  279. esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submodule, bool enable);
  280. /**
  281. * @brief Get current WiFi log info
  282. *
  283. * @param log_level the return log level.
  284. * @param log_mod the return log module and submodule
  285. *
  286. * @return
  287. * - ESP_OK: succeed
  288. */
  289. esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod);
  290. /**
  291. * @brief Get the user-configured channel info
  292. *
  293. * @param ifx : WiFi interface
  294. * @param primary : store the configured primary channel
  295. * @param second : store the configured second channel
  296. *
  297. * @return
  298. * - ESP_OK: succeed
  299. */
  300. esp_err_t esp_wifi_internal_get_config_channel(wifi_interface_t ifx, uint8_t *primary, uint8_t *second);
  301. /**
  302. * @brief Get the negotiated channel info after WiFi connection established
  303. *
  304. * @param ifx : WiFi interface
  305. * @param aid : the connection number when a STA connects to the softAP
  306. * @param primary : store the negotiated primary channel
  307. * @param second : store the negotiated second channel
  308. * @attention the aid param is only works when the ESP32 in softAP/softAP+STA mode
  309. *
  310. * @return
  311. * - ESP_OK: succeed
  312. */
  313. esp_err_t esp_wifi_internal_get_negotiated_channel(wifi_interface_t ifx, uint8_t aid, uint8_t *primary, uint8_t *second);
  314. /**
  315. * @brief Get the negotiated bandwidth info after WiFi connection established
  316. *
  317. * @param ifx : WiFi interface
  318. * @param bw : store the negotiated bandwidth
  319. *
  320. * @return
  321. * - ESP_OK: succeed
  322. */
  323. esp_err_t esp_wifi_internal_get_negotiated_bandwidth(wifi_interface_t ifx, uint8_t aid, uint8_t *bw);
  324. #ifdef __cplusplus
  325. }
  326. #endif
  327. #endif /* __ESP_WIFI_H__ */