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-common.h"
23 struct bt_l2cap_sdp_state_s
{
24 struct bt_l2cap_conn_params_s
*channel
;
26 struct sdp_service_record_s
{
31 struct sdp_service_attribute_s
{
43 static ssize_t
sdp_datalen(const uint8_t **element
, ssize_t
*left
)
45 uint32_t len
= *(*element
) ++ & SDP_DSIZE_MASK
;
51 if (len
< SDP_DSIZE_NEXT1
)
53 else if (len
== SDP_DSIZE_NEXT1
) {
58 return *(*element
) ++;
59 } else if (len
== SDP_DSIZE_NEXT2
) {
64 len
= (*(*element
) ++) << 8;
65 return len
| (*(*element
) ++);
71 len
= (*(*element
) ++) << 24;
72 len
|= (*(*element
) ++) << 16;
73 len
|= (*(*element
) ++) << 8;
74 return len
| (*(*element
) ++);
78 static const uint8_t bt_base_uuid
[12] = {
79 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
82 static int sdp_uuid_match(struct sdp_service_record_s
*record
,
83 const uint8_t *uuid
, ssize_t datalen
)
87 if (datalen
== 16 || datalen
== 4) {
88 if (datalen
== 16 && memcmp(uuid
+ 4, bt_base_uuid
, 12))
91 if (uuid
[0] | uuid
[1])
96 val
= (uuid
[0] << 8) | uuid
[1];
106 #define CONTINUATION_PARAM_SIZE (1 + sizeof(int))
107 #define MAX_PDU_OUT_SIZE 96 /* Arbitrary */
108 #define PDU_HEADER_SIZE 5
109 #define MAX_RSP_PARAM_SIZE (MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE - \
110 CONTINUATION_PARAM_SIZE)
112 static int sdp_svc_match(struct bt_l2cap_sdp_state_s
*sdp
,
113 const uint8_t **req
, ssize_t
*len
)
118 if ((**req
& ~SDP_DSIZE_MASK
) != SDP_DTYPE_UUID
)
121 datalen
= sdp_datalen(req
, len
);
122 if (datalen
!= 2 && datalen
!= 4 && datalen
!= 16)
125 for (i
= 0; i
< sdp
->services
; i
++)
126 if (sdp_uuid_match(&sdp
->service_list
[i
], *req
, datalen
))
127 sdp
->service_list
[i
].match
= 1;
135 static ssize_t
sdp_svc_search(struct bt_l2cap_sdp_state_s
*sdp
,
136 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
139 int i
, count
, start
, end
, max
;
142 /* Perform the search */
143 for (i
= 0; i
< sdp
->services
; i
++)
144 sdp
->service_list
[i
].match
= 0;
147 return -SDP_INVALID_SYNTAX
;
148 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
149 seqlen
= sdp_datalen(&req
, &len
);
150 if (seqlen
< 3 || len
< seqlen
)
151 return -SDP_INVALID_SYNTAX
;
154 if (sdp_svc_match(sdp
, &req
, &seqlen
))
155 return -SDP_INVALID_SYNTAX
;
157 if (sdp_svc_match(sdp
, &req
, &len
)) {
158 return -SDP_INVALID_SYNTAX
;
163 return -SDP_INVALID_SYNTAX
;
164 max
= (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
, 4);
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
;
284 if (sdp_attr_match(record
, &req
, &len
)) {
285 return -SDP_INVALID_SYNTAX
;
290 return -SDP_INVALID_SYNTAX
;
293 if (len
<= sizeof(int))
294 return -SDP_INVALID_SYNTAX
;
296 memcpy(&start
, req
+ 1, sizeof(int));
301 return -SDP_INVALID_SYNTAX
;
303 /* Output the results */
305 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
308 for (i
= 0; i
< record
->attributes
; i
++)
309 if (record
->attribute_list
[i
].match
) {
310 if (len
>= 0 && len
+ record
->attribute_list
[i
].len
< max
) {
311 memcpy(lst
+ len
, record
->attribute_list
[i
].pair
,
312 record
->attribute_list
[i
].len
);
313 end
= len
+ record
->attribute_list
[i
].len
;
315 len
+= record
->attribute_list
[i
].len
;
318 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
319 lst
[1] = (len
+ start
- 3) >> 8;
320 lst
[2] = (len
+ start
- 3) & 0xff;
328 lst
[end
++] = sizeof(int);
329 memcpy(lst
+ end
, &len
, sizeof(int));
337 static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s
*sdp
,
338 const uint8_t **req
, ssize_t
*len
)
340 int i
, j
, start
, end
;
341 struct sdp_service_record_s
*record
;
343 if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_2
)) {
348 start
= (*(*req
) ++) << 8;
352 } else if (**req
== (SDP_DTYPE_UINT
| SDP_DSIZE_4
)) {
357 start
= (*(*req
) ++) << 8;
359 end
= (*(*req
) ++) << 8;
365 for (i
= 0; i
< sdp
->services
; i
++)
366 if ((record
= &sdp
->service_list
[i
])->match
)
367 for (j
= 0; j
< record
->attributes
; j
++)
368 if (record
->attribute_list
[j
].attribute_id
>= start
&&
369 record
->attribute_list
[j
].attribute_id
<= end
)
370 record
->attribute_list
[j
].match
= 1;
375 static ssize_t
sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s
*sdp
,
376 uint8_t *rsp
, const uint8_t *req
, ssize_t len
)
379 int i
, j
, start
, end
, max
;
380 struct sdp_service_record_s
*record
;
383 /* Perform the search */
384 for (i
= 0; i
< sdp
->services
; i
++) {
385 sdp
->service_list
[i
].match
= 0;
386 for (j
= 0; j
< sdp
->service_list
[i
].attributes
; j
++)
387 sdp
->service_list
[i
].attribute_list
[j
].match
= 0;
391 return -SDP_INVALID_SYNTAX
;
392 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
393 seqlen
= sdp_datalen(&req
, &len
);
394 if (seqlen
< 3 || len
< seqlen
)
395 return -SDP_INVALID_SYNTAX
;
399 if (sdp_svc_match(sdp
, &req
, &seqlen
))
400 return -SDP_INVALID_SYNTAX
;
402 if (sdp_svc_match(sdp
, &req
, &len
)) {
403 return -SDP_INVALID_SYNTAX
;
408 return -SDP_INVALID_SYNTAX
;
409 max
= (req
[0] << 8) | req
[1];
413 return -SDP_INVALID_SYNTAX
;
415 if ((*req
& ~SDP_DSIZE_MASK
) == SDP_DTYPE_SEQ
) {
416 seqlen
= sdp_datalen(&req
, &len
);
417 if (seqlen
< 3 || len
< seqlen
)
418 return -SDP_INVALID_SYNTAX
;
422 if (sdp_svc_attr_match(sdp
, &req
, &seqlen
))
423 return -SDP_INVALID_SYNTAX
;
425 if (sdp_svc_attr_match(sdp
, &req
, &len
)) {
426 return -SDP_INVALID_SYNTAX
;
431 return -SDP_INVALID_SYNTAX
;
434 if (len
<= sizeof(int))
435 return -SDP_INVALID_SYNTAX
;
437 memcpy(&start
, req
+ 1, sizeof(int));
442 return -SDP_INVALID_SYNTAX
;
444 /* Output the results */
445 /* This assumes empty attribute lists are never to be returned even
446 * for matching Service Records. In practice this shouldn't happen
447 * as the requestor will usually include the always present
448 * ServiceRecordHandle AttributeID in AttributeIDList. */
450 max
= MIN(max
, MAX_RSP_PARAM_SIZE
);
453 for (i
= 0; i
< sdp
->services
; i
++)
454 if ((record
= &sdp
->service_list
[i
])->match
) {
457 for (j
= 0; j
< record
->attributes
; j
++)
458 if (record
->attribute_list
[j
].match
) {
460 if (len
+ record
->attribute_list
[j
].len
< max
) {
461 memcpy(lst
+ len
, record
->attribute_list
[j
].pair
,
462 record
->attribute_list
[j
].len
);
463 end
= len
+ record
->attribute_list
[j
].len
;
465 len
+= record
->attribute_list
[j
].len
;
469 else if (seqlen
>= 3 && seqlen
< max
) {
470 lst
[seqlen
- 3] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
471 lst
[seqlen
- 2] = (len
- seqlen
) >> 8;
472 lst
[seqlen
- 1] = (len
- seqlen
) & 0xff;
475 if (len
== 3 - start
)
477 else if (0 >= start
) {
478 lst
[0] = SDP_DTYPE_SEQ
| SDP_DSIZE_NEXT2
;
479 lst
[1] = (len
+ start
- 3) >> 8;
480 lst
[2] = (len
+ start
- 3) & 0xff;
488 lst
[end
++] = sizeof(int);
489 memcpy(lst
+ end
, &len
, sizeof(int));
497 static void bt_l2cap_sdp_sdu_in(void *opaque
, const uint8_t *data
, int len
)
499 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
500 enum bt_sdp_cmd pdu_id
;
501 uint8_t rsp
[MAX_PDU_OUT_SIZE
- PDU_HEADER_SIZE
], *sdu_out
;
502 int transaction_id
, plen
;
507 fprintf(stderr
, "%s: short SDP PDU (%iB).\n", __FUNCTION__
, len
);
512 transaction_id
= (data
[0] << 8) | data
[1];
513 plen
= (data
[2] << 8) | data
[3];
518 fprintf(stderr
, "%s: wrong SDP PDU length (%iB != %iB).\n",
519 __FUNCTION__
, plen
, len
);
520 err
= SDP_INVALID_PDU_SIZE
;
525 case SDP_SVC_SEARCH_REQ
:
526 rsp_len
= sdp_svc_search(sdp
, rsp
, data
, len
);
527 pdu_id
= SDP_SVC_SEARCH_RSP
;
530 case SDP_SVC_ATTR_REQ
:
531 rsp_len
= sdp_attr_get(sdp
, rsp
, data
, len
);
532 pdu_id
= SDP_SVC_ATTR_RSP
;
535 case SDP_SVC_SEARCH_ATTR_REQ
:
536 rsp_len
= sdp_svc_search_attr_get(sdp
, rsp
, data
, len
);
537 pdu_id
= SDP_SVC_SEARCH_ATTR_RSP
;
541 case SDP_SVC_ATTR_RSP
:
542 case SDP_SVC_SEARCH_RSP
:
543 case SDP_SVC_SEARCH_ATTR_RSP
:
545 fprintf(stderr
, "%s: unexpected SDP PDU ID %02x.\n",
546 __FUNCTION__
, pdu_id
);
547 err
= SDP_INVALID_SYNTAX
;
558 pdu_id
= SDP_ERROR_RSP
;
559 rsp
[rsp_len
++] = err
>> 8;
560 rsp
[rsp_len
++] = err
& 0xff;
563 sdu_out
= sdp
->channel
->sdu_out(sdp
->channel
, rsp_len
+ PDU_HEADER_SIZE
);
566 sdu_out
[1] = transaction_id
>> 8;
567 sdu_out
[2] = transaction_id
& 0xff;
568 sdu_out
[3] = rsp_len
>> 8;
569 sdu_out
[4] = rsp_len
& 0xff;
570 memcpy(sdu_out
+ PDU_HEADER_SIZE
, rsp
, rsp_len
);
572 sdp
->channel
->sdu_submit(sdp
->channel
);
575 static void bt_l2cap_sdp_close_ch(void *opaque
)
577 struct bt_l2cap_sdp_state_s
*sdp
= opaque
;
580 for (i
= 0; i
< sdp
->services
; i
++) {
581 g_free(sdp
->service_list
[i
].attribute_list
->pair
);
582 g_free(sdp
->service_list
[i
].attribute_list
);
583 g_free(sdp
->service_list
[i
].uuid
);
585 g_free(sdp
->service_list
);
589 struct sdp_def_service_s
{
591 struct sdp_def_attribute_s
{
593 struct sdp_def_data_element_s
{
598 struct sdp_def_data_element_s
*list
;
604 /* Calculate a safe byte count to allocate that will store the given
605 * element, at the same time count elements of a UUID type. */
606 static int sdp_attr_max_size(struct sdp_def_data_element_s
*element
,
609 int type
= element
->type
& ~SDP_DSIZE_MASK
;
612 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_UUID
||
613 type
== SDP_DTYPE_BOOL
) {
614 if (type
== SDP_DTYPE_UUID
)
616 return 1 + (1 << (element
->type
& SDP_DSIZE_MASK
));
619 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
620 if (element
->type
& SDP_DSIZE_MASK
) {
621 for (len
= 0; element
->value
.str
[len
] |
622 element
->value
.str
[len
+ 1]; len
++);
625 return 2 + strlen(element
->value
.str
);
628 if (type
!= SDP_DTYPE_SEQ
)
631 element
= element
->value
.list
;
632 while (element
->type
)
633 len
+= sdp_attr_max_size(element
++, uuids
);
640 static int sdp_attr_write(uint8_t *data
,
641 struct sdp_def_data_element_s
*element
, int **uuid
)
643 int type
= element
->type
& ~SDP_DSIZE_MASK
;
646 if (type
== SDP_DTYPE_UINT
|| type
== SDP_DTYPE_BOOL
) {
647 data
[len
++] = element
->type
;
648 if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_1
)
649 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
650 else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_2
) {
651 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
652 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
653 } else if ((element
->type
& SDP_DSIZE_MASK
) == SDP_DSIZE_4
) {
654 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
655 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
656 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
657 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
663 if (type
== SDP_DTYPE_UUID
) {
664 *(*uuid
) ++ = element
->value
.uint
;
666 data
[len
++] = element
->type
;
667 data
[len
++] = (element
->value
.uint
>> 24) & 0xff;
668 data
[len
++] = (element
->value
.uint
>> 16) & 0xff;
669 data
[len
++] = (element
->value
.uint
>> 8) & 0xff;
670 data
[len
++] = (element
->value
.uint
>> 0) & 0xff;
671 memcpy(data
+ len
, bt_base_uuid
, 12);
676 data
[0] = type
| SDP_DSIZE_NEXT1
;
677 if (type
== SDP_DTYPE_STRING
|| type
== SDP_DTYPE_URL
) {
678 if (element
->type
& SDP_DSIZE_MASK
)
679 for (len
= 0; element
->value
.str
[len
] |
680 element
->value
.str
[len
+ 1]; len
++);
682 len
= strlen(element
->value
.str
);
683 memcpy(data
+ 2, element
->value
.str
, data
[1] = len
);
689 element
= element
->value
.list
;
690 while (element
->type
)
691 len
+= sdp_attr_write(data
+ len
, element
++, uuid
);
697 static int sdp_attributeid_compare(const struct sdp_service_attribute_s
*a
,
698 const struct sdp_service_attribute_s
*b
)
700 return (int) b
->attribute_id
- a
->attribute_id
;
703 static int sdp_uuid_compare(const int *a
, const int *b
)
708 static void sdp_service_record_build(struct sdp_service_record_s
*record
,
709 struct sdp_def_service_s
*def
, int handle
)
716 while (def
->attributes
[record
->attributes
].data
.type
) {
718 len
+= sdp_attr_max_size(&def
->attributes
[record
->attributes
++].data
,
721 record
->uuids
= pow2ceil(record
->uuids
);
722 record
->attribute_list
=
723 g_malloc0(record
->attributes
* sizeof(*record
->attribute_list
));
725 g_malloc0(record
->uuids
* sizeof(*record
->uuid
));
726 data
= g_malloc(len
);
728 record
->attributes
= 0;
730 while (def
->attributes
[record
->attributes
].data
.type
) {
731 record
->attribute_list
[record
->attributes
].pair
= data
;
734 data
[len
++] = SDP_DTYPE_UINT
| SDP_DSIZE_2
;
735 data
[len
++] = def
->attributes
[record
->attributes
].id
>> 8;
736 data
[len
++] = def
->attributes
[record
->attributes
].id
& 0xff;
737 len
+= sdp_attr_write(data
+ len
,
738 &def
->attributes
[record
->attributes
].data
, &uuid
);
740 /* Special case: assign a ServiceRecordHandle in sequence */
741 if (def
->attributes
[record
->attributes
].id
== SDP_ATTR_RECORD_HANDLE
)
742 def
->attributes
[record
->attributes
].data
.value
.uint
= handle
;
743 /* Note: we could also assign a ServiceDescription based on
744 * sdp->device.device->lmp_name. */
746 record
->attribute_list
[record
->attributes
++].len
= len
;
750 /* Sort the attribute list by the AttributeID */
751 qsort(record
->attribute_list
, record
->attributes
,
752 sizeof(*record
->attribute_list
),
753 (void *) sdp_attributeid_compare
);
754 /* Sort the searchable UUIDs list for bisection */
755 qsort(record
->uuid
, record
->uuids
,
756 sizeof(*record
->uuid
),
757 (void *) sdp_uuid_compare
);
760 static void sdp_service_db_build(struct bt_l2cap_sdp_state_s
*sdp
,
761 struct sdp_def_service_s
**service
)
764 while (service
[sdp
->services
])
767 g_malloc0(sdp
->services
* sizeof(*sdp
->service_list
));
771 sdp_service_record_build(&sdp
->service_list
[sdp
->services
],
772 *service
, sdp
->services
);
778 #define LAST { .type = 0 }
779 #define SERVICE(name, attrs) \
780 static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
781 .attributes = { attrs { .data = LAST } }, \
783 #define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
784 #define UINT8(val) { \
785 .type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
788 #define UINT16(val) { \
789 .type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
792 #define UINT32(val) { \
793 .type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
796 #define UUID128(val) { \
797 .type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
801 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
804 #define SDP_FALSE { \
805 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
808 #define STRING(val) { \
809 .type = SDP_DTYPE_STRING, \
812 #define ARRAY(...) { \
813 .type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
814 .value.str = (char []) { __VA_ARGS__, 0, 0 }, \
817 .type = SDP_DTYPE_URL, \
821 #define LIST(val) { \
822 .type = SDP_DTYPE_SEQ, \
823 .value.list = (struct sdp_def_data_element_s []) { val LAST }, \
827 /* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
828 * in resulting SDP data representation size. */
831 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
832 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(HID_SVCLASS_ID
)))
833 ATTRIBUTE(RECORD_STATE
, UINT32(1))
834 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
835 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_HID_CTRL
))
836 LIST(UUID128(HIDP_UUID
))
838 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
839 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
840 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
842 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
843 LIST(UUID128(HID_PROFILE_ID
) UINT16(0x0100))
845 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
846 ATTRIBUTE(SVCNAME_PRIMARY
, STRING("QEMU Bluetooth HID"))
847 ATTRIBUTE(SVCDESC_PRIMARY
, STRING("QEMU Keyboard/Mouse"))
848 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
850 /* Profile specific */
851 ATTRIBUTE(DEVICE_RELEASE_NUMBER
, UINT16(0x0091)) /* Deprecated, remove */
852 ATTRIBUTE(PARSER_VERSION
, UINT16(0x0111))
853 /* TODO: extract from l2cap_device->device.class[0] */
854 ATTRIBUTE(DEVICE_SUBCLASS
, UINT8(0x40))
855 ATTRIBUTE(COUNTRY_CODE
, UINT8(0x15))
856 ATTRIBUTE(VIRTUAL_CABLE
, SDP_TRUE
)
857 ATTRIBUTE(RECONNECT_INITIATE
, SDP_FALSE
)
858 /* TODO: extract from hid->usbdev->report_desc */
859 ATTRIBUTE(DESCRIPTOR_LIST
, LIST(
860 LIST(UINT8(0x22) ARRAY(
861 0x05, 0x01, /* Usage Page (Generic Desktop) */
862 0x09, 0x06, /* Usage (Keyboard) */
863 0xa1, 0x01, /* Collection (Application) */
864 0x75, 0x01, /* Report Size (1) */
865 0x95, 0x08, /* Report Count (8) */
866 0x05, 0x07, /* Usage Page (Key Codes) */
867 0x19, 0xe0, /* Usage Minimum (224) */
868 0x29, 0xe7, /* Usage Maximum (231) */
869 0x15, 0x00, /* Logical Minimum (0) */
870 0x25, 0x01, /* Logical Maximum (1) */
871 0x81, 0x02, /* Input (Data, Variable, Absolute) */
872 0x95, 0x01, /* Report Count (1) */
873 0x75, 0x08, /* Report Size (8) */
874 0x81, 0x01, /* Input (Constant) */
875 0x95, 0x05, /* Report Count (5) */
876 0x75, 0x01, /* Report Size (1) */
877 0x05, 0x08, /* Usage Page (LEDs) */
878 0x19, 0x01, /* Usage Minimum (1) */
879 0x29, 0x05, /* Usage Maximum (5) */
880 0x91, 0x02, /* Output (Data, Variable, Absolute) */
881 0x95, 0x01, /* Report Count (1) */
882 0x75, 0x03, /* Report Size (3) */
883 0x91, 0x01, /* Output (Constant) */
884 0x95, 0x06, /* Report Count (6) */
885 0x75, 0x08, /* Report Size (8) */
886 0x15, 0x00, /* Logical Minimum (0) */
887 0x25, 0xff, /* Logical Maximum (255) */
888 0x05, 0x07, /* Usage Page (Key Codes) */
889 0x19, 0x00, /* Usage Minimum (0) */
890 0x29, 0xff, /* Usage Maximum (255) */
891 0x81, 0x00, /* Input (Data, Array) */
892 0xc0 /* End Collection */
894 ATTRIBUTE(LANG_ID_BASE_LIST
, LIST(
895 LIST(UINT16(0x0409) UINT16(0x0100))
897 ATTRIBUTE(SDP_DISABLE
, SDP_FALSE
)
898 ATTRIBUTE(BATTERY_POWER
, SDP_TRUE
)
899 ATTRIBUTE(REMOTE_WAKEUP
, SDP_TRUE
)
900 ATTRIBUTE(BOOT_DEVICE
, SDP_TRUE
) /* XXX: untested */
901 ATTRIBUTE(SUPERVISION_TIMEOUT
, UINT16(0x0c80))
902 ATTRIBUTE(NORMALLY_CONNECTABLE
, SDP_TRUE
)
903 ATTRIBUTE(PROFILE_VERSION
, UINT16(0x0100))
907 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
908 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(SDP_SERVER_SVCLASS_ID
)))
909 ATTRIBUTE(RECORD_STATE
, UINT32(1))
910 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
911 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
912 LIST(UUID128(SDP_UUID
))
914 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
915 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
916 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
918 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
919 LIST(UUID128(SDP_SERVER_PROFILE_ID
) UINT16(0x0100))
921 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
922 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
924 /* Profile specific */
925 ATTRIBUTE(VERSION_NUM_LIST
, LIST(UINT16(0x0100)))
926 ATTRIBUTE(SVCDB_STATE
, UINT32(1))
930 ATTRIBUTE(RECORD_HANDLE
, UINT32(0)) /* Filled in later */
931 ATTRIBUTE(SVCLASS_ID_LIST
, LIST(UUID128(PNP_INFO_SVCLASS_ID
)))
932 ATTRIBUTE(RECORD_STATE
, UINT32(1))
933 ATTRIBUTE(PROTO_DESC_LIST
, LIST(
934 LIST(UUID128(L2CAP_UUID
) UINT16(BT_PSM_SDP
))
935 LIST(UUID128(SDP_UUID
))
937 ATTRIBUTE(BROWSE_GRP_LIST
, LIST(UUID128(0x1002)))
938 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST
, LIST(
939 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
941 ATTRIBUTE(PFILE_DESC_LIST
, LIST(
942 LIST(UUID128(PNP_INFO_PROFILE_ID
) UINT16(0x0100))
944 ATTRIBUTE(DOC_URL
, URL("http://bellard.org/qemu/user-doc.html"))
945 ATTRIBUTE(SVCPROV_PRIMARY
, STRING("QEMU"))
947 /* Profile specific */
948 ATTRIBUTE(SPECIFICATION_ID
, UINT16(0x0100))
949 ATTRIBUTE(VERSION
, UINT16(0x0100))
950 ATTRIBUTE(PRIMARY_RECORD
, SDP_TRUE
)
953 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s
*dev
,
954 struct bt_l2cap_conn_params_s
*params
)
956 struct bt_l2cap_sdp_state_s
*sdp
= g_malloc0(sizeof(*sdp
));
957 struct sdp_def_service_s
*services
[] = {
964 sdp
->channel
= params
;
965 sdp
->channel
->opaque
= sdp
;
966 sdp
->channel
->close
= bt_l2cap_sdp_close_ch
;
967 sdp
->channel
->sdu_in
= bt_l2cap_sdp_sdu_in
;
969 sdp_service_db_build(sdp
, services
);
974 void bt_l2cap_sdp_init(struct bt_l2cap_device_s
*dev
)
976 bt_l2cap_psm_register(dev
, BT_PSM_SDP
,
977 MAX_PDU_OUT_SIZE
, bt_l2cap_sdp_new_ch
);