genericAccess.c
5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
Copyright by Optek in 2015
*/
#include "c_def.h"
#include "debug.h"
#include "include/bt_def.h"
#include "include/bluetooth.h"
#include "include/hci.h"
#include "include/hci_core.h"
#include "include/l2cap.h"
#include "../bluez/uuid.h"
//#include "../blueZ/bluetooth.h"
//#include "../blueZ/sdp_lib.h"
#include "include/list.h"
#include "malloc.h"
#include "include/g_slist.h"
#include "../attrib/att.h"
#include "../attrib/gattrib.h"
#include "../attrib/gatt.h"
#include "../attrib/gatt_profile_uuid.h"
#include "../attrib/gatt-service.h"
/*********************************************************************
* Profile Attributes - Table
*/
static const bt_uuid_t genaralAccessService = { ATT_BT_UUID_SIZE, GENERAL_ACCESS_SERV_UUID };
static const uint8_t generalDevName[16] = {" OPTEK BLE TEST1\0"};
static const uint16_t generalAccessAppearance = 0x0000;
#define DEFAULT_MIN_CONN_INTERVAL 0x0006 // 100 milliseconds
#define DEFAULT_MAX_CONN_INTERVAL 0x0C80 // 4 seconds
#define MIN_CONN_INTERVAL 0x0006
#define MAX_CONN_INTERVAL 0x0C80
#define MIN_SLAVE_LATENCY 0
#define MAX_SLAVE_LATENCY 500
#define MIN_TIMEOUT_MULTIPLIER 0x000a
#define MAX_TIMEOUT_MULTIPLIER 0x0c80
// 0B 50 00 A0 00 00 00 E8 03 read from ti demo
static const uint16_t generalAccessConnParms[4] = {0x0050, 0x00A0, 0x0000, 0x03E8};
static gattAttribute_t generalAccessTbl[] =
{
// General Access Service
{
//{ ATT_BT_UUID_SIZE, GATT_PRIM_SVC_UUID }, /* type */
&gattPrimSvc,
GATT_PROP_READ, /* permissions */
0, /* handle */
(uint8_t *)&genaralAccessService /* pValue */
},
// Characteristic Declaration Device Name
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_UUID },
&gattCharac,
GATT_PROP_READ,
0,
(uint8_t *)&gattReadProps
},
// Characteristic Value- Device Name
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_DEVICE_NAME },
&gattCharacDevName,
GATT_PROP_READ,
0,
generalDevName
},
// Characteristic Declaration Appearance
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_UUID },
&gattCharac,
GATT_PROP_READ,
0,
(uint8_t *)&gattReadProps
},
// Characteristic Value- Appearance
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_APPEARANCE },
&gattCharacAppearance,
GATT_PROP_READ,
0,
(uint8_t *) &generalAccessAppearance
},
// Characteristic Declaration Connection Parms
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_UUID },
&gattCharac,
GATT_PROP_READ,
0,
(uint8_t *)&gattReadProps
},
// Characteristic Value- Connection Parms
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_PERIPHERAL_PREF_CONN },
&gattCharacPeriPrefConn,
GATT_PROP_READ,
0,
(uint8_t *) &generalAccessConnParms[0]
},
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static uint8_t geneticAcessReadAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t *pLen, uint16_t offset, uint8_t maxLen );
static bStatus_t geneticAcessWriteAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t len, uint16_t offset );
/*********************************************************************
* PROFILE CALLBACKS
*/
// Battery Service Callbacks
const gattServiceCBs_t geneticAcessCBs =
{
NULL,
NULL,
geneticAcessReadAttrCB, // Read callback function pointer
geneticAcessWriteAttrCB, // Write callback function pointer
NULL // Authorization callback function pointer
};
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn Batt_AddService
*
* @brief Initializes the Battery Service by registering
* GATT attributes with the GATT server.
*
* @return Success or Failure
*/
bStatus_t geneticAcess_AddService( void )
{
uint8_t status;
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService( generalAccessTbl,
GATT_NUM_ATTRS( generalAccessTbl ),
&geneticAcessCBs );
return ( status );
}
static uint8_t geneticAcessReadAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t *pLen, uint16_t offset, uint8_t maxLen )
{
bStatus_t status = SUCCESS;
// Make sure it's not a blob operation (no attributes in the profile are long)
if ( offset > 0 )
{
return ( ATT_ERR_ATTR_NOT_LONG );
}
uint16_t uuid = pAttr->pType->value.u16_val;
if ( uuid == GATT_CHARAC_DEVICE_NAME )
{
*pLen = sizeof(generalDevName);
CFasm_memcpy( pValue, pAttr->pValue, sizeof(generalDevName) );
}
else if ( uuid == GATT_CHARAC_APPEARANCE )
{
*pLen = sizeof(generalAccessAppearance);
CFasm_memcpy( pValue, pAttr->pValue, sizeof(generalAccessAppearance) );
}
else if ( uuid == GATT_CHARAC_PERIPHERAL_PREF_CONN )
{
*pLen = sizeof(generalAccessConnParms);
CFasm_memcpy( pValue, pAttr->pValue, sizeof(generalAccessConnParms) );
}
else
{
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
}
return ( status );
}
static bStatus_t geneticAcessWriteAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t len, uint16_t offset )
{
DBG_Assert(FALSE);
return SUCCESS;
}