2 * Service Discover Protocol server for QEMU L2CAP devices
4 * Copyright (C) 2008 Andrzej Zaborowski <balrog@zabor.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "qemu-common.h"
24 struct bt_l2cap_sdp_state_s
{
25 struct bt_l2cap_conn_params_s
*channel
;
27 struct sdp_service_record_s
{
32 struct sdp_service_attribute_s
{
44 static ssize_t
sdp_datalen(const uint8_t **element
, ssize_t
*left
)
46 size_t len
= *(*element
) ++ & SDP_DSIZE_MASK
;
52 if (len
< SDP_DSIZE_NEXT1
)
54 else if (len
== SDP_DSIZE_NEXT1
) {
59 return *(*element
) ++;
60 } else if (len
== SDP_DSIZE_NEXT2
) {
65 len
= (*(*element
) ++) << 8;
66 return len
| (*(*element
) ++);
72 len
= (*(*element
) ++) << 24;
73 len
|= (*(*element
) ++) << 16;
74 len
|= (*(*element
) ++) << 8;
75 return len
| (*(*element
) ++);
79 static const uint8_t bt_base_uuid
[12] = {
80 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
83 static int sdp_uuid_match(struct sdp_service_record_s
*record
,
84 const uint8_t *uuid
, ssize_t datalen
)
88 if (datalen
== 16 || datalen
== 4) {
89 if (datalen
== 16 && memcmp(uuid
+ 4, bt_base_uuid
, 12))
92 if (uuid
[0] | uuid
[1])
97 val
= (uuid
[0] << 8) | uuid
[1];
107 #define CONTINUATION_PARAM_SIZE (1 + sizeof(int))
108 #define MAX_PDU_OUT_SIZE 96 /* Arbitrary */
109 #define PDU_HEADER_SIZE 5
110 #define MAX_RSP_PARAM_SIZE (MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE - \
111 CONTINUATION_PARAM_SIZE)
113 static int sdp_svc_match(struct bt_l2cap_sdp_state_s
*sdp
,
114 const uint8_t **req
, ssize_t
*len
)
119 if ((**req
& ~SDP_DSIZE_MASK
) != SDP_DTYPE_UUID
)
122 datalen
= sdp_datalen(req
, len
);
123 if (datalen
!= 2 && datalen
!= 4 && datalen
!= 16)
126 for (i
= 0; i
< sdp
->services
; i
++)
127 if (sdp_uuid_match(&sdp
->service_list
[i
], *req
, datalen
))
128 sdp
->service_list
[i
].match
= 1;
136 static ssize_t
sdp_svc_search(struct bt_l2cap_sdp_state_s
*sdp
,
137 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
140 int i
, count
, start
, end
, max
;
143 /* Perform the search */
144 for (i
= 0; i
< sdp
->services
; i
++)
145 sdp
->service_list
[i
].match
= 0;
148 return -SDP_INVALID_SYNTAX
;
149 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
150 seqlen
= sdp_datalen(&req
, &len
);
151 if (seqlen
< 3 || len
< seqlen
)
152 return -SDP_INVALID_SYNTAX
;
156 if (sdp_svc_match(sdp
, &req
, &seqlen
))
157 return -SDP_INVALID_SYNTAX
;
158 } else if (sdp_svc_match(sdp
, &req
, &seqlen
))
159 return -SDP_INVALID_SYNTAX
;
162 return -SDP_INVALID_SYNTAX
;
163 end
= (req
[0] << 8) | req
[1];
168 if (len
<= sizeof(int))
169 return -SDP_INVALID_SYNTAX
;
171 memcpy(&start
, req
+ 1, sizeof(int));
176 return -SDP_INVALID_SYNTAX
;
178 /* Output the results */
182 for (i
= 0; i
< sdp
->services
; i
++)
183 if (sdp
->service_list
[i
].match
) {
184 if (count
>= start
&& count
< max
&& len
+ 4 < MAX_RSP_PARAM_SIZE
) {
186 memcpy(rsp
+ len
, &handle
, 4);
195 rsp
[1] = count
& 0xff;
196 rsp
[2] = (end
- start
) >> 8;
197 rsp
[3] = (end
- start
) & 0xff;
200 rsp
[len
++] = sizeof(int);
201 memcpy(rsp
+ len
, &end
, sizeof(int));
209 static int sdp_attr_match(struct sdp_service_record_s
*record
,
210 const uint8_t **req
, ssize_t
*len
)
214 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
219 start
= (*(*req
) ++) << 8;
223 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
228 start
= (*(*req
) ++) << 8;
230 end
= (*(*req
) ++) << 8;
236 for (i
= 0; i
< record
->attributes
; i
++)
237 if (record
->attribute_list
[i
].attribute_id
>= start
&&
238 record
->attribute_list
[i
].attribute_id
<= end
)
239 record
->attribute_list
[i
].match
= 1;
244 static ssize_t
sdp_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
245 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
248 int i
, start
, end
, max
;
250 struct sdp_service_record_s
*record
;
253 /* Perform the search */
255 return -SDP_INVALID_SYNTAX
;
256 memcpy(&handle
, req
, 4);
260 if (handle
< 0 || handle
> sdp
->services
)
261 return -SDP_INVALID_RECORD_HANDLE
;
262 record
= &sdp
->service_list
[handle
];
264 for (i
= 0; i
< record
->attributes
; i
++)
265 record
->attribute_list
[i
].match
= 0;
267 max
= (req
[0] << 8) | req
[1];
271 return -SDP_INVALID_SYNTAX
;
273 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
274 seqlen
= sdp_datalen(&req
, &len
);
275 if (seqlen
< 3 || len
< seqlen
)
276 return -SDP_INVALID_SYNTAX
;
280 if (sdp_attr_match(record
, &req
, &seqlen
))
281 return -SDP_INVALID_SYNTAX
;
282 } else if (sdp_attr_match(record
, &req
, &seqlen
))
283 return -SDP_INVALID_SYNTAX
;
286 return -SDP_INVALID_SYNTAX
;
289 if (len
<= sizeof(int))
290 return -SDP_INVALID_SYNTAX
;
292 memcpy(&start
, req
+ 1, sizeof(int));
297 return -SDP_INVALID_SYNTAX
;
299 /* Output the results */
301 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
304 for (i
= 0; i
< record
->attributes
; i
++)
305 if (record
->attribute_list
[i
].match
) {
306 if (len
>= 0 && len
+ record
->attribute_list
[i
].len
< max
) {
307 memcpy(lst
+ len
, record
->attribute_list
[i
].pair
,
308 record
->attribute_list
[i
].len
);
309 end
= len
+ record
->attribute_list
[i
].len
;
311 len
+= record
->attribute_list
[i
].len
;
314 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
315 lst
[1] = (len
+ start
- 3) >> 8;
316 lst
[2] = (len
+ start
- 3) & 0xff;
324 lst
[end
++] = sizeof(int);
325 memcpy(lst
+ end
, &len
, sizeof(int));
333 static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s
*sdp
,
334 const uint8_t **req
, ssize_t
*len
)
336 int i
, j
, start
, end
;
337 struct sdp_service_record_s
*record
;
339 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
344 start
= (*(*req
) ++) << 8;
348 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
353 start
= (*(*req
) ++) << 8;
355 end
= (*(*req
) ++) << 8;
361 for (i
= 0; i
< sdp
->services
; i
++)
362 if ((record
= &sdp
->service_list
[i
])->match
)
363 for (j
= 0; j
< record
->attributes
; j
++)
364 if (record
->attribute_list
[j
].attribute_id
>= start
&&
365 record
->attribute_list
[j
].attribute_id
<= end
)
366 record
->attribute_list
[j
].match
= 1;
371 static ssize_t
sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
372 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
375 int i
, j
, start
, end
, max
;
376 struct sdp_service_record_s
*record
;
379 /* Perform the search */
380 for (i
= 0; i
< sdp
->services
; i
++) {
381 sdp
->service_list
[i
].match
= 0;
382 for (j
= 0; j
< sdp
->service_list
[i
].attributes
; j
++)
383 sdp
->service_list
[i
].attribute_list
[j
].match
= 0;
387 return -SDP_INVALID_SYNTAX
;
388 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
389 seqlen
= sdp_datalen(&req
, &len
);
390 if (seqlen
< 3 || len
< seqlen
)
391 return -SDP_INVALID_SYNTAX
;
395 if (sdp_svc_match(sdp
, &req
, &seqlen
))
396 return -SDP_INVALID_SYNTAX
;
397 } else if (sdp_svc_match(sdp
, &req
, &seqlen
))
398 return -SDP_INVALID_SYNTAX
;
401 return -SDP_INVALID_SYNTAX
;
402 max
= (req
[0] << 8) | req
[1];
406 return -SDP_INVALID_SYNTAX
;
408 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
409 seqlen
= sdp_datalen(&req
, &len
);
410 if (seqlen
< 3 || len
< seqlen
)
411 return -SDP_INVALID_SYNTAX
;
415 if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
416 return -SDP_INVALID_SYNTAX
;
417 } else if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
418 return -SDP_INVALID_SYNTAX
;
421 return -SDP_INVALID_SYNTAX
;
424 if (len
<= sizeof(int))
425 return -SDP_INVALID_SYNTAX
;
427 memcpy(&start
, req
+ 1, sizeof(int));
432 return -SDP_INVALID_SYNTAX
;
434 /* Output the results */
435 /* This assumes empty attribute lists are never to be returned even
436 * for matching Service Records. In practice this shouldn't happen
437 * as the requestor will usually include the always present
438 * ServiceRecordHandle AttributeID in AttributeIDList. */
440 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
443 for (i
= 0; i
< sdp
->services
; i
++)
444 if ((record
= &sdp
->service_list
[i
])->match
) {
447 for (j
= 0; j
< record
->attributes
; j
++)
448 if (record
->attribute_list
[j
].match
) {
450 if (len
+ record
->attribute_list
[j
].len
< max
) {
451 memcpy(lst
+ len
, record
->attribute_list
[j
].pair
,
452 record
->attribute_list
[j
].len
);
453 end
= len
+ record
->attribute_list
[j
].len
;
455 len
+= record
->attribute_list
[j
].len
;
459 else if (seqlen
>= 3 && seqlen
< max
) {
460 lst
[seqlen
- 3] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
461 lst
[seqlen
- 2] = (len
- seqlen
) >> 8;
462 lst
[seqlen
- 1] = (len
- seqlen
) & 0xff;
465 if (len
== 3 - start
)
467 else if (0 >= start
) {
468 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
469 lst
[1] = (len
+ start
- 3) >> 8;
470 lst
[2] = (len
+ start
- 3) & 0xff;
478 lst
[end
++] = sizeof(int);
479 memcpy(lst
+ end
, &len
, sizeof(int));
487 static void bt_l2cap_sdp_sdu_in(void *opaque
, const uint8_t *data
, int len
)
489 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
490 enum bt_sdp_cmd pdu_id
;
491 uint8_t rsp
[MAX_PDU_OUT_SIZE
- PDU_HEADER_SIZE
], *sdu_out
;
492 int transaction_id
, plen
;
497 fprintf(stderr
, "%s: short SDP PDU (%iB).\n", __FUNCTION__
, len
);
502 transaction_id
= (data
[0] << 8) | data
[1];
503 plen
= (data
[2] << 8) | data
[3];
508 fprintf(stderr
, "%s: wrong SDP PDU length (%iB != %iB).\n",
509 __FUNCTION__
, plen
, len
);
510 err
= SDP_INVALID_PDU_SIZE
;
515 case SDP_SVC_SEARCH_REQ
:
516 rsp_len
= sdp_svc_search(sdp
, rsp
, data
, len
);
517 pdu_id
= SDP_SVC_SEARCH_RSP
;
520 case SDP_SVC_ATTR_REQ
:
521 rsp_len
= sdp_attr_get(sdp
, rsp
, data
, len
);
522 pdu_id
= SDP_SVC_ATTR_RSP
;
525 case SDP_SVC_SEARCH_ATTR_REQ
:
526 rsp_len
= sdp_svc_search_attr_get(sdp
, rsp
, data
, len
);
527 pdu_id
= SDP_SVC_SEARCH_ATTR_RSP
;
531 case SDP_SVC_ATTR_RSP
:
532 case SDP_SVC_SEARCH_RSP
:
533 case SDP_SVC_SEARCH_ATTR_RSP
:
535 fprintf(stderr
, "%s: unexpected SDP PDU ID %02x.\n",
536 __FUNCTION__
, pdu_id
);
537 err
= SDP_INVALID_SYNTAX
;
548 pdu_id
= SDP_ERROR_RSP
;
549 rsp
[rsp_len
++] = err
>> 8;
550 rsp
[rsp_len
++] = err
& 0xff;
553 sdu_out
= sdp
->channel
->sdu_out(sdp
->channel
, rsp_len
+ PDU_HEADER_SIZE
);
556 sdu_out
[1] = transaction_id
>> 8;
557 sdu_out
[2] = transaction_id
& 0xff;
558 sdu_out
[3] = rsp_len
>> 8;
559 sdu_out
[4] = rsp_len
& 0xff;
560 memcpy(sdu_out
+ PDU_HEADER_SIZE
, rsp
, rsp_len
);
562 sdp
->channel
->sdu_submit(sdp
->channel
);
565 static void bt_l2cap_sdp_close_ch(void *opaque
)
567 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
570 for (i
= 0; i
< sdp
->services
; i
++) {
571 qemu_free(sdp
->service_list
[i
].attribute_list
->pair
);
572 qemu_free(sdp
->service_list
[i
].attribute_list
);
573 qemu_free(sdp
->service_list
[i
].uuid
);
575 qemu_free(sdp
->service_list
);
579 struct sdp_def_service_s
{
581 struct sdp_def_attribute_s
{
583 struct sdp_def_data_element_s
{
588 struct sdp_def_data_element_s
*list
;
594 /* Calculate a safe byte count to allocate that will store the given
595 * element, at the same time count elements of a UUID type. */
596 static int sdp_attr_max_size(struct sdp_def_data_element_s
*element
,
599 int type
= element
->type
& ~SDP_DSIZE_MASK
;
602 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_UUID
||
603 type
== SDP_DTYPE_BOOL
) {
604 if (type
== SDP_DTYPE_UUID
)
606 return 1 + (1 << (element
->type
& SDP_DSIZE_MASK
));
609 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
610 if (element
->type
& SDP_DSIZE_MASK
) {
611 for (len
= 0; element
->value
.str
[len
] |
612 element
->value
.str
[len
+ 1]; len
++);
615 return 2 + strlen(element
->value
.str
);
618 if (type
!= SDP_DTYPE_SEQ
)
621 element
= element
->value
.list
;
622 while (element
->type
)
623 len
+= sdp_attr_max_size(element
++, uuids
);
630 static int sdp_attr_write(uint8_t *data
,
631 struct sdp_def_data_element_s
*element
, int **uuid
)
633 int type
= element
->type
& ~SDP_DSIZE_MASK
;
636 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_BOOL
) {
637 data
[len
++] = element
->type
;
638 if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_1
)
639 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
640 else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_2
) {
641 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
642 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
643 } else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_4
) {
644 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
645 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
646 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
647 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
653 if (type
== SDP_DTYPE_UUID
) {
654 *(*uuid
) ++ = element
->value
.uint
;
656 data
[len
++] = element
->type
;
657 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
658 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
659 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
660 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
661 memcpy(data
+ len
, bt_base_uuid
, 12);
666 data
[0] = type
| SDP_DSIZE_NEXT1
;
667 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
668 if (element
->type
& SDP_DSIZE_MASK
)
669 for (len
= 0; element
->value
.str
[len
] |
670 element
->value
.str
[len
+ 1]; len
++);
672 len
= strlen(element
->value
.str
);
673 memcpy(data
+ 2, element
->value
.str
, data
[1] = len
);
679 element
= element
->value
.list
;
680 while (element
->type
)
681 len
+= sdp_attr_write(data
+ len
, element
++, uuid
);
687 static int sdp_attributeid_compare(const struct sdp_service_attribute_s
*a
,
688 const struct sdp_service_attribute_s
*b
)
690 return (int) b
->attribute_id
- a
->attribute_id
;
693 static int sdp_uuid_compare(const int *a
, const int *b
)
698 static void sdp_service_record_build(struct sdp_service_record_s
*record
,
699 struct sdp_def_service_s
*def
, int handle
)
706 while (def
->attributes
[record
->attributes
].data
.type
) {
708 len
+= sdp_attr_max_size(&def
->attributes
[record
->attributes
++].data
,
711 record
->uuids
= 1 << ffs(record
->uuids
- 1);
712 record
->attribute_list
=
713 qemu_mallocz(record
->attributes
* sizeof(*record
->attribute_list
));
715 qemu_mallocz(record
->uuids
* sizeof(*record
->uuid
));
716 data
= qemu_malloc(len
);
718 record
->attributes
= 0;
720 while (def
->attributes
[record
->attributes
].data
.type
) {
721 record
->attribute_list
[record
->attributes
].pair
= data
;
724 data
[len
++] = SDP_DTYPE_UINT
| SDP_DSIZE_2
;
725 data
[len
++] = def
->attributes
[record
->attributes
].id
>> 8;
726 data
[len
++] = def
->attributes
[record
->attributes
].id
& 0xff;
727 len
+= sdp_attr_write(data
+ len
,
728 &def
->attributes
[record
->attributes
].data
, &uuid
);
730 /* Special case: assign a ServiceRecordHandle in sequence */
731 if (def
->attributes
[record
->attributes
].id
== SDP_ATTR_RECORD_HANDLE
)
732 def
->attributes
[record
->attributes
].data
.value
.uint
= handle
;
733 /* Note: we could also assign a ServiceDescription based on
734 * sdp->device.device->lmp_name. */
736 record
->attribute_list
[record
->attributes
++].len
= len
;
740 /* Sort the attribute list by the AttributeID */
741 qsort(record
->attribute_list
, record
->attributes
,
742 sizeof(*record
->attribute_list
),
743 (void *) sdp_attributeid_compare
);
744 /* Sort the searchable UUIDs list for bisection */
745 qsort(record
->uuid
, record
->uuids
,
746 sizeof(*record
->uuid
),
747 (void *) sdp_uuid_compare
);
750 static void sdp_service_db_build(struct bt_l2cap_sdp_state_s
*sdp
,
751 struct sdp_def_service_s
**service
)
754 while (service
[sdp
->services
])
757 qemu_mallocz(sdp
->services
* sizeof(*sdp
->service_list
));
761 sdp_service_record_build(&sdp
->service_list
[sdp
->services
],
762 *service
, sdp
->services
);
768 #define LAST { .type = 0 }
769 #define SERVICE(name, attrs) \
770 static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
771 .attributes = { attrs { .data = LAST } }, \
773 #define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
774 #define UINT8(val) { \
775 .type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
778 #define UINT16(val) { \
779 .type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
782 #define UINT32(val) { \
783 .type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
786 #define UUID128(val) { \
787 .type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
791 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
795 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
798 #define STRING(val) { \
799 .type = SDP_DTYPE_STRING, \
802 #define ARRAY(...) { \
803 .type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
804 .value.str = (char []) { __VA_ARGS__, 0, 0 }, \
807 .type = SDP_DTYPE_URL, \
811 #define LIST(val) { \
812 .type = SDP_DTYPE_SEQ, \
813 .value.list = (struct sdp_def_data_element_s []) { val LAST }, \
817 /* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
818 * in resulting SDP data representation size. */
821 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
822 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(HID_SVCLASS_ID
)))
823 ATTRIBUTE(RECORD_STATE
, UINT32(1))
824 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
825 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_HID_CTRL
))
826 LIST(UUID128(HIDP_UUID
))
828 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
829 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
830 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
832 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
833 LIST(UUID128(HID_PROFILE_ID
) UINT16(0x0100))
835 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
836 ATTRIBUTE(SVCNAME_PRIMARY
, STRING("QEMU Bluetooth HID"))
837 ATTRIBUTE(SVCDESC_PRIMARY
, STRING("QEMU Keyboard/Mouse"))
838 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
840 /* Profile specific */
841 ATTRIBUTE(DEVICE_RELEASE_NUMBER
, UINT16(0x0091)) /* Deprecated, remove */
842 ATTRIBUTE(PARSER_VERSION
, UINT16(0x0111))
843 /* TODO: extract from l2cap_device->device.class[0] */
844 ATTRIBUTE(DEVICE_SUBCLASS
, UINT8(0x40))
845 ATTRIBUTE(COUNTRY_CODE
, UINT8(0x15))
846 ATTRIBUTE(VIRTUAL_CABLE
, TRUE
)
847 ATTRIBUTE(RECONNECT_INITIATE
, FALSE
)
848 /* TODO: extract from hid->usbdev->report_desc */
849 ATTRIBUTE(DESCRIPTOR_LIST
, LIST(
850 LIST(UINT8(0x22) ARRAY(
851 0x05, 0x01, /* Usage Page (Generic Desktop) */
852 0x09, 0x06, /* Usage (Keyboard) */
853 0xa1, 0x01, /* Collection (Application) */
854 0x75, 0x01, /* Report Size (1) */
855 0x95, 0x08, /* Report Count (8) */
856 0x05, 0x07, /* Usage Page (Key Codes) */
857 0x19, 0xe0, /* Usage Minimum (224) */
858 0x29, 0xe7, /* Usage Maximum (231) */
859 0x15, 0x00, /* Logical Minimum (0) */
860 0x25, 0x01, /* Logical Maximum (1) */
861 0x81, 0x02, /* Input (Data, Variable, Absolute) */
862 0x95, 0x01, /* Report Count (1) */
863 0x75, 0x08, /* Report Size (8) */
864 0x81, 0x01, /* Input (Constant) */
865 0x95, 0x05, /* Report Count (5) */
866 0x75, 0x01, /* Report Size (1) */
867 0x05, 0x08, /* Usage Page (LEDs) */
868 0x19, 0x01, /* Usage Minimum (1) */
869 0x29, 0x05, /* Usage Maximum (5) */
870 0x91, 0x02, /* Output (Data, Variable, Absolute) */
871 0x95, 0x01, /* Report Count (1) */
872 0x75, 0x03, /* Report Size (3) */
873 0x91, 0x01, /* Output (Constant) */
874 0x95, 0x06, /* Report Count (6) */
875 0x75, 0x08, /* Report Size (8) */
876 0x15, 0x00, /* Logical Minimum (0) */
877 0x25, 0xff, /* Logical Maximum (255) */
878 0x05, 0x07, /* Usage Page (Key Codes) */
879 0x19, 0x00, /* Usage Minimum (0) */
880 0x29, 0xff, /* Usage Maximum (255) */
881 0x81, 0x00, /* Input (Data, Array) */
882 0xc0 /* End Collection */
884 ATTRIBUTE(LANG_ID_BASE_LIST
, LIST(
885 LIST(UINT16(0x0409) UINT16(0x0100))
887 ATTRIBUTE(SDP_DISABLE
, FALSE
)
888 ATTRIBUTE(BATTERY_POWER
, TRUE
)
889 ATTRIBUTE(REMOTE_WAKEUP
, TRUE
)
890 ATTRIBUTE(BOOT_DEVICE
, TRUE
) /* XXX: untested */
891 ATTRIBUTE(SUPERVISION_TIMEOUT
, UINT16(0x0c80))
892 ATTRIBUTE(NORMALLY_CONNECTABLE
, TRUE
)
893 ATTRIBUTE(PROFILE_VERSION
, UINT16(0x0100))
897 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
898 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(SDP_SERVER_SVCLASS_ID
)))
899 ATTRIBUTE(RECORD_STATE
, UINT32(1))
900 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
901 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
902 LIST(UUID128(SDP_UUID
))
904 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
905 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
906 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
908 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
909 LIST(UUID128(SDP_SERVER_PROFILE_ID
) UINT16(0x0100))
911 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
912 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
914 /* Profile specific */
915 ATTRIBUTE(VERSION_NUM_LIST
, LIST(UINT16(0x0100)))
916 ATTRIBUTE(SVCDB_STATE
, UINT32(1))
920 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
921 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(PNP_INFO_SVCLASS_ID
)))
922 ATTRIBUTE(RECORD_STATE
, UINT32(1))
923 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
924 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
925 LIST(UUID128(SDP_UUID
))
927 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
928 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
929 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
931 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
932 LIST(UUID128(PNP_INFO_PROFILE_ID
) UINT16(0x0100))
934 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
935 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
937 /* Profile specific */
938 ATTRIBUTE(SPECIFICATION_ID
, UINT16(0x0100))
939 ATTRIBUTE(VERSION
, UINT16(0x0100))
940 ATTRIBUTE(PRIMARY_RECORD
, TRUE
)
943 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s
*dev
,
944 struct bt_l2cap_conn_params_s
*params
)
946 struct bt_l2cap_sdp_state_s
*sdp
= qemu_mallocz(sizeof(*sdp
));
947 struct sdp_def_service_s
*services
[] = {
954 sdp
->channel
= params
;
955 sdp
->channel
->opaque
= sdp
;
956 sdp
->channel
->close
= bt_l2cap_sdp_close_ch
;
957 sdp
->channel
->sdu_in
= bt_l2cap_sdp_sdu_in
;
959 sdp_service_db_build(sdp
, services
);
964 void bt_l2cap_sdp_init(struct bt_l2cap_device_s
*dev
)
966 bt_l2cap_psm_register(dev
, BT_PSM_SDP
,
967 MAX_PDU_OUT_SIZE
, bt_l2cap_sdp_new_ch
);