hci.c (2a6c0f8203a6e80b026f1d5508f53de0dbb70501) | hci.c (15a15be326af256e2fa5def32b1909e3d09fb8cc) |
---|---|
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 --- 210 unchanged lines hidden (view full) --- 219#endif 220#ifdef ENABLE_LE_PERIPHERAL 221#ifdef ENABLE_LE_EXTENDED_ADVERTISING 222static void hci_periodic_advertiser_list_free(void); 223static le_advertising_set_t * hci_advertising_set_for_handle(uint8_t advertising_handle); 224#endif /* ENABLE_LE_EXTENDED_ADVERTISING */ 225#endif /* ENABLE_LE_PERIPHERAL */ 226#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS | 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 --- 210 unchanged lines hidden (view full) --- 219#endif 220#ifdef ENABLE_LE_PERIPHERAL 221#ifdef ENABLE_LE_EXTENDED_ADVERTISING 222static void hci_periodic_advertiser_list_free(void); 223static le_advertising_set_t * hci_advertising_set_for_handle(uint8_t advertising_handle); 224#endif /* ENABLE_LE_EXTENDED_ADVERTISING */ 225#endif /* ENABLE_LE_PERIPHERAL */ 226#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS |
227static uint8_t hci_iso_stream_create(hci_con_handle_t cis_handle); | 227static uint8_t hci_iso_stream_create(hci_con_handle_t con_handle); |
228static void hci_iso_stream_finalize(hci_iso_stream_t * iso_stream); | 228static void hci_iso_stream_finalize(hci_iso_stream_t * iso_stream); |
229static hci_iso_stream_t * hci_iso_stream_for_cis_handle(hci_con_handle_t cis_handle); 230static void hci_iso_stream_requested_finalize(void); 231static void hci_iso_stream_requested_confirm(void); | 229static hci_iso_stream_t * hci_iso_stream_for_con_handle(hci_con_handle_t con_handle); 230static void hci_iso_stream_requested_finalize(uint8_t big_handle); 231static void hci_iso_stream_requested_confirm(uint8_t big_handle); |
232static void hci_iso_packet_handler(uint8_t * packet, uint16_t size); 233static le_audio_big_t * hci_big_for_handle(uint8_t big_handle); 234static void hci_emit_big_created(const le_audio_big_t * big, uint8_t status); 235static void hci_emit_big_terminated(const le_audio_big_t * big); 236static void hci_emit_big_sync_created(const le_audio_big_sync_t * big_sync, uint8_t status); 237static void hci_emit_big_sync_stopped(const le_audio_big_sync_t * big_sync); 238static le_audio_big_sync_t * hci_big_sync_for_handle(uint8_t big_handle); 239#endif /* ENABLE_LE_ISOCHRONOUS_STREAMS */ --- 3395 unchanged lines hidden (view full) --- 3635 hci_stack->iso_fragmentation_pos = 0; 3636 if (release_buffer){ 3637 hci_release_packet_buffer(); 3638 } 3639 } 3640 } 3641 3642 // finalize iso stream if handle matches | 232static void hci_iso_packet_handler(uint8_t * packet, uint16_t size); 233static le_audio_big_t * hci_big_for_handle(uint8_t big_handle); 234static void hci_emit_big_created(const le_audio_big_t * big, uint8_t status); 235static void hci_emit_big_terminated(const le_audio_big_t * big); 236static void hci_emit_big_sync_created(const le_audio_big_sync_t * big_sync, uint8_t status); 237static void hci_emit_big_sync_stopped(const le_audio_big_sync_t * big_sync); 238static le_audio_big_sync_t * hci_big_sync_for_handle(uint8_t big_handle); 239#endif /* ENABLE_LE_ISOCHRONOUS_STREAMS */ --- 3395 unchanged lines hidden (view full) --- 3635 hci_stack->iso_fragmentation_pos = 0; 3636 if (release_buffer){ 3637 hci_release_packet_buffer(); 3638 } 3639 } 3640 } 3641 3642 // finalize iso stream if handle matches |
3643 iso_stream = hci_iso_stream_for_cis_handle(handle); | 3643 iso_stream = hci_iso_stream_for_con_handle(handle); |
3644 if (iso_stream != NULL){ 3645 hci_iso_stream_finalize(iso_stream); 3646 break; 3647 } 3648#endif 3649 3650 conn = hci_connection_for_handle(handle); 3651 if (!conn) break; --- 141 unchanged lines hidden (view full) --- 3793 if (conn) { 3794 conn->le_max_tx_octets = hci_subevent_le_data_length_change_get_max_tx_octets(packet); 3795 } 3796 break; 3797#endif 3798#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS 3799 case HCI_SUBEVENT_LE_CIS_ESTABLISHED: 3800 handle = hci_subevent_le_cis_established_get_connection_handle(packet); | 3644 if (iso_stream != NULL){ 3645 hci_iso_stream_finalize(iso_stream); 3646 break; 3647 } 3648#endif 3649 3650 conn = hci_connection_for_handle(handle); 3651 if (!conn) break; --- 141 unchanged lines hidden (view full) --- 3793 if (conn) { 3794 conn->le_max_tx_octets = hci_subevent_le_data_length_change_get_max_tx_octets(packet); 3795 } 3796 break; 3797#endif 3798#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS 3799 case HCI_SUBEVENT_LE_CIS_ESTABLISHED: 3800 handle = hci_subevent_le_cis_established_get_connection_handle(packet); |
3801 iso_stream = hci_iso_stream_for_cis_handle(handle); | 3801 iso_stream = hci_iso_stream_for_con_handle(handle); |
3802 if (iso_stream){ 3803 uint8_t status = hci_subevent_le_cis_established_get_status(packet); 3804 if (status == ERROR_CODE_SUCCESS){ 3805 iso_stream->state = HCI_ISO_STREAM_STATE_ESTABLISHED; 3806 } else { 3807 hci_iso_stream_finalize(iso_stream); 3808 } 3809 } --- 4914 unchanged lines hidden (view full) --- 8724 hci_stack->le_periodic_terminate_sync_handle = sync_handle; 8725 hci_run(); 8726 return ERROR_CODE_SUCCESS; 8727} 8728 8729#endif 8730#endif 8731#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS | 3802 if (iso_stream){ 3803 uint8_t status = hci_subevent_le_cis_established_get_status(packet); 3804 if (status == ERROR_CODE_SUCCESS){ 3805 iso_stream->state = HCI_ISO_STREAM_STATE_ESTABLISHED; 3806 } else { 3807 hci_iso_stream_finalize(iso_stream); 3808 } 3809 } --- 4914 unchanged lines hidden (view full) --- 8724 hci_stack->le_periodic_terminate_sync_handle = sync_handle; 8725 hci_run(); 8726 return ERROR_CODE_SUCCESS; 8727} 8728 8729#endif 8730#endif 8731#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS |
8732static uint8_t hci_iso_stream_create(hci_con_handle_t cis_handle){ | 8732static uint8_t hci_iso_stream_create(hci_con_handle_t con_handle){ |
8733 hci_iso_stream_t * iso_stream = btstack_memory_hci_iso_stream_get(); 8734 if (iso_stream == NULL){ 8735 return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED; 8736 } else { 8737 iso_stream->state = HCI_ISO_STREAM_STATE_REQUESTED; | 8733 hci_iso_stream_t * iso_stream = btstack_memory_hci_iso_stream_get(); 8734 if (iso_stream == NULL){ 8735 return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED; 8736 } else { 8737 iso_stream->state = HCI_ISO_STREAM_STATE_REQUESTED; |
8738 iso_stream->con_handle = cis_handle; | 8738 iso_stream->con_handle = con_handle; |
8739 btstack_linked_list_add(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); 8740 return ERROR_CODE_SUCCESS; 8741 } 8742} 8743 | 8739 btstack_linked_list_add(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); 8740 return ERROR_CODE_SUCCESS; 8741 } 8742} 8743 |
8744static hci_iso_stream_t * hci_iso_stream_for_cis_handle(hci_con_handle_t cis_handle){ | 8744static hci_iso_stream_t * hci_iso_stream_for_con_handle(hci_con_handle_t con_handle){ |
8745 btstack_linked_list_iterator_t it; 8746 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); 8747 while (btstack_linked_list_iterator_has_next(&it)){ 8748 hci_iso_stream_t * iso_stream = (hci_iso_stream_t *) btstack_linked_list_iterator_next(&it); | 8745 btstack_linked_list_iterator_t it; 8746 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); 8747 while (btstack_linked_list_iterator_has_next(&it)){ 8748 hci_iso_stream_t * iso_stream = (hci_iso_stream_t *) btstack_linked_list_iterator_next(&it); |
8749 if ( iso_stream->con_handle == cis_handle ) { | 8749 if (iso_stream->con_handle == con_handle ) { |
8750 return iso_stream; 8751 } 8752 } 8753 return NULL; 8754} 8755 8756static void hci_iso_stream_finalize(hci_iso_stream_t * iso_stream){ 8757 btstack_linked_list_remove(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); --- 36 unchanged lines hidden (view full) --- 8794 if (size < 4) { 8795 return; 8796 } 8797 8798 // parse header 8799 uint16_t conn_handle_and_flags = little_endian_read_16(packet, 0); 8800 uint16_t iso_data_len = little_endian_read_16(packet, 2); 8801 hci_con_handle_t cis_handle = (hci_con_handle_t) (conn_handle_and_flags & 0xfff); | 8750 return iso_stream; 8751 } 8752 } 8753 return NULL; 8754} 8755 8756static void hci_iso_stream_finalize(hci_iso_stream_t * iso_stream){ 8757 btstack_linked_list_remove(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); --- 36 unchanged lines hidden (view full) --- 8794 if (size < 4) { 8795 return; 8796 } 8797 8798 // parse header 8799 uint16_t conn_handle_and_flags = little_endian_read_16(packet, 0); 8800 uint16_t iso_data_len = little_endian_read_16(packet, 2); 8801 hci_con_handle_t cis_handle = (hci_con_handle_t) (conn_handle_and_flags & 0xfff); |
8802 hci_iso_stream_t * iso_stream = hci_iso_stream_for_cis_handle(cis_handle); | 8802 hci_iso_stream_t * iso_stream = hci_iso_stream_for_con_handle(cis_handle); |
8803 uint8_t pb_flag = (conn_handle_and_flags >> 12) & 3; 8804 8805 // assert packet is complete 8806 if ((iso_data_len + 4u) != size){ 8807 return; 8808 } 8809 8810 if ((pb_flag & 0x01) == 0){ --- 294 unchanged lines hidden --- | 8803 uint8_t pb_flag = (conn_handle_and_flags >> 12) & 3; 8804 8805 // assert packet is complete 8806 if ((iso_data_len + 4u) != size){ 8807 return; 8808 } 8809 8810 if ((pb_flag & 0x01) == 0){ --- 294 unchanged lines hidden --- |