Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/ble/common/ble_advdata.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | /** @file |
Vincent Coubard |
638:c90ae1400bf2 | 34 | * |
Vincent Coubard |
638:c90ae1400bf2 | 35 | * @defgroup ble_sdk_lib_advdata Advertising and Scan Response Data Encoder |
Vincent Coubard |
638:c90ae1400bf2 | 36 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 37 | * @ingroup ble_sdk_lib |
Vincent Coubard |
638:c90ae1400bf2 | 38 | * @brief Functions for encoding data in the Advertising and Scan Response Data format, |
Vincent Coubard |
638:c90ae1400bf2 | 39 | * and for passing the data to the stack. |
Vincent Coubard |
638:c90ae1400bf2 | 40 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 41 | |
Vincent Coubard |
638:c90ae1400bf2 | 42 | #ifndef BLE_ADVDATA_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 43 | #define BLE_ADVDATA_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 44 | |
Vincent Coubard |
638:c90ae1400bf2 | 45 | #include <stdint.h> |
Vincent Coubard |
638:c90ae1400bf2 | 46 | #include <stdbool.h> |
Vincent Coubard |
638:c90ae1400bf2 | 47 | #include <string.h> |
Vincent Coubard |
638:c90ae1400bf2 | 48 | #include "nrf_ble.h" |
Vincent Coubard |
638:c90ae1400bf2 | 49 | #include "app_util.h" |
Vincent Coubard |
638:c90ae1400bf2 | 50 | |
Vincent Coubard |
638:c90ae1400bf2 | 51 | |
Vincent Coubard |
638:c90ae1400bf2 | 52 | #define ADV_LENGTH_FIELD_SIZE 1UL /**< Advertising Data and Scan Response format contains 1 octet for the length. */ |
Vincent Coubard |
638:c90ae1400bf2 | 53 | #define ADV_AD_TYPE_FIELD_SIZE 1UL /**< Advertising Data and Scan Response format contains 1 octet for the AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 54 | #define ADV_AD_DATA_OFFSET (ADV_LENGTH_FIELD_SIZE + \ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | ADV_AD_TYPE_FIELD_SIZE) /**< Offset for the AD data field of the Advertising Data and Scan Response format. */ |
Vincent Coubard |
638:c90ae1400bf2 | 56 | #define AD_TYPE_TK_VALUE_DATA_SIZE (sizeof(ble_advdata_tk_value_t)) /**< Data size (in octets) of the Security Manager TK value AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 57 | #define AD_TYPE_TK_VALUE_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 58 | AD_TYPE_TK_VALUE_DATA_SIZE) /**< Size (in octets) of the Security Manager TK value AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 59 | #define AD_TYPE_LE_ROLE_DATA_SIZE 1UL /**< Data size (in octets) of the LE Bluetooth Device Address AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 60 | #define AD_TYPE_LE_ROLE_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 61 | AD_TYPE_LE_ROLE_DATA_SIZE) /**< Size (in octets) of the LE Bluetooth Device Address AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 62 | #define AD_TYPE_BLE_DEVICE_ADDR_TYPE_SIZE 1UL /**< Data size (in octets) of the Address type of the LE Bluetooth Device Address AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 63 | #define AD_TYPE_BLE_DEVICE_ADDR_DATA_SIZE (BLE_GAP_ADDR_LEN + \ |
Vincent Coubard |
638:c90ae1400bf2 | 64 | AD_TYPE_BLE_DEVICE_ADDR_TYPE_SIZE) /**< Data size (in octets) of the LE Bluetooth Device Address AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 65 | #define AD_TYPE_BLE_DEVICE_ADDR_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 66 | AD_TYPE_BLE_DEVICE_ADDR_DATA_SIZE) /**< Size (in octets) of the LE Bluetooth Device Address AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 67 | #define AD_TYPE_APPEARANCE_DATA_SIZE 2UL /**< Data size (in octets) of the Appearance AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 68 | #define AD_TYPE_APPEARANCE_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 69 | AD_TYPE_APPEARANCE_DATA_SIZE) /**< Size (in octets) of the Appearance AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 70 | #define AD_TYPE_FLAGS_DATA_SIZE 1UL /**< Data size (in octets) of the Flags AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 71 | #define AD_TYPE_FLAGS_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 72 | AD_TYPE_FLAGS_DATA_SIZE) /**< Size (in octets) of the Flags AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 73 | #define AD_TYPE_TX_POWER_LEVEL_DATA_SIZE 1UL /**< Data size (in octets) of the TX Power Level AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 74 | #define AD_TYPE_TX_POWER_LEVEL_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 75 | AD_TYPE_TX_POWER_LEVEL_DATA_SIZE) /**< Size (in octets) of the TX Power Level AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 76 | #define AD_TYPE_CONN_INT_DATA_SIZE 4UL /**< Data size (in octets) of the Slave Connection Interval Range AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 77 | #define AD_TYPE_CONN_INT_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 78 | AD_TYPE_CONN_INT_DATA_SIZE) /**< Data size (in octets) of the Slave Connection Interval Range AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 79 | #define AD_TYPE_MANUF_SPEC_DATA_ID_SIZE 2UL /**< Size (in octets) of the Company Identifier Code, which is a part of the Manufacturer Specific Data AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 80 | #define AD_TYPE_SERV_DATA_16BIT_UUID_SIZE 2UL /**< Size (in octets) of the 16-bit UUID, which is a part of the Service Data AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 81 | #define AD_TYPE_OOB_FLAGS_DATA_SIZE 1UL /**< Data size (in octets) of the Security Manager OOB Flags AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 82 | #define AD_TYPE_OOB_FLAGS_SIZE (ADV_AD_DATA_OFFSET + \ |
Vincent Coubard |
638:c90ae1400bf2 | 83 | AD_TYPE_OOB_FLAGS_DATA_SIZE) /**< Size (in octets) of the Security Manager OOB Flags AD type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 84 | |
Vincent Coubard |
638:c90ae1400bf2 | 85 | #define AD_TYPE_SEC_MGR_OOB_FLAG_SET 1U /**< Security Manager OOB Flag set. Flag selection is done using _POS defines */ |
Vincent Coubard |
638:c90ae1400bf2 | 86 | #define AD_TYPE_SEC_MGR_OOB_FLAG_CLEAR 0U /**< Security Manager OOB Flag clear. Flag selection is done using _POS defines */ |
Vincent Coubard |
638:c90ae1400bf2 | 87 | #define AD_TYPE_SEC_MGR_OOB_FLAG_OOB_DATA_PRESENT_POS 0UL /**< Security Manager OOB Data Present Flag position. */ |
Vincent Coubard |
638:c90ae1400bf2 | 88 | #define AD_TYPE_SEC_MGR_OOB_FLAG_OOB_LE_SUPPORTED_POS 1UL /**< Security Manager OOB Low Energy Supported Flag position. */ |
Vincent Coubard |
638:c90ae1400bf2 | 89 | #define AD_TYPE_SEC_MGR_OOB_FLAG_SIM_LE_AND_EP_POS 2UL /**< Security Manager OOB Simultaneous LE and BR/EDR to Same Device Capable Flag position. */ |
Vincent Coubard |
638:c90ae1400bf2 | 90 | #define AD_TYPE_SEC_MGR_OOB_ADDRESS_TYPE_PUBLIC 0UL /**< Security Manager OOB Public Address type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 91 | #define AD_TYPE_SEC_MGR_OOB_ADDRESS_TYPE_RANDOM 1UL /**< Security Manager OOB Random Address type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 92 | #define AD_TYPE_SEC_MGR_OOB_FLAG_ADDRESS_TYPE_POS 3UL /**< Security Manager OOB Address type Flag (0 = Public Address, 1 = Random Address) position. */ |
Vincent Coubard |
638:c90ae1400bf2 | 93 | |
Vincent Coubard |
638:c90ae1400bf2 | 94 | |
Vincent Coubard |
638:c90ae1400bf2 | 95 | /**@brief Security Manager TK value. */ |
Vincent Coubard |
638:c90ae1400bf2 | 96 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 97 | { |
Vincent Coubard |
638:c90ae1400bf2 | 98 | uint8_t tk[BLE_GAP_SEC_KEY_LEN]; /**< Array containing TK value. */ |
Vincent Coubard |
638:c90ae1400bf2 | 99 | } ble_advdata_tk_value_t; |
Vincent Coubard |
638:c90ae1400bf2 | 100 | |
Vincent Coubard |
638:c90ae1400bf2 | 101 | /**@brief Advertising data LE Role types. This enumeration contains the options available for the LE role inside |
Vincent Coubard |
638:c90ae1400bf2 | 102 | * the advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 103 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 104 | { |
Vincent Coubard |
638:c90ae1400bf2 | 105 | BLE_ADVDATA_ROLE_NOT_PRESENT = 0, /**< LE Role AD structure not present. */ |
Vincent Coubard |
638:c90ae1400bf2 | 106 | BLE_ADVDATA_ROLE_ONLY_PERIPH, /**< Only Peripheral Role supported. */ |
Vincent Coubard |
638:c90ae1400bf2 | 107 | BLE_ADVDATA_ROLE_ONLY_CENTRAL, /**< Only Central Role supported. */ |
Vincent Coubard |
638:c90ae1400bf2 | 108 | BLE_ADVDATA_ROLE_BOTH_PERIPH_PREFERRED, /**< Peripheral and Central Role supported. Peripheral Role preferred for connection establishment. */ |
Vincent Coubard |
638:c90ae1400bf2 | 109 | BLE_ADVDATA_ROLE_BOTH_CENTRAL_PREFERRED /**< Peripheral and Central Role supported. Central Role preferred for connection establishment */ |
Vincent Coubard |
638:c90ae1400bf2 | 110 | } ble_advdata_le_role_t; |
Vincent Coubard |
638:c90ae1400bf2 | 111 | |
Vincent Coubard |
638:c90ae1400bf2 | 112 | /**@brief Advertising data name type. This enumeration contains the options available for the device name inside |
Vincent Coubard |
638:c90ae1400bf2 | 113 | * the advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 114 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 115 | { |
Vincent Coubard |
638:c90ae1400bf2 | 116 | BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 117 | BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 118 | BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 119 | } ble_advdata_name_type_t; |
Vincent Coubard |
638:c90ae1400bf2 | 120 | |
Vincent Coubard |
638:c90ae1400bf2 | 121 | /**@brief UUID list type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 122 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 123 | { |
Vincent Coubard |
638:c90ae1400bf2 | 124 | uint16_t uuid_cnt; /**< Number of UUID entries. */ |
Vincent Coubard |
638:c90ae1400bf2 | 125 | ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */ |
Vincent Coubard |
638:c90ae1400bf2 | 126 | } ble_advdata_uuid_list_t; |
Vincent Coubard |
638:c90ae1400bf2 | 127 | |
Vincent Coubard |
638:c90ae1400bf2 | 128 | /**@brief Connection interval range structure. */ |
Vincent Coubard |
638:c90ae1400bf2 | 129 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 130 | { |
Vincent Coubard |
638:c90ae1400bf2 | 131 | uint16_t min_conn_interval; /**< Minimum connection interval, in units of 1.25 ms, range 6 to 3200 (7.5 ms to 4 s). */ |
Vincent Coubard |
638:c90ae1400bf2 | 132 | uint16_t max_conn_interval; /**< Maximum connection interval, in units of 1.25 ms, range 6 to 3200 (7.5 ms to 4 s). The value 0xFFFF indicates no specific maximum. */ |
Vincent Coubard |
638:c90ae1400bf2 | 133 | } ble_advdata_conn_int_t; |
Vincent Coubard |
638:c90ae1400bf2 | 134 | |
Vincent Coubard |
638:c90ae1400bf2 | 135 | /**@brief Manufacturer specific data structure. */ |
Vincent Coubard |
638:c90ae1400bf2 | 136 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 137 | { |
Vincent Coubard |
638:c90ae1400bf2 | 138 | uint16_t company_identifier; /**< Company identifier code. */ |
Vincent Coubard |
638:c90ae1400bf2 | 139 | uint8_array_t data; /**< Additional manufacturer specific data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 140 | } ble_advdata_manuf_data_t; |
Vincent Coubard |
638:c90ae1400bf2 | 141 | |
Vincent Coubard |
638:c90ae1400bf2 | 142 | /**@brief Service data structure. */ |
Vincent Coubard |
638:c90ae1400bf2 | 143 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 144 | { |
Vincent Coubard |
638:c90ae1400bf2 | 145 | uint16_t service_uuid; /**< Service UUID. */ |
Vincent Coubard |
638:c90ae1400bf2 | 146 | uint8_array_t data; /**< Additional service data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 147 | } ble_advdata_service_data_t; |
Vincent Coubard |
638:c90ae1400bf2 | 148 | |
Vincent Coubard |
638:c90ae1400bf2 | 149 | /**@brief Advertising data structure. This structure contains all options and data needed for encoding and |
Vincent Coubard |
638:c90ae1400bf2 | 150 | * setting the advertising data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 151 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 152 | { |
Vincent Coubard |
638:c90ae1400bf2 | 153 | ble_advdata_name_type_t name_type; /**< Type of device name. */ |
Vincent Coubard |
638:c90ae1400bf2 | 154 | uint8_t short_name_len; /**< Length of short device name (if short type is specified). */ |
Vincent Coubard |
638:c90ae1400bf2 | 155 | bool include_appearance; /**< Determines if Appearance shall be included. */ |
Vincent Coubard |
638:c90ae1400bf2 | 156 | uint8_t flags; /**< Advertising data Flags field. */ |
Vincent Coubard |
638:c90ae1400bf2 | 157 | int8_t * p_tx_power_level; /**< TX Power Level field. */ |
Vincent Coubard |
638:c90ae1400bf2 | 158 | ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */ |
Vincent Coubard |
638:c90ae1400bf2 | 159 | ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */ |
Vincent Coubard |
638:c90ae1400bf2 | 160 | ble_advdata_uuid_list_t uuids_solicited; /**< List of solicited UUIDs. */ |
Vincent Coubard |
638:c90ae1400bf2 | 161 | ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */ |
Vincent Coubard |
638:c90ae1400bf2 | 162 | ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 163 | ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */ |
Vincent Coubard |
638:c90ae1400bf2 | 164 | uint8_t service_data_count; /**< Number of Service data structures. */ |
Vincent Coubard |
638:c90ae1400bf2 | 165 | bool include_ble_device_addr; /**< Determines if LE Bluetooth Device Address shall be included. */ |
Vincent Coubard |
638:c90ae1400bf2 | 166 | ble_advdata_le_role_t le_role; /**< LE Role field. Included when different from @ref BLE_ADVDATA_ROLE_NOT_PRESENT.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 167 | ble_advdata_tk_value_t * p_tk_value; /**< Security Manager TK value field. Included when different from NULL.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 168 | uint8_t * p_sec_mgr_oob_flags; /**< Security Manager Out Of Band Flags field. Included when different from NULL.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 169 | } ble_advdata_t; |
Vincent Coubard |
638:c90ae1400bf2 | 170 | |
Vincent Coubard |
638:c90ae1400bf2 | 171 | /**@brief Function for encoding data in the Advertising and Scan Response data format |
Vincent Coubard |
638:c90ae1400bf2 | 172 | * (AD structures). |
Vincent Coubard |
638:c90ae1400bf2 | 173 | * |
Vincent Coubard |
638:c90ae1400bf2 | 174 | * @details This function encodes data into the Advertising and Scan Response data format |
Vincent Coubard |
638:c90ae1400bf2 | 175 | * (AD structures) based on the selections in the supplied structures. This function can be used to |
Vincent Coubard |
638:c90ae1400bf2 | 176 | * create a payload of Advertising packet or Scan Response packet, or a payload of NFC |
Vincent Coubard |
638:c90ae1400bf2 | 177 | * message intended for initiating the Out-of-Band pairing. |
Vincent Coubard |
638:c90ae1400bf2 | 178 | * |
Vincent Coubard |
638:c90ae1400bf2 | 179 | * @param[in] p_advdata Pointer to the structure for specifying the content of encoded data. |
Vincent Coubard |
638:c90ae1400bf2 | 180 | * @param[out] p_encoded_data Pointer to the buffer where encoded data will be returned. |
Vincent Coubard |
638:c90ae1400bf2 | 181 | * @param[in,out] p_len \c in: Size of \p p_encoded_data buffer. |
Vincent Coubard |
638:c90ae1400bf2 | 182 | * \c out: Length of encoded data. |
Vincent Coubard |
638:c90ae1400bf2 | 183 | * |
Vincent Coubard |
638:c90ae1400bf2 | 184 | * @retval NRF_SUCCESS If the operation was successful. |
Vincent Coubard |
638:c90ae1400bf2 | 185 | * @retval NRF_ERROR_INVALID_PARAM If the operation failed because a wrong parameter was provided in \p p_advdata. |
Vincent Coubard |
638:c90ae1400bf2 | 186 | * @retval NRF_ERROR_DATA_SIZE If the operation failed because not all the requested data could fit into the |
Vincent Coubard |
638:c90ae1400bf2 | 187 | * provided buffer or some encoded AD structure is too long and its |
Vincent Coubard |
638:c90ae1400bf2 | 188 | * length cannot be encoded with one octet. |
Vincent Coubard |
638:c90ae1400bf2 | 189 | * |
Vincent Coubard |
638:c90ae1400bf2 | 190 | * @warning This API may override the application's request to use the long name and use a short name |
Vincent Coubard |
638:c90ae1400bf2 | 191 | * instead. This truncation will occur in case the long name does not fit the provided buffer size. |
Vincent Coubard |
638:c90ae1400bf2 | 192 | * The application can specify a preferred short name length if truncation is required. |
Vincent Coubard |
638:c90ae1400bf2 | 193 | * For example, if the complete device name is ABCD_HRMonitor, the application can specify the short name |
Vincent Coubard |
638:c90ae1400bf2 | 194 | * length to be 8, so that the short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni |
Vincent Coubard |
638:c90ae1400bf2 | 195 | * if the available size for the short name is 9 or 12 respectively, to have a more appropriate short name. |
Vincent Coubard |
638:c90ae1400bf2 | 196 | * However, it should be noted that this is just a preference that the application can specify, and |
Vincent Coubard |
638:c90ae1400bf2 | 197 | * if the preference is too large to fit in the provided buffer, the name can be truncated further. |
Vincent Coubard |
638:c90ae1400bf2 | 198 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 199 | uint32_t adv_data_encode(ble_advdata_t const * const p_advdata, |
Vincent Coubard |
638:c90ae1400bf2 | 200 | uint8_t * const p_encoded_data, |
Vincent Coubard |
638:c90ae1400bf2 | 201 | uint16_t * const p_len); |
Vincent Coubard |
638:c90ae1400bf2 | 202 | |
Vincent Coubard |
638:c90ae1400bf2 | 203 | /**@brief Function for encoding and setting the advertising data and/or scan response data. |
Vincent Coubard |
638:c90ae1400bf2 | 204 | * |
Vincent Coubard |
638:c90ae1400bf2 | 205 | * @details This function encodes advertising data and/or scan response data based on the selections |
Vincent Coubard |
638:c90ae1400bf2 | 206 | * in the supplied structures, and passes the encoded data to the stack. |
Vincent Coubard |
638:c90ae1400bf2 | 207 | * |
Vincent Coubard |
638:c90ae1400bf2 | 208 | * @param[in] p_advdata Structure for specifying the content of the advertising data. |
Vincent Coubard |
638:c90ae1400bf2 | 209 | * Set to NULL if advertising data is not to be set. |
Vincent Coubard |
638:c90ae1400bf2 | 210 | * @param[in] p_srdata Structure for specifying the content of the scan response data. |
Vincent Coubard |
638:c90ae1400bf2 | 211 | * Set to NULL if scan response data is not to be set. |
Vincent Coubard |
638:c90ae1400bf2 | 212 | * |
Vincent Coubard |
638:c90ae1400bf2 | 213 | * @retval NRF_SUCCESS If the operation was successful. |
Vincent Coubard |
638:c90ae1400bf2 | 214 | * @retval NRF_ERROR_INVALID_PARAM If the operation failed because a wrong parameter was provided in \p p_advdata. |
Vincent Coubard |
638:c90ae1400bf2 | 215 | * @retval NRF_ERROR_DATA_SIZE If the operation failed because not all the requested data could fit into the |
Vincent Coubard |
638:c90ae1400bf2 | 216 | * advertising packet. The maximum size of the advertisement packet |
Vincent Coubard |
638:c90ae1400bf2 | 217 | * is @ref BLE_GAP_ADV_MAX_SIZE. |
Vincent Coubard |
638:c90ae1400bf2 | 218 | * |
Vincent Coubard |
638:c90ae1400bf2 | 219 | * @warning This API may override the application's request to use the long name and use a short name |
Vincent Coubard |
638:c90ae1400bf2 | 220 | * instead. This truncation will occur in case the long name does not fit the provided buffer size. |
Vincent Coubard |
638:c90ae1400bf2 | 221 | * The application can specify a preferred short name length if truncation is required. |
Vincent Coubard |
638:c90ae1400bf2 | 222 | * For example, if the complete device name is ABCD_HRMonitor, the application can specify the short name |
Vincent Coubard |
638:c90ae1400bf2 | 223 | * length to be 8, so that the short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni |
Vincent Coubard |
638:c90ae1400bf2 | 224 | * if the available size for the short name is 9 or 12 respectively, to have a more appropriate short name. |
Vincent Coubard |
638:c90ae1400bf2 | 225 | * However, it should be noted that this is just a preference that the application can specify, and |
Vincent Coubard |
638:c90ae1400bf2 | 226 | * if the preference is too large to fit in the provided buffer, the name can be truncated further. |
Vincent Coubard |
638:c90ae1400bf2 | 227 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 228 | uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata); |
Vincent Coubard |
638:c90ae1400bf2 | 229 | |
Vincent Coubard |
638:c90ae1400bf2 | 230 | #endif // BLE_ADVDATA_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 231 | |
Vincent Coubard |
638:c90ae1400bf2 | 232 | /** @} */ |