| Nordic Thingy:52 v2.0.0

ble_tcs.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form, except as embedded into a Nordic
12 Semiconductor ASA integrated circuit in a product or a software update for
13 such product, must reproduce the above copyright notice, this list of
14 conditions and the following disclaimer in the documentation and/or other
15 materials provided with the distribution.
16
17 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18 contributors may be used to endorse or promote products derived from this
19 software without specific prior written permission.
20
21 4. This software, with or without modification, must only be used with a
22 Nordic Semiconductor ASA integrated circuit.
23
24 5. Any software provided in binary form under this license must not be reverse
25 engineered, decompiled, modified and/or disassembled.
26
27 THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
58 #ifndef BLE_TCS_H__
59 #define BLE_TCS_H__
60
61 #include "ble.h"
62 #include "ble_srv_common.h"
63 #include "app_util_platform.h"
64 #include <stdint.h>
65 #include <stdbool.h>
66
67 #define BLE_UUID_TCS_SERVICE 0x0100
68 #define BLE_TCS_MAX_DATA_LEN (BLE_GATT_ATT_MTU_DEFAULT - 3)
70 #define BLE_TCS_DEVICE_NAME_LEN_MAX 10
71 #define BLE_TCS_BEACON_LEN_MAX 17
72 #define BLE_TCS_BEACON_LEN_MIN 3
73 #define BLE_TCS_CLOUD_LEN_MAX 250
74 #define BLE_TCS_CLOUD_LEN_MIN 0
75
76 #ifdef __GNUC__
77 #ifdef PACKED
78 #undef PACKED
79 #endif
80
81 #define PACKED(TYPE) TYPE __attribute__ ((packed))
82 #endif
83
84 typedef PACKED( struct
85 {
86 uint8_t name[BLE_TCS_DEVICE_NAME_LEN_MAX+1];
87 uint8_t len;
88 }) ble_tcs_dev_name_t;
89
90 typedef PACKED( struct
91 {
92 uint16_t interval;
93 uint8_t timeout;
94 }) ble_tcs_adv_params_t;
95
96 #define TCS_ADV_PARAMS_INTERVAL_MIN 32UL
97 #define TCS_ADV_PARAMS_INTERVAL_MAX 8000UL
98 #define TCS_ADV_PARAMS_TIMEOUT_MIN 0UL
99 #define TCS_ADV_PARAMS_TIMEOUT_MAX 180UL
100
101 typedef uint16_t ble_tcs_appear_t;
102
103 typedef PACKED( struct
104 {
105 uint16_t min_conn_int;
106 uint16_t max_conn_int;
107 uint16_t slave_latency;
108 uint16_t sup_timeout;
109 }) ble_tcs_conn_params_t;
110
111 typedef PACKED( struct
112 {
113 uint8_t data[BLE_TCS_BEACON_LEN_MAX];
114 uint8_t len;
115 }) ble_tcs_eddystone_url_t;
116
117 typedef PACKED( struct
118 {
119 uint8_t token[BLE_TCS_CLOUD_LEN_MAX];
120 uint8_t len;
121 }) ble_tcs_cloud_token_t;
122
123 typedef PACKED( struct
124 {
125 uint8_t major;
126 uint8_t minor;
127 uint8_t patch;
128 }) ble_tcs_fw_version_t;
129
130 typedef PACKED( struct
131 {
132 uint8_t req;
133 uint16_t size;
134 }) ble_tcs_mtu_t;
135
136 #define TCS_MTU_REQ_EXCHANGE 0x01
137 #define TCS_MTU_REQ_MIN 0UL
138 #define TCS_MTU_REQ_MAX 1UL
139 #define TCS_MTU_SIZE_MIN 23UL
140 #define TCS_MTU_SIZE_MAX 276UL
141
142 typedef struct
143 {
144 ble_tcs_dev_name_t dev_name;
145 ble_tcs_adv_params_t adv_params;
146 ble_tcs_conn_params_t conn_params;
147 ble_tcs_eddystone_url_t eddystone_url;
148 ble_tcs_cloud_token_t cloud_token;
149 ble_tcs_fw_version_t fw_version;
150 ble_tcs_mtu_t mtu;
151 }ble_tcs_params_t;
152
153 typedef enum
154 {
155 BLE_TCS_EVT_DEV_NAME,
156 BLE_TCS_EVT_ADV_PARAM,
157 BLE_TCS_EVT_CONN_PARAM,
158 BLE_TCS_EVT_BEACON,
159 BLE_TCS_EVT_CLOUD_TOKEN,
160 BLE_TCS_EVT_MTU
161 }ble_tcs_evt_type_t;
162
163 /* Forward declaration of the ble_tcs_t type. */
164 typedef struct ble_tcs_s ble_tcs_t;
165
167 typedef void (*ble_tcs_evt_handler_t) (ble_tcs_t * p_tcs,
168 ble_tcs_evt_type_t evt_type,
169 uint8_t * p_data,
170 uint16_t length);
171
177 typedef struct
178 {
179 ble_tcs_params_t * p_init_vals;
180 ble_tcs_evt_handler_t evt_handler;
181 } ble_tcs_init_t;
182
187 struct ble_tcs_s
188 {
189 uint8_t uuid_type;
190 uint16_t service_handle;
191 ble_gatts_char_handles_t dev_name_handles;
192 ble_gatts_char_handles_t adv_param_handles;
193 ble_gatts_char_handles_t conn_param_handles;
194 ble_gatts_char_handles_t beacon_handles;
195 ble_gatts_char_handles_t cloud_handles;
196 ble_gatts_char_handles_t fwv_handles;
197 ble_gatts_char_handles_t mtu_handles;
198 uint16_t conn_handle;
199 ble_tcs_evt_handler_t evt_handler;
200 };
201
212 uint32_t ble_tcs_init(ble_tcs_t * p_tcs, const ble_tcs_init_t * p_tcs_init);
213
224 void ble_tcs_on_ble_evt(ble_tcs_t * p_tcs, ble_evt_t * p_ble_evt);
225
235 uint32_t ble_tcs_mtu_set(ble_tcs_t * p_tcs, ble_tcs_mtu_t * p_data);
236
237 #endif // BLE_TCS_H__
238
ble_tcs_s::dev_name_handles
ble_gatts_char_handles_t dev_name_handles
Definition: ble_tcs.h:191
ble_tcs_mtu_set
uint32_t ble_tcs_mtu_set(ble_tcs_t *p_tcs, ble_tcs_mtu_t *p_data)
Function for setting the MTU char data.
ble_tcs_init_t::evt_handler
ble_tcs_evt_handler_t evt_handler
Definition: ble_tcs.h:180
ble_tcs_s::service_handle
uint16_t service_handle
Definition: ble_tcs.h:190
ble_tcs_init
uint32_t ble_tcs_init(ble_tcs_t *p_tcs, const ble_tcs_init_t *p_tcs_init)
Function for initializing the Thingy Configuration Service.
ble_tcs_s::conn_param_handles
ble_gatts_char_handles_t conn_param_handles
Definition: ble_tcs.h:193
ble_tcs_evt_handler_t
void(* ble_tcs_evt_handler_t)(ble_tcs_t *p_tcs, ble_tcs_evt_type_t evt_type, uint8_t *p_data, uint16_t length)
Thingy Configuration Service event handler type.
Definition: ble_tcs.h:167
ble_tcs_s::conn_handle
uint16_t conn_handle
Definition: ble_tcs.h:198
ble_tcs_s::uuid_type
uint8_t uuid_type
Definition: ble_tcs.h:189
ble_tcs_s::evt_handler
ble_tcs_evt_handler_t evt_handler
Definition: ble_tcs.h:199
ble_tcs_init_t
Thingy Configuration Service initialization structure.
Definition: ble_tcs.h:177
ble_tcs_on_ble_evt
void ble_tcs_on_ble_evt(ble_tcs_t *p_tcs, ble_evt_t *p_ble_evt)
Function for handling the Thingy Configuration Service&#39;s BLE events.
ble_tcs_s::adv_param_handles
ble_gatts_char_handles_t adv_param_handles
Definition: ble_tcs.h:192
ble_tcs_s
Thingy Configuration Service structure.
Definition: ble_tcs.h:187