esp_wifi_internal.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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_ERROR = 0, /*enabled by default*/
  47. WIFI_LOG_WARNING, /*enabled by default*/
  48. WIFI_LOG_INFO, /*enabled by default*/
  49. WIFI_LOG_DEBUG, /*can be set in menuconfig*/
  50. WIFI_LOG_VERBOSE, /*can be set in menuconfig*/
  51. } wifi_log_level_t;
  52. /**
  53. * @brief WiFi log module definition
  54. *
  55. */
  56. typedef enum {
  57. WIFI_LOG_MODULE_ALL = 0, /*all log modules */
  58. WIFI_LOG_MODULE_WIFI, /*logs related to WiFi*/
  59. WIFI_LOG_MODULE_COEX, /*logs related to WiFi and BT(or BLE) coexist*/
  60. WIFI_LOG_MODULE_MESH, /*logs related to Mesh*/
  61. } wifi_log_module_t;
  62. /**
  63. * @brief WiFi log submodule definition
  64. *
  65. */
  66. #define WIFI_LOG_SUBMODULE_ALL (0) /*all log submodules*/
  67. #define WIFI_LOG_SUBMODULE_INIT (1) /*logs related to initialization*/
  68. #define WIFI_LOG_SUBMODULE_IOCTL (1<<1) /*logs related to API calling*/
  69. #define WIFI_LOG_SUBMODULE_CONN (1<<2) /*logs related to connecting*/
  70. #define WIFI_LOG_SUBMODULE_SCAN (1<<3) /*logs related to scaning*/
  71. /**
  72. * @brief Initialize Wi-Fi Driver
  73. * Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
  74. * WiFi NVS structure among others.
  75. *
  76. * For the most part, you need not call this function directly. It gets called
  77. * from esp_wifi_init().
  78. *
  79. * This function may be called, if you only need to initialize the Wi-Fi driver
  80. * without having to use the network stack on top.
  81. *
  82. * @param config provide WiFi init configuration
  83. *
  84. * @return
  85. * - ESP_OK: succeed
  86. * - ESP_ERR_NO_MEM: out of memory
  87. * - others: refer to error code esp_err.h
  88. */
  89. esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
  90. /**
  91. * @brief get whether the wifi driver is allowed to transmit data or not
  92. *
  93. * @return
  94. * - true : upper layer should stop to transmit data to wifi driver
  95. * - false : upper layer can transmit data to wifi driver
  96. */
  97. bool esp_wifi_internal_tx_is_stop(void);
  98. /**
  99. * @brief free the rx buffer which allocated by wifi driver
  100. *
  101. * @param void* buffer: rx buffer pointer
  102. */
  103. void esp_wifi_internal_free_rx_buffer(void* buffer);
  104. /**
  105. * @brief transmit the buffer via wifi driver
  106. *
  107. * @param wifi_interface_t wifi_if : wifi interface id
  108. * @param void *buffer : the buffer to be tansmit
  109. * @param uint16_t len : the length of buffer
  110. *
  111. * @return
  112. * - ERR_OK : Successfully transmit the buffer to wifi driver
  113. * - ERR_MEM : Out of memory
  114. * - ERR_IF : WiFi driver error
  115. * - ERR_ARG : Invalid argument
  116. */
  117. int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, uint16_t len);
  118. /**
  119. * @brief The WiFi RX callback function
  120. *
  121. * Each time the WiFi need to forward the packets to high layer, the callback function will be called
  122. */
  123. typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
  124. /**
  125. * @brief Set the WiFi RX callback
  126. *
  127. * @attention 1. Currently we support only one RX callback for each interface
  128. *
  129. * @param wifi_interface_t ifx : interface
  130. * @param wifi_rxcb_t fn : WiFi RX callback
  131. *
  132. * @return
  133. * - ESP_OK : succeed
  134. * - others : fail
  135. */
  136. esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
  137. /**
  138. * @brief Notify WIFI driver that the station got ip successfully
  139. *
  140. * @return
  141. * - ESP_OK : succeed
  142. * - others : fail
  143. */
  144. esp_err_t esp_wifi_internal_set_sta_ip(void);
  145. /**
  146. * @brief enable or disable transmitting WiFi MAC frame with fixed rate
  147. *
  148. * @attention 1. If fixed rate is enabled, both management and data frame are transmitted with fixed rate
  149. * @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
  150. *
  151. * @param ifx : wifi interface
  152. * @param en : false - disable, true - enable
  153. * @param rate : PHY rate
  154. *
  155. * @return
  156. * - ERR_OK : succeed
  157. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  158. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  159. * - ESP_ERR_WIFI_IF : invalid WiFi interface
  160. * - ESP_ERR_INVALID_ARG : invalid rate
  161. * - ESP_ERR_NOT_SUPPORTED : do not support to set fixed rate if TX AMPDU is enabled
  162. */
  163. esp_err_t esp_wifi_internal_set_fix_rate(wifi_interface_t ifx, bool en, wifi_phy_rate_t rate);
  164. /**
  165. * @brief Check the MD5 values of the OS adapter header files in IDF and WiFi library
  166. *
  167. * @attention 1. It is used for internal CI version check
  168. *
  169. * @return
  170. * - ESP_OK : succeed
  171. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  172. */
  173. esp_err_t esp_wifi_internal_osi_funcs_md5_check(const char *md5);
  174. /**
  175. * @brief Check the MD5 values of the crypto types header files in IDF and WiFi library
  176. *
  177. * @attention 1. It is used for internal CI version check
  178. *
  179. * @return
  180. * - ESP_OK : succeed
  181. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  182. */
  183. esp_err_t esp_wifi_internal_crypto_funcs_md5_check(const char *md5);
  184. /**
  185. * @brief Check the git commit id of WiFi library
  186. *
  187. * @attention 1. It is used for internal CI WiFi library check
  188. *
  189. * @return
  190. * - ESP_OK : succeed
  191. * - ESP_FAIL : fail
  192. */
  193. esp_err_t esp_wifi_internal_git_commit_id_check(void);
  194. /**
  195. * @brief Allocate a chunk of memory for WiFi driver
  196. *
  197. * @attention This API is not used for DMA memory allocation.
  198. *
  199. * @param size_t size : Size, in bytes, of the amount of memory to allocate
  200. *
  201. * @return A pointer to the memory allocated on success, NULL on failure
  202. */
  203. void *wifi_malloc( size_t size );
  204. /**
  205. * @brief Reallocate a chunk of memory for WiFi driver
  206. *
  207. * @attention This API is not used for DMA memory allocation.
  208. *
  209. * @param void * ptr : Pointer to previously allocated memory, or NULL for a new allocation.
  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_realloc( void *ptr, size_t size );
  215. /**
  216. * @brief Callocate memory for WiFi driver
  217. *
  218. * @attention This API is not used for DMA memory allocation.
  219. *
  220. * @param size_t n : Number of continuing chunks of memory to allocate
  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_calloc( size_t n, size_t size );
  226. /**
  227. * @brief Update WiFi MAC time
  228. *
  229. * @param uint32_t time_delta : time duration since the WiFi/BT common clock is disabled
  230. *
  231. * @return Always returns ESP_OK
  232. */
  233. esp_err_t esp_wifi_internal_update_mac_time( uint32_t time_delta );
  234. /**
  235. * @brief Set current WiFi log level
  236. *
  237. * @param level Log level.
  238. *
  239. * @return
  240. * - ESP_OK: succeed
  241. * - ESP_FAIL: level is invalid
  242. */
  243. esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level);
  244. /**
  245. * @brief Set current log module and submodule
  246. *
  247. * @param module Log module
  248. * @param submodule Log submodule
  249. * @param enable enable or disable
  250. * If module == 0 && enable == 0, all log modules are disabled.
  251. * If module == 0 && enable == 1, all log modules are enabled.
  252. * If submodule == 0 && enable == 0, all log submodules are disabled.
  253. * If submodule == 0 && enable == 1, all log submodules are enabled.
  254. *
  255. * @return
  256. * - ESP_OK: succeed
  257. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  258. * - ESP_ERR_WIFI_ARG: invalid argument
  259. */
  260. esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submodule, bool enable);
  261. /**
  262. * @brief Get current WiFi log info
  263. *
  264. * @param log_level the return log level.
  265. * @param log_mod the return log module and submodule
  266. *
  267. * @return
  268. * - ESP_OK: succeed
  269. */
  270. esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod);
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274. #endif /* __ESP_WIFI_H__ */