diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 08037e6..edf258b 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
uint16_t src;
} __attribute__ ((packed));
-struct bnep_conn {
+struct bnep {
GIOChannel *io;
uint16_t src;
uint16_t dst;
bnep_connect_cb conn_cb;
};
-static void free_bnep_connect(struct bnep_conn *bc)
+static void free_bnep_connect(struct bnep *session)
{
- if (!bc)
+ if (!session)
return;
- if (bc->io) {
- g_io_channel_unref(bc->io);
- bc->io = NULL;
+ if (session->io) {
+ g_io_channel_unref(session->io);
+ session->io = NULL;
}
- g_free(bc);
+ g_free(session);
}
uint16_t bnep_service_id(const char *svc)
static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
- struct bnep_conn *bc = data;
+ struct bnep *session = data;
struct bnep_control_rsp *rsp;
struct timeval timeo;
char pkt[BNEP_MTU];
if (cond & G_IO_NVAL)
goto failed;
- if (bc->setup_to > 0) {
- g_source_remove(bc->setup_to);
- bc->setup_to = 0;
+ if (session->setup_to > 0) {
+ g_source_remove(session->setup_to);
+ session->setup_to = 0;
}
if (cond & (G_IO_HUP | G_IO_ERR)) {
timeo.tv_sec = 0;
setsockopt(sk, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
- sk = g_io_channel_unix_get_fd(bc->io);
- if (bnep_connadd(sk, bc->src, iface)) {
+ sk = g_io_channel_unix_get_fd(session->io);
+ if (bnep_connadd(sk, session->src, iface)) {
error("bnep conn could not be added");
goto failed;
}
goto failed;
}
- bc->conn_cb(chan, iface, 0, bc->data);
- free_bnep_connect(bc);
+ session->conn_cb(chan, iface, 0, session->data);
+ free_bnep_connect(session);
return FALSE;
failed:
- bc->conn_cb(NULL, NULL, -EIO, bc->data);
- free_bnep_connect(bc);
+ session->conn_cb(NULL, NULL, -EIO, session->data);
+ free_bnep_connect(session);
return FALSE;
}
-static int bnep_setup_conn_req(struct bnep_conn *bc)
+static int bnep_setup_conn_req(struct bnep *session)
{
struct bnep_setup_conn_req *req;
struct __service_16 *s;
req->ctrl = BNEP_SETUP_CONN_REQ;
req->uuid_size = 2; /* 16bit UUID */
s = (void *) req->service;
- s->src = htons(bc->src);
- s->dst = htons(bc->dst);
+ s->src = htons(session->src);
+ s->dst = htons(session->dst);
- fd = g_io_channel_unix_get_fd(bc->io);
+ fd = g_io_channel_unix_get_fd(session->io);
if (write(fd, pkt, sizeof(*req) + sizeof(*s)) < 0) {
error("bnep connection req send failed: %s", strerror(errno));
return -errno;
}
- bc->attempts++;
+ session->attempts++;
return 0;
}
static gboolean bnep_conn_req_to(gpointer user_data)
{
- struct bnep_conn *bc = user_data;
+ struct bnep *session = user_data;
- if (bc->attempts == CON_SETUP_RETRIES) {
+ if (session->attempts == CON_SETUP_RETRIES) {
error("Too many bnep connection attempts");
} else {
error("bnep connection setup TO, retrying...");
- if (bnep_setup_conn_req(bc) == 0)
+ if (bnep_setup_conn_req(session) == 0)
return TRUE;
}
- bc->conn_cb(NULL, NULL, -ETIMEDOUT, bc->data);
- free_bnep_connect(bc);
+ session->conn_cb(NULL, NULL, -ETIMEDOUT, session->data);
+ free_bnep_connect(session);
return FALSE;
}
int bnep_connect(int sk, uint16_t src, uint16_t dst, bnep_connect_cb conn_cb,
void *data)
{
- struct bnep_conn *bc;
+ struct bnep *session;
int err;
if (!conn_cb)
return -EINVAL;
- bc = g_new0(struct bnep_conn, 1);
- bc->io = g_io_channel_unix_new(sk);
- bc->attempts = 0;
- bc->src = src;
- bc->dst = dst;
- bc->conn_cb = conn_cb;
- bc->data = data;
+ session = g_new0(struct bnep, 1);
+ session->io = g_io_channel_unix_new(sk);
+ session->attempts = 0;
+ session->src = src;
+ session->dst = dst;
+ session->conn_cb = conn_cb;
+ session->data = data;
- err = bnep_setup_conn_req(bc);
+ err = bnep_setup_conn_req(session);
if (err < 0)
return err;
- bc->setup_to = g_timeout_add_seconds(CON_SETUP_TO,
- bnep_conn_req_to, bc);
- g_io_add_watch(bc->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
- bnep_setup_cb, bc);
+ session->setup_to = g_timeout_add_seconds(CON_SETUP_TO,
+ bnep_conn_req_to, session);
+ g_io_add_watch(session->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ bnep_setup_cb, session);
return 0;
}