xref: /btstack/src/classic/device_id_server.c (revision f9f2075ceac5e9dc08e9abea437e43d733a3a0ea)
1 /*
2  * Copyright (C) 2014 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  * device_id_server.c
40  *
41  * Creates Device ID SDP Records
42  */
43 
44 #include "classic/device_id_server.h"
45 
46 #include <string.h>
47 
48 #include "bluetooth.h"
49 #include "bluetooth_sdp.h"
50 #include "btstack_config.h"
51 #include "classic/core.h"
52 #include "classic/sdp_util.h"
53 
54 void device_id_create_sdp_record(uint8_t *service, uint32_t service_record_handle, uint16_t vendor_id_source, uint16_t vendor_id, uint16_t product_id, uint16_t version){
55 
56 	uint8_t* attribute;
57 	de_create_sequence(service);
58 
59     // 0x0000 "Service Record Handle"
60 	de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE);
61 	de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
62 
63 	// 0x0001 "Service Class ID List"
64 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST);
65 	attribute = de_push_sequence(service);
66 	{
67 		de_add_number(attribute,  DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_PNP_INFORMATION );
68 	}
69 	de_pop_sequence(service, attribute);
70 
71 	// 0x0005 "Public Browse Group"
72 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_BrowseGroupList); // public browse group
73 	attribute = de_push_sequence(service);
74 	{
75 		de_add_number(attribute,  DE_UUID, DE_SIZE_16, SDP_PublicBrowseGroup );
76 	}
77 	de_pop_sequence(service, attribute);
78 
79 	// 0x0200 "SpecificationID"
80 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SPECIFICATION_ID);
81 	de_add_number(service,  DE_UINT, DE_SIZE_16, 0x0103);	// v1.3
82 
83 	// 0x0201 "VendorID"
84 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_VENDOR_ID);
85 	de_add_number(service,  DE_UINT, DE_SIZE_16, vendor_id);
86 
87 	// 0x0202 "ProductID"
88 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PRODUCT_ID);
89 	de_add_number(service,  DE_UINT, DE_SIZE_16, product_id);
90 
91 	// 0x0203 "Version"
92 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_VERSION);
93 	de_add_number(service,  DE_UINT, DE_SIZE_16, version);
94 
95 	// 0x0204 "PrimaryRecord"
96 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PRIMARY_RECORD);
97 	de_add_number(service,  DE_UINT, DE_SIZE_16, 1);	// yes, this is the primary record - there are no others
98 
99 	// 0x0205 "VendorIDSource"
100 	de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_VENDOR_ID_SOURCE);
101 	de_add_number(service,  DE_UINT, DE_SIZE_16, vendor_id_source);
102 }