save/restore cr2, cr3 from vmcb
[freebsd-src/fkvm-freebsd.git] / usr.sbin / bluetooth / sdpd / sd.c
blob52f6c953bd09076319aabd04897c7f5a484d3d3f
1 /*
2 * sd.c
4 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $Id: sd.c,v 1.4 2004/01/13 01:54:39 max Exp $
29 * $FreeBSD$
32 #include <sys/queue.h>
33 #include <bluetooth.h>
34 #include <sdp.h>
35 #include <string.h>
36 #include "profile.h"
37 #include "provider.h"
39 static int32_t
40 sd_profile_create_service_class_id_list(
41 uint8_t *buf, uint8_t const * const eob,
42 uint8_t const *data, uint32_t datalen)
44 static uint16_t service_classes[] = {
45 SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER
48 return (common_profile_create_service_class_id_list(
49 buf, eob,
50 (uint8_t const *) service_classes,
51 sizeof(service_classes)));
54 static int32_t
55 sd_profile_create_service_id(
56 uint8_t *buf, uint8_t const * const eob,
57 uint8_t const *data, uint32_t datalen)
59 if (buf + 3 > eob)
60 return (-1);
63 * The ServiceID is a UUID that universally and uniquely identifies
64 * the service instance described by the service record. This service
65 * attribute is particularly useful if the same service is described
66 * by service records in more than one SDP server
69 SDP_PUT8(SDP_DATA_UUID16, buf);
70 SDP_PUT16(SDP_UUID_PROTOCOL_SDP, buf); /* XXX ??? */
72 return (3);
75 static int32_t
76 sd_profile_create_service_name(
77 uint8_t *buf, uint8_t const * const eob,
78 uint8_t const *data, uint32_t datalen)
80 static char service_name[] = "Bluetooth service discovery";
82 return (common_profile_create_string8(
83 buf, eob,
84 (uint8_t const *) service_name, strlen(service_name)));
87 static int32_t
88 sd_profile_create_protocol_descriptor_list(
89 uint8_t *buf, uint8_t const * const eob,
90 uint8_t const *data, uint32_t datalen)
92 if (buf + 13 > eob)
93 return (-1);
95 SDP_PUT8(SDP_DATA_SEQ8, buf);
96 SDP_PUT8(11, buf);
98 SDP_PUT8(SDP_DATA_SEQ8, buf);
99 SDP_PUT8(9, buf);
101 SDP_PUT8(SDP_DATA_UUID16, buf);
102 SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP, buf);
104 SDP_PUT8(SDP_DATA_UINT16, buf);
105 SDP_PUT16(NG_L2CAP_PSM_SDP, buf);
107 SDP_PUT8(SDP_DATA_UINT16, buf);
108 SDP_PUT16(1, buf); /* version */
110 return (13);
113 static int32_t
114 sd_profile_create_browse_group_list(
115 uint8_t *buf, uint8_t const * const eob,
116 uint8_t const *data, uint32_t datalen)
118 if (buf + 5 > eob)
119 return (-1);
121 SDP_PUT8(SDP_DATA_SEQ8, buf);
122 SDP_PUT8(3, buf);
125 * The top-level browse group ID, called PublicBrowseRoot and
126 * representing the root of the browsing hierarchy, has the value
127 * 00001002-0000-1000-8000-00805F9B34FB (UUID16: 0x1002) from the
128 * Bluetooth Assigned Numbers document
131 SDP_PUT8(SDP_DATA_UUID16, buf);
132 SDP_PUT16(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP, buf);
134 return (5);
137 static int32_t
138 sd_profile_create_version_number_list(
139 uint8_t *buf, uint8_t const * const eob,
140 uint8_t const *data, uint32_t datalen)
142 if (buf + 5 > eob)
143 return (-1);
145 SDP_PUT8(SDP_DATA_SEQ8, buf);
146 SDP_PUT8(3, buf);
149 * The VersionNumberList is a data element sequence in which each
150 * element of the sequence is a version number supported by the SDP
151 * server. A version number is a 16-bit unsigned integer consisting
152 * of two fields. The higher-order 8 bits contain the major version
153 * number field and the low-order 8 bits contain the minor version
154 * number field. The initial version of SDP has a major version of
155 * 1 and a minor version of 0
158 SDP_PUT8(SDP_DATA_UINT16, buf);
159 SDP_PUT16(0x0100, buf);
161 return (5);
164 static int32_t
165 sd_profile_create_service_database_state(
166 uint8_t *buf, uint8_t const * const eob,
167 uint8_t const *data, uint32_t datalen)
169 uint32_t change_state = provider_get_change_state();
171 if (buf + 5 > eob)
172 return (-1);
174 SDP_PUT8(SDP_DATA_UINT32, buf);
175 SDP_PUT32(change_state, buf);
177 return (5);
180 static attr_t sd_profile_attrs[] = {
181 { SDP_ATTR_SERVICE_RECORD_HANDLE,
182 common_profile_create_service_record_handle },
183 { SDP_ATTR_SERVICE_CLASS_ID_LIST,
184 sd_profile_create_service_class_id_list },
185 { SDP_ATTR_SERVICE_ID,
186 sd_profile_create_service_id },
187 { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
188 common_profile_create_language_base_attribute_id_list },
189 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET,
190 sd_profile_create_service_name },
191 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET,
192 sd_profile_create_service_name },
193 { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_PROVIDER_NAME_OFFSET,
194 common_profile_create_service_provider_name },
195 { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
196 sd_profile_create_protocol_descriptor_list },
197 { SDP_ATTR_BROWSE_GROUP_LIST,
198 sd_profile_create_browse_group_list },
199 { SDP_ATTR_VERSION_NUMBER_LIST,
200 sd_profile_create_version_number_list },
201 { SDP_ATTR_SERVICE_DATABASE_STATE,
202 sd_profile_create_service_database_state },
203 { 0, NULL } /* end entry */
206 profile_t sd_profile_descriptor = {
207 SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER,
209 (profile_data_valid_p) NULL,
210 (attr_t const * const) &sd_profile_attrs