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, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "qemu/host-utils.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 uint32_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
;
156 if (sdp_svc_match(sdp
, &req
, &seqlen
))
157 return -SDP_INVALID_SYNTAX
;
159 if (sdp_svc_match(sdp
, &req
, &len
)) {
160 return -SDP_INVALID_SYNTAX
;
165 return -SDP_INVALID_SYNTAX
;
166 max
= (req
[0] << 8) | req
[1];
171 if (len
<= sizeof(int))
172 return -SDP_INVALID_SYNTAX
;
174 memcpy(&start
, req
+ 1, sizeof(int));
179 return -SDP_INVALID_SYNTAX
;
181 /* Output the results */
185 for (i
= 0; i
< sdp
->services
; i
++)
186 if (sdp
->service_list
[i
].match
) {
187 if (count
>= start
&& count
< max
&& len
+ 4 < MAX_RSP_PARAM_SIZE
) {
189 memcpy(rsp
+ len
, &handle
, 4);
198 rsp
[1] = count
& 0xff;
199 rsp
[2] = (end
- start
) >> 8;
200 rsp
[3] = (end
- start
) & 0xff;
203 rsp
[len
++] = sizeof(int);
204 memcpy(rsp
+ len
, &end
, sizeof(int));
212 static int sdp_attr_match(struct sdp_service_record_s
*record
,
213 const uint8_t **req
, ssize_t
*len
)
217 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
222 start
= (*(*req
) ++) << 8;
226 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
231 start
= (*(*req
) ++) << 8;
233 end
= (*(*req
) ++) << 8;
239 for (i
= 0; i
< record
->attributes
; i
++)
240 if (record
->attribute_list
[i
].attribute_id
>= start
&&
241 record
->attribute_list
[i
].attribute_id
<= end
)
242 record
->attribute_list
[i
].match
= 1;
247 static ssize_t
sdp_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
248 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
251 int i
, start
, end
, max
;
253 struct sdp_service_record_s
*record
;
256 /* Perform the search */
258 return -SDP_INVALID_SYNTAX
;
259 memcpy(&handle
, req
, 4);
263 if (handle
< 0 || handle
> sdp
->services
)
264 return -SDP_INVALID_RECORD_HANDLE
;
265 record
= &sdp
->service_list
[handle
];
267 for (i
= 0; i
< record
->attributes
; i
++)
268 record
->attribute_list
[i
].match
= 0;
270 max
= (req
[0] << 8) | req
[1];
274 return -SDP_INVALID_SYNTAX
;
276 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
277 seqlen
= sdp_datalen(&req
, &len
);
278 if (seqlen
< 3 || len
< seqlen
)
279 return -SDP_INVALID_SYNTAX
;
283 if (sdp_attr_match(record
, &req
, &seqlen
))
284 return -SDP_INVALID_SYNTAX
;
286 if (sdp_attr_match(record
, &req
, &len
)) {
287 return -SDP_INVALID_SYNTAX
;
292 return -SDP_INVALID_SYNTAX
;
295 if (len
<= sizeof(int))
296 return -SDP_INVALID_SYNTAX
;
298 memcpy(&start
, req
+ 1, sizeof(int));
303 return -SDP_INVALID_SYNTAX
;
305 /* Output the results */
307 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
310 for (i
= 0; i
< record
->attributes
; i
++)
311 if (record
->attribute_list
[i
].match
) {
312 if (len
>= 0 && len
+ record
->attribute_list
[i
].len
< max
) {
313 memcpy(lst
+ len
, record
->attribute_list
[i
].pair
,
314 record
->attribute_list
[i
].len
);
315 end
= len
+ record
->attribute_list
[i
].len
;
317 len
+= record
->attribute_list
[i
].len
;
320 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
321 lst
[1] = (len
+ start
- 3) >> 8;
322 lst
[2] = (len
+ start
- 3) & 0xff;
330 lst
[end
++] = sizeof(int);
331 memcpy(lst
+ end
, &len
, sizeof(int));
339 static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s
*sdp
,
340 const uint8_t **req
, ssize_t
*len
)
342 int i
, j
, start
, end
;
343 struct sdp_service_record_s
*record
;
345 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
350 start
= (*(*req
) ++) << 8;
354 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
359 start
= (*(*req
) ++) << 8;
361 end
= (*(*req
) ++) << 8;
367 for (i
= 0; i
< sdp
->services
; i
++)
368 if ((record
= &sdp
->service_list
[i
])->match
)
369 for (j
= 0; j
< record
->attributes
; j
++)
370 if (record
->attribute_list
[j
].attribute_id
>= start
&&
371 record
->attribute_list
[j
].attribute_id
<= end
)
372 record
->attribute_list
[j
].match
= 1;
377 static ssize_t
sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
378 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
381 int i
, j
, start
, end
, max
;
382 struct sdp_service_record_s
*record
;
385 /* Perform the search */
386 for (i
= 0; i
< sdp
->services
; i
++) {
387 sdp
->service_list
[i
].match
= 0;
388 for (j
= 0; j
< sdp
->service_list
[i
].attributes
; j
++)
389 sdp
->service_list
[i
].attribute_list
[j
].match
= 0;
393 return -SDP_INVALID_SYNTAX
;
394 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
395 seqlen
= sdp_datalen(&req
, &len
);
396 if (seqlen
< 3 || len
< seqlen
)
397 return -SDP_INVALID_SYNTAX
;
401 if (sdp_svc_match(sdp
, &req
, &seqlen
))
402 return -SDP_INVALID_SYNTAX
;
404 if (sdp_svc_match(sdp
, &req
, &len
)) {
405 return -SDP_INVALID_SYNTAX
;
410 return -SDP_INVALID_SYNTAX
;
411 max
= (req
[0] << 8) | req
[1];
415 return -SDP_INVALID_SYNTAX
;
417 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
418 seqlen
= sdp_datalen(&req
, &len
);
419 if (seqlen
< 3 || len
< seqlen
)
420 return -SDP_INVALID_SYNTAX
;
424 if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
425 return -SDP_INVALID_SYNTAX
;
427 if (sdp_svc_attr_match(sdp
, &req
, &len
)) {
428 return -SDP_INVALID_SYNTAX
;
433 return -SDP_INVALID_SYNTAX
;
436 if (len
<= sizeof(int))
437 return -SDP_INVALID_SYNTAX
;
439 memcpy(&start
, req
+ 1, sizeof(int));
444 return -SDP_INVALID_SYNTAX
;
446 /* Output the results */
447 /* This assumes empty attribute lists are never to be returned even
448 * for matching Service Records. In practice this shouldn't happen
449 * as the requestor will usually include the always present
450 * ServiceRecordHandle AttributeID in AttributeIDList. */
452 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
455 for (i
= 0; i
< sdp
->services
; i
++)
456 if ((record
= &sdp
->service_list
[i
])->match
) {
459 for (j
= 0; j
< record
->attributes
; j
++)
460 if (record
->attribute_list
[j
].match
) {
462 if (len
+ record
->attribute_list
[j
].len
< max
) {
463 memcpy(lst
+ len
, record
->attribute_list
[j
].pair
,
464 record
->attribute_list
[j
].len
);
465 end
= len
+ record
->attribute_list
[j
].len
;
467 len
+= record
->attribute_list
[j
].len
;
471 else if (seqlen
>= 3 && seqlen
< max
) {
472 lst
[seqlen
- 3] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
473 lst
[seqlen
- 2] = (len
- seqlen
) >> 8;
474 lst
[seqlen
- 1] = (len
- seqlen
) & 0xff;
477 if (len
== 3 - start
)
479 else if (0 >= start
) {
480 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
481 lst
[1] = (len
+ start
- 3) >> 8;
482 lst
[2] = (len
+ start
- 3) & 0xff;
490 lst
[end
++] = sizeof(int);
491 memcpy(lst
+ end
, &len
, sizeof(int));
499 static void bt_l2cap_sdp_sdu_in(void *opaque
, const uint8_t *data
, int len
)
501 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
502 enum bt_sdp_cmd pdu_id
;
503 uint8_t rsp
[MAX_PDU_OUT_SIZE
- PDU_HEADER_SIZE
], *sdu_out
;
504 int transaction_id
, plen
;
509 fprintf(stderr
, "%s: short SDP PDU (%iB).\n", __FUNCTION__
, len
);
514 transaction_id
= (data
[0] << 8) | data
[1];
515 plen
= (data
[2] << 8) | data
[3];
520 fprintf(stderr
, "%s: wrong SDP PDU length (%iB != %iB).\n",
521 __FUNCTION__
, plen
, len
);
522 err
= SDP_INVALID_PDU_SIZE
;
527 case SDP_SVC_SEARCH_REQ
:
528 rsp_len
= sdp_svc_search(sdp
, rsp
, data
, len
);
529 pdu_id
= SDP_SVC_SEARCH_RSP
;
532 case SDP_SVC_ATTR_REQ
:
533 rsp_len
= sdp_attr_get(sdp
, rsp
, data
, len
);
534 pdu_id
= SDP_SVC_ATTR_RSP
;
537 case SDP_SVC_SEARCH_ATTR_REQ
:
538 rsp_len
= sdp_svc_search_attr_get(sdp
, rsp
, data
, len
);
539 pdu_id
= SDP_SVC_SEARCH_ATTR_RSP
;
543 case SDP_SVC_ATTR_RSP
:
544 case SDP_SVC_SEARCH_RSP
:
545 case SDP_SVC_SEARCH_ATTR_RSP
:
547 fprintf(stderr
, "%s: unexpected SDP PDU ID %02x.\n",
548 __FUNCTION__
, pdu_id
);
549 err
= SDP_INVALID_SYNTAX
;
560 pdu_id
= SDP_ERROR_RSP
;
561 rsp
[rsp_len
++] = err
>> 8;
562 rsp
[rsp_len
++] = err
& 0xff;
565 sdu_out
= sdp
->channel
->sdu_out(sdp
->channel
, rsp_len
+ PDU_HEADER_SIZE
);
568 sdu_out
[1] = transaction_id
>> 8;
569 sdu_out
[2] = transaction_id
& 0xff;
570 sdu_out
[3] = rsp_len
>> 8;
571 sdu_out
[4] = rsp_len
& 0xff;
572 memcpy(sdu_out
+ PDU_HEADER_SIZE
, rsp
, rsp_len
);
574 sdp
->channel
->sdu_submit(sdp
->channel
);
577 static void bt_l2cap_sdp_close_ch(void *opaque
)
579 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
582 for (i
= 0; i
< sdp
->services
; i
++) {
583 g_free(sdp
->service_list
[i
].attribute_list
->pair
);
584 g_free(sdp
->service_list
[i
].attribute_list
);
585 g_free(sdp
->service_list
[i
].uuid
);
587 g_free(sdp
->service_list
);
591 struct sdp_def_service_s
{
593 struct sdp_def_attribute_s
{
595 struct sdp_def_data_element_s
{
600 struct sdp_def_data_element_s
*list
;
606 /* Calculate a safe byte count to allocate that will store the given
607 * element, at the same time count elements of a UUID type. */
608 static int sdp_attr_max_size(struct sdp_def_data_element_s
*element
,
611 int type
= element
->type
& ~SDP_DSIZE_MASK
;
614 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_UUID
||
615 type
== SDP_DTYPE_BOOL
) {
616 if (type
== SDP_DTYPE_UUID
)
618 return 1 + (1 << (element
->type
& SDP_DSIZE_MASK
));
621 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
622 if (element
->type
& SDP_DSIZE_MASK
) {
623 for (len
= 0; element
->value
.str
[len
] |
624 element
->value
.str
[len
+ 1]; len
++);
627 return 2 + strlen(element
->value
.str
);
630 if (type
!= SDP_DTYPE_SEQ
)
633 element
= element
->value
.list
;
634 while (element
->type
)
635 len
+= sdp_attr_max_size(element
++, uuids
);
642 static int sdp_attr_write(uint8_t *data
,
643 struct sdp_def_data_element_s
*element
, int **uuid
)
645 int type
= element
->type
& ~SDP_DSIZE_MASK
;
648 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_BOOL
) {
649 data
[len
++] = element
->type
;
650 if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_1
)
651 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
652 else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_2
) {
653 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
654 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
655 } else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_4
) {
656 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
657 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
658 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
659 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
665 if (type
== SDP_DTYPE_UUID
) {
666 *(*uuid
) ++ = element
->value
.uint
;
668 data
[len
++] = element
->type
;
669 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
670 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
671 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
672 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
673 memcpy(data
+ len
, bt_base_uuid
, 12);
678 data
[0] = type
| SDP_DSIZE_NEXT1
;
679 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
680 if (element
->type
& SDP_DSIZE_MASK
)
681 for (len
= 0; element
->value
.str
[len
] |
682 element
->value
.str
[len
+ 1]; len
++);
684 len
= strlen(element
->value
.str
);
685 memcpy(data
+ 2, element
->value
.str
, data
[1] = len
);
691 element
= element
->value
.list
;
692 while (element
->type
)
693 len
+= sdp_attr_write(data
+ len
, element
++, uuid
);
699 static int sdp_attributeid_compare(const struct sdp_service_attribute_s
*a
,
700 const struct sdp_service_attribute_s
*b
)
702 return (int) b
->attribute_id
- a
->attribute_id
;
705 static int sdp_uuid_compare(const int *a
, const int *b
)
710 static void sdp_service_record_build(struct sdp_service_record_s
*record
,
711 struct sdp_def_service_s
*def
, int handle
)
718 while (def
->attributes
[record
->attributes
].data
.type
) {
720 len
+= sdp_attr_max_size(&def
->attributes
[record
->attributes
++].data
,
723 record
->uuids
= pow2ceil(record
->uuids
);
724 record
->attribute_list
=
725 g_malloc0(record
->attributes
* sizeof(*record
->attribute_list
));
727 g_malloc0(record
->uuids
* sizeof(*record
->uuid
));
728 data
= g_malloc(len
);
730 record
->attributes
= 0;
732 while (def
->attributes
[record
->attributes
].data
.type
) {
733 record
->attribute_list
[record
->attributes
].pair
= data
;
736 data
[len
++] = SDP_DTYPE_UINT
| SDP_DSIZE_2
;
737 data
[len
++] = def
->attributes
[record
->attributes
].id
>> 8;
738 data
[len
++] = def
->attributes
[record
->attributes
].id
& 0xff;
739 len
+= sdp_attr_write(data
+ len
,
740 &def
->attributes
[record
->attributes
].data
, &uuid
);
742 /* Special case: assign a ServiceRecordHandle in sequence */
743 if (def
->attributes
[record
->attributes
].id
== SDP_ATTR_RECORD_HANDLE
)
744 def
->attributes
[record
->attributes
].data
.value
.uint
= handle
;
745 /* Note: we could also assign a ServiceDescription based on
746 * sdp->device.device->lmp_name. */
748 record
->attribute_list
[record
->attributes
++].len
= len
;
752 /* Sort the attribute list by the AttributeID */
753 qsort(record
->attribute_list
, record
->attributes
,
754 sizeof(*record
->attribute_list
),
755 (void *) sdp_attributeid_compare
);
756 /* Sort the searchable UUIDs list for bisection */
757 qsort(record
->uuid
, record
->uuids
,
758 sizeof(*record
->uuid
),
759 (void *) sdp_uuid_compare
);
762 static void sdp_service_db_build(struct bt_l2cap_sdp_state_s
*sdp
,
763 struct sdp_def_service_s
**service
)
766 while (service
[sdp
->services
])
769 g_malloc0(sdp
->services
* sizeof(*sdp
->service_list
));
773 sdp_service_record_build(&sdp
->service_list
[sdp
->services
],
774 *service
, sdp
->services
);
780 #define LAST { .type = 0 }
781 #define SERVICE(name, attrs) \
782 static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
783 .attributes = { attrs { .data = LAST } }, \
785 #define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
786 #define UINT8(val) { \
787 .type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
790 #define UINT16(val) { \
791 .type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
794 #define UINT32(val) { \
795 .type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
798 #define UUID128(val) { \
799 .type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
803 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
806 #define SDP_FALSE { \
807 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
810 #define STRING(val) { \
811 .type = SDP_DTYPE_STRING, \
814 #define ARRAY(...) { \
815 .type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
816 .value.str = (char []) { __VA_ARGS__, 0, 0 }, \
819 .type = SDP_DTYPE_URL, \
823 #define LIST(val) { \
824 .type = SDP_DTYPE_SEQ, \
825 .value.list = (struct sdp_def_data_element_s []) { val LAST }, \
829 /* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
830 * in resulting SDP data representation size. */
833 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
834 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(HID_SVCLASS_ID
)))
835 ATTRIBUTE(RECORD_STATE
, UINT32(1))
836 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
837 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_HID_CTRL
))
838 LIST(UUID128(HIDP_UUID
))
840 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
841 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
842 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
844 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
845 LIST(UUID128(HID_PROFILE_ID
) UINT16(0x0100))
847 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
848 ATTRIBUTE(SVCNAME_PRIMARY
, STRING("QEMU Bluetooth HID"))
849 ATTRIBUTE(SVCDESC_PRIMARY
, STRING("QEMU Keyboard/Mouse"))
850 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
852 /* Profile specific */
853 ATTRIBUTE(DEVICE_RELEASE_NUMBER
, UINT16(0x0091)) /* Deprecated, remove */
854 ATTRIBUTE(PARSER_VERSION
, UINT16(0x0111))
855 /* TODO: extract from l2cap_device->device.class[0] */
856 ATTRIBUTE(DEVICE_SUBCLASS
, UINT8(0x40))
857 ATTRIBUTE(COUNTRY_CODE
, UINT8(0x15))
858 ATTRIBUTE(VIRTUAL_CABLE
, SDP_TRUE
)
859 ATTRIBUTE(RECONNECT_INITIATE
, SDP_FALSE
)
860 /* TODO: extract from hid->usbdev->report_desc */
861 ATTRIBUTE(DESCRIPTOR_LIST
, LIST(
862 LIST(UINT8(0x22) ARRAY(
863 0x05, 0x01, /* Usage Page (Generic Desktop) */
864 0x09, 0x06, /* Usage (Keyboard) */
865 0xa1, 0x01, /* Collection (Application) */
866 0x75, 0x01, /* Report Size (1) */
867 0x95, 0x08, /* Report Count (8) */
868 0x05, 0x07, /* Usage Page (Key Codes) */
869 0x19, 0xe0, /* Usage Minimum (224) */
870 0x29, 0xe7, /* Usage Maximum (231) */
871 0x15, 0x00, /* Logical Minimum (0) */
872 0x25, 0x01, /* Logical Maximum (1) */
873 0x81, 0x02, /* Input (Data, Variable, Absolute) */
874 0x95, 0x01, /* Report Count (1) */
875 0x75, 0x08, /* Report Size (8) */
876 0x81, 0x01, /* Input (Constant) */
877 0x95, 0x05, /* Report Count (5) */
878 0x75, 0x01, /* Report Size (1) */
879 0x05, 0x08, /* Usage Page (LEDs) */
880 0x19, 0x01, /* Usage Minimum (1) */
881 0x29, 0x05, /* Usage Maximum (5) */
882 0x91, 0x02, /* Output (Data, Variable, Absolute) */
883 0x95, 0x01, /* Report Count (1) */
884 0x75, 0x03, /* Report Size (3) */
885 0x91, 0x01, /* Output (Constant) */
886 0x95, 0x06, /* Report Count (6) */
887 0x75, 0x08, /* Report Size (8) */
888 0x15, 0x00, /* Logical Minimum (0) */
889 0x25, 0xff, /* Logical Maximum (255) */
890 0x05, 0x07, /* Usage Page (Key Codes) */
891 0x19, 0x00, /* Usage Minimum (0) */
892 0x29, 0xff, /* Usage Maximum (255) */
893 0x81, 0x00, /* Input (Data, Array) */
894 0xc0 /* End Collection */
896 ATTRIBUTE(LANG_ID_BASE_LIST
, LIST(
897 LIST(UINT16(0x0409) UINT16(0x0100))
899 ATTRIBUTE(SDP_DISABLE
, SDP_FALSE
)
900 ATTRIBUTE(BATTERY_POWER
, SDP_TRUE
)
901 ATTRIBUTE(REMOTE_WAKEUP
, SDP_TRUE
)
902 ATTRIBUTE(BOOT_DEVICE
, SDP_TRUE
) /* XXX: untested */
903 ATTRIBUTE(SUPERVISION_TIMEOUT
, UINT16(0x0c80))
904 ATTRIBUTE(NORMALLY_CONNECTABLE
, SDP_TRUE
)
905 ATTRIBUTE(PROFILE_VERSION
, UINT16(0x0100))
909 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
910 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(SDP_SERVER_SVCLASS_ID
)))
911 ATTRIBUTE(RECORD_STATE
, UINT32(1))
912 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
913 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
914 LIST(UUID128(SDP_UUID
))
916 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
917 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
918 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
920 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
921 LIST(UUID128(SDP_SERVER_PROFILE_ID
) UINT16(0x0100))
923 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
924 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
926 /* Profile specific */
927 ATTRIBUTE(VERSION_NUM_LIST
, LIST(UINT16(0x0100)))
928 ATTRIBUTE(SVCDB_STATE
, UINT32(1))
932 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
933 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(PNP_INFO_SVCLASS_ID
)))
934 ATTRIBUTE(RECORD_STATE
, UINT32(1))
935 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
936 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
937 LIST(UUID128(SDP_UUID
))
939 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
940 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
941 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
943 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
944 LIST(UUID128(PNP_INFO_PROFILE_ID
) UINT16(0x0100))
946 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
947 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
949 /* Profile specific */
950 ATTRIBUTE(SPECIFICATION_ID
, UINT16(0x0100))
951 ATTRIBUTE(VERSION
, UINT16(0x0100))
952 ATTRIBUTE(PRIMARY_RECORD
, SDP_TRUE
)
955 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s
*dev
,
956 struct bt_l2cap_conn_params_s
*params
)
958 struct bt_l2cap_sdp_state_s
*sdp
= g_malloc0(sizeof(*sdp
));
959 struct sdp_def_service_s
*services
[] = {
966 sdp
->channel
= params
;
967 sdp
->channel
->opaque
= sdp
;
968 sdp
->channel
->close
= bt_l2cap_sdp_close_ch
;
969 sdp
->channel
->sdu_in
= bt_l2cap_sdp_sdu_in
;
971 sdp_service_db_build(sdp
, services
);
976 void bt_l2cap_sdp_init(struct bt_l2cap_device_s
*dev
)
978 bt_l2cap_psm_register(dev
, BT_PSM_SDP
,
979 MAX_PDU_OUT_SIZE
, bt_l2cap_sdp_new_ch
);