<commit_before>/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * 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.
 */

#ifndef __GAP_H__
#define __GAP_H__

#include "ble/BLEProtocol.h"
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
#include "GapScanningParams.h"
#include "GapEvents.h"
#include "CallChainOfFunctionPointersWithContext.h"
#include "FunctionPointerWithContext.h"
#include "deprecate.h"

/* Forward declarations for classes that will only be used for pointers or references in the following. */
class GapAdvertisingParams;
class GapScanningParams;
class GapAdvertisingData;

class Gap {
    /*
     * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated.
     * They have been relocated to the class BLEProtocol.
     */
public:
    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead.
     */
    typedef BLEProtocol::AddressType_t AddressType_t;

    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead.
     */
    typedef BLEProtocol::AddressType_t addr_type_t;

    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead. The following
     *             constants have been left in their deprecated state to
     *             transparently support existing applications which may have
     *             used Gap::ADDR_TYPE_*.
     */
    enum DeprecatedAddressType_t {
        ADDR_TYPE_PUBLIC                        = BLEProtocol::AddressType::PUBLIC,
        ADDR_TYPE_RANDOM_STATIC                 = BLEProtocol::AddressType::RANDOM_STATIC,
        ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE     = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE,
        ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
    };

    /**
     * Length (in octets) of the BLE MAC address.
     */
    static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN;
    /**
     * 48-bit address, LSB format.
     *
     * @deprecated Use BLEProtocol::AddressBytes_t instead.
     */
    typedef BLEProtocol::AddressBytes_t Address_t;
    /**
     * 48-bit address, LSB format.
     *
     * @deprecated Use BLEProtocol::AddressBytes_t instead.
     */
    typedef BLEProtocol::AddressBytes_t address_t;

public:
    /**
     * Enumeration for timeout sources.
     */
    enum TimeoutSource_t {
        TIMEOUT_SRC_ADVERTISING      = 0x00, /**< Advertising timeout. */
        TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */
        TIMEOUT_SRC_SCAN             = 0x02, /**< Scanning timeout. */
        TIMEOUT_SRC_CONN             = 0x03, /**< Connection timeout. */
    };

    /**
     * Enumeration for disconnection reasons. The values for these reasons are
     * derived from Nordic's implementation, but the reasons are meant to be
     * independent of the transport. If you are returned a reason that is not
     * covered by this enumeration, please refer to the underlying
     * transport library.
     */
    enum DisconnectionReason_t {
        CONNECTION_TIMEOUT                          = 0x08,
        REMOTE_USER_TERMINATED_CONNECTION           = 0x13,
        REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14,  /**< Remote device terminated connection due to low resources.*/
        REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF     = 0x15,  /**< Remote device terminated connection due to power off. */
        LOCAL_HOST_TERMINATED_CONNECTION            = 0x16,
        CONN_INTERVAL_UNACCEPTABLE                  = 0x3B,
    };

    /**
     * Enumeration for whitelist advertising policy filter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (Vol. 6), Part B, Section 4.3.2.
     *
     * @experimental
     */
    enum AdvertisingPolicyMode_t {
        ADV_POLICY_IGNORE_WHITELIST = 0,
        ADV_POLICY_FILTER_SCAN_REQS = 1,
        ADV_POLICY_FILTER_CONN_REQS = 2,
        ADV_POLICY_FILTER_ALL_REQS  = 3,
    };

    /**
     * Enumeration for whitelist scanning policy filter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (Vol. 6), Part B, Section 4.3.3.
     *
     * @experimental
     */
    enum ScanningPolicyMode_t {
        SCAN_POLICY_IGNORE_WHITELIST = 0,
        SCAN_POLICY_FILTER_ALL_ADV   = 1,
    };

    /**
     * Enumeration for the whitelist initiator policy fiter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (vol. 6), Part B, Section 4.4.4.
     *
     * @experimental
     */
    enum InitiatorPolicyMode_t {
        INIT_POLICY_IGNORE_WHITELIST = 0,
        INIT_POLICY_FILTER_ALL_ADV   = 1,
    };

    /**
     * Representation of a Bluetooth Low Enery Whitelist containing addresses.
     *
     * @experimental
     */
    struct Whitelist_t {
        BLEProtocol::Address_t *addresses; /**< List of BLE addresses in the whitelist. */
        uint8_t                 size;      /**< Total number of BLE addresses in this whitelist */
        uint8_t                 capacity;  /**< Maximum number of BLE addresses that can be added to this whitelist. */
    };


