/* Copyright (C) 2015-2025 Espressif Systems (Shanghai) PTE LTD */
/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */

syntax = "proto3";

/* Enums similar to ESP IDF */
enum Ctrl_VendorIEType {
    Beacon = 0;
    Probe_req = 1;
    Probe_resp = 2;
    Assoc_req = 3;
    Assoc_resp = 4;
}

enum Ctrl_VendorIEID {
    ID_0 = 0;
    ID_1 = 1;
}

enum Ctrl_WifiMode {
    NONE = 0;
    STA = 1;
    AP = 2;
    APSTA = 3;
}

enum Ctrl_WifiBw {
    BW_Invalid = 0;
    HT20 = 1;
    HT40 = 2;
}

enum Ctrl_WifiPowerSave {
    NO_PS = 0;
    MIN_MODEM = 1;
    MAX_MODEM = 2;
    PS_Invalid = 3;
}

enum Ctrl_WifiSecProt {
    Open = 0;
    WEP = 1;
    WPA_PSK = 2;
    WPA2_PSK = 3;
    WPA_WPA2_PSK = 4;
    WPA2_ENTERPRISE = 5;
    WPA3_PSK = 6;
    WPA2_WPA3_PSK = 7;
}

/* enums for Control path */
enum Ctrl_Status {
    Connected = 0;
    Not_Connected = 1;
    No_AP_Found = 2;
    Connection_Fail = 3;
    Invalid_Argument = 4;
    Out_Of_Range = 5;
}


enum CtrlMsgType {
    MsgType_Invalid = 0;
    Req = 1;
    Resp = 2;
    Event = 3;
    MsgType_Max = 4;
}

enum CtrlMsgId {
    MsgId_Invalid = 0;

    /** Request Msgs **/
    Req_Base = 100;

    Req_GetMACAddress = 101;
    Req_SetMacAddress = 102;
    Req_GetWifiMode = 103;
    Req_SetWifiMode = 104;

    Req_GetAPScanList = 105;
    Req_GetAPConfig = 106;
    Req_ConnectAP = 107;
    Req_DisconnectAP = 108;

    Req_GetSoftAPConfig = 109;
    Req_SetSoftAPVendorSpecificIE = 110;
    Req_StartSoftAP = 111;
    Req_GetSoftAPConnectedSTAList = 112;
    Req_StopSoftAP = 113;

    Req_SetPowerSaveMode = 114;
    Req_GetPowerSaveMode = 115;

    Req_OTABegin = 116;
    Req_OTAWrite = 117;
    Req_OTAEnd = 118;

    Req_SetWifiMaxTxPower = 119;
    Req_GetWifiCurrTxPower = 120;

    Req_ConfigHeartbeat = 121;
    Req_EnableDisable = 122;
    Req_GetFwVersion = 123;
    Req_SetCountryCode = 124;
    Req_GetCountryCode = 125;
    Req_Custom_RPC_Unserialised_Msg = 126;
    /* Add new control path command response before Req_Max
     * and update Req_Max */
    Req_Max = 127;

    /** Response Msgs **/
    Resp_Base = 200;

    Resp_GetMACAddress = 201;
    Resp_SetMacAddress = 202;
    Resp_GetWifiMode = 203;
    Resp_SetWifiMode = 204;

    Resp_GetAPScanList = 205;
    Resp_GetAPConfig = 206;
    Resp_ConnectAP = 207;
    Resp_DisconnectAP = 208;

    Resp_GetSoftAPConfig = 209;
    Resp_SetSoftAPVendorSpecificIE = 210;
    Resp_StartSoftAP = 211;
    Resp_GetSoftAPConnectedSTAList = 212;
    Resp_StopSoftAP = 213;

    Resp_SetPowerSaveMode = 214;
    Resp_GetPowerSaveMode = 215;

    Resp_OTABegin = 216;
    Resp_OTAWrite = 217;
    Resp_OTAEnd = 218;

    Resp_SetWifiMaxTxPower = 219;
    Resp_GetWifiCurrTxPower = 220;

    Resp_ConfigHeartbeat = 221;
    Resp_EnableDisable = 222;
    Resp_GetFwVersion = 223;
    Resp_SetCountryCode = 224;
    Resp_GetCountryCode = 225;
    Resp_Custom_RPC_Unserialised_Msg = 226;
    /* Add new control path command response before Resp_Max
     * and update Resp_Max */
    Resp_Max = 227;

