Add L2CAP logic and a virtual SDP server for use in emulated devices.

Note that the L2CAP flow-controlled mode is not fully supported.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5346 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
balrog 2008-09-29 00:14:22 +00:00
parent 4e38eb5438
commit 4d2d181cdb
4 changed files with 2886 additions and 1 deletions

View File

@ -81,7 +81,7 @@ OBJS+=scsi-generic.o
OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o
OBJS+=usb-serial.o usb-net.o
OBJS+=sd.o ssi-sd.o
OBJS+=bt.o bt-host.o bt-hci.o
OBJS+=bt.o bt-host.o bt-l2cap.o bt-sdp.o bt-hci.o
ifdef CONFIG_BRLAPI
OBJS+= baum.o

1364
hw/bt-l2cap.c Normal file

File diff suppressed because it is too large Load Diff

969
hw/bt-sdp.c Normal file
View File

@ -0,0 +1,969 @@
/*
* Service Discover Protocol server for QEMU L2CAP devices
*
* Copyright (C) 2008 Andrzej Zaborowski <balrog@zabor.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include "qemu-common.h"
#include "bt.h"
struct bt_l2cap_sdp_state_s {
struct bt_l2cap_conn_params_s *channel;
struct sdp_service_record_s {
int match;
int *uuid;
int uuids;
struct sdp_service_attribute_s {
int match;
int attribute_id;
int len;
void *pair;
} *attribute_list;
int attributes;
} *service_list;
int services;
};
static ssize_t sdp_datalen(const uint8_t **element, ssize_t *left)
{
size_t len = *(*element) ++ & SDP_DSIZE_MASK;
if (!*left)
return -1;
(*left) --;
if (len < SDP_DSIZE_NEXT1)
return 1 << len;
else if (len == SDP_DSIZE_NEXT1) {
if (*left < 1)
return -1;
(*left) --;
return *(*element) ++;
} else if (len == SDP_DSIZE_NEXT2) {
if (*left < 2)
return -1;
(*left) -= 2;
len = (*(*element) ++) << 8;
return len | (*(*element) ++);
} else {
if (*left < 4)
return -1;
(*left) -= 4;
len = (*(*element) ++) << 24;
len |= (*(*element) ++) << 16;
len |= (*(*element) ++) << 8;
return len | (*(*element) ++);
}
}
static const uint8_t bt_base_uuid[12] = {
0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
};
static int sdp_uuid_match(struct sdp_service_record_s *record,
const uint8_t *uuid, ssize_t datalen)
{
int *lo, hi, val;
if (datalen == 16 || datalen == 4) {
if (datalen == 16 && memcmp(uuid + 4, bt_base_uuid, 12))
return 0;
if (uuid[0] | uuid[1])
return 0;
uuid += 2;
}
val = (uuid[0] << 8) | uuid[1];
lo = record->uuid;
hi = record->uuids;
while (hi >>= 1)
if (lo[hi] <= val)
lo += hi;
return *lo == val;
}
#define CONTINUATION_PARAM_SIZE (1 + sizeof(int))
#define MAX_PDU_OUT_SIZE 96 /* Arbitrary */
#define PDU_HEADER_SIZE 5
#define MAX_RSP_PARAM_SIZE (MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE - \
CONTINUATION_PARAM_SIZE)
static int sdp_svc_match(struct bt_l2cap_sdp_state_s *sdp,
const uint8_t **req, ssize_t *len)
{
size_t datalen;
int i;
if ((**req & ~SDP_DSIZE_MASK) != SDP_DTYPE_UUID)
return 1;
datalen = sdp_datalen(req, len);
if (datalen != 2 && datalen != 4 && datalen != 16)
return 1;
for (i = 0; i < sdp->services; i ++)
if (sdp_uuid_match(&sdp->service_list[i], *req, datalen))
sdp->service_list[i].match = 1;
(*req) += datalen;
(*len) -= datalen;
return 0;
}
static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,
uint8_t *rsp, const uint8_t *req, ssize_t len)
{
ssize_t seqlen;
int i, count, start, end, max;
int32_t handle;
/* Perform the search */
for (i = 0; i < sdp->services; i ++)
sdp->service_list[i].match = 0;
if (len < 1)
return -SDP_INVALID_SYNTAX;
if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
seqlen = sdp_datalen(&req, &len);
if (seqlen < 3 || len < seqlen)
return -SDP_INVALID_SYNTAX;
len -= seqlen;
while (seqlen)
if (sdp_svc_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
} else if (sdp_svc_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
if (len < 3)
return -SDP_INVALID_SYNTAX;
end = (req[0] << 8) | req[1];
req += 2;
len -= 2;
if (*req) {
if (len <= sizeof(int))
return -SDP_INVALID_SYNTAX;
len -= sizeof(int);
memcpy(&start, req + 1, sizeof(int));
} else
start = 0;
if (len > 1);
return -SDP_INVALID_SYNTAX;
/* Output the results */
len = 4;
count = 0;
end = start;
for (i = 0; i < sdp->services; i ++)
if (sdp->service_list[i].match) {
if (count >= start && count < max && len + 4 < MAX_RSP_PARAM_SIZE) {
handle = i;
memcpy(rsp + len, &handle, 4);
len += 4;
end = count + 1;
}
count ++;
}
rsp[0] = count >> 8;
rsp[1] = count & 0xff;
rsp[2] = (end - start) >> 8;
rsp[3] = (end - start) & 0xff;
if (end < count) {
rsp[len ++] = sizeof(int);
memcpy(rsp + len, &end, sizeof(int));
len += 4;
} else
rsp[len ++] = 0;
return len;
}
static int sdp_attr_match(struct sdp_service_record_s *record,
const uint8_t **req, ssize_t *len)
{
int i, start, end;
if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_2)) {
(*req) ++;
if (*len < 3)
return 1;
start = (*(*req) ++) << 8;
start |= *(*req) ++;
end = start;
*len -= 3;
} else if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_4)) {
(*req) ++;
if (*len < 5)
return 1;
start = (*(*req) ++) << 8;
start |= *(*req) ++;
end = (*(*req) ++) << 8;
end |= *(*req) ++;
*len -= 5;
} else
return 1;
for (i = 0; i < record->attributes; i ++)
if (record->attribute_list[i].attribute_id >= start &&
record->attribute_list[i].attribute_id <= end)
record->attribute_list[i].match = 1;
return 0;
}
static ssize_t sdp_attr_get(struct bt_l2cap_sdp_state_s *sdp,
uint8_t *rsp, const uint8_t *req, ssize_t len)
{
ssize_t seqlen;
int i, start, end, max;
int32_t handle;
struct sdp_service_record_s *record;
uint8_t *lst;
/* Perform the search */
if (len < 7)
return -SDP_INVALID_SYNTAX;
memcpy(&handle, req, 6);
req += 4;
len -= 4;
if (handle < 0 || handle > sdp->services)
return -SDP_INVALID_RECORD_HANDLE;
record = &sdp->service_list[handle];
for (i = 0; i < record->attributes; i ++)
record->attribute_list[i].match = 0;
max = (req[0] << 8) | req[1];
req += 2;
len -= 2;
if (max < 0x0007)
return -SDP_INVALID_SYNTAX;
if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
seqlen = sdp_datalen(&req, &len);
if (seqlen < 3 || len < seqlen)
return -SDP_INVALID_SYNTAX;
len -= seqlen;
while (seqlen)
if (sdp_attr_match(record, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
} else if (sdp_attr_match(record, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
if (len < 1)
return -SDP_INVALID_SYNTAX;
if (*req) {
if (len <= sizeof(int))
return -SDP_INVALID_SYNTAX;
len -= sizeof(int);
memcpy(&start, req + 1, sizeof(int));
} else
start = 0;
if (len > 1)
return -SDP_INVALID_SYNTAX;
/* Output the results */
lst = rsp + 2;
max = MIN(max, MAX_RSP_PARAM_SIZE);
len = 3 - start;
end = 0;
for (i = 0; i < record->attributes; i ++)
if (record->attribute_list[i].match) {
if (len >= 0 && len + record->attribute_list[i].len < max) {
memcpy(lst + len, record->attribute_list[i].pair,
record->attribute_list[i].len);
end = len + record->attribute_list[i].len;
}
len += record->attribute_list[i].len;
}
if (0 >= start) {
lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
lst[1] = (len + start - 3) >> 8;
lst[2] = (len + start - 3) & 0xff;
}
rsp[0] = end >> 8;
rsp[1] = end & 0xff;
if (end < len) {
len = end + start;
lst[end ++] = sizeof(int);
memcpy(lst + end, &len, sizeof(int));
end += sizeof(int);
} else
lst[end ++] = 0;
return end + 2;
}
static int sdp_svc_attr_match(struct bt_l2cap_sdp_state_s *sdp,
const uint8_t **req, ssize_t *len)
{
int i, j, start, end;
struct sdp_service_record_s *record;
if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_2)) {
(*req) ++;
if (*len < 3)
return 1;
start = (*(*req) ++) << 8;
start |= *(*req) ++;
end = start;
*len -= 3;
} else if (**req == (SDP_DTYPE_UINT | SDP_DSIZE_4)) {
(*req) ++;
if (*len < 5)
return 1;
start = (*(*req) ++) << 8;
start |= *(*req) ++;
end = (*(*req) ++) << 8;
end |= *(*req) ++;
*len -= 5;
} else
return 1;
for (i = 0; i < sdp->services; i ++)
if ((record = &sdp->service_list[i])->match)
for (j = 0; j < record->attributes; j ++)
if (record->attribute_list[j].attribute_id >= start &&
record->attribute_list[j].attribute_id <= end)
record->attribute_list[j].match = 1;
return 0;
}
static ssize_t sdp_svc_search_attr_get(struct bt_l2cap_sdp_state_s *sdp,
uint8_t *rsp, const uint8_t *req, ssize_t len)
{
ssize_t seqlen;
int i, j, start, end, max;
struct sdp_service_record_s *record;
uint8_t *lst;
/* Perform the search */
for (i = 0; i < sdp->services; i ++) {
sdp->service_list[i].match = 0;
for (j = 0; j < sdp->service_list[i].attributes; j ++)
sdp->service_list[i].attribute_list[j].match = 0;
}
if (len < 1)
return -SDP_INVALID_SYNTAX;
if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
seqlen = sdp_datalen(&req, &len);
if (seqlen < 3 || len < seqlen)
return -SDP_INVALID_SYNTAX;
len -= seqlen;
while (seqlen)
if (sdp_svc_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
} else if (sdp_svc_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
if (len < 3)
return -SDP_INVALID_SYNTAX;
max = (req[0] << 8) | req[1];
req += 2;
len -= 2;
if (max < 0x0007)
return -SDP_INVALID_SYNTAX;
if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {
seqlen = sdp_datalen(&req, &len);
if (seqlen < 3 || len < seqlen)
return -SDP_INVALID_SYNTAX;
len -= seqlen;
while (seqlen)
if (sdp_svc_attr_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
} else if (sdp_svc_attr_match(sdp, &req, &seqlen))
return -SDP_INVALID_SYNTAX;
if (len < 1)
return -SDP_INVALID_SYNTAX;
if (*req) {
if (len <= sizeof(int))
return -SDP_INVALID_SYNTAX;
len -= sizeof(int);
memcpy(&start, req + 1, sizeof(int));
} else
start = 0;
if (len > 1)
return -SDP_INVALID_SYNTAX;
/* Output the results */
/* This assumes empty attribute lists are never to be returned even
* for matching Service Records. In practice this shouldn't happen
* as the requestor will usually include the always present
* ServiceRecordHandle AttributeID in AttributeIDList. */
lst = rsp + 2;
max = MIN(max, MAX_RSP_PARAM_SIZE);
len = 3 - start;
end = 0;
for (i = 0; i < sdp->services; i ++)
if ((record = &sdp->service_list[i])->match) {
len += 3;
seqlen = len;
for (j = 0; j < record->attributes; j ++)
if (record->attribute_list[j].match) {
if (len >= 0)
if (len + record->attribute_list[j].len < max) {
memcpy(lst + len, record->attribute_list[j].pair,
record->attribute_list[j].len);
end = len + record->attribute_list[j].len;
}
len += record->attribute_list[j].len;
}
if (seqlen == len)
len -= 3;
else if (seqlen >= 3 && seqlen < max) {
lst[seqlen - 3] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
lst[seqlen - 2] = (len - seqlen) >> 8;
lst[seqlen - 1] = (len - seqlen) & 0xff;
}
}
if (len == 3 - start)
len -= 3;
else if (0 >= start) {
lst[0] = SDP_DTYPE_SEQ | SDP_DSIZE_NEXT2;
lst[1] = (len + start - 3) >> 8;
lst[2] = (len + start - 3) & 0xff;
}
rsp[0] = end >> 8;
rsp[1] = end & 0xff;
if (end < len) {
len = end + start;
lst[end ++] = sizeof(int);
memcpy(lst + end, &len, sizeof(int));
end += sizeof(int);
} else
lst[end ++] = 0;
return end + 2;
}
static void bt_l2cap_sdp_sdu_in(void *opaque, const uint8_t *data, int len)
{
struct bt_l2cap_sdp_state_s *sdp = opaque;
enum bt_sdp_cmd pdu_id;
uint8_t rsp[MAX_PDU_OUT_SIZE - PDU_HEADER_SIZE], *sdu_out;
int transaction_id, plen;
int err = 0;
int rsp_len = 0;
if (len < 5) {
fprintf(stderr, "%s: short SDP PDU (%iB).\n", __FUNCTION__, len);
return;
}
pdu_id = *data ++;
transaction_id = (data[0] << 8) | data[1];
plen = (data[2] << 8) | data[3];
data += 4;
len -= 5;
if (len != plen) {
fprintf(stderr, "%s: wrong SDP PDU length (%iB != %iB).\n",
__FUNCTION__, plen, len);
err = SDP_INVALID_PDU_SIZE;
goto respond;
}
switch (pdu_id) {
case SDP_SVC_SEARCH_REQ:
rsp_len = sdp_svc_search(sdp, rsp, data, len);
pdu_id = SDP_SVC_SEARCH_RSP;
break;
case SDP_SVC_ATTR_REQ:
rsp_len = sdp_attr_get(sdp, rsp, data, len);
pdu_id = SDP_SVC_ATTR_RSP;
break;
case SDP_SVC_SEARCH_ATTR_REQ:
rsp_len = sdp_svc_search_attr_get(sdp, rsp, data, len);
pdu_id = SDP_SVC_SEARCH_ATTR_RSP;
break;
case SDP_ERROR_RSP:
case SDP_SVC_ATTR_RSP:
case SDP_SVC_SEARCH_RSP:
case SDP_SVC_SEARCH_ATTR_RSP:
default:
fprintf(stderr, "%s: unexpected SDP PDU ID %02x.\n",
__FUNCTION__, pdu_id);
err = SDP_INVALID_SYNTAX;
break;
}
if (rsp_len < 0) {
err = -rsp_len;
rsp_len = 0;
}
respond:
if (err) {
pdu_id = SDP_ERROR_RSP;
rsp[rsp_len ++] = err >> 8;
rsp[rsp_len ++] = err & 0xff;
}
sdu_out = sdp->channel->sdu_out(sdp->channel, rsp_len + PDU_HEADER_SIZE);
sdu_out[0] = pdu_id;
sdu_out[1] = transaction_id >> 8;
sdu_out[2] = transaction_id & 0xff;
sdu_out[3] = rsp_len >> 8;
sdu_out[4] = rsp_len & 0xff;
memcpy(sdu_out + PDU_HEADER_SIZE, rsp, rsp_len);
sdp->channel->sdu_submit(sdp->channel);
}
static void bt_l2cap_sdp_close_ch(void *opaque)
{
struct bt_l2cap_sdp_state_s *sdp = opaque;
int i;
for (i = 0; i < sdp->services; i ++) {
qemu_free(sdp->service_list[i].attribute_list->pair);
qemu_free(sdp->service_list[i].attribute_list);
qemu_free(sdp->service_list[i].uuid);
}
qemu_free(sdp->service_list);
qemu_free(sdp);
}
struct sdp_def_service_s {
uint16_t class_uuid;
struct sdp_def_attribute_s {
uint16_t id;
struct sdp_def_data_element_s {
uint8_t type;
union {
uint32_t uint;
const char *str;
struct sdp_def_data_element_s *list;
} value;
} data;
} attributes[];
};
/* Calculate a safe byte count to allocate that will store the given
* element, at the same time count elements of a UUID type. */
static int sdp_attr_max_size(struct sdp_def_data_element_s *element,
int *uuids)
{
int type = element->type & ~SDP_DSIZE_MASK;
int len;
if (type == SDP_DTYPE_UINT || type == SDP_DTYPE_UUID ||
type == SDP_DTYPE_BOOL) {
if (type == SDP_DTYPE_UUID)
(*uuids) ++;
return 1 + (1 << (element->type & SDP_DSIZE_MASK));
}
if (type == SDP_DTYPE_STRING || type == SDP_DTYPE_URL) {
if (element->type & SDP_DSIZE_MASK) {
for (len = 0; element->value.str[len] |
element->value.str[len + 1]; len ++);
return len;
} else
return 2 + strlen(element->value.str);
}
if (type != SDP_DTYPE_SEQ)
exit(-1);
len = 2;
element = element->value.list;
while (element->type)
len += sdp_attr_max_size(element ++, uuids);
if (len > 255)
exit (-1);
return len;
}
static int sdp_attr_write(uint8_t *data,
struct sdp_def_data_element_s *element, int **uuid)
{
int type = element->type & ~SDP_DSIZE_MASK;
int len = 0;
if (type == SDP_DTYPE_UINT || type == SDP_DTYPE_BOOL) {
data[len ++] = element->type;
if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_1)
data[len ++] = (element->value.uint >> 0) & 0xff;
else if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_2) {
data[len ++] = (element->value.uint >> 8) & 0xff;
data[len ++] = (element->value.uint >> 0) & 0xff;
} else if ((element->type & SDP_DSIZE_MASK) == SDP_DSIZE_4) {
data[len ++] = (element->value.uint >> 24) & 0xff;
data[len ++] = (element->value.uint >> 16) & 0xff;
data[len ++] = (element->value.uint >> 8) & 0xff;
data[len ++] = (element->value.uint >> 0) & 0xff;
}
return len;
}
if (type == SDP_DTYPE_UUID) {
*(*uuid) ++ = element->value.uint;
data[len ++] = element->type;
data[len ++] = (element->value.uint >> 24) & 0xff;
data[len ++] = (element->value.uint >> 16) & 0xff;
data[len ++] = (element->value.uint >> 8) & 0xff;
data[len ++] = (element->value.uint >> 0) & 0xff;
memcpy(data + len, bt_base_uuid, 12);
return len + 12;
}
data[0] = type | SDP_DSIZE_NEXT1;
if (type == SDP_DTYPE_STRING || type == SDP_DTYPE_URL) {
if (element->type & SDP_DSIZE_MASK)
for (len = 0; element->value.str[len] |
element->value.str[len + 1]; len ++);
else
len = strlen(element->value.str);
memcpy(data + 2, element->value.str, data[1] = len);
return len + 2;
}
len = 2;
element = element->value.list;
while (element->type)
len += sdp_attr_write(data + len, element ++, uuid);
data[1] = len - 2;
return len;
}
static int sdp_attributeid_compare(const struct sdp_service_attribute_s *a,
const struct sdp_service_attribute_s *b)
{
return (int) b->attribute_id - a->attribute_id;
}
static int sdp_uuid_compare(const int *a, const int *b)
{
return *a - *b;
}
static void sdp_service_record_build(struct sdp_service_record_s *record,
struct sdp_def_service_s *def, int handle)
{
int len = 0;
uint8_t *data;
int *uuid;
record->uuids = 0;
while (def->attributes[record->attributes].data.type) {
len += 3;
len += sdp_attr_max_size(&def->attributes[record->attributes ++].data,
&record->uuids);
}
record->uuids = 1 << ffs(record->uuids - 1);
record->attribute_list =
qemu_mallocz(record->attributes * sizeof(*record->attribute_list));
record->uuid =
qemu_mallocz(record->uuids * sizeof(*record->uuid));
data = qemu_malloc(len);
record->attributes = 0;
uuid = record->uuid;
while (def->attributes[record->attributes].data.type) {
record->attribute_list[record->attributes].pair = data;
len = 0;
data[len ++] = SDP_DTYPE_UINT | SDP_DSIZE_2;
data[len ++] = def->attributes[record->attributes].id >> 8;
data[len ++] = def->attributes[record->attributes].id & 0xff;
len += sdp_attr_write(data + len,
&def->attributes[record->attributes].data, &uuid);
/* Special case: assign a ServiceRecordHandle in sequence */
if (def->attributes[record->attributes].id == SDP_ATTR_RECORD_HANDLE)
def->attributes[record->attributes].data.value.uint = handle;
/* Note: we could also assign a ServiceDescription based on
* sdp->device.device->lmp_name. */
record->attribute_list[record->attributes ++].len = len;
data += len;
}
/* Sort the attribute list by the AttributeID */
qsort(record->attribute_list, record->attributes,
sizeof(*record->attribute_list),
(void *) sdp_attributeid_compare);
/* Sort the searchable UUIDs list for bisection */
qsort(record->uuid, record->uuids,
sizeof(*record->uuid),
(void *) sdp_uuid_compare);
}
static void sdp_service_db_build(struct bt_l2cap_sdp_state_s *sdp,
struct sdp_def_service_s **service)
{
sdp->services = 0;
while (service[sdp->services])
sdp->services ++;
sdp->service_list =
qemu_mallocz(sdp->services * sizeof(*sdp->service_list));
sdp->services = 0;
while (*service) {
sdp_service_record_build(&sdp->service_list[sdp->services],
*service, sdp->services);
service ++;
sdp->services ++;
}
}
#define LAST { .type = 0 }
#define SERVICE(name, attrs) \
static struct sdp_def_service_s glue(glue(sdp_service_, name), _s) = { \
.attributes = { attrs { .data = LAST } }, \
};
#define ATTRIBUTE(attrid, val) { .id = glue(SDP_ATTR_, attrid), .data = val },
#define UINT8(val) { \
.type = SDP_DTYPE_UINT | SDP_DSIZE_1, \
.value.uint = val, \
},
#define UINT16(val) { \
.type = SDP_DTYPE_UINT | SDP_DSIZE_2, \
.value.uint = val, \
},
#define UINT32(val) { \
.type = SDP_DTYPE_UINT | SDP_DSIZE_4, \
.value.uint = val, \
},
#define UUID128(val) { \
.type = SDP_DTYPE_UUID | SDP_DSIZE_16, \
.value.uint = val, \
},
#define TRUE { \
.type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
.value.uint = 1, \
},
#define FALSE { \
.type = SDP_DTYPE_BOOL | SDP_DSIZE_1, \
.value.uint = 0, \
},
#define STRING(val) { \
.type = SDP_DTYPE_STRING, \
.value.str = val, \
},
#define ARRAY(...) { \
.type = SDP_DTYPE_STRING | SDP_DSIZE_2, \
.value.str = (char []) { __VA_ARGS__, 0, 0 }, \
},
#define URL(val) { \
.type = SDP_DTYPE_URL, \
.value.str = val, \
},
#if 1
#define LIST(val) { \
.type = SDP_DTYPE_SEQ, \
.value.list = (struct sdp_def_data_element_s []) { val LAST }, \
},
#endif
/* Try to keep each single attribute below MAX_PDU_OUT_SIZE bytes
* in resulting SDP data representation size. */
SERVICE(hid,
ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(HID_SVCLASS_ID)))
ATTRIBUTE(RECORD_STATE, UINT32(1))
ATTRIBUTE(PROTO_DESC_LIST, LIST(
LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_HID_CTRL))
LIST(UUID128(HIDP_UUID))
))
ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
))
ATTRIBUTE(PFILE_DESC_LIST, LIST(
LIST(UUID128(HID_PROFILE_ID) UINT16(0x0100))
))
ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
ATTRIBUTE(SVCNAME_PRIMARY, STRING("QEMU Bluetooth HID"))
ATTRIBUTE(SVCDESC_PRIMARY, STRING("QEMU Keyboard/Mouse"))
ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU " QEMU_VERSION))
/* Profile specific */
ATTRIBUTE(DEVICE_RELEASE_NUMBER, UINT16(0x0091)) /* Deprecated, remove */
ATTRIBUTE(PARSER_VERSION, UINT16(0x0111))
/* TODO: extract from l2cap_device->device.class[0] */
ATTRIBUTE(DEVICE_SUBCLASS, UINT8(0x40))
ATTRIBUTE(COUNTRY_CODE, UINT8(0x15))
ATTRIBUTE(VIRTUAL_CABLE, TRUE)
ATTRIBUTE(RECONNECT_INITIATE, FALSE)
/* TODO: extract from hid->usbdev->report_desc */
ATTRIBUTE(DESCRIPTOR_LIST, LIST(
LIST(UINT8(0x22) ARRAY(
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xa1, 0x01, /* Collection (Application) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0xe0, /* Usage Minimum (224) */
0x29, 0xe7, /* Usage Maximum (231) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x01, /* Input (Constant) */
0x95, 0x05, /* Report Count (5) */
0x75, 0x01, /* Report Size (1) */
0x05, 0x08, /* Usage Page (LEDs) */
0x19, 0x01, /* Usage Minimum (1) */
0x29, 0x05, /* Usage Maximum (5) */
0x91, 0x02, /* Output (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x03, /* Report Size (3) */
0x91, 0x01, /* Output (Constant) */
0x95, 0x06, /* Report Count (6) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0xff, /* Logical Maximum (255) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0x00, /* Usage Minimum (0) */
0x29, 0xff, /* Usage Maximum (255) */
0x81, 0x00, /* Input (Data, Array) */
0xc0 /* End Collection */
))))
ATTRIBUTE(LANG_ID_BASE_LIST, LIST(
LIST(UINT16(0x0409) UINT16(0x0100))
))
ATTRIBUTE(SDP_DISABLE, FALSE)
ATTRIBUTE(BATTERY_POWER, TRUE)
ATTRIBUTE(REMOTE_WAKEUP, TRUE)
ATTRIBUTE(BOOT_DEVICE, TRUE) /* XXX: untested */
ATTRIBUTE(SUPERVISION_TIMEOUT, UINT16(0x0c80))
ATTRIBUTE(NORMALLY_CONNECTABLE, TRUE)
ATTRIBUTE(PROFILE_VERSION, UINT16(0x0100))
)
SERVICE(sdp,
ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(SDP_SERVER_SVCLASS_ID)))
ATTRIBUTE(RECORD_STATE, UINT32(1))
ATTRIBUTE(PROTO_DESC_LIST, LIST(
LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_SDP))
LIST(UUID128(SDP_UUID))
))
ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
))
ATTRIBUTE(PFILE_DESC_LIST, LIST(
LIST(UUID128(SDP_SERVER_PROFILE_ID) UINT16(0x0100))
))
ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU " QEMU_VERSION))
/* Profile specific */
ATTRIBUTE(VERSION_NUM_LIST, LIST(UINT16(0x0100)))
ATTRIBUTE(SVCDB_STATE , UINT32(1))
)
SERVICE(pnp,
ATTRIBUTE(RECORD_HANDLE, UINT32(0)) /* Filled in later */
ATTRIBUTE(SVCLASS_ID_LIST, LIST(UUID128(PNP_INFO_SVCLASS_ID)))
ATTRIBUTE(RECORD_STATE, UINT32(1))
ATTRIBUTE(PROTO_DESC_LIST, LIST(
LIST(UUID128(L2CAP_UUID) UINT16(BT_PSM_SDP))
LIST(UUID128(SDP_UUID))
))
ATTRIBUTE(BROWSE_GRP_LIST, LIST(UUID128(0x1002)))
ATTRIBUTE(LANG_BASE_ATTR_ID_LIST, LIST(
UINT16(0x656e) UINT16(0x006a) UINT16(0x0100)
))
ATTRIBUTE(PFILE_DESC_LIST, LIST(
LIST(UUID128(PNP_INFO_PROFILE_ID) UINT16(0x0100))
))
ATTRIBUTE(DOC_URL, URL("http://bellard.org/qemu/user-doc.html"))
ATTRIBUTE(SVCPROV_PRIMARY, STRING("QEMU " QEMU_VERSION))
/* Profile specific */
ATTRIBUTE(SPECIFICATION_ID, UINT16(0x0100))
ATTRIBUTE(VERSION, UINT16(0x0100))
ATTRIBUTE(PRIMARY_RECORD, TRUE)
)
static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
struct bt_l2cap_conn_params_s *params)
{
struct bt_l2cap_sdp_state_s *sdp = qemu_mallocz(sizeof(*sdp));
struct sdp_def_service_s *services[] = {
&sdp_service_sdp_s,
&sdp_service_hid_s,
&sdp_service_pnp_s,
0,
};
sdp->channel = params;
sdp->channel->opaque = sdp;
sdp->channel->close = bt_l2cap_sdp_close_ch;
sdp->channel->sdu_in = bt_l2cap_sdp_sdu_in;
sdp_service_db_build(sdp, services);
return 0;
}
void bt_l2cap_sdp_init(struct bt_l2cap_device_s *dev)
{
bt_l2cap_psm_register(dev, BT_PSM_SDP,
MAX_PDU_OUT_SIZE, bt_l2cap_sdp_new_ch);
}

552
hw/bt.h
View File

@ -124,6 +124,49 @@ enum {
qemu_irq *csrhci_pins_get(CharDriverState *chr);
CharDriverState *uart_hci_init(qemu_irq wakeup);
/* bt-l2cap.c */
struct bt_l2cap_device_s;
struct bt_l2cap_conn_params_s;
struct bt_l2cap_psm_s;
void bt_l2cap_device_init(struct bt_l2cap_device_s *dev,
struct bt_scatternet_s *net);
void bt_l2cap_device_done(struct bt_l2cap_device_s *dev);
void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm,
int min_mtu, int (*new_channel)(struct bt_l2cap_device_s *dev,
struct bt_l2cap_conn_params_s *params));
struct bt_l2cap_device_s {
struct bt_device_s device;
struct bt_l2cap_psm_s *first_psm;
};
struct bt_l2cap_conn_params_s {
/* Input */
uint8_t *(*sdu_out)(struct bt_l2cap_conn_params_s *chan, int len);
void (*sdu_submit)(struct bt_l2cap_conn_params_s *chan);
int remote_mtu;
/* Output */
void *opaque;
void (*sdu_in)(void *opaque, const uint8_t *data, int len);
void (*close)(void *opaque);
};
enum bt_l2cap_psm_predef {
BT_PSM_SDP = 0x0001,
BT_PSM_RFCOMM = 0x0003,
BT_PSM_TELEPHONY = 0x0005,
BT_PSM_TCS = 0x0007,
BT_PSM_BNEP = 0x000f,
BT_PSM_HID_CTRL = 0x0011,
BT_PSM_HID_INTR = 0x0013,
BT_PSM_UPNP = 0x0015,
BT_PSM_AVCTP = 0x0017,
BT_PSM_AVDTP = 0x0019,
};
/* bt-sdp.c */
void bt_l2cap_sdp_init(struct bt_l2cap_device_s *dev);
/* Link Management Protocol layer defines */
#define LLID_ACLU_CONT 0x1
@ -1626,3 +1669,512 @@ struct hci_sco_hdr {
uint16_t handle;
uint8_t dlen;
} __attribute__ ((packed));
/* L2CAP layer defines */
enum bt_l2cap_lm_bits {
L2CAP_LM_MASTER = 1 << 0,
L2CAP_LM_AUTH = 1 << 1,
L2CAP_LM_ENCRYPT = 1 << 2,
L2CAP_LM_TRUSTED = 1 << 3,
L2CAP_LM_RELIABLE = 1 << 4,
L2CAP_LM_SECURE = 1 << 5,
};
enum bt_l2cap_cid_predef {
L2CAP_CID_INVALID = 0x0000,
L2CAP_CID_SIGNALLING= 0x0001,
L2CAP_CID_GROUP = 0x0002,
L2CAP_CID_ALLOC = 0x0040,
};
/* L2CAP command codes */
enum bt_l2cap_cmd {
L2CAP_COMMAND_REJ = 1,
L2CAP_CONN_REQ,
L2CAP_CONN_RSP,
L2CAP_CONF_REQ,
L2CAP_CONF_RSP,
L2CAP_DISCONN_REQ,
L2CAP_DISCONN_RSP,
L2CAP_ECHO_REQ,
L2CAP_ECHO_RSP,
L2CAP_INFO_REQ,
L2CAP_INFO_RSP,
};
enum bt_l2cap_sar_bits {
L2CAP_SAR_NO_SEG = 0,
L2CAP_SAR_START,
L2CAP_SAR_END,
L2CAP_SAR_CONT,
};
/* L2CAP structures */
typedef struct {
uint16_t len;
uint16_t cid;
uint8_t data[0];
} __attribute__ ((packed)) l2cap_hdr;
#define L2CAP_HDR_SIZE 4
typedef struct {
uint8_t code;
uint8_t ident;
uint16_t len;
} __attribute__ ((packed)) l2cap_cmd_hdr;
#define L2CAP_CMD_HDR_SIZE 4
typedef struct {
uint16_t reason;
} __attribute__ ((packed)) l2cap_cmd_rej;
#define L2CAP_CMD_REJ_SIZE 2
typedef struct {
uint16_t dcid;
uint16_t scid;
} __attribute__ ((packed)) l2cap_cmd_rej_cid;
#define L2CAP_CMD_REJ_CID_SIZE 4
/* reject reason */
enum bt_l2cap_rej_reason {
L2CAP_REJ_CMD_NOT_UNDERSTOOD = 0,
L2CAP_REJ_SIG_TOOBIG,
L2CAP_REJ_CID_INVAL,
};
typedef struct {
uint16_t psm;
uint16_t scid;
} __attribute__ ((packed)) l2cap_conn_req;
#define L2CAP_CONN_REQ_SIZE 4
typedef struct {
uint16_t dcid;
uint16_t scid;
uint16_t result;
uint16_t status;
} __attribute__ ((packed)) l2cap_conn_rsp;
#define L2CAP_CONN_RSP_SIZE 8
/* connect result */
enum bt_l2cap_conn_res {
L2CAP_CR_SUCCESS = 0,
L2CAP_CR_PEND,
L2CAP_CR_BAD_PSM,
L2CAP_CR_SEC_BLOCK,
L2CAP_CR_NO_MEM,
};
/* connect status */
enum bt_l2cap_conn_stat {
L2CAP_CS_NO_INFO = 0,
L2CAP_CS_AUTHEN_PEND,
L2CAP_CS_AUTHOR_PEND,
};
typedef struct {
uint16_t dcid;
uint16_t flags;
uint8_t data[0];
} __attribute__ ((packed)) l2cap_conf_req;
#define L2CAP_CONF_REQ_SIZE(datalen) (4 + (datalen))
typedef struct {
uint16_t scid;
uint16_t flags;
uint16_t result;
uint8_t data[0];
} __attribute__ ((packed)) l2cap_conf_rsp;
#define L2CAP_CONF_RSP_SIZE(datalen) (6 + datalen)
enum bt_l2cap_conf_res {
L2CAP_CONF_SUCCESS = 0,
L2CAP_CONF_UNACCEPT,
L2CAP_CONF_REJECT,
L2CAP_CONF_UNKNOWN,
};
typedef struct {
uint8_t type;
uint8_t len;
uint8_t val[0];
} __attribute__ ((packed)) l2cap_conf_opt;
#define L2CAP_CONF_OPT_SIZE 2
enum bt_l2cap_conf_val {
L2CAP_CONF_MTU = 1,
L2CAP_CONF_FLUSH_TO,
L2CAP_CONF_QOS,
L2CAP_CONF_RFC,
L2CAP_CONF_RFC_MODE = L2CAP_CONF_RFC,
};
typedef struct {
uint8_t flags;
uint8_t service_type;
uint32_t token_rate;
uint32_t token_bucket_size;
uint32_t peak_bandwidth;
uint32_t latency;
uint32_t delay_variation;
} __attribute__ ((packed)) l2cap_conf_opt_qos;
#define L2CAP_CONF_OPT_QOS_SIZE 22
enum bt_l2cap_conf_opt_qos_st {
L2CAP_CONF_QOS_NO_TRAFFIC = 0x00,
L2CAP_CONF_QOS_BEST_EFFORT,
L2CAP_CONF_QOS_GUARANTEED,
};
#define L2CAP_CONF_QOS_WILDCARD 0xffffffff
enum bt_l2cap_mode {
L2CAP_MODE_BASIC = 0,
L2CAP_MODE_RETRANS = 1,
L2CAP_MODE_FLOWCTL = 2,
};
typedef struct {
uint16_t dcid;
uint16_t scid;
} __attribute__ ((packed)) l2cap_disconn_req;
#define L2CAP_DISCONN_REQ_SIZE 4
typedef struct {
uint16_t dcid;
uint16_t scid;
} __attribute__ ((packed)) l2cap_disconn_rsp;
#define L2CAP_DISCONN_RSP_SIZE 4
typedef struct {
uint16_t type;
} __attribute__ ((packed)) l2cap_info_req;
#define L2CAP_INFO_REQ_SIZE 2
typedef struct {
uint16_t type;
uint16_t result;
uint8_t data[0];
} __attribute__ ((packed)) l2cap_info_rsp;
#define L2CAP_INFO_RSP_SIZE 4
/* info type */
enum bt_l2cap_info_type {
L2CAP_IT_CL_MTU = 1,
L2CAP_IT_FEAT_MASK,
};
/* info result */
enum bt_l2cap_info_result {
L2CAP_IR_SUCCESS = 0,
L2CAP_IR_NOTSUPP,
};
/* Service Discovery Protocol defines */
/* Note that all multibyte values in lower layer protocols (above in this file)
* are little-endian while SDP is big-endian. */
/* Protocol UUIDs */
enum sdp_proto_uuid {
SDP_UUID = 0x0001,
UDP_UUID = 0x0002,
RFCOMM_UUID = 0x0003,
TCP_UUID = 0x0004,
TCS_BIN_UUID = 0x0005,
TCS_AT_UUID = 0x0006,
OBEX_UUID = 0x0008,
IP_UUID = 0x0009,
FTP_UUID = 0x000a,
HTTP_UUID = 0x000c,
WSP_UUID = 0x000e,
BNEP_UUID = 0x000f,
UPNP_UUID = 0x0010,
HIDP_UUID = 0x0011,
HCRP_CTRL_UUID = 0x0012,
HCRP_DATA_UUID = 0x0014,
HCRP_NOTE_UUID = 0x0016,
AVCTP_UUID = 0x0017,
AVDTP_UUID = 0x0019,
CMTP_UUID = 0x001b,
UDI_UUID = 0x001d,
MCAP_CTRL_UUID = 0x001e,
MCAP_DATA_UUID = 0x001f,
L2CAP_UUID = 0x0100,
};
/*
* Service class identifiers of standard services and service groups
*/
enum service_class_id {
SDP_SERVER_SVCLASS_ID = 0x1000,
BROWSE_GRP_DESC_SVCLASS_ID = 0x1001,
PUBLIC_BROWSE_GROUP = 0x1002,
SERIAL_PORT_SVCLASS_ID = 0x1101,
LAN_ACCESS_SVCLASS_ID = 0x1102,
DIALUP_NET_SVCLASS_ID = 0x1103,
IRMC_SYNC_SVCLASS_ID = 0x1104,
OBEX_OBJPUSH_SVCLASS_ID = 0x1105,
OBEX_FILETRANS_SVCLASS_ID = 0x1106,
IRMC_SYNC_CMD_SVCLASS_ID = 0x1107,
HEADSET_SVCLASS_ID = 0x1108,
CORDLESS_TELEPHONY_SVCLASS_ID = 0x1109,
AUDIO_SOURCE_SVCLASS_ID = 0x110a,
AUDIO_SINK_SVCLASS_ID = 0x110b,
AV_REMOTE_TARGET_SVCLASS_ID = 0x110c,
ADVANCED_AUDIO_SVCLASS_ID = 0x110d,
AV_REMOTE_SVCLASS_ID = 0x110e,
VIDEO_CONF_SVCLASS_ID = 0x110f,
INTERCOM_SVCLASS_ID = 0x1110,
FAX_SVCLASS_ID = 0x1111,
HEADSET_AGW_SVCLASS_ID = 0x1112,
WAP_SVCLASS_ID = 0x1113,
WAP_CLIENT_SVCLASS_ID = 0x1114,
PANU_SVCLASS_ID = 0x1115,
NAP_SVCLASS_ID = 0x1116,
GN_SVCLASS_ID = 0x1117,
DIRECT_PRINTING_SVCLASS_ID = 0x1118,
REFERENCE_PRINTING_SVCLASS_ID = 0x1119,
IMAGING_SVCLASS_ID = 0x111a,
IMAGING_RESPONDER_SVCLASS_ID = 0x111b,
IMAGING_ARCHIVE_SVCLASS_ID = 0x111c,
IMAGING_REFOBJS_SVCLASS_ID = 0x111d,
HANDSFREE_SVCLASS_ID = 0x111e,
HANDSFREE_AGW_SVCLASS_ID = 0x111f,
DIRECT_PRT_REFOBJS_SVCLASS_ID = 0x1120,
REFLECTED_UI_SVCLASS_ID = 0x1121,
BASIC_PRINTING_SVCLASS_ID = 0x1122,
PRINTING_STATUS_SVCLASS_ID = 0x1123,
HID_SVCLASS_ID = 0x1124,
HCR_SVCLASS_ID = 0x1125,
HCR_PRINT_SVCLASS_ID = 0x1126,
HCR_SCAN_SVCLASS_ID = 0x1127,
CIP_SVCLASS_ID = 0x1128,
VIDEO_CONF_GW_SVCLASS_ID = 0x1129,
UDI_MT_SVCLASS_ID = 0x112a,
UDI_TA_SVCLASS_ID = 0x112b,
AV_SVCLASS_ID = 0x112c,
SAP_SVCLASS_ID = 0x112d,
PBAP_PCE_SVCLASS_ID = 0x112e,
PBAP_PSE_SVCLASS_ID = 0x112f,
PBAP_SVCLASS_ID = 0x1130,
PNP_INFO_SVCLASS_ID = 0x1200,
GENERIC_NETWORKING_SVCLASS_ID = 0x1201,
GENERIC_FILETRANS_SVCLASS_ID = 0x1202,
GENERIC_AUDIO_SVCLASS_ID = 0x1203,
GENERIC_TELEPHONY_SVCLASS_ID = 0x1204,
UPNP_SVCLASS_ID = 0x1205,
UPNP_IP_SVCLASS_ID = 0x1206,
UPNP_PAN_SVCLASS_ID = 0x1300,
UPNP_LAP_SVCLASS_ID = 0x1301,
UPNP_L2CAP_SVCLASS_ID = 0x1302,
VIDEO_SOURCE_SVCLASS_ID = 0x1303,
VIDEO_SINK_SVCLASS_ID = 0x1304,
VIDEO_DISTRIBUTION_SVCLASS_ID = 0x1305,
MDP_SVCLASS_ID = 0x1400,
MDP_SOURCE_SVCLASS_ID = 0x1401,
MDP_SINK_SVCLASS_ID = 0x1402,
APPLE_AGENT_SVCLASS_ID = 0x2112,
};
/*
* Standard profile descriptor identifiers; note these
* may be identical to some of the service classes defined above
*/
#define SDP_SERVER_PROFILE_ID SDP_SERVER_SVCLASS_ID
#define BROWSE_GRP_DESC_PROFILE_ID BROWSE_GRP_DESC_SVCLASS_ID
#define SERIAL_PORT_PROFILE_ID SERIAL_PORT_SVCLASS_ID
#define LAN_ACCESS_PROFILE_ID LAN_ACCESS_SVCLASS_ID
#define DIALUP_NET_PROFILE_ID DIALUP_NET_SVCLASS_ID
#define IRMC_SYNC_PROFILE_ID IRMC_SYNC_SVCLASS_ID
#define OBEX_OBJPUSH_PROFILE_ID OBEX_OBJPUSH_SVCLASS_ID
#define OBEX_FILETRANS_PROFILE_ID OBEX_FILETRANS_SVCLASS_ID
#define IRMC_SYNC_CMD_PROFILE_ID IRMC_SYNC_CMD_SVCLASS_ID
#define HEADSET_PROFILE_ID HEADSET_SVCLASS_ID
#define CORDLESS_TELEPHONY_PROFILE_ID CORDLESS_TELEPHONY_SVCLASS_ID
#define AUDIO_SOURCE_PROFILE_ID AUDIO_SOURCE_SVCLASS_ID
#define AUDIO_SINK_PROFILE_ID AUDIO_SINK_SVCLASS_ID
#define AV_REMOTE_TARGET_PROFILE_ID AV_REMOTE_TARGET_SVCLASS_ID
#define ADVANCED_AUDIO_PROFILE_ID ADVANCED_AUDIO_SVCLASS_ID
#define AV_REMOTE_PROFILE_ID AV_REMOTE_SVCLASS_ID
#define VIDEO_CONF_PROFILE_ID VIDEO_CONF_SVCLASS_ID
#define INTERCOM_PROFILE_ID INTERCOM_SVCLASS_ID
#define FAX_PROFILE_ID FAX_SVCLASS_ID
#define HEADSET_AGW_PROFILE_ID HEADSET_AGW_SVCLASS_ID
#define WAP_PROFILE_ID WAP_SVCLASS_ID
#define WAP_CLIENT_PROFILE_ID WAP_CLIENT_SVCLASS_ID
#define PANU_PROFILE_ID PANU_SVCLASS_ID
#define NAP_PROFILE_ID NAP_SVCLASS_ID
#define GN_PROFILE_ID GN_SVCLASS_ID
#define DIRECT_PRINTING_PROFILE_ID DIRECT_PRINTING_SVCLASS_ID
#define REFERENCE_PRINTING_PROFILE_ID REFERENCE_PRINTING_SVCLASS_ID
#define IMAGING_PROFILE_ID IMAGING_SVCLASS_ID
#define IMAGING_RESPONDER_PROFILE_ID IMAGING_RESPONDER_SVCLASS_ID
#define IMAGING_ARCHIVE_PROFILE_ID IMAGING_ARCHIVE_SVCLASS_ID
#define IMAGING_REFOBJS_PROFILE_ID IMAGING_REFOBJS_SVCLASS_ID
#define HANDSFREE_PROFILE_ID HANDSFREE_SVCLASS_ID
#define HANDSFREE_AGW_PROFILE_ID HANDSFREE_AGW_SVCLASS_ID
#define DIRECT_PRT_REFOBJS_PROFILE_ID DIRECT_PRT_REFOBJS_SVCLASS_ID
#define REFLECTED_UI_PROFILE_ID REFLECTED_UI_SVCLASS_ID
#define BASIC_PRINTING_PROFILE_ID BASIC_PRINTING_SVCLASS_ID
#define PRINTING_STATUS_PROFILE_ID PRINTING_STATUS_SVCLASS_ID
#define HID_PROFILE_ID HID_SVCLASS_ID
#define HCR_PROFILE_ID HCR_SCAN_SVCLASS_ID
#define HCR_PRINT_PROFILE_ID HCR_PRINT_SVCLASS_ID
#define HCR_SCAN_PROFILE_ID HCR_SCAN_SVCLASS_ID
#define CIP_PROFILE_ID CIP_SVCLASS_ID
#define VIDEO_CONF_GW_PROFILE_ID VIDEO_CONF_GW_SVCLASS_ID
#define UDI_MT_PROFILE_ID UDI_MT_SVCLASS_ID
#define UDI_TA_PROFILE_ID UDI_TA_SVCLASS_ID
#define AV_PROFILE_ID AV_SVCLASS_ID
#define SAP_PROFILE_ID SAP_SVCLASS_ID
#define PBAP_PCE_PROFILE_ID PBAP_PCE_SVCLASS_ID
#define PBAP_PSE_PROFILE_ID PBAP_PSE_SVCLASS_ID
#define PBAP_PROFILE_ID PBAP_SVCLASS_ID
#define PNP_INFO_PROFILE_ID PNP_INFO_SVCLASS_ID
#define GENERIC_NETWORKING_PROFILE_ID GENERIC_NETWORKING_SVCLASS_ID
#define GENERIC_FILETRANS_PROFILE_ID GENERIC_FILETRANS_SVCLASS_ID
#define GENERIC_AUDIO_PROFILE_ID GENERIC_AUDIO_SVCLASS_ID
#define GENERIC_TELEPHONY_PROFILE_ID GENERIC_TELEPHONY_SVCLASS_ID
#define UPNP_PROFILE_ID UPNP_SVCLASS_ID
#define UPNP_IP_PROFILE_ID UPNP_IP_SVCLASS_ID
#define UPNP_PAN_PROFILE_ID UPNP_PAN_SVCLASS_ID
#define UPNP_LAP_PROFILE_ID UPNP_LAP_SVCLASS_ID
#define UPNP_L2CAP_PROFILE_ID UPNP_L2CAP_SVCLASS_ID
#define VIDEO_SOURCE_PROFILE_ID VIDEO_SOURCE_SVCLASS_ID
#define VIDEO_SINK_PROFILE_ID VIDEO_SINK_SVCLASS_ID
#define VIDEO_DISTRIBUTION_PROFILE_ID VIDEO_DISTRIBUTION_SVCLASS_ID
#define MDP_PROFILE_ID MDP_SVCLASS_ID
#define MDP_SOURCE_PROFILE_ID MDP_SROUCE_SVCLASS_ID
#define MDP_SINK_PROFILE_ID MDP_SINK_SVCLASS_ID
#define APPLE_AGENT_PROFILE_ID APPLE_AGENT_SVCLASS_ID
/* Data Representation */
enum bt_sdp_data_type {
SDP_DTYPE_NIL = 0 << 3,
SDP_DTYPE_UINT = 1 << 3,
SDP_DTYPE_SINT = 2 << 3,
SDP_DTYPE_UUID = 3 << 3,
SDP_DTYPE_STRING = 4 << 3,
SDP_DTYPE_BOOL = 5 << 3,
SDP_DTYPE_SEQ = 6 << 3,
SDP_DTYPE_ALT = 7 << 3,
SDP_DTYPE_URL = 8 << 3,
};
enum bt_sdp_data_size {
SDP_DSIZE_1 = 0,
SDP_DSIZE_2,
SDP_DSIZE_4,
SDP_DSIZE_8,
SDP_DSIZE_16,
SDP_DSIZE_NEXT1,
SDP_DSIZE_NEXT2,
SDP_DSIZE_NEXT4,
SDP_DSIZE_MASK = SDP_DSIZE_NEXT4,
};
enum bt_sdp_cmd {
SDP_ERROR_RSP = 0x01,
SDP_SVC_SEARCH_REQ = 0x02,
SDP_SVC_SEARCH_RSP = 0x03,
SDP_SVC_ATTR_REQ = 0x04,
SDP_SVC_ATTR_RSP = 0x05,
SDP_SVC_SEARCH_ATTR_REQ = 0x06,
SDP_SVC_SEARCH_ATTR_RSP = 0x07,
};
enum bt_sdp_errorcode {
SDP_INVALID_VERSION = 0x0001,
SDP_INVALID_RECORD_HANDLE = 0x0002,
SDP_INVALID_SYNTAX = 0x0003,
SDP_INVALID_PDU_SIZE = 0x0004,
SDP_INVALID_CSTATE = 0x0005,
};
/*
* String identifiers are based on the SDP spec stating that
* "base attribute id of the primary (universal) language must be 0x0100"
*
* Other languages should have their own offset; e.g.:
* #define XXXLangBase yyyy
* #define AttrServiceName_XXX 0x0000+XXXLangBase
*/
#define SDP_PRIMARY_LANG_BASE 0x0100
enum bt_sdp_attribute_id {
SDP_ATTR_RECORD_HANDLE = 0x0000,
SDP_ATTR_SVCLASS_ID_LIST = 0x0001,
SDP_ATTR_RECORD_STATE = 0x0002,
SDP_ATTR_SERVICE_ID = 0x0003,
SDP_ATTR_PROTO_DESC_LIST = 0x0004,
SDP_ATTR_BROWSE_GRP_LIST = 0x0005,
SDP_ATTR_LANG_BASE_ATTR_ID_LIST = 0x0006,
SDP_ATTR_SVCINFO_TTL = 0x0007,
SDP_ATTR_SERVICE_AVAILABILITY = 0x0008,
SDP_ATTR_PFILE_DESC_LIST = 0x0009,
SDP_ATTR_DOC_URL = 0x000a,
SDP_ATTR_CLNT_EXEC_URL = 0x000b,
SDP_ATTR_ICON_URL = 0x000c,
SDP_ATTR_ADD_PROTO_DESC_LIST = 0x000d,
SDP_ATTR_SVCNAME_PRIMARY = SDP_PRIMARY_LANG_BASE + 0,
SDP_ATTR_SVCDESC_PRIMARY = SDP_PRIMARY_LANG_BASE + 1,
SDP_ATTR_SVCPROV_PRIMARY = SDP_PRIMARY_LANG_BASE + 2,
SDP_ATTR_GROUP_ID = 0x0200,
SDP_ATTR_IP_SUBNET = 0x0200,
/* SDP */
SDP_ATTR_VERSION_NUM_LIST = 0x0200,
SDP_ATTR_SVCDB_STATE = 0x0201,
SDP_ATTR_SERVICE_VERSION = 0x0300,
SDP_ATTR_EXTERNAL_NETWORK = 0x0301,
SDP_ATTR_SUPPORTED_DATA_STORES_LIST = 0x0301,
SDP_ATTR_FAX_CLASS1_SUPPORT = 0x0302,
SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL = 0x0302,
SDP_ATTR_FAX_CLASS20_SUPPORT = 0x0303,
SDP_ATTR_SUPPORTED_FORMATS_LIST = 0x0303,
SDP_ATTR_FAX_CLASS2_SUPPORT = 0x0304,
SDP_ATTR_AUDIO_FEEDBACK_SUPPORT = 0x0305,
SDP_ATTR_NETWORK_ADDRESS = 0x0306,
SDP_ATTR_WAP_GATEWAY = 0x0307,
SDP_ATTR_HOMEPAGE_URL = 0x0308,
SDP_ATTR_WAP_STACK_TYPE = 0x0309,
SDP_ATTR_SECURITY_DESC = 0x030a,
SDP_ATTR_NET_ACCESS_TYPE = 0x030b,
SDP_ATTR_MAX_NET_ACCESSRATE = 0x030c,
SDP_ATTR_IP4_SUBNET = 0x030d,
SDP_ATTR_IP6_SUBNET = 0x030e,
SDP_ATTR_SUPPORTED_CAPABILITIES = 0x0310,
SDP_ATTR_SUPPORTED_FEATURES = 0x0311,
SDP_ATTR_SUPPORTED_FUNCTIONS = 0x0312,
SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY = 0x0313,
SDP_ATTR_SUPPORTED_REPOSITORIES = 0x0314,
/* PnP Information */
SDP_ATTR_SPECIFICATION_ID = 0x0200,
SDP_ATTR_VENDOR_ID = 0x0201,
SDP_ATTR_PRODUCT_ID = 0x0202,
SDP_ATTR_VERSION = 0x0203,
SDP_ATTR_PRIMARY_RECORD = 0x0204,
SDP_ATTR_VENDOR_ID_SOURCE = 0x0205,
/* BT HID */
SDP_ATTR_DEVICE_RELEASE_NUMBER = 0x0200,
SDP_ATTR_PARSER_VERSION = 0x0201,
SDP_ATTR_DEVICE_SUBCLASS = 0x0202,
SDP_ATTR_COUNTRY_CODE = 0x0203,
SDP_ATTR_VIRTUAL_CABLE = 0x0204,
SDP_ATTR_RECONNECT_INITIATE = 0x0205,
SDP_ATTR_DESCRIPTOR_LIST = 0x0206,
SDP_ATTR_LANG_ID_BASE_LIST = 0x0207,
SDP_ATTR_SDP_DISABLE = 0x0208,
SDP_ATTR_BATTERY_POWER = 0x0209,
SDP_ATTR_REMOTE_WAKEUP = 0x020a,
SDP_ATTR_PROFILE_VERSION = 0x020b,
SDP_ATTR_SUPERVISION_TIMEOUT = 0x020c,
SDP_ATTR_NORMALLY_CONNECTABLE = 0x020d,
SDP_ATTR_BOOT_DEVICE = 0x020e,
};