1*b442c9e6SMilanka Ringwald 2*b442c9e6SMilanka Ringwald /* 3*b442c9e6SMilanka Ringwald * Copyright (C) 2016 BlueKitchen GmbH 4*b442c9e6SMilanka Ringwald * 5*b442c9e6SMilanka Ringwald * Redistribution and use in source and binary forms, with or without 6*b442c9e6SMilanka Ringwald * modification, are permitted provided that the following conditions 7*b442c9e6SMilanka Ringwald * are met: 8*b442c9e6SMilanka Ringwald * 9*b442c9e6SMilanka Ringwald * 1. Redistributions of source code must retain the above copyright 10*b442c9e6SMilanka Ringwald * notice, this list of conditions and the following disclaimer. 11*b442c9e6SMilanka Ringwald * 2. Redistributions in binary form must reproduce the above copyright 12*b442c9e6SMilanka Ringwald * notice, this list of conditions and the following disclaimer in the 13*b442c9e6SMilanka Ringwald * documentation and/or other materials provided with the distribution. 14*b442c9e6SMilanka Ringwald * 3. Neither the name of the copyright holders nor the names of 15*b442c9e6SMilanka Ringwald * contributors may be used to endorse or promote products derived 16*b442c9e6SMilanka Ringwald * from this software without specific prior written permission. 17*b442c9e6SMilanka Ringwald * 4. Any redistribution, use, or modification is done solely for 18*b442c9e6SMilanka Ringwald * personal benefit and not for any commercial purpose or for 19*b442c9e6SMilanka Ringwald * monetary gain. 20*b442c9e6SMilanka Ringwald * 21*b442c9e6SMilanka Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 22*b442c9e6SMilanka Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*b442c9e6SMilanka Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*b442c9e6SMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 25*b442c9e6SMilanka Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*b442c9e6SMilanka Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*b442c9e6SMilanka Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*b442c9e6SMilanka Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29*b442c9e6SMilanka Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30*b442c9e6SMilanka Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 31*b442c9e6SMilanka Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*b442c9e6SMilanka Ringwald * SUCH DAMAGE. 33*b442c9e6SMilanka Ringwald * 34*b442c9e6SMilanka Ringwald * Please inquire about commercial licensing options at 35*b442c9e6SMilanka Ringwald * [email protected] 36*b442c9e6SMilanka Ringwald * 37*b442c9e6SMilanka Ringwald */ 38*b442c9e6SMilanka Ringwald 39*b442c9e6SMilanka Ringwald #define __BTSTACK_FILE__ "a2dp_source.c" 40*b442c9e6SMilanka Ringwald 41*b442c9e6SMilanka Ringwald #include <stdint.h> 42*b442c9e6SMilanka Ringwald #include <stdio.h> 43*b442c9e6SMilanka Ringwald #include <stdlib.h> 44*b442c9e6SMilanka Ringwald #include <string.h> 45*b442c9e6SMilanka Ringwald #include <unistd.h> 46*b442c9e6SMilanka Ringwald 47*b442c9e6SMilanka Ringwald #include "btstack.h" 48*b442c9e6SMilanka Ringwald #include "avdtp.h" 49*b442c9e6SMilanka Ringwald #include "avdtp_util.h" 50*b442c9e6SMilanka Ringwald #include "avdtp_source.h" 51*b442c9e6SMilanka Ringwald #include "a2dp_source.h" 52*b442c9e6SMilanka Ringwald 53*b442c9e6SMilanka Ringwald static const char * default_a2dp_source_service_name = "BTstack A2DP Source Service"; 54*b442c9e6SMilanka Ringwald static const char * default_a2dp_source_service_provider_name = "BTstack A2DP Source Service Provider"; 55*b442c9e6SMilanka Ringwald 56*b442c9e6SMilanka Ringwald // static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 57*b442c9e6SMilanka Ringwald 58*b442c9e6SMilanka Ringwald 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){ 59*b442c9e6SMilanka Ringwald uint8_t* attribute; 60*b442c9e6SMilanka Ringwald de_create_sequence(service); 61*b442c9e6SMilanka Ringwald 62*b442c9e6SMilanka Ringwald // 0x0000 "Service Record Handle" 63*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE); 64*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle); 65*b442c9e6SMilanka Ringwald 66*b442c9e6SMilanka Ringwald // 0x0001 "Service Class ID List" 67*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST); 68*b442c9e6SMilanka Ringwald attribute = de_push_sequence(service); 69*b442c9e6SMilanka Ringwald { 70*b442c9e6SMilanka Ringwald de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_AUDIO_SOURCE); 71*b442c9e6SMilanka Ringwald } 72*b442c9e6SMilanka Ringwald de_pop_sequence(service, attribute); 73*b442c9e6SMilanka Ringwald 74*b442c9e6SMilanka Ringwald // 0x0004 "Protocol Descriptor List" 75*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST); 76*b442c9e6SMilanka Ringwald attribute = de_push_sequence(service); 77*b442c9e6SMilanka Ringwald { 78*b442c9e6SMilanka Ringwald uint8_t* l2cpProtocol = de_push_sequence(attribute); 79*b442c9e6SMilanka Ringwald { 80*b442c9e6SMilanka Ringwald de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP); 81*b442c9e6SMilanka Ringwald de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, BLUETOOTH_PROTOCOL_AVDTP); 82*b442c9e6SMilanka Ringwald } 83*b442c9e6SMilanka Ringwald de_pop_sequence(attribute, l2cpProtocol); 84*b442c9e6SMilanka Ringwald 85*b442c9e6SMilanka Ringwald uint8_t* avProtocol = de_push_sequence(attribute); 86*b442c9e6SMilanka Ringwald { 87*b442c9e6SMilanka Ringwald de_add_number(avProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_AVDTP); // avProtocol_service 88*b442c9e6SMilanka Ringwald de_add_number(avProtocol, DE_UINT, DE_SIZE_16, 0x0103); // version 89*b442c9e6SMilanka Ringwald } 90*b442c9e6SMilanka Ringwald de_pop_sequence(attribute, avProtocol); 91*b442c9e6SMilanka Ringwald } 92*b442c9e6SMilanka Ringwald de_pop_sequence(service, attribute); 93*b442c9e6SMilanka Ringwald 94*b442c9e6SMilanka Ringwald // 0x0005 "Public Browse Group" 95*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BROWSE_GROUP_LIST); // public browse group 96*b442c9e6SMilanka Ringwald attribute = de_push_sequence(service); 97*b442c9e6SMilanka Ringwald { 98*b442c9e6SMilanka Ringwald de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT); 99*b442c9e6SMilanka Ringwald } 100*b442c9e6SMilanka Ringwald de_pop_sequence(service, attribute); 101*b442c9e6SMilanka Ringwald 102*b442c9e6SMilanka Ringwald // 0x0009 "Bluetooth Profile Descriptor List" 103*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST); 104*b442c9e6SMilanka Ringwald attribute = de_push_sequence(service); 105*b442c9e6SMilanka Ringwald { 106*b442c9e6SMilanka Ringwald uint8_t *a2dProfile = de_push_sequence(attribute); 107*b442c9e6SMilanka Ringwald { 108*b442c9e6SMilanka Ringwald de_add_number(a2dProfile, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION); 109*b442c9e6SMilanka Ringwald de_add_number(a2dProfile, DE_UINT, DE_SIZE_16, 0x0103); 110*b442c9e6SMilanka Ringwald } 111*b442c9e6SMilanka Ringwald de_pop_sequence(attribute, a2dProfile); 112*b442c9e6SMilanka Ringwald } 113*b442c9e6SMilanka Ringwald de_pop_sequence(service, attribute); 114*b442c9e6SMilanka Ringwald 115*b442c9e6SMilanka Ringwald 116*b442c9e6SMilanka Ringwald // 0x0100 "Service Name" 117*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100); 118*b442c9e6SMilanka Ringwald if (service_name){ 119*b442c9e6SMilanka Ringwald de_add_data(service, DE_STRING, strlen(service_name), (uint8_t *) service_name); 120*b442c9e6SMilanka Ringwald } else { 121*b442c9e6SMilanka Ringwald de_add_data(service, DE_STRING, strlen(default_a2dp_source_service_name), (uint8_t *) default_a2dp_source_service_name); 122*b442c9e6SMilanka Ringwald } 123*b442c9e6SMilanka Ringwald 124*b442c9e6SMilanka Ringwald // 0x0100 "Provider Name" 125*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, 0x0102); 126*b442c9e6SMilanka Ringwald if (service_provider_name){ 127*b442c9e6SMilanka Ringwald de_add_data(service, DE_STRING, strlen(service_provider_name), (uint8_t *) service_provider_name); 128*b442c9e6SMilanka Ringwald } else { 129*b442c9e6SMilanka Ringwald de_add_data(service, DE_STRING, strlen(default_a2dp_source_service_provider_name), (uint8_t *) default_a2dp_source_service_provider_name); 130*b442c9e6SMilanka Ringwald } 131*b442c9e6SMilanka Ringwald 132*b442c9e6SMilanka Ringwald // 0x0311 "Supported Features" 133*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, 0x0311); 134*b442c9e6SMilanka Ringwald de_add_number(service, DE_UINT, DE_SIZE_16, supported_features); 135*b442c9e6SMilanka Ringwald } 136*b442c9e6SMilanka Ringwald 137*b442c9e6SMilanka Ringwald // static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 138*b442c9e6SMilanka Ringwald // } 139