From: José Antonio Santos-Cadenas <santoscadenas@xxxxxxxxx> --- mcap/mcap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/mcap/mcap.c b/mcap/mcap.c index 61d6621..b70545a 100644 --- a/mcap/mcap.c +++ b/mcap/mcap.c @@ -1558,6 +1558,66 @@ static gboolean mdl_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data) return FALSE; } +static void mcap_connect_mdl_cb(GIOChannel *chan, GError *conn_err, + gpointer data) +{ + struct mcap_mdl_op_cb *con = data; + struct mcap_mdl *mdl = con->mdl; + mcap_mdl_operation_cb cb = con->cb.op; + gpointer user_data = con->user_data; + + g_free(con); + DBG("mdl connect callback"); + + if (conn_err) { + DBG("ERROR: mdl connect callback"); + mdl->state = MDL_CLOSED; + g_io_channel_unref(mdl->dc); + mdl->dc = NULL; + cb(mdl, conn_err, user_data); + return; + } + + mdl->state = MDL_CONNECTED; + mdl->wid = g_io_add_watch(mdl->dc, G_IO_ERR | G_IO_HUP | G_IO_NVAL, + (GIOFunc) mdl_event_cb, mdl); + + cb(mdl, conn_err, user_data); +} + +void mcap_mdl_connect(struct mcap_mdl *mdl, BtIOType BtType, uint16_t dcpsm, + GError **err, mcap_mdl_operation_cb connect_cb, gpointer user_data) +{ + struct mcap_mdl_op_cb *con; + + if (mdl->state != MDL_WAITING) { + g_set_error(err, MCAP_ERROR, MCAP_ERROR_INVALID_MDL, + "%s", error2str(MCAP_INVALID_MDL)); + return; + } + + con = g_new0(struct mcap_mdl_op_cb, 1); + con->mdl = mdl; + con->cb.op = connect_cb; + con->user_data = user_data; + + /* TODO: Check if BtIOType is ERTM or Streaming before continue */ + + mdl->dc = bt_io_connect(BtType, mcap_connect_mdl_cb, con, + NULL, err, + BT_IO_OPT_SOURCE_BDADDR, &mdl->mcl->ms->src, + BT_IO_OPT_DEST_BDADDR, &mdl->mcl->addr, + BT_IO_OPT_PSM, dcpsm, + BT_IO_OPT_MTU, MCAP_DC_MTU, + BT_IO_OPT_SEC_LEVEL, mdl->mcl->ms->sec, + BT_IO_OPT_INVALID); + if (*err) { + DBG("MDL Connection error"); + mdl->state = MDL_CLOSED; + g_free(con); + } +} + static gboolean mcl_control_cb(GIOChannel *chan, GIOCondition cond, gpointer data) { -- 1.6.3.3 -- 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