gatt_client.c (c839c6f943a092feb48f0fe1470f7b8a1cc49f3b) gatt_client.c (b3f03c843f6a029757848cf4db52890477de181b)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 477 unchanged lines hidden (view full) ---

486 if (!callback) return;
487 hci_dump_packet(HCI_EVENT_PACKET, 0, packet, size);
488 (*callback)(HCI_EVENT_PACKET, 0, packet, size);
489}
490
491void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){
492 notification->callback = packet_handler;
493 notification->con_handle = con_handle;
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 477 unchanged lines hidden (view full) ---

486 if (!callback) return;
487 hci_dump_packet(HCI_EVENT_PACKET, 0, packet, size);
488 (*callback)(HCI_EVENT_PACKET, 0, packet, size);
489}
490
491void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){
492 notification->callback = packet_handler;
493 notification->con_handle = con_handle;
494 notification->attribute_handle = characteristic->value_handle;
494 if (characteristic == NULL){
495 notification->attribute_handle = GATT_CLIENT_ANY_VALUE_HANDLE;
496 } else {
497 notification->attribute_handle = characteristic->value_handle;
498 }
495 btstack_linked_list_add(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
496}
497
498void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification){
499 btstack_linked_list_remove(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
500}
501
502static void emit_event_to_registered_listeners(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t * packet, uint16_t size){
503 btstack_linked_list_iterator_t it;
504 btstack_linked_list_iterator_init(&it, &gatt_client_value_listeners);
505 while (btstack_linked_list_iterator_has_next(&it)){
506 gatt_client_notification_t * notification = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it);
499 btstack_linked_list_add(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
500}
501
502void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification){
503 btstack_linked_list_remove(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
504}
505
506static void emit_event_to_registered_listeners(hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t * packet, uint16_t size){
507 btstack_linked_list_iterator_t it;
508 btstack_linked_list_iterator_init(&it, &gatt_client_value_listeners);
509 while (btstack_linked_list_iterator_has_next(&it)){
510 gatt_client_notification_t * notification = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it);
507 if (notification->con_handle != con_handle) continue;
508 if (notification->attribute_handle != attribute_handle) continue;
511 if ((notification->con_handle != GATT_CLIENT_ANY_CONNECTION) && (notification->con_handle != con_handle)) continue;
512 if ((notification->attribute_handle != GATT_CLIENT_ANY_VALUE_HANDLE) && (notification->attribute_handle != attribute_handle)) continue;
509 (*notification->callback)(HCI_EVENT_PACKET, 0, packet, size);
510 }
511}
512
513static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t att_status){
514 // @format H1
515 uint8_t packet[5];
516 packet[0] = GATT_EVENT_QUERY_COMPLETE;

--- 1619 unchanged lines hidden ---
513 (*notification->callback)(HCI_EVENT_PACKET, 0, packet, size);
514 }
515}
516
517static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t att_status){
518 // @format H1
519 uint8_t packet[5];
520 packet[0] = GATT_EVENT_QUERY_COMPLETE;

--- 1619 unchanged lines hidden ---