gatt_client.c (7907f06931c075b55e3402fa469abbe35eebee25) gatt_client.c (5611a760af48d1ce1beea59c7908be73bd2393f1)
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

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

504 gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
505 (*subclient->callback)(HCI_EVENT_PACKET, packet, size);
506 }
507}
508
509static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t status){
510 // @format H1
511 uint8_t packet[5];
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

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

504 gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
505 (*subclient->callback)(HCI_EVENT_PACKET, packet, size);
506 }
507}
508
509static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t status){
510 // @format H1
511 uint8_t packet[5];
512 packet[0] = GATT_QUERY_COMPLETE;
512 packet[0] = GATT_EVENT_QUERY_COMPLETE;
513 packet[1] = 3;
514 bt_store_16(packet, 2, peripheral->handle);
515 packet[4] = status;
516 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
517}
518
519static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
520 // @format HX
521 uint8_t packet[24];
513 packet[1] = 3;
514 bt_store_16(packet, 2, peripheral->handle);
515 packet[4] = status;
516 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
517}
518
519static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
520 // @format HX
521 uint8_t packet[24];
522 packet[0] = GATT_SERVICE_QUERY_RESULT;
522 packet[0] = GATT_EVENT_SERVICE_QUERY_RESULT;
523 packet[1] = sizeof(packet) - 2;
524 bt_store_16(packet, 2, peripheral->handle);
525 ///
526 bt_store_16(packet, 4, start_group_handle);
527 bt_store_16(packet, 6, end_group_handle);
528 swap128(uuid128, &packet[8]);
529 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
530}
531
532static void emit_gatt_included_service_query_result_event(gatt_client_t * peripheral, uint16_t include_handle, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
533 // @format HX
534 uint8_t packet[26];
523 packet[1] = sizeof(packet) - 2;
524 bt_store_16(packet, 2, peripheral->handle);
525 ///
526 bt_store_16(packet, 4, start_group_handle);
527 bt_store_16(packet, 6, end_group_handle);
528 swap128(uuid128, &packet[8]);
529 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
530}
531
532static void emit_gatt_included_service_query_result_event(gatt_client_t * peripheral, uint16_t include_handle, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
533 // @format HX
534 uint8_t packet[26];
535 packet[0] = GATT_INCLUDED_SERVICE_QUERY_RESULT;
535 packet[0] = GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT;
536 packet[1] = sizeof(packet) - 2;
537 bt_store_16(packet, 2, peripheral->handle);
538 ///
539 bt_store_16(packet, 4, include_handle);
540 //
541 bt_store_16(packet, 6, start_group_handle);
542 bt_store_16(packet, 8, end_group_handle);
543 swap128(uuid128, &packet[10]);
544 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
545}
546
547static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripheral, uint16_t start_handle, uint16_t value_handle, uint16_t end_handle,
548 uint16_t properties, uint8_t * uuid128){
549 // @format HY
550 uint8_t packet[28];
536 packet[1] = sizeof(packet) - 2;
537 bt_store_16(packet, 2, peripheral->handle);
538 ///
539 bt_store_16(packet, 4, include_handle);
540 //
541 bt_store_16(packet, 6, start_group_handle);
542 bt_store_16(packet, 8, end_group_handle);
543 swap128(uuid128, &packet[10]);
544 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
545}
546
547static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripheral, uint16_t start_handle, uint16_t value_handle, uint16_t end_handle,
548 uint16_t properties, uint8_t * uuid128){
549 // @format HY
550 uint8_t packet[28];
551 packet[0] = GATT_CHARACTERISTIC_QUERY_RESULT;
551 packet[0] = GATT_EVENT_CHARACTERISTIC_QUERY_RESULT;
552 packet[1] = sizeof(packet) - 2;
553 bt_store_16(packet, 2, peripheral->handle);
554 ///
555 bt_store_16(packet, 4, start_handle);
556 bt_store_16(packet, 6, value_handle);
557 bt_store_16(packet, 8, end_handle);
558 bt_store_16(packet, 10, properties);
559 swap128(uuid128, &packet[12]);
560 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
561}
562
563static void emit_gatt_all_characteristic_descriptors_result_event(
564 gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t * uuid128){
565 // @format HZ
566 uint8_t packet[22];
552 packet[1] = sizeof(packet) - 2;
553 bt_store_16(packet, 2, peripheral->handle);
554 ///
555 bt_store_16(packet, 4, start_handle);
556 bt_store_16(packet, 6, value_handle);
557 bt_store_16(packet, 8, end_handle);
558 bt_store_16(packet, 10, properties);
559 swap128(uuid128, &packet[12]);
560 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
561}
562
563static void emit_gatt_all_characteristic_descriptors_result_event(
564 gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t * uuid128){
565 // @format HZ
566 uint8_t packet[22];
567 packet[0] = GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT;
567 packet[0] = GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT;
568 packet[1] = sizeof(packet) - 2;
569 bt_store_16(packet, 2, peripheral->handle);
570 ///
571 bt_store_16(packet, 4, descriptor_handle);
572 swap128(uuid128, &packet[6]);
573 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
574}
575///

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

