#include <config.h>
#endif
-#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
-#include <string.h>
#include <limits.h>
-#include <sys/socket.h>
+#include <stdbool.h>
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/l2cap.h>
-#include <bluetooth/sdp.h>
-#include <bluetooth/sdp_lib.h>
+#include "lib/bluetooth.h"
+#include "lib/l2cap.h"
+#include "lib/sdp.h"
+#include "lib/sdp_lib.h"
-#include <netinet/in.h>
+#include "src/shared/util.h"
#include "sdpd.h"
#include "log.h"
for (;;) {
char *pElem = NULL;
int localSeqLength = 0;
+ uuid_t *puuid;
if (bufsize < sizeof(uint8_t)) {
SDPDBG("->Unexpected end of buffer");
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 = get_be16(p);
pElem = (char *) aid;
} else {
+ uint16_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
pElem = malloc(sizeof(uint16_t));
- bt_put_unaligned(ntohs(bt_get_unaligned((uint16_t *)p)), (uint16_t *)pElem);
+ put_be16(tmp, pElem);
}
p += sizeof(uint16_t);
seqlen += sizeof(uint16_t);
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 = get_be32(p);
+
pElem = (char *) aid;
} else {
+ uint32_t tmp;
+
+ memcpy(&tmp, p, sizeof(tmp));
+
pElem = malloc(sizeof(uint32_t));
- bt_put_unaligned(ntohl(bt_get_unaligned((uint32_t *)p)), (uint32_t *)pElem);
+ put_be32(tmp, pElem);
}
p += sizeof(uint32_t);
seqlen += sizeof(uint32_t);
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;
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);
goto done;
}
- expected = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ expected = get_be16(pdata);
SDPDBG("Expected count: %d", expected);
SDPDBG("Bytes scanned : %d", scanned);
pdata = buf->data;
/* total service record count = 0 */
- pTotalRecordCount = (short *)pdata;
- bt_put_unaligned(0, (uint16_t *)pdata);
+ pTotalRecordCount = pdata;
+ 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;
+ put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);
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);
+ put_be32(rec->handle, pdata);
pdata += sizeof(uint32_t);
handleSize += sizeof(uint32_t);
}
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);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(rsp_count, pCurrentRecordCount);
if (rsp_count > actual) {
/* cache the rsp and generate a continuation state */
if (pCache) {
pCacheBuffer = pCache->data;
/* get the rsp_count from the cached buffer */
- rsp_count = ntohs(bt_get_unaligned((uint16_t *)pCacheBuffer));
+ rsp_count = get_be16(pCacheBuffer);
/* get index of the last sdp_record_t sent */
lastIndex = cstate->cStateValue.lastIndexSent;
* 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);
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);
}
}
buf->data_size += handleSize;
- bt_put_unaligned(htons(rsp_count), (uint16_t *)pTotalRecordCount);
- bt_put_unaligned(htons(i - lastIndex), (uint16_t *)pCurrentRecordCount);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(i - lastIndex, pCurrentRecordCount);
if (i == rsp_count) {
/* set "null" continuationState */
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;
goto done;
}
- handle = ntohl(bt_get_unaligned((uint32_t *)pdata));
+ handle = get_be32(pdata);
pdata += sizeof(uint32_t);
data_left -= sizeof(uint32_t);
goto done;
}
- max_rsp_size = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ max_rsp_size = get_be16(pdata);
pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
return status;
/* set attribute list byte count */
- bt_put_unaligned(htons(buf->data_size - cstate_size), (uint16_t *)buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
return 0;
}
goto done;
}
- max = ntohs(bt_get_unaligned((uint16_t *)pdata));
+ max = get_be16(pdata);
pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
if (!status) {
/* set attribute list byte count */
- bt_put_unaligned(htons(buf->data_size - cstate_size), (uint16_t *)buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
}
send_rsp:
if (status) {
rsphdr->pdu_id = SDP_ERROR_RSP;
- bt_put_unaligned(htons(status), (uint16_t *)rsp.data);
+ put_be16(status, rsp.data);
rsp.data_size = sizeof(uint16_t);
}
free(req->buf);
}
+void handle_internal_request(int sk, int mtu, void *data, int len)
+{
+ sdp_req_t req;
+
+ bacpy(&req.device, BDADDR_ANY);
+ bacpy(&req.bdaddr, BDADDR_LOCAL);
+ req.local = 0;
+ req.sock = sk;
+ req.mtu = mtu;
+ req.flags = 0;
+ req.buf = data;
+ req.len = len;
+
+ process_request(&req);
+}
+
void handle_request(int sk, uint8_t *data, int len)
{
struct sockaddr_l2 sa;