summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sdp_lib.h6
-rw-r--r--src/sdp.c73
2 files changed, 78 insertions, 1 deletions
diff --git a/include/sdp_lib.h b/include/sdp_lib.h
index 8a89ab6e..a4b2cb4b 100644
--- a/include/sdp_lib.h
+++ b/include/sdp_lib.h
@@ -112,6 +112,12 @@ int sdp_get_socket(const sdp_session_t *session);
uint16_t sdp_gen_tid(sdp_session_t *session);
/*
+ * SDP transaction: functions for asynchronous search.
+ */
+typedef void sdp_callback_t(uint8_t type, sdp_list_t *rsp, void *udata, int err);
+sdp_session_t *sdp_create(int sk, uint32_t flags);
+
+/*
* find all devices in the piconet
*/
int sdp_general_inquiry(inquiry_info *ii, int dev_num, int duration, uint8_t *found);
diff --git a/src/sdp.c b/src/sdp.c
index b1ef47ea..f535ad48 100644
--- a/src/sdp.c
+++ b/src/sdp.c
@@ -3033,6 +3033,59 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
}
/*
+ * SDP transaction structure for asynchronous search
+ */
+struct sdp_transaction {
+ sdp_callback_t *cb;
+ void *udata;
+ sdp_cstate_t *cstate;
+ uint8_t *reqbuf;
+ sdp_buf_t rsp_concat_buf;
+ uint32_t reqsize;
+ int cstate_len;
+ int attr_list_len;
+};
+
+/*
+ * Creates a new sdp session for asynchronous search
+ * INPUT:
+ * int sk
+ * non-blocking L2CAP socket
+ *
+ * RETURN:
+ * sdp_session_t *
+ * NULL - On memory allocation failure
+ */
+sdp_session_t *sdp_create(int sk, uint32_t flags)
+{
+
+ struct sdp_transaction *t;
+ sdp_session_t *session = malloc(sizeof(sdp_session_t));
+ if (!session) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ memset(session, 0, sizeof(*session));
+
+ session->flags = flags;
+ session->sock = sk;
+
+ t = malloc(sizeof(struct sdp_transaction));
+ if (!t) {
+ errno = ENOMEM;
+ free(session);
+ return NULL;
+ }
+
+ memset(t, 0, sizeof(*t));
+
+ session->priv = t;
+
+ return session;
+}
+
+/*
* This is a service search request combined with the service
* attribute request. First a service class match is done and
* for matching service, requested attributes are extracted
@@ -3256,7 +3309,25 @@ int sdp_general_inquiry(inquiry_info *ii, int num_dev, int duration, uint8_t *fo
int sdp_close(sdp_session_t *session)
{
- int ret = close(session->sock);
+ struct sdp_transaction *t;
+ int ret;
+
+ if (!session)
+ return -1;
+
+ ret = close(session->sock);
+
+ t = session->priv;
+
+ if (t) {
+ if (t->reqbuf)
+ free(t->reqbuf);
+
+ if (t->rsp_concat_buf.data)
+ free(t->rsp_concat_buf.data);
+
+ free(t);
+ }
free(session);
return ret;
}