genericAttr.c
4.11 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
/*
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 genaralAttrService = { ATT_BT_UUID_SIZE, GENERAL_ATTR_SERV_UUID };
static const uint16_t generalAccessServiceChange[2] = {0x0001, 0xFFFF};
static gattCharCfg_t generalAttrClientCharCfg[GATT_MAX_NUM_CONN];
static gattAttribute_t generalAttrTbl[] =
{
// General Attribute Service
{
//{ ATT_BT_UUID_SIZE, GATT_PRIM_SVC_UUID }, /* type */
&gattPrimSvc,
GATT_PROP_READ, /* permissions */
0, /* handle */
(uint8_t *)&genaralAttrService /* pValue */
},
// Characteristic Declaration Device Name
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_UUID },
&gattCharac,
GATT_PROP_READ,
0,
(uint8_t *)&gattNotifyProps
},
// Characteristic Value- Device Name
{
//{ ATT_BT_UUID_SIZE, GATT_CHARAC_SERVICE_CHANGED },
&gattCharacServiceChanged,
0,
0,
(uint8_t *) &generalAccessServiceChange[0]
},
// General Attr Client Characteristic Configuration
{
//{ ATT_BT_UUID_SIZE, GATT_CLIENT_CHARAC_CFG_UUID },
&gattClientCharacCFG,
GATT_PROP_READ | GATT_PROP_WRITE,
0,
(uint8_t *) &generalAttrClientCharCfg
},
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static uint8_t genericAttrReadAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t *pLen, uint16_t offset, uint8_t maxLen );
static bStatus_t genericAttrWriteAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t len, uint16_t offset );
//static void battNotifyCB( linkDBItem_t *pLinkItem );
//static uint8_t battMeasure( void );
//static void battNotifyLevel( void );
/*********************************************************************
* PROFILE CALLBACKS
*/
// Battery Service Callbacks
const gattServiceCBs_t genericAttrCBs =
{
NULL,
NULL,
genericAttrReadAttrCB, // Read callback function pointer
genericAttrWriteAttrCB, // 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 genericAttr_AddService( void )
{
uint8_t status;
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE, generalAttrClientCharCfg );
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService( generalAttrTbl,
GATT_NUM_ATTRS( generalAttrTbl ),
&genericAttrCBs );
return ( status );
}
static uint8_t genericAttrReadAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t *pLen, uint16_t offset, uint8_t maxLen )
{
//asm ("break 1,1");
bStatus_t status = SUCCESS;
// Make sure it's not a blob operation (no attributes in the profile are long)
*pLen = 0;
status = ATT_ERR_READ_NOT_PERMITTED;
return ( status );
}
static bStatus_t genericAttrWriteAttrCB( GAttrib *pConn, gattAttribute_t *pAttr,
uint8_t *pValue, uint8_t len, uint16_t offset )
{
//asm ("break 1,1");
return SUCCESS;
}