summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sdpd/main.c11
-rw-r--r--sdpd/sdpd.h3
-rw-r--r--sdpd/service.c20
-rw-r--r--sdpd/servicedb.c2
4 files changed, 23 insertions, 13 deletions
diff --git a/sdpd/main.c b/sdpd/main.c
index 51accc9a..734b8bda 100644
--- a/sdpd/main.c
+++ b/sdpd/main.c
@@ -113,7 +113,7 @@ static void register_public_browse_group(int public)
} else
browse->handle = SDP_SERVER_RECORD_HANDLE + 1;
- sdp_record_add(browse);
+ sdp_record_add(BDADDR_ANY, browse);
sdpdata = sdp_data_alloc(SDP_UINT32, &browse->handle);
sdp_attr_add(browse, SDP_ATTR_RECORD_HANDLE, sdpdata);
@@ -155,7 +155,7 @@ static void register_server_service(int public)
/* Force the record to be SDP_SERVER_RECORD_HANDLE */
server->handle = SDP_SERVER_RECORD_HANDLE;
- sdp_record_add(server);
+ sdp_record_add(BDADDR_ANY, server);
sdp_attr_add(server, SDP_ATTR_RECORD_HANDLE, sdp_data_alloc(SDP_UINT32, &server->handle));
/*
@@ -320,7 +320,7 @@ static inline void handle_request(int sk, uint8_t *data, int len)
sdp_req_t req;
size = sizeof(sa);
- if (getpeername(sk, (struct sockaddr *)&sa, &size) < 0)
+ if (getpeername(sk, (struct sockaddr *) &sa, &size) < 0)
return;
if (sa.l2_family == AF_BLUETOOTH) {
@@ -331,7 +331,12 @@ static inline void handle_request(int sk, uint8_t *data, int len)
req.bdaddr = sa.l2_bdaddr;
req.mtu = lo.omtu;
req.local = 0;
+ memset(&sa, 0, sizeof(sa));
+ size = sizeof(sa);
+ getsockname(sk, (struct sockaddr *) &sa, &size);
+ req.device = sa.l2_bdaddr;
} else {
+ req.device = *BDADDR_ANY;
req.bdaddr = *BDADDR_LOCAL;
req.mtu = 2048;
req.local = 1;
diff --git a/sdpd/sdpd.h b/sdpd/sdpd.h
index 3df83fca..0bca315f 100644
--- a/sdpd/sdpd.h
+++ b/sdpd/sdpd.h
@@ -45,6 +45,7 @@
#endif
typedef struct request {
+ bdaddr_t device;
bdaddr_t bdaddr;
int local;
int sock;
@@ -80,7 +81,7 @@ void sdp_svcdb_collect_all(int sock);
void sdp_svcdb_set_collectable(sdp_record_t *rec, int sock);
void sdp_svcdb_collect(sdp_record_t *rec);
sdp_record_t *sdp_record_find(uint32_t handle);
-void sdp_record_add(sdp_record_t *rec);
+void sdp_record_add(bdaddr_t *device, sdp_record_t *rec);
int sdp_record_remove(uint32_t handle);
sdp_list_t *sdp_get_record_list();
uint32_t sdp_next_handle(void);
diff --git a/sdpd/service.c b/sdpd/service.c
index 843371ea..437bcd69 100644
--- a/sdpd/service.c
+++ b/sdpd/service.c
@@ -46,7 +46,7 @@
extern void update_db_timestamp(void);
// FIXME: refactor for server-side
-static sdp_record_t *extract_pdu_server(uint8_t *p, uint32_t handleExpected, int *scanned)
+static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, uint32_t handleExpected, int *scanned)
{
int extractStatus = -1, localExtractedLength = 0;
uint8_t dtd;
@@ -71,15 +71,15 @@ static sdp_record_t *extract_pdu_server(uint8_t *p, uint32_t handleExpected, int
} else if (handleExpected != 0xffffffff)
rec = sdp_record_find(handleExpected);
- if (rec == NULL) {
+ if (!rec) {
rec = sdp_record_alloc();
rec->attrlist = NULL;
if (lookAheadAttrId == SDP_ATTR_RECORD_HANDLE) {
rec->handle = handle;
- sdp_record_add(rec);
+ sdp_record_add(device, rec);
} else if (handleExpected != 0xffffffff) {
rec->handle = handleExpected;
- sdp_record_add(rec);
+ sdp_record_add(device, rec);
}
}
@@ -133,10 +133,14 @@ int service_register_req(sdp_req_t *req, sdp_buf_t *rsp)
sdp_record_t *rec;
req->flags = *p++;
+ if (req->flags & SDP_DEVICE_RECORD) {
+ bacpy(&req->device, (bdaddr_t *) p);
+ p += sizeof(bdaddr_t);
+ }
// save image of PDU: we need it when clients request this attribute
- rec = extract_pdu_server(p, 0xffffffff, &scanned);
- if (rec == NULL) {
+ rec = extract_pdu_server(&req->device, p, 0xffffffff, &scanned);
+ if (!rec) {
sdp_put_unaligned(htons(SDP_INVALID_SYNTAX), (uint16_t *)rsp->data);
rsp->data_size = sizeof(uint16_t);
return -1;
@@ -146,7 +150,7 @@ int service_register_req(sdp_req_t *req, sdp_buf_t *rsp)
if (rec->handle < 0x10000)
return -1;
- sdp_record_add(rec);
+ sdp_record_add(&req->device, rec);
if (!(req->flags & SDP_RECORD_PERSIST))
sdp_svcdb_set_collectable(rec, req->sock);
handle = sdp_data_alloc(SDP_UINT32, &rec->handle);
@@ -189,7 +193,7 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)
SDPDBG("SvcRecOld: 0x%x\n", (uint32_t)orec);
if (orec) {
- sdp_record_t *nrec = extract_pdu_server(p, handle, &scanned);
+ sdp_record_t *nrec = extract_pdu_server(BDADDR_ANY, p, handle, &scanned);
if (nrec && handle == nrec->handle)
update_db_timestamp();
else {
diff --git a/sdpd/servicedb.c b/sdpd/servicedb.c
index 45f45b91..c977bc81 100644
--- a/sdpd/servicedb.c
+++ b/sdpd/servicedb.c
@@ -143,7 +143,7 @@ void sdp_svcdb_set_collectable(sdp_record_t *record, int sock)
/*
* Add a service record to the repository
*/
-void sdp_record_add(sdp_record_t *rec)
+void sdp_record_add(bdaddr_t *device, sdp_record_t *rec)
{
#ifdef SDP_DEBUG
SDPDBG("Adding rec : 0x%lx\n", (long) rec);