Nordic Thingy:52 v2.2.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 #define BLE_TCS_NFC_LEN_MAX 247
76 
77 #ifdef __GNUC__
78  #ifdef PACKED
79  #undef PACKED
80  #endif
81 
82  #define PACKED(TYPE) TYPE __attribute__ ((packed))
83 #endif
84 
85 typedef PACKED( struct
86 {
87  uint8_t name[BLE_TCS_DEVICE_NAME_LEN_MAX+1];
88  uint8_t len;
89 }) ble_tcs_dev_name_t;
90 
91 typedef PACKED( struct
92 {
93  uint16_t interval;
94  uint8_t timeout;
95 }) ble_tcs_adv_params_t;
96 
97 #define TCS_ADV_PARAMS_INTERVAL_MIN 32UL
98 #define TCS_ADV_PARAMS_INTERVAL_MAX 8000UL
99 #define TCS_ADV_PARAMS_TIMEOUT_MIN 0UL
100 #define TCS_ADV_PARAMS_TIMEOUT_MAX 180UL
101 
102 typedef uint16_t ble_tcs_appear_t;
103 
104 typedef PACKED( struct
105 {
106  uint16_t min_conn_int;
107  uint16_t max_conn_int;
108  uint16_t slave_latency;
109  uint16_t sup_timeout;
110 }) ble_tcs_conn_params_t;
111 
112 typedef PACKED( struct
113 {
114  uint8_t data[BLE_TCS_BEACON_LEN_MAX];
115  uint8_t len;
116 }) ble_tcs_eddystone_url_t;
117 
118 typedef PACKED( struct
119 {
120  uint8_t token[BLE_TCS_CLOUD_LEN_MAX];
121  uint8_t len;
122 }) ble_tcs_cloud_token_t;
123 
124 typedef PACKED( struct
125 {
126  uint8_t major;
127  uint8_t minor;
128  uint8_t patch;
129 }) ble_tcs_fw_version_t;
130 
131 typedef PACKED( struct
132 {
133  uint8_t req;
134  uint16_t size;
135 }) ble_tcs_mtu_t;
136 
137 typedef PACKED( struct
138 {
139  uint8_t data[BLE_TCS_NFC_LEN_MAX];
140  uint8_t len;
141 }) ble_tcs_nfc_t;
142 
143 #define TCS_MTU_REQ_EXCHANGE 0x01
144 #define TCS_MTU_REQ_MIN 0UL
145 #define TCS_MTU_REQ_MAX 1UL
146 #define TCS_MTU_SIZE_MIN 23UL
147 #define TCS_MTU_SIZE_MAX 276UL
148 
149 typedef struct
150 {
151  ble_tcs_dev_name_t dev_name;
152  ble_tcs_adv_params_t adv_params;
153  ble_tcs_conn_params_t conn_params;
154  ble_tcs_eddystone_url_t eddystone_url;
155  ble_tcs_cloud_token_t cloud_token;
156  ble_tcs_fw_version_t fw_version;
157  ble_tcs_mtu_t mtu;
158  ble_tcs_nfc_t nfc;
159 }ble_tcs_params_t;
160 
161 typedef enum
162 {
163  BLE_TCS_EVT_DEV_NAME,
164  BLE_TCS_EVT_ADV_PARAM,
165  BLE_TCS_EVT_CONN_PARAM,
166  BLE_TCS_EVT_BEACON,
167  BLE_TCS_EVT_CLOUD_TOKEN,
168  BLE_TCS_EVT_MTU,
169  BLE_TCS_EVT_NFC
170 }ble_tcs_evt_type_t;
171 
172 /* Forward declaration of the ble_tcs_t type. */
173 typedef struct ble_tcs_s ble_tcs_t;
174 
176 typedef void (*ble_tcs_evt_handler_t) (ble_tcs_t * p_tcs,
177  ble_tcs_evt_type_t evt_type,
178  uint8_t * p_data,
179  uint16_t length);
180 
186 typedef struct
187 {
188  ble_tcs_params_t * p_init_vals;
191 
196 struct ble_tcs_s
197 {
198  uint8_t uuid_type;
199  uint16_t service_handle;
200  ble_gatts_char_handles_t dev_name_handles;
201  ble_gatts_char_handles_t adv_param_handles;
202  ble_gatts_char_handles_t conn_param_handles;
203  ble_gatts_char_handles_t beacon_handles;
204  ble_gatts_char_handles_t cloud_handles;
205  ble_gatts_char_handles_t fwv_handles;
206  ble_gatts_char_handles_t mtu_handles;
207  ble_gatts_char_handles_t nfc_handles;
208  uint16_t conn_handle;
210 };
211 
222 uint32_t ble_tcs_init(ble_tcs_t * p_tcs, const ble_tcs_init_t * p_tcs_init);
223 
234 void ble_tcs_on_ble_evt(ble_tcs_t * p_tcs, ble_evt_t * p_ble_evt);
235 
245 uint32_t ble_tcs_mtu_set(ble_tcs_t * p_tcs, ble_tcs_mtu_t * p_data);
246 
256 uint32_t ble_tcs_nfc_set(ble_tcs_t * p_tcs, ble_tcs_nfc_t * p_data);
257 
258 #endif // BLE_TCS_H__
259 
ble_gatts_char_handles_t dev_name_handles
Definition: ble_tcs.h:200
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_evt_handler_t evt_handler
Definition: ble_tcs.h:189
uint16_t service_handle
Definition: ble_tcs.h:199
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_gatts_char_handles_t conn_param_handles
Definition: ble_tcs.h:202
uint32_t ble_tcs_nfc_set(ble_tcs_t *p_tcs, ble_tcs_nfc_t *p_data)
Function for setting the NFC char data.
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:176
uint16_t conn_handle
Definition: ble_tcs.h:208
uint8_t uuid_type
Definition: ble_tcs.h:198
ble_tcs_evt_handler_t evt_handler
Definition: ble_tcs.h:209
Thingy Configuration Service initialization structure.
Definition: ble_tcs.h:186
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_gatts_char_handles_t adv_param_handles
Definition: ble_tcs.h:201
Thingy Configuration Service structure.
Definition: ble_tcs.h:196