    /** Event Msgs **/
    Event_Base = 300;
    Event_ESPInit = 301;
    Event_Heartbeat = 302;
    Event_StationDisconnectFromAP = 303;
    Event_StationDisconnectFromESPSoftAP = 304;
    Event_StationConnectedToAP = 305;
    Event_StationConnectedToESPSoftAP = 306;
    Event_Custom_RPC_Unserialised_Msg = 307;
    /* Add new control path command notification before Event_Max
     * and update Event_Max */
    Event_Max = 308;
}

enum HostedFeature {
    Hosted_InvalidFeature = 0;
    Hosted_Wifi = 1;
    Hosted_Bluetooth = 2;
    /* Add your new features here and re-build prot using build_proto.sh */
}

/* internal supporting structures for CtrlMsg */
message ScanResult {
    bytes ssid = 1;
    uint32 chnl = 2;
    int32 rssi = 3;
    bytes bssid = 4;
    Ctrl_WifiSecProt sec_prot = 5;
}

message ConnectedSTAList {
    bytes mac = 1;
    int32 rssi = 2;
}


/* Control path structures */
/** Req/Resp structure **/
message CtrlMsg_Req_GetMacAddress {
    int32 mode = 1;
}

message CtrlMsg_Resp_GetMacAddress {
    bytes mac = 1;
    int32 resp = 2;
}

message CtrlMsg_Req_GetMode {
}

message CtrlMsg_Resp_GetMode {
    int32 mode = 1;
    int32 resp = 2;
}

message CtrlMsg_Req_SetMode {
    int32 mode = 1;
}

message CtrlMsg_Resp_SetMode {
    int32 resp = 1;
}

message CtrlMsg_Req_GetStatus {
}

message CtrlMsg_Resp_GetStatus {
    int32 resp = 1;
}

message CtrlMsg_Req_SetMacAddress {
    bytes mac = 1;
    int32 mode = 2;
}

message CtrlMsg_Resp_SetMacAddress {
    int32 resp = 1;
}

message CtrlMsg_Req_GetAPConfig {
}

message CtrlMsg_Resp_GetAPConfig {
    bytes ssid = 1;
    bytes bssid = 2;
    int32 rssi = 3;
    int32 chnl = 4;
    Ctrl_WifiSecProt sec_prot = 5;
    int32 resp = 6;
    int32 band_mode = 7;
}

message CtrlMsg_Req_ConnectAP {
    string ssid = 1;
    string pwd = 2;
    string bssid = 3;
    bool is_wpa3_supported = 4;
    int32 listen_interval = 5;
    int32 band_mode = 6;
}

message  CtrlMsg_Resp_ConnectAP {
    int32 resp = 1;
    bytes mac = 2;
    int32 band_mode = 3;
}

message CtrlMsg_Req_GetSoftAPConfig {
}

message CtrlMsg_Resp_GetSoftAPConfig {
    bytes ssid = 1;
    bytes pwd = 2;
    int32 chnl = 3;
    Ctrl_WifiSecProt sec_prot = 4;
    int32 max_conn = 5;
    bool ssid_hidden = 6;
    int32 bw = 7;
    int32 resp = 8;
    int32 band_mode = 9;
}

message CtrlMsg_Req_StartSoftAP {
    string ssid = 1;
    string pwd = 2;
    int32 chnl = 3;
    Ctrl_WifiSecProt sec_prot = 4;
    int32 max_conn = 5;
    bool ssid_hidden = 6;
    int32 bw = 7;
    int32 band_mode = 8;
}

message CtrlMsg_Resp_StartSoftAP {
    int32 resp = 1;
    bytes mac = 2;
    int32 band_mode = 3;
}

message CtrlMsg_Req_ScanResult {
}

message CtrlMsg_Resp_ScanResult {
    uint32 count = 1;
    repeated ScanResult entries = 2;
    int32 resp = 3;
}

message CtrlMsg_Req_SoftAPConnectedSTA {
}

message CtrlMsg_Resp_SoftAPConnectedSTA {
    uint32 num = 1;
    repeated ConnectedSTAList stations = 2;
    int32 resp = 3;
}

message CtrlMsg_Req_OTABegin {
}

message CtrlMsg_Resp_OTABegin {
    int32 resp = 1;
}

message CtrlMsg_Req_OTAWrite {
    bytes ota_data = 1;
}

message CtrlMsg_Resp_OTAWrite {
    int32 resp = 1;
}

message CtrlMsg_Req_OTAEnd {
}

message CtrlMsg_Resp_OTAEnd {
    int32 resp = 1;
}

message CtrlMsg_Req_VendorIEData {
    int32 element_id = 1;
    int32 length = 2;
    bytes vendor_oui = 3;
    int32 vendor_oui_type = 4;
    bytes payload = 5;
}

