Diff between 0c27ca7f4586ac3387343ad5d11fdf745bd8d75d and 75c7ab2d995a46d3ba439ffbd4ffe2f75bbde9d2

Changed Files

File Additions Deletions Status
emulator/bthost.c +32 -0 modified
emulator/bthost.h +7 -0 modified

Full Patch

diff --git a/emulator/bthost.c b/emulator/bthost.c
index 0f07259..eb2eb73 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -96,6 +96,13 @@ struct l2cap_conn_cb_data {
 	struct l2cap_conn_cb_data *next;
 };
 
+struct rfcomm_conn_cb_data {
+	uint8_t channel;
+	bthost_rfcomm_connect_cb func;
+	void *user_data;
+	struct rfcomm_conn_cb_data *next;
+};
+
 struct bthost {
 	uint8_t bdaddr[6];
 	bthost_send_func send_handler;
@@ -108,6 +115,7 @@ struct bthost {
 	bthost_new_conn_cb new_conn_cb;
 	void *new_conn_data;
 	struct l2cap_conn_cb_data *new_l2cap_conn_data;
+	struct rfcomm_conn_cb_data *new_rfcomm_conn_data;
 	struct l2cap_pending_req *l2reqs;
 	uint8_t pin[16];
 	uint8_t pin_len;
@@ -260,6 +268,13 @@ void bthost_destroy(struct bthost *bthost)
 		free(cb);
 	}
 
+	while (bthost->new_rfcomm_conn_data) {
+		struct rfcomm_conn_cb_data *cb = bthost->new_rfcomm_conn_data;
+
+		bthost->new_rfcomm_conn_data = cb->next;
+		free(cb);
+	}
+
 	free(bthost);
 }
 
@@ -1620,6 +1635,23 @@ void bthost_set_reject_user_confirm(struct bthost *bthost, bool reject)
 	bthost->reject_user_confirm = reject;
 }
 
+void bthost_add_rfcomm_server(struct bthost *bthost, uint8_t channel,
+				bthost_rfcomm_connect_cb func, void *user_data)
+{
+	struct rfcomm_conn_cb_data *data;
+
+	data = malloc(sizeof(struct rfcomm_conn_cb_data));
+	if (!data)
+		return;
+
+	data->channel = channel;
+	data->user_data = user_data;
+	data->func = func;
+	data->next = bthost->new_rfcomm_conn_data;
+
+	bthost->new_rfcomm_conn_data = data;
+}
+
 void bthost_start(struct bthost *bthost)
 {
 	if (!bthost)
diff --git a/emulator/bthost.h b/emulator/bthost.h
index 5fb7ad4..50185a2 100644
--- a/emulator/bthost.h
+++ b/emulator/bthost.h
@@ -89,5 +89,12 @@ void bthost_set_pin_code(struct bthost *bthost, const uint8_t *pin,
 void bthost_set_io_capability(struct bthost *bthost, uint8_t io_capability);
 void bthost_set_reject_user_confirm(struct bthost *bthost, bool reject);
 
+typedef void (*bthost_rfcomm_connect_cb) (uint16_t handle, uint16_t cid,
+					uint8_t channel, void *user_data,
+					bool status);
+
+void bthost_add_rfcomm_server(struct bthost *bthost, uint8_t channel,
+			bthost_rfcomm_connect_cb func, void *user_data);
+
 void bthost_start(struct bthost *bthost);
 void bthost_stop(struct bthost *bthost);