@@ -34,48 +34,53 @@ static gattAttribute_t attr_table[] = {
3434
3535#define notiAttr attr_table[4]
3636
37-
3837static bStatus_t write_handler (uint16 connHandle , gattAttribute_t * pAttr ,
39- uint8 * pValue , uint16 len , uint16 offset , uint8 method )
38+ uint8 * pValue , uint16 len , uint16 offset , uint8 method )
4039{
4140 PRINT ("ble: write_handler(): connHandle: %04X\n" , connHandle );
4241
43- if (!gattPermitWrite (pAttr -> permissions )) {
42+ if (!gattPermitWrite (pAttr -> permissions ))
43+ {
4444 return ATT_ERR_WRITE_NOT_PERMITTED ;
4545 }
46-
46+
4747 uint16_t uuid = BUILD_UINT16 (pAttr -> type .uuid [0 ], pAttr -> type .uuid [1 ]);
48- if (uuid == GATT_CLIENT_CHAR_CFG_UUID ) {
48+ if (uuid == GATT_CLIENT_CHAR_CFG_UUID )
49+ {
4950 bStatus_t ret = GATTServApp_ProcessCCCWriteReq (connHandle , pAttr , pValue , len ,
50- offset , GATT_CLIENT_CFG_NOTIFY );
51+ offset , GATT_CLIENT_CFG_NOTIFY );
5152 PRINT ("ble: CCCD changed: %02X\n" , TxCCCD -> value );
5253 return ret ;
5354 }
5455
55- if (uuid == RxCharUUID ) {
56+ if (uuid == RxCharUUID )
57+ {
5658 return ng_parse (pValue , len );
5759 }
5860
5961 return ATT_ERR_ATTR_NOT_FOUND ;
6062}
6163
6264static bStatus_t read_handler (uint16_t connHandle , gattAttribute_t * pAttr ,
63- uint8_t * pValue , uint16_t * pLen , uint16_t offset ,
64- uint16_t maxLen , uint8_t method )
65+ uint8_t * pValue , uint16_t * pLen , uint16_t offset ,
66+ uint16_t maxLen , uint8_t method )
6567{
66- if (!gattPermitRead (pAttr -> permissions )) {
68+ if (!gattPermitRead (pAttr -> permissions ))
69+ {
6770 return ATT_ERR_READ_NOT_PERMITTED ;
6871 }
6972
7073 uint16_t uuid = BUILD_UINT16 (pAttr -> type .uuid [0 ], pAttr -> type .uuid [1 ]);
71- if (uuid == GATT_CLIENT_CHAR_CFG_UUID ) {
74+ if (uuid == GATT_CLIENT_CHAR_CFG_UUID )
75+ {
7276 * pLen = 2 ;
7377 tmos_memcpy (pValue , pAttr -> pValue , * pLen );
7478 return SUCCESS ;
7579 }
7680
77- if (uuid == TxCharUUID ) {
78- * pLen = MIN (TxLen - offset , maxLen );
81+ if (uuid == TxCharUUID )
82+ {
83+ * pLen = MIN (TxLen - offset , maxLen );
7984 tmos_memcpy (pValue , & pAttr -> pValue [offset ], * pLen );
8085 return SUCCESS ;
8186 }
@@ -86,23 +91,22 @@ static bStatus_t read_handler(uint16_t connHandle, gattAttribute_t *pAttr,
8691static gattServiceCBs_t service_handlers = {
8792 read_handler ,
8893 write_handler ,
89- NULL
90- };
94+ NULL };
9195
9296static void connStatus_handler (uint16 connHandle , uint8 changeType )
9397{
94- if (connHandle == LOOPBACK_CONNHANDLE )
98+ if (connHandle == LOOPBACK_CONNHANDLE )
9599 return ;
96100
97101 // Reset ClientCharConfig if connection has dropped
98- if ((changeType == LINKDB_STATUS_UPDATE_REMOVED )
99- || ((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS )
100- && (!linkDB_Up (connHandle )))) {
102+ if ((changeType == LINKDB_STATUS_UPDATE_REMOVED ) || ((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) && (!linkDB_Up (connHandle ))))
103+ {
101104 GATTServApp_InitCharCfg (connHandle , TxCCCD );
102105 }
103- if (badge_cfg .ble_always_on ) {
104- PRINT ("BLE disconnected, restarting advertising due to Always-On\n" );
105- ble_enable_advertise ();
106+ if (badge_cfg .ble_always_on )
107+ {
108+ PRINT ("BLE disconnected, restarting advertising due to Always-On\n" );
109+ ble_enable_advertise ();
106110 }
107111}
108112
@@ -113,9 +117,9 @@ int ng_registerService()
113117 linkDB_Register (connStatus_handler );
114118
115119 status = GATTServApp_RegisterService (attr_table ,
116- GATT_NUM_ATTRS (attr_table ),
117- GATT_MAX_ENCRYPT_KEY_SIZE ,
118- & service_handlers );
120+ GATT_NUM_ATTRS (attr_table ),
121+ GATT_MAX_ENCRYPT_KEY_SIZE ,
122+ & service_handlers );
119123 return (status );
120124}
121125
@@ -127,36 +131,39 @@ static uint8 isNotifyEnabled(uint16 connHandle)
127131/**
128132 * @brief Send notify to client. Currently support one client connection
129133 * only.
130- *
134+ *
131135 * @param val Value to be sent
132136 * @param len length of val. This should not be larger than MTU.
133137 * @return bStatus_t
134138 */
135139bStatus_t ng_notify (uint8_t * val , uint8_t len )
136140{
137- if (!isNotifyEnabled (TxCCCD -> connHandle )) {
141+ if (!isNotifyEnabled (TxCCCD -> connHandle ))
142+ {
138143 PRINT ("ble: ng_notify() notify is not enabled\n" );
139144 return bleIncorrectMode ;
140145 }
141- if (len > ATT_GetMTU (TxCCCD -> connHandle )) {
146+ if (len > ATT_GetMTU (TxCCCD -> connHandle ))
147+ {
142148 return bleInvalidRange ;
143149 }
144150
145151 attHandleValueNoti_t noti = {
146152 .handle = notiAttr .handle ,
147- .len = len
148- };
153+ .len = len };
149154 noti .pValue = GATT_bm_alloc (TxCCCD -> connHandle , ATT_HANDLE_VALUE_NOTI ,
150- len , NULL , 0 );
151- if (noti .pValue == NULL ) {
155+ len , NULL , 0 );
156+ if (noti .pValue == NULL )
157+ {
152158 return bleMemAllocError ;
153159 }
154160
155161 tmos_memcpy (noti .pValue , val , len );
156162
157163 bStatus_t ret = GATT_Notification (TxCCCD -> connHandle , & noti , FALSE);
158164 GATT_bm_free ((gattMsg_t * )& noti , ATT_HANDLE_VALUE_NOTI );
159- if (ret != SUCCESS ) {
165+ if (ret != SUCCESS )
166+ {
160167 PRINT ("ble: noti sending failed\n" );
161168 return ret ;
162169 }
0 commit comments