• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  *****************************************************************************************
3  *
4  * @file escs.h
5  *
6  * @brief Eddystone Configuration Service API
7  *
8  *****************************************************************************************
9  * @attention
10   #####Copyright (c) 2019 GOODIX
11   All rights reserved.
12 
13     Redistribution and use in source and binary forms, with or without
14     modification, are permitted provided that the following conditions are met:
15   * Redistributions of source code must retain the above copyright
16     notice, this list of conditions and the following disclaimer.
17   * Redistributions in binary form must reproduce the above copyright
18     notice, this list of conditions and the following disclaimer in the
19     documentation and/or other materials provided with the distribution.
20   * Neither the name of GOODIX nor the names of its contributors may be used
21     to endorse or promote products derived from this software without
22     specific prior written permission.
23 
24   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34   POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************************
36  */
37 /**
38 * @addtogroup BLE_SRV BLE Services
39 * @{
40 * @brief Definitions and prototypes for the BLE Service interface.
41 */
42 /**
43  * @defgroup BLE_SDK_ESCS BLE Eddystone Configuration Service (ESCS)
44  * @{
45  * @brief Eddystone Configuration Service module.
46  */
47 #ifndef _ESCS_H_
48 #define _ESCS_H_
49 #include <stdbool.h>
50 #include <stdint.h>
51 #include "es_app_config.h"
52 #include "es.h"
53 #include "ble_prf_types.h"
54 #include "ble_sdk_error.h"
55 #include "es_utility.h"
56 #include "es_nvds.h"
57 #include "es_gatts_read_write.h"
58 
59 /**
60  * @defgroup ESCS_ENUM Enumerations
61  * @{
62  */
63 /** @brief ESCS Service Attributes Indexes. */
64 enum escs_attr_idx_t {
65     ESEC_IDX_SVC,
66     ESCS_BROADCAST_CAP_RD_CHAR,
67     ESCS_BROADCAST_CAP_RD_VALUE,
68     ESCS_ACTIVE_SLOT_RW_CHAR,
69     ESCS_ACTIVE_SLOT_RW_VALUE,
70     ESCS_ADV_INTERVAL_RW_CHAR,
71     ESCS_ADV_INTERVAL_RW_VALUE,
72     ESCS_RADIO_TX_PWR_RW_CHAR,
73     ESCS_RADIO_TX_PWR_RW_VALUE,
74     ESCS_ADV_TX_PWR_RW_CHAR,
75     ESCS_ADV_TX_PWR_RW_VALUE,
76     ESCS_LOCK_STATE_RW_CHAR,
77     ESCS_LOCK_STATE_RW_VALUE,
78     ESCS_UNLOCK_RW_CHAR,
79     ESCS_UNLOCK_RW_VALUE,
80     ESCS_PUBLIC_ECDH_KEY_RD_CHAR,
81     ESCS_PUBLIC_ECDH_KEY_RD_VALUE,
82     ESCS_EID_ID_KEY_RD_CHAR,
83     ESCS_EID_ID_KEY_RD_VALUE,
84     ESCS_RW_ADV_SLOT_RW_CHAR,
85     ESCS_RW_ADV_SLOT_RW_VALUE,
86     ESCS_FACTORY_RESET_SET_CHAR,
87     ESCS_FACTORY_RESET_SET_VALUE,
88     ESCS_REMAIN_CONNECTABLE_RW_CHAR,
89     ESCS_REMAIN_CONNECTABLE_RW_VALUE,
90     ESCSS_IDX_NB,
91 };
92 /** @} */
93 
94 /**
95  * @defgroup ESCS_STRUCT Structures
96  * @{
97  */
98 /** @} */
99 /**@brief Structure for storing a slot key. */
100 typedef struct {
101     uint8_t security_key[ESCS_LOCK_CODE_WRITE_LENGTH];                  /**< security key.*/
102     uint8_t k_scaler;                                                   /**< K rotation scaler.*/
103 } slot_lock_code_t;
104 
105 /**@brief Structure for storing EID slot key. */
106 typedef struct {
107     uint8_t pub_ecdh_key[ESCS_ECDH_KEY_SIZE];   /**< public ecdh key.*/
108     uint8_t k_scaler;                           /**< K rotation scaler.*/
109 } escs_eid_t;
110 
111 /**@brief EddyStone Configuration Service environment variable. */
112 typedef struct {
113     uint8_t          active_slot_no;                    /**< curret active slot number.*/
114     uint8_t          lock_state;                        /**< beacon lock state.*/
115     uint16_t         adv_interval;                      /**< advertising interval.*/
116     int8_t           slot_tx_power[APP_MAX_ADV_SLOTS];  /**< radio tx power.*/
117     int8_t           adv_tx_power;                      /**< advertised tx Power.*/
118     bool             remain_connectable;                /**< whether to remain connectable.*/
119     slot_lock_code_t beacon_lock_code;                  /**< beacon lock code.*/
120 #if(APP_IS_EID_SUPPORTED)
121     escs_eid_t       eid_slot_data[APP_MAX_ADV_SLOTS];
122 #endif // APP_IS_EID_SUPPORTED
123 } ble_escs_init_params_t;
124 
125 /**
126  * @defgroup ESCE_FUNCTION Functions
127  * @{
128  */
129 /**
130  *****************************************************************************************
131  * @brief  get eddystone remain connectable state
132  *
133  * @retval true beacon connectable function is on.
134  * @retval false beacon connectable function is off.
135  *
136  *****************************************************************************************
137  */
138 bool es_adv_remain_connectable_get(void);
139 
140 /**
141  *****************************************************************************************
142  * @brief set eddystone remain connectable state
143  *
144  * @param[in] remain_connectable: turn on or off beacon connectable function.
145  *
146  *****************************************************************************************
147  */
148 void es_adv_remain_connectable_set(bool remain_connectable);
149 
150 /**
151  *****************************************************************************************
152  * @brief get public ecdh key
153  *
154  * @param[out] p_ecdh_key_buf: pointer to key buffer.
155  *
156  *****************************************************************************************
157  */
158 void es_public_ecdh_key_get (uint8_t* p_ecdh_key_buf);
159 
160 /**
161  *****************************************************************************************
162  * @brief set public ecdh key
163  *
164  * @param[in] p_ecdh_key_buf: pointer of key buffer to set.
165  *
166  *****************************************************************************************
167  */
168 void es_public_ecdh_key_set (uint8_t* p_ecdh_key_buf);
169 
170 /**
171  *****************************************************************************************
172  * @brief set security key for slot
173  *
174  * @param[in] p_security_key: pointer to setting key data.
175  * @param[in] is_eid_write:   true if the key for EID slot.
176  *
177  *****************************************************************************************
178  */
179 void es_security_key_set(uint8_t* p_security_key, bool is_eid_write);
180 
181 /**
182  *****************************************************************************************
183  * @brief to konw if a beacon has EID slot
184  *
185  * @return      true if has EID slot.
186  *
187  *****************************************************************************************
188  */
189 bool es_beacon_has_eid_adv(void);
190 
191 /**
192  *****************************************************************************************
193  * @brief set number of the actived slot
194  *
195  * @param[in]   slot_no: the number to be set to actived slot.
196  *
197  *****************************************************************************************
198  */
199 void es_active_slot_number_set (uint8_t slot_no);
200 
201 /**
202  *****************************************************************************************
203  * @brief get number of the actived slot
204  *
205  * @return      slot number of the actived slot.
206  *
207  *****************************************************************************************
208  */
209 uint8_t es_active_slot_number_get (void);
210 
211 /**
212  *****************************************************************************************
213  * @brief to know if the actived slot is a n EID slot
214  *
215  *****************************************************************************************
216  */
217 bool is_active_slot_eid(void);
218 
219 /**
220  *****************************************************************************************
221  * @brief lock a beacon
222  *
223  *****************************************************************************************
224  */
225 void set_beacon_locked(void);
226 
227 /**
228  *****************************************************************************************
229  * @brief unlock a beacon
230  *
231  *****************************************************************************************
232  */
233 void set_beacon_unlocked(void);
234 
235 /**
236  *****************************************************************************************
237  * @brief get the radio tx power
238  *
239  * @return      tx power(dBm).
240  *
241  *****************************************************************************************
242  */
243 int8_t es_adv_tx_power_get(void);
244 
245 /**
246  *****************************************************************************************
247  * @brief set the radio tx power
248  *
249  * @param[in]   adv_tx_power: tx power(dBm) to set.
250  *
251  *****************************************************************************************
252  */
253 void es_adv_tx_power_set(int8_t adv_tx_power);
254 
255 /**
256  *****************************************************************************************
257  * @brief get advertised tx power of a slot
258  *
259  * @return      advertised tx power(dBm).
260  *
261  *****************************************************************************************
262  */
263 int8_t es_slot_tx_power_get(void);
264 
265 /**
266  *****************************************************************************************
267  * @brief set advertised tx power of a slot
268  *
269  * @param[in]   tx_power: advertised tx power(dBm).
270  *
271  *****************************************************************************************
272  */
273 void es_slot_tx_power_set(int8_t tx_power);
274 
275 /**
276  *****************************************************************************************
277  * @brief get advertising interval for slot
278  *
279  * @return     advertising interval(mS).
280  *
281  *****************************************************************************************
282  */
283 uint16_t es_adv_interval_get(void);
284 
285 /**
286  *****************************************************************************************
287  * @brief set advertising interval for slot
288  *
289  * @param[in]   adv_interval: advertising interval(mS).
290  *
291  *****************************************************************************************
292  */
293 void es_adv_interval_set (uint16_t adv_interval);
294 
295 /**
296  *****************************************************************************************
297  * @brief Initialize Eddystone Configuration Service,and data for the service.
298  *
299  * @param[in] p_escs_init:  pointer to a initializing data structure.
300  *
301  *****************************************************************************************
302  */
303 sdk_err_t esec_service_init(ble_escs_init_params_t *p_escs_init);
304 /** @} */
305 
306 #endif
307 /** @} */
308 /** @} */
309