xref: /btstack/src/classic/spp_server.c (revision 4c7b5f7454ef118efc1f5c21f6607e2939cfc1cc)
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  *  spp_server.c
40  *
41  * Create SPP SDP Records
42  */
43 
44 #include "spp_server.h"
45 
46 #include <string.h>
47 
48 #include "bluetooth.h"
49 #include "classic/sdp_util.h"
50 
51 void spp_create_sdp_record(uint8_t *service, uint32_t service_record_handle, int rfcomm_channel, const char *name){
52 
53 	uint8_t* attribute;
54 	de_create_sequence(service);
55 
56     // 0x0000 "Service Record Handle"
57 	de_add_number(service, DE_UINT, DE_SIZE_16, SDP_ServiceRecordHandle);
58 	de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
59 
60 	// 0x0001 "Service Class ID List"
61 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_ServiceClassIDList);
62 	attribute = de_push_sequence(service);
63 	{
64 		de_add_number(attribute,  DE_UUID, DE_SIZE_16, 0x1101 );
65 	}
66 	de_pop_sequence(service, attribute);
67 
68 	// 0x0004 "Protocol Descriptor List"
69 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_ProtocolDescriptorList);
70 	attribute = de_push_sequence(service);
71 	{
72 		uint8_t* l2cpProtocol = de_push_sequence(attribute);
73 		{
74 			de_add_number(l2cpProtocol,  DE_UUID, DE_SIZE_16, SDP_L2CAPProtocol);
75 		}
76 		de_pop_sequence(attribute, l2cpProtocol);
77 
78 		uint8_t* rfcomm = de_push_sequence(attribute);
79 		{
80 			de_add_number(rfcomm,  DE_UUID, DE_SIZE_16, SDP_RFCOMMProtocol);  // rfcomm_service
81 			de_add_number(rfcomm,  DE_UINT, DE_SIZE_8,  rfcomm_channel);  // rfcomm channel
82 		}
83 		de_pop_sequence(attribute, rfcomm);
84 	}
85 	de_pop_sequence(service, attribute);
86 
87 	// 0x0005 "Public Browse Group"
88 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_BrowseGroupList); // public browse group
89 	attribute = de_push_sequence(service);
90 	{
91 		de_add_number(attribute,  DE_UUID, DE_SIZE_16, 0x1002 );
92 	}
93 	de_pop_sequence(service, attribute);
94 
95 	// 0x0006
96 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_LanguageBaseAttributeIDList);
97 	attribute = de_push_sequence(service);
98 	{
99 		de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x656e);
100 		de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x006a);
101 		de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x0100);
102 	}
103 	de_pop_sequence(service, attribute);
104 
105 	// 0x0009 "Bluetooth Profile Descriptor List"
106 	de_add_number(service,  DE_UINT, DE_SIZE_16, SDP_BluetoothProfileDescriptorList);
107 	attribute = de_push_sequence(service);
108 	{
109 		uint8_t *sppProfile = de_push_sequence(attribute);
110 		{
111 			de_add_number(sppProfile,  DE_UUID, DE_SIZE_16, 0x1101);
112 			de_add_number(sppProfile,  DE_UINT, DE_SIZE_16, 0x0102);
113 		}
114 		de_pop_sequence(attribute, sppProfile);
115 	}
116 	de_pop_sequence(service, attribute);
117 
118 	// 0x0100 "ServiceName"
119 	de_add_number(service,  DE_UINT, DE_SIZE_16, 0x0100);
120 	de_add_data(service,  DE_STRING, strlen(name), (uint8_t *) name);
121 }