-
Notifications
You must be signed in to change notification settings - Fork 2
/
sink_gatt.c
189 lines (152 loc) · 4.98 KB
/
sink_gatt.c
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
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005 - 2015.
FILE NAME
sink_gatt.c
DESCRIPTION
Contains GATT functionality.
*/
#include "sink_gatt.h"
#include "sink_development.h"
#include "sink_gatt_client.h"
#include "sink_gatt_device.h"
#include "sink_gatt_server_gap.h"
#include "sink_debug.h"
#include "sink_private.h"
#include "sink_ble_advertising.h"
#include <gatt.h>
#include <connection_no_ble.h>
#include <csrtypes.h>
#ifdef GATT_ENABLED
#ifdef DEBUG_GATT
#define GATT_INFO(x) DEBUG(x)
#define GATT_ERROR(x) DEBUG(x) TOLERATED_ERROR(x)
#else
#define GATT_INFO(x)
#define GATT_ERROR(x)
#endif
/*******************************************************************************
NAME
handleGattConnectInd
DESCRIPTION
Handle when GATT_CONNECT_IND message was received
PARAMETERS
ind Pointer to a GATT_CONNECT_IND message
*/
static void handleGattConnectInd(const GATT_CONNECT_IND_T * ind)
{
GATT_INFO(("GATT_CONNECT_IND - Rejected\n"));
/* Reject GATT connection over BR/EDR */
GattConnectResponse(&BLE.task, ind->cid, ind->flags, FALSE);
}
/*******************************************************************************
NAME
handleGattConnectCfm
DESCRIPTION
Handle when GATT_CONNECT_CFM message was received
PARAMETERS
cfm Pointer to a GATT_CONNECT_CFM_T message
*/
static void handleGattConnectCfm(const GATT_CONNECT_CFM_T * cfm)
{
GATT_INFO(("GATT_CONNECT_CFM - Ignored\n"));
}
/*******************************************************************************
NAME
handleGattExchangeMtuInd
DESCRIPTION
Handle when GATT_EXCHANGE_MTU_IND message was received
PARAMETERS
ind Pointer to a GATT_EXCHANGE_MTU_IND message
RETURNS
TRUE if the message was handled, FALSE otherwise
*/
static void handleGattExchangeMtuInd(const GATT_EXCHANGE_MTU_IND_T * ind)
{
GATT_INFO(("GATT_EXCHANGE_MTU_IND\n"));
if (ind)
{
GattExchangeMtuResponse(ind->cid, SINK_GATT_MTU_MIN);
}
}
/*******************************************************************************
handleGattExchangeMtuCfm
DESCRIPTION
Handle when GATT_EXCHANGE_MTU_CFM message was received
PARAMETERS
cfm Pointer to a GATT_EXCHANGE_MTU_CFM message
*/
static void handleGattExchangeMtuCfm(const GATT_EXCHANGE_MTU_CFM_T * cfm)
{
GATT_INFO(("GATT_EXCHANGE_MTU_CFM\n"));
if (cfm)
{
gatt_client_connection_t *connection = gattClientFindByCid(cfm->cid);
gatt_client_services_t *data = gattClientGetServiceData(connection);
if(connection && data && data->number_discovered_services == 0)
{
/* Discover primary services on connection */
gattDiscoverPrimaryServices(connection);
/* Discovery in progress */
sinkBleGapSetDiscoveryInProgress(TRUE);
}
}
}
/*******************************************************************************
NAME
handleGattDiscoverAllPrimaryServicesCfm
DESCRIPTION
Handle when GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM message was received
PARAMETERS
cfm Pointer to a GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM message
RETURNS
void
*/
static void handleGattDiscoverAllPrimaryServicesCfm(const GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM_T * cfm)
{
GATT_INFO(("GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM\n"));
GATT_INFO((" cid[0x%x] Start[0x%x] End[0x%x] more[%u]\n",
cfm->cid,
cfm->handle,
cfm->end,
cfm->more_to_come
));
gattClientStoreDiscoveredService(cfm->cid, cfm->uuid_type, (uint32*)&cfm->uuid[0], cfm->handle, cfm->end, cfm->more_to_come);
}
/******************************************************************************/
void sinkGattMsgHandler(Task task, MessageId id, Message message)
{
switch(id)
{
case GATT_CONNECT_IND:
{
handleGattConnectInd((GATT_CONNECT_IND_T*)message);
}
break;
case GATT_CONNECT_CFM:
{
handleGattConnectCfm((GATT_CONNECT_CFM_T*)message);
}
break;
case GATT_EXCHANGE_MTU_IND:
{
handleGattExchangeMtuInd((GATT_EXCHANGE_MTU_IND_T*)message);
}
break;
case GATT_EXCHANGE_MTU_CFM:
{
handleGattExchangeMtuCfm((GATT_EXCHANGE_MTU_CFM_T*)message);
}
break;
case GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM:
{
handleGattDiscoverAllPrimaryServicesCfm((GATT_DISCOVER_ALL_PRIMARY_SERVICES_CFM_T*)message);
}
break;
default:
{
GATT_ERROR(("GATT Unhandled msg[%x]\n", id));
}
break;
}
}
#endif /* GATT_ENABLED */