    /**
     * Describes the current state of the device (more than one bit can be set).
     */
    struct GapState_t {
        unsigned advertising : 1; /**< Peripheral is currently advertising. */
        unsigned connected   : 1; /**< Peripheral is connected to a central. */
    };

    /**
     * Type for connection handle.
     */
    typedef uint16_t Handle_t;

    /**
     * Structure containing GAP connection parameters. When in peripheral role
     * the connection parameters are suggestions. The choice of the connection
     * parameters is eventually up to the central.
     */
    typedef struct {
        uint16_t minConnectionInterval;        /**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
        uint16_t maxConnectionInterval;        /**< Maximum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
        uint16_t slaveLatency;                 /**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/
        uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/
    } ConnectionParams_t;

    /**
     * Enumeration for the possible GAP roles of a BLE device.
     */
    enum Role_t {
        PERIPHERAL  = 0x1, /**< Peripheral Role. */
        CENTRAL     = 0x2, /**< Central Role.    */
    };

    /**
     * Structure containing data and metadata of a scanned advertising packet.
     */
    struct AdvertisementCallbackParams_t {
        BLEProtocol::AddressBytes_t              peerAddr;           /**< The peer's BLE address. */
        int8_t                                   rssi;               /**< The advertisement packet RSSI value. */
        bool                                     isScanResponse;     /**< Whether this packet is the response to a scan request. */
        GapAdvertisingParams::AdvertisingType_t  type;               /**< The type of advertisement. */
        uint8_t                                  advertisingDataLen; /**< Length of the advertisement data. */
        const uint8_t                           *advertisingData;    /**< Pointer to the advertisement packet's data. */<commit_msg>BLE: use common type ble::connection_handle_t as Handle_t.<commit_after>/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * 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.
 */

#ifndef __GAP_H__
#define __GAP_H__

#include "BLETypes.h"
#include "ble/BLEProtocol.h"
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
#include "GapScanningParams.h"
#include "GapEvents.h"
#include "CallChainOfFunctionPointersWithContext.h"
#include "FunctionPointerWithContext.h"
#include "deprecate.h"

/* Forward declarations for classes that will only be used for pointers or references in the following. */
class GapAdvertisingParams;
class GapScanningParams;
class GapAdvertisingData;

class Gap {
    /*
     * DEPRECATION ALERT: all of the APIs in this `public` block are deprecated.
     * They have been relocated to the class BLEProtocol.
     */
public:
    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead.
     */
    typedef BLEProtocol::AddressType_t AddressType_t;

    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead.
     */
    typedef BLEProtocol::AddressType_t addr_type_t;

    /**
     * Address-type for BLEProtocol addresses.
     *
     * @deprecated Use BLEProtocol::AddressType_t instead. The following
     *             constants have been left in their deprecated state to
     *             transparently support existing applications which may have
     *             used Gap::ADDR_TYPE_*.
     */
    enum DeprecatedAddressType_t {
        ADDR_TYPE_PUBLIC                        = BLEProtocol::AddressType::PUBLIC,
        ADDR_TYPE_RANDOM_STATIC                 = BLEProtocol::AddressType::RANDOM_STATIC,
        ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE     = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE,
        ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE
    };

    /**
     * Length (in octets) of the BLE MAC address.
     */
    static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN;
    /**
     * 48-bit address, LSB format.
     *
     * @deprecated Use BLEProtocol::AddressBytes_t instead.
     */
    typedef BLEProtocol::AddressBytes_t Address_t;
    /**
     * 48-bit address, LSB format.
     *
     * @deprecated Use BLEProtocol::AddressBytes_t instead.
     */
    typedef BLEProtocol::AddressBytes_t address_t;

public:
    /**
     * Enumeration for timeout sources.
     */
    enum TimeoutSource_t {
        TIMEOUT_SRC_ADVERTISING      = 0x00, /**< Advertising timeout. */
        TIMEOUT_SRC_SECURITY_REQUEST = 0x01, /**< Security request timeout. */
        TIMEOUT_SRC_SCAN             = 0x02, /**< Scanning timeout. */
        TIMEOUT_SRC_CONN             = 0x03, /**< Connection timeout. */
    };

    /**
     * Enumeration for disconnection reasons. The values for these reasons are
     * derived from Nordic's implementation, but the reasons are meant to be
     * independent of the transport. If you are returned a reason that is not
     * covered by this enumeration, please refer to the underlying
     * transport library.
     */
    enum DisconnectionReason_t {
        CONNECTION_TIMEOUT                          = 0x08,
        REMOTE_USER_TERMINATED_CONNECTION           = 0x13,
        REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14,  /**< Remote device terminated connection due to low resources.*/
        REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF     = 0x15,  /**< Remote device terminated connection due to power off. */
        LOCAL_HOST_TERMINATED_CONNECTION            = 0x16,
        CONN_INTERVAL_UNACCEPTABLE                  = 0x3B,
    };

    /**
     * Enumeration for whitelist advertising policy filter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (Vol. 6), Part B, Section 4.3.2.
     *
     * @experimental
     */
    enum AdvertisingPolicyMode_t {
        ADV_POLICY_IGNORE_WHITELIST = 0,
        ADV_POLICY_FILTER_SCAN_REQS = 1,
        ADV_POLICY_FILTER_CONN_REQS = 2,
        ADV_POLICY_FILTER_ALL_REQS  = 3,
    };

    /**
     * Enumeration for whitelist scanning policy filter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (Vol. 6), Part B, Section 4.3.3.
     *
     * @experimental
     */
    enum ScanningPolicyMode_t {
        SCAN_POLICY_IGNORE_WHITELIST = 0,
        SCAN_POLICY_FILTER_ALL_ADV   = 1,
    };

    /**
     * Enumeration for the whitelist initiator policy fiter modes. The possible
     * filter modes were obtained from the Bluetooth Core Specification
     * 4.2 (vol. 6), Part B, Section 4.4.4.
     *
     * @experimental
     */
    enum InitiatorPolicyMode_t {
        INIT_POLICY_IGNORE_WHITELIST = 0,
        INIT_POLICY_FILTER_ALL_ADV   = 1,
    };

    /**
     * Representation of a Bluetooth Low Enery Whitelist containing addresses.
     *
     * @experimental
     */
    struct Whitelist_t {
        BLEProtocol::Address_t *addresses; /**< List of BLE addresses in the whitelist. */
        uint8_t                 size;      /**< Total number of BLE addresses in this whitelist */
        uint8_t                 capacity;  /**< Maximum number of BLE addresses that can be added to this whitelist. */
    };


    /**
     * Describes the current state of the device (more than one bit can be set).
     */
    struct GapState_t {
        unsigned advertising : 1; /**< Peripheral is currently advertising. */
        unsigned connected   : 1; /**< Peripheral is connected to a central. */
    };

    /**
     * Type for connection handle.
     */
    typedef ble::connection_handle_t Handle_t;

    /**
     * Structure containing GAP connection parameters. When in peripheral role
     * the connection parameters are suggestions. The choice of the connection
     * parameters is eventually up to the central.
     */
    typedef struct {
        uint16_t minConnectionInterval;        /**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
        uint16_t maxConnectionInterval;        /**< Maximum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
        uint16_t slaveLatency;                 /**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/
        uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/
    } ConnectionParams_t;

    /**
     * Enumeration for the possible GAP roles of a BLE device.
     */
    enum Role_t {
        PERIPHERAL  = 0x1, /**< Peripheral Role. */
        CENTRAL     = 0x2, /**< Central Role.    */
    };

    /**
     * Structure containing data and metadata of a scanned advertising packet.
     */
    struct AdvertisementCallbackParams_t {
        BLEProtocol::AddressBytes_t              peerAddr;           /**< The peer's BLE address. */
        int8_t                                   rssi;               /**< The advertisement packet RSSI value. */
        bool                                     isScanResponse;     /**< Whether this packet is the response to a scan request. */
        GapAdvertisingParams::AdvertisingType_t  type;               /**< The type of advertisement. */
        uint8_t                                  advertisingDataLen; /**< Length of the advertisement data. */
        const uint8_t                           *advertisingData;    /**< Pointer to the advertisement packet's data. */
{'fraction_non_alphanumeric': 0.07942732648615002, 'fraction_numerical': 0.012324929971988795, 'mean_word_length': 2.3603848567245347, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2861106', 'n_tokens_mistral': 4817, 'n_tokens_neox': 4479, 'n_words': 1374}