xref: /btstack/src/classic/gatt_sdp.c (revision 84e3541e4b5ea68a774e8e8a4f738501f48cf864)
1e5836bafSMatthias Ringwald /*
2e5836bafSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3e5836bafSMatthias Ringwald  *
4e5836bafSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5e5836bafSMatthias Ringwald  * modification, are permitted provided that the following conditions
6e5836bafSMatthias Ringwald  * are met:
7e5836bafSMatthias Ringwald  *
8e5836bafSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9e5836bafSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10e5836bafSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11e5836bafSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12e5836bafSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13e5836bafSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14e5836bafSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15e5836bafSMatthias Ringwald  *    from this software without specific prior written permission.
16e5836bafSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17e5836bafSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18e5836bafSMatthias Ringwald  *    monetary gain.
19e5836bafSMatthias Ringwald  *
20e5836bafSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21e5836bafSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22e5836bafSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23e5836bafSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24e5836bafSMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25e5836bafSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26e5836bafSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27e5836bafSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28e5836bafSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29e5836bafSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30e5836bafSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31e5836bafSMatthias Ringwald  * SUCH DAMAGE.
32e5836bafSMatthias Ringwald  *
33e5836bafSMatthias Ringwald  * Please inquire about commercial licensing options at
34e5836bafSMatthias Ringwald  * [email protected]
35e5836bafSMatthias Ringwald  *
36e5836bafSMatthias Ringwald  */
37e5836bafSMatthias Ringwald 
38e5836bafSMatthias Ringwald #define BTSTACK_FILE__ "gatt_sdp.c"
39e5836bafSMatthias Ringwald 
40e5836bafSMatthias Ringwald /*
41e5836bafSMatthias Ringwald  *  gatt_sdp.c
42e5836bafSMatthias Ringwald  */
43e5836bafSMatthias Ringwald 
44e5836bafSMatthias Ringwald #include "gatt_sdp.h"
45e5836bafSMatthias Ringwald 
46e5836bafSMatthias Ringwald #include <stdio.h>
47e5836bafSMatthias Ringwald #include <string.h>
48e5836bafSMatthias Ringwald 
49*84e3541eSMilanka Ringwald #include "bluetooth_gatt.h"
50*84e3541eSMilanka Ringwald #include "bluetooth_psm.h"
51e5836bafSMatthias Ringwald #include "bluetooth_sdp.h"
52e5836bafSMatthias Ringwald #include "btstack_config.h"
53e5836bafSMatthias Ringwald #include "classic/core.h"
54e5836bafSMatthias Ringwald #include "classic/sdp_util.h"
55*84e3541eSMilanka Ringwald #include "l2cap.h"
56e5836bafSMatthias Ringwald 
57e5836bafSMatthias Ringwald void gatt_create_sdp_record(uint8_t *service, uint32_t service_record_handle, uint16_t gatt_start_handle, uint16_t gatt_end_handle){
58e5836bafSMatthias Ringwald 
59e5836bafSMatthias Ringwald     uint8_t* attribute;
60e5836bafSMatthias Ringwald     de_create_sequence(service);
61e5836bafSMatthias Ringwald 
62e5836bafSMatthias Ringwald     // 0x0000 "Service Record Handle"
63e5836bafSMatthias Ringwald     de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE);
64e5836bafSMatthias Ringwald     de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
65e5836bafSMatthias Ringwald 
66e5836bafSMatthias Ringwald     // 0x0001 "Service Class ID List"
67e5836bafSMatthias Ringwald     de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST);
68e5836bafSMatthias Ringwald     attribute = de_push_sequence(service);
69e5836bafSMatthias Ringwald     {
70e5836bafSMatthias Ringwald         de_add_number(attribute, DE_UUID, DE_SIZE_32, ORG_BLUETOOTH_SERVICE_GENERIC_ATTRIBUTE);
71e5836bafSMatthias Ringwald     }
72e5836bafSMatthias Ringwald     de_pop_sequence(service, attribute);
73e5836bafSMatthias Ringwald 
74e5836bafSMatthias Ringwald     // 0x0004 "Protocol Descriptor List"
75e5836bafSMatthias Ringwald     de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST);
76e5836bafSMatthias Ringwald     attribute = de_push_sequence(service);
77e5836bafSMatthias Ringwald     {
78e5836bafSMatthias Ringwald         uint8_t* l2cap_protocol = de_push_sequence(attribute);
79e5836bafSMatthias Ringwald         {
80e5836bafSMatthias Ringwald             de_add_number(l2cap_protocol,  DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
81*84e3541eSMilanka Ringwald             de_add_number(l2cap_protocol,  DE_UINT, DE_SIZE_16, BLUETOOTH_PSM_ATT);
82e5836bafSMatthias Ringwald         }
83e5836bafSMatthias Ringwald         de_pop_sequence(attribute, l2cap_protocol);
84e5836bafSMatthias Ringwald 
85e5836bafSMatthias Ringwald         uint8_t* att_protocol = de_push_sequence(attribute);
86e5836bafSMatthias Ringwald         {
87e5836bafSMatthias Ringwald             de_add_number(att_protocol,  DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_ATT);
88e5836bafSMatthias Ringwald             de_add_number(att_protocol,  DE_UINT, DE_SIZE_16, gatt_start_handle);
89e5836bafSMatthias Ringwald             de_add_number(att_protocol,  DE_UINT, DE_SIZE_16, gatt_end_handle);
90e5836bafSMatthias Ringwald 
91e5836bafSMatthias Ringwald         }
92e5836bafSMatthias Ringwald         de_pop_sequence(attribute, att_protocol);
93e5836bafSMatthias Ringwald     }
94e5836bafSMatthias Ringwald     de_pop_sequence(service, attribute);
95e5836bafSMatthias Ringwald 
96e5836bafSMatthias Ringwald     // 0x0005 "Public Browse Group"
97e5836bafSMatthias Ringwald     de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BROWSE_GROUP_LIST);
98e5836bafSMatthias Ringwald     attribute = de_push_sequence(service);
99e5836bafSMatthias Ringwald     {
100e5836bafSMatthias Ringwald         de_add_number(attribute,  DE_UUID, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT);
101e5836bafSMatthias Ringwald     }
102e5836bafSMatthias Ringwald     de_pop_sequence(service, attribute);
103e5836bafSMatthias Ringwald }
104