xref: /btstack/src/classic/sdp_util.h (revision 3edc84c5b6b1e23a3d103fe8ce1f6b5ad1df3498)
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  *  sdp_util.h
40  */
41 
42 #ifndef __SDP_UTIL_H
43 #define __SDP_UTIL_H
44 
45 #include <stdint.h>
46 
47 #if defined __cplusplus
48 extern "C" {
49 #endif
50 
51 /* API_START */
52 
53 // UNIVERSAL ATTRIBUTE DEFINITIONS
54 #define SDP_ServiceRecordHandle     0x0000
55 #define SDP_ServiceClassIDList      0x0001
56 #define SDP_ServiceRecordState      0x0002
57 #define SDP_ServiceID               0x0003
58 #define SDP_ProtocolDescriptorList  0x0004
59 #define SDP_BrowseGroupList		    0x0005
60 #define SDP_LanguageBaseAttributeIDList 0x0006
61 #define SDP_ServiceInfoTimeToLive	0x0007
62 #define SDP_ServiceAvailability		0x0008
63 #define SDP_BluetoothProfileDescriptorList 0x0009
64 #define SDP_DocumentationURL		0x000a
65 #define SDP_ClientExecutableURL     0x000b
66 #define SDP_IconURL                 0x000c
67 #define SDP_AdditionalProtocolDescriptorList 0x000d
68 #define SDP_SupportedFormatsList    0x0303
69 
70 // SERVICE CLASSES
71 #define SDP_OBEXObjectPush          0x1105
72 #define SDP_OBEXFileTransfer        0x1106
73 #define SDP_PublicBrowseGroup       0x1002
74 #define SDP_HSP                     0x1108
75 #define SDP_Headset_AG              0x1112
76 #define SDP_PANU                    0x1115
77 #define SDP_NAP                     0x1116
78 #define SDP_GN                      0x1117
79 #define SDP_Handsfree               0x111E
80 #define SDP_HandsfreeAudioGateway   0x111F
81 #define SDP_Headset_HS              0x1131
82 #define SDP_GenericAudio            0x1203
83 
84 
85 // PROTOCOLS
86 #define SDP_SDPProtocol       0x0001
87 #define SDP_UDPProtocol       0x0002
88 #define SDP_RFCOMMProtocol    0x0003
89 #define SDP_OBEXProtocol      0x0008
90 #define SDP_L2CAPProtocol     0x0100
91 #define SDP_BNEPProtocol      0x000F
92 #define SDP_AVDTPProtocol     0x0019
93 
94 // OFFSETS FOR LOCALIZED ATTRIBUTES - SDP_LanguageBaseAttributeIDList
95 #define SDP_Offest_ServiceName      0x0000
96 #define SDP_Offest_ServiceDescription 0x0001
97 #define SDP_Offest_ProviderName     0x0002
98 
99 // OBEX
100 #define SDP_vCard_2_1       0x01
101 #define SDP_vCard_3_0       0x02
102 #define SDP_vCal_1_0        0x03
103 #define SDP_iCal_2_0        0x04
104 #define SDP_vNote           0x05
105 #define SDP_vMessage        0x06
106 #define SDP_OBEXFileTypeAny 0xFF
107 
108 
109 typedef enum {
110     DE_NIL = 0,
111     DE_UINT,
112     DE_INT,
113     DE_UUID,
114     DE_STRING,
115     DE_BOOL,
116     DE_DES,
117     DE_DEA,
118     DE_URL
119 } de_type_t;
120 
121 typedef enum {
122     DE_SIZE_8 = 0,
123     DE_SIZE_16,
124     DE_SIZE_32,
125     DE_SIZE_64,
126     DE_SIZE_128,
127     DE_SIZE_VAR_8,
128     DE_SIZE_VAR_16,
129     DE_SIZE_VAR_32
130 } de_size_t;
131 
132 // MARK: DateElement
133 void      de_dump_data_element(uint8_t * record);
134 int       de_get_len(uint8_t *header);
135 de_size_t de_get_size_type(uint8_t *header);
136 de_type_t de_get_element_type(uint8_t *header);
137 int       de_get_header_size(uint8_t * header);
138 void      de_create_sequence(uint8_t *header);
139 void      de_store_descriptor_with_len(uint8_t * header, de_type_t type, de_size_t size, uint32_t len);
140 uint8_t * de_push_sequence(uint8_t *header);
141 void      de_pop_sequence(uint8_t * parent, uint8_t * child);
142 void      de_add_number(uint8_t *seq, de_type_t type, de_size_t size, uint32_t value);
143 void      de_add_data( uint8_t *seq, de_type_t type, uint16_t size, uint8_t *data);
144 int       de_element_get_uint16(uint8_t * element, uint16_t * value);
145 
146 int       de_get_data_size(uint8_t * header);
147 void      de_add_uuid128(uint8_t * seq, uint8_t * uuid);
148 uint32_t  de_get_uuid32(uint8_t * element);
149 int       de_get_normalized_uuid(uint8_t *uuid128, uint8_t *element);
150 
151 // MARK: DES iterator
152 typedef struct {
153     uint8_t * element;
154     uint16_t pos;
155     uint16_t length;
156 } des_iterator_t;
157 
158 int des_iterator_init(des_iterator_t * it, uint8_t * element);
159 int  des_iterator_has_more(des_iterator_t * it);
160 de_type_t des_iterator_get_type (des_iterator_t * it);
161 uint16_t des_iterator_get_size (des_iterator_t * it);
162 uint8_t * des_iterator_get_element(des_iterator_t * it);
163 void des_iterator_next(des_iterator_t * it);
164 
165 // MARK: SDP
166 uint16_t  sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startOffset, uint16_t maxBytes, uint8_t *buffer);
167 uint8_t * sdp_get_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID);
168 uint8_t   sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value);
169 int       sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern);
170 int       spd_get_filtered_size(uint8_t *record, uint8_t *attributeIDList);
171 int       sdp_filter_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startOffset, uint16_t maxBytes, uint16_t *usedBytes, uint8_t *buffer);
172 int       sdp_attribute_list_constains_id(uint8_t *attributeIDList, uint16_t attributeID);
173 int       sdp_traversal_match_pattern(uint8_t * element, de_type_t attributeType, de_size_t size, void *my_context);
174 
175 void      sdp_create_spp_service(uint8_t *service, int service_id, const char *name);
176 
177 /* API_END */
178 
179 #if defined __cplusplus
180 }
181 #endif
182 
183 #endif // __SDP_UTIL_H
184