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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #include "qemu-common.h"
25 struct bt_l2cap_sdp_state_s
{
26 struct bt_l2cap_conn_params_s
*channel
;
28 struct sdp_service_record_s
{
33 struct sdp_service_attribute_s
{
45 static ssize_t
sdp_datalen(const uint8_t **element
, ssize_t
*left
)
47 size_t len
= *(*element
) ++ & SDP_DSIZE_MASK
;
53 if (len
< SDP_DSIZE_NEXT1
)
55 else if (len
== SDP_DSIZE_NEXT1
) {
60 return *(*element
) ++;
61 } else if (len
== SDP_DSIZE_NEXT2
) {
66 len
= (*(*element
) ++) << 8;
67 return len
| (*(*element
) ++);
73 len
= (*(*element
) ++) << 24;
74 len
|= (*(*element
) ++) << 16;
75 len
|= (*(*element
) ++) << 8;
76 return len
| (*(*element
) ++);
80 static const uint8_t bt_base_uuid
[12] = {
81 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
84 static int sdp_uuid_match(struct sdp_service_record_s
*record
,
85 const uint8_t *uuid
, ssize_t datalen
)
89 if (datalen
== 16 || datalen
== 4) {
90 if (datalen
== 16 && memcmp(uuid
+ 4, bt_base_uuid
, 12))
93 if (uuid
[0] | uuid
[1])
98 val
= (uuid
[0] << 8) | uuid
[1];
108 #define CONTINUATION_PARAM_SIZE (1 + sizeof(int))
109 #define MAX_PDU_OUT_SIZE 96 /* Arbitrary */
110 #define PDU_HEADER_SIZE 5
111 #define MAX_RSP_PARAM_SIZE (MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE - \
112 CONTINUATION_PARAM_SIZE)
114 static int sdp_svc_match(struct bt_l2cap_sdp_state_s
*sdp
,
115 const uint8_t **req
, ssize_t
*len
)
120 if ((**req
& ~SDP_DSIZE_MASK
) != SDP_DTYPE_UUID
)
123 datalen
= sdp_datalen(req
, len
);
124 if (datalen
!= 2 && datalen
!= 4 && datalen
!= 16)
127 for (i
= 0; i
< sdp
->services
; i
++)
128 if (sdp_uuid_match(&sdp
->service_list
[i
], *req
, datalen
))
129 sdp
->service_list
[i
].match
= 1;
137 static ssize_t
sdp_svc_search(struct bt_l2cap_sdp_state_s
*sdp
,
138 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
141 int i
, count
, start
, end
, max
;
144 /* Perform the search */
145 for (i
= 0; i
< sdp
->services
; i
++)
146 sdp
->service_list
[i
].match
= 0;
149 return -SDP_INVALID_SYNTAX
;
150 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
151 seqlen
= sdp_datalen(&req
, &len
);
152 if (seqlen
< 3 || len
< seqlen
)
153 return -SDP_INVALID_SYNTAX
;
157 if (sdp_svc_match(sdp
, &req
, &seqlen
))
158 return -SDP_INVALID_SYNTAX
;
159 } else if (sdp_svc_match(sdp
, &req
, &seqlen
))
160 return -SDP_INVALID_SYNTAX
;
163 return -SDP_INVALID_SYNTAX
;
164 end
= (req
[0] << 8) | req
[1];
169 if (len
<= sizeof(int))
170 return -SDP_INVALID_SYNTAX
;
172 memcpy(&start
, req
+ 1, sizeof(int));
177 return -SDP_INVALID_SYNTAX
;
179 /* Output the results */
183 for (i
= 0; i
< sdp
->services
; i
++)
184 if (sdp
->service_list
[i
].match
) {
185 if (count
>= start
&& count
< max
&& len
+ 4 < MAX_RSP_PARAM_SIZE
) {
187 memcpy(rsp
+ len
, &handle
, 4);
196 rsp
[1] = count
& 0xff;
197 rsp
[2] = (end
- start
) >> 8;
198 rsp
[3] = (end
- start
) & 0xff;
201 rsp
[len
++] = sizeof(int);
202 memcpy(rsp
+ len
, &end
, sizeof(int));
210 static int sdp_attr_match(struct sdp_service_record_s
*record
,
211 const uint8_t **req
, ssize_t
*len
)
215 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
220 start
= (*(*req
) ++) << 8;
224 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
229 start
= (*(*req
) ++) << 8;
231 end
= (*(*req
) ++) << 8;
237 for (i
= 0; i
< record
->attributes
; i
++)
238 if (record
->attribute_list
[i
].attribute_id
>= start
&&
239 record
->attribute_list
[i
].attribute_id
<= end
)
240 record
->attribute_list
[i
].match
= 1;
245 static ssize_t
sdp_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
246 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
249 int i
, start
, end
, max
;
251 struct sdp_service_record_s
*record
;
254 /* Perform the search */
256 return -SDP_INVALID_SYNTAX
;
257 memcpy(&handle
, req
, 6);
261 if (handle
< 0 || handle
> sdp
->services
)
262 return -SDP_INVALID_RECORD_HANDLE
;
263 record
= &sdp
->service_list
[handle
];
265 for (i
= 0; i
< record
->attributes
; i
++)
266 record
->attribute_list
[i
].match
= 0;
268 max
= (req
[0] << 8) | req
[1];
272 return -SDP_INVALID_SYNTAX
;
274 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
275 seqlen
= sdp_datalen(&req
, &len
);
276 if (seqlen
< 3 || len
< seqlen
)
277 return -SDP_INVALID_SYNTAX
;
281 if (sdp_attr_match(record
, &req
, &seqlen
))
282 return -SDP_INVALID_SYNTAX
;
283 } else if (sdp_attr_match(record
, &req
, &seqlen
))
284 return -SDP_INVALID_SYNTAX
;
287 return -SDP_INVALID_SYNTAX
;
290 if (len
<= sizeof(int))
291 return -SDP_INVALID_SYNTAX
;
293 memcpy(&start
, req
+ 1, sizeof(int));
298 return -SDP_INVALID_SYNTAX
;
300 /* Output the results */
302 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
305 for (i
= 0; i
< record
->attributes
; i
++)
306 if (record
->attribute_list
[i
].match
) {
307 if (len
>= 0 && len
+ record
->attribute_list
[i
].len
< max
) {
308 memcpy(lst
+ len
, record
->attribute_list
[i
].pair
,
309 record
->attribute_list
[i
].len
);
310 end
= len
+ record
->attribute_list
[i
].len
;
312 len
+= record
->attribute_list
[i
].len
;
315 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
316 lst
[1] = (len
+ start
- 3) >> 8;
317 lst
[2] = (len
+ start
- 3) & 0xff;
325 lst
[end
++] = sizeof(int);
326 memcpy(lst
+ end
, &len
, sizeof(int));
334 static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s
*sdp
,
335 const uint8_t **req
, ssize_t
*len
)
337 int i
, j
, start
, end
;
338 struct sdp_service_record_s
*record
;
340 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
345 start
= (*(*req
) ++) << 8;
349 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
354 start
= (*(*req
) ++) << 8;
356 end
= (*(*req
) ++) << 8;
362 for (i
= 0; i
< sdp
->services
; i
++)
363 if ((record
= &sdp
->service_list
[i
])->match
)
364 for (j
= 0; j
< record
->attributes
; j
++)
365 if (record
->attribute_list
[j
].attribute_id
>= start
&&
366 record
->attribute_list
[j
].attribute_id
<= end
)
367 record
->attribute_list
[j
].match
= 1;
372 static ssize_t
sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
373 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
376 int i
, j
, start
, end
, max
;
377 struct sdp_service_record_s
*record
;
380 /* Perform the search */
381 for (i
= 0; i
< sdp
->services
; i
++) {
382 sdp
->service_list
[i
].match
= 0;
383 for (j
= 0; j
< sdp
->service_list
[i
].attributes
; j
++)
384 sdp
->service_list
[i
].attribute_list
[j
].match
= 0;
388 return -SDP_INVALID_SYNTAX
;
389 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
390 seqlen
= sdp_datalen(&req
, &len
);
391 if (seqlen
< 3 || len
< seqlen
)
392 return -SDP_INVALID_SYNTAX
;
396 if (sdp_svc_match(sdp
, &req
, &seqlen
))
397 return -SDP_INVALID_SYNTAX
;
398 } else if (sdp_svc_match(sdp
, &req
, &seqlen
))
399 return -SDP_INVALID_SYNTAX
;
402 return -SDP_INVALID_SYNTAX
;
403 max
= (req
[0] << 8) | req
[1];
407 return -SDP_INVALID_SYNTAX
;
409 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
410 seqlen
= sdp_datalen(&req
, &len
);
411 if (seqlen
< 3 || len
< seqlen
)
412 return -SDP_INVALID_SYNTAX
;
416 if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
417 return -SDP_INVALID_SYNTAX
;
418 } else if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
419 return -SDP_INVALID_SYNTAX
;
422 return -SDP_INVALID_SYNTAX
;
425 if (len
<= sizeof(int))
426 return -SDP_INVALID_SYNTAX
;
428 memcpy(&start
, req
+ 1, sizeof(int));
433 return -SDP_INVALID_SYNTAX
;
435 /* Output the results */
436 /* This assumes empty attribute lists are never to be returned even
437 * for matching Service Records. In practice this shouldn't happen
438 * as the requestor will usually include the always present
439 * ServiceRecordHandle AttributeID in AttributeIDList. */
441 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
444 for (i
= 0; i
< sdp
->services
; i
++)
445 if ((record
= &sdp
->service_list
[i
])->match
) {
448 for (j
= 0; j
< record
->attributes
; j
++)
449 if (record
->attribute_list
[j
].match
) {
451 if (len
+ record
->attribute_list
[j
].len
< max
) {
452 memcpy(lst
+ len
, record
->attribute_list
[j
].pair
,
453 record
->attribute_list
[j
].len
);
454 end
= len
+ record
->attribute_list
[j
].len
;
456 len
+= record
->attribute_list
[j
].len
;
460 else if (seqlen
>= 3 && seqlen
< max
) {
461 lst
[seqlen
- 3] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
462 lst
[seqlen
- 2] = (len
- seqlen
) >> 8;
463 lst
[seqlen
- 1] = (len
- seqlen
) & 0xff;
466 if (len
== 3 - start
)
468 else if (0 >= start
) {
469 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
470 lst
[1] = (len
+ start
- 3) >> 8;
471 lst
[2] = (len
+ start
- 3) & 0xff;
479 lst
[end
++] = sizeof(int);
480 memcpy(lst
+ end
, &len
, sizeof(int));
488 static void bt_l2cap_sdp_sdu_in(void *opaque
, const uint8_t *data
, int len
)
490 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
491 enum bt_sdp_cmd pdu_id
;
492 uint8_t rsp
[MAX_PDU_OUT_SIZE
- PDU_HEADER_SIZE
], *sdu_out
;
493 int transaction_id
, plen
;
498 fprintf(stderr
, "%s: short SDP PDU (%iB).\n", __FUNCTION__
, len
);
503 transaction_id
= (data
[0] << 8) | data
[1];
504 plen
= (data
[2] << 8) | data
[3];
509 fprintf(stderr
, "%s: wrong SDP PDU length (%iB != %iB).\n",
510 __FUNCTION__
, plen
, len
);
511 err
= SDP_INVALID_PDU_SIZE
;
516 case SDP_SVC_SEARCH_REQ
:
517 rsp_len
= sdp_svc_search(sdp
, rsp
, data
, len
);
518 pdu_id
= SDP_SVC_SEARCH_RSP
;
521 case SDP_SVC_ATTR_REQ
:
522 rsp_len
= sdp_attr_get(sdp
, rsp
, data
, len
);
523 pdu_id
= SDP_SVC_ATTR_RSP
;
526 case SDP_SVC_SEARCH_ATTR_REQ
:
527 rsp_len
= sdp_svc_search_attr_get(sdp
, rsp
, data
, len
);
528 pdu_id
= SDP_SVC_SEARCH_ATTR_RSP
;
532 case SDP_SVC_ATTR_RSP
:
533 case SDP_SVC_SEARCH_RSP
:
534 case SDP_SVC_SEARCH_ATTR_RSP
:
536 fprintf(stderr
, "%s: unexpected SDP PDU ID %02x.\n",
537 __FUNCTION__
, pdu_id
);
538 err
= SDP_INVALID_SYNTAX
;
549 pdu_id
= SDP_ERROR_RSP
;
550 rsp
[rsp_len
++] = err
>> 8;
551 rsp
[rsp_len
++] = err
& 0xff;
554 sdu_out
= sdp
->channel
->sdu_out(sdp
->channel
, rsp_len
+ PDU_HEADER_SIZE
);
557 sdu_out
[1] = transaction_id
>> 8;
558 sdu_out
[2] = transaction_id
& 0xff;
559 sdu_out
[3] = rsp_len
>> 8;
560 sdu_out
[4] = rsp_len
& 0xff;
561 memcpy(sdu_out
+ PDU_HEADER_SIZE
, rsp
, rsp_len
);
563 sdp
->channel
->sdu_submit(sdp
->channel
);
566 static void bt_l2cap_sdp_close_ch(void *opaque
)
568 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
571 for (i
= 0; i
< sdp
->services
; i
++) {
572 qemu_free(sdp
->service_list
[i
].attribute_list
->pair
);
573 qemu_free(sdp
->service_list
[i
].attribute_list
);
574 qemu_free(sdp
->service_list
[i
].uuid
);
576 qemu_free(sdp
->service_list
);
580 struct sdp_def_service_s
{
582 struct sdp_def_attribute_s
{
584 struct sdp_def_data_element_s
{
589 struct sdp_def_data_element_s
*list
;
595 /* Calculate a safe byte count to allocate that will store the given
596 * element, at the same time count elements of a UUID type. */
597 static int sdp_attr_max_size(struct sdp_def_data_element_s
*element
,
600 int type
= element
->type
& ~SDP_DSIZE_MASK
;
603 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_UUID
||
604 type
== SDP_DTYPE_BOOL
) {
605 if (type
== SDP_DTYPE_UUID
)
607 return 1 + (1 << (element
->type
& SDP_DSIZE_MASK
));
610 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
611 if (element
->type
& SDP_DSIZE_MASK
) {
612 for (len
= 0; element
->value
.str
[len
] |
613 element
->value
.str
[len
+ 1]; len
++);
616 return 2 + strlen(element
->value
.str
);
619 if (type
!= SDP_DTYPE_SEQ
)
622 element
= element
->value
.list
;
623 while (element
->type
)
624 len
+= sdp_attr_max_size(element
++, uuids
);
631 static int sdp_attr_write(uint8_t *data
,
632 struct sdp_def_data_element_s
*element
, int **uuid
)
634 int type
= element
->type
& ~SDP_DSIZE_MASK
;
637 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_BOOL
) {
638 data
[len
++] = element
->type
;
639 if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_1
)
640 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
641 else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_2
) {
642 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
643 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
644 } else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_4
) {
645 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
646 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
647 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
648 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
654 if (type
== SDP_DTYPE_UUID
) {
655 *(*uuid
) ++ = element
->value
.uint
;
657 data
[len
++] = element
->type
;
658 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
659 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
660 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
661 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
662 memcpy(data
+ len
, bt_base_uuid
, 12);
667 data
[0] = type
| SDP_DSIZE_NEXT1
;
668 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
669 if (element
->type
& SDP_DSIZE_MASK
)
670 for (len
= 0; element
->value
.str
[len
] |
671 element
->value
.str
[len
+ 1]; len
++);
673 len
= strlen(element
->value
.str
);
674 memcpy(data
+ 2, element
->value
.str
, data
[1] = len
);
680 element
= element
->value
.list
;
681 while (element
->type
)
682 len
+= sdp_attr_write(data
+ len
, element
++, uuid
);
688 static int sdp_attributeid_compare(const struct sdp_service_attribute_s
*a
,
689 const struct sdp_service_attribute_s
*b
)
691 return (int) b
->attribute_id
- a
->attribute_id
;
694 static int sdp_uuid_compare(const int *a
, const int *b
)
699 static void sdp_service_record_build(struct sdp_service_record_s
*record
,
700 struct sdp_def_service_s
*def
, int handle
)
707 while (def
->attributes
[record
->attributes
].data
.type
) {
709 len
+= sdp_attr_max_size(&def
->attributes
[record
->attributes
++].data
,
712 record
->uuids
= 1 << ffs(record
->uuids
- 1);
713 record
->attribute_list
=
714 qemu_mallocz(record
->attributes
* sizeof(*record
->attribute_list
));
716 qemu_mallocz(record
->uuids
* sizeof(*record
->uuid
));
717 data
= qemu_malloc(len
);
719 record
->attributes
= 0;
721 while (def
->attributes
[record
->attributes
].data
.type
) {
722 record
->attribute_list
[record
->attributes
].pair
= data
;
725 data
[len
++] = SDP_DTYPE_UINT
| SDP_DSIZE_2
;
726 data
[len
++] = def
->attributes
[record
->attributes
].id
>> 8;
727 data
[len
++] = def
->attributes
[record
->attributes
].id
& 0xff;
728 len
+= sdp_attr_write(data
+ len
,
729 &def
->attributes
[record
->attributes
].data
, &uuid
);
731 /* Special case: assign a ServiceRecordHandle in sequence */
732 if (def
->attributes
[record
->attributes
].id
== SDP_ATTR_RECORD_HANDLE
)
733 def
->attributes
[record
->attributes
].data
.value
.uint
= handle
;
734 /* Note: we could also assign a ServiceDescription based on
735 * sdp->device.device->lmp_name. */
737 record
->attribute_list
[record
->attributes
++].len
= len
;
741 /* Sort the attribute list by the AttributeID */
742 qsort(record
->attribute_list
, record
->attributes
,
743 sizeof(*record
->attribute_list
),
744 (void *) sdp_attributeid_compare
);
745 /* Sort the searchable UUIDs list for bisection */
746 qsort(record
->uuid
, record
->uuids
,
747 sizeof(*record
->uuid
),
748 (void *) sdp_uuid_compare
);
751 static void sdp_service_db_build(struct bt_l2cap_sdp_state_s
*sdp
,
752 struct sdp_def_service_s
**service
)
755 while (service
[sdp
->services
])
758 qemu_mallocz(sdp
->services
* sizeof(*sdp
->service_list
));
762 sdp_service_record_build(&sdp
->service_list
[sdp
->services
],
763 *service
, sdp
->services
);
769 #define LAST { .type = 0 }
770 #define SERVICE(name, attrs) \
771 static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
772 .attributes = { attrs { .data = LAST } }, \
774 #define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
775 #define UINT8(val) { \
776 .type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
779 #define UINT16(val) { \
780 .type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
783 #define UINT32(val) { \
784 .type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
787 #define UUID128(val) { \
788 .type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
792 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
796 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
799 #define STRING(val) { \
800 .type = SDP_DTYPE_STRING, \
803 #define ARRAY(...) { \
804 .type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
805 .value.str = (char []) { __VA_ARGS__, 0, 0 }, \
808 .type = SDP_DTYPE_URL, \
812 #define LIST(val) { \
813 .type = SDP_DTYPE_SEQ, \
814 .value.list = (struct sdp_def_data_element_s []) { val LAST }, \
818 /* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
819 * in resulting SDP data representation size. */
822 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
823 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(HID_SVCLASS_ID
)))
824 ATTRIBUTE(RECORD_STATE
, UINT32(1))
825 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
826 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_HID_CTRL
))
827 LIST(UUID128(HIDP_UUID
))
829 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
830 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
831 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
833 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
834 LIST(UUID128(HID_PROFILE_ID
) UINT16(0x0100))
836 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
837 ATTRIBUTE(SVCNAME_PRIMARY
, STRING("QEMU Bluetooth HID"))
838 ATTRIBUTE(SVCDESC_PRIMARY
, STRING("QEMU Keyboard/Mouse"))
839 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
841 /* Profile specific */
842 ATTRIBUTE(DEVICE_RELEASE_NUMBER
, UINT16(0x0091)) /* Deprecated, remove */
843 ATTRIBUTE(PARSER_VERSION
, UINT16(0x0111))
844 /* TODO: extract from l2cap_device->device.class[0] */
845 ATTRIBUTE(DEVICE_SUBCLASS
, UINT8(0x40))
846 ATTRIBUTE(COUNTRY_CODE
, UINT8(0x15))
847 ATTRIBUTE(VIRTUAL_CABLE
, TRUE
)
848 ATTRIBUTE(RECONNECT_INITIATE
, FALSE
)
849 /* TODO: extract from hid->usbdev->report_desc */
850 ATTRIBUTE(DESCRIPTOR_LIST
, LIST(
851 LIST(UINT8(0x22) ARRAY(
852 0x05, 0x01, /* Usage Page (Generic Desktop) */
853 0x09, 0x06, /* Usage (Keyboard) */
854 0xa1, 0x01, /* Collection (Application) */
855 0x75, 0x01, /* Report Size (1) */
856 0x95, 0x08, /* Report Count (8) */
857 0x05, 0x07, /* Usage Page (Key Codes) */
858 0x19, 0xe0, /* Usage Minimum (224) */
859 0x29, 0xe7, /* Usage Maximum (231) */
860 0x15, 0x00, /* Logical Minimum (0) */
861 0x25, 0x01, /* Logical Maximum (1) */
862 0x81, 0x02, /* Input (Data, Variable, Absolute) */
863 0x95, 0x01, /* Report Count (1) */
864 0x75, 0x08, /* Report Size (8) */
865 0x81, 0x01, /* Input (Constant) */
866 0x95, 0x05, /* Report Count (5) */
867 0x75, 0x01, /* Report Size (1) */
868 0x05, 0x08, /* Usage Page (LEDs) */
869 0x19, 0x01, /* Usage Minimum (1) */
870 0x29, 0x05, /* Usage Maximum (5) */
871 0x91, 0x02, /* Output (Data, Variable, Absolute) */
872 0x95, 0x01, /* Report Count (1) */
873 0x75, 0x03, /* Report Size (3) */
874 0x91, 0x01, /* Output (Constant) */
875 0x95, 0x06, /* Report Count (6) */
876 0x75, 0x08, /* Report Size (8) */
877 0x15, 0x00, /* Logical Minimum (0) */
878 0x25, 0xff, /* Logical Maximum (255) */
879 0x05, 0x07, /* Usage Page (Key Codes) */
880 0x19, 0x00, /* Usage Minimum (0) */
881 0x29, 0xff, /* Usage Maximum (255) */
882 0x81, 0x00, /* Input (Data, Array) */
883 0xc0 /* End Collection */
885 ATTRIBUTE(LANG_ID_BASE_LIST
, LIST(
886 LIST(UINT16(0x0409) UINT16(0x0100))
888 ATTRIBUTE(SDP_DISABLE
, FALSE
)
889 ATTRIBUTE(BATTERY_POWER
, TRUE
)
890 ATTRIBUTE(REMOTE_WAKEUP
, TRUE
)
891 ATTRIBUTE(BOOT_DEVICE
, TRUE
) /* XXX: untested */
892 ATTRIBUTE(SUPERVISION_TIMEOUT
, UINT16(0x0c80))
893 ATTRIBUTE(NORMALLY_CONNECTABLE
, TRUE
)
894 ATTRIBUTE(PROFILE_VERSION
, UINT16(0x0100))
898 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
899 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(SDP_SERVER_SVCLASS_ID
)))
900 ATTRIBUTE(RECORD_STATE
, UINT32(1))
901 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
902 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
903 LIST(UUID128(SDP_UUID
))
905 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
906 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
907 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
909 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
910 LIST(UUID128(SDP_SERVER_PROFILE_ID
) UINT16(0x0100))
912 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
913 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
915 /* Profile specific */
916 ATTRIBUTE(VERSION_NUM_LIST
, LIST(UINT16(0x0100)))
917 ATTRIBUTE(SVCDB_STATE
, UINT32(1))
921 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
922 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(PNP_INFO_SVCLASS_ID
)))
923 ATTRIBUTE(RECORD_STATE
, UINT32(1))
924 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
925 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
926 LIST(UUID128(SDP_UUID
))
928 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
929 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
930 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
932 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
933 LIST(UUID128(PNP_INFO_PROFILE_ID
) UINT16(0x0100))
935 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
936 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU " QEMU_VERSION
))
938 /* Profile specific */
939 ATTRIBUTE(SPECIFICATION_ID
, UINT16(0x0100))
940 ATTRIBUTE(VERSION
, UINT16(0x0100))
941 ATTRIBUTE(PRIMARY_RECORD
, TRUE
)
944 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s
*dev
,
945 struct bt_l2cap_conn_params_s
*params
)
947 struct bt_l2cap_sdp_state_s
*sdp
= qemu_mallocz(sizeof(*sdp
));
948 struct sdp_def_service_s
*services
[] = {
955 sdp
->channel
= params
;
956 sdp
->channel
->opaque
= sdp
;
957 sdp
->channel
->close
= bt_l2cap_sdp_close_ch
;
958 sdp
->channel
->sdu_in
= bt_l2cap_sdp_sdu_in
;
960 sdp_service_db_build(sdp
, services
);
965 void bt_l2cap_sdp_init(struct bt_l2cap_device_s
*dev
)
967 bt_l2cap_psm_register(dev
, BT_PSM_SDP
,
968 MAX_PDU_OUT_SIZE
, bt_l2cap_sdp_new_ch
);