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 MATTHIAS 24 * RINGWALD 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 #include <stdint.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 #include <unistd.h> 44 45 #include "btstack.h" 46 #include "avdtp.h" 47 #include "avdtp_source.h" 48 49 50 static const char * default_avdtp_sink_service_name = "BTstack AVDTP Sink Service"; 51 static const char * default_avdtp_sink_service_provider_name = "BTstack AVDTP Sink Service Provider"; 52 53 void a2dp_source_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t supported_features, const char * service_name, const char * service_provider_name){ 54 uint8_t* attribute; 55 de_create_sequence(service); 56 57 // 0x0000 "Service Record Handle" 58 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ServiceRecordHandle); 59 de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle); 60 61 // 0x0001 "Service Class ID List" 62 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ServiceClassIDList); 63 attribute = de_push_sequence(service); 64 { 65 de_add_number(attribute, DE_UUID, DE_SIZE_16, AUDIO_SOURCE_GROUP); 66 } 67 de_pop_sequence(service, attribute); 68 69 // 0x0004 "Protocol Descriptor List" 70 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ProtocolDescriptorList); 71 attribute = de_push_sequence(service); 72 { 73 uint8_t* l2cpProtocol = de_push_sequence(attribute); 74 { 75 de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, SDP_L2CAPProtocol); 76 de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, PSM_AVDTP); 77 } 78 de_pop_sequence(attribute, l2cpProtocol); 79 80 uint8_t* avProtocol = de_push_sequence(attribute); 81 { 82 de_add_number(avProtocol, DE_UUID, DE_SIZE_16, PSM_AVDTP); // avProtocol_service 83 de_add_number(avProtocol, DE_UINT, DE_SIZE_16, 0x0103); // version 84 } 85 de_pop_sequence(attribute, avProtocol); 86 } 87 de_pop_sequence(service, attribute); 88 89 // 0x0005 "Public Browse Group" 90 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_BrowseGroupList); // public browse group 91 attribute = de_push_sequence(service); 92 { 93 de_add_number(attribute, DE_UUID, DE_SIZE_16, SDP_PublicBrowseGroup); 94 } 95 de_pop_sequence(service, attribute); 96 97 // 0x0009 "Bluetooth Profile Descriptor List" 98 de_add_number(service, DE_UINT, DE_SIZE_16, SDP_BluetoothProfileDescriptorList); 99 attribute = de_push_sequence(service); 100 { 101 uint8_t *a2dProfile = de_push_sequence(attribute); 102 { 103 de_add_number(a2dProfile, DE_UUID, DE_SIZE_16, ADVANCED_AUDIO_DISTRIBUTION); 104 de_add_number(a2dProfile, DE_UINT, DE_SIZE_16, 0x0103); 105 } 106 de_pop_sequence(attribute, a2dProfile); 107 } 108 de_pop_sequence(service, attribute); 109 110 111 // 0x0100 "Service Name" 112 de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100); 113 if (service_name){ 114 de_add_data(service, DE_STRING, strlen(service_name), (uint8_t *) service_name); 115 } else { 116 de_add_data(service, DE_STRING, strlen(default_avdtp_sink_service_name), (uint8_t *) default_avdtp_sink_service_name); 117 } 118 119 // 0x0100 "Provider Name" 120 de_add_number(service, DE_UINT, DE_SIZE_16, 0x0102); 121 if (service_provider_name){ 122 de_add_data(service, DE_STRING, strlen(service_provider_name), (uint8_t *) service_provider_name); 123 } else { 124 de_add_data(service, DE_STRING, strlen(default_avdtp_sink_service_provider_name), (uint8_t *) default_avdtp_sink_service_provider_name); 125 } 126 127 // 0x0311 "Supported Features" 128 de_add_number(service, DE_UINT, DE_SIZE_16, 0x0311); 129 de_add_number(service, DE_UINT, DE_SIZE_16, supported_features); 130 } 131 132 133 134 135