syntax = "proto3";

package particle.ctrl.wifi;
option java_package = "io.particle.firmwareprotos.ctrl.wifi";

import "control/extensions.proto";
import "control/network.proto";

/**
 * WiFi security types.
 *
 * Note: The values of this enum should match the values defined by the `WifiSecurity` enum in
 * the firmware.
 */
enum Security {
  NO_SECURITY = 0; // No security
  WEP = 1; // WEP
  WPA_PSK = 2; // WPA PSK
  WPA2_PSK = 3; // WPA2 PSK
  WPA_WPA2_PSK = 4; // WPA/WPA2 PSK
  WPA3_PSK = 5; // WPA3 PSK
  WPA2_WPA3_PSK = 6; // WPA2/WPA3 PSK
}

/**
 * Network credential types.
 *
 * Note: The values of this enum should match the values defined by the `WiFiCredentials::Type` enum
 * in the firmware.
 */
enum CredentialsType {
  NO_CREDENTIALS = 0; // No WiFi credentials
  PASSWORD = 1; // WiFi password
}

/**
 * Network credentials.
 */
message Credentials {
  CredentialsType type = 1;
  string password = 2;
}

/**
 * Join a new network.
 *
 * On success, the network credentials get saved to a persistent storage.
 */
message JoinNewNetworkRequest {
  option (type_id) = 500; // CTRL_REQUEST_WIFI_JOIN_NEW_NETWORK
  string ssid = 1; // Network SSID
  bytes bssid = 2 [(nanopb).max_size = 6]; // Network address
  Security security = 3; // Network security
  Credentials credentials = 4; // Network credentials
  Interface interface_config = 5; // Network interface configuration (IP, mask, DNS etc)
  bool hidden = 6;
}

message JoinNewNetworkReply {
}

/**
 * Join a known network.
 */
message JoinKnownNetworkRequest {
  option (type_id) = 501; // CTRL_REQUEST_WIFI_JOIN_KNOWN_NETWORK
  string ssid = 1; // Network SSID
}

message JoinKnownNetworkReply {
}

/**
 * Get the list of known networks.
 */
message GetKnownNetworksRequest {
  option (type_id) = 502; // CTRL_REQUEST_WIFI_GET_KNOWN_NETWORKS
}

message GetKnownNetworksReply {
  message Network {
    string ssid = 1; // Network SSID
    Security security = 2; // Network security
    CredentialsType credentials_type = 3; // Network credentials
  }

  repeated Network networks = 1; // All known networks
}

/**
 * Remove the network from the list of known networks.
 */
message RemoveKnownNetworkRequest {
  option (type_id) = 503; // CTRL_REQUEST_WIFI_REMOVE_KNOWN_NETWORK
  string ssid = 1; // Network SSID
}

message RemoveKnownNetworkReply {
}

/**
 * Remove all known networks.
 */
message ClearKnownNetworksRequest {
  option (type_id) = 504; // CTRL_REQUEST_WIFI_CLEAR_KNOWN_NETWORKS
}

message ClearKnownNetworksReply {
}

/**
 * Get the current network.
 *
 * This request gets the network which the device is currently connected to.
 */
message GetCurrentNetworkRequest {
  option (type_id) = 505; // CTRL_REQUEST_WIFI_GET_CURRENT_NETWORK
}

message GetCurrentNetworkReply {
  string ssid = 1; // Network SSID
  bytes bssid = 2 [(nanopb).max_size = 6]; // Network address
  int32 channel = 3; // Network channel
  int32 rssi = 4; // Network signal strength
}

/**
 * Scan for networks.
 */
message ScanNetworksRequest {
  option (type_id) = 506; // CTRL_REQUEST_WIFI_SCAN_NETWORKS
}

message ScanNetworksReply {
  message Network {
    string ssid = 1; // Network SSID
    bytes bssid = 2 [(nanopb).max_size = 6]; // Network address
    Security security = 3; // Network security
    int32 channel = 4; // Network channel
    int32 rssi = 5; // Network signal strength
  }

  repeated Network networks = 1; // All found networks
}

/**
 * Store network credential but do not attempt to power on wifi or connect.
 *
 * On success, the network credentials get saved to a persistent storage.
 * On failure, there was not enough room to store the credentials
 */
message SetNetworkCredentialsRequest {
  option (type_id) = 507; // CTRL_REQUEST_WIFI_SET_NETWORK_CREDENTIALS
  string ssid = 1; // Network SSID
  bytes bssid = 2 [(nanopb).max_size = 6]; // Network address
  Security security = 3; // Network security
  Credentials credentials = 4; // Network credentials
  Interface interface_config = 5; // Network interface configuration (IP, mask, DNS etc)
  bool hidden = 6;
}

message SetNetworkCredentialsReply {
}