687 log_error("HCI_INCOMING_PRE_BUFFER_SIZE >= 2 required for long characteristic reads");
688 return NULL;
689#endif
690}
691
692
693// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
694static void report_gatt_notification(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
568 packet[1] = sizeof(packet) - 2;
569 bt_store_16(packet, 2, peripheral->handle);
570 ///
571 bt_store_16(packet, 4, descriptor_handle);
572 swap128(uuid128, &packet[6]);
573 emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
574}
575///

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

687 log_error("HCI_INCOMING_PRE_BUFFER_SIZE >= 2 required for long characteristic reads");
688 return NULL;
689#endif
690}
691
692
693// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
694static void report_gatt_notification(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
695 uint8_t * packet = setup_characteristic_value_packet(GATT_NOTIFICATION, con_handle, value_handle, value, length);
695 uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_NOTIFICATION, con_handle, value_handle, value, length);
696 emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
697}
698
699// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
700static void report_gatt_indication(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
696 emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
697}
698
699// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
700static void report_gatt_indication(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
701 uint8_t * packet = setup_characteristic_value_packet(GATT_INDICATION, con_handle, value_handle, value, length);
701 uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_INDICATION, con_handle, value_handle, value, length);
702 emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
703}
704
705// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
706static void report_gatt_characteristic_value(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * value, uint16_t length){
702 emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
703}
704
705// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
706static void report_gatt_characteristic_value(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * value, uint16_t length){
707 uint8_t * packet = setup_characteristic_value_packet(GATT_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value, length);
707 uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value, length);
708 emit_event_new(peripheral->subclient_id, packet, characteristic_value_event_header_size + length);
709}
710
711// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
712static void report_gatt_long_characteristic_value_blob(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * blob, uint16_t blob_length, int value_offset){
708 emit_event_new(peripheral->subclient_id, packet, characteristic_value_event_header_size + length);
709}
710
711// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
712static void report_gatt_long_characteristic_value_blob(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * blob, uint16_t blob_length, int value_offset){
713 uint8_t * packet = setup_long_characteristic_value_packet(GATT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value_offset, blob, blob_length);
713 uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value_offset, blob, blob_length);
714 if (!packet) return;
715 emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
716}
717
718static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *value, uint16_t value_length, uint16_t value_offset){
714 if (!packet) return;
715 emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
716}
717
718static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *value, uint16_t value_length, uint16_t value_offset){
719 uint8_t * packet = setup_characteristic_value_packet(GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value, value_length);
719 uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value, value_length);
720 emit_event_new(peripheral->subclient_id, packet, value_length + 8);
721}
722
723static void report_gatt_long_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *blob, uint16_t blob_length, uint16_t value_offset){
720 emit_event_new(peripheral->subclient_id, packet, value_length + 8);
721}
722
723static void report_gatt_long_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *blob, uint16_t blob_length, uint16_t value_offset){
724 uint8_t * packet = setup_long_characteristic_value_packet(GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value_offset, blob, blob_length);
724 uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value_offset, blob, blob_length);
725 if (!packet) return;
726 emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
727}
728
729static void report_gatt_all_characteristic_descriptors(gatt_client_t * peripheral, uint8_t * packet, uint16_t size, uint16_t pair_size){
730 int i;
731 for (i = 0; i<size; i+=pair_size){
732 uint16_t descriptor_handle = READ_BT_16(packet,i);

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

1084
1085 break;
1086 }
1087 case ATT_READ_BY_GROUP_TYPE_RESPONSE:
1088 switch(peripheral->gatt_client_state){
1089 case P_W4_SERVICE_QUERY_RESULT:
1090 report_gatt_services(peripheral, packet, size);
1091 trigger_next_service_query(peripheral, get_last_result_handle_from_service_list(packet, size));
725 if (!packet) return;
726 emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
727}
728
729static void report_gatt_all_characteristic_descriptors(gatt_client_t * peripheral, uint8_t * packet, uint16_t size, uint16_t pair_size){
730 int i;
731 for (i = 0; i<size; i+=pair_size){
732 uint16_t descriptor_handle = READ_BT_16(packet,i);

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

1084
1085 break;
1086 }
1087 case ATT_READ_BY_GROUP_TYPE_RESPONSE:
1088 switch(peripheral->gatt_client_state){
1089 case P_W4_SERVICE_QUERY_RESULT:
1090 report_gatt_services(peripheral, packet, size);
1091 trigger_next_service_query(peripheral, get_last_result_handle_from_service_list(packet, size));
1092 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1092 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1093 break;
1094 default:
1095 break;
1096 }
1097 break;
1098 case ATT_HANDLE_VALUE_INDICATION:
1099 report_gatt_indication(handle, READ_BT_16(packet,1), &packet[3], size-3);
1100 peripheral->send_confirmation = 1;
1101 break;
1102
1103 case ATT_READ_BY_TYPE_RESPONSE:
1104 switch (peripheral->gatt_client_state){
1105 case P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT:
1106 report_gatt_characteristics(peripheral, packet, size);
1107 trigger_next_characteristic_query(peripheral, get_last_result_handle_from_characteristics_list(packet, size));
1093 break;
1094 default:
1095 break;
1096 }
1097 break;
1098 case ATT_HANDLE_VALUE_INDICATION:
1099 report_gatt_indication(handle, READ_BT_16(packet,1), &packet[3], size-3);
1100 peripheral->send_confirmation = 1;
1101 break;
1102
1103 case ATT_READ_BY_TYPE_RESPONSE:
1104 switch (peripheral->gatt_client_state){
1105 case P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT:
1106 report_gatt_characteristics(peripheral, packet, size);
1107 trigger_next_characteristic_query(peripheral, get_last_result_handle_from_characteristics_list(packet, size));
1108 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done, or by ATT_ERROR
1108 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done, or by ATT_ERROR
1109 break;
1110 case P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT:
1111 report_gatt_characteristics(peripheral, packet, size);
1112 trigger_next_characteristic_query(peripheral, get_last_result_handle_from_characteristics_list(packet, size));
1109 break;
1110 case P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT:
1111 report_gatt_characteristics(peripheral, packet, size);
1112 trigger_next_characteristic_query(peripheral, get_last_result_handle_from_characteristics_list(packet, size));
1113 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done, or by ATT_ERROR
1113 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done, or by ATT_ERROR
1114 break;
1115 case P_W4_INCLUDED_SERVICE_QUERY_RESULT:
1116 {
1117 uint16_t uuid16 = 0;
1118 uint16_t pair_size = packet[1];
1119
1120 if (pair_size < 7){
1121 // UUIDs not available, query first included service

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

1131 uint16_t include_handle = READ_BT_16(packet, offset);
1132 peripheral->query_start_handle = READ_BT_16(packet,offset+2);
1133 peripheral->query_end_handle = READ_BT_16(packet,offset+4);
1134 uuid16 = READ_BT_16(packet, offset+6);
1135 report_gatt_included_service_uuid16(peripheral, include_handle, uuid16);
1136 }
1137
1138 trigger_next_included_service_query(peripheral, get_last_result_handle_from_included_services_list(packet, size));
1114 break;
1115 case P_W4_INCLUDED_SERVICE_QUERY_RESULT:
1116 {
1117 uint16_t uuid16 = 0;
1118 uint16_t pair_size = packet[1];
1119
1120 if (pair_size < 7){
1121 // UUIDs not available, query first included service

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

1131 uint16_t include_handle = READ_BT_16(packet, offset);
1132 peripheral->query_start_handle = READ_BT_16(packet,offset+2);
1133 peripheral->query_end_handle = READ_BT_16(packet,offset+4);
1134 uuid16 = READ_BT_16(packet, offset+6);
1135 report_gatt_included_service_uuid16(peripheral, include_handle, uuid16);
1136 }
1137
1138 trigger_next_included_service_query(peripheral, get_last_result_handle_from_included_services_list(packet, size));
1139 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1139 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1140 break;
1141 }
1142 case P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT:
1143 peripheral->client_characteristic_configuration_handle = READ_BT_16(packet, 2);
1144 peripheral->gatt_client_state = P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION;
1145 break;
1146 case P_W4_READ_BY_TYPE_RESPONSE: {
1147 uint16_t pair_size = packet[1];

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

1161 break;
1162 case ATT_READ_RESPONSE:
1163 switch (peripheral->gatt_client_state){
1164 case P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT: {
1165 uint8_t uuid128[16];
1166 swap128(&packet[1], uuid128);
1167 report_gatt_included_service_uuid128(peripheral, peripheral->start_group_handle, uuid128);
1168 trigger_next_included_service_query(peripheral, peripheral->start_group_handle);
1140 break;
1141 }
1142 case P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT:
1143 peripheral->client_characteristic_configuration_handle = READ_BT_16(packet, 2);
1144 peripheral->gatt_client_state = P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION;
1145 break;
1146 case P_W4_READ_BY_TYPE_RESPONSE: {
1147 uint16_t pair_size = packet[1];

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

1161 break;
1162 case ATT_READ_RESPONSE:
1163 switch (peripheral->gatt_client_state){
1164 case P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT: {
1165 uint8_t uuid128[16];
1166 swap128(&packet[1], uuid128);
1167 report_gatt_included_service_uuid128(peripheral, peripheral->start_group_handle, uuid128);
1168 trigger_next_included_service_query(peripheral, peripheral->start_group_handle);
1169 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1169 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1170 break;
1171 }
1172 case P_W4_READ_CHARACTERISTIC_VALUE_RESULT:
1173 gatt_client_handle_transaction_complete(peripheral);
1174 report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1);
1175 emit_gatt_complete_event(peripheral, 0);
1176 break;
1177

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

1186 }
1187 break;
1188
1189 case ATT_FIND_BY_TYPE_VALUE_RESPONSE:
1190 {
1191 uint8_t pair_size = 4;
1192 int i;
1193 uint16_t start_group_handle;
1170 break;
1171 }
1172 case P_W4_READ_CHARACTERISTIC_VALUE_RESULT:
1173 gatt_client_handle_transaction_complete(peripheral);
1174 report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1);
1175 emit_gatt_complete_event(peripheral, 0);
1176 break;
1177

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

1186 }
1187 break;
1188
1189 case ATT_FIND_BY_TYPE_VALUE_RESPONSE:
1190 {
1191 uint8_t pair_size = 4;
1192 int i;
1193 uint16_t start_group_handle;
1194 uint16_t end_group_handle= 0xffff; // asserts GATT_QUERY_COMPLETE is emitted if no results
1194 uint16_t end_group_handle= 0xffff; // asserts GATT_EVENT_QUERY_COMPLETE is emitted if no results
1195 for (i = 1; i<size; i+=pair_size){
1196 start_group_handle = READ_BT_16(packet,i);
1197 end_group_handle = READ_BT_16(packet,i+2);
1198 emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, peripheral->uuid128);
1199 }
1200 trigger_next_service_by_uuid_query(peripheral, end_group_handle);
1195 for (i = 1; i<size; i+=pair_size){
1196 start_group_handle = READ_BT_16(packet,i);
1197 end_group_handle = READ_BT_16(packet,i+2);
1198 emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, peripheral->uuid128);
1199 }
1200 trigger_next_service_by_uuid_query(peripheral, end_group_handle);
1201 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1201 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1202 break;
1203 }
1204 case ATT_FIND_INFORMATION_REPLY:
1205 {
1206 uint8_t pair_size = 4;
1207 if (packet[1] == 2){
1208 pair_size = 18;
1209 }
1210 uint16_t last_descriptor_handle = READ_BT_16(packet, size - pair_size);
1211
1212 report_gatt_all_characteristic_descriptors(peripheral, &packet[2], size-2, pair_size);
1213 trigger_next_characteristic_descriptor_query(peripheral, last_descriptor_handle);
1202 break;
1203 }
1204 case ATT_FIND_INFORMATION_REPLY:
1205 {
1206 uint8_t pair_size = 4;
1207 if (packet[1] == 2){
1208 pair_size = 18;
1209 }
1210 uint16_t last_descriptor_handle = READ_BT_16(packet, size - pair_size);
1211
1212 report_gatt_all_characteristic_descriptors(peripheral, &packet[2], size-2, pair_size);
1213 trigger_next_characteristic_descriptor_query(peripheral, last_descriptor_handle);
1214 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1214 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1215 break;
1216 }
1217
1218 case ATT_WRITE_RESPONSE:
1219 switch (peripheral->gatt_client_state){
1220 case P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT:
1221 gatt_client_handle_transaction_complete(peripheral);
1222 emit_gatt_complete_event(peripheral, 0);

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

1236
1237 case ATT_READ_BLOB_RESPONSE:{
1238 uint16_t received_blob_length = size-1;
1239
1240 switch(peripheral->gatt_client_state){
1241 case P_W4_READ_BLOB_RESULT:
1242 report_gatt_long_characteristic_value_blob(peripheral, peripheral->attribute_handle, &packet[1], received_blob_length, peripheral->attribute_offset);
1243 trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_QUERY, received_blob_length);
1215 break;
1216 }
1217
1218 case ATT_WRITE_RESPONSE:
1219 switch (peripheral->gatt_client_state){
1220 case P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT:
1221 gatt_client_handle_transaction_complete(peripheral);
1222 emit_gatt_complete_event(peripheral, 0);

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

1236
1237 case ATT_READ_BLOB_RESPONSE:{
1238 uint16_t received_blob_length = size-1;
1239
1240 switch(peripheral->gatt_client_state){
1241 case P_W4_READ_BLOB_RESULT:
1242 report_gatt_long_characteristic_value_blob(peripheral, peripheral->attribute_handle, &packet[1], received_blob_length, peripheral->attribute_offset);
1243 trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_QUERY, received_blob_length);
1244 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1244 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1245 break;
1246 case P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT:
1247 report_gatt_long_characteristic_descriptor(peripheral, peripheral->attribute_handle,
1248 &packet[1], received_blob_length,
1249 peripheral->attribute_offset);
1250 trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, received_blob_length);
1245 break;
1246 case P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT:
1247 report_gatt_long_characteristic_descriptor(peripheral, peripheral->attribute_handle,
1248 &packet[1], received_blob_length,
1249 peripheral->attribute_offset);
1250 trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, received_blob_length);
1251 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1251 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1252 break;
1253 default:
1254 break;
1255 }
1256 break;
1257 }
1258 case ATT_PREPARE_WRITE_RESPONSE:
1259 switch (peripheral->gatt_client_state){

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

1264 } else {
1265 emit_gatt_complete_event(peripheral, ATT_ERROR_DATA_MISMATCH);
1266 }
1267 break;
1268
1269 case P_W4_PREPARE_WRITE_RESULT:{
1270 peripheral->attribute_offset = READ_BT_16(packet, 3);
1271 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_WRITE, P_W2_EXECUTE_PREPARED_WRITE);
1252 break;
1253 default:
1254 break;
1255 }
1256 break;
1257 }
1258 case ATT_PREPARE_WRITE_RESPONSE:
1259 switch (peripheral->gatt_client_state){

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

1264 } else {
1265 emit_gatt_complete_event(peripheral, ATT_ERROR_DATA_MISMATCH);
1266 }
1267 break;
1268
1269 case P_W4_PREPARE_WRITE_RESULT:{
1270 peripheral->attribute_offset = READ_BT_16(packet, 3);
1271 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_WRITE, P_W2_EXECUTE_PREPARED_WRITE);
1272 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1272 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1273 break;
1274 }
1275 case P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:{
1276 peripheral->attribute_offset = READ_BT_16(packet, 3);
1277 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR);
1273 break;
1274 }
1275 case P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:{
1276 peripheral->attribute_offset = READ_BT_16(packet, 3);
1277 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR);
1278 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1278 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1279 break;
1280 }
1281 case P_W4_PREPARE_RELIABLE_WRITE_RESULT:{
1282 if (is_value_valid(peripheral, packet, size)){
1283 peripheral->attribute_offset = READ_BT_16(packet, 3);
1284 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_RELIABLE_WRITE, P_W2_EXECUTE_PREPARED_WRITE);
1279 break;
1280 }
1281 case P_W4_PREPARE_RELIABLE_WRITE_RESULT:{
1282 if (is_value_valid(peripheral, packet, size)){
1283 peripheral->attribute_offset = READ_BT_16(packet, 3);
1284 trigger_next_prepare_write_query(peripheral, P_W2_PREPARE_RELIABLE_WRITE, P_W2_EXECUTE_PREPARED_WRITE);
1285 // GATT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1285 // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
1286 break;
1287 }
1288 peripheral->gatt_client_state = P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH;
1289 break;
1290 }
1291 default:
1292 break;
1293 }

--- 578 unchanged lines hidden ---
1286 break;
1287 }
1288 peripheral->gatt_client_state = P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH;
1289 break;
1290 }
1291 default:
1292 break;
1293 }

--- 578 unchanged lines hidden ---