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"
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 uint32_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;
155 if (sdp_svc_match(sdp, &req, &seqlen))
156 return -SDP_INVALID_SYNTAX;
158 if (sdp_svc_match(sdp, &req, &len)) {
159 return -SDP_INVALID_SYNTAX;
164 return -SDP_INVALID_SYNTAX;
165 max = (req[0] << 8) | req[1];
170 if (len <= sizeof(int))
171 return -SDP_INVALID_SYNTAX;
173 memcpy(&start, req + 1, sizeof(int));
178 return -SDP_INVALID_SYNTAX;
180 /* Output the results */
184 for (i = 0; i < sdp->services; i ++)
185 if (sdp->service_list[i].match) {
186 if (count >= start && count < max && len + 4 < MAX_RSP_PARAM_SIZE) {
188 memcpy(rsp + len, &handle, 4);
197 rsp[1] = count & 0xff;
198 rsp[2] = (end - start) >> 8;
199 rsp[3] = (end - start) & 0xff;
202 rsp[len ++] = sizeof(int);
203 memcpy(rsp + len, &end, sizeof(int));
211 static int sdp_attr_match(struct sdp_service_record_s *record,
212 const uint8_t **req, ssize_t *len)
216 if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_2)) {
221 start = (*(*req) ++) << 8;
225 } else if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_4)) {
230 start = (*(*req) ++) << 8;
232 end = (*(*req) ++) << 8;
238 for (i = 0; i < record->attributes; i ++)
239 if (record->attribute_list[i].attribute_id >= start &&
240 record->attribute_list[i].attribute_id <= end)
241 record->attribute_list[i].match = 1;
246 static ssize_t sdp_attr_get(struct bt_l2cap_sdp_state_s *sdp,
247 uint8_t *rsp, const uint8_t *req, ssize_t len)
250 int i, start, end, max;
252 struct sdp_service_record_s *record;
255 /* Perform the search */
257 return -SDP_INVALID_SYNTAX;
258 memcpy(&handle, req, 4);
262 if (handle < 0 || handle > sdp->services)
263 return -SDP_INVALID_RECORD_HANDLE;
264 record = &sdp->service_list[handle];
266 for (i = 0; i < record->attributes; i ++)
267 record->attribute_list[i].match = 0;
269 max = (req[0] << 8) | req[1];
273 return -SDP_INVALID_SYNTAX;
275 if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
276 seqlen = sdp_datalen(&req, &len);
277 if (seqlen < 3 || len < seqlen)
278 return -SDP_INVALID_SYNTAX;
282 if (sdp_attr_match(record, &req, &seqlen))
283 return -SDP_INVALID_SYNTAX;
285 if (sdp_attr_match(record, &req, &len)) {
286 return -SDP_INVALID_SYNTAX;
291 return -SDP_INVALID_SYNTAX;
294 if (len <= sizeof(int))
295 return -SDP_INVALID_SYNTAX;
297 memcpy(&start, req + 1, sizeof(int));
302 return -SDP_INVALID_SYNTAX;
304 /* Output the results */
306 max = MIN(max, MAX_RSP_PARAM_SIZE);
309 for (i = 0; i < record->attributes; i ++)
310 if (record->attribute_list[i].match) {
311 if (len >= 0 && len + record->attribute_list[i].len < max) {
312 memcpy(lst + len, record->attribute_list[i].pair,
313 record->attribute_list[i].len);
314 end = len + record->attribute_list[i].len;
316 len += record->attribute_list[i].len;
319 lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
320 lst[1] = (len + start - 3) >> 8;
321 lst[2] = (len + start - 3) & 0xff;
329 lst[end ++] = sizeof(int);
330 memcpy(lst + end, &len, sizeof(int));
338 static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s *sdp,
339 const uint8_t **req, ssize_t *len)
341 int i, j, start, end;
342 struct sdp_service_record_s *record;
344 if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_2)) {
349 start = (*(*req) ++) << 8;
353 } else if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_4)) {
358 start = (*(*req) ++) << 8;
360 end = (*(*req) ++) << 8;
366 for (i = 0; i < sdp->services; i ++)
367 if ((record = &sdp->service_list[i])->match)
368 for (j = 0; j < record->attributes; j ++)
369 if (record->attribute_list[j].attribute_id >= start &&
370 record->attribute_list[j].attribute_id <= end)
371 record->attribute_list[j].match = 1;
376 static ssize_t sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s *sdp,
377 uint8_t *rsp, const uint8_t *req, ssize_t len)
380 int i, j, start, end, max;
381 struct sdp_service_record_s *record;
384 /* Perform the search */
385 for (i = 0; i < sdp->services; i ++) {
386 sdp->service_list[i].match = 0;
387 for (j = 0; j < sdp->service_list[i].attributes; j ++)
388 sdp->service_list[i].attribute_list[j].match = 0;
392 return -SDP_INVALID_SYNTAX;
393 if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
394 seqlen = sdp_datalen(&req, &len);
395 if (seqlen < 3 || len < seqlen)
396 return -SDP_INVALID_SYNTAX;
400 if (sdp_svc_match(sdp, &req, &seqlen))
401 return -SDP_INVALID_SYNTAX;
403 if (sdp_svc_match(sdp, &req, &len)) {
404 return -SDP_INVALID_SYNTAX;
409 return -SDP_INVALID_SYNTAX;
410 max = (req[0] << 8) | req[1];
414 return -SDP_INVALID_SYNTAX;
416 if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
417 seqlen = sdp_datalen(&req, &len);
418 if (seqlen < 3 || len < seqlen)
419 return -SDP_INVALID_SYNTAX;
423 if (sdp_svc_attr_match(sdp, &req, &seqlen))
424 return -SDP_INVALID_SYNTAX;
426 if (sdp_svc_attr_match(sdp, &req, &len)) {
427 return -SDP_INVALID_SYNTAX;
432 return -SDP_INVALID_SYNTAX;
435 if (len <= sizeof(int))
436 return -SDP_INVALID_SYNTAX;
438 memcpy(&start, req + 1, sizeof(int));
443 return -SDP_INVALID_SYNTAX;
445 /* Output the results */
446 /* This assumes empty attribute lists are never to be returned even
447 * for matching Service Records. In practice this shouldn't happen
448 * as the requestor will usually include the always present
449 * ServiceRecordHandle AttributeID in AttributeIDList. */
451 max = MIN(max, MAX_RSP_PARAM_SIZE);
454 for (i = 0; i < sdp->services; i ++)
455 if ((record = &sdp->service_list[i])->match) {
458 for (j = 0; j < record->attributes; j ++)
459 if (record->attribute_list[j].match) {
461 if (len + record->attribute_list[j].len < max) {
462 memcpy(lst + len, record->attribute_list[j].pair,
463 record->attribute_list[j].len);
464 end = len + record->attribute_list[j].len;
466 len += record->attribute_list[j].len;
470 else if (seqlen >= 3 && seqlen < max) {
471 lst[seqlen - 3] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
472 lst[seqlen - 2] = (len - seqlen) >> 8;
473 lst[seqlen - 1] = (len - seqlen) & 0xff;
476 if (len == 3 - start)
478 else if (0 >= start) {
479 lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
480 lst[1] = (len + start - 3) >> 8;
481 lst[2] = (len + start - 3) & 0xff;
489 lst[end ++] = sizeof(int);
490 memcpy(lst + end, &len, sizeof(int));
498 static void bt_l2cap_sdp_sdu_in(void *opaque, const uint8_t *data, int len)
500 struct bt_l2cap_sdp_state_s *sdp = opaque;
501 enum bt_sdp_cmd pdu_id;
502 uint8_t rsp[MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE], *sdu_out;
503 int transaction_id, plen;
508 fprintf(stderr, "%s: short SDP PDU (%iB).\n", __FUNCTION__, len);
513 transaction_id = (data[0] << 8) | data[1];
514 plen = (data[2] << 8) | data[3];
519 fprintf(stderr, "%s: wrong SDP PDU length (%iB != %iB).\n",
520 __FUNCTION__, plen, len);
521 err = SDP_INVALID_PDU_SIZE;
526 case SDP_SVC_SEARCH_REQ:
527 rsp_len = sdp_svc_search(sdp, rsp, data, len);
528 pdu_id = SDP_SVC_SEARCH_RSP;
531 case SDP_SVC_ATTR_REQ:
532 rsp_len = sdp_attr_get(sdp, rsp, data, len);
533 pdu_id = SDP_SVC_ATTR_RSP;
536 case SDP_SVC_SEARCH_ATTR_REQ:
537 rsp_len = sdp_svc_search_attr_get(sdp, rsp, data, len);
538 pdu_id = SDP_SVC_SEARCH_ATTR_RSP;
542 case SDP_SVC_ATTR_RSP:
543 case SDP_SVC_SEARCH_RSP:
544 case SDP_SVC_SEARCH_ATTR_RSP:
546 fprintf(stderr, "%s: unexpected SDP PDU ID %02x.\n",
547 __FUNCTION__, pdu_id);
548 err = SDP_INVALID_SYNTAX;
559 pdu_id = SDP_ERROR_RSP;
560 rsp[rsp_len ++] = err >> 8;
561 rsp[rsp_len ++] = err & 0xff;
564 sdu_out = sdp->channel->sdu_out(sdp->channel, rsp_len + PDU_HEADER_SIZE);
567 sdu_out[1] = transaction_id >> 8;
568 sdu_out[2] = transaction_id & 0xff;
569 sdu_out[3] = rsp_len >> 8;
570 sdu_out[4] = rsp_len & 0xff;
571 memcpy(sdu_out + PDU_HEADER_SIZE, rsp, rsp_len);
573 sdp->channel->sdu_submit(sdp->channel);
576 static void bt_l2cap_sdp_close_ch(void *opaque)
578 struct bt_l2cap_sdp_state_s *sdp = opaque;
581 for (i = 0; i < sdp->services; i ++) {
582 g_free(sdp->service_list[i].attribute_list->pair);
583 g_free(sdp->service_list[i].attribute_list);
584 g_free(sdp->service_list[i].uuid);
586 g_free(sdp->service_list);
590 struct sdp_def_service_s {
592 struct sdp_def_attribute_s {
594 struct sdp_def_data_element_s {
599 struct sdp_def_data_element_s *list;
605 /* Calculate a safe byte count to allocate that will store the given
606 * element, at the same time count elements of a UUID type. */
607 static int sdp_attr_max_size(struct sdp_def_data_element_s *element,
610 int type = element->type & ~SDP_DSIZE_MASK;
613 if (type == SDP_DTYPE_UINT || type == SDP_DTYPE_UUID ||
614 type == SDP_DTYPE_BOOL) {
615 if (type == SDP_DTYPE_UUID)
617 return 1 + (1 << (element->type & SDP_DSIZE_MASK));
620 if (type == SDP_DTYPE_STRING || type == SDP_DTYPE_URL) {
621 if (element->type & SDP_DSIZE_MASK) {
622 for (len = 0; element->value.str[len] |
623 element->value.str[len + 1]; len ++);
626 return 2 + strlen(element->value.str);
629 if (type != SDP_DTYPE_SEQ)
632 element = element->value.list;
633 while (element->type)
634 len += sdp_attr_max_size(element ++, uuids);
641 static int sdp_attr_write(uint8_t *data,
642 struct sdp_def_data_element_s *element, int **uuid)
644 int type = element->type & ~SDP_DSIZE_MASK;
647 if (type == SDP_DTYPE_UINT || type == SDP_DTYPE_BOOL) {
648 data[len ++] = element->type;
649 if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_1)
650 data[len ++] = (element->value.uint >> 0) & 0xff;
651 else if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_2) {
652 data[len ++] = (element->value.uint >> 8) & 0xff;
653 data[len ++] = (element->value.uint >> 0) & 0xff;
654 } else if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_4) {
655 data[len ++] = (element->value.uint >> 24) & 0xff;
656 data[len ++] = (element->value.uint >> 16) & 0xff;
657 data[len ++] = (element->value.uint >> 8) & 0xff;
658 data[len ++] = (element->value.uint >> 0) & 0xff;
664 if (type == SDP_DTYPE_UUID) {
665 *(*uuid) ++ = element->value.uint;
667 data[len ++] = element->type;
668 data[len ++] = (element->value.uint >> 24) & 0xff;
669 data[len ++] = (element->value.uint >> 16) & 0xff;
670 data[len ++] = (element->value.uint >> 8) & 0xff;
671 data[len ++] = (element->value.uint >> 0) & 0xff;
672 memcpy(data + len, bt_base_uuid, 12);
677 data[0] = type | SDP_DSIZE_NEXT1;
678 if (type == SDP_DTYPE_STRING || type == SDP_DTYPE_URL) {
679 if (element->type & SDP_DSIZE_MASK)
680 for (len = 0; element->value.str[len] |
681 element->value.str[len + 1]; len ++);
683 len = strlen(element->value.str);
684 memcpy(data + 2, element->value.str, data[1] = len);
690 element = element->value.list;
691 while (element->type)
692 len += sdp_attr_write(data + len, element ++, uuid);
698 static int sdp_attributeid_compare(const struct sdp_service_attribute_s *a,
699 const struct sdp_service_attribute_s *b)
701 return (int) b->attribute_id - a->attribute_id;
704 static int sdp_uuid_compare(const int *a, const int *b)
709 static void sdp_service_record_build(struct sdp_service_record_s *record,
710 struct sdp_def_service_s *def, int handle)
717 while (def->attributes[record->attributes].data.type) {
719 len += sdp_attr_max_size(&def->attributes[record->attributes ++].data,
722 record->uuids = pow2ceil(record->uuids);
723 record->attribute_list =
724 g_malloc0(record->attributes * sizeof(*record->attribute_list));
726 g_malloc0(record->uuids * sizeof(*record->uuid));
727 data = g_malloc(len);
729 record->attributes = 0;
731 while (def->attributes[record->attributes].data.type) {
732 record->attribute_list[record->attributes].pair = data;
735 data[len ++] = SDP_DTYPE_UINT | SDP_DSIZE_2;
736 data[len ++] = def->attributes[record->attributes].id >> 8;
737 data[len ++] = def->attributes[record->attributes].id & 0xff;
738 len += sdp_attr_write(data + len,
739 &def->attributes[record->attributes].data, &uuid);
741 /* Special case: assign a ServiceRecordHandle in sequence */
742 if (def->attributes[record->attributes].id == SDP_ATTR_RECORD_HANDLE)
743 def->attributes[record->attributes].data.value.uint = handle;
744 /* Note: we could also assign a ServiceDescription based on
745 * sdp->device.device->lmp_name. */
747 record->attribute_list[record->attributes ++].len = len;
751 /* Sort the attribute list by the AttributeID */
752 qsort(record->attribute_list, record->attributes,
753 sizeof(*record->attribute_list),
754 (void *) sdp_attributeid_compare);
755 /* Sort the searchable UUIDs list for bisection */
756 qsort(record->uuid, record->uuids,
757 sizeof(*record->uuid),
758 (void *) sdp_uuid_compare);
761 static void sdp_service_db_build(struct bt_l2cap_sdp_state_s *sdp,
762 struct sdp_def_service_s **service)
765 while (service[sdp->services])
768 g_malloc0(sdp->services * sizeof(*sdp->service_list));
772 sdp_service_record_build(&sdp->service_list[sdp->services],
773 *service, sdp->services);
779 #define LAST { .type = 0 }
780 #define SERVICE(name, attrs) \
781 static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
782 .attributes = { attrs { .data = LAST } }, \
784 #define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
785 #define UINT8(val) { \
786 .type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
789 #define UINT16(val) { \
790 .type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
793 #define UINT32(val) { \
794 .type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
797 #define UUID128(val) { \
798 .type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
802 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
805 #define SDP_FALSE { \
806 .type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
809 #define STRING(val) { \
810 .type = SDP_DTYPE_STRING, \
813 #define ARRAY(...) { \
814 .type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
815 .value.str = (char []) { __VA_ARGS__, 0, 0 }, \
818 .type = SDP_DTYPE_URL, \
822 #define LIST(val) { \
823 .type = SDP_DTYPE_SEQ, \
824 .value.list = (struct sdp_def_data_element_s []) { val LAST }, \
828 /* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
829 * in resulting SDP data representation size. */
832 ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
833 ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(HID_SVCLASS_ID)))
834 ATTRIBUTE(RECORD_STATE, UINT32(1))
835 ATTRIBUTE(PROTO_DESC_LIST, LIST(
836 LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_HID_CTRL))
837 LIST(UUID128(HIDP_UUID))
839 ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
840 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
841 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
843 ATTRIBUTE(PFILE_DESC_LIST, LIST(
844 LIST(UUID128(HID_PROFILE_ID) UINT16(0x0100))
846 ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
847 ATTRIBUTE(SVCNAME_PRIMARY, STRING("QEMU Bluetooth HID"))
848 ATTRIBUTE(SVCDESC_PRIMARY, STRING("QEMU Keyboard/Mouse"))
849 ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU"))
851 /* Profile specific */
852 ATTRIBUTE(DEVICE_RELEASE_NUMBER, UINT16(0x0091)) /* Deprecated, remove */
853 ATTRIBUTE(PARSER_VERSION, UINT16(0x0111))
854 /* TODO: extract from l2cap_device->device.class[0] */
855 ATTRIBUTE(DEVICE_SUBCLASS, UINT8(0x40))
856 ATTRIBUTE(COUNTRY_CODE, UINT8(0x15))
857 ATTRIBUTE(VIRTUAL_CABLE, SDP_TRUE)
858 ATTRIBUTE(RECONNECT_INITIATE, SDP_FALSE)
859 /* TODO: extract from hid->usbdev->report_desc */
860 ATTRIBUTE(DESCRIPTOR_LIST, LIST(
861 LIST(UINT8(0x22) ARRAY(
862 0x05, 0x01, /* Usage Page (Generic Desktop) */
863 0x09, 0x06, /* Usage (Keyboard) */
864 0xa1, 0x01, /* Collection (Application) */
865 0x75, 0x01, /* Report Size (1) */
866 0x95, 0x08, /* Report Count (8) */
867 0x05, 0x07, /* Usage Page (Key Codes) */
868 0x19, 0xe0, /* Usage Minimum (224) */
869 0x29, 0xe7, /* Usage Maximum (231) */
870 0x15, 0x00, /* Logical Minimum (0) */
871 0x25, 0x01, /* Logical Maximum (1) */
872 0x81, 0x02, /* Input (Data, Variable, Absolute) */
873 0x95, 0x01, /* Report Count (1) */
874 0x75, 0x08, /* Report Size (8) */
875 0x81, 0x01, /* Input (Constant) */
876 0x95, 0x05, /* Report Count (5) */
877 0x75, 0x01, /* Report Size (1) */
878 0x05, 0x08, /* Usage Page (LEDs) */
879 0x19, 0x01, /* Usage Minimum (1) */
880 0x29, 0x05, /* Usage Maximum (5) */
881 0x91, 0x02, /* Output (Data, Variable, Absolute) */
882 0x95, 0x01, /* Report Count (1) */
883 0x75, 0x03, /* Report Size (3) */
884 0x91, 0x01, /* Output (Constant) */
885 0x95, 0x06, /* Report Count (6) */
886 0x75, 0x08, /* Report Size (8) */
887 0x15, 0x00, /* Logical Minimum (0) */
888 0x25, 0xff, /* Logical Maximum (255) */
889 0x05, 0x07, /* Usage Page (Key Codes) */
890 0x19, 0x00, /* Usage Minimum (0) */
891 0x29, 0xff, /* Usage Maximum (255) */
892 0x81, 0x00, /* Input (Data, Array) */
893 0xc0 /* End Collection */
895 ATTRIBUTE(LANG_ID_BASE_LIST, LIST(
896 LIST(UINT16(0x0409) UINT16(0x0100))
898 ATTRIBUTE(SDP_DISABLE, SDP_FALSE)
899 ATTRIBUTE(BATTERY_POWER, SDP_TRUE)
900 ATTRIBUTE(REMOTE_WAKEUP, SDP_TRUE)
901 ATTRIBUTE(BOOT_DEVICE, SDP_TRUE) /* XXX: untested */
902 ATTRIBUTE(SUPERVISION_TIMEOUT, UINT16(0x0c80))
903 ATTRIBUTE(NORMALLY_CONNECTABLE, SDP_TRUE)
904 ATTRIBUTE(PROFILE_VERSION, UINT16(0x0100))
908 ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
909 ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(SDP_SERVER_SVCLASS_ID)))
910 ATTRIBUTE(RECORD_STATE, UINT32(1))
911 ATTRIBUTE(PROTO_DESC_LIST, LIST(
912 LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_SDP))
913 LIST(UUID128(SDP_UUID))
915 ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
916 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
917 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
919 ATTRIBUTE(PFILE_DESC_LIST, LIST(
920 LIST(UUID128(SDP_SERVER_PROFILE_ID) UINT16(0x0100))
922 ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
923 ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU"))
925 /* Profile specific */
926 ATTRIBUTE(VERSION_NUM_LIST, LIST(UINT16(0x0100)))
927 ATTRIBUTE(SVCDB_STATE , UINT32(1))
931 ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
932 ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(PNP_INFO_SVCLASS_ID)))
933 ATTRIBUTE(RECORD_STATE, UINT32(1))
934 ATTRIBUTE(PROTO_DESC_LIST, LIST(
935 LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_SDP))
936 LIST(UUID128(SDP_UUID))
938 ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
939 ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
940 UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
942 ATTRIBUTE(PFILE_DESC_LIST, LIST(
943 LIST(UUID128(PNP_INFO_PROFILE_ID) UINT16(0x0100))
945 ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
946 ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU"))
948 /* Profile specific */
949 ATTRIBUTE(SPECIFICATION_ID, UINT16(0x0100))
950 ATTRIBUTE(VERSION, UINT16(0x0100))
951 ATTRIBUTE(PRIMARY_RECORD, SDP_TRUE)
954 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
955 struct bt_l2cap_conn_params_s *params)
957 struct bt_l2cap_sdp_state_s *sdp = g_malloc0(sizeof(*sdp));
958 struct sdp_def_service_s *services[] = {
965 sdp->channel = params;
966 sdp->channel->opaque = sdp;
967 sdp->channel->close = bt_l2cap_sdp_close_ch;
968 sdp->channel->sdu_in = bt_l2cap_sdp_sdu_in;
970 sdp_service_db_build(sdp, services);
975 void bt_l2cap_sdp_init(struct bt_l2cap_device_s *dev)
977 bt_l2cap_psm_register(dev, BT_PSM_SDP,
978 MAX_PDU_OUT_SIZE, bt_l2cap_sdp_new_ch);