ctrl_api.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. /*
  2. * Espressif Systems Wireless LAN device driver
  3. *
  4. * Copyright (C) 2015-2022 Espressif Systems (Shanghai) PTE LTD
  5. * SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0
  6. */
  7. /** prevent recursive inclusion **/
  8. #ifndef __CTRL_API_H
  9. #define __CTRL_API_H
  10. #include <stdbool.h>
  11. #include "esp_hosted_config.pb-c.h"
  12. #define SUCCESS 0
  13. #define FAILURE -1
  14. #define MAC_SIZE_BYTES 6
  15. #define SSID_LENGTH 33
  16. #define MAX_MAC_STR_SIZE 18
  17. #define BSSID_STR_SIZE MAX_MAC_STR_SIZE
  18. #define PASSWORD_LENGTH 65
  19. #define STATUS_LENGTH 14
  20. #define VENDOR_OUI_BUF 3
  21. #define CALLBACK_SET_SUCCESS 0
  22. #define CALLBACK_AVAILABLE 0
  23. #define CALLBACK_NOT_REGISTERED -1
  24. #define MSG_ID_OUT_OF_ORDER -2
  25. #define MAX_FREE_BUFF_HANDLES 20
  26. /* If request is already being served and
  27. * another request is pending, time period for
  28. * which new request will wait in seconds
  29. * */
  30. #define WAIT_TIME_B2B_CTRL_REQ 5
  31. #define DEFAULT_CTRL_RESP_TIMEOUT 30
  32. #define DEFAULT_CTRL_RESP_AP_SCAN_TIMEOUT (60*3)
  33. #define DEFAULT_CTRL_RESP_CONNECT_AP_TIMEOUT (15*3)
  34. #ifndef MAC2STR
  35. #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
  36. #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
  37. #endif
  38. /*---- Control structures ----*/
  39. enum {
  40. CTRL_ERR_NOT_CONNECTED = 1,
  41. CTRL_ERR_NO_AP_FOUND,
  42. CTRL_ERR_INVALID_PASSWORD,
  43. CTRL_ERR_INVALID_ARGUMENT,
  44. CTRL_ERR_OUT_OF_RANGE,
  45. CTRL_ERR_MEMORY_FAILURE,
  46. CTRL_ERR_UNSUPPORTED_MSG,
  47. CTRL_ERR_INCORRECT_ARG,
  48. CTRL_ERR_PROTOBUF_ENCODE,
  49. CTRL_ERR_PROTOBUF_DECODE,
  50. CTRL_ERR_SET_ASYNC_CB,
  51. CTRL_ERR_TRANSPORT_SEND,
  52. CTRL_ERR_REQUEST_TIMEOUT,
  53. CTRL_ERR_REQ_IN_PROG,
  54. OUT_OF_RANGE
  55. };
  56. typedef enum {
  57. CTRL_MSGTYPE_INVALID = CTRL_MSG_TYPE__MsgType_Invalid,
  58. CTRL_REQ = CTRL_MSG_TYPE__Req,
  59. CTRL_RESP = CTRL_MSG_TYPE__Resp,
  60. CTRL_EVENT = CTRL_MSG_TYPE__Event,
  61. CTRL_MSGTYPE_MAX = CTRL_MSG_TYPE__MsgType_Max,
  62. } AppMsgType_e;
  63. typedef enum {
  64. CTRL_MSGID_INVALID = CTRL_MSG_ID__MsgId_Invalid,
  65. /*
  66. ** Request Msgs *
  67. */
  68. CTRL_REQ_BASE = CTRL_MSG_ID__Req_Base,
  69. CTRL_REQ_GET_MAC_ADDR = CTRL_MSG_ID__Req_GetMACAddress, //0x65
  70. CTRL_REQ_SET_MAC_ADDR = CTRL_MSG_ID__Req_SetMacAddress, //0x66
  71. CTRL_REQ_GET_WIFI_MODE = CTRL_MSG_ID__Req_GetWifiMode, //0x67
  72. CTRL_REQ_SET_WIFI_MODE = CTRL_MSG_ID__Req_SetWifiMode, //0x68
  73. CTRL_REQ_GET_AP_SCAN_LIST = CTRL_MSG_ID__Req_GetAPScanList, //0x69
  74. CTRL_REQ_GET_AP_CONFIG = CTRL_MSG_ID__Req_GetAPConfig, //0x6a
  75. CTRL_REQ_CONNECT_AP = CTRL_MSG_ID__Req_ConnectAP, //0x6b
  76. CTRL_REQ_DISCONNECT_AP = CTRL_MSG_ID__Req_DisconnectAP, //0x6c
  77. CTRL_REQ_GET_SOFTAP_CONFIG = CTRL_MSG_ID__Req_GetSoftAPConfig, //0x6d
  78. CTRL_REQ_SET_SOFTAP_VND_IE = CTRL_MSG_ID__Req_SetSoftAPVendorSpecificIE, //0x6e
  79. CTRL_REQ_START_SOFTAP = CTRL_MSG_ID__Req_StartSoftAP, //0x6f
  80. CTRL_REQ_GET_SOFTAP_CONN_STA_LIST = CTRL_MSG_ID__Req_GetSoftAPConnectedSTAList, //0x70
  81. CTRL_REQ_STOP_SOFTAP = CTRL_MSG_ID__Req_StopSoftAP, //0x71
  82. CTRL_REQ_SET_PS_MODE = CTRL_MSG_ID__Req_SetPowerSaveMode, //0x72
  83. CTRL_REQ_GET_PS_MODE = CTRL_MSG_ID__Req_GetPowerSaveMode, //0x73
  84. CTRL_REQ_OTA_BEGIN = CTRL_MSG_ID__Req_OTABegin, //0x74
  85. CTRL_REQ_OTA_WRITE = CTRL_MSG_ID__Req_OTAWrite, //0x75
  86. CTRL_REQ_OTA_END = CTRL_MSG_ID__Req_OTAEnd, //0x76
  87. CTRL_REQ_SET_WIFI_MAX_TX_POWER = CTRL_MSG_ID__Req_SetWifiMaxTxPower, //0x77
  88. CTRL_REQ_GET_WIFI_CURR_TX_POWER = CTRL_MSG_ID__Req_GetWifiCurrTxPower, //0x78
  89. CTRL_REQ_CONFIG_HEARTBEAT = CTRL_MSG_ID__Req_ConfigHeartbeat, //0x79
  90. CTRL_REQ_ENABLE_DISABLE = CTRL_MSG_ID__Req_EnableDisable, //0x7a
  91. CTRL_REQ_GET_FW_VERSION = CTRL_MSG_ID__Req_GetFwVersion, //0x7b
  92. /*
  93. * Add new control path command response before Req_Max
  94. * and update Req_Max
  95. */
  96. CTRL_REQ_MAX = CTRL_MSG_ID__Req_Max,
  97. /*
  98. ** Response Msgs *
  99. */
  100. CTRL_RESP_BASE = CTRL_MSG_ID__Resp_Base,
  101. CTRL_RESP_GET_MAC_ADDR = CTRL_MSG_ID__Resp_GetMACAddress, //0x65 -> 0xc9
  102. CTRL_RESP_SET_MAC_ADDRESS = CTRL_MSG_ID__Resp_SetMacAddress, //0x66 -> 0xca
  103. CTRL_RESP_GET_WIFI_MODE = CTRL_MSG_ID__Resp_GetWifiMode, //0x67 -> 0xcb
  104. CTRL_RESP_SET_WIFI_MODE = CTRL_MSG_ID__Resp_SetWifiMode, //0x68 -> 0xcc
  105. CTRL_RESP_GET_AP_SCAN_LIST = CTRL_MSG_ID__Resp_GetAPScanList, //0x69 -> 0xcd
  106. CTRL_RESP_GET_AP_CONFIG = CTRL_MSG_ID__Resp_GetAPConfig, //0x6a -> 0xce
  107. CTRL_RESP_CONNECT_AP = CTRL_MSG_ID__Resp_ConnectAP, //0x6b -> 0xdf
  108. CTRL_RESP_DISCONNECT_AP = CTRL_MSG_ID__Resp_DisconnectAP, //0x6c -> 0xd0
  109. CTRL_RESP_GET_SOFTAP_CONFIG = CTRL_MSG_ID__Resp_GetSoftAPConfig, //0x6d -> 0xd1
  110. CTRL_RESP_SET_SOFTAP_VND_IE = CTRL_MSG_ID__Resp_SetSoftAPVendorSpecificIE, //0x6e -> 0xd2
  111. CTRL_RESP_START_SOFTAP = CTRL_MSG_ID__Resp_StartSoftAP, //0x6f -> 0xd3
  112. CTRL_RESP_GET_SOFTAP_CONN_STA_LIST = CTRL_MSG_ID__Resp_GetSoftAPConnectedSTAList, //0x70 -> 0xd4
  113. CTRL_RESP_STOP_SOFTAP = CTRL_MSG_ID__Resp_StopSoftAP, //0x71 -> 0xd5
  114. CTRL_RESP_SET_PS_MODE = CTRL_MSG_ID__Resp_SetPowerSaveMode, //0x72 -> 0xd6
  115. CTRL_RESP_GET_PS_MODE = CTRL_MSG_ID__Resp_GetPowerSaveMode, //0x73 -> 0xd7
  116. CTRL_RESP_OTA_BEGIN = CTRL_MSG_ID__Resp_OTABegin, //0x74 -> 0xd8
  117. CTRL_RESP_OTA_WRITE = CTRL_MSG_ID__Resp_OTAWrite, //0x75 -> 0xd9
  118. CTRL_RESP_OTA_END = CTRL_MSG_ID__Resp_OTAEnd, //0x76 -> 0xda
  119. CTRL_RESP_SET_WIFI_MAX_TX_POWER = CTRL_MSG_ID__Resp_SetWifiMaxTxPower, //0x77 -> 0xdb
  120. CTRL_RESP_GET_WIFI_CURR_TX_POWER = CTRL_MSG_ID__Resp_GetWifiCurrTxPower, //0x78 -> 0xdc
  121. CTRL_RESP_CONFIG_HEARTBEAT = CTRL_MSG_ID__Resp_ConfigHeartbeat, //0x79 -> 0xdd
  122. CTRL_RESP_ENABLE_DISABLE = CTRL_MSG_ID__Resp_EnableDisable, //0x7a -> 0xde
  123. CTRL_RESP_GET_FW_VERSION = CTRL_MSG_ID__Resp_GetFwVersion, //0x7b -> 0xdf
  124. /*
  125. * Add new control path comm and response before Resp_Max
  126. * and update Resp_Max
  127. */
  128. CTRL_RESP_MAX = CTRL_MSG_ID__Resp_Max,
  129. /*
  130. ** Events
  131. */
  132. CTRL_EVENT_BASE = CTRL_MSG_ID__Event_Base,
  133. CTRL_EVENT_ESP_INIT = CTRL_MSG_ID__Event_ESPInit,
  134. CTRL_EVENT_HEARTBEAT = CTRL_MSG_ID__Event_Heartbeat,
  135. CTRL_EVENT_STATION_DISCONNECT_FROM_AP =
  136. CTRL_MSG_ID__Event_StationDisconnectFromAP,
  137. CTRL_EVENT_STATION_DISCONNECT_FROM_ESP_SOFTAP =
  138. CTRL_MSG_ID__Event_StationDisconnectFromESPSoftAP,
  139. CTRL_EVENT_STATION_CONNECTED_TO_AP =
  140. CTRL_MSG_ID__Event_StationConnectedToAP,
  141. CTRL_EVENT_STATION_CONNECTED_TO_ESP_SOFTAP =
  142. CTRL_MSG_ID__Event_StationConnectedToESPSoftAP,
  143. /*
  144. * Add new control path command notification before Event_Max
  145. * and update Event_Max
  146. */
  147. CTRL_EVENT_MAX = CTRL_MSG_ID__Event_Max,
  148. } AppMsgId_e;
  149. typedef enum {
  150. WIFI_MODE_NONE = CTRL__WIFI_MODE__NONE,
  151. WIFI_MODE_STA = CTRL__WIFI_MODE__STA,
  152. WIFI_MODE_AP = CTRL__WIFI_MODE__AP,
  153. WIFI_MODE_APSTA = CTRL__WIFI_MODE__APSTA,
  154. WIFI_MODE_MAX
  155. } wifi_mode_e;
  156. typedef enum {
  157. WIFI_BW_HT20 = CTRL__WIFI_BW__HT20,
  158. WIFI_BW_HT40 = CTRL__WIFI_BW__HT40,
  159. } wifi_bandwidth_e;
  160. typedef enum {
  161. WIFI_PS_MIN_MODEM = CTRL__WIFI_POWER_SAVE__MIN_MODEM,
  162. WIFI_PS_MAX_MODEM = CTRL__WIFI_POWER_SAVE__MAX_MODEM,
  163. WIFI_PS_INVALID,
  164. } wifi_ps_type_e;
  165. typedef enum {
  166. WIFI_VND_IE_TYPE_BEACON = CTRL__VENDOR_IETYPE__Beacon,
  167. WIFI_VND_IE_TYPE_PROBE_REQ = CTRL__VENDOR_IETYPE__Probe_req,
  168. WIFI_VND_IE_TYPE_PROBE_RESP = CTRL__VENDOR_IETYPE__Probe_resp,
  169. WIFI_VND_IE_TYPE_ASSOC_REQ = CTRL__VENDOR_IETYPE__Assoc_req,
  170. WIFI_VND_IE_TYPE_ASSOC_RESP = CTRL__VENDOR_IETYPE__Assoc_resp,
  171. } wifi_vendor_ie_type_e;
  172. typedef enum {
  173. WIFI_VND_IE_ID_0 = CTRL__VENDOR_IEID__ID_0,
  174. WIFI_VND_IE_ID_1 = CTRL__VENDOR_IEID__ID_1,
  175. } wifi_vendor_ie_id_e;
  176. enum hosted_features_t {
  177. HOSTED_WIFI = HOSTED_FEATURE__Hosted_Wifi,
  178. HOSTED_BT = HOSTED_FEATURE__Hosted_Bluetooth,
  179. };
  180. typedef struct {
  181. /* Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
  182. uint8_t element_id;
  183. /* Len of all bytes in the element data
  184. * following this field. Minimum 4 */
  185. uint8_t length;
  186. /* Vendor identifier (OUI) */
  187. uint8_t vendor_oui[VENDOR_OUI_BUF];
  188. /* Vendor-specific OUI type */
  189. uint8_t vendor_oui_type;
  190. /*length of payload field*/
  191. uint16_t payload_len;
  192. /* Payload. Length is equal to value in 'length' field, minus 4 */
  193. uint8_t* payload;
  194. } vendor_ie_data_t;
  195. /**
  196. * @brief Wi-Fi second channel type
  197. */
  198. typedef enum {
  199. WIFI_SECOND_CHAN_NONE = 0, /**< The channel width is HT20 */
  200. WIFI_SECOND_CHAN_ABOVE, /**< The channel width is HT40 and the secondary channel is above the primary channel */
  201. WIFI_SECOND_CHAN_BELOW, /**< The channel width is HT40 and the secondary channel is below the primary channel */
  202. } wifi_second_chan_t;
  203. /**
  204. * @brief Wi-Fi authmode type
  205. * Strength of authmodes
  206. * Personal Networks : OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA3_PSK = WPA2_WPA3_PSK = DPP
  207. * Enterprise Networks : WIFI_AUTH_WPA2_ENTERPRISE < WIFI_AUTH_WPA3_ENTERPRISE = WIFI_AUTH_WPA2_WPA3_ENTERPRISE < WIFI_AUTH_WPA3_ENT_192
  208. */
  209. typedef enum {
  210. WIFI_AUTH_OPEN = 0, /**< Authenticate mode : open */
  211. WIFI_AUTH_WEP, /**< Authenticate mode : WEP */
  212. WIFI_AUTH_WPA_PSK, /**< Authenticate mode : WPA_PSK */
  213. WIFI_AUTH_WPA2_PSK, /**< Authenticate mode : WPA2_PSK */
  214. WIFI_AUTH_WPA_WPA2_PSK, /**< Authenticate mode : WPA_WPA2_PSK */
  215. WIFI_AUTH_ENTERPRISE, /**< Authenticate mode : Wi-Fi EAP security */
  216. WIFI_AUTH_WPA2_ENTERPRISE = WIFI_AUTH_ENTERPRISE, /**< Authenticate mode : Wi-Fi EAP security */
  217. WIFI_AUTH_WPA3_PSK, /**< Authenticate mode : WPA3_PSK */
  218. WIFI_AUTH_WPA2_WPA3_PSK, /**< Authenticate mode : WPA2_WPA3_PSK */
  219. WIFI_AUTH_WAPI_PSK, /**< Authenticate mode : WAPI_PSK */
  220. WIFI_AUTH_OWE, /**< Authenticate mode : OWE */
  221. WIFI_AUTH_WPA3_ENT_192, /**< Authenticate mode : WPA3_ENT_SUITE_B_192_BIT */
  222. WIFI_AUTH_WPA3_EXT_PSK, /**< This authentication mode will yield same result as WIFI_AUTH_WPA3_PSK and not recommended to be used. It will be deprecated in future, please use WIFI_AUTH_WPA3_PSK instead. */
  223. WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE, /**< This authentication mode will yield same result as WIFI_AUTH_WPA3_PSK and not recommended to be used. It will be deprecated in future, please use WIFI_AUTH_WPA3_PSK instead.*/
  224. WIFI_AUTH_DPP, /**< Authenticate mode : DPP */
  225. WIFI_AUTH_MAX
  226. } wifi_auth_mode_t;
  227. /**
  228. * @brief Wi-Fi cipher type
  229. */
  230. typedef enum {
  231. WIFI_CIPHER_TYPE_NONE = 0, /**< The cipher type is none */
  232. WIFI_CIPHER_TYPE_WEP40, /**< The cipher type is WEP40 */
  233. WIFI_CIPHER_TYPE_WEP104, /**< The cipher type is WEP104 */
  234. WIFI_CIPHER_TYPE_TKIP, /**< The cipher type is TKIP */
  235. WIFI_CIPHER_TYPE_CCMP, /**< The cipher type is CCMP */
  236. WIFI_CIPHER_TYPE_TKIP_CCMP, /**< The cipher type is TKIP and CCMP */
  237. WIFI_CIPHER_TYPE_AES_CMAC128,/**< The cipher type is AES-CMAC-128 */
  238. WIFI_CIPHER_TYPE_SMS4, /**< The cipher type is SMS4 */
  239. WIFI_CIPHER_TYPE_GCMP, /**< The cipher type is GCMP */
  240. WIFI_CIPHER_TYPE_GCMP256, /**< The cipher type is GCMP-256 */
  241. WIFI_CIPHER_TYPE_AES_GMAC128,/**< The cipher type is AES-GMAC-128 */
  242. WIFI_CIPHER_TYPE_AES_GMAC256,/**< The cipher type is AES-GMAC-256 */
  243. WIFI_CIPHER_TYPE_UNKNOWN, /**< The cipher type is unknown */
  244. } wifi_cipher_type_t;
  245. /**
  246. * @brief Wi-Fi antenna
  247. */
  248. typedef enum {
  249. WIFI_ANT_ANT0, /**< Wi-Fi antenna 0 */
  250. WIFI_ANT_ANT1, /**< Wi-Fi antenna 1 */
  251. WIFI_ANT_MAX, /**< Invalid Wi-Fi antenna */
  252. } wifi_ant_t;
  253. /**
  254. * @brief Wi-Fi country policy
  255. */
  256. typedef enum {
  257. WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */
  258. WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */
  259. } wifi_country_policy_t;
  260. /**
  261. * @brief Structure describing Wi-Fi country-based regional restrictions.
  262. */
  263. typedef struct {
  264. char cc[3]; /**< Country code string */
  265. uint8_t schan; /**< Start channel of the allowed 2.4GHz Wi-Fi channels */
  266. uint8_t nchan; /**< Total channel number of the allowed 2.4GHz Wi-Fi channels */
  267. int8_t max_tx_power; /**< This field is used for getting Wi-Fi maximum transmitting power, call esp_wifi_set_max_tx_power to set the maximum transmitting power. */
  268. wifi_country_policy_t policy; /**< Country policy */
  269. } wifi_country_t;
  270. /**
  271. * @brief Description of a Wi-Fi AP HE Info
  272. */
  273. typedef struct {
  274. uint8_t bss_color: 6; /**< The BSS Color value associated with the AP's corresponding BSS */
  275. uint8_t partial_bss_color: 1; /**< Indicates whether an AID assignment rule is based on the BSS color */
  276. uint8_t bss_color_disabled: 1; /**< Indicates whether the BSS color usage is disabled */
  277. uint8_t bssid_index; /**< In a M-BSSID set, identifies the non-transmitted BSSID */
  278. } wifi_he_ap_info_t;
  279. /**
  280. * @brief Configuration structure for Protected Management Frame
  281. */
  282. typedef struct {
  283. bool capable; /**< Deprecated variable. Device will always connect in PMF mode if other device also advertises PMF capability. */
  284. bool required; /**< Advertises that Protected Management Frame is required. Device will not associate to non-PMF capable devices. */
  285. } wifi_pmf_config_t;
  286. /**
  287. * @brief Configuration for SAE PWE derivation
  288. */
  289. typedef enum {
  290. WPA3_SAE_PWE_UNSPECIFIED,
  291. WPA3_SAE_PWE_HUNT_AND_PECK,
  292. WPA3_SAE_PWE_HASH_TO_ELEMENT,
  293. WPA3_SAE_PWE_BOTH,
  294. } wifi_sae_pwe_method_t;
  295. /**
  296. * @brief Description of a Wi-Fi AP
  297. */
  298. typedef struct {
  299. uint8_t bssid[6]; /**< MAC address of AP */
  300. uint8_t ssid[33]; /**< SSID of AP */
  301. uint8_t primary; /**< Channel of AP */
  302. wifi_second_chan_t second; /**< Secondary channel of AP */
  303. int8_t rssi; /**< Signal strength of AP. Note that in some rare cases where signal strength is very strong, RSSI values can be slightly positive */
  304. wifi_auth_mode_t authmode; /**< Auth mode of AP */
  305. wifi_cipher_type_t pairwise_cipher; /**< Pairwise cipher of AP */
  306. wifi_cipher_type_t group_cipher; /**< Group cipher of AP */
  307. wifi_ant_t ant; /**< Antenna used to receive beacon from AP */
  308. uint32_t phy_11b: 1; /**< Bit: 0 flag to identify if 11b mode is enabled or not */
  309. uint32_t phy_11g: 1; /**< Bit: 1 flag to identify if 11g mode is enabled or not */
  310. uint32_t phy_11n: 1; /**< Bit: 2 flag to identify if 11n mode is enabled or not */
  311. uint32_t phy_lr: 1; /**< Bit: 3 flag to identify if low rate is enabled or not */
  312. uint32_t phy_11a: 1; /**< Bit: 4 flag to identify if 11ax mode is enabled or not */
  313. uint32_t phy_11ac: 1; /**< Bit: 5 flag to identify if 11ax mode is enabled or not */
  314. uint32_t phy_11ax: 1; /**< Bit: 6 flag to identify if 11ax mode is enabled or not */
  315. uint32_t wps: 1; /**< Bit: 7 flag to identify if WPS is supported or not */
  316. uint32_t ftm_responder: 1; /**< Bit: 8 flag to identify if FTM is supported in responder mode */
  317. uint32_t ftm_initiator: 1; /**< Bit: 9 flag to identify if FTM is supported in initiator mode */
  318. uint32_t reserved: 22; /**< Bit: 10..31 reserved */
  319. wifi_country_t country; /**< Country information of AP */
  320. wifi_he_ap_info_t he_ap; /**< HE AP info */
  321. uint8_t bandwidth; /**< For AP 20 MHz this value is set to 1. For AP 40 MHz this value is set to 2.
  322. For AP 80 MHz this value is set to 3. For AP 160MHz this value is set to 4.
  323. For AP 80+80MHz this value is set to 5*/
  324. uint8_t vht_ch_freq1; /**< This fields are used only AP bandwidth is 80 and 160 MHz, to transmit the center channel
  325. frequency of the BSS. For AP bandwidth is 80 + 80 MHz, it is the center channel frequency
  326. of the lower frequency segment.*/
  327. uint8_t vht_ch_freq2; /**< This fields are used only AP bandwidth is 80 + 80 MHz, and is used to transmit the center
  328. channel frequency of the second segment. */
  329. } wifi_ap_record_t;
  330. /**
  331. * @brief Wi-Fi scan method
  332. */
  333. typedef enum {
  334. WIFI_FAST_SCAN = 0, /**< Do fast scan, scan will end after find SSID match AP */
  335. WIFI_ALL_CHANNEL_SCAN, /**< All channel scan, scan will end after scan all the channel */
  336. } wifi_scan_method_t;
  337. /**
  338. * @brief Wi-Fi sort AP method
  339. */
  340. typedef enum {
  341. WIFI_CONNECT_AP_BY_SIGNAL = 0, /**< Sort match AP in scan list by RSSI */
  342. WIFI_CONNECT_AP_BY_SECURITY, /**< Sort match AP in scan list by security mode */
  343. } wifi_sort_method_t;
  344. /**
  345. * @brief Structure describing parameters for a Wi-Fi fast scan
  346. */
  347. typedef struct {
  348. int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */
  349. wifi_auth_mode_t authmode; /**< The weakest auth mode to accept in the fast scan mode
  350. Note: In case this value is not set and password is set as per WPA2 standards(password len >= 8), it will be defaulted to WPA2 and device won't connect to deprecated WEP/WPA networks. Please set auth mode threshold as WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK to connect to WEP/WPA networks */
  351. } wifi_scan_threshold_t;
  352. /**
  353. * @brief Configuration for SAE-PK
  354. */
  355. typedef enum {
  356. WPA3_SAE_PK_MODE_AUTOMATIC = 0,
  357. WPA3_SAE_PK_MODE_ONLY = 1,
  358. WPA3_SAE_PK_MODE_DISABLED = 2,
  359. } wifi_sae_pk_mode_t;
  360. /**
  361. * @brief Soft-AP configuration settings for the device
  362. */
  363. typedef struct {
  364. uint8_t ssid[32]; /**< SSID of soft-AP. If ssid_len field is 0, this must be a Null terminated string. Otherwise, length is set according to ssid_len. */
  365. uint8_t password[64]; /**< Password of soft-AP. */
  366. uint8_t ssid_len; /**< Optional length of SSID field. */
  367. uint8_t channel; /**< Channel of soft-AP */
  368. wifi_auth_mode_t authmode; /**< Auth mode of soft-AP. Do not support AUTH_WEP, AUTH_WAPI_PSK and AUTH_OWE in soft-AP mode. When the auth mode is set to WPA2_PSK, WPA2_WPA3_PSK or WPA3_PSK, the pairwise cipher will be overwritten with WIFI_CIPHER_TYPE_CCMP. */
  369. uint8_t ssid_hidden; /**< Broadcast SSID or not, default 0, broadcast the SSID */
  370. uint8_t max_connection; /**< Max number of stations allowed to connect in */
  371. uint16_t beacon_interval; /**< Beacon interval which should be multiples of 100. Unit: TU(time unit, 1 TU = 1024 us). Range: 100 ~ 60000. Default value: 100 */
  372. uint8_t csa_count; /**< Channel Switch Announcement Count. Notify the station that the channel will switch after the csa_count beacon intervals. Range: 1 ~ 30. Default value: 3 */
  373. uint8_t dtim_period; /**< Dtim period of soft-AP. Range: 1 ~ 10. Default value: 1 */
  374. wifi_cipher_type_t pairwise_cipher; /**< Pairwise cipher of SoftAP, group cipher will be derived using this. Cipher values are valid starting from WIFI_CIPHER_TYPE_TKIP, enum values before that will be considered as invalid and default cipher suites(TKIP+CCMP) will be used. Valid cipher suites in softAP mode are WIFI_CIPHER_TYPE_TKIP, WIFI_CIPHER_TYPE_CCMP and WIFI_CIPHER_TYPE_TKIP_CCMP. */
  375. bool ftm_responder; /**< Enable FTM Responder mode */
  376. wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame */
  377. wifi_sae_pwe_method_t sae_pwe_h2e; /**< Configuration for SAE PWE derivation method */
  378. } wifi_ap_config_t;
  379. #define SAE_H2E_IDENTIFIER_LEN 32 /**< Length of the password identifier for H2E */
  380. /**
  381. * @brief STA configuration settings for the device
  382. */
  383. typedef struct {
  384. uint8_t ssid[32]; /**< SSID of target AP. */
  385. uint8_t password[64]; /**< Password of target AP. */
  386. wifi_scan_method_t scan_method; /**< Do all channel scan or fast scan */
  387. bool bssid_set; /**< Whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
  388. uint8_t bssid[6]; /**< MAC address of target AP*/
  389. uint8_t channel; /**< Channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
  390. uint16_t listen_interval; /**< Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */
  391. wifi_sort_method_t sort_method; /**< Sort the connect AP in the list by rssi or security mode */
  392. wifi_scan_threshold_t threshold; /**< When scan_threshold is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
  393. wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame. Will be advertised in RSN Capabilities in RSN IE. */
  394. uint32_t rm_enabled: 1; /**< Whether Radio Measurements are enabled for the connection */
  395. uint32_t btm_enabled: 1; /**< Whether BSS Transition Management is enabled for the connection. Note that when btm is enabled, the application itself should not set specific bssid (i.e using bssid_set and bssid in this config)or channel to connect to. This defeats the purpose of a BTM supported network, and hence if btm is supported and a specific bssid or channel is set in this config, it will be cleared from the config at the first disconnection or connection so that the device can roam to other BSS. It is recommended not to set BSSID when BTM is enabled. */
  396. uint32_t mbo_enabled: 1; /**< Whether MBO is enabled for the connection. Note that when mbo is enabled, the application itself should not set specific bssid (i.e using bssid_set and bssid in this config)or channel to connect to. This defeats the purpose of a MBO supported network, and hence if btm is supported and a specific bssid or channel is set in this config, it will be cleared from the config at the first disconnection or connection so that the device can roam to other BSS. It is recommended not to set BSSID when MBO is enabled. Enabling mbo here, automatically enables btm and rm above.*/
  397. uint32_t ft_enabled: 1; /**< Whether FT is enabled for the connection */
  398. uint32_t owe_enabled: 1; /**< Whether OWE is enabled for the connection */
  399. uint32_t transition_disable: 1; /**< Whether to enable transition disable feature */
  400. uint32_t reserved: 26; /**< Reserved for future feature set */
  401. wifi_sae_pwe_method_t sae_pwe_h2e; /**< Configuration for SAE PWE derivation method */
  402. wifi_sae_pk_mode_t sae_pk_mode; /**< Configuration for SAE-PK (Public Key) Authentication method */
  403. uint8_t failure_retry_cnt; /**< Number of connection retries station will do before moving to next AP. scan_method should be set as WIFI_ALL_CHANNEL_SCAN to use this config.
  404. Note: Enabling this may cause connection time to increase in case best AP doesn't behave properly. */
  405. uint32_t he_dcm_set: 1; /**< Whether DCM max.constellation for transmission and reception is set. */
  406. uint32_t he_dcm_max_constellation_tx: 2; /**< Indicate the max.constellation for DCM in TB PPDU the STA supported. 0: not supported. 1: BPSK, 2: QPSK, 3: 16-QAM. The default value is 3. */
  407. uint32_t he_dcm_max_constellation_rx: 2; /**< Indicate the max.constellation for DCM in both Data field and HE-SIG-B field the STA supported. 0: not supported. 1: BPSK, 2: QPSK, 3: 16-QAM. The default value is 3. */
  408. uint32_t he_mcs9_enabled: 1; /**< Whether to support HE-MCS 0 to 9. The default value is 0. */
  409. uint32_t he_su_beamformee_disabled: 1; /**< Whether to disable support for operation as an SU beamformee. */
  410. uint32_t he_trig_su_bmforming_feedback_disabled: 1; /**< Whether to disable support the transmission of SU feedback in an HE TB sounding sequence. */
  411. uint32_t he_trig_mu_bmforming_partial_feedback_disabled: 1; /**< Whether to disable support the transmission of partial-bandwidth MU feedback in an HE TB sounding sequence. */
  412. uint32_t he_trig_cqi_feedback_disabled: 1; /**< Whether to disable support the transmission of CQI feedback in an HE TB sounding sequence. */
  413. uint32_t he_reserved: 22; /**< Reserved for future feature set */
  414. uint8_t sae_h2e_identifier[SAE_H2E_IDENTIFIER_LEN];/**< Password identifier for H2E. this needs to be null terminated string */
  415. } wifi_sta_config_t;
  416. /**
  417. * @brief Configuration data for device's AP or STA or NAN.
  418. *
  419. * The usage of this union (for ap, sta or nan configuration) is determined by the accompanying
  420. * interface argument passed to esp_wifi_set_config() or esp_wifi_get_config()
  421. *
  422. */
  423. typedef union {
  424. wifi_ap_config_t ap; /**< Configuration of AP */
  425. wifi_sta_config_t sta; /**< Configuration of STA */
  426. } wifi_config_t;
  427. typedef struct {
  428. uint8_t bssid[BSSID_STR_SIZE];
  429. int rssi;
  430. } wifi_connected_stations_list_t;
  431. typedef struct {
  432. int mode;
  433. char mac[MAX_MAC_STR_SIZE];
  434. } wifi_mac_t;
  435. typedef struct {
  436. int mode;
  437. } wifi_mode_t;
  438. typedef struct {
  439. uint8_t ssid[SSID_LENGTH];
  440. uint8_t pwd[PASSWORD_LENGTH];
  441. int channel;
  442. int encryption_mode;
  443. int max_connections;
  444. bool ssid_hidden;
  445. wifi_bandwidth_e bandwidth;
  446. char out_mac[MAX_MAC_STR_SIZE];
  447. int band_mode;
  448. } softap_config_t;
  449. typedef struct {
  450. int count;
  451. /* dynamic size */
  452. wifi_ap_record_t *out_list;
  453. } wifi_ap_scan_list_t;
  454. typedef struct {
  455. int count;
  456. /* dynamic list*/
  457. wifi_connected_stations_list_t *out_list;
  458. } wifi_softap_conn_sta_list_t;
  459. typedef struct {
  460. int ps_mode;
  461. } wifi_power_save_t;
  462. typedef struct {
  463. bool enable;
  464. wifi_vendor_ie_type_e type;
  465. wifi_vendor_ie_id_e idx;
  466. vendor_ie_data_t vnd_ie;
  467. } wifi_softap_vendor_ie_t;
  468. typedef struct {
  469. uint8_t *ota_data;
  470. uint32_t ota_data_len;
  471. } ota_write_t;
  472. typedef struct {
  473. int power;
  474. } wifi_tx_power_t;
  475. typedef struct {
  476. char project_name[3];
  477. uint8_t major_1;
  478. uint8_t major_2;
  479. uint8_t minor;
  480. uint8_t revision_patch_1;
  481. uint8_t revision_patch_2;
  482. } fw_version_t;
  483. typedef struct {
  484. HostedFeature feature;
  485. uint8_t enable;
  486. } feature_enable_disable_t;
  487. typedef struct {
  488. /* event */
  489. uint32_t hb_num;
  490. /* Req */
  491. uint8_t enable;
  492. uint32_t duration;
  493. } event_heartbeat_t;
  494. typedef struct {
  495. uint8_t ssid[SSID_LENGTH];
  496. uint32_t ssid_len;
  497. uint8_t bssid[BSSID_STR_SIZE];
  498. int channel;
  499. int authmode;
  500. int aid;
  501. } event_sta_conn_t;
  502. typedef struct {
  503. uint8_t ssid[SSID_LENGTH];
  504. uint32_t ssid_len;
  505. uint8_t bssid[BSSID_STR_SIZE];
  506. uint32_t reason;
  507. int32_t rssi;
  508. } event_sta_disconn_t;
  509. typedef struct {
  510. uint8_t mac[MAX_MAC_STR_SIZE];
  511. int32_t aid;
  512. int32_t is_mesh_child;
  513. } event_softap_sta_conn_t;
  514. typedef struct {
  515. uint8_t mac[MAX_MAC_STR_SIZE];
  516. int32_t aid;
  517. int32_t is_mesh_child;
  518. uint32_t reason;
  519. } event_softap_sta_disconn_t;
  520. typedef struct Ctrl_cmd_t {
  521. /* msg type could be 1. req 2. resp 3. notification */
  522. uint8_t msg_type;
  523. /* control path protobuf msg number */
  524. uint16_t msg_id;
  525. /* uid of request / response */
  526. int32_t uid;
  527. /* statusof response or notification */
  528. int32_t resp_event_status;
  529. union {
  530. wifi_mac_t wifi_mac;
  531. wifi_mode_t wifi_mode;
  532. wifi_ap_scan_list_t wifi_ap_scan;
  533. wifi_ap_record_t wifi_ap_record;
  534. // wifi_ap_config_t wifi_ap_config;
  535. wifi_sta_config_t wifi_sta_config;
  536. softap_config_t wifi_softap_config;
  537. wifi_softap_vendor_ie_t wifi_softap_vendor_ie;
  538. wifi_softap_conn_sta_list_t wifi_softap_con_sta;
  539. wifi_power_save_t wifi_ps;
  540. ota_write_t ota_write;
  541. feature_enable_disable_t feat_ena_disable;
  542. wifi_tx_power_t wifi_tx_power;
  543. fw_version_t fw_version;
  544. event_heartbeat_t e_heartbeat;
  545. event_sta_conn_t e_sta_conn;
  546. event_sta_disconn_t e_sta_disconn;
  547. event_softap_sta_conn_t e_softap_sta_conn;
  548. event_softap_sta_disconn_t e_softap_sta_disconn;
  549. }u;
  550. /* By default this callback is set to NULL.
  551. * When this callback is set by app while triggering request,
  552. * it will be automatically called asynchronously
  553. * by hosted control lib on receiving control response
  554. * in this case app will not be waiting for response.
  555. *
  556. * Whereas, when this is not set i.e. is NULL, it is understood
  557. * as synchronous response, and app after sending request,
  558. * will wait till getting a response
  559. */
  560. int (*ctrl_resp_cb)(struct Ctrl_cmd_t *data);
  561. /* Wait for timeout duration, if response not received,
  562. * it will send timeout response.
  563. * Default value for this time out is DEFAULT_CTRL_RESP_TIMEOUT */
  564. int cmd_timeout_sec;
  565. /* assign the data pointer to free by lower layer.
  566. * Ignored if assigned as NULL */
  567. void *free_buffer_handle;
  568. /* free handle to be registered
  569. * Ignored if assigned as NULL */
  570. void (*free_buffer_func)(void *free_buffer_handle);
  571. void *ctrl_free_buff_hdls[MAX_FREE_BUFF_HANDLES];
  572. uint8_t n_ctrl_free_buff_hdls;
  573. } ctrl_cmd_t;
  574. /* resp callback */
  575. typedef int (*ctrl_resp_cb_t) (ctrl_cmd_t * resp);
  576. /* event callback */
  577. typedef int (*ctrl_event_cb_t) (ctrl_cmd_t * event);
  578. /*---- Control API Function ----*/
  579. /* This file contains hosted control library exposed APIs.
  580. * For detailed documentation, Please refer `../../../docs/common/ctrl_apis.md`
  581. *
  582. * As important note, application using these APIs, should clean
  583. * 1. allocated buffer within library are saved in `app_resp->free_buffer_handle`
  584. * Please use `app_resp->free_buffer_func` for freeing them.
  585. * 2. Response `ctrl_cmd_t *app_resp` is also allocated from library,
  586. * need to free using hosted_free() function.
  587. **/
  588. /* Set control event callback
  589. *
  590. * when user sets event callback, user provided function pointer
  591. * will be registered with user function
  592. * If user does not register event callback,
  593. * events received from ESP32 will be dropped
  594. *
  595. * Inputs:
  596. * > event - Control Event ID from `AppMsgId_e`
  597. * > event_cb - NULL - resets event callback
  598. * Function pointer - Registers event callback
  599. * Returns:
  600. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  601. * > CALLBACK_SET_SUCCESS - Callback is set successful
  602. **/
  603. int set_event_callback(int event, ctrl_resp_cb_t event_cb);
  604. /* Reset control event callback
  605. *
  606. * when user sets event callback, user provided function pointer
  607. * will be registered with user function
  608. * If user does not register event callback,
  609. * events received from ESP32 will be dropped
  610. *
  611. * Inputs:
  612. * > event - Control Event ID from `AppMsgId_e`
  613. *
  614. * Returns:
  615. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  616. * > CALLBACK_SET_SUCCESS - Callback is set successful
  617. **/
  618. int reset_event_callback(int event);
  619. /* Initialize hosted control library
  620. *
  621. * This is first step for application while using control path
  622. * This will allocate and instantiate hosted control library
  623. *
  624. * Returns:
  625. * > SUCCESS - 0
  626. * > FAILURE - -1
  627. **/
  628. int init_hosted_control_lib(void);
  629. /* De-initialize hosted control library
  630. *
  631. * This is last step for application while using control path
  632. * This will deallocate and cleanup hosted control library
  633. *
  634. * Returns:
  635. * > SUCCESS - 0
  636. * > FAILURE - -1
  637. **/
  638. int deinit_hosted_control_lib(void);
  639. /* Get the MAC address of station or softAP interface of ESP32 */
  640. ctrl_cmd_t * wifi_get_mac(ctrl_cmd_t req);
  641. /* Set MAC address of ESP32 interface for given wifi mode */
  642. ctrl_cmd_t * wifi_set_mac(ctrl_cmd_t req);
  643. /* Get Wi-Fi mode of ESP32 */
  644. ctrl_cmd_t * wifi_get_mode(ctrl_cmd_t req);
  645. /* Set the Wi-Fi mode of ESP32 */
  646. ctrl_cmd_t * wifi_set_mode(ctrl_cmd_t req);
  647. /* Set Wi-Fi power save mode of ESP32 */
  648. ctrl_cmd_t * wifi_set_power_save_mode(ctrl_cmd_t req);
  649. /* Get the Wi-Fi power save mode of ESP32 */
  650. ctrl_cmd_t * wifi_get_power_save_mode(ctrl_cmd_t req);
  651. /* Get list of available neighboring APs of ESP32 */
  652. ctrl_cmd_t * wifi_ap_scan_list(ctrl_cmd_t req);
  653. /* Get the AP config to which ESP32 station is connected */
  654. ctrl_cmd_t * wifi_get_ap_config(ctrl_cmd_t req);
  655. /* Set the AP config to which ESP32 station should connect to */
  656. ctrl_cmd_t * wifi_connect_ap(ctrl_cmd_t req);
  657. /* Disconnect ESP32 station from AP */
  658. ctrl_cmd_t * wifi_disconnect_ap(ctrl_cmd_t req);
  659. /* Set configuration of ESP32 softAP and start broadcasting */
  660. ctrl_cmd_t * wifi_start_softap(ctrl_cmd_t req);
  661. /* Get configuration of ESP32 softAP */
  662. ctrl_cmd_t * wifi_get_softap_config(ctrl_cmd_t req);
  663. /* Stop ESP32 softAP */
  664. ctrl_cmd_t * wifi_stop_softap(ctrl_cmd_t req);
  665. /* Get list of connected stations to ESP32 softAP */
  666. ctrl_cmd_t * wifi_get_softap_connected_station_list(ctrl_cmd_t req);
  667. /* Function set 802.11 Vendor-Specific Information Element.
  668. * It needs to get called before starting of ESP32 softAP */
  669. ctrl_cmd_t * wifi_set_vendor_specific_ie(ctrl_cmd_t req);
  670. /* Sets maximum WiFi transmitting power at ESP32 */
  671. ctrl_cmd_t * wifi_set_max_tx_power(ctrl_cmd_t req);
  672. /* Gets current WiFi transmiting power at ESP32 */
  673. ctrl_cmd_t * wifi_get_curr_tx_power(ctrl_cmd_t req);
  674. /* Configure heartbeat event. Be default heartbeat is not enabled.
  675. * To enable heartbeats, user need to use this API in addition
  676. * to setting event callback for heartbeat event */
  677. ctrl_cmd_t * config_heartbeat(ctrl_cmd_t req);
  678. /* Performs an OTA begin operation for ESP32 which erases and
  679. * prepares existing flash partition for new flash writing */
  680. ctrl_cmd_t * ota_begin(ctrl_cmd_t req);
  681. /* Performs an OTA write operation for ESP32, It writes bytes from `ota_data`
  682. * buffer with `ota_data_len` number of bytes to OTA partition in flash. Number
  683. * of bytes can be small than size of complete binary to be flashed. In that
  684. * case, this caller is expected to repeatedly call this function till
  685. * total size written equals size of complete binary */
  686. ctrl_cmd_t * ota_write(ctrl_cmd_t req);
  687. /* Performs an OTA end operation for ESP32, It validates written OTA image,
  688. * sets newly written OTA partition as boot partition for next boot,
  689. * Creates timer which reset ESP32 after 5 sec */
  690. ctrl_cmd_t * ota_end(ctrl_cmd_t req);
  691. /* Enable or disable specific feautures from hosted_features_t */
  692. ctrl_cmd_t * feature_config(ctrl_cmd_t req);
  693. /* Get FW Version */
  694. ctrl_cmd_t * get_fw_version(ctrl_cmd_t req);
  695. /* Get the interface up for interface `iface` */
  696. int interface_up(int sockfd, char* iface);
  697. /* Get the interface down for interface `iface` */
  698. int interface_down(int sockfd, char* iface);
  699. /* Set ethernet interface MAC address `mac` to interface `iface` */
  700. int set_hw_addr(int sockfd, char* iface, char* mac);
  701. /* Create an endpoint for communication */
  702. int create_socket(int domain, int type, int protocol, int *sock);
  703. /* Close an endpoint of the communication */
  704. int close_socket(int sock);
  705. #endif