1 /* $NetBSD: sd.c,v 1.2 2007/11/09 20:08:41 plunky Exp $ */
6 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $Id: sd.c,v 1.2 2007/11/30 07:39:37 griffin Exp $
31 * $FreeBSD: src/usr.sbin/bluetooth/sdpd/sd.c,v 1.1 2004/01/20 20:48:26 emax Exp $
34 #include <sys/queue.h>
35 #include <bluetooth.h>
42 sd_profile_create_service_class_id_list(
43 uint8_t *buf
, uint8_t const * const eob
,
44 uint8_t const *data
, uint32_t datalen
)
46 static uint16_t service_classes
[] = {
47 SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER
50 return (common_profile_create_service_class_id_list(
52 (uint8_t const *) service_classes
,
53 sizeof(service_classes
)));
57 sd_profile_create_service_id(
58 uint8_t *buf
, uint8_t const * const eob
,
59 uint8_t const *data
, uint32_t datalen
)
65 * The ServiceID is a UUID that universally and uniquely identifies
66 * the service instance described by the service record. This service
67 * attribute is particularly useful if the same service is described
68 * by service records in more than one SDP server
71 SDP_PUT8(SDP_DATA_UUID16
, buf
);
72 SDP_PUT16(SDP_UUID_PROTOCOL_SDP
, buf
); /* XXX ??? */
78 sd_profile_create_service_name(
79 uint8_t *buf
, uint8_t const * const eob
,
80 uint8_t const *data
, uint32_t datalen
)
82 static char service_name
[] = "Bluetooth service discovery";
84 return (common_profile_create_string8(
86 (uint8_t const *) service_name
, strlen(service_name
)));
90 sd_profile_create_protocol_descriptor_list(
91 uint8_t *buf
, uint8_t const * const eob
,
92 uint8_t const *data
, uint32_t datalen
)
97 SDP_PUT8(SDP_DATA_SEQ8
, buf
);
100 SDP_PUT8(SDP_DATA_SEQ8
, buf
);
103 SDP_PUT8(SDP_DATA_UUID16
, buf
);
104 SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP
, buf
);
106 SDP_PUT8(SDP_DATA_UINT16
, buf
);
107 SDP_PUT16(L2CAP_PSM_SDP
, buf
);
109 SDP_PUT8(SDP_DATA_UINT16
, buf
);
110 SDP_PUT16(1, buf
); /* version */
116 sd_profile_create_browse_group_list(
117 uint8_t *buf
, uint8_t const * const eob
,
118 uint8_t const *data
, uint32_t datalen
)
123 SDP_PUT8(SDP_DATA_SEQ8
, buf
);
127 * The top-level browse group ID, called PublicBrowseRoot and
128 * representing the root of the browsing hierarchy, has the value
129 * 00001002-0000-1000-8000-00805F9B34FB (UUID16: 0x1002) from the
130 * Bluetooth Assigned Numbers document
133 SDP_PUT8(SDP_DATA_UUID16
, buf
);
134 SDP_PUT16(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP
, buf
);
140 sd_profile_create_version_number_list(
141 uint8_t *buf
, uint8_t const * const eob
,
142 uint8_t const *data
, uint32_t datalen
)
147 SDP_PUT8(SDP_DATA_SEQ8
, buf
);
151 * The VersionNumberList is a data element sequence in which each
152 * element of the sequence is a version number supported by the SDP
153 * server. A version number is a 16-bit unsigned integer consisting
154 * of two fields. The higher-order 8 bits contain the major version
155 * number field and the low-order 8 bits contain the minor version
156 * number field. The initial version of SDP has a major version of
157 * 1 and a minor version of 0
160 SDP_PUT8(SDP_DATA_UINT16
, buf
);
161 SDP_PUT16(0x0100, buf
);
167 sd_profile_create_service_database_state(
168 uint8_t *buf
, uint8_t const * const eob
,
169 uint8_t const *data
, uint32_t datalen
)
171 uint32_t change_state
= provider_get_change_state();
176 SDP_PUT8(SDP_DATA_UINT32
, buf
);
177 SDP_PUT32(change_state
, buf
);
182 static attr_t sd_profile_attrs
[] = {
183 { SDP_ATTR_SERVICE_RECORD_HANDLE
,
184 common_profile_create_service_record_handle
},
185 { SDP_ATTR_SERVICE_CLASS_ID_LIST
,
186 sd_profile_create_service_class_id_list
},
187 { SDP_ATTR_SERVICE_ID
,
188 sd_profile_create_service_id
},
189 { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST
,
190 common_profile_create_language_base_attribute_id_list
},
191 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID
+ SDP_ATTR_SERVICE_NAME_OFFSET
,
192 sd_profile_create_service_name
},
193 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID
+ SDP_ATTR_SERVICE_DESCRIPTION_OFFSET
,
194 sd_profile_create_service_name
},
195 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID
+ SDP_ATTR_PROVIDER_NAME_OFFSET
,
196 common_profile_create_service_provider_name
},
197 { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST
,
198 sd_profile_create_protocol_descriptor_list
},
199 { SDP_ATTR_BROWSE_GROUP_LIST
,
200 sd_profile_create_browse_group_list
},
201 { SDP_ATTR_VERSION_NUMBER_LIST
,
202 sd_profile_create_version_number_list
},
203 { SDP_ATTR_SERVICE_DATABASE_STATE
,
204 sd_profile_create_service_database_state
},
205 { 0, NULL
} /* end entry */
208 static uint16_t sd_profile_uuids
[] = {
209 SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER
,
210 SDP_UUID_PROTOCOL_L2CAP
,
213 profile_t sd_profile_descriptor
= {
215 sizeof(sd_profile_uuids
),
218 (attr_t
const * const) &sd_profile_attrs