From 800c6b667868c58320a9f488daf8058af05d7f41 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 6 Feb 2014 16:28:36 +0100 Subject: [PATCH] profiles/network: Allow to pass interface name to bnep_new --- android/pan.c | 3 ++- profiles/network/bnep.c | 5 ++++- profiles/network/bnep.h | 3 ++- profiles/network/connection.c | 6 ++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/android/pan.c b/android/pan.c index 6b19120bb..b8d740469 100644 --- a/android/pan.c +++ b/android/pan.c @@ -52,6 +52,7 @@ #define SVC_HINT_NETWORKING 0x02 #define BNEP_BRIDGE "bnep" +#define BNEP_PANU_INTERFACE "bt-pan" #define FORWARD_DELAY_PATH "/sys/class/net/"BNEP_BRIDGE"/bridge/forward_delay" static bdaddr_t adapter_addr; @@ -202,7 +203,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer data) sk = g_io_channel_unix_get_fd(dev->io); - dev->session = bnep_new(sk, l_role, r_role); + dev->session = bnep_new(sk, l_role, r_role, BNEP_PANU_INTERFACE); if (!dev->session) goto fail; diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c index 82d0d99df..1aa078311 100644 --- a/profiles/network/bnep.c +++ b/profiles/network/bnep.c @@ -386,7 +386,8 @@ static gboolean bnep_conn_req_to(gpointer user_data) return FALSE; } -struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role) +struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role, + char *iface) { struct bnep *session; int dup_fd; @@ -399,6 +400,8 @@ struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role) session->io = g_io_channel_unix_new(dup_fd); session->src = local_role; session->dst = remote_role; + strncpy(session->iface, iface, 16); + session->iface[15] = '\0'; g_io_channel_set_close_on_unref(session->io, TRUE); session->watch = g_io_add_watch(session->io, diff --git a/profiles/network/bnep.h b/profiles/network/bnep.h index 87cdacf0e..bc43d4fa6 100644 --- a/profiles/network/bnep.h +++ b/profiles/network/bnep.h @@ -30,7 +30,8 @@ uint16_t bnep_service_id(const char *svc); const char *bnep_uuid(uint16_t id); const char *bnep_name(uint16_t id); -struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role); +struct bnep *bnep_new(int sk, uint16_t local_role, uint16_t remote_role, + char *iface); void bnep_free(struct bnep *session); typedef void (*bnep_connect_cb) (char *iface, int err, void *data); diff --git a/profiles/network/connection.c b/profiles/network/connection.c index 5f45fdb0d..cc73989ff 100644 --- a/profiles/network/connection.c +++ b/profiles/network/connection.c @@ -51,6 +51,7 @@ #include "connection.h" #define NETWORK_PEER_INTERFACE "org.bluez.Network1" +#define BNEP_INTERFACE "bnep%d" typedef enum { CONNECTED, @@ -128,7 +129,8 @@ static void bnep_disconn_cb(gpointer data) nc->state = DISCONNECTED; memset(nc->dev, 0, sizeof(nc->dev)); - strcpy(nc->dev, "bnep%d"); + strncpy(nc->dev, BNEP_INTERFACE, 16); + nc->dev[15] = '\0'; bnep_free(nc->session); nc->session = NULL; @@ -243,7 +245,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer data) } sk = g_io_channel_unix_get_fd(nc->io); - nc->session = bnep_new(sk, BNEP_SVC_PANU, nc->id); + nc->session = bnep_new(sk, BNEP_SVC_PANU, nc->id, BNEP_INTERFACE); if (!nc->session) goto failed; -- 2.47.3