summaryrefslogtreecommitdiffstats
path: root/gisi/pep.c
diff options
context:
space:
mode:
authorRĂ©mi Denis-Courmont <remi.denis-courmont@nokia.com>2009-08-28 14:53:56 +0300
committerAki Niemi <aki.niemi@nokia.com>2009-08-28 15:20:27 +0300
commitaef72327c2ba673c5fd51c616b78fde407c3e662 (patch)
tree7618ace4cd52918e3860cf6322335010e34f35e4 /gisi/pep.c
parent373665cdd04add7d4e78ef3463782362ea449ab9 (diff)
downloadofono-aef72327c2ba673c5fd51c616b78fde407c3e662.tar.bz2
gisi: return GPRS interface index/name
Diffstat (limited to 'gisi/pep.c')
-rw-r--r--gisi/pep.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/gisi/pep.c b/gisi/pep.c
index 04d3e637..860688b9 100644
--- a/gisi/pep.c
+++ b/gisi/pep.c
@@ -37,6 +37,8 @@
#include "pep.h"
struct _GIsiPEP {
+ GIsiPEPCallback ready;
+ void *opaque;
int gprs_fd;
guint source;
uint16_t handle;
@@ -50,8 +52,6 @@ static gboolean g_isi_pep_callback(GIOChannel *channel, GIOCondition cond,
GIsiPEP *pep = data;
int fd = g_io_channel_unix_get_fd(channel);
int encap = PNPIPE_ENCAP_IP;
- unsigned ifi;
- socklen_t len = sizeof(ifi);
if (cond & (G_IO_HUP|G_IO_NVAL))
return FALSE;
@@ -61,16 +61,16 @@ static gboolean g_isi_pep_callback(GIOChannel *channel, GIOCondition cond,
return TRUE;
fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (setsockopt(fd, SOL_PNPIPE, PNPIPE_ENCAP, &encap, sizeof(encap))
- || getsockopt(fd, SOL_PNPIPE, PNPIPE_IFINDEX, &ifi, &len)) {
+ if (setsockopt(fd, SOL_PNPIPE, PNPIPE_ENCAP, &encap, sizeof(encap))) {
close(fd);
return TRUE;
}
pep->gprs_fd = fd;
+ pep->ready(pep, pep->opaque);
return FALSE;
}
-GIsiPEP *g_isi_pep_create(GIsiModem *modem)
+GIsiPEP *g_isi_pep_create(GIsiModem *modem, GIsiPEPCallback cb, void *opaque)
{
GIsiPEP *pep = g_malloc(sizeof(*pep));
GIOChannel *channel;
@@ -89,6 +89,8 @@ GIsiPEP *g_isi_pep_create(GIsiModem *modem)
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, buf, IF_NAMESIZE))
goto error;
+ pep->ready = cb;
+ pep->opaque = opaque;
pep->gprs_fd = -1;
pep->handle = 0;
if (listen(fd, 1) || ioctl(fd, SIOCPNGETOBJECT, &pep->handle))
@@ -122,3 +124,20 @@ void g_isi_pep_destroy(GIsiPEP *pep)
g_source_remove(pep->source);
g_free(pep);
}
+
+unsigned g_isi_pep_get_ifindex(const GIsiPEP *pep)
+{
+ unsigned ifi;
+ socklen_t len = sizeof (ifi);
+
+ g_assert (pep->gprs_fd != -1);
+
+ getsockopt(pep->gprs_fd, SOL_PNPIPE, PNPIPE_IFINDEX, &ifi, &len);
+ return ifi;
+}
+
+char *g_isi_pep_get_ifname(const GIsiPEP *pep, char *ifname)
+{
+ unsigned ifi = g_isi_pep_get_ifindex(pep);
+ return if_indextoname(ifi, ifname);
+}