message CtrlMsg_Req_SetSoftAPVendorSpecificIE {
    bool enable = 1;
    Ctrl_VendorIEType type = 2;
    Ctrl_VendorIEID idx = 3;
    CtrlMsg_Req_VendorIEData vendor_ie_data = 4;
}

message CtrlMsg_Resp_SetSoftAPVendorSpecificIE {
    int32 resp = 1;
}

message CtrlMsg_Req_SetWifiMaxTxPower {
    int32 wifi_max_tx_power = 1;
}

message CtrlMsg_Resp_SetWifiMaxTxPower {
    int32 resp = 1;
}

message CtrlMsg_Req_GetWifiCurrTxPower {
}

message CtrlMsg_Resp_GetWifiCurrTxPower {
    int32 wifi_curr_tx_power = 1;
    int32 resp = 2;
}

message CtrlMsg_Req_ConfigHeartbeat {
    bool enable = 1;
    int32 duration = 2;
}

message CtrlMsg_Resp_ConfigHeartbeat {
    int32 resp = 1;
}

message CtrlMsg_Req_EnableDisable {
    uint32 feature = 1;
    bool enable = 2;
}

message CtrlMsg_Resp_EnableDisable {
    int32 resp = 1;
}

message CtrlMsg_Req_GetFwVersion {
}

message CtrlMsg_Resp_GetFwVersion {
    int32 resp = 1;
    string name = 2;
    uint32 major1 = 3;
    uint32 major2 = 4;
    uint32 minor = 5;
    uint32 rev_patch1 = 6;
    uint32 rev_patch2 = 7;
}

message CtrlMsg_Req_SetCountryCode {
    bytes country = 1;
    bool ieee80211d_enabled = 2;
}

message CtrlMsg_Resp_SetCountryCode {
    int32 resp = 1;
}

message CtrlMsg_Req_GetCountryCode {
}

message CtrlMsg_Resp_GetCountryCode {
    int32 resp = 1;
    bytes country = 2;
}

/** Event structure **/
message CtrlMsg_Event_ESPInit {
    bytes init_data = 1;
}

message CtrlMsg_Event_Heartbeat {
    int32 hb_num = 1;
}

message CtrlMsg_Event_StationDisconnectFromAP {
    int32 resp = 1;
    bytes ssid = 2;
    uint32 ssid_len = 3;
    bytes bssid = 4;
    uint32 reason = 5;
    int32 rssi = 6;
}

message CtrlMsg_Event_StationConnectedToAP {
    int32 resp = 1;
    bytes ssid = 2;
    uint32 ssid_len = 3;
    bytes bssid = 4;
    uint32 channel = 5;
    int32 authmode = 6;
    int32 aid = 7;
}


message CtrlMsg_Event_StationDisconnectFromESPSoftAP {
    int32 resp = 1;
    bytes mac = 2;
    uint32 aid = 3;
    bool is_mesh_child = 4;
    uint32 reason = 5;
}

message CtrlMsg_Event_StationConnectedToESPSoftAP {
    int32 resp = 1;
    bytes mac = 2;
    uint32 aid = 3;
    bool is_mesh_child = 4;
}

/* Add Custom RPC message structures after existing message structures to make it easily notice */
message CtrlMsg_Req_CustomRpcUnserialisedMsg {
    uint32 custom_msg_id = 1;
    bytes data = 2;
}

message CtrlMsg_Resp_CustomRpcUnserialisedMsg {
    int32 resp = 1;
    uint32 custom_msg_id = 2;
    bytes data = 3;
}

message CtrlMsg_Event_CustomRpcUnserialisedMsg {
    int32 resp = 1;
    uint32 custom_evt_id = 2;
    bytes data = 3;
}

