/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.wifi.hostapd@1.0;

import android.hardware.wifi.supplicant@1.0::Ssid;

/**
 * Top-level object for managing SoftAPs.
 */
interface IHostapd {
    /**
     * Size limits for some of the params used in this interface.
     */
    enum ParamSizeLimits : uint32_t {
        /** Max length of SSID param. */
        SSID_MAX_LEN_IN_BYTES = 32,

        /** Min length of PSK passphrase param. */
        WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES = 8,

        /** Max length of PSK passphrase param. */
        WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES = 63,
    };

    /** Possble Security types. */
    enum EncryptionType : uint32_t {
        NONE,
        WPA,
        WPA2
    };

    /**
     * Band to use for the SoftAp operations.
     * When using ACS, special value |BAND_ANY| can be
     * used to indicate that any supported band can be used. This special
     * case is currently supported only with drivers with which
     * offloaded ACS is used.
     */
    enum Band : uint32_t {
        BAND_2_4_GHZ,
        BAND_5_GHZ,
        BAND_ANY
    };

    /**
     * Parameters to control the HW mode for the interface.
     */
    struct HwModeParams {
        /**
         * Whether IEEE 802.11n (HT) is enabled or not.
         * Note: hwMode=G (2.4 GHz) and hwMode=A (5 GHz) is used to specify
         * the band.
         */
        bool enable80211N;
         /**
          * Whether IEEE 802.11ac (VHT) is enabled or not.
          * Note: hw_mode=a is used to specify that 5 GHz band is used with VHT.
          */
        bool enable80211AC;
    };

    /**
     * Parameters to control the channel selection for the interface.
     */
    struct ChannelParams {
        /**
         * Whether to enable ACS (Automatic Channel Selection) or not.
         * The channel can be selected automatically at run time by setting
         * this flag, which must enable the ACS survey based algorithm.
         */
        bool enableAcs;
        /**
         * This option can be used to exclude all DFS channels from the ACS
         * channel list in cases where the driver supports DFS channels.
         **/
        bool acsShouldExcludeDfs;
        /**
         * Channel number (IEEE 802.11) to use for the interface.
         * If ACS is enabled, this field is ignored.
         */
        uint32_t channel;
        /**
         * Band to use for the SoftAp operations.
         */
        Band band;
    };

    /**
     * Parameters to use for setting up the access point interface.
     */
    struct IfaceParams {
        /** Name of the interface */
        string ifaceName;
        /** Hw mode params for the interface */
        HwModeParams hwModeParams;
        /** Chanel params for the interface */
        ChannelParams channelParams;
    };

    /**
     * Parameters to use for setting up the access point network.
     */
    struct NetworkParams {
        /** SSID to set for the network */
        Ssid ssid;
        /** Whether the network needs to be hidden or not. */
        bool isHidden;
        /** Key management mask for the network. */
        EncryptionType encryptionType;
        /** Passphrase for WPA_PSK network. */
        string pskPassphrase;
    };

    /**
     * Adds a new access point for hostapd to control.
     *
     * This should trigger the setup of an access point with the specified
     * interface and network params.
     *
     * @param ifaceParams AccessPoint Params for the access point.
     * @param nwParams Network Params for the access point.
     * @return status Status of the operation.
     *         Possible status codes:
     *         |HostapdStatusCode.SUCCESS|,
     *         |HostapdStatusCode.FAILURE_ARGS_INVALID|,
     *         |HostapdStatusCode.FAILURE_UNKNOWN|,
     *         |HostapdStatusCode.FAILURE_IFACE_EXISTS|
     */
    addAccessPoint(IfaceParams ifaceParams, NetworkParams nwParams)
        generates(HostapdStatus status);

    /**
     * Removes an existing access point from hostapd.
     *
     * This should bring down the access point previously setup on the
     * interface.
     *
     * @param ifaceName Name of the interface.
     * @return status Status of the operation.
     *         Possible status codes:
     *         |HostapdStatusCode.SUCCESS|,
     *         |HostapdStatusCode.FAILURE_UNKNOWN|,
     *         |HostapdStatusCode.FAILURE_IFACE_UNKNOWN|
     */
    removeAccessPoint(string ifaceName) generates(HostapdStatus status);

    /**
     * Terminate the service.
     * This must de-register the service and clear all state. If this HAL
     * supports the lazy HAL protocol, then this may trigger daemon to exit and
     * wait to be restarted.
     */
    oneway terminate();
};