1 /* $NetBSD: sdp_record.c$ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: sdp_record.c$");
44 * This is the interface to sdpd(8); These PDU IDs are NOT part
45 * of the Bluetooth specification.
49 sdp_record_insert(struct sdp_session
*ss
, bdaddr_t
*bdaddr
,
50 uint32_t *handle
, const sdp_data_t
*rec
)
60 * setup BluetoothDeviceAddress
62 bdaddr_copy(&ba
, (bdaddr
== NULL
) ? BDADDR_ANY
: bdaddr
);
63 req
[1].iov_base
= &ba
;
64 req
[1].iov_len
= sizeof(bdaddr_t
);
69 len
= rec
->end
- rec
->next
;
70 if (len
< 0 || len
> UINT16_MAX
) {
76 hdr
.end
= data
+ sizeof(data
) + len
;
77 sdp_put_seq(&hdr
, len
);
78 req
[2].iov_base
= data
;
79 req
[2].iov_len
= hdr
.next
- data
;
81 req
[3].iov_base
= rec
->next
;
85 * InsertRecord Transaction
87 if (!_sdp_send_pdu(ss
, SDP_PDU_RECORD_INSERT_REQUEST
,
88 req
, __arraycount(req
)))
91 len
= _sdp_recv_pdu(ss
, SDP_PDU_ERROR_RESPONSE
);
95 if (len
!= sizeof(uint16_t) + sizeof(uint32_t)) {
101 * extract and check ErrorCode (success == 0)
103 ec
= be16dec(ss
->ibuf
);
105 errno
= _sdp_errno(ec
);
110 * extract ServiceRecordHandle if required
113 *handle
= be32dec(ss
->ibuf
+ sizeof(uint16_t));
119 sdp_record_update(struct sdp_session
*ss
, uint32_t handle
,
120 const sdp_data_t
*rec
)
129 * setup ServiceRecordHandle
131 handle
= htobe32(handle
);
132 req
[1].iov_base
= &handle
;
133 req
[1].iov_len
= sizeof(handle
);
136 * setup ServiceRecord
138 len
= rec
->end
- rec
->next
;
139 if (len
< 0 || len
> UINT16_MAX
) {
145 hdr
.end
= data
+ sizeof(data
) + len
;
146 sdp_put_seq(&hdr
, len
);
147 req
[2].iov_base
= data
;
148 req
[2].iov_len
= hdr
.next
- data
;
150 req
[3].iov_base
= rec
->next
;
151 req
[3].iov_len
= len
;
154 * UpdateRecord Transaction
156 if (!_sdp_send_pdu(ss
, SDP_PDU_RECORD_UPDATE_REQUEST
,
157 req
, __arraycount(req
)))
160 len
= _sdp_recv_pdu(ss
, SDP_PDU_ERROR_RESPONSE
);
164 if (len
!= sizeof(uint16_t)) {
170 * extract and check ErrorCode (success == 0)
172 if ((ec
= be16dec(ss
->ibuf
)) != 0) {
173 errno
= _sdp_errno(ec
);
181 sdp_record_remove(struct sdp_session
*ss
, uint32_t handle
)
188 * setup ServiceRecordHandle
190 handle
= htobe32(handle
);
191 req
[1].iov_base
= &handle
;
192 req
[1].iov_len
= sizeof(handle
);
195 * RemoveRecord Transaction
197 if (!_sdp_send_pdu(ss
, SDP_PDU_RECORD_REMOVE_REQUEST
,
198 req
, __arraycount(req
)))
201 len
= _sdp_recv_pdu(ss
, SDP_PDU_ERROR_RESPONSE
);
205 if (len
!= sizeof(uint16_t)) {
211 * extract and check ErrorCode (success == 0)
213 ec
= be16dec(ss
->ibuf
);
215 errno
= _sdp_errno(ec
);