message CtrlMsg {
    /* msg_type could be req, resp or Event */
    CtrlMsgType msg_type = 1;

    /* msg id */
    CtrlMsgId msg_id = 2;

    /* UID of message */
    int32 uid = 3;

    /* Request/response type: sync or async */
    uint32 req_resp_type = 4;

    /* union of all msg ids */
    oneof payload {
        /** Requests **/
        CtrlMsg_Req_GetMacAddress req_get_mac_address = 101;
        CtrlMsg_Req_SetMacAddress req_set_mac_address = 102;
        CtrlMsg_Req_GetMode req_get_wifi_mode = 103;
        CtrlMsg_Req_SetMode req_set_wifi_mode = 104;

        CtrlMsg_Req_ScanResult req_scan_ap_list = 105;
        CtrlMsg_Req_GetAPConfig req_get_ap_config = 106;
        CtrlMsg_Req_ConnectAP req_connect_ap = 107;
        CtrlMsg_Req_GetStatus req_disconnect_ap = 108;

        CtrlMsg_Req_GetSoftAPConfig req_get_softap_config = 109;
        CtrlMsg_Req_SetSoftAPVendorSpecificIE req_set_softap_vendor_specific_ie = 110;
        CtrlMsg_Req_StartSoftAP req_start_softap = 111;
        CtrlMsg_Req_SoftAPConnectedSTA req_softap_connected_stas_list = 112;
        CtrlMsg_Req_GetStatus req_stop_softap = 113;

        CtrlMsg_Req_SetMode req_set_power_save_mode = 114;
        CtrlMsg_Req_GetMode req_get_power_save_mode = 115;

        CtrlMsg_Req_OTABegin req_ota_begin = 116;
        CtrlMsg_Req_OTAWrite req_ota_write = 117;
        CtrlMsg_Req_OTAEnd req_ota_end = 118;

        CtrlMsg_Req_SetWifiMaxTxPower req_set_wifi_max_tx_power = 119;
        CtrlMsg_Req_GetWifiCurrTxPower req_get_wifi_curr_tx_power = 120;
        CtrlMsg_Req_ConfigHeartbeat req_config_heartbeat = 121;
        CtrlMsg_Req_EnableDisable req_enable_disable_feat = 122;
        CtrlMsg_Req_GetFwVersion req_get_fw_version = 123;
        CtrlMsg_Req_SetCountryCode req_set_country_code = 124;
        CtrlMsg_Req_GetCountryCode req_get_country_code = 125;
        CtrlMsg_Req_CustomRpcUnserialisedMsg req_custom_rpc_unserialised_msg = 126;

        /** Responses **/
        CtrlMsg_Resp_GetMacAddress resp_get_mac_address = 201;
        CtrlMsg_Resp_SetMacAddress resp_set_mac_address = 202;
        CtrlMsg_Resp_GetMode resp_get_wifi_mode = 203;
        CtrlMsg_Resp_SetMode resp_set_wifi_mode = 204;

        CtrlMsg_Resp_ScanResult resp_scan_ap_list = 205;
        CtrlMsg_Resp_GetAPConfig resp_get_ap_config = 206;
        CtrlMsg_Resp_ConnectAP resp_connect_ap = 207;
        CtrlMsg_Resp_GetStatus resp_disconnect_ap = 208;

        CtrlMsg_Resp_GetSoftAPConfig resp_get_softap_config = 209;
        CtrlMsg_Resp_SetSoftAPVendorSpecificIE resp_set_softap_vendor_specific_ie = 210;
        CtrlMsg_Resp_StartSoftAP resp_start_softap = 211;
        CtrlMsg_Resp_SoftAPConnectedSTA resp_softap_connected_stas_list = 212;
        CtrlMsg_Resp_GetStatus resp_stop_softap = 213;

        CtrlMsg_Resp_SetMode resp_set_power_save_mode = 214;
        CtrlMsg_Resp_GetMode resp_get_power_save_mode = 215;

        CtrlMsg_Resp_OTABegin resp_ota_begin = 216;
        CtrlMsg_Resp_OTAWrite resp_ota_write = 217;
        CtrlMsg_Resp_OTAEnd resp_ota_end = 218;
        CtrlMsg_Resp_SetWifiMaxTxPower resp_set_wifi_max_tx_power = 219;
        CtrlMsg_Resp_GetWifiCurrTxPower resp_get_wifi_curr_tx_power = 220;
        CtrlMsg_Resp_ConfigHeartbeat resp_config_heartbeat = 221;
        CtrlMsg_Resp_EnableDisable resp_enable_disable_feat = 222;
        CtrlMsg_Resp_GetFwVersion resp_get_fw_version = 223;
        CtrlMsg_Resp_SetCountryCode resp_set_country_code = 224;
        CtrlMsg_Resp_GetCountryCode resp_get_country_code = 225;
        CtrlMsg_Resp_CustomRpcUnserialisedMsg resp_custom_rpc_unserialised_msg = 226;

        /** Notifications **/
        CtrlMsg_Event_ESPInit event_esp_init = 301;
        CtrlMsg_Event_Heartbeat event_heartbeat = 302;
        CtrlMsg_Event_StationDisconnectFromAP event_station_disconnect_from_AP = 303;
        CtrlMsg_Event_StationDisconnectFromESPSoftAP event_station_disconnect_from_ESP_SoftAP = 304;
        CtrlMsg_Event_StationConnectedToAP event_station_connected_to_AP = 305;
        CtrlMsg_Event_StationConnectedToESPSoftAP event_station_connected_to_ESP_SoftAP = 306;
        CtrlMsg_Event_CustomRpcUnserialisedMsg event_custom_rpc_unserialised_msg = 307;
    }
}
