ctrl_api.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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_MAX,
  168. } wifi_auth_mode_e;
  169. typedef enum {
  170. WIFI_BW_HT20 = CTRL__WIFI_BW__HT20,
  171. WIFI_BW_HT40 = CTRL__WIFI_BW__HT40,
  172. } wifi_bandwidth_e;
  173. typedef enum {
  174. WIFI_PS_MIN_MODEM = CTRL__WIFI_POWER_SAVE__MIN_MODEM,
  175. WIFI_PS_MAX_MODEM = CTRL__WIFI_POWER_SAVE__MAX_MODEM,
  176. WIFI_PS_INVALID,
  177. } wifi_ps_type_e;
  178. typedef enum {
  179. WIFI_VND_IE_TYPE_BEACON = CTRL__VENDOR_IETYPE__Beacon,
  180. WIFI_VND_IE_TYPE_PROBE_REQ = CTRL__VENDOR_IETYPE__Probe_req,
  181. WIFI_VND_IE_TYPE_PROBE_RESP = CTRL__VENDOR_IETYPE__Probe_resp,
  182. WIFI_VND_IE_TYPE_ASSOC_REQ = CTRL__VENDOR_IETYPE__Assoc_req,
  183. WIFI_VND_IE_TYPE_ASSOC_RESP = CTRL__VENDOR_IETYPE__Assoc_resp,
  184. } wifi_vendor_ie_type_e;
  185. typedef enum {
  186. WIFI_VND_IE_ID_0 = CTRL__VENDOR_IEID__ID_0,
  187. WIFI_VND_IE_ID_1 = CTRL__VENDOR_IEID__ID_1,
  188. } wifi_vendor_ie_id_e;
  189. enum hosted_features_t {
  190. HOSTED_WIFI = HOSTED_FEATURE__Hosted_Wifi,
  191. HOSTED_BT = HOSTED_FEATURE__Hosted_Bluetooth,
  192. };
  193. typedef struct {
  194. /* Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
  195. uint8_t element_id;
  196. /* Len of all bytes in the element data
  197. * following this field. Minimum 4 */
  198. uint8_t length;
  199. /* Vendor identifier (OUI) */
  200. uint8_t vendor_oui[VENDOR_OUI_BUF];
  201. /* Vendor-specific OUI type */
  202. uint8_t vendor_oui_type;
  203. /*length of payload field*/
  204. uint16_t payload_len;
  205. /* Payload. Length is equal to value in 'length' field, minus 4 */
  206. uint8_t* payload;
  207. } vendor_ie_data_t;
  208. typedef struct {
  209. uint8_t ssid[SSID_LENGTH];
  210. uint8_t bssid[BSSID_STR_SIZE];
  211. int rssi;
  212. int channel;
  213. int encryption_mode;
  214. } wifi_scanlist_t;
  215. typedef struct {
  216. uint8_t bssid[BSSID_STR_SIZE];
  217. int rssi;
  218. } wifi_connected_stations_list_t;
  219. typedef struct {
  220. int mode;
  221. char mac[MAX_MAC_STR_SIZE];
  222. } wifi_mac_t;
  223. typedef struct {
  224. int mode;
  225. } wifi_mode_t;
  226. typedef struct {
  227. uint8_t ssid[SSID_LENGTH];
  228. uint8_t pwd[PASSWORD_LENGTH];
  229. uint8_t bssid[BSSID_STR_SIZE];
  230. bool is_wpa3_supported;
  231. int rssi;
  232. int channel;
  233. int encryption_mode;
  234. uint16_t listen_interval;
  235. char status[STATUS_LENGTH];
  236. char out_mac[MAX_MAC_STR_SIZE];
  237. int band_mode;
  238. } wifi_ap_config_t;
  239. typedef struct {
  240. uint8_t ssid[SSID_LENGTH];
  241. uint8_t pwd[PASSWORD_LENGTH];
  242. int channel;
  243. int encryption_mode;
  244. int max_connections;
  245. bool ssid_hidden;
  246. wifi_bandwidth_e bandwidth;
  247. char out_mac[MAX_MAC_STR_SIZE];
  248. int band_mode;
  249. } softap_config_t;
  250. typedef struct {
  251. int count;
  252. /* dynamic size */
  253. wifi_scanlist_t *out_list;
  254. } wifi_ap_scan_list_t;
  255. typedef struct {
  256. int count;
  257. /* dynamic list*/
  258. wifi_connected_stations_list_t *out_list;
  259. } wifi_softap_conn_sta_list_t;
  260. typedef struct {
  261. int ps_mode;
  262. } wifi_power_save_t;
  263. typedef struct {
  264. bool enable;
  265. wifi_vendor_ie_type_e type;
  266. wifi_vendor_ie_id_e idx;
  267. vendor_ie_data_t vnd_ie;
  268. } wifi_softap_vendor_ie_t;
  269. typedef struct {
  270. uint8_t *ota_data;
  271. uint32_t ota_data_len;
  272. } ota_write_t;
  273. typedef struct {
  274. int power;
  275. } wifi_tx_power_t;
  276. typedef struct {
  277. char project_name[3];
  278. uint8_t major_1;
  279. uint8_t major_2;
  280. uint8_t minor;
  281. uint8_t revision_patch_1;
  282. uint8_t revision_patch_2;
  283. } fw_version_t;
  284. typedef struct {
  285. HostedFeature feature;
  286. uint8_t enable;
  287. } feature_enable_disable_t;
  288. typedef struct {
  289. /* event */
  290. uint32_t hb_num;
  291. /* Req */
  292. uint8_t enable;
  293. uint32_t duration;
  294. } event_heartbeat_t;
  295. typedef struct {
  296. uint8_t ssid[SSID_LENGTH];
  297. uint32_t ssid_len;
  298. uint8_t bssid[BSSID_STR_SIZE];
  299. int channel;
  300. int authmode;
  301. int aid;
  302. } event_sta_conn_t;
  303. typedef struct {
  304. uint8_t ssid[SSID_LENGTH];
  305. uint32_t ssid_len;
  306. uint8_t bssid[BSSID_STR_SIZE];
  307. uint32_t reason;
  308. int32_t rssi;
  309. } event_sta_disconn_t;
  310. typedef struct {
  311. uint8_t mac[MAX_MAC_STR_SIZE];
  312. int32_t aid;
  313. int32_t is_mesh_child;
  314. } event_softap_sta_conn_t;
  315. typedef struct {
  316. uint8_t mac[MAX_MAC_STR_SIZE];
  317. int32_t aid;
  318. int32_t is_mesh_child;
  319. uint32_t reason;
  320. } event_softap_sta_disconn_t;
  321. typedef struct Ctrl_cmd_t {
  322. /* msg type could be 1. req 2. resp 3. notification */
  323. uint8_t msg_type;
  324. /* control path protobuf msg number */
  325. uint16_t msg_id;
  326. /* uid of request / response */
  327. int32_t uid;
  328. /* statusof response or notification */
  329. int32_t resp_event_status;
  330. union {
  331. wifi_mac_t wifi_mac;
  332. wifi_mode_t wifi_mode;
  333. wifi_ap_scan_list_t wifi_ap_scan;
  334. wifi_ap_config_t wifi_ap_config;
  335. softap_config_t wifi_softap_config;
  336. wifi_softap_vendor_ie_t wifi_softap_vendor_ie;
  337. wifi_softap_conn_sta_list_t wifi_softap_con_sta;
  338. wifi_power_save_t wifi_ps;
  339. ota_write_t ota_write;
  340. feature_enable_disable_t feat_ena_disable;
  341. wifi_tx_power_t wifi_tx_power;
  342. fw_version_t fw_version;
  343. event_heartbeat_t e_heartbeat;
  344. event_sta_conn_t e_sta_conn;
  345. event_sta_disconn_t e_sta_disconn;
  346. event_softap_sta_conn_t e_softap_sta_conn;
  347. event_softap_sta_disconn_t e_softap_sta_disconn;
  348. }u;
  349. /* By default this callback is set to NULL.
  350. * When this callback is set by app while triggering request,
  351. * it will be automatically called asynchronously
  352. * by hosted control lib on receiving control response
  353. * in this case app will not be waiting for response.
  354. *
  355. * Whereas, when this is not set i.e. is NULL, it is understood
  356. * as synchronous response, and app after sending request,
  357. * will wait till getting a response
  358. */
  359. int (*ctrl_resp_cb)(struct Ctrl_cmd_t *data);
  360. /* Wait for timeout duration, if response not received,
  361. * it will send timeout response.
  362. * Default value for this time out is DEFAULT_CTRL_RESP_TIMEOUT */
  363. int cmd_timeout_sec;
  364. /* assign the data pointer to free by lower layer.
  365. * Ignored if assigned as NULL */
  366. void *free_buffer_handle;
  367. /* free handle to be registered
  368. * Ignored if assigned as NULL */
  369. void (*free_buffer_func)(void *free_buffer_handle);
  370. } ctrl_cmd_t;
  371. /* resp callback */
  372. typedef int (*ctrl_resp_cb_t) (ctrl_cmd_t * resp);
  373. /* event callback */
  374. typedef int (*ctrl_event_cb_t) (ctrl_cmd_t * event);
  375. /*---- Control API Function ----*/
  376. /* This file contains hosted control library exposed APIs.
  377. * For detailed documentation, Please refer `../../../docs/common/ctrl_apis.md`
  378. *
  379. * As important note, application using these APIs, should clean
  380. * 1. allocated buffer within library are saved in `app_resp->free_buffer_handle`
  381. * Please use `app_resp->free_buffer_func` for freeing them.
  382. * 2. Response `ctrl_cmd_t *app_resp` is also allocated from library,
  383. * need to free using hosted_free() function.
  384. **/
  385. /* Set control event callback
  386. *
  387. * when user sets event callback, user provided function pointer
  388. * will be registered with user function
  389. * If user does not register event callback,
  390. * events received from ESP32 will be dropped
  391. *
  392. * Inputs:
  393. * > event - Control Event ID from `AppMsgId_e`
  394. * > event_cb - NULL - resets event callback
  395. * Function pointer - Registers event callback
  396. * Returns:
  397. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  398. * > CALLBACK_SET_SUCCESS - Callback is set successful
  399. **/
  400. int set_event_callback(int event, ctrl_resp_cb_t event_cb);
  401. /* Reset control event callback
  402. *
  403. * when user sets event callback, user provided function pointer
  404. * will be registered with user function
  405. * If user does not register event callback,
  406. * events received from ESP32 will be dropped
  407. *
  408. * Inputs:
  409. * > event - Control Event ID from `AppMsgId_e`
  410. *
  411. * Returns:
  412. * > MSG_ID_OUT_OF_ORDER - If event is not registered with hosted control lib
  413. * > CALLBACK_SET_SUCCESS - Callback is set successful
  414. **/
  415. int reset_event_callback(int event);
  416. /* Initialize hosted control library
  417. *
  418. * This is first step for application while using control path
  419. * This will allocate and instantiate hosted control library
  420. *
  421. * Returns:
  422. * > SUCCESS - 0
  423. * > FAILURE - -1
  424. **/
  425. int init_hosted_control_lib(void);
  426. /* De-initialize hosted control library
  427. *
  428. * This is last step for application while using control path
  429. * This will deallocate and cleanup hosted control library
  430. *
  431. * Returns:
  432. * > SUCCESS - 0
  433. * > FAILURE - -1
  434. **/
  435. int deinit_hosted_control_lib(void);
  436. /* Get the MAC address of station or softAP interface of ESP32 */
  437. ctrl_cmd_t * wifi_get_mac(ctrl_cmd_t req);
  438. /* Set MAC address of ESP32 interface for given wifi mode */
  439. ctrl_cmd_t * wifi_set_mac(ctrl_cmd_t req);
  440. /* Get Wi-Fi mode of ESP32 */
  441. ctrl_cmd_t * wifi_get_mode(ctrl_cmd_t req);
  442. /* Set the Wi-Fi mode of ESP32 */
  443. ctrl_cmd_t * wifi_set_mode(ctrl_cmd_t req);
  444. /* Set Wi-Fi power save mode of ESP32 */
  445. ctrl_cmd_t * wifi_set_power_save_mode(ctrl_cmd_t req);
  446. /* Get the Wi-Fi power save mode of ESP32 */
  447. ctrl_cmd_t * wifi_get_power_save_mode(ctrl_cmd_t req);
  448. /* Get list of available neighboring APs of ESP32 */
  449. ctrl_cmd_t * wifi_ap_scan_list(ctrl_cmd_t req);
  450. /* Get the AP config to which ESP32 station is connected */
  451. ctrl_cmd_t * wifi_get_ap_config(ctrl_cmd_t req);
  452. /* Set the AP config to which ESP32 station should connect to */
  453. ctrl_cmd_t * wifi_connect_ap(ctrl_cmd_t req);
  454. /* Disconnect ESP32 station from AP */
  455. ctrl_cmd_t * wifi_disconnect_ap(ctrl_cmd_t req);
  456. /* Set configuration of ESP32 softAP and start broadcasting */
  457. ctrl_cmd_t * wifi_start_softap(ctrl_cmd_t req);
  458. /* Get configuration of ESP32 softAP */
  459. ctrl_cmd_t * wifi_get_softap_config(ctrl_cmd_t req);
  460. /* Stop ESP32 softAP */
  461. ctrl_cmd_t * wifi_stop_softap(ctrl_cmd_t req);
  462. /* Get list of connected stations to ESP32 softAP */
  463. ctrl_cmd_t * wifi_get_softap_connected_station_list(ctrl_cmd_t req);
  464. /* Function set 802.11 Vendor-Specific Information Element.
  465. * It needs to get called before starting of ESP32 softAP */
  466. ctrl_cmd_t * wifi_set_vendor_specific_ie(ctrl_cmd_t req);
  467. /* Sets maximum WiFi transmitting power at ESP32 */
  468. ctrl_cmd_t * wifi_set_max_tx_power(ctrl_cmd_t req);
  469. /* Gets current WiFi transmiting power at ESP32 */
  470. ctrl_cmd_t * wifi_get_curr_tx_power(ctrl_cmd_t req);
  471. /* Configure heartbeat event. Be default heartbeat is not enabled.
  472. * To enable heartbeats, user need to use this API in addition
  473. * to setting event callback for heartbeat event */
  474. ctrl_cmd_t * config_heartbeat(ctrl_cmd_t req);
  475. /* Performs an OTA begin operation for ESP32 which erases and
  476. * prepares existing flash partition for new flash writing */
  477. ctrl_cmd_t * ota_begin(ctrl_cmd_t req);
  478. /* Performs an OTA write operation for ESP32, It writes bytes from `ota_data`
  479. * buffer with `ota_data_len` number of bytes to OTA partition in flash. Number
  480. * of bytes can be small than size of complete binary to be flashed. In that
  481. * case, this caller is expected to repeatedly call this function till
  482. * total size written equals size of complete binary */
  483. ctrl_cmd_t * ota_write(ctrl_cmd_t req);
  484. /* Performs an OTA end operation for ESP32, It validates written OTA image,
  485. * sets newly written OTA partition as boot partition for next boot,
  486. * Creates timer which reset ESP32 after 5 sec */
  487. ctrl_cmd_t * ota_end(ctrl_cmd_t req);
  488. /* Enable or disable specific feautures from hosted_features_t */
  489. ctrl_cmd_t * feature_config(ctrl_cmd_t req);
  490. /* Get FW Version */
  491. ctrl_cmd_t * get_fw_version(ctrl_cmd_t req);
  492. /* Get the interface up for interface `iface` */
  493. int interface_up(int sockfd, char* iface);
  494. /* Get the interface down for interface `iface` */
  495. int interface_down(int sockfd, char* iface);
  496. /* Set ethernet interface MAC address `mac` to interface `iface` */
  497. int set_hw_addr(int sockfd, char* iface, char* mac);
  498. /* Create an endpoint for communication */
  499. int create_socket(int domain, int type, int protocol, int *sock);
  500. /* Close an endpoint of the communication */
  501. int close_socket(int sock);
  502. #endif