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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /** 39 * Audio/Video Distribution Transport Protocol - Utils 40 * 41 */ 42 43 #ifndef AVDTP_UITL_H 44 #define AVDTP_UITL_H 45 46 #include <stdint.h> 47 #include "classic/avdtp.h" 48 49 #if defined __cplusplus 50 extern "C" { 51 #endif 52 53 #define AVDTP_MAX_MEDIA_CODEC_INFORMATION_LENGTH 30 54 55 // assume AVDTP_MEDIA_CONFIG_OTHER_EVENT_LEN greater or equal to all others 56 #define AVDTP_MEDIA_CONFIG_SBC_EVENT_LEN 18 57 #define AVDTP_MEDIA_CONFIG_MPEG_AUDIO_EVENT_LEN 18 58 #define AVDTP_MEDIA_CONFIG_MPEG_AAC_EVENT_LEN 18 59 #define AVDTP_MEDIA_CONFIG_ATRAC_EVENT_LEN 18 60 #define AVDTP_MEDIA_CONFIG_OTHER_EVENT_LEN (13 + AVDTP_MAX_MEDIA_CODEC_INFORMATION_LENGTH) 61 62 static inline uint8_t avdtp_header(uint8_t tr_label, avdtp_packet_type_t packet_type, avdtp_message_type_t msg_type){ 63 return (tr_label<<4) | ((uint8_t)packet_type<<2) | (uint8_t)msg_type; 64 } 65 66 avdtp_message_type_t avdtp_get_signaling_message_type(uint8_t * packet); 67 68 int avdtp_read_signaling_header(avdtp_signaling_packet_t * signaling_header, uint8_t * packet, uint16_t size); 69 70 uint16_t store_bit16(uint16_t bitmap, int position, uint8_t value); 71 int get_bit16(uint16_t bitmap, int position); 72 73 int avdtp_pack_service_capabilities(uint8_t * buffer, int size, avdtp_capabilities_t caps, avdtp_service_category_t category); 74 uint16_t avdtp_unpack_service_capabilities(avdtp_connection_t * connection, avdtp_signal_identifier_t signal_identifier, avdtp_capabilities_t * caps, uint8_t * packet, uint16_t size); 75 76 void avdtp_prepare_capabilities(avdtp_signaling_packet_t * signaling_packet, uint8_t transaction_label, uint16_t service_categories, avdtp_capabilities_t capabilities, uint8_t identifier); 77 int avdtp_signaling_create_fragment(uint16_t cid, avdtp_signaling_packet_t * signaling_packet, uint8_t * out_buffer); 78 79 void avdtp_signaling_emit_connection_established(uint16_t avdtp_cid, bd_addr_t addr, hci_con_handle_t con_handle, uint8_t status); 80 81 void avdtp_signaling_emit_connection_released(uint16_t avdtp_cid); 82 83 void avdtp_signaling_emit_sep(uint16_t avdtp_cid, avdtp_sep_t sep); 84 85 void avdtp_signaling_emit_sep_done(uint16_t avdtp_cid); 86 87 void avdtp_signaling_emit_accept(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, 88 bool is_initiator); 89 void avdtp_signaling_emit_accept_for_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint, uint8_t local_seid, 90 avdtp_signal_identifier_t identifier, bool is_initiator); 91 92 void avdtp_signaling_emit_general_reject(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, 93 bool is_initiator); 94 void avdtp_signaling_emit_reject(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, 95 bool is_initiator); 96 97 void avdtp_signaling_emit_capabilities(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_capabilities_t *capabilities, 98 uint16_t registered_service_categories); 99 100 void avdtp_signaling_emit_delay(uint16_t avdtp_cid, uint8_t local_seid, uint16_t delay); 101 102 void 103 avdtp_signaling_emit_configuration(avdtp_stream_endpoint_t *stream_endpoint, uint16_t avdtp_cid, uint8_t reconfigure, 104 avdtp_capabilities_t *configuration, uint16_t configured_service_categories); 105 106 uint16_t avdtp_setup_media_codec_config_event(uint8_t *event, uint16_t size, const avdtp_stream_endpoint_t *stream_endpoint, 107 uint16_t avdtp_cid, uint8_t reconfigure, 108 const adtvp_media_codec_capabilities_t * media_codec); 109 110 void avdtp_streaming_emit_connection_established(avdtp_stream_endpoint_t *stream_endpoint, uint8_t status); 111 112 void avdtp_streaming_emit_connection_released(avdtp_stream_endpoint_t *stream_endpoint, uint16_t avdtp_cid, uint8_t local_seid); 113 114 void avdtp_streaming_emit_can_send_media_packet_now(avdtp_stream_endpoint_t *stream_endpoint, uint16_t sequence_number); 115 116 uint8_t avdtp_request_can_send_now_acceptor(avdtp_connection_t *connection); 117 118 uint8_t avdtp_request_can_send_now_initiator(avdtp_connection_t *connection); 119 120 void avdtp_reset_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint); 121 122 // uint16_t avdtp_cid(avdtp_stream_endpoint_t * stream_endpoint); 123 uint8_t avdtp_local_seid(const avdtp_stream_endpoint_t * stream_endpoint); 124 uint8_t avdtp_remote_seid(const avdtp_stream_endpoint_t * stream_endpoint); 125 const char * avdtp_si2str(uint16_t index); 126 127 // helper to set/get configuration 128 void avdtp_config_sbc_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz); 129 void avdtp_config_sbc_store(uint8_t * config, const avdtp_configuration_sbc_t * configuration); 130 void avdtp_config_mpeg_audio_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz); 131 void avdtp_config_mpeg_audio_store(uint8_t * config, const avdtp_configuration_mpeg_audio_t * configuration); 132 void avdtp_config_mpeg_aac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz); 133 void avdtp_config_mpeg_aac_store(uint8_t * config, const avdtp_configuration_mpeg_aac_t * configuration); 134 void avdtp_config_atrac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz); 135 void avdtp_config_atrac_store(uint8_t * config, const avdtp_configuration_atrac_t * configuration); 136 137 #if defined __cplusplus 138 } 139 #endif 140 141 #endif // AVDTP_UITL_H 142