project for nrf51822 qfab
Dependencies: eddystone_URL mbed
Fork of eddystone_URL by
nRF51822/nordic/nrf-sdk/ble/ble_advdata.h@5:267bdacf5508, 2017-11-23 (annotated)
- Committer:
- tridung141196
- Date:
- Thu Nov 23 15:38:48 2017 +0000
- Revision:
- 5:267bdacf5508
- Parent:
- 0:76dfa9657d9d
ibeacon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:76dfa9657d9d | 2 | * |
jksoft | 0:76dfa9657d9d | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:76dfa9657d9d | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:76dfa9657d9d | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:76dfa9657d9d | 6 | * |
jksoft | 0:76dfa9657d9d | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:76dfa9657d9d | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:76dfa9657d9d | 9 | * the file. |
jksoft | 0:76dfa9657d9d | 10 | * |
jksoft | 0:76dfa9657d9d | 11 | */ |
jksoft | 0:76dfa9657d9d | 12 | |
jksoft | 0:76dfa9657d9d | 13 | /** @file |
jksoft | 0:76dfa9657d9d | 14 | * |
jksoft | 0:76dfa9657d9d | 15 | * @defgroup ble_sdk_lib_advdata Advertising Data Encoder |
jksoft | 0:76dfa9657d9d | 16 | * @{ |
jksoft | 0:76dfa9657d9d | 17 | * @ingroup ble_sdk_lib |
jksoft | 0:76dfa9657d9d | 18 | * @brief Function for encoding the advertising data and/or scan response data, and passing them to |
jksoft | 0:76dfa9657d9d | 19 | * the stack. |
jksoft | 0:76dfa9657d9d | 20 | */ |
jksoft | 0:76dfa9657d9d | 21 | |
jksoft | 0:76dfa9657d9d | 22 | #ifndef BLE_ADVDATA_H__ |
jksoft | 0:76dfa9657d9d | 23 | #define BLE_ADVDATA_H__ |
jksoft | 0:76dfa9657d9d | 24 | |
jksoft | 0:76dfa9657d9d | 25 | #include <stdint.h> |
jksoft | 0:76dfa9657d9d | 26 | #include <stdbool.h> |
jksoft | 0:76dfa9657d9d | 27 | #include <string.h> |
jksoft | 0:76dfa9657d9d | 28 | #include "ble.h" |
jksoft | 0:76dfa9657d9d | 29 | #include "app_util.h" |
jksoft | 0:76dfa9657d9d | 30 | |
jksoft | 0:76dfa9657d9d | 31 | #ifdef __cplusplus |
jksoft | 0:76dfa9657d9d | 32 | extern "C" { |
jksoft | 0:76dfa9657d9d | 33 | #endif |
jksoft | 0:76dfa9657d9d | 34 | |
jksoft | 0:76dfa9657d9d | 35 | /**@brief Advertising data name type. This contains the options available for the device name inside |
jksoft | 0:76dfa9657d9d | 36 | * the advertising data. */ |
jksoft | 0:76dfa9657d9d | 37 | typedef enum |
jksoft | 0:76dfa9657d9d | 38 | { |
jksoft | 0:76dfa9657d9d | 39 | BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */ |
jksoft | 0:76dfa9657d9d | 40 | BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */ |
jksoft | 0:76dfa9657d9d | 41 | BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */ |
jksoft | 0:76dfa9657d9d | 42 | } ble_advdata_name_type_t; |
jksoft | 0:76dfa9657d9d | 43 | |
jksoft | 0:76dfa9657d9d | 44 | /**@brief UUID list type. */ |
jksoft | 0:76dfa9657d9d | 45 | typedef struct |
jksoft | 0:76dfa9657d9d | 46 | { |
jksoft | 0:76dfa9657d9d | 47 | uint16_t uuid_cnt; /**< Number of UUID entries. */ |
jksoft | 0:76dfa9657d9d | 48 | ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */ |
jksoft | 0:76dfa9657d9d | 49 | } ble_advdata_uuid_list_t; |
jksoft | 0:76dfa9657d9d | 50 | |
jksoft | 0:76dfa9657d9d | 51 | /**@brief Connection interval range structure. */ |
jksoft | 0:76dfa9657d9d | 52 | typedef struct |
jksoft | 0:76dfa9657d9d | 53 | { |
jksoft | 0:76dfa9657d9d | 54 | uint16_t min_conn_interval; /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */ |
jksoft | 0:76dfa9657d9d | 55 | uint16_t max_conn_interval; /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */ |
jksoft | 0:76dfa9657d9d | 56 | } ble_advdata_conn_int_t; |
jksoft | 0:76dfa9657d9d | 57 | |
jksoft | 0:76dfa9657d9d | 58 | /**@brief Manufacturer specific data structure. */ |
jksoft | 0:76dfa9657d9d | 59 | typedef struct |
jksoft | 0:76dfa9657d9d | 60 | { |
jksoft | 0:76dfa9657d9d | 61 | uint16_t company_identifier; /**< Company Identifier Code. */ |
jksoft | 0:76dfa9657d9d | 62 | uint8_array_t data; /**< Additional manufacturer specific data. */ |
jksoft | 0:76dfa9657d9d | 63 | } ble_advdata_manuf_data_t; |
jksoft | 0:76dfa9657d9d | 64 | |
jksoft | 0:76dfa9657d9d | 65 | /**@brief Service data structure. */ |
jksoft | 0:76dfa9657d9d | 66 | typedef struct |
jksoft | 0:76dfa9657d9d | 67 | { |
jksoft | 0:76dfa9657d9d | 68 | uint16_t service_uuid; /**< Service UUID. */ |
jksoft | 0:76dfa9657d9d | 69 | uint8_array_t data; /**< Additional service data. */ |
jksoft | 0:76dfa9657d9d | 70 | } ble_advdata_service_data_t; |
jksoft | 0:76dfa9657d9d | 71 | |
jksoft | 0:76dfa9657d9d | 72 | /**@brief Advertising data structure. This contains all options and data needed for encoding and |
jksoft | 0:76dfa9657d9d | 73 | * setting the advertising data. */ |
jksoft | 0:76dfa9657d9d | 74 | typedef struct |
jksoft | 0:76dfa9657d9d | 75 | { |
jksoft | 0:76dfa9657d9d | 76 | ble_advdata_name_type_t name_type; /**< Type of device name. */ |
jksoft | 0:76dfa9657d9d | 77 | uint8_t short_name_len; /**< Length of short device name (if short type is specified). */ |
jksoft | 0:76dfa9657d9d | 78 | bool include_appearance; /**< Determines if Appearance shall be included. */ |
jksoft | 0:76dfa9657d9d | 79 | uint8_array_t flags; /**< Advertising data Flags field. */ |
jksoft | 0:76dfa9657d9d | 80 | int8_t * p_tx_power_level; /**< TX Power Level field. */ |
jksoft | 0:76dfa9657d9d | 81 | ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */ |
jksoft | 0:76dfa9657d9d | 82 | ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */ |
jksoft | 0:76dfa9657d9d | 83 | ble_advdata_uuid_list_t uuids_solicited; /**< List of solcited UUIDs. */ |
jksoft | 0:76dfa9657d9d | 84 | ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */ |
jksoft | 0:76dfa9657d9d | 85 | ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */ |
jksoft | 0:76dfa9657d9d | 86 | ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */ |
jksoft | 0:76dfa9657d9d | 87 | uint8_t service_data_count; /**< Number of Service data structures. */ |
jksoft | 0:76dfa9657d9d | 88 | } ble_advdata_t; |
jksoft | 0:76dfa9657d9d | 89 | |
jksoft | 0:76dfa9657d9d | 90 | /**@brief Function for encoding and setting the advertising data and/or scan response data. |
jksoft | 0:76dfa9657d9d | 91 | * |
jksoft | 0:76dfa9657d9d | 92 | * @details This function encodes advertising data and/or scan response data based on the selections |
jksoft | 0:76dfa9657d9d | 93 | * in the supplied structures, and passes the encoded data to the stack. |
jksoft | 0:76dfa9657d9d | 94 | * |
jksoft | 0:76dfa9657d9d | 95 | * @param[in] p_advdata Structure for specifying the content of the advertising data. |
jksoft | 0:76dfa9657d9d | 96 | * Set to NULL if advertising data is not to be set. |
jksoft | 0:76dfa9657d9d | 97 | * @param[in] p_srdata Structure for specifying the content of the scan response data. |
jksoft | 0:76dfa9657d9d | 98 | * Set to NULL if scan response data is not to be set. |
jksoft | 0:76dfa9657d9d | 99 | * |
jksoft | 0:76dfa9657d9d | 100 | * @return NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit |
jksoft | 0:76dfa9657d9d | 101 | * into the advertising packet. The maximum size of the advertisement packet is @ref |
jksoft | 0:76dfa9657d9d | 102 | * BLE_GAP_ADV_MAX_SIZE. |
jksoft | 0:76dfa9657d9d | 103 | * |
jksoft | 0:76dfa9657d9d | 104 | * @warning This API may override application's request to use the long name and use a short name |
jksoft | 0:76dfa9657d9d | 105 | * instead. This truncation will occur in case the long name does not fit advertisement data size. |
jksoft | 0:76dfa9657d9d | 106 | * Application is permitted to specify a preferred short name length in case truncation is required. |
jksoft | 0:76dfa9657d9d | 107 | * For example, if the complete device name is ABCD_HRMonitor, application can specify short name |
jksoft | 0:76dfa9657d9d | 108 | * length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni |
jksoft | 0:76dfa9657d9d | 109 | * etc if available size for short name is 9 or 12 respectively to have more apporpriate short name. |
jksoft | 0:76dfa9657d9d | 110 | * However, it should be noted that this is just a preference that application can specify and |
jksoft | 0:76dfa9657d9d | 111 | * if the preference too large to fit in Advertisement Data, this can be further truncated. |
jksoft | 0:76dfa9657d9d | 112 | */ |
jksoft | 0:76dfa9657d9d | 113 | uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata); |
jksoft | 0:76dfa9657d9d | 114 | |
jksoft | 0:76dfa9657d9d | 115 | #ifdef __cplusplus |
jksoft | 0:76dfa9657d9d | 116 | } |
jksoft | 0:76dfa9657d9d | 117 | #endif |
jksoft | 0:76dfa9657d9d | 118 | |
jksoft | 0:76dfa9657d9d | 119 | #endif // BLE_ADVDATA_H__ |
jksoft | 0:76dfa9657d9d | 120 | |
jksoft | 0:76dfa9657d9d | 121 | /** @} */ |