* [RFC 13/15] sdpd-request: Fix build errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix number of build errors on ARM similar to one below.
CC src/bluetooth-sdpd-request.o
src/sdpd-request.c: In function extra_des:
src/sdpd-request.c:181:5: error: cast increases required alignment
of targettype [-Werror=cast-align]
Change-Id: I7323634e7d51d56936b5253660a5f6eb02ac0645
---
src/sdpd-request.c | 62 ++++++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 6a903c6..6f24a89 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -139,6 +139,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
for (;;) {
char *pElem = NULL;
int localSeqLength = 0;
+ uuid_t *puuid;
if (bufsize < sizeof(uint8_t)) {
SDPDBG("->Unexpected end of buffer");
@@ -178,11 +179,11 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- bt_put_unaligned(ntohs(bt_get_unaligned((uint16_t *)p)), (uint16_t *)&aid->uint16);
+ aid->uint16 = bt_get_be16(p);
pElem = (char *) aid;
} else {
pElem = malloc(sizeof(uint16_t));
- bt_put_unaligned(ntohs(bt_get_unaligned((uint16_t *)p)), (uint16_t *)pElem);
+ bt_put_be16(bt_get_16(p), pElem);
}
p += sizeof(uint16_t);
seqlen += sizeof(uint16_t);
@@ -201,11 +202,12 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- bt_put_unaligned(ntohl(bt_get_unaligned((uint32_t *)p)), (uint32_t *)&aid->uint32);
+ aid->uint32 = bt_get_be32(p);
+
pElem = (char *) aid;
} else {
pElem = malloc(sizeof(uint32_t));
- bt_put_unaligned(ntohl(bt_get_unaligned((uint32_t *)p)), (uint32_t *)pElem);
+ bt_put_be32(bt_get_32(p), pElem);
}
p += sizeof(uint32_t);
seqlen += sizeof(uint32_t);
@@ -214,12 +216,14 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
case SDP_UUID16:
case SDP_UUID32:
case SDP_UUID128:
- pElem = malloc(sizeof(uuid_t));
- status = sdp_uuid_extract(p, bufsize, (uuid_t *) pElem, &localSeqLength);
+ puuid = malloc(sizeof(uuid_t));
+ status = sdp_uuid_extract(p, bufsize, puuid, &localSeqLength);
if (status < 0) {
- free(pElem);
+ free(puuid);
goto failed;
}
+
+ pElem = (char *) puuid;
seqlen += localSeqLength;
p += localSeqLength;
bufsize -= localSeqLength;
@@ -359,7 +363,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
uint8_t *pCacheBuffer = NULL;
int handleSize = 0;
uint32_t cStateId = 0;
- short *pTotalRecordCount, *pCurrentRecordCount;
+ uint8_t *pTotalRecordCount, *pCurrentRecordCount;
uint8_t *pdata = req->buf + sizeof(sdp_pdu_hdr_t);
size_t data_left = req->len - sizeof(sdp_pdu_hdr_t);
@@ -385,7 +389,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}
- expected = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ expected = bt_get_be16(pdata);
SDPDBG("Expected count: %d", expected);
SDPDBG("Bytes scanned : %d", scanned);
@@ -409,14 +413,14 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
pdata = buf->data;
/* total service record count = 0 */
- pTotalRecordCount = (short *)pdata;
- bt_put_unaligned(0, (uint16_t *)pdata);
+ pTotalRecordCount = pdata;
+ bt_put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);
/* current service record count = 0 */
- pCurrentRecordCount = (short *)pdata;
- bt_put_unaligned(0, (uint16_t *)pdata);
+ pCurrentRecordCount = pdata;
+ bt_put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);
@@ -433,7 +437,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (sdp_match_uuid(pattern, rec->pattern) > 0 &&
sdp_check_access(rec->handle, &req->device)) {
rsp_count++;
- bt_put_unaligned(htonl(rec->handle), (uint32_t *)pdata);
+ bt_put_be32(rec->handle, pdata);
pdata += sizeof(uint32_t);
handleSize += sizeof(uint32_t);
}
@@ -442,8 +446,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
SDPDBG("Match count: %d", rsp_count);
buf->data_size += handleSize;
- bt_put_unaligned(htons(rsp_count), (uint16_t *)pTotalRecordCount);
- bt_put_unaligned(htons(rsp_count), (uint16_t *)pCurrentRecordCount);
+ bt_put_be16(rsp_count, pTotalRecordCount);
+ bt_put_be16(rsp_count, pCurrentRecordCount);
if (rsp_count > actual) {
/* cache the rsp and generate a continuation state */
@@ -472,7 +476,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (pCache) {
pCacheBuffer = pCache->data;
/* get the rsp_count from the cached buffer */
- rsp_count = ntohs(bt_get_unaligned((uint16_t *)pCacheBuffer));
+ rsp_count = bt_get_be16(pCacheBuffer);
/* get index of the last sdp_record_t sent */
lastIndex = cstate->cStateValue.lastIndexSent;
@@ -490,7 +494,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
* current record count and increment the cached
* buffer pointer to beyond the counters
*/
- pdata = (uint8_t *) pCurrentRecordCount + sizeof(uint16_t);
+ pdata = pCurrentRecordCount + sizeof(uint16_t);
/* increment beyond the totalCount and the currentCount */
pCacheBuffer += 2 * sizeof(uint16_t);
@@ -498,7 +502,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (cstate) {
handleSize = 0;
for (i = lastIndex; (i - lastIndex) < actual && i < rsp_count; i++) {
- bt_put_unaligned(bt_get_unaligned((uint32_t *)(pCacheBuffer + i * sizeof(uint32_t))), (uint32_t *)pdata);
+ memcpy(pdata, pCacheBuffer + i * sizeof(uint32_t), sizeof(uint32_t));
pdata += sizeof(uint32_t);
handleSize += sizeof(uint32_t);
}
@@ -508,8 +512,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
}
buf->data_size += handleSize;
- bt_put_unaligned(htons(rsp_count), (uint16_t *)pTotalRecordCount);
- bt_put_unaligned(htons(i - lastIndex), (uint16_t *)pCurrentRecordCount);
+ bt_put_be16(rsp_count, pTotalRecordCount);
+ bt_put_be16(i - lastIndex, pCurrentRecordCount);
if (i == rsp_count) {
/* set "null" continuationState */
@@ -571,12 +575,12 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, sdp_buf_t *buf)
SDPDBG("AttrDataType : %d", aid->dtd);
if (aid->dtd == SDP_UINT16) {
- uint16_t attr = bt_get_unaligned((uint16_t *)&aid->uint16);
+ uint16_t attr = aid->uint16;
sdp_data_t *a = sdp_data_get(rec, attr);
if (a)
sdp_append_to_pdu(buf, a);
} else if (aid->dtd == SDP_UINT32) {
- uint32_t range = bt_get_unaligned((uint32_t *)&aid->uint32);
+ uint32_t range = aid->uint32;
uint16_t attr;
uint16_t low = (0xffff0000 & range) >> 16;
uint16_t high = 0x0000ffff & range;
@@ -639,7 +643,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}
- handle = ntohl(bt_get_unaligned((uint32_t *)pdata));
+ handle = bt_get_be32(pdata);
pdata += sizeof(uint32_t);
data_left -= sizeof(uint32_t);
@@ -649,7 +653,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}
- max_rsp_size = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ max_rsp_size = bt_get_be16(pdata);
pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
@@ -765,7 +769,7 @@ done:
return status;
/* set attribute list byte count */
- bt_put_unaligned(htons(buf->data_size - cstate_size), (uint16_t *)buf->data);
+ bt_put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
return 0;
}
@@ -806,7 +810,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}
- max = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ max = bt_get_be16(pdata);
pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
@@ -936,7 +940,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
if (!status) {
/* set attribute list byte count */
- bt_put_unaligned(htons(buf->data_size - cstate_size), (uint16_t *)buf->data);
+ bt_put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
}
@@ -1020,7 +1024,7 @@ static void process_request(sdp_req_t *req)
send_rsp:
if (status) {
rsphdr->pdu_id = SDP_ERROR_RSP;
- bt_put_unaligned(htons(status), (uint16_t *)rsp.data);
+ bt_put_be16(status, rsp.data);
rsp.data_size = sizeof(uint16_t);
}
--
1.7.9.5
^ permalink raw reply related
* [RFC 12/15] adaptername: Refactor handle_inotify_cb
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
Refactor handle_inotify_cb to avoid unaligned memory access.
Instead of reading whole events buffer and cast to event struct when
iterating over it, read data directly to struct inotify_event one
event at time.
This fix following build error on ARM.
CC plugins/bluetoothd-adaptername.o
plugins/adaptername.c: In function handle_inotify_cb:
plugins/adaptername.c:244:34: error: cast increases required alignment
of target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [plugins/bluetoothd-adaptername.o] Error 1
make: *** [all] Error 2
Change-Id: Ibcf2daa06fcb79853c71c00502b5ebe13773e6ff
---
plugins/adaptername.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index d3341b5..f5010ea 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -226,35 +226,41 @@ static int adaptername_probe(struct btd_adapter *adapter)
static gboolean handle_inotify_cb(GIOChannel *channel, GIOCondition cond,
gpointer data)
{
- char buf[EVENT_BUF_LEN];
+ struct inotify_event event;
+ gsize len;
GIOStatus err;
- gsize len, i;
- gboolean changed;
+ char name[FILENAME_MAX + 1];
- changed = FALSE;
+ while ((err = g_io_channel_read_chars(channel, (gchar *)&event,
+ sizeof(event), &len, NULL)) != G_IO_STATUS_AGAIN) {
+ if (err != G_IO_STATUS_NORMAL) {
+ error("Error reading inotify event: %d", err);
+ return FALSE;
+ }
- err = g_io_channel_read_chars(channel, buf, EVENT_BUF_LEN, &len, NULL);
- if (err != G_IO_STATUS_NORMAL) {
- error("Error reading inotify event: %d\n", err);
- return FALSE;
- }
+ if (len != sizeof(event)) {
+ error("Not enough bytes of inotify event read");
+ return FALSE;
+ }
- i = 0;
- while (i < len) {
- struct inotify_event *pevent = (struct inotify_event *) &buf[i];
+ if (event.len == 0)
+ continue;
- /* check that it's ours */
- if (pevent->len && pevent->name != NULL &&
- strcmp(pevent->name, MACHINE_INFO_FILE) == 0)
- changed = TRUE;
+ err = g_io_channel_read_chars(channel, name, event.len, &len,
+ NULL);
+ if (err != G_IO_STATUS_NORMAL) {
+ error("Error reading inotify event: %d", err);
+ return FALSE;
+ }
- i += EVENT_SIZE + pevent->len;
- }
+ if (strcmp(name, MACHINE_INFO_FILE) != 0)
+ continue;
- if (changed != FALSE) {
DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
" changed, changing names for adapters");
+
manager_foreach_adapter((adapter_cb) adaptername_probe, NULL);
+ break;
}
return TRUE;
--
1.7.9.5
^ permalink raw reply related
* [RFC 11/15] sap: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following build errors on ARM.
CC profiles/sap/bluetoothd-server.o
profiles/sap/server.c: In function connect_req:
profiles/sap/server.c:317:8: error: cast increases required alignment
of targettype [-Werror=cast-align]
profiles/sap/server.c: In function sap_connect_rsp:
profiles/sap/server.c:676:16: error: cast increases required alignment
of target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [profiles/sap/bluetoothd-server.o] Error 1
make: *** [all] Error 2
Change-Id: I7015a0e99df7b49e734f3bcac0f2298129722359
---
profiles/sap/server.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 3adbb1a..78a63bf 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -302,7 +302,7 @@ static void connect_req(struct sap_server *server,
struct sap_parameter *param)
{
struct sap_connection *conn = server->conn;
- uint16_t maxmsgsize, *val;
+ uint16_t maxmsgsize;
DBG("conn %p state %d", conn, conn->state);
@@ -314,8 +314,7 @@ static void connect_req(struct sap_server *server,
stop_guard_timer(server);
- val = (uint16_t *) ¶m->val;
- maxmsgsize = ntohs(*val);
+ maxmsgsize = bt_get_be16(¶m->val);
DBG("Connect MaxMsgSize: 0x%04x", maxmsgsize);
@@ -638,7 +637,6 @@ int sap_connect_rsp(void *sap_device, uint8_t status)
struct sap_message *msg = (struct sap_message *) buf;
struct sap_parameter *param = (struct sap_parameter *) msg->param;
size_t size = sizeof(struct sap_message);
- uint16_t *maxmsgsize;
if (!conn)
return -EINVAL;
@@ -673,8 +671,7 @@ int sap_connect_rsp(void *sap_device, uint8_t status)
param = (struct sap_parameter *) &buf[size];
param->id = SAP_PARAM_ID_MAX_MSG_SIZE;
param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
- maxmsgsize = (uint16_t *) ¶m->val;
- *maxmsgsize = htons(SAP_BUF_SIZE);
+ bt_put_be16(SAP_BUF_SIZE, ¶m->val);
size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
/* fall */
--
1.7.9.5
^ permalink raw reply related
* [RFC 10/15] avrcp: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following build errors on ARM.
CC audio/bluetoothd-avrcp.o
audio/avrcp.c: In function avrcp_handle_get_element_attributes:
audio/avrcp.c:667:25: error: cast increases required alignment of
target type [-Werror=cast-align]
audio/avrcp.c:690:20: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [audio/bluetoothd-avrcp.o] Error 1
make: *** [all] Error 2
Change-Id: I0c4b15063672b602170809ee1aecc6b9305c3a67
---
audio/avrcp.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index d925365..9c474f3 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -664,13 +664,13 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
uint8_t transaction)
{
uint16_t len = ntohs(pdu->params_len);
- uint64_t *identifier = (uint64_t *) &pdu->params[0];
+ uint64_t identifier = bt_get_64(&pdu->params[0]);
uint16_t pos;
uint8_t nattr;
GList *attr_ids;
uint16_t offset;
- if (len < 9 || *identifier != 0)
+ if (len < 9 || identifier != 0)
goto err;
nattr = pdu->params[8];
@@ -687,10 +687,10 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
len = g_list_length(attr_ids);
} else {
unsigned int i;
- uint32_t *attr = (uint32_t *) &pdu->params[9];
+ for (i = 0, len = 0, attr_ids = NULL; i < nattr; i++) {
+ uint32_t id;
- for (i = 0, len = 0, attr_ids = NULL; i < nattr; i++, attr++) {
- uint32_t id = ntohl(bt_get_unaligned(attr));
+ id = bt_get_be32(&pdu->params[9] + (i * sizeof(id)));
/* Don't add invalid attributes */
if (id == AVRCP_MEDIA_ATTRIBUTE_ILLEGAL ||
--
1.7.9.5
^ permalink raw reply related
* [RFC 09/15] scotest: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following build errors on ARM.
CC test/scotest.o
test/scotest.c: In function send_mode:
test/scotest.c:272:4: error: cast increases required alignment of
target type [-Werror=cast-align]
test/scotest.c:273:4: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [test/scotest.o] Error 1
make: *** [all] Error 2
Change-Id: Ib0fb15e000f333bce4228e96762ee2c849c580d9
---
test/scotest.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/test/scotest.c b/test/scotest.c
index 17bd8a6..de65edf 100644
--- a/test/scotest.c
+++ b/test/scotest.c
@@ -269,8 +269,9 @@ static void send_mode(char *svr)
seq = 0;
while (1) {
- *(uint32_t *) buf = htobl(seq);
- *(uint16_t *) (buf + 4) = htobs(data_size);
+ bt_put_le32(seq, buf);
+ bt_put_le16(data_size, buf + 4);
+
seq++;
if (send(sk, buf, so.mtu, 0) <= 0) {
--
1.7.9.5
^ permalink raw reply related
* [RFC 08/15] monitor: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following compilation errors on ARM.
CC monitor/hcidump.o
monitor/hcidump.c: In function device_callback:
monitor/hcidump.c:147:11: error: cast increases required alignment of
target type [-Werror=cast-align]
monitor/hcidump.c:150:10: error: cast increases required alignment of
target type [-Werror=cast-align]
monitor/hcidump.c: In function stack_internal_callback:
monitor/hcidump.c:348:9: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [monitor/hcidump.o] Error 1
make: *** [all] Error 2
CC monitor/hcidump.o
monitor/hcidump.c: In function stack_internal_callback:
monitor/hcidump.c:357:9: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [monitor/hcidump.o] Error 1
make: *** [all] Error 2
CC monitor/control.o
monitor/control.c: In function data_callback:
monitor/control.c:574:10: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [monitor/control.o] Error 1
make: *** [all] Error 2
Change-Id: I94bff30d7c531bd6a7cdbb791df6995cc099a810
---
monitor/control.c | 7 +++++--
monitor/hcidump.c | 23 ++++++++++++++++-------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/monitor/control.c b/monitor/control.c
index c300ae9..c5ff26b 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -555,6 +555,7 @@ static void data_callback(int fd, uint32_t events, void *user_data)
while (1) {
struct cmsghdr *cmsg;
struct timeval *tv = NULL;
+ struct timeval ctv;
uint16_t opcode, index, pktlen;
ssize_t len;
@@ -570,8 +571,10 @@ static void data_callback(int fd, uint32_t events, void *user_data)
if (cmsg->cmsg_level != SOL_SOCKET)
continue;
- if (cmsg->cmsg_type == SCM_TIMESTAMP)
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ if (cmsg->cmsg_type == SCM_TIMESTAMP) {
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
+ }
}
opcode = btohs(hdr.opcode);
diff --git a/monitor/hcidump.c b/monitor/hcidump.c
index 373d2f5..8653446 100644
--- a/monitor/hcidump.c
+++ b/monitor/hcidump.c
@@ -130,8 +130,10 @@ static void device_callback(int fd, uint32_t events, void *user_data)
while (1) {
struct cmsghdr *cmsg;
struct timeval *tv = NULL;
- int *dir = NULL;
+ struct timeval ctv;
+ bool dir = false;
ssize_t len;
+ bool dir_present = false;
len = recvmsg(fd, &msg, MSG_DONTWAIT);
if (len < 0)
@@ -144,15 +146,19 @@ static void device_callback(int fd, uint32_t events, void *user_data)
switch (cmsg->cmsg_type) {
case HCI_DATA_DIR:
- dir = (int *) CMSG_DATA(cmsg);
+ dir = !!bt_get_32(CMSG_DATA(cmsg));
+ dir_present = true;
+
break;
case HCI_CMSG_TSTAMP:
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
+
break;
}
}
- if (!dir || len < 1)
+ if (!dir_present || len < 1)
continue;
switch (buf[0]) {
@@ -163,11 +169,11 @@ static void device_callback(int fd, uint32_t events, void *user_data)
packet_hci_event(tv, data->index, buf + 1, len - 1);
break;
case HCI_ACLDATA_PKT:
- packet_hci_acldata(tv, data->index, !!(*dir),
+ packet_hci_acldata(tv, data->index, dir,
buf + 1, len - 1);
break;
case HCI_SCODATA_PKT:
- packet_hci_scodata(tv, data->index, !!(*dir),
+ packet_hci_scodata(tv, data->index, dir,
buf + 1, len - 1);
break;
}
@@ -314,6 +320,7 @@ static void stack_internal_callback(int fd, uint32_t events, void *user_data)
evt_stack_internal *si;
evt_si_device *sd;
struct timeval *tv = NULL;
+ struct timeval ctv;
uint8_t type = 0xff, bus = 0xff;
char str[18], name[8] = "";
bdaddr_t bdaddr;
@@ -345,7 +352,9 @@ static void stack_internal_callback(int fd, uint32_t events, void *user_data)
switch (cmsg->cmsg_type) {
case HCI_CMSG_TSTAMP:
- tv = (struct timeval *) CMSG_DATA(cmsg);
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
+
break;
}
}
--
1.7.9.5
^ permalink raw reply related
* [RFC 07/15] rctest: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following build errors on ARM.
CC test/rctest.o
test/rctest.c: In function do_send:
test/rctest.c:539:4: error: cast increases required alignment of target
type [-Werror=cast-align]
test/rctest.c:540:4: error: cast increases required alignment of target
type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [test/rctest.o] Error 1
Change-Id: Ied636b0926fba2fece1ae3fbbdeff73bed764de9
---
test/rctest.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index 4d7c90a..43ae09d 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -536,8 +536,9 @@ static void do_send(int sk)
seq = 0;
while ((num_frames == -1) || (num_frames-- > 0)) {
- *(uint32_t *) buf = htobl(seq);
- *(uint16_t *) (buf + 4) = htobs(data_size);
+ bt_put_le32(seq, buf);
+ bt_put_le16(data_size, buf + 4);
+
seq++;
if (send(sk, buf, data_size, 0) <= 0) {
--
1.7.9.5
^ permalink raw reply related
* [RFC 06/15] l2test: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following build errors on ARM.
CC test/l2test.o
test/l2test.c: In function recv_mode:
test/l2test.c:826:9: error: cast increases required alignment of target
type [-Werror=cast-align]
test/l2test.c:834:8: error: cast increases required alignment of target
type [-Werror=cast-align]
test/l2test.c: In function do_send:
test/l2test.c:893:4: error: cast increases required alignment of target
type [-Werror=cast-align]
test/l2test.c:894:4: error: cast increases required alignment of target
type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [test/l2test.o] Error 1
Change-Id: If23f312fcb10d66f74891f6a8bffcac737ae5eda
---
test/l2test.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/test/l2test.c b/test/l2test.c
index d31be10..7645681 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -823,7 +823,7 @@ static void recv_mode(int sk)
}
/* Check sequence */
- sq = btohl(*(uint32_t *) buf);
+ sq = bt_get_le32(buf);
if (seq != sq) {
syslog(LOG_INFO, "seq missmatch: %d -> %d", seq, sq);
seq = sq;
@@ -831,7 +831,7 @@ static void recv_mode(int sk)
seq++;
/* Check length */
- l = btohs(*(uint16_t *) (buf + 4));
+ l = bt_get_le16(buf + 4);
if (len != l) {
syslog(LOG_INFO, "size missmatch: %d -> %d", len, l);
continue;
@@ -890,8 +890,9 @@ static void do_send(int sk)
seq = 0;
while ((num_frames == -1) || (num_frames-- > 0)) {
- *(uint32_t *) buf = htobl(seq);
- *(uint16_t *) (buf + 4) = htobs(data_size);
+ bt_put_le32(seq, buf);
+ bt_put_le16(data_size, buf + 4);
+
seq++;
sent = 0;
--
1.7.9.5
^ permalink raw reply related
* [RFC 05/15] sdp: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix number of build errors on ARM similar to one below.
lib/sdp.c: In function 'sdp_set_seq_len':
lib/sdp.c:625:3: error: cast increases required alignment of target
type [-Werror=cast-align]
lib/sdp.c:625:3: error: cast increases required alignment of target
type [-Werror=cast-align]
lib/sdp.c:631:3: error: cast increases required alignment of target
type [-Werror=cast-align]
lib/sdp.c:631:3: error: cast increases required alignment of target
type [-Werror=cast-align]
Change-Id: Ic539c930f05f905d78fdbc2a77c1f0ff59a04bae
---
lib/sdp.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/lib/sdp.c b/lib/sdp.c
index d40500f..59a958f 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -622,13 +622,13 @@ void sdp_set_seq_len(uint8_t *ptr, uint32_t length)
case SDP_ALT16:
case SDP_TEXT_STR16:
case SDP_URL_STR16:
- bt_put_unaligned(htons(length), (uint16_t *) ptr);
+ bt_put_be16(length, ptr);
break;
case SDP_SEQ32:
case SDP_ALT32:
case SDP_TEXT_STR32:
case SDP_URL_STR32:
- bt_put_unaligned(htonl(length), (uint32_t *) ptr);
+ bt_put_be32(length, ptr);
break;
}
}
@@ -685,7 +685,7 @@ void sdp_set_attrid(sdp_buf_t *buf, uint16_t attr)
/* data type for attr */
*p++ = SDP_UINT16;
buf->data_size = sizeof(uint8_t);
- bt_put_unaligned(htons(attr), (uint16_t *) p);
+ bt_put_be16(attr, p);
buf->data_size += sizeof(uint16_t);
}
@@ -2791,10 +2791,10 @@ void sdp_append_to_buf(sdp_buf_t *dst, uint8_t *data, uint32_t len)
*(uint8_t *) p = dst->data_size - sizeof(uint8_t) - sizeof(uint8_t);
break;
case SDP_SEQ16:
- bt_put_unaligned(htons(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t)), (uint16_t *) p);
+ bt_put_be16(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t), p);
break;
case SDP_SEQ32:
- bt_put_unaligned(htonl(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t)), (uint32_t *) p);
+ bt_put_be32(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t), p);
break;
}
}
@@ -2974,7 +2974,7 @@ int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device
p = reqbuf + sizeof(sdp_pdu_hdr_t);
reqsize = sizeof(sdp_pdu_hdr_t);
- bt_put_unaligned(htonl(handle), (uint32_t *) p);
+ bt_put_be32(handle, p);
reqsize += sizeof(uint32_t);
reqhdr->plen = htons(reqsize - sizeof(sdp_pdu_hdr_t));
@@ -3067,7 +3067,7 @@ int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp
p = reqbuf + sizeof(sdp_pdu_hdr_t);
reqsize = sizeof(sdp_pdu_hdr_t);
- bt_put_unaligned(htonl(handle), (uint32_t *) p);
+ bt_put_be32(handle, p);
reqsize += sizeof(uint32_t);
p += sizeof(uint32_t);
@@ -3354,7 +3354,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
pdata += seqlen;
/* specify the maximum svc rec count that client expects */
- bt_put_unaligned(htons(max_rec_num), (uint16_t *) pdata);
+ bt_put_be16(max_rec_num, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
@@ -3516,12 +3516,12 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
reqsize = sizeof(sdp_pdu_hdr_t);
/* add the service record handle */
- bt_put_unaligned(htonl(handle), (uint32_t *) pdata);
+ bt_put_be32(handle, pdata);
reqsize += sizeof(uint32_t);
pdata += sizeof(uint32_t);
/* specify the response limit */
- bt_put_unaligned(htons(65535), (uint16_t *) pdata);
+ bt_put_be16(65535, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
@@ -3775,7 +3775,7 @@ int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, u
t->reqsize += seqlen;
pdata += seqlen;
- bt_put_unaligned(htons(max_rec_num), (uint16_t *) pdata);
+ bt_put_be16(max_rec_num, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
@@ -3868,12 +3868,12 @@ int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_
t->reqsize = sizeof(sdp_pdu_hdr_t);
/* add the service record handle */
- bt_put_unaligned(htonl(handle), (uint32_t *) pdata);
+ bt_put_be32(handle, pdata);
t->reqsize += sizeof(uint32_t);
pdata += sizeof(uint32_t);
/* specify the response limit */
- bt_put_unaligned(htons(65535), (uint16_t *) pdata);
+ bt_put_be16(65535, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
@@ -3988,7 +3988,7 @@ int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *sear
t->reqsize += seqlen;
pdata += seqlen;
- bt_put_unaligned(htons(SDP_MAX_ATTR_LEN), (uint16_t *) pdata);
+ bt_put_be16(SDP_MAX_ATTR_LEN, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
@@ -4146,14 +4146,18 @@ int sdp_process(sdp_session_t *session)
rsp_count = sizeof(tsrc) + sizeof(csrc) + csrc * 4;
} else {
/* point to the first csrc */
- uint16_t *pcsrc = (uint16_t *) (t->rsp_concat_buf.data + 2);
+ uint8_t *pcsrc = t->rsp_concat_buf.data + 2;
+ uint16_t tcsrc;
+
+ tcsrc = bt_get_16(pcsrc);
/* FIXME: update the interface later. csrc doesn't need be passed to clients */
pdata += sizeof(uint16_t); /* point to csrc */
/* the first csrc contains the sum of partial csrc responses */
- *pcsrc += bt_get_unaligned((uint16_t *) pdata);
+ tcsrc += bt_get_16(pdata);
+ memcpy(pcsrc, &tcsrc, sizeof(tcsrc));
pdata += sizeof(uint16_t); /* point to the first handle */
rsp_count = csrc * 4;
@@ -4336,7 +4340,7 @@ int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search
reqsize += seqlen;
pdata += seqlen;
- bt_put_unaligned(htons(SDP_MAX_ATTR_LEN), (uint16_t *) pdata);
+ bt_put_be16(SDP_MAX_ATTR_LEN, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);
--
1.7.9.5
^ permalink raw reply related
* [RFC 04/15] Add helper functions for putting integers on unaligned memory address
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
Those functions are similar to bt_get_* functions.
Change-Id: I122fd9fcd7cdb3950fbce0ac4a0ea49b2f9ce0f9
---
lib/bluetooth.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index f0776aa..7e6ced9 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -198,6 +198,37 @@ static inline uint16_t bt_get_be16(const void *ptr)
{
return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
}
+
+static inline void bt_put_le64(uint64_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint64_t *) ptr);
+}
+
+static inline void bt_put_be64(uint64_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
+}
+
+static inline void bt_put_le32(uint32_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint32_t *) ptr);
+}
+
+static inline void bt_put_be32(uint32_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
+}
+
+static inline void bt_put_le16(uint16_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint16_t *) ptr);
+}
+
+static inline void bt_put_be16(uint16_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
+}
+
#elif __BYTE_ORDER == __BIG_ENDIAN
static inline uint64_t bt_get_le64(const void *ptr)
{
@@ -228,6 +259,36 @@ static inline uint16_t bt_get_be16(const void *ptr)
{
return bt_get_unaligned((const uint16_t *) ptr);
}
+
+static inline void bt_put_le64(uint64_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
+}
+
+static inline void bt_put_be64(uint64_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint64_t *) ptr);
+}
+
+static inline void bt_put_le32(uint32_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
+}
+
+static inline void bt_put_be32(uint32_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint32_t *) ptr);
+}
+
+static inline void bt_put_le16(uint16_t val, const void *ptr)
+{
+ bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
+}
+
+static inline void bt_put_be16(uint16_t val, const void *ptr)
+{
+ bt_put_unaligned(val, (uint16_t *) ptr);
+}
#else
#error "Unknown byte order"
#endif
--
1.7.9.5
^ permalink raw reply related
* [RFC 03/15] sdp: Use helper functions instead of bt_get_unaligned macro
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix number of compilation errors on ARM similar to one below.
lib/sdp.c: In function 'sdp_uuid_extract':
lib/sdp.c:1019:27: error: cast increases required alignment
of target type [-Werror=cast-align]
lib/sdp.c:1019:27: error: cast increases required alignment
of target type [-Werror=cast-align]
lib/sdp.c:1026:27: error: cast increases required alignment
of target type [-Werror=cast-align]
lib/sdp.c:1026:27: error: cast increases required alignment
of target type [-Werror=cast-align]
Change-Id: I587fb99328d7e5b9053af81597bd48b3a4e610ad
---
lib/sdp.c | 56 ++++++++++++++++++++++++++++----------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/lib/sdp.c b/lib/sdp.c
index 36b4d08..d40500f 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -376,27 +376,27 @@ sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value,
d->unitSize += sizeof(int8_t);
break;
case SDP_UINT16:
- d->val.uint16 = bt_get_unaligned((uint16_t *) value);
+ d->val.uint16 = bt_get_16(value);
d->unitSize += sizeof(uint16_t);
break;
case SDP_INT16:
- d->val.int16 = bt_get_unaligned((int16_t *) value);
+ d->val.int16 = bt_get_16(value);
d->unitSize += sizeof(int16_t);
break;
case SDP_UINT32:
- d->val.uint32 = bt_get_unaligned((uint32_t *) value);
+ d->val.uint32 = bt_get_32(value);
d->unitSize += sizeof(uint32_t);
break;
case SDP_INT32:
- d->val.int32 = bt_get_unaligned((int32_t *) value);
+ d->val.int32 = bt_get_32(value);
d->unitSize += sizeof(int32_t);
break;
case SDP_INT64:
- d->val.int64 = bt_get_unaligned((int64_t *) value);
+ d->val.int64 = bt_get_64(value);
d->unitSize += sizeof(int64_t);
break;
case SDP_UINT64:
- d->val.uint64 = bt_get_unaligned((uint64_t *) value);
+ d->val.uint64 = bt_get_64(value);
d->unitSize += sizeof(uint64_t);
break;
case SDP_UINT128:
@@ -408,11 +408,11 @@ sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value,
d->unitSize += sizeof(uint128_t);
break;
case SDP_UUID16:
- sdp_uuid16_create(&d->val.uuid, bt_get_unaligned((uint16_t *) value));
+ sdp_uuid16_create(&d->val.uuid, bt_get_16(value));
d->unitSize += sizeof(uint16_t);
break;
case SDP_UUID32:
- sdp_uuid32_create(&d->val.uuid, bt_get_unaligned((uint32_t *) value));
+ sdp_uuid32_create(&d->val.uuid, bt_get_32(value));
d->unitSize += sizeof(uint32_t);
break;
case SDP_UUID128:
@@ -1016,14 +1016,14 @@ int sdp_uuid_extract(const uint8_t *p, int bufsize, uuid_t *uuid, int *scanned)
SDPERR("Not enough room for 16-bit UUID");
return -1;
}
- sdp_uuid16_create(uuid, ntohs(bt_get_unaligned((uint16_t *) p)));
+ sdp_uuid16_create(uuid, bt_get_be16(p));
*scanned += sizeof(uint16_t);
} else if (type == SDP_UUID32) {
if (bufsize < (int) sizeof(uint32_t)) {
SDPERR("Not enough room for 32-bit UUID");
return -1;
}
- sdp_uuid32_create(uuid, ntohl(bt_get_unaligned((uint32_t *) p)));
+ sdp_uuid32_create(uuid, bt_get_be32(p));
*scanned += sizeof(uint32_t);
} else {
if (bufsize < (int) sizeof(uint128_t)) {
@@ -1078,7 +1078,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint16_t);
- d->val.uint16 = ntohs(bt_get_unaligned((uint16_t *) p));
+ d->val.uint16 = bt_get_be16(p);
break;
case SDP_INT32:
case SDP_UINT32:
@@ -1088,7 +1088,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint32_t);
- d->val.uint32 = ntohl(bt_get_unaligned((uint32_t *) p));
+ d->val.uint32 = bt_get_be32(p);
break;
case SDP_INT64:
case SDP_UINT64:
@@ -1098,7 +1098,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint64_t);
- d->val.uint64 = ntoh64(bt_get_unaligned((uint64_t *) p));
+ d->val.uint64 = bt_get_be64(p);
break;
case SDP_INT128:
case SDP_UINT128:
@@ -1181,7 +1181,7 @@ static sdp_data_t *extract_str(const void *p, int bufsize, int *len)
free(d);
return NULL;
}
- n = ntohs(bt_get_unaligned((uint16_t *) p));
+ n = bt_get_be16(p);
p += sizeof(uint16_t);
*len += sizeof(uint16_t) + n;
bufsize -= sizeof(uint16_t);
@@ -1251,7 +1251,7 @@ int sdp_extract_seqtype(const uint8_t *buf, int bufsize, uint8_t *dtdp, int *siz
SDPERR("Unexpected end of packet");
return 0;
}
- *size = ntohs(bt_get_unaligned((uint16_t *) buf));
+ *size = bt_get_be16(buf);
scanned += sizeof(uint16_t);
break;
case SDP_SEQ32:
@@ -1260,7 +1260,7 @@ int sdp_extract_seqtype(const uint8_t *buf, int bufsize, uint8_t *dtdp, int *siz
SDPERR("Unexpected end of packet");
return 0;
}
- *size = ntohl(bt_get_unaligned((uint32_t *) buf));
+ *size = bt_get_be32(buf);
scanned += sizeof(uint32_t);
break;
default:
@@ -1427,7 +1427,7 @@ sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int bufsize, int *scanned)
}
dtd = *(uint8_t *) p;
- attr = ntohs(bt_get_unaligned((uint16_t *) (p + n)));
+ attr = bt_get_be16((p + n));
n += sizeof(uint16_t);
SDPDBG("DTD of attrId : %d Attr id : 0x%x \n", dtd, attr);
@@ -2891,7 +2891,7 @@ int sdp_device_record_register_binary(sdp_session_t *session, bdaddr_t *device,
goto end;
}
if (handle)
- *handle = ntohl(bt_get_unaligned((uint32_t *) p));
+ *handle = bt_get_be32(p);
}
end:
@@ -2991,7 +2991,7 @@ int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device
rsphdr = (sdp_pdu_hdr_t *) rspbuf;
p = rspbuf + sizeof(sdp_pdu_hdr_t);
- status = bt_get_unaligned((uint16_t *) p);
+ status = bt_get_16(p);
if (rsphdr->pdu_id == SDP_ERROR_RSP) {
/* For this case the status always is invalid record handle */
@@ -3096,7 +3096,7 @@ int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp
rsphdr = (sdp_pdu_hdr_t *) rspbuf;
p = rspbuf + sizeof(sdp_pdu_hdr_t);
- status = bt_get_unaligned((uint16_t *) p);
+ status = bt_get_16(p);
if (rsphdr->pdu_id == SDP_ERROR_RSP) {
/* The status can be invalid sintax or invalid record handle */
@@ -3183,7 +3183,7 @@ static void extract_record_handle_seq(uint8_t *pdu, int bufsize, sdp_list_t **se
pSvcRec = malloc(sizeof(uint32_t));
if (!pSvcRec)
break;
- *pSvcRec = ntohl(bt_get_unaligned((uint32_t *) pdata));
+ *pSvcRec = bt_get_be32(pdata);
pSeq = sdp_list_append(pSeq, pSvcRec);
pdata += sizeof(uint32_t);
*scanned += sizeof(uint32_t);
@@ -3407,7 +3407,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
pdata += sizeof(uint16_t);
scanned += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
- rec_count = ntohs(bt_get_unaligned((uint16_t *) pdata));
+ rec_count = bt_get_be16(pdata);
pdata += sizeof(uint16_t);
scanned += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
@@ -3573,7 +3573,7 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
goto end;
}
- rsp_count = ntohs(bt_get_unaligned((uint16_t *) pdata));
+ rsp_count = bt_get_be16(pdata);
attr_list_len += rsp_count;
pdata += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
@@ -4124,9 +4124,9 @@ int sdp_process(sdp_session_t *session)
* CSRC: Current Service Record Count (2 bytes)
*/
ssr_pdata = pdata;
- tsrc = ntohs(bt_get_unaligned((uint16_t *) ssr_pdata));
+ tsrc = bt_get_be16(ssr_pdata);
ssr_pdata += sizeof(uint16_t);
- csrc = ntohs(bt_get_unaligned((uint16_t *) ssr_pdata));
+ csrc = bt_get_be16(ssr_pdata);
/* csrc should never be larger than tsrc */
if (csrc > tsrc) {
@@ -4162,7 +4162,7 @@ int sdp_process(sdp_session_t *session)
break;
case SDP_SVC_ATTR_RSP:
case SDP_SVC_SEARCH_ATTR_RSP:
- rsp_count = ntohs(bt_get_unaligned((uint16_t *) pdata));
+ rsp_count = bt_get_be16(pdata);
SDPDBG("Attrlist byte count : %d\n", rsp_count);
/*
@@ -4175,7 +4175,7 @@ int sdp_process(sdp_session_t *session)
status = 0x0000;
break;
case SDP_ERROR_RSP:
- status = ntohs(bt_get_unaligned((uint16_t *) pdata));
+ status = bt_get_be16(pdata);
size = ntohs(rsphdr->plen);
goto end;
@@ -4395,7 +4395,7 @@ int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search
goto end;
}
- rsp_count = ntohs(bt_get_unaligned((uint16_t *) pdata));
+ rsp_count = bt_get_be16(pdata);
attr_list_len += rsp_count;
pdata += sizeof(uint16_t); /* pdata points to attribute list */
pdata_len -= sizeof(uint16_t);
--
1.7.9.5
^ permalink raw reply related
* [RFC 02/15] sap-u8500: Fix compile error due to unaligned memory access
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
This fix following compilation error on ARM.
CC profiles/sap/sap-u8500.o
profiles/sap/sap-u8500.c: In function recv_card_status:
profiles/sap/sap-u8500.c:323:16: error: cast increases required
alignment of target type [-Werror=cast-align]
profiles/sap/sap-u8500.c: In function recv_response:
profiles/sap/sap-u8500.c:423:12: error: cast increases required
alignment of target type [-Werror=cast-align]
cc1: all warnings being treated as errors
Change-Id: Id771049b5c18ddd95a28aa50b48775f3ee3e9074
---
profiles/sap/sap-u8500.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/profiles/sap/sap-u8500.c b/profiles/sap/sap-u8500.c
index f07209d..6e95d7a 100644
--- a/profiles/sap/sap-u8500.c
+++ b/profiles/sap/sap-u8500.c
@@ -32,6 +32,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include <bluetooth/bluetooth.h>
+
#include "log.h"
#include "sap.h"
@@ -313,16 +315,16 @@ static void recv_status(uint32_t status)
static void recv_card_status(uint32_t status, uint8_t *param)
{
- uint32_t *card_status;
+ uint32_t card_status;
uint8_t result;
uint8_t iccrs;
if (status != STE_STATUS_OK)
return;
- card_status = (uint32_t *)param;
+ card_status = bt_get_32(param);
- if (get_sap_reader_status(*card_status, &iccrs) < 0)
+ if (get_sap_reader_status(card_status, &iccrs) < 0)
result = SAP_RESULT_ERROR_NO_REASON;
else
result = get_sap_result(STE_GET_STATUS_MSG, status);
@@ -420,7 +422,7 @@ static void recv_response(struct ste_message *msg)
}
param = msg->payload;
- status = *(uint32_t *)param;
+ status = bt_get_32(param);
param += sizeof(status);
SAP_VDBG("status 0x%x", status);
--
1.7.9.5
^ permalink raw reply related
* [RFC 01/15] lib: Add host order unaligned access functions
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1346402185-9487-1-git-send-email-szymon.janc@tieto.com>
Change-Id: I3c647249a88b8ca05ef215096e6b9a5609e8eab9
---
lib/bluetooth.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 0fc4508..f0776aa 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -153,6 +153,21 @@ do { \
__p->__v = (val); \
} while(0)
+static inline uint64_t bt_get_64(const void *ptr)
+{
+ return bt_get_unaligned((const uint64_t *) ptr);
+}
+
+static inline uint32_t bt_get_32(const void *ptr)
+{
+ return bt_get_unaligned((const uint32_t *) ptr);
+}
+
+static inline uint16_t bt_get_16(const void *ptr)
+{
+ return bt_get_unaligned((const uint16_t *) ptr);
+}
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
static inline uint64_t bt_get_le64(const void *ptr)
{
--
1.7.9.5
^ permalink raw reply related
* [RFC 00/15] Unaligned memory access fixes
From: Szymon Janc @ 2012-08-31 8:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Hi,
A list of patches that address unaligned memory access issues all over
the code base.
It looks like recent versions of GCC are more picky about that. These
patches allow to build BlueZ in boostrap-configure configuration
(excluding gstreamer code) with GCC 4.7.1 for ARM.
In few places I had to do a small refactor instead of just use bt_put/get
functions. So please have a look at those.
There could be also bt_put_* functions added for putting u16/32/64 in
unaligned memory in host order. That could allow to eliminate some of
memcpy(ptr, &some_u32, sizeof(some_u32);
with more convenient
bt_put_32(some_u32, ptr);
Comments are welcome.
--
BR
Szymon Janc
Szymon Janc (15):
lib: Add host order unaligned access functions
sap-u8500: Fix compile error due to unaligned memory access
sdp: Use helper functions instead of bt_get_unaligned macro
Add helper functions for putting integers on unaligned memory address
sdp: Fix compilation errors due to unaligned memory access
l2test: Fix compilation errors due to unaligned memory access
rctest: Fix compilation errors due to unaligned memory access
monitor: Fix compilation errors due to unaligned memory access
scotest: Fix compilation errors due to unaligned memory access
avrcp: Fix compilation errors due to unaligned memory access
sap: Fix compilation errors due to unaligned memory access
adaptername: Refactor handle_inotify_cb
sdpd-request: Fix build errors due to unaligned memory access
sdpd-service: Fix build errors due to unaligned memory access
hciemu: Fix build errors due to unaligned memory access
audio/avrcp.c | 10 ++---
lib/bluetooth.h | 76 +++++++++++++++++++++++++++++++++++++
lib/sdp.c | 94 ++++++++++++++++++++++++----------------------
monitor/control.c | 7 +++-
monitor/hcidump.c | 23 ++++++++----
plugins/adaptername.c | 44 ++++++++++++----------
profiles/sap/sap-u8500.c | 10 +++--
profiles/sap/server.c | 9 ++---
src/sdpd-request.c | 62 ++++++++++++++++--------------
src/sdpd-service.c | 21 +++++------
test/hciemu.c | 6 ++-
test/l2test.c | 9 +++--
test/rctest.c | 5 ++-
test/scotest.c | 5 ++-
14 files changed, 243 insertions(+), 138 deletions(-)
--
1.7.9.5
^ permalink raw reply
* [PATCH hcidump] amp: Decode Num Completed Data Blocks
From: Andrei Emeltchenko @ 2012-08-31 7:37 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Adds decoding Number Of Completed Data Blocks Event
> HCI Event: Number Of Completed Data Blocks (0x48) plen 9
Total num blocks 4 Num handles 1
Handle 0x0001: Num complt pkts 1 Num complt blks 1
---
lib/hci.h | 10 ++++++++++
parser/hci.c | 22 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/lib/hci.h b/lib/hci.h
index d068a2f..7eacca5 100644
--- a/lib/hci.h
+++ b/lib/hci.h
@@ -2197,6 +2197,16 @@ typedef struct {
#define EVT_FLOW_SPEC_MODIFY_COMPLETE_SIZE 3
#define EVT_NUMBER_COMPLETED_BLOCKS 0x48
+typedef struct {
+ uint16_t handle;
+ uint16_t num_cmplt_pkts;
+ uint16_t num_cmplt_blks;
+} __attribute__ ((packed)) cmplt_handle;
+typedef struct {
+ uint16_t total_num_blocks;
+ uint8_t num_handles;
+ cmplt_handle handles[0];
+} __attribute__ ((packed)) evt_num_completed_blocks;
#define EVT_AMP_STATUS_CHANGE 0x4D
typedef struct {
diff --git a/parser/hci.c b/parser/hci.c
index 38794bd..19cd419 100644
--- a/parser/hci.c
+++ b/parser/hci.c
@@ -3743,6 +3743,25 @@ static inline void flow_spec_modify_dump(int level, struct frame *frm)
}
}
+static inline void num_completed_blocks_dump(int level, struct frame *frm)
+{
+ evt_num_completed_blocks *evt = frm->ptr;
+ int i;
+
+ p_indent(level, frm);
+ printf("Total num blocks %d Num handles %d\n",
+ btohs(evt->total_num_blocks), evt->num_handles);
+
+ for (i = 0; i < evt->num_handles; i++) {
+ cmplt_handle *h = &evt->handles[i];
+
+ p_indent(level + 1, frm);
+ printf("Handle 0x%4.4x: Num complt pkts %d Num complt blks %d\n",
+ btohs(h->handle), btohs(h->num_cmplt_pkts),
+ btohs(h->num_cmplt_blks));
+ }
+}
+
static inline void event_dump(int level, struct frame *frm)
{
hci_event_hdr *hdr = frm->ptr;
@@ -3969,6 +3988,9 @@ static inline void event_dump(int level, struct frame *frm)
case EVT_FLOW_SPEC_MODIFY_COMPLETE:
flow_spec_modify_dump(level + 1, frm);
break;
+ case EVT_NUMBER_COMPLETED_BLOCKS:
+ num_completed_blocks_dump(level + 1, frm);
+ break;
default:
raw_dump(level, frm);
break;
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH obexd] client: Add parameters to get message in map module
From: Frederic Danis @ 2012-08-31 7:23 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <CABBYNZKgTHcPDGOj4Qi+6=XDqFK6g9c-zZ-tANKCjLQqhKKjQw@mail.gmail.com>
Hello Luiz,
On 30/08/2012 17:21, Luiz Augusto von Dentz wrote:
>> + apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_ATTACHMENT, 0);
>> + apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_CHARSET, 1);
>> + len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
>> +
>> + obc_transfer_set_params(transfer, buf, len);
>> +
>> + g_obex_apparam_free(apparam);
>> +
>> if (!obc_session_queue(msg->data->session, transfer, NULL, NULL, &err))
>> goto fail;
>>
>> --
>> 1.7.9.5
>
> I have a pending patchset to address this, basically adding filters
> parameters so the application can enable what this parameters should
> be. Btw, Im confused why are you setting attachment as type uint8, the
> spec says it should assume "On" or "Off", which normally means it is
> of string type.
>
I sent this as those parameters are needed to be able to retrieve
message on Samsung GT-I9300.
Forgot it as you have more complete patchset.
Attachment parameter is defined as a byte in chapter 6.3.1 of the MAP
spec (page 65, bitmask with 0="OFF" and 1="ON").
--
Frederic Danis Open Source Technology Center
frederic.danis@intel.com Intel Corporation
^ permalink raw reply
* [PATCH] Bluetooth: Use GFP_KERNEL in read_index_list
From: Szymon Janc @ 2012-08-31 7:05 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
read_index_list is executed by user thread running in kernel-mode
thus is allowed to sleep.
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
net/bluetooth/mgmt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a3329cb..7b1a5c8 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -340,7 +340,7 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,
}
rp_len = sizeof(*rp) + (2 * count);
- rp = kmalloc(rp_len, GFP_ATOMIC);
+ rp = kmalloc(rp_len, GFP_KERNEL);
if (!rp) {
read_unlock(&hci_dev_list_lock);
return -ENOMEM;
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/2] Cache firmware images for later use
From: Jesse Sung @ 2012-08-31 5:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1346390510-18538-1-git-send-email-jesse.sung@canonical.com>
From: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Since request_firmware() may fail when resume from suspend, store
used firmware image in ram to make sure that we can have what we need
on resume.
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
---
drivers/bluetooth/btusb.c | 77 +++++++++++++++++++++++++++++++++++----------
1 file changed, 60 insertions(+), 17 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 7189fed..8bf9e89 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -218,18 +218,34 @@ MODULE_FIRMWARE(FW_0A5C_21F3);
MODULE_FIRMWARE(FW_0A5C_21F4);
MODULE_FIRMWARE(FW_413C_8197);
+struct firmware_cache {
+ const char *filename;
+ u8* data;
+ size_t size;
+};
+
+static struct firmware_cache firmware[] = {
+ { .filename = FW_0A5C_21D3, },
+ { .filename = FW_0A5C_21D7, },
+ { .filename = FW_413C_8197, },
+ { .filename = FW_0489_E031, },
+ { .filename = FW_0A5C_21E6, },
+ { .filename = FW_0A5C_21F3, },
+ { .filename = FW_0A5C_21F4, },
+};
+
static struct usb_device_id patchram_table[] = {
/* Dell DW1704 */
- { USB_DEVICE(0x0a5c, 0x21d3), .driver_info = (kernel_ulong_t) FW_0A5C_21D3 },
- { USB_DEVICE(0x0a5c, 0x21d7), .driver_info = (kernel_ulong_t) FW_0A5C_21D7 },
+ { USB_DEVICE(0x0a5c, 0x21d3), .driver_info = (kernel_ulong_t) &firmware[0] },
+ { USB_DEVICE(0x0a5c, 0x21d7), .driver_info = (kernel_ulong_t) &firmware[1] },
/* Dell DW380 */
- { USB_DEVICE(0x413c, 0x8197), .driver_info = (kernel_ulong_t) FW_413C_8197 },
+ { USB_DEVICE(0x413c, 0x8197), .driver_info = (kernel_ulong_t) &firmware[2] },
/* FoxConn Hon Hai */
- { USB_DEVICE(0x0489, 0xe031), .driver_info = (kernel_ulong_t) FW_0489_E031 },
+ { USB_DEVICE(0x0489, 0xe031), .driver_info = (kernel_ulong_t) &firmware[3] },
/* Lenovo */
- { USB_DEVICE(0x0a5c, 0x21e6), .driver_info = (kernel_ulong_t) FW_0A5C_21E6 },
- { USB_DEVICE(0x0a5c, 0x21f3), .driver_info = (kernel_ulong_t) FW_0A5C_21F3 },
- { USB_DEVICE(0x0a5c, 0x21f4), .driver_info = (kernel_ulong_t) FW_0A5C_21F4 },
+ { USB_DEVICE(0x0a5c, 0x21e6), .driver_info = (kernel_ulong_t) &firmware[4] },
+ { USB_DEVICE(0x0a5c, 0x21f3), .driver_info = (kernel_ulong_t) &firmware[5] },
+ { USB_DEVICE(0x0a5c, 0x21f4), .driver_info = (kernel_ulong_t) &firmware[6] },
};
#define BTUSB_MAX_ISOC_FRAMES 10
@@ -953,14 +969,27 @@ static inline void load_patchram_fw(struct usb_device *udev, const struct usb_de
{
size_t pos = 0;
int err = 0;
- const struct firmware *fw;
+ struct firmware_cache *fwcache;
unsigned char reset_cmd[] = { 0x03, 0x0c, 0x00 };
unsigned char download_cmd[] = { 0x2e, 0xfc, 0x00 };
- if (request_firmware(&fw, (const char *) id->driver_info, &udev->dev) < 0) {
- BT_INFO("can't load firmware, may not work correctly");
- return;
+ fwcache = (struct firmware_cache *)id->driver_info;
+ if (!fwcache->data) {
+ const struct firmware *fw;
+ if (request_firmware(&fw, fwcache->filename, &udev->dev) < 0) {
+ BT_INFO("can't load firmware, may not work correctly");
+ return;
+ }
+ fwcache->data = kmalloc(fw->size, GFP_KERNEL);
+ if (!fwcache->data) {
+ BT_INFO("OOM");
+ release_firmware(fw);
+ return;
+ }
+ fwcache->size = fw->size;
+ memcpy(fwcache->data, fw->data, fwcache->size);
+ release_firmware(fw);
}
if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
@@ -977,12 +1006,12 @@ static inline void load_patchram_fw(struct usb_device *udev, const struct usb_de
}
msleep(300);
- while (pos < fw->size) {
+ while (pos < fwcache->size) {
size_t len;
- len = fw->data[pos + 2] + 3;
- if ((pos + len > fw->size) ||
+ len = fwcache->data[pos + 2] + 3;
+ if ((pos + len > fwcache->size) ||
(usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
- USB_TYPE_CLASS, 0, 0, (void *)fw->data + pos, len,
+ USB_TYPE_CLASS, 0, 0, (void *)(fwcache->data + pos), len,
PATCHRAM_TIMEOUT) < 0)) {
err = -1;
goto out;
@@ -995,7 +1024,6 @@ static inline void load_patchram_fw(struct usb_device *udev, const struct usb_de
out:
if (err)
BT_INFO("fail to load firmware, may not work correctly");
- release_firmware(fw);
}
static int btusb_probe(struct usb_interface *intf,
@@ -1326,7 +1354,22 @@ static struct usb_driver btusb_driver = {
.disable_hub_initiated_lpm = 1,
};
-module_usb_driver(btusb_driver);
+static int __init btusb_init(void)
+{
+ return usb_register(&btusb_driver);
+}
+
+static void __exit btusb_exit(void)
+{
+ int i;
+ for (i = 0; i < sizeof(firmware) / sizeof(firmware[0]); i++)
+ if (firmware[i].data)
+ kfree(firmware[i].data);
+ usb_deregister(&btusb_driver);
+}
+
+module_init(btusb_init);
+module_exit(btusb_exit);
module_param(ignore_dga, bool, 0644);
MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
--
1.7.9.5
^ permalink raw reply related
* [PATCH 1/2] Implement broadcom patchram firmware loader
From: Jesse Sung @ 2012-08-31 5:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1346390510-18538-1-git-send-email-jesse.sung@canonical.com>
From: Wen-chien Jesse Sung <jesse.sung@canonical.com>
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
---
drivers/bluetooth/btusb.c | 103 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 99 insertions(+), 4 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 654e248..7189fed 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -23,6 +23,8 @@
#include <linux/module.h>
#include <linux/usb.h>
+#include <linux/delay.h>
+#include <linux/firmware.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
@@ -47,6 +49,7 @@ static struct usb_driver btusb_driver;
#define BTUSB_BROKEN_ISOC 0x20
#define BTUSB_WRONG_SCO_MTU 0x40
#define BTUSB_ATH3012 0x80
+#define BTUSB_BCM_PATCHRAM 0x100
static struct usb_device_id btusb_table[] = {
/* Generic Bluetooth USB device */
@@ -96,14 +99,15 @@ static struct usb_device_id btusb_table[] = {
{ USB_DEVICE(0x0c10, 0x0000) },
/* Broadcom BCM20702A0 */
+ { USB_DEVICE(0x0489, 0xe031), .driver_info = BTUSB_BCM_PATCHRAM },
{ USB_DEVICE(0x0489, 0xe042) },
- { USB_DEVICE(0x413c, 0x8197) },
+ { USB_DEVICE(0x413c, 0x8197), .driver_info = BTUSB_BCM_PATCHRAM },
/* Foxconn - Hon Hai */
{ USB_DEVICE(0x0489, 0xe033) },
/*Broadcom devices with vendor specific id */
- { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
+ { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01), .driver_info = BTUSB_BCM_PATCHRAM },
{ } /* Terminating entry */
};
@@ -197,6 +201,37 @@ static struct usb_device_id blacklist_table[] = {
{ } /* Terminating entry */
};
+#define PATCHRAM_TIMEOUT 1000
+#define FW_0489_E031 "fw-0489_e031.hcd"
+#define FW_0A5C_21D3 "fw-0a5c_21d3.hcd"
+#define FW_0A5C_21D7 "fw-0a5c_21d7.hcd"
+#define FW_0A5C_21E6 "fw-0a5c_21e6.hcd"
+#define FW_0A5C_21F3 "fw-0a5c_21f3.hcd"
+#define FW_0A5C_21F4 "fw-0a5c_21f4.hcd"
+#define FW_413C_8197 "fw-413c_8197.hcd"
+
+MODULE_FIRMWARE(FW_0489_E031);
+MODULE_FIRMWARE(FW_0A5C_21D3);
+MODULE_FIRMWARE(FW_0A5C_21D7);
+MODULE_FIRMWARE(FW_0A5C_21E6);
+MODULE_FIRMWARE(FW_0A5C_21F3);
+MODULE_FIRMWARE(FW_0A5C_21F4);
+MODULE_FIRMWARE(FW_413C_8197);
+
+static struct usb_device_id patchram_table[] = {
+ /* Dell DW1704 */
+ { USB_DEVICE(0x0a5c, 0x21d3), .driver_info = (kernel_ulong_t) FW_0A5C_21D3 },
+ { USB_DEVICE(0x0a5c, 0x21d7), .driver_info = (kernel_ulong_t) FW_0A5C_21D7 },
+ /* Dell DW380 */
+ { USB_DEVICE(0x413c, 0x8197), .driver_info = (kernel_ulong_t) FW_413C_8197 },
+ /* FoxConn Hon Hai */
+ { USB_DEVICE(0x0489, 0xe031), .driver_info = (kernel_ulong_t) FW_0489_E031 },
+ /* Lenovo */
+ { USB_DEVICE(0x0a5c, 0x21e6), .driver_info = (kernel_ulong_t) FW_0A5C_21E6 },
+ { USB_DEVICE(0x0a5c, 0x21f3), .driver_info = (kernel_ulong_t) FW_0A5C_21F3 },
+ { USB_DEVICE(0x0a5c, 0x21f4), .driver_info = (kernel_ulong_t) FW_0A5C_21F4 },
+};
+
#define BTUSB_MAX_ISOC_FRAMES 10
#define BTUSB_INTR_RUNNING 0
@@ -914,6 +949,55 @@ static void btusb_waker(struct work_struct *work)
usb_autopm_put_interface(data->intf);
}
+static inline void load_patchram_fw(struct usb_device *udev, const struct usb_device_id *id)
+{
+ size_t pos = 0;
+ int err = 0;
+ const struct firmware *fw;
+
+ unsigned char reset_cmd[] = { 0x03, 0x0c, 0x00 };
+ unsigned char download_cmd[] = { 0x2e, 0xfc, 0x00 };
+
+ if (request_firmware(&fw, (const char *) id->driver_info, &udev->dev) < 0) {
+ BT_INFO("can't load firmware, may not work correctly");
+ return;
+ }
+
+ if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
+ reset_cmd, sizeof(reset_cmd), PATCHRAM_TIMEOUT) < 0) {
+ err = -1;
+ goto out;
+ }
+ msleep(300);
+
+ if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
+ download_cmd, sizeof(download_cmd), PATCHRAM_TIMEOUT) < 0) {
+ err = -1;
+ goto out;
+ }
+ msleep(300);
+
+ while (pos < fw->size) {
+ size_t len;
+ len = fw->data[pos + 2] + 3;
+ if ((pos + len > fw->size) ||
+ (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
+ USB_TYPE_CLASS, 0, 0, (void *)fw->data + pos, len,
+ PATCHRAM_TIMEOUT) < 0)) {
+ err = -1;
+ goto out;
+ }
+ pos += len;
+ }
+
+ err = (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
+ reset_cmd, sizeof(reset_cmd), PATCHRAM_TIMEOUT) < 0);
+out:
+ if (err)
+ BT_INFO("fail to load firmware, may not work correctly");
+ release_firmware(fw);
+}
+
static int btusb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
@@ -1078,15 +1162,26 @@ static int btusb_probe(struct usb_interface *intf,
}
}
+ usb_set_intfdata(intf, data);
+
+ if (id->driver_info & BTUSB_BCM_PATCHRAM) {
+ const struct usb_device_id *match;
+ match = usb_match_id(intf, patchram_table);
+ if (match) {
+ btusb_open(hdev);
+ load_patchram_fw(interface_to_usbdev(intf), match);
+ btusb_close(hdev);
+ }
+ }
+
err = hci_register_dev(hdev);
if (err < 0) {
hci_free_dev(hdev);
+ usb_set_intfdata(intf, NULL);
kfree(data);
return err;
}
- usb_set_intfdata(intf, data);
-
return 0;
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH 0/2] broadcom patchram firmware loader
From: Jesse Sung @ 2012-08-31 5:21 UTC (permalink / raw)
To: linux-bluetooth
From: Wen-chien Jesse Sung <jesse.sung@canonical.com>
There is an user space firmware loading tool which can be found at
http://marc.info/?l=linux-bluetooth&m=132039175324993&w=2
This tool requires hci device to do the firmware loading, but this
may cause some race condition between patchram tool and bluetoothd
or something that also works on hci interface.
Also it needs some hooks to make firmware loads after bootup, s3,
s4, rfkill, and device hotplug events. Implement this loader in kernel
module would make things more easier.
These patches are sent to the mailing list for comment on Aug-15:
http://marc.info/?t=134495475100008&r=1&w=2
No further comment since then. I've rebased these patches against
current bluetooth git tree and would like to propose them for merging.
Wen-chien Jesse Sung (2):
Implement broadcom patchram firmware loader
Cache firmware images for later use
drivers/bluetooth/btusb.c | 148 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 143 insertions(+), 5 deletions(-)
--
1.7.9.5
^ permalink raw reply
* [PATCH] Add support for Logitech Harmony Adapter for PS3
From: David Dillow @ 2012-08-31 2:06 UTC (permalink / raw)
To: linux-bluetooth
This emulates a Sony BD Remote for the Logitech Harmony series of
universal remotes.
--
profiles/input/fakehid.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/profiles/input/fakehid.c b/profiles/input/fakehid.c
index 3be1489..dd47287 100644
--- a/profiles/input/fakehid.c
+++ b/profiles/input/fakehid.c
@@ -342,6 +342,16 @@ static struct fake_hid fake_hid_table[] = {
.setup_uinput = ps3remote_setup_uinput,
.devices = NULL,
},
+ /* Logitech Harmony Adapter for PS3 */
+ {
+ .vendor = 0x046d,
+ .product = 0x0306,
+ .connect = fake_hid_common_connect,
+ .disconnect = fake_hid_common_disconnect,
+ .event = ps3remote_event,
+ .setup_uinput = ps3remote_setup_uinput,
+ .devices = NULL,
+ },
{ },
};
^ permalink raw reply related
* Re: [PATCH BlueZ v4 01/15] core: Fix missing g_io_channel_ref
From: Johan Hedberg @ 2012-08-30 23:34 UTC (permalink / raw)
To: João Paulo Rechi Vita; +Cc: linux-bluetooth
In-Reply-To: <1346364960-7699-2-git-send-email-jprvita@openbossa.org>
Hi João Paulo,
On Thu, Aug 30, 2012, João Paulo Rechi Vita wrote:
> ---
> src/device.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/device.c b/src/device.c
> index 3b44d9b..2c40ec2 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -2027,7 +2027,7 @@ static gboolean att_connect(gpointer user_data)
> return FALSE;
> }
>
> - device->att_io = io;
> + device->att_io = g_io_channel_ref(io);
>
> return FALSE;
> }
This doesn't look right to me. bt_io_connect returns a reference for the
caller and you shouldn't need to re-increment the ref count again unless
you store a pointer in multiple places (which you don't). If this patch
fixes some behavior the real bug must be somewhere else.
Johan
^ permalink raw reply
* [PATCH BlueZ v4 15/15] core: Suspend scanning before connect on pairing
From: João Paulo Rechi Vita @ 2012-08-30 22:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: João Paulo Rechi Vita
In-Reply-To: <1346364960-7699-1-git-send-email-jprvita@openbossa.org>
If there is a disconnected bonded device there will be a scanning
procedure active due to the General Connection Establishment Procedure.
This scan have to be suspended before trying to connect to the remote
device for pairing.
---
src/device.c | 150 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 77 insertions(+), 73 deletions(-)
diff --git a/src/device.c b/src/device.c
index 3789c6c..bb625d2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1707,8 +1707,8 @@ send_reply:
else if (dbus_message_is_method_call(req->msg, ADAPTER_INTERFACE,
"CreateDevice")) {
if (err < 0) {
- DBusMessage *reply;
- reply = btd_error_failed(req->msg, strerror(-err));
+ DBusMessage *reply = btd_error_failed(req->msg,
+ strerror(-err));
g_dbus_send_message(req->conn, reply);
goto cleanup;
}
@@ -1920,6 +1920,38 @@ done:
browse_request_free(req);
}
+static void bonding_request_free(struct bonding_req *bonding)
+{
+ struct btd_device *device;
+
+ if (!bonding)
+ return;
+
+ if (bonding->listener_id)
+ g_dbus_remove_watch(bonding->conn, bonding->listener_id);
+
+ if (bonding->msg)
+ dbus_message_unref(bonding->msg);
+
+ if (bonding->conn)
+ dbus_connection_unref(bonding->conn);
+
+ device = bonding->device;
+ g_free(bonding);
+
+ if (!device)
+ return;
+
+ device->bonding = NULL;
+
+ if (!device->agent)
+ return;
+
+ agent_cancel(device->agent);
+ agent_free(device->agent);
+ device->agent = NULL;
+}
+
static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
{
struct att_callbacks *attcb = user_data;
@@ -1949,6 +1981,21 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
if (attcb->success)
attcb->success(user_data);
+
+ if (device->bonding) {
+ /* this is a LE device during pairing */
+ int err = adapter_create_bonding(device->adapter,
+ &device->bdaddr, device->bdaddr_type,
+ agent_get_io_capability(device->agent));
+ if (err < 0) {
+ DBusMessage *reply = btd_error_failed(
+ device->bonding->msg, strerror(-err));
+ g_dbus_send_message(device->bonding->conn, reply);
+ bonding_request_cancel(device->bonding);
+ bonding_request_free(device->bonding);
+ }
+ }
+
done:
g_free(attcb);
}
@@ -2000,16 +2047,30 @@ GIOChannel *device_att_connect(gpointer user_data)
attcb->user_data = device;
if (device_is_bredr(device)) {
- io = bt_io_connect(att_connect_cb,
- attcb, NULL, &gerr,
+ io = bt_io_connect(att_connect_cb, attcb, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, &sba,
BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
BT_IO_OPT_PSM, ATT_PSM,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
BT_IO_OPT_INVALID);
+ } else if (device->bonding) {
+ /* this is a LE device during pairing, using low sec level */
+ io = bt_io_connect(att_connect_cb, attcb, NULL, &gerr,
+ BT_IO_OPT_SOURCE_BDADDR, &sba,
+ BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
+ BT_IO_OPT_DEST_TYPE, device->bdaddr_type,
+ BT_IO_OPT_CID, ATT_CID,
+ BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+ BT_IO_OPT_INVALID);
+ if (io == NULL) {
+ DBusMessage *reply = btd_error_failed(
+ device->bonding->msg, gerr->message);
+ g_dbus_send_message(device->bonding->conn, reply);
+ bonding_request_cancel(device->bonding);
+ bonding_request_free(device->bonding);
+ }
} else {
- io = bt_io_connect(att_connect_cb,
- attcb, NULL, &gerr,
+ io = bt_io_connect(att_connect_cb, attcb, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, &sba,
BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
BT_IO_OPT_DEST_TYPE, device->bdaddr_type,
@@ -2335,38 +2396,6 @@ static DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status)
}
}
-static void bonding_request_free(struct bonding_req *bonding)
-{
- struct btd_device *device;
-
- if (!bonding)
- return;
-
- if (bonding->listener_id)
- g_dbus_remove_watch(bonding->conn, bonding->listener_id);
-
- if (bonding->msg)
- dbus_message_unref(bonding->msg);
-
- if (bonding->conn)
- dbus_connection_unref(bonding->conn);
-
- device = bonding->device;
- g_free(bonding);
-
- if (!device)
- return;
-
- device->bonding = NULL;
-
- if (!device->agent)
- return;
-
- agent_cancel(device->agent);
- agent_free(device->agent);
- device->agent = NULL;
-}
-
void device_set_paired(struct btd_device *device, gboolean value)
{
DBusConnection *conn = get_dbus_connection();
@@ -2460,41 +2489,6 @@ DBusMessage *device_create_bonding(struct btd_device *device,
if (device_is_bonded(device))
return btd_error_already_exists(msg);
- if (device_is_le(device)) {
- struct att_callbacks *attcb;
- GError *gerr = NULL;
- bdaddr_t sba;
-
- adapter_get_address(adapter, &sba);
-
- attcb = g_new0(struct att_callbacks, 1);
- attcb->user_data = device;
-
- device->att_io = bt_io_connect(att_connect_cb,
- attcb, NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, &sba,
- BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
- BT_IO_OPT_DEST_TYPE, device->bdaddr_type,
- BT_IO_OPT_CID, ATT_CID,
- BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
- BT_IO_OPT_INVALID);
-
- if (device->att_io == NULL) {
- DBusMessage *reply = btd_error_failed(msg,
- gerr->message);
-
- error("Bonding bt_io_connect(): %s", gerr->message);
- g_error_free(gerr);
- g_free(attcb);
- return reply;
- }
- }
-
- err = adapter_create_bonding(adapter, &device->bdaddr,
- device->bdaddr_type, capability);
- if (err < 0)
- return btd_error_failed(msg, strerror(-err));
-
bonding = bonding_request_new(conn, msg, device, agent_path,
capability);
@@ -2506,6 +2500,16 @@ DBusMessage *device_create_bonding(struct btd_device *device,
device->bonding = bonding;
bonding->device = device;
+ if (device_is_le(device)) {
+ adapter_connect_list_add(adapter, device);
+ return NULL;
+ }
+
+ err = adapter_create_bonding(adapter, &device->bdaddr,
+ device->bdaddr_type, capability);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
return NULL;
}
--
1.7.11.4
^ permalink raw reply related
* [PATCH BlueZ v4 14/15] mgmt: Add address type to bonding debug message
From: João Paulo Rechi Vita @ 2012-08-30 22:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: João Paulo Rechi Vita
In-Reply-To: <1346364960-7699-1-git-send-email-jprvita@openbossa.org>
---
src/mgmt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/mgmt.c b/src/mgmt.c
index 662d70b..f52cc67a 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -2333,7 +2333,8 @@ int mgmt_create_bonding(int index, bdaddr_t *bdaddr, uint8_t addr_type, uint8_t
char addr[18];
ba2str(bdaddr, addr);
- DBG("hci%d bdaddr %s io_cap 0x%02x", index, addr, io_cap);
+ DBG("hci%d bdaddr %s type %d io_cap 0x%02x",
+ index, addr, addr_type, io_cap);
memset(buf, 0, sizeof(buf));
hdr->opcode = htobs(MGMT_OP_PAIR_DEVICE);
--
1.7.11.4
^ permalink raw reply related
* [PATCH BlueZ v4 13/15] core: Re-connect for ECONNRESET or ECONNABORTED
From: João Paulo Rechi Vita @ 2012-08-30 22:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1346364960-7699-1-git-send-email-jprvita@openbossa.org>
From: Claudio Takahasi <claudio.takahasi@openbossa.org>
This patch keeps scanning and re-connections active if the disconnection
reason is ECONNRESET(Remote Initiated Disconnection).
Re-connection is a behaviour determined by Profiles or by the upper
layer(user actions). For instance, HoG requires re-connection always
active, no matter if the previous disconnection reason was page timeout
or remote initiated disconnection (ECONNRESET). Some devices disconnects
after some idle time, connectable advertises are sent by the peripheral
when commanded by the user(eg: key pressed). Disconnection can be also
triggered by the local host (ECONNABORTED) using command line tools or
Disconnect method in the Device interface.
The peripheral dictates the re-connection controlling the connectable
advertises, BlueZ(central) needs to keep the scanning always active to
able to detect the advertises and trigger the connection.
---
src/device.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/device.c b/src/device.c
index b0c4b12..3789c6c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1850,10 +1850,18 @@ static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond,
g_slist_foreach(device->attios, attio_disconnected, NULL);
- if (device->auto_connect == FALSE || err != ETIMEDOUT)
+ if (device->auto_connect == FALSE) {
+ DBG("Automatic connection disabled");
goto done;
+ }
- adapter_connect_list_add(device_get_adapter(device), device);
+ /*
+ * Keep scanning/re-connection active if disconnection reason
+ * is page timeout, remote user terminated connection or local
+ * initiated disconnection.
+ */
+ if (err == ETIMEDOUT || err == ECONNRESET || err == ECONNABORTED)
+ adapter_connect_list_add(device_get_adapter(device), device);
done:
attio_cleanup(device);
--
1.7.11.4
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox