Set disconnect call and callback will be triggered by I/O event on bnep channel. Call bnep_disconnect, it will delete bnep connection and down the interface, if interface is not up and running do not use this api, simply call bnep_free. --- profiles/network/bnep.c | 35 +++++++++++++++++++++++++++++++++++ profiles/network/bnep.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c index 304b9da..4bc08d9 100644 --- a/profiles/network/bnep.c +++ b/profiles/network/bnep.c @@ -71,11 +71,15 @@ struct bnep { GIOChannel *io; uint16_t src; uint16_t dst; + bdaddr_t dst_addr; + char iface[16]; guint attempts; guint setup_to; guint watch; void *data; bnep_connect_cb conn_cb; + bnep_disconnect_cb disconn_cb; + void *disconn_data; }; static void free_bnep_connect(struct bnep *session) @@ -447,6 +451,37 @@ int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb, return 0; } +void bnep_disconnect(struct bnep *session) +{ + if (!session) + return; + + if (session->watch > 0) { + g_source_remove(session->watch); + session->watch = 0; + } + + if (session->io) { + g_io_channel_unref(session->io); + session->io = NULL; + } + + bnep_if_down(session->iface); + bnep_conndel(&session->dst_addr); +} + +void bnep_set_disconnect(struct bnep *session, bnep_disconnect_cb disconn_cb, + void *data) +{ + if (!session || !disconn_cb) + return; + + if (!session->disconn_cb && !session->disconn_data) { + session->disconn_cb = disconn_cb; + session->disconn_data = data; + } +} + int bnep_add_to_bridge(const char *devname, const char *bridge) { int ifindex; diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h index 91ca622..d3c5c1b 100644 --- a/profiles/network/bnep.h +++ b/profiles/network/bnep.h @@ -44,6 +44,10 @@ typedef void (*bnep_connect_cb) (GIOChannel *chan, char *iface, int err, void *data); int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb, void *data); +typedef void (*bnep_disconnect_cb) (void *data); +void bnep_set_disconnect(struct bnep *session, bnep_disconnect_cb disconn_cb, + void *data); +void bnep_disconnect(struct bnep *session); ssize_t bnep_send_ctrl_rsp(int sk, uint8_t type, uint8_t ctrl, uint16_t resp); uint16_t bnep_setup_chk(uint16_t dst_role, uint16_t src_role); -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html