avdtp_util.c (b548dda644e018ef90d0b63644184e25310c9d78) avdtp_util.c (6484b28a8cf2e8dc89acafacb3c57e97937a4b51)
1/*
2 * Copyright (C) 2016 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

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

52 return (tr_label<<4) | ((uint8_t)packet_type<<2) | (uint8_t)msg_type;
53}
54
55void avdtp_initialize_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint){
56 stream_endpoint->connection = NULL;
57 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_IDLE;
58 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
59 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE;
1/*
2 * Copyright (C) 2016 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

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

52 return (tr_label<<4) | ((uint8_t)packet_type<<2) | (uint8_t)msg_type;
53}
54
55void avdtp_initialize_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint){
56 stream_endpoint->connection = NULL;
57 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_IDLE;
58 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
59 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE;
60 stream_endpoint->remote_sep_index = 0;
60 stream_endpoint->remote_sep_index = AVDTP_INVALID_SEP_INDEX;
61 stream_endpoint->media_disconnect = 0;
61 stream_endpoint->media_disconnect = 0;
62 stream_endpoint->remote_seps_num = 0;
62 stream_endpoint->sep.in_use = 0;
63 stream_endpoint->sep.in_use = 0;
63 stream_endpoint->remote_sep_index = 0;
64 memset(stream_endpoint->remote_seps, 0, sizeof(stream_endpoint->remote_seps));
64}
65
66avdtp_stream_endpoint_t * avdtp_stream_endpoint_for_seid(uint16_t seid, avdtp_context_t * context){
67 btstack_linked_list_iterator_t it;
68 btstack_linked_list_iterator_init(&it, &context->stream_endpoints);
69 while (btstack_linked_list_iterator_has_next(&it)){
70 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
71 if (stream_endpoint->sep.seid == seid){

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

81 while (btstack_linked_list_iterator_has_next(&it)){
82 avdtp_connection_t * connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
83 if (memcmp(addr, connection->remote_addr, 6) != 0) continue;
84 return connection;
85 }
86 return NULL;
87}
88
65}
66
67avdtp_stream_endpoint_t * avdtp_stream_endpoint_for_seid(uint16_t seid, avdtp_context_t * context){
68 btstack_linked_list_iterator_t it;
69 btstack_linked_list_iterator_init(&it, &context->stream_endpoints);
70 while (btstack_linked_list_iterator_has_next(&it)){
71 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
72 if (stream_endpoint->sep.seid == seid){

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

82 while (btstack_linked_list_iterator_has_next(&it)){
83 avdtp_connection_t * connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
84 if (memcmp(addr, connection->remote_addr, 6) != 0) continue;
85 return connection;
86 }
87 return NULL;
88}
89
90avdtp_connection_t * avdtp_connection_for_con_handle(hci_con_handle_t con_handle, avdtp_context_t * context){
91 btstack_linked_list_iterator_t it;
92 btstack_linked_list_iterator_init(&it, &context->connections);
93 while (btstack_linked_list_iterator_has_next(&it)){
94 avdtp_connection_t * connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
95 if (connection->con_handle != con_handle) continue;
96 return connection;
97 }
98 return NULL;
99}
100
89avdtp_connection_t * avdtp_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid, avdtp_context_t * context){
90 btstack_linked_list_iterator_t it;
91 btstack_linked_list_iterator_init(&it, &context->connections);
92 while (btstack_linked_list_iterator_has_next(&it)){
93 avdtp_connection_t * connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
94 if (connection->l2cap_signaling_cid != l2cap_cid) continue;
95 return connection;
96 }

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

128}
129
130avdtp_stream_endpoint_t * avdtp_stream_endpoint_associated_with_acp_seid(uint16_t acp_seid, avdtp_context_t * context){
131 btstack_linked_list_iterator_t it;
132 btstack_linked_list_iterator_init(&it, &context->stream_endpoints);
133 while (btstack_linked_list_iterator_has_next(&it)){
134 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
135 if (stream_endpoint->remote_sep_index >= 0 && stream_endpoint->remote_sep_index < MAX_NUM_SEPS){
101avdtp_connection_t * avdtp_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid, avdtp_context_t * context){
102 btstack_linked_list_iterator_t it;
103 btstack_linked_list_iterator_init(&it, &context->connections);
104 while (btstack_linked_list_iterator_has_next(&it)){
105 avdtp_connection_t * connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
106 if (connection->l2cap_signaling_cid != l2cap_cid) continue;
107 return connection;
108 }

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

140}
141
142avdtp_stream_endpoint_t * avdtp_stream_endpoint_associated_with_acp_seid(uint16_t acp_seid, avdtp_context_t * context){
143 btstack_linked_list_iterator_t it;
144 btstack_linked_list_iterator_init(&it, &context->stream_endpoints);
145 while (btstack_linked_list_iterator_has_next(&it)){
146 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
147 if (stream_endpoint->remote_sep_index >= 0 && stream_endpoint->remote_sep_index < MAX_NUM_SEPS){
136 if (!stream_endpoint->connection) continue;
137 if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid == acp_seid){
148 if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid == acp_seid){
138 return stream_endpoint;
139 }
140 }
141 }
142 return NULL;
143}
144
145int get_bit16(uint16_t bitmap, int position){

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

493 }
494 out_buffer[0] = avdtp_header(signaling_packet->transaction_label, signaling_packet->packet_type, signaling_packet->message_type);
495 memcpy(out_buffer+pos, signaling_packet->command + offset, data_len);
496 pos += data_len;
497 return pos;
498}
499
500
149 return stream_endpoint;
150 }
151 }
152 }
153 return NULL;
154}
155
156int get_bit16(uint16_t bitmap, int position){

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

504 }
505 out_buffer[0] = avdtp_header(signaling_packet->transaction_label, signaling_packet->packet_type, signaling_packet->message_type);
506 memcpy(out_buffer+pos, signaling_packet->command + offset, data_len);
507 pos += data_len;
508 return pos;
509}
510
511
501void avdtp_signaling_emit_connection_established(btstack_packet_handler_t callback, uint16_t avdtp_cid, bd_addr_t addr, uint8_t status){
512void avdtp_signaling_emit_connection_established(btstack_packet_handler_t callback, uint16_t con_handle, bd_addr_t addr, uint8_t status){
502 if (!callback) return;
503 uint8_t event[12];
504 int pos = 0;
505 event[pos++] = HCI_EVENT_AVDTP_META;
506 event[pos++] = sizeof(event) - 2;
507 event[pos++] = AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED;
513 if (!callback) return;
514 uint8_t event[12];
515 int pos = 0;
516 event[pos++] = HCI_EVENT_AVDTP_META;
517 event[pos++] = sizeof(event) - 2;
518 event[pos++] = AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED;
508 little_endian_store_16(event, pos, avdtp_cid);
519 little_endian_store_16(event, pos, con_handle);
509 pos += 2;
510 reverse_bd_addr(addr,&event[pos]);
511 pos += 6;
512 event[pos++] = status;
513 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
514}
515
520 pos += 2;
521 reverse_bd_addr(addr,&event[pos]);
522 pos += 6;
523 event[pos++] = status;
524 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
525}
526
516void avdtp_streaming_emit_can_send_media_packet_now(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t seid, uint16_t sequence_number){
527void avdtp_streaming_emit_connection_established(btstack_packet_handler_t callback, uint16_t con_handle, uint8_t status){
517 if (!callback) return;
528 if (!callback) return;
518 uint8_t event[8];
529 uint8_t event[6];
519 int pos = 0;
520 event[pos++] = HCI_EVENT_AVDTP_META;
521 event[pos++] = sizeof(event) - 2;
530 int pos = 0;
531 event[pos++] = HCI_EVENT_AVDTP_META;
532 event[pos++] = sizeof(event) - 2;
522 event[pos++] = AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW;
523 little_endian_store_16(event, pos, avdtp_cid);
524 pos += 2;
525 event[pos++] = seid;
526 little_endian_store_16(event, pos, sequence_number);
527 pos += 2;
528 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
529}
530
531void avdtp_streaming_emit_connection_established(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, uint8_t status){
532 if (!callback) return;
533 uint8_t event[8];
534 int pos = 0;
535 event[pos++] = HCI_EVENT_AVDTP_META;
536 event[pos++] = sizeof(event) - 2;
537 event[pos++] = AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED;
533 event[pos++] = AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED;
538 little_endian_store_16(event, pos, avdtp_cid);
534 little_endian_store_16(event, pos, con_handle);
539 pos += 2;
535 pos += 2;
540 event[pos++] = int_seid;
541 event[pos++] = acp_seid;
542 event[pos++] = status;
543 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
544}
545
536 event[pos++] = status;
537 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
538}
539
546void avdtp_signaling_emit_sep(btstack_packet_handler_t callback, uint16_t avdtp_cid, avdtp_sep_t sep){
540void avdtp_signaling_emit_sep(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_sep_t sep){
547 if (!callback) return;
548 uint8_t event[9];
549 int pos = 0;
550 event[pos++] = HCI_EVENT_AVDTP_META;
551 event[pos++] = sizeof(event) - 2;
552 event[pos++] = AVDTP_SUBEVENT_SIGNALING_SEP_FOUND;
541 if (!callback) return;
542 uint8_t event[9];
543 int pos = 0;
544 event[pos++] = HCI_EVENT_AVDTP_META;
545 event[pos++] = sizeof(event) - 2;
546 event[pos++] = AVDTP_SUBEVENT_SIGNALING_SEP_FOUND;
553 little_endian_store_16(event, pos, avdtp_cid);
547 little_endian_store_16(event, pos, con_handle);
554 pos += 2;
555 event[pos++] = sep.seid;
556 event[pos++] = sep.in_use;
557 event[pos++] = sep.media_type;
558 event[pos++] = sep.type;
559 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
560}
561
548 pos += 2;
549 event[pos++] = sep.seid;
550 event[pos++] = sep.in_use;
551 event[pos++] = sep.media_type;
552 event[pos++] = sep.type;
553 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
554}
555
562void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier, uint8_t status){
556void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_signal_identifier_t identifier, uint8_t status){
563 if (!callback) return;
557 if (!callback) return;
564 uint8_t event[8];
558 uint8_t event[7];
565 int pos = 0;
566 event[pos++] = HCI_EVENT_AVDTP_META;
567 event[pos++] = sizeof(event) - 2;
568 event[pos++] = AVDTP_SUBEVENT_SIGNALING_ACCEPT;
559 int pos = 0;
560 event[pos++] = HCI_EVENT_AVDTP_META;
561 event[pos++] = sizeof(event) - 2;
562 event[pos++] = AVDTP_SUBEVENT_SIGNALING_ACCEPT;
569 little_endian_store_16(event, pos, avdtp_cid);
563 little_endian_store_16(event, pos, con_handle);
570 pos += 2;
564 pos += 2;
571 event[pos++] = int_seid;
572 event[pos++] = identifier;
573 event[pos++] = status;
574 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
575}
576
565 event[pos++] = identifier;
566 event[pos++] = status;
567 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
568}
569
577void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier){
570void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_signal_identifier_t identifier){
578 if (!callback) return;
571 if (!callback) return;
579 uint8_t event[7];
572 uint8_t event[6];
580 int pos = 0;
581 event[pos++] = HCI_EVENT_AVDTP_META;
582 event[pos++] = sizeof(event) - 2;
583 event[pos++] = AVDTP_SUBEVENT_SIGNALING_REJECT;
573 int pos = 0;
574 event[pos++] = HCI_EVENT_AVDTP_META;
575 event[pos++] = sizeof(event) - 2;
576 event[pos++] = AVDTP_SUBEVENT_SIGNALING_REJECT;
584 little_endian_store_16(event, pos, avdtp_cid);
577 little_endian_store_16(event, pos, con_handle);
585 pos += 2;
578 pos += 2;
586 event[pos++] = int_seid;
587 event[pos++] = identifier;
588 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
589}
590
579 event[pos++] = identifier;
580 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
581}
582
591void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier){
583void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_signal_identifier_t identifier){
592 if (!callback) return;
584 if (!callback) return;
593 uint8_t event[7];
585 uint8_t event[6];
594 int pos = 0;
595 event[pos++] = HCI_EVENT_AVDTP_META;
596 event[pos++] = sizeof(event) - 2;
597 event[pos++] = AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT;
586 int pos = 0;
587 event[pos++] = HCI_EVENT_AVDTP_META;
588 event[pos++] = sizeof(event) - 2;
589 event[pos++] = AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT;
598 little_endian_store_16(event, pos, avdtp_cid);
590 little_endian_store_16(event, pos, con_handle);
599 pos += 2;
591 pos += 2;
600 event[pos++] = int_seid;
601 event[pos++] = identifier;
602 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
603}
604
592 event[pos++] = identifier;
593 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
594}
595
605void avdtp_signaling_emit_media_codec_sbc_capability(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
596void avdtp_signaling_emit_media_codec_sbc_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
606 if (!callback) return;
597 if (!callback) return;
607 uint8_t event[15];
598 uint8_t event[13];
608 int pos = 0;
609 event[pos++] = HCI_EVENT_AVDTP_META;
610 event[pos++] = sizeof(event) - 2;
611 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY;
599 int pos = 0;
600 event[pos++] = HCI_EVENT_AVDTP_META;
601 event[pos++] = sizeof(event) - 2;
602 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY;
612 little_endian_store_16(event, pos, avdtp_cid);
603 little_endian_store_16(event, pos, con_handle);
613 pos += 2;
604 pos += 2;
614 event[pos++] = int_seid;
615 event[pos++] = acp_seid;
616 event[pos++] = media_codec.media_type;
617 event[pos++] = media_codec.media_codec_information[0] >> 4;
618 event[pos++] = media_codec.media_codec_information[0] & 0x0F;
619 event[pos++] = media_codec.media_codec_information[1] >> 4;
620 event[pos++] = (media_codec.media_codec_information[1] & 0x0F) >> 2;
621 event[pos++] = media_codec.media_codec_information[1] & 0x03;
622 event[pos++] = media_codec.media_codec_information[2];
623 event[pos++] = media_codec.media_codec_information[3];
624 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
625}
626
605 event[pos++] = media_codec.media_type;
606 event[pos++] = media_codec.media_codec_information[0] >> 4;
607 event[pos++] = media_codec.media_codec_information[0] & 0x0F;
608 event[pos++] = media_codec.media_codec_information[1] >> 4;
609 event[pos++] = (media_codec.media_codec_information[1] & 0x0F) >> 2;
610 event[pos++] = media_codec.media_codec_information[1] & 0x03;
611 event[pos++] = media_codec.media_codec_information[2];
612 event[pos++] = media_codec.media_codec_information[3];
613 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
614}
615
627void avdtp_signaling_emit_media_codec_other_capability(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
616void avdtp_signaling_emit_media_codec_other_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
628 if (!callback) return;
617 if (!callback) return;
629 uint8_t event[111];
618 uint8_t event[109];
630 int pos = 0;
631 event[pos++] = HCI_EVENT_AVDTP_META;
632 event[pos++] = sizeof(event) - 2;
633 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY;
619 int pos = 0;
620 event[pos++] = HCI_EVENT_AVDTP_META;
621 event[pos++] = sizeof(event) - 2;
622 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY;
634 little_endian_store_16(event, pos, avdtp_cid);
623 little_endian_store_16(event, pos, con_handle);
635 pos += 2;
624 pos += 2;
636 event[pos++] = int_seid;
637 event[pos++] = acp_seid;
638 event[pos++] = media_codec.media_type;
639 little_endian_store_16(event, pos, media_codec.media_codec_type);
640 pos += 2;
641 little_endian_store_16(event, pos, media_codec.media_codec_information_len);
642 pos += 2;
643 if (media_codec.media_codec_information_len < 100){
644 memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
645 } else {
646 memcpy(event+pos, media_codec.media_codec_information, 100);
647 }
648 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
649}
650
625 event[pos++] = media_codec.media_type;
626 little_endian_store_16(event, pos, media_codec.media_codec_type);
627 pos += 2;
628 little_endian_store_16(event, pos, media_codec.media_codec_information_len);
629 pos += 2;
630 if (media_codec.media_codec_information_len < 100){
631 memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
632 } else {
633 memcpy(event+pos, media_codec.media_codec_information, 100);
634 }
635 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
636}
637
651static inline void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
638static inline void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
652 if (!callback) return;
639 if (!callback) return;
653 uint8_t event[16+2];
640 uint8_t event[14+2];
654 int pos = 0;
655 event[pos++] = HCI_EVENT_AVDTP_META;
656 event[pos++] = sizeof(event) - 2;
657
658 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION;
641 int pos = 0;
642 event[pos++] = HCI_EVENT_AVDTP_META;
643 event[pos++] = sizeof(event) - 2;
644
645 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION;
659 little_endian_store_16(event, pos, avdtp_cid);
646 little_endian_store_16(event, pos, con_handle);
660 pos += 2;
647 pos += 2;
661 event[pos++] = int_seid;
662 event[pos++] = acp_seid;
663 event[pos++] = reconfigure;
664
665 uint8_t num_channels = 0;
666 uint16_t sampling_frequency = 0;
667 uint8_t subbands = 0;
668 uint8_t block_length = 0;
669
670 uint8_t sampling_frequency_bitmap = media_codec.media_codec_information[0] >> 4;

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

723 event[pos++] = block_length;
724 event[pos++] = subbands;
725 event[pos++] = media_codec.media_codec_information[1] & 0x03;
726 event[pos++] = media_codec.media_codec_information[2];
727 event[pos++] = media_codec.media_codec_information[3];
728 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
729}
730
648 event[pos++] = reconfigure;
649
650 uint8_t num_channels = 0;
651 uint16_t sampling_frequency = 0;
652 uint8_t subbands = 0;
653 uint8_t block_length = 0;
654
655 uint8_t sampling_frequency_bitmap = media_codec.media_codec_information[0] >> 4;

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

708 event[pos++] = block_length;
709 event[pos++] = subbands;
710 event[pos++] = media_codec.media_codec_information[1] & 0x03;
711 event[pos++] = media_codec.media_codec_information[2];
712 event[pos++] = media_codec.media_codec_information[3];
713 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
714}
715
731void avdtp_signaling_emit_media_codec_sbc_configuration(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
716void avdtp_signaling_emit_media_codec_sbc_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
732 if (!callback) return;
717 if (!callback) return;
733 avdtp_signaling_emit_media_codec_sbc(callback, avdtp_cid, int_seid, acp_seid, media_codec, 0);
718 avdtp_signaling_emit_media_codec_sbc(callback, con_handle, media_codec, 0);
734}
735
719}
720
736void avdtp_signaling_emit_media_codec_sbc_reconfiguration(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
721void avdtp_signaling_emit_media_codec_sbc_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
737 if (!callback) return;
722 if (!callback) return;
738 avdtp_signaling_emit_media_codec_sbc(callback, avdtp_cid, int_seid, acp_seid, media_codec, 1);
723 avdtp_signaling_emit_media_codec_sbc(callback, con_handle, media_codec, 1);
739}
740
724}
725
741static inline void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
742 uint8_t event[112];
726static inline void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
727 uint8_t event[110];
743 int pos = 0;
744 event[pos++] = HCI_EVENT_AVDTP_META;
745 event[pos++] = sizeof(event) - 2;
746 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION;
728 int pos = 0;
729 event[pos++] = HCI_EVENT_AVDTP_META;
730 event[pos++] = sizeof(event) - 2;
731 event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION;
747 little_endian_store_16(event, pos, avdtp_cid);
732 little_endian_store_16(event, pos, con_handle);
748 pos += 2;
733 pos += 2;
749 event[pos++] = int_seid;
750 event[pos++] = acp_seid;
734
751 event[pos++] = reconfigure;
752
753 event[pos++] = media_codec.media_type;
754 little_endian_store_16(event, pos, media_codec.media_codec_type);
755 pos += 2;
756 little_endian_store_16(event, pos, media_codec.media_codec_information_len);
757 pos += 2;
758
759 if (media_codec.media_codec_information_len < 100){
760 memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
761 } else {
762 memcpy(event+pos, media_codec.media_codec_information, 100);
763 }
764 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
765}
766
735 event[pos++] = reconfigure;
736
737 event[pos++] = media_codec.media_type;
738 little_endian_store_16(event, pos, media_codec.media_codec_type);
739 pos += 2;
740 little_endian_store_16(event, pos, media_codec.media_codec_information_len);
741 pos += 2;
742
743 if (media_codec.media_codec_information_len < 100){
744 memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
745 } else {
746 memcpy(event+pos, media_codec.media_codec_information, 100);
747 }
748 (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
749}
750
767void avdtp_signaling_emit_media_codec_other_configuration(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
751void avdtp_signaling_emit_media_codec_other_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
768 if (!callback) return;
752 if (!callback) return;
769 avdtp_signaling_emit_media_codec_other(callback, avdtp_cid, int_seid, acp_seid, media_codec, 0);
753 avdtp_signaling_emit_media_codec_other(callback, con_handle, media_codec, 0);
770}
771
754}
755
772void avdtp_signaling_emit_media_codec_other_reconfiguration(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, adtvp_media_codec_capabilities_t media_codec){
756void avdtp_signaling_emit_media_codec_other_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
773 if (!callback) return;
757 if (!callback) return;
774 avdtp_signaling_emit_media_codec_other(callback, avdtp_cid, int_seid, acp_seid, media_codec, 1);
758 avdtp_signaling_emit_media_codec_other(callback, con_handle, media_codec, 1);
775}
776
777
778void avdtp_request_can_send_now_acceptor(avdtp_connection_t * connection, uint16_t l2cap_cid){
779 connection->wait_to_send_acceptor = 1;
780 l2cap_request_can_send_now_event(l2cap_cid);
781}
782void avdtp_request_can_send_now_initiator(avdtp_connection_t * connection, uint16_t l2cap_cid){
783 connection->wait_to_send_initiator = 1;
784 l2cap_request_can_send_now_event(l2cap_cid);
785}
786void avdtp_request_can_send_now_self(avdtp_connection_t * connection, uint16_t l2cap_cid){
787 connection->wait_to_send_self = 1;
788 l2cap_request_can_send_now_event(l2cap_cid);
789}
790
791uint8_t avdtp_get_index_of_remote_stream_endpoint_with_seid(avdtp_stream_endpoint_t * stream_endpoint, uint16_t seid){
759}
760
761
762void avdtp_request_can_send_now_acceptor(avdtp_connection_t * connection, uint16_t l2cap_cid){
763 connection->wait_to_send_acceptor = 1;
764 l2cap_request_can_send_now_event(l2cap_cid);
765}
766void avdtp_request_can_send_now_initiator(avdtp_connection_t * connection, uint16_t l2cap_cid){
767 connection->wait_to_send_initiator = 1;
768 l2cap_request_can_send_now_event(l2cap_cid);
769}
770void avdtp_request_can_send_now_self(avdtp_connection_t * connection, uint16_t l2cap_cid){
771 connection->wait_to_send_self = 1;
772 l2cap_request_can_send_now_event(l2cap_cid);
773}
774
775uint8_t avdtp_get_index_of_remote_stream_endpoint_with_seid(avdtp_stream_endpoint_t * stream_endpoint, uint16_t seid){
792 if (!stream_endpoint->connection) return 0xFF;
793 if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid == seid){
776 if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid == seid){
794 return stream_endpoint->remote_sep_index;
795 }
796 int i;
777 return stream_endpoint->remote_sep_index;
778 }
779 int i;
797 for (i=0; i < stream_endpoint->connection->remote_seps_num; i++){
798 if (stream_endpoint->connection->remote_seps[i].seid == seid){
780 for (i=0; i < stream_endpoint->remote_seps_num; i++){
781 if (stream_endpoint->remote_seps[i].seid == seid){
799 return i;
800 }
801 }
802 return 0xFF;
803}
782 return i;
783 }
784 }
785 return 0xFF;
786}
804
805uint8_t avdtp_find_remote_sep(avdtp_connection_t * connection, uint8_t remote_seid){
806 if (!connection) return 0xFF;
807 int i;
808 for (i = 0; i < connection->remote_seps_num; i++){
809 if (connection->remote_seps[i].seid == remote_seid){
810 return i;
811 }
812 }
813 return 0xFF;
814}
815