att_server.c (9305033e0290a73b79a29900c5b9f35f77d880b1) | att_server.c (1979f09cf045e87f55a9cd8067e8ef902cc8d78b) |
---|---|
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 --- 117 unchanged lines hidden (view full) --- 126 l2cap_request_can_send_now_event(att_server->l2cap_cid); 127 return; 128 } 129#endif 130 att_connection_t * att_connection = &hci_connection->att_connection; 131 att_dispatch_server_request_can_send_now_event(att_connection->con_handle); 132} 133 | 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 --- 117 unchanged lines hidden (view full) --- 126 l2cap_request_can_send_now_event(att_server->l2cap_cid); 127 return; 128 } 129#endif 130 att_connection_t * att_connection = &hci_connection->att_connection; 131 att_dispatch_server_request_can_send_now_event(att_connection->con_handle); 132} 133 |
134static int att_server_can_send_packet(hci_connection_t * hci_connection){ | 134static bool att_server_can_send_packet(hci_connection_t * hci_connection){ |
135#ifdef ENABLE_GATT_OVER_CLASSIC 136 att_server_t * att_server = &hci_connection->att_server; 137 if (att_server->l2cap_cid != 0){ | 135#ifdef ENABLE_GATT_OVER_CLASSIC 136 att_server_t * att_server = &hci_connection->att_server; 137 if (att_server->l2cap_cid != 0){ |
138 return l2cap_can_send_packet_now(att_server->l2cap_cid); | 138 return l2cap_can_send_packet_now(att_server->l2cap_cid) != 0; |
139 } 140#endif 141 att_connection_t * att_connection = &hci_connection->att_connection; | 139 } 140#endif 141 att_connection_t * att_connection = &hci_connection->att_connection; |
142 return att_dispatch_server_can_send_now(att_connection->con_handle); | 142 return att_dispatch_server_can_send_now(att_connection->con_handle) != 0; |
143} 144 145static void att_handle_value_indication_notify_client(uint8_t status, uint16_t client_handle, uint16_t attribute_handle){ 146 btstack_packet_handler_t packet_handler = att_server_packet_handler_for_handle(attribute_handle); 147 if (!packet_handler) return; 148 149 uint8_t event[7]; 150 int pos = 0; --- 518 unchanged lines hidden (view full) --- 669 att_server_request_can_send_now(hci_connection); 670 break; 671 672 default: 673 break; 674 } 675} 676 | 143} 144 145static void att_handle_value_indication_notify_client(uint8_t status, uint16_t client_handle, uint16_t attribute_handle){ 146 btstack_packet_handler_t packet_handler = att_server_packet_handler_for_handle(attribute_handle); 147 if (!packet_handler) return; 148 149 uint8_t event[7]; 150 int pos = 0; --- 518 unchanged lines hidden (view full) --- 669 att_server_request_can_send_now(hci_connection); 670 break; 671 672 default: 673 break; 674 } 675} 676 |
677static int att_server_data_ready_for_phase(att_server_t * att_server, att_server_run_phase_t phase){ | 677static bool att_server_data_ready_for_phase(att_server_t * att_server, att_server_run_phase_t phase){ |
678 switch (phase){ 679 case ATT_SERVER_RUN_PHASE_1_REQUESTS: 680 return att_server->state == ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED; 681 case ATT_SERVER_RUN_PHASE_2_INDICATIONS: 682 return (!btstack_linked_list_empty(&att_server->indication_requests) && (att_server->value_indication_handle == 0)); 683 case ATT_SERVER_RUN_PHASE_3_NOTIFICATIONS: 684 return (!btstack_linked_list_empty(&att_server->notification_requests)); 685 default: 686 btstack_assert(false); | 678 switch (phase){ 679 case ATT_SERVER_RUN_PHASE_1_REQUESTS: 680 return att_server->state == ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED; 681 case ATT_SERVER_RUN_PHASE_2_INDICATIONS: 682 return (!btstack_linked_list_empty(&att_server->indication_requests) && (att_server->value_indication_handle == 0)); 683 case ATT_SERVER_RUN_PHASE_3_NOTIFICATIONS: 684 return (!btstack_linked_list_empty(&att_server->notification_requests)); 685 default: 686 btstack_assert(false); |
687 return 0; | 687 return false; |
688 } 689} 690 691static void att_server_trigger_send_for_phase(hci_connection_t * hci_connection, att_server_run_phase_t phase){ 692 btstack_context_callback_registration_t * client; 693 att_server_t * att_server = &hci_connection->att_server; 694 switch (phase){ 695 case ATT_SERVER_RUN_PHASE_1_REQUESTS: --- 14 unchanged lines hidden (view full) --- 710 break; 711 } 712} 713 714static void att_server_handle_can_send_now(void){ 715 716 hci_con_handle_t last_send_con_handle = HCI_CON_HANDLE_INVALID; 717 hci_connection_t * request_hci_connection = NULL; | 688 } 689} 690 691static void att_server_trigger_send_for_phase(hci_connection_t * hci_connection, att_server_run_phase_t phase){ 692 btstack_context_callback_registration_t * client; 693 att_server_t * att_server = &hci_connection->att_server; 694 switch (phase){ 695 case ATT_SERVER_RUN_PHASE_1_REQUESTS: --- 14 unchanged lines hidden (view full) --- 710 break; 711 } 712} 713 714static void att_server_handle_can_send_now(void){ 715 716 hci_con_handle_t last_send_con_handle = HCI_CON_HANDLE_INVALID; 717 hci_connection_t * request_hci_connection = NULL; |
718 int can_send_now = 1; | 718 bool can_send_now = true; |
719 int phase_index; 720 721 for (phase_index = ATT_SERVER_RUN_PHASE_1_REQUESTS; phase_index <= ATT_SERVER_RUN_PHASE_3_NOTIFICATIONS; phase_index++){ 722 att_server_run_phase_t phase = (att_server_run_phase_t) phase_index; 723 hci_con_handle_t skip_connections_until = att_server_last_can_send_now; 724 while (true){ 725 btstack_linked_list_iterator_t it; 726 hci_connections_get_iterator(&it); 727 while(btstack_linked_list_iterator_has_next(&it)){ 728 hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it); 729 att_server_t * att_server = &connection->att_server; 730 att_connection_t * att_connection = &connection->att_connection; 731 | 719 int phase_index; 720 721 for (phase_index = ATT_SERVER_RUN_PHASE_1_REQUESTS; phase_index <= ATT_SERVER_RUN_PHASE_3_NOTIFICATIONS; phase_index++){ 722 att_server_run_phase_t phase = (att_server_run_phase_t) phase_index; 723 hci_con_handle_t skip_connections_until = att_server_last_can_send_now; 724 while (true){ 725 btstack_linked_list_iterator_t it; 726 hci_connections_get_iterator(&it); 727 while(btstack_linked_list_iterator_has_next(&it)){ 728 hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it); 729 att_server_t * att_server = &connection->att_server; 730 att_connection_t * att_connection = &connection->att_connection; 731 |
732 int data_ready = att_server_data_ready_for_phase(att_server, phase); | 732 bool data_ready = att_server_data_ready_for_phase(att_server, phase); |
733 734 // log_debug("phase %u, handle 0x%04x, skip until 0x%04x, data ready %u", phase, att_connection->con_handle, skip_connections_until, data_ready); 735 736 // skip until last sender found (which is also skipped) 737 if (skip_connections_until != HCI_CON_HANDLE_INVALID){ 738 if (data_ready && (request_hci_connection == NULL)){ 739 request_hci_connection = connection; 740 } --- 510 unchanged lines hidden --- | 733 734 // log_debug("phase %u, handle 0x%04x, skip until 0x%04x, data ready %u", phase, att_connection->con_handle, skip_connections_until, data_ready); 735 736 // skip until last sender found (which is also skipped) 737 if (skip_connections_until != HCI_CON_HANDLE_INVALID){ 738 if (data_ready && (request_hci_connection == NULL)){ 739 request_hci_connection = connection; 740 } --- 510 unchanged lines hidden --- |