EVE 1.0
ble.h
Go to the documentation of this file.
1 #ifndef EVE_BLE_H_INCLUDED
2 #define EVE_BLE_H_INCLUDED
3 
4 /**********************************************************************/
5 /* Copyright (c) 2016 Jetro AS.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33  /**
34  * \file
35  * \brief Header file for BLE subsystem interface.
36  *
37  * \author DT, Jetro AS
38  */ /******************************************************************/
39 
40 #include <stdbool.h>
41 #include <core/work.h>
42 #include <sys/process.h>
43 #include <sys/event-base.h>
44 #include <lib/assert.h>
45 #include <ble_types.h>
46 #include <ble_advdata.h>
47 #ifndef __cplusplus
48  /* XXX: nrf_svc.h:57:6: error: impossible constraint in 'asm' ... */
49  #include <ble.h>
50 #endif
51 
52 /**
53  * \addtogroup ble
54  * @{
55  */
56 
57 /* TODO: Replace by open interface */
58 
59 #define BLE_DEVICE_MANAGER_FLASH_RESERVED (10 * 0x1000)
60 
61 /** Number of entries in the internal bond database */
62 #define BLE_BOND_DB_SIZE (0x08)
63 
64 /** Return code, indicates that a current connection is not with a bonded device */
65 #define BLE_NO_BOND (0xFF)
66 
67 /**
68  * EVE service manager init structure.
69  *
70  * \note The structure is reserved for future use.
71  */
72 typedef struct {
73  ble_uuid128_t uuid128; /**< UUID */
74  bool multiservice; /**< TOC defines more than one service */
75  bool omit_structures; /**< Do not include structures to services */
76  bool m2m; /**< Machine-to-machine interface */
78 
79 extern bool eve_svc_push(uint8_t toc_id);
80 extern bool eve_svc_pull(uint8_t toc_id);
81 #ifndef __cplusplus
82  extern void eve_dm_sys_event_handler(uint32_t evt);
83  extern void eve_connection_on_ble_evt(const ble_evt_t *p_ble_evt);
84  extern void eve_svc_on_ble_evt(const ble_evt_t *p_ble_evt);
85  extern bool eve_disc_on_ble_evt(const ble_evt_t *p_ble_evt);
86 #endif
87 
88 /**
89  * Function for initializing the EVE service manager.
90  *
91  * \param[in] eve_svc_init Information needed to initialize the service.
92  *
93  * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
94  */
96 
97 /**
98  * Set an out-of-band key to be used for the connection.
99  */
100 void BleSetOobAuthKey(const ble_advdata_tk_value_t *AuthKey);
101 
102 /**
103  * Get index of the current connection in an internal bond database
104  *
105  * \return index in the internal bond database in range of [0...BLE_BOND_DB_SIZE)
106  or BLE_NO_BOND if the connected device does not have a bond.
107  */
108 uint8_t BleGetBondId(void);
109 
110 /**
111  * Delete a record from an internal bond database
112  *
113  * \param[in] BondId Index of the record in the database
114  */
115 void BleDeleteBond(uint8_t BondId);
116 
117 /**
118  * Delete all records from an internal bond database
119  */
120 void BleDeleteAllBonds(void);
121 
122 /**
123  * Synchronously wait for completion of pending flash write operations
124  */
125 void BleWaitForFlashOpCompletion(void);
126 
127 #define BLE_AUTO_LOCK() SWINT_AUTO_LOCK()
128 
129 #define BLE_PULL(Id) { \
130  BLE_AUTO_LOCK(); \
131  eve_svc_pull(Id); \
132 }
133 
134 #define BLE_PUSH(Id) { \
135  BLE_AUTO_LOCK(); \
136  eve_svc_push(Id); \
137 }
138 
139 #define BLE_SYNC(pt, evt, data) \
140  do { \
141  BLE_PULL(0xFF); \
142  do { \
143  PT_YIELD(pt); \
144  if (evt == EVENT_BLE_SYNCED) \
145  break; \
146  if (evt == EVENT_BLE_INITIALIZED \
147  || evt == EVENT_BLE_ERROR) \
148  goto BleReset_Handler; \
149  process_post(PROCESS_CURRENT(), evt, data); \
150  } while (1); \
151  } while (0)
152 
153 enum
154 {
155  EVENT_BLE_SYNCED = EVENT_BASE_BLE_START,
156 
157  EVENT_BLE__LAST,
158 };
159 CTASSERT(EVENT_BLE__LAST <= EVENT_BASE_BLE_END + 1);
160 
161 PROCESS_NAME(BleProcess);
162 
163 /** @} */ /* ble */
164 
165 #endif
uint8_t BleGetBondId(void)
Header file for BLE subsystem interface.
uint32_t eve_svc_init(const eve_svc_init_t *eve_svc_init)
bool omit_structures
Definition: ble.h:75
void BleDeleteAllBonds(void)
bool multiservice
Definition: ble.h:74
Header file for the EVE work scheduling.
void BleDeleteBond(uint8_t BondId)
#define PROCESS_NAME(name)
Definition: process.h:295
void BleWaitForFlashOpCompletion(void)
bool m2m
Definition: ble.h:76
void BleSetOobAuthKey(const ble_advdata_tk_value_t *AuthKey)
ble_uuid128_t uuid128
Definition: ble.h:73