ctrl_api.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. /* If request is already being served and
  26. * another request is pending, time period for
  27. * which new request will wait in seconds
  28. * */
  29. #define WAIT_TIME_B2B_CTRL_REQ 5
  30. #define DEFAULT_CTRL_RESP_TIMEOUT 30
  31. #define DEFAULT_CTRL_RESP_AP_SCAN_TIMEOUT (60*3)
  32. #define DEFAULT_CTRL_RESP_CONNECT_AP_TIMEOUT (15*3)
  33. #ifndef MAC2STR
  34. #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
  35. #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
  36. #endif
  37. #define SUCCESS_STR "success"
  38. #define FAILURE_STR "failure"
  39. #define NOT_CONNECTED_STR "not_connected"
  40. /*---- Control structures ----*/
  41. enum {
  42. CTRL_ERR_NOT_CONNECTED = 1,
  43. CTRL_ERR_NO_AP_FOUND,
  44. CTRL_ERR_INVALID_PASSWORD,
  45. CTRL_ERR_INVALID_ARGUMENT,
  46. CTRL_ERR_OUT_OF_RANGE,
  47. CTRL_ERR_MEMORY_FAILURE,
  48. CTRL_ERR_UNSUPPORTED_MSG,
  49. CTRL_ERR_INCORRECT_ARG,
  50. CTRL_ERR_PROTOBUF_ENCODE,
  51. CTRL_ERR_PROTOBUF_DECODE,
  52. CTRL_ERR_SET_ASYNC_CB,
  53. CTRL_ERR_TRANSPORT_SEND,
  54. CTRL_ERR_REQUEST_TIMEOUT,
  55. CTRL_ERR_REQ_IN_PROG,
  56. OUT_OF_RANGE
  57. };
  58. typedef enum {
  59. CTRL_MSGTYPE_INVALID = CTRL_MSG_TYPE__MsgType_Invalid,
  60. CTRL_REQ = CTRL_MSG_TYPE__Req,
  61. CTRL_RESP = CTRL_MSG_TYPE__Resp,
  62. CTRL_EVENT = CTRL_MSG_TYPE__Event,
  63. CTRL_MSGTYPE_MAX = CTRL_MSG_TYPE__MsgType_Max,
  64. } AppMsgType_e;
  65. typedef enum {
  66. CTRL_MSGID_INVALID = CTRL_MSG_ID__MsgId_Invalid,
  67. /*
  68. ** Request Msgs *
  69. */
  70. CTRL_REQ_BASE = CTRL_MSG_ID__Req_Base,
  71. CTRL_REQ_GET_MAC_ADDR = CTRL_MSG_ID__Req_GetMACAddress, //0x65
  72. CTRL_REQ_SET_MAC_ADDR = CTRL_MSG_ID__Req_SetMacAddress, //0x66
  73. CTRL_REQ_GET_WIFI_MODE = CTRL_MSG_ID__Req_GetWifiMode, //0x67
  74. CTRL_REQ_SET_WIFI_MODE = CTRL_MSG_ID__Req_SetWifiMode, //0x68
  75. CTRL_REQ_GET_AP_SCAN_LIST = CTRL_MSG_ID__Req_GetAPScanList, //0x69
  76. CTRL_REQ_GET_AP_CONFIG = CTRL_MSG_ID__Req_GetAPConfig, //0x6a
  77. CTRL_REQ_CONNECT_AP = CTRL_MSG_ID__Req_ConnectAP, //0x6b
  78. CTRL_REQ_DISCONNECT_AP = CTRL_MSG_ID__Req_DisconnectAP, //0x6c
  79. CTRL_REQ_GET_SOFTAP_CONFIG = CTRL_MSG_ID__Req_GetSoftAPConfig, //0x6d
  80. CTRL_REQ_SET_SOFTAP_VND_IE = CTRL_MSG_ID__Req_SetSoftAPVendorSpecificIE, //0x6e
  81. CTRL_REQ_START_SOFTAP = CTRL_MSG_ID__Req_StartSoftAP, //0x6f
  82. CTRL_REQ_GET_SOFTAP_CONN_STA_LIST = CTRL_MSG_ID__Req_GetSoftAPConnectedSTAList, //0x70
  83. CTRL_REQ_STOP_SOFTAP = CTRL_MSG_ID__Req_StopSoftAP, //0x71
  84. CTRL_REQ_SET_PS_MODE = CTRL_MSG_ID__Req_SetPowerSaveMode, //0x72
  85. CTRL_REQ_GET_PS_MODE = CTRL_MSG_ID__Req_GetPowerSaveMode, //0x73
  86. CTRL_REQ_OTA_BEGIN = CTRL_MSG_ID__Req_OTABegin, //0x74
  87. CTRL_REQ_OTA_WRITE = CTRL_MSG_ID__Req_OTAWrite, //0x75
  88. CTRL_REQ_OTA_END = CTRL_MSG_ID__Req_OTAEnd, //0x76
  89. CTRL_REQ_SET_WIFI_MAX_TX_POWER = CTRL_MSG_ID__Req_SetWifiMaxTxPower, //0x77
  90. CTRL_REQ_GET_WIFI_CURR_TX_POWER = CTRL_MSG_ID__Req_GetWifiCurrTxPower, //0x78
  91. CTRL_REQ_CONFIG_HEARTBEAT = CTRL_MSG_ID__Req_ConfigHeartbeat, //0x79
  92. CTRL_REQ_ENABLE_DISABLE = CTRL_MSG_ID__Req_EnableDisable, //0x7a
  93. CTRL_REQ_GET_FW_VERSION = CTRL_MSG_ID__Req_GetFwVersion, //0x7b
  94. /*
  95. * Add new control path command response before Req_Max
  96. * and update Req_Max
  97. */
  98. CTRL_REQ_MAX = CTRL_MSG_ID__Req_Max,
  99. /*
  100. ** Response Msgs *
  101. */
  102. CTRL_RESP_BASE = CTRL_MSG_ID__Resp_Base,
  103. CTRL_RESP_GET_MAC_ADDR = CTRL_MSG_ID__Resp_GetMACAddress, //0x65 -> 0xc9
  104. CTRL_RESP_SET_MAC_ADDRESS = CTRL_MSG_ID__Resp_SetMacAddress, //0x66 -> 0xca
  105. CTRL_RESP_GET_WIFI_MODE = CTRL_MSG_ID__Resp_GetWifiMode, //0x67 -> 0xcb
  106. CTRL_RESP_SET_WIFI_MODE = CTRL_MSG_ID__Resp_SetWifiMode, //0x68 -> 0xcc
  107. CTRL_RESP_GET_AP_SCAN_LIST = CTRL_MSG_ID__Resp_GetAPScanList, //0x69 -> 0xcd
  108. CTRL_RESP_GET_AP_CONFIG = CTRL_MSG_ID__Resp_GetAPConfig, //0x6a -> 0xce
  109. CTRL_RESP_CONNECT_AP = CTRL_MSG_ID__Resp_ConnectAP, //0x6b -> 0xdf
  110. CTRL_RESP_DISCONNECT_AP = CTRL_MSG_ID__Resp_DisconnectAP, //0x6c -> 0xd0
  111. CTRL_RESP_GET_SOFTAP_CONFIG = CTRL_MSG_ID__Resp_GetSoftAPConfig, //0x6d -> 0xd1
  112. CTRL_RESP_SET_SOFTAP_VND_IE = CTRL_MSG_ID__Resp_SetSoftAPVendorSpecificIE, //0x6e -> 0xd2
  113. CTRL_RESP_START_SOFTAP = CTRL_MSG_ID__Resp_StartSoftAP, //0x6f -> 0xd3
  114. CTRL_RESP_GET_SOFTAP_CONN_STA_LIST = CTRL_MSG_ID__Resp_GetSoftAPConnectedSTAList, //0x70 -> 0xd4
  115. CTRL_RESP_STOP_SOFTAP = CTRL_MSG_ID__Resp_StopSoftAP, //0x71 -> 0xd5
  116. CTRL_RESP_SET_PS_MODE = CTRL_MSG_ID__Resp_SetPowerSaveMode, //0x72 -> 0xd6
  117. CTRL_RESP_GET_PS_MODE = CTRL_MSG_ID__Resp_GetPowerSaveMode, //0x73 -> 0xd7
  118. CTRL_RESP_OTA_BEGIN = CTRL_MSG_ID__Resp_OTABegin, //0x74 -> 0xd8
  119. CTRL_RESP_OTA_WRITE = CTRL_MSG_ID__Resp_OTAWrite, //0x75 -> 0xd9
  120. CTRL_RESP_OTA_END = CTRL_MSG_ID__Resp_OTAEnd, //0x76 -> 0xda
  121. CTRL_RESP_SET_WIFI_MAX_TX_POWER = CTRL_MSG_ID__Resp_SetWifiMaxTxPower, //0x77 -> 0xdb
  122. CTRL_RESP_GET_WIFI_CURR_TX_POWER = CTRL_MSG_ID__Resp_GetWifiCurrTxPower, //0x78 -> 0xdc
  123. CTRL_RESP_CONFIG_HEARTBEAT = CTRL_MSG_ID__Resp_ConfigHeartbeat, //0x79 -> 0xdd
  124. CTRL_RESP_ENABLE_DISABLE = CTRL_MSG_ID__Resp_EnableDisable, //0x7a -> 0xde
  125. CTRL_RESP_GET_FW_VERSION = CTRL_MSG_ID__Resp_GetFwVersion, //0x7b -> 0xdf
  126. /*
  127. * Add new control path comm and response before Resp_Max
  128. * and update Resp_Max
  129. */
  130. CTRL_RESP_MAX = CTRL_MSG_ID__Resp_Max,
  131. /*
  132. ** Events
  133. */
  134. CTRL_EVENT_BASE = CTRL_MSG_ID__Event_Base,
  135. CTRL_EVENT_ESP_INIT = CTRL_MSG_ID__Event_ESPInit,
  136. CTRL_EVENT_HEARTBEAT = CTRL_MSG_ID__Event_Heartbeat,
  137. CTRL_EVENT_STATION_DISCONNECT_FROM_AP =
  138. CTRL_MSG_ID__Event_StationDisconnectFromAP,
  139. CTRL_EVENT_STATION_DISCONNECT_FROM_ESP_SOFTAP =
  140. CTRL_MSG_ID__Event_StationDisconnectFromESPSoftAP,
  141. CTRL_EVENT_STATION_CONNECTED_TO_AP =
  142. CTRL_MSG_ID__Event_StationConnectedToAP,
  143. CTRL_EVENT_STATION_CONNECTED_TO_ESP_SOFTAP =
  144. CTRL_MSG_ID__Event_StationConnectedToESPSoftAP,
  145. /*
  146. * Add new control path command notification before Event_Max
  147. * and update Event_Max
  148. */
  149. CTRL_EVENT_MAX = CTRL_MSG_ID__Event_Max,
  150. } AppMsgId_e;
  151. typedef enum {
  152. WIFI_MODE_NONE = CTRL__WIFI_MODE__NONE,
  153. WIFI_MODE_STA = CTRL__WIFI_MODE__STA,
  154. WIFI_MODE_AP = CTRL__WIFI_MODE__AP,
  155. WIFI_MODE_APSTA = CTRL__WIFI_MODE__APSTA,
  156. WIFI_MODE_MAX
  157. } wifi_mode_e;
  158. typedef enum {
  159. WIFI_AUTH_OPEN = CTRL__WIFI_SEC_PROT__Open,
  160. WIFI_AUTH_WEP = CTRL__WIFI_SEC_PROT__WEP,
  161. WIFI_AUTH_WPA_PSK = CTRL__WIFI_SEC_PROT__WPA_PSK,
  162. WIFI_AUTH_WPA2_PSK = CTRL__WIFI_SEC_PROT__WPA2_PSK,
  163. WIFI_AUTH_WPA_WPA2_PSK = CTRL__WIFI_SEC_PROT__WPA_WPA2_PSK,
  164. WIFI_AUTH_WPA2_ENTERPRISE = CTRL__WIFI_SEC_PROT__WPA2_ENTERPRISE,
  165. WIFI_AUTH_WPA3_PSK = CTRL__WIFI_SEC_PROT__WPA3_PSK,
  166. WIFI_AUTH_WPA2_WPA3_PSK = CTRL__WIFI_SEC_PROT__WPA2_WPA3_PSK,
  167. WIFI_AUTH_WAPI_PSK = CTRL__WIFI_SEC_PROT__WAPI_PSK,
  168. WIFI_AUTH_OWE = CTRL__WIFI_SEC_PROT__OWE,
  169. WIFI_AUTH_WPA3_ENT_192 = CTRL__WIFI_SEC_PROT__WPA3_ENT_192,
  170. WIFI_AUTH_WPA3_EXT_PSK = CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK,
  171. WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE = CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK_MIXED_MODE,
  172. WIFI_AUTH_DPP = CTRL__WIFI_SEC_PROT__DPP,
  173. WIFI_AUTH_MAX,
  174. } wifi_auth_mode_e;
  175. typedef enum {
  176. WIFI_BW_HT20 = CTRL__WIFI_BW__HT20,
  177. WIFI_BW_HT40 = CTRL__WIFI_BW__HT40,
  178. } wifi_bandwidth_e;
  179. typedef enum {
  180. WIFI_PS_MIN_MODEM = CTRL__WIFI_POWER_SAVE__MIN_MODEM,
  181. WIFI_PS_MAX_MODEM = CTRL__WIFI_POWER_SAVE__MAX_MODEM,
  182. WIFI_PS_INVALID,
  183. } wifi_ps_type_e;
  184. typedef enum {
  185. WIFI_VND_IE_TYPE_BEACON = CTRL__VENDOR_IETYPE__Beacon,
  186. WIFI_VND_IE_TYPE_PROBE_REQ = CTRL__VENDOR_IETYPE__Probe_req,
  187. WIFI_VND_IE_TYPE_PROBE_RESP = CTRL__VENDOR_IETYPE__Probe_resp,
  188. WIFI_VND_IE_TYPE_ASSOC_REQ = CTRL__VENDOR_IETYPE__Assoc_req,
  189. WIFI_VND_IE_TYPE_ASSOC_RESP = CTRL__VENDOR_IETYPE__Assoc_resp,
  190. } wifi_vendor_ie_type_e;
  191. typedef enum {
  192. WIFI_VND_IE_ID_0 = CTRL__VENDOR_IEID__ID_0,
  193. WIFI_VND_IE_ID_1 = CTRL__VENDOR_IEID__ID_1,
  194. } wifi_vendor_ie_id_e;
  195. enum hosted_features_t {
  196. HOSTED_WIFI = HOSTED_FEATURE__Hosted_Wifi,
  197. HOSTED_BT = HOSTED_FEATURE__Hosted_Bluetooth,
  198. };
  199. typedef struct {
  200. /* Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
  201. uint8_t element_id;
  202. /* Len of all bytes in the element data
  203. * following this field. Minimum 4 */
  204. uint8_t length;
  205. /* Vendor identifier (OUI) */
  206. uint8_t vendor_oui[VENDOR_OUI_BUF];
  207. /* Vendor-specific OUI type */
  208. uint8_t vendor_oui_type;
  209. /*length of payload field*/
  210. uint16_t payload_len;
  211. /* Payload. Length is equal to value in 'length' field, minus 4 */
  212. uint8_t* payload;
  213. } vendor_ie_data_t;
  214. typedef struct {
  215. uint8_t ssid[SSID_LENGTH];
  216. uint8_t bssid[BSSID_STR_SIZE];
  217. int rssi;
  218. int channel;
  219. int encryption_mode;
  220. wifi_bandwidth_e bandwidth;
  221. struct {
  222. uint32_t phy_11b: 1; /**< Bit: 0 flag to identify if 11b mode is enabled or not */
  223. uint32_t phy_11g: 1; /**< Bit: 1 flag to identify if 11g mode is enabled or not */
  224. uint32_t phy_11n: 1; /**< Bit: 2 flag to identify if 11n mode is enabled or not */
  225. uint32_t phy_lr: 1; /**< Bit: 3 flag to identify if low rate is enabled or not */
  226. uint32_t phy_11a: 1; /**< Bit: 4 flag to identify if 11ax mode is enabled or not */
  227. uint32_t phy_11ac: 1; /**< Bit: 5 flag to identify if 11ax mode is enabled or not */
  228. uint32_t phy_11ax: 1; /**< Bit: 6 flag to identify if 11ax mode is enabled or not */
  229. uint32_t wps: 1; /**< Bit: 7 flag to identify if WPS is supported or not */
  230. uint32_t ftm_responder: 1; /**< Bit: 8 flag to identify if FTM is supported in responder mode */
  231. uint32_t ftm_initiator: 1; /**< Bit: 9 flag to identify if FTM is supported in initiator mode */
  232. uint32_t reserved: 22; /**< Bit: 10..31 reserved */
  233. } support;
  234. } wifi_scanlist_t;
  235. typedef struct {
  236. uint8_t bssid[BSSID_STR_SIZE];
  237. int rssi;
  238. } wifi_connected_stations_list_t;
  239. typedef struct {
  240. int mode;
  241. char mac[MAX_MAC_STR_SIZE];
  242. } wifi_mac_t;
  243. typedef struct {
  244. int mode;
  245. } wifi_mode_t;
  246. typedef struct {
  247. uint8_t ssid[SSID_LENGTH];
  248. uint8_t pwd[PASSWORD_LENGTH];
  249. uint8_t bssid[BSSID_STR_SIZE];
  250. bool is_wpa3_supported;
  251. int rssi;
  252. int channel;
  253. int encryption_mode;
  254. uint16_t listen_interval;
  255. char status[STATUS_LENGTH];
  256. char out_mac[MAX_MAC_STR_SIZE];
  257. int band_mode;
  258. } wifi_ap_config_t;
  259. typedef struct {
  260. uint8_t ssid[SSID_LENGTH];
  261. uint8_t pwd[PASSWORD_LENGTH];
  262. int channel;
  263. int encryption_mode;
  264. int max_connections;
  265. bool ssid_hidden;
  266. wifi_bandwidth_e bandwidth;
  267. char out_mac[MAX_MAC_STR_SIZE];
  268. int band_mode;
  269. } softap_config_t;
  270. typedef struct {
  271. int count;
  272. /* dynamic size */
  273. wifi_scanlist_t *out_list;
  274. } wifi_ap_scan_list_t;
  275. typedef struct {
  276. int count;
  277. /* dynamic list*/
  278. wifi_connected_stations_list_t *out_list;
  279. } wifi_softap_conn_sta_list_t;
  280. typedef struct {
  281. int ps_mode;
  282. } wifi_power_save_t;
  283. typedef struct {
  284. bool enable;
  285. wifi_vendor_ie_type_e type;
  286. wifi_vendor_ie_id_e idx;
  287. vendor_ie_data_t vnd_ie;
  288. } wifi_softap_vendor_ie_t;
  289. typedef struct {
  290. uint8_t *ota_data;
  291. uint32_t ota_data_len;
  292. } ota_write_t;
  293. typedef struct {
  294. int power;
  295. } wifi_tx_power_t;
  296. typedef struct {
  297. char project_name[3];
  298. uint8_t major_1;
  299. uint8_t major_2;
  300. uint8_t minor;
  301. uint8_t revision_patch_1;
  302. uint8_t revision_patch_2;
  303. } fw_version_t;
  304. typedef struct {
  305. HostedFeature feature;
  306. uint8_t enable;
  307. } feature_enable_disable_t;
  308. typedef struct {
  309. /* event */
  310. uint32_t hb_num;
  311. /* Req */
  312. uint8_t enable;
  313. uint32_t duration;
  314. } event_heartbeat_t;
  315. typedef struct {
  316. uint8_t ssid[SSID_LENGTH];
  317. uint32_t ssid_len;
  318. uint8_t bssid[BSSID_STR_SIZE];
  319. int channel;
  320. int authmode;
  321. int aid;
  322. } event_sta_conn_t;
  323. typedef struct {
  324. uint8_t ssid[SSID_LENGTH];
  325. uint32_t ssid_len;
  326. uint8_t bssid[BSSID_STR_SIZE];
  327. uint32_t reason;
  328. int32_t rssi;
  329. } event_sta_disconn_t;
  330. typedef struct {
  331. uint8_t mac[MAX_MAC_STR_SIZE];
  332. int32_t aid;
  333. int32_t is_mesh_child;
  334. } event_softap_sta_conn_t;
  335. typedef struct {
  336. uint8_t mac[MAX_MAC_STR_SIZE];
  337. int32_t aid;
  338. int32_t is_mesh_child;
  339. uint32_t reason;
  340. } event_softap_sta_disconn_t;
  341. typedef struct Ctrl_cmd_t {
  342. /* msg type could be 1. req 2. resp 3. notification */
  343. uint8_t msg_type;
  344. /* control path protobuf msg number */
  345. uint16_t msg_id;
  346. /* uid of request / response */
  347. int32_t uid;
  348. /* statusof response or notification */
  349. int32_t resp_event_status;
  350. union {
  351. wifi_mac_t wifi_mac;
  352. wifi_mode_t wifi_mode;
  353. wifi_ap_scan_list_t wifi_ap_scan;
  354. wifi_ap_config_t wifi_ap_config;
  355. softap_config_t wifi_softap_config;
  356. wifi_softap_vendor_ie_t wifi_softap_vendor_ie;
  357. wifi_softap_conn_sta_list_t wifi_softap_con_sta;
  358. wifi_power_save_t wifi_ps;
  359. ota_write_t ota_write;
  360. feature_enable_disable_t feat_ena_disable;
  361. wifi_tx_power_t wifi_tx_power;
  362. fw_version_t fw_version;
  363. event_heartbeat_t e_heartbeat;
  364. event_sta_conn_t e_sta_conn;
  365. event_sta_disconn_t e_sta_disconn;
  366. event_softap_sta_conn_t e_softap_sta_conn;
  367. event_softap_sta_disconn_t e_softap_sta_disconn;
  368. }u;
  369. /* By default this callback is set to NULL.
  370. * When this callback is set by app while triggering request,
  371. * it will be automatically called asynchronously
  372. * by hosted control lib on receiving control response
  373. * in this case app will not be waiting for response.
  374. *
  375. * Whereas, when this is not set i.e. is NULL, it is understood
  376. * as synchronous response, and app after sending request,
  377. * will wait till getting a response
  378. */
  379. int (*ctrl_resp_cb)(struct Ctrl_cmd_t *data);
  380. /* Wait for timeout duration, if response not received,
  381. * it will send timeout response.
  382. * Default value for this time out is DEFAULT_CTRL_RESP_TIMEOUT */
  383. int cmd_timeout_sec;
  384. /* assign the data pointer to free by lower layer.
  385. * Ignored if assigned as NULL */
  386. void *free_buffer_handle;
  387. /* free handle to be registered
  388. * Ignored if assigned as NULL */
  389. void (*free_buffer_func)(void *free_buffer_handle);
  390. } ctrl_cmd_t;
  391. /* resp callback */
  392. typedef int (*ctrl_resp_cb_t) (ctrl_cmd_t * resp);
  393. /* event callback */
  394. typedef int (*ctrl_event_cb_t) (ctrl_cmd_t * event);
  395. /*---- Control API Function ----*/
  396. /* This file contains hosted control library exposed APIs.
  397. * For detailed documentation, Please refer `../../../docs/common/ctrl_apis.md`
  398. *
  399. * As important note, application using these APIs, should clean
  400. * 1. allocated buffer within library are saved in `app_resp->free_buffer_handle`
  401. * Please use `app_resp->free_buffer_func` for freeing them.
  402. * 2. Response `ctrl_cmd_t *app_resp` is also allocated from library,
  403. * need to free using hosted_free() function.
  404. **/
  405. /* Set control event callback
  406. *
  407. * when user sets event callback, user provided function pointer
  408. * will be registered with user function
  409. * If user does not register event callback,
  410. * events received from ESP32 will be dropped
  411. *
  412. * Inputs:
  413. * > event - Control Event ID from `AppMsgId_e`
  414. * > event_cb - NULL - resets event callback
  415. * Function pointer - Registers event callback
  416. * Returns:
  417. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  418. * > CALLBACK_SET_SUCCESS - Callback is set successful
  419. **/
  420. int set_event_callback(int event, ctrl_resp_cb_t event_cb);
  421. /* Reset control event callback
  422. *
  423. * when user sets event callback, user provided function pointer
  424. * will be registered with user function
  425. * If user does not register event callback,
  426. * events received from ESP32 will be dropped
  427. *
  428. * Inputs:
  429. * > event - Control Event ID from `AppMsgId_e`
  430. *
  431. * Returns:
  432. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  433. * > CALLBACK_SET_SUCCESS - Callback is set successful
  434. **/
  435. int reset_event_callback(int event);
  436. /* Initialize hosted control library
  437. *
  438. * This is first step for application while using control path
  439. * This will allocate and instantiate hosted control library
  440. *
  441. * Returns:
  442. * > SUCCESS - 0
  443. * > FAILURE - -1
  444. **/
  445. int init_hosted_control_lib(void);
  446. /* De-initialize hosted control library
  447. *
  448. * This is last step for application while using control path
  449. * This will deallocate and cleanup hosted control library
  450. *
  451. * Returns:
  452. * > SUCCESS - 0
  453. * > FAILURE - -1
  454. **/
  455. int deinit_hosted_control_lib(void);
  456. /* Get the MAC address of station or softAP interface of ESP32 */
  457. ctrl_cmd_t * wifi_get_mac(ctrl_cmd_t req);
  458. /* Set MAC address of ESP32 interface for given wifi mode */
  459. ctrl_cmd_t * wifi_set_mac(ctrl_cmd_t req);
  460. /* Get Wi-Fi mode of ESP32 */
  461. ctrl_cmd_t * wifi_get_mode(ctrl_cmd_t req);
  462. /* Set the Wi-Fi mode of ESP32 */
  463. ctrl_cmd_t * wifi_set_mode(ctrl_cmd_t req);
  464. /* Set Wi-Fi power save mode of ESP32 */
  465. ctrl_cmd_t * wifi_set_power_save_mode(ctrl_cmd_t req);
  466. /* Get the Wi-Fi power save mode of ESP32 */
  467. ctrl_cmd_t * wifi_get_power_save_mode(ctrl_cmd_t req);
  468. /* Get list of available neighboring APs of ESP32 */
  469. ctrl_cmd_t * wifi_ap_scan_list(ctrl_cmd_t req);
  470. /* Get the AP config to which ESP32 station is connected */
  471. ctrl_cmd_t * wifi_get_ap_config(ctrl_cmd_t req);
  472. /* Set the AP config to which ESP32 station should connect to */
  473. ctrl_cmd_t * wifi_connect_ap(ctrl_cmd_t req);
  474. /* Disconnect ESP32 station from AP */
  475. ctrl_cmd_t * wifi_disconnect_ap(ctrl_cmd_t req);
  476. /* Set configuration of ESP32 softAP and start broadcasting */
  477. ctrl_cmd_t * wifi_start_softap(ctrl_cmd_t req);
  478. /* Get configuration of ESP32 softAP */
  479. ctrl_cmd_t * wifi_get_softap_config(ctrl_cmd_t req);
  480. /* Stop ESP32 softAP */
  481. ctrl_cmd_t * wifi_stop_softap(ctrl_cmd_t req);
  482. /* Get list of connected stations to ESP32 softAP */
  483. ctrl_cmd_t * wifi_get_softap_connected_station_list(ctrl_cmd_t req);
  484. /* Function set 802.11 Vendor-Specific Information Element.
  485. * It needs to get called before starting of ESP32 softAP */
  486. ctrl_cmd_t * wifi_set_vendor_specific_ie(ctrl_cmd_t req);
  487. /* Sets maximum WiFi transmitting power at ESP32 */
  488. ctrl_cmd_t * wifi_set_max_tx_power(ctrl_cmd_t req);
  489. /* Gets current WiFi transmiting power at ESP32 */
  490. ctrl_cmd_t * wifi_get_curr_tx_power(ctrl_cmd_t req);
  491. /* Configure heartbeat event. Be default heartbeat is not enabled.
  492. * To enable heartbeats, user need to use this API in addition
  493. * to setting event callback for heartbeat event */
  494. ctrl_cmd_t * config_heartbeat(ctrl_cmd_t req);
  495. /* Performs an OTA begin operation for ESP32 which erases and
  496. * prepares existing flash partition for new flash writing */
  497. ctrl_cmd_t * ota_begin(ctrl_cmd_t req);
  498. /* Performs an OTA write operation for ESP32, It writes bytes from `ota_data`
  499. * buffer with `ota_data_len` number of bytes to OTA partition in flash. Number
  500. * of bytes can be small than size of complete binary to be flashed. In that
  501. * case, this caller is expected to repeatedly call this function till
  502. * total size written equals size of complete binary */
  503. ctrl_cmd_t * ota_write(ctrl_cmd_t req);
  504. /* Performs an OTA end operation for ESP32, It validates written OTA image,
  505. * sets newly written OTA partition as boot partition for next boot,
  506. * Creates timer which reset ESP32 after 5 sec */
  507. ctrl_cmd_t * ota_end(ctrl_cmd_t req);
  508. /* Enable or disable specific feautures from hosted_features_t */
  509. ctrl_cmd_t * feature_config(ctrl_cmd_t req);
  510. /* Get FW Version */
  511. ctrl_cmd_t * get_fw_version(ctrl_cmd_t req);
  512. /* Get the interface up for interface `iface` */
  513. int interface_up(int sockfd, char* iface);
  514. /* Get the interface down for interface `iface` */
  515. int interface_down(int sockfd, char* iface);
  516. /* Set ethernet interface MAC address `mac` to interface `iface` */
  517. int set_hw_addr(int sockfd, char* iface, char* mac);
  518. /* Create an endpoint for communication */
  519. int create_socket(int domain, int type, int protocol, int *sock);
  520. /* Close an endpoint of the communication */
  521. int close_socket(int sock);
  522. #endif