@@ -128,8 +128,6 @@ uint8_t profile_notify_process (bt_conn_t *conn,
128128 bt_gatt_subscribe_params_t *params,
129129 const void *data, uint16_t length)
130130{
131- // BLEPeripheralHelper* peripheral = BLECentralRole::instance()->peripheral(conn);// Find peripheral by bt_conn
132- // BLEAttribute* notifyatt = peripheral->attribute(params); // Find attribute by params
133131 BLECharacteristicImp* chrc = NULL ;
134132 BLEDevice bleDevice (bt_conn_get_dst (conn));
135133 chrc = BLEProfileManager::instance ()->characteristic (bleDevice, params->value_handle );
@@ -151,7 +149,6 @@ uint8_t profile_discover_process(bt_conn_t *conn,
151149 uint8_t ret = BT_GATT_ITER_STOP;
152150 pr_debug (LOG_MODULE_BLE, " %s-%d" , __FUNCTION__, __LINE__);
153151 ret = BLEProfileManager::instance ()->discoverResponseProc (conn, attr, params);
154- pr_debug (LOG_MODULE_BLE, " %s-%d" , __FUNCTION__, __LINE__);
155152 return ret;
156153}
157154
@@ -242,69 +239,13 @@ void bleConnectEventHandler(bt_conn_t *conn,
242239 p->handleConnectEvent (conn, err);
243240}
244241
245- static uint8_t ble_gatt_disconnected_cb (const struct bt_gatt_attr *attr, void *user_data)
246- {
247- struct bt_conn *conn = (struct bt_conn *)user_data;
248- struct _bt_gatt_ccc *ccc;
249- size_t i;
250-
251- /* Check attribute user_data must be of type struct _bt_gatt_ccc */
252- if (attr->write != profile_gatt_attr_write_ccc) {
253- return BT_GATT_ITER_CONTINUE;
254- }
255-
256- ccc = (struct _bt_gatt_ccc *)attr->user_data ;
257- /* If already disabled skip */
258- if (!ccc->value ) {
259- return BT_GATT_ITER_CONTINUE;
260- }
261-
262- for (i = 0 ; i < ccc->cfg_len ; i++)
263- {
264- /* Ignore configurations with disabled value */
265- if (!ccc->cfg [i].value )
266- {
267- continue ;
268- }
269-
270- if (bt_addr_le_cmp (&conn->le .dst , &ccc->cfg [i].peer ))
271- {
272- struct bt_conn *tmp;
273-
274- /* Skip if there is another peer connected */
275- tmp = bt_conn_lookup_addr_le (&ccc->cfg [i].peer );
276- if (tmp) {
277- if (tmp->state == BT_CONN_CONNECTED) {
278- bt_conn_unref (tmp);
279- return BT_GATT_ITER_CONTINUE;
280- }
281-
282- bt_conn_unref (tmp);
283- }
284- }
285- }
286-
287- /* Reset value while disconnected */
288- memset (&ccc->value , 0 , sizeof (ccc->value ));
289-
290- if (ccc->cfg_changed ) {
291- ccc->cfg_changed (ccc->value );
292- }
293-
294- pr_debug (LOG_MODULE_BLE, " ccc %p reseted" , ccc);
295-
296- return BT_GATT_ITER_CONTINUE;
297- }
298-
299-
300242void bleDisconnectEventHandler (bt_conn_t *conn,
301243 uint8_t reason,
302244 void *param)
303245{
304246 BLEDeviceManager* p = (BLEDeviceManager*)param;
305247
306248 pr_info (LOG_MODULE_BLE, " Connect lost. Reason: %d" , reason);
307- bt_gatt_foreach_attr (0x0001 , 0xffff , ble_gatt_disconnected_cb, conn);
308249
309250 p->handleDisconnectEvent (conn, reason);
310251}
@@ -343,29 +284,14 @@ void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
343284 BLECharacteristicImp::writeResponseReceived (conn, err, data);
344285}
345286
346- ssize_t profile_gatt_attr_write_ccc (struct bt_conn *conn,
347- const struct bt_gatt_attr *attr,
348- const void *buf,
349- uint16_t len,
350- uint16_t offset)
287+ void prfile_cccd_cfg_changed (void *user_data, uint16_t value)
351288{
352- struct _bt_gatt_ccc *ccc = (struct _bt_gatt_ccc *)attr->user_data ;
353- const uint16_t *data = (const uint16_t *)buf;
354- bool cccdChanged = (ccc->value != *data);
355- ssize_t retValue = bt_gatt_attr_write_ccc (conn, attr, buf, len, offset);
356- if (cccdChanged)
357- {
358- // Find characteristic and do notification
359- const struct bt_gatt_attr *attrChrc = attr - 1 ;
360- BLEAttribute *bleattr = (BLEAttribute *)attrChrc->user_data ;
361- BLEAttributeType type = bleattr->type ();
362- pr_debug (LOG_MODULE_BLE, " The Attribute type:%d" , type);
363- if (BLETypeCharacteristic == type)
364- {
365- BLECharacteristicImp *blecharacteritic = (BLECharacteristicImp*)bleattr;
366- blecharacteritic->cccdValueChanged ();
367- }
368- }
369- return retValue;
289+ if (NULL == user_data)
290+ return ;
291+ pr_debug (LOG_MODULE_BLE, " %s-%d: ccc userdata %p" , __FUNCTION__, __LINE__, user_data);
292+
293+ BLECharacteristicImp *blecharacteritic = (BLECharacteristicImp *)user_data;
294+ blecharacteritic->cccdValueChanged ();
370295}
371296
297+
0 commit comments