summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRĂ©mi Denis-Courmont <remi.denis-courmont@nokia.com>2009-09-10 14:49:30 +0300
committerAki Niemi <aki.niemi@nokia.com>2009-09-10 15:31:21 +0300
commit54f61961b591114abed40dc3a2da19fe9e5cd616 (patch)
tree5e5f36eae678997276fd81e6cce82ed8d280ffe8
parent3feaacb6ce4ef17cda1dfedfaae2ce30d6f9cb48 (diff)
downloadofono-54f61961b591114abed40dc3a2da19fe9e5cd616.tar.bz2
gisi: bring Phonet interface up before telling upper layers about it
This should get kernel-assisted Phonet autoconfiguration to work (and it shouldn't hurt in other cases). Otherwise, the upper layers will try to send packets, which will fail. Then they will probably just time out.
-rw-r--r--gisi/netlink.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gisi/netlink.c b/gisi/netlink.c
index 8fe2de75..0d3e128b 100644
--- a/gisi/netlink.c
+++ b/gisi/netlink.c
@@ -38,6 +38,9 @@
#endif
#include "phonet.h"
#include <linux/rtnetlink.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <errno.h>
#include <glib.h>
#include "netlink.h"
@@ -53,6 +56,19 @@ static inline GIsiModem *make_modem(unsigned idx)
return (void *)(uintptr_t)idx;
}
+static int bring_up(int fd, unsigned ifindex)
+{
+ struct ifreq req = { .ifr_ifindex = ifindex, };
+
+ if (ioctl(fd, SIOCGIFINDEX, &req) ||
+ ioctl(fd, SIOCGIFFLAGS, &req))
+ return -errno;
+ req.ifr_flags |= IFF_UP | IFF_RUNNING;
+ if (ioctl(fd, SIOCSIFFLAGS, &req))
+ return -errno;
+ return 0;
+}
+
/* Parser Netlink messages */
static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond,
gpointer data)
@@ -113,6 +129,8 @@ static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond,
rta = RTA_NEXT(rta, len))
if (rta->rta_type == IFA_LOCAL)
memcpy(&addr, RTA_DATA(rta), 1);
+ if (up)
+ bring_up(fd, ifa->ifa_index);
self->callback(up, addr,
make_modem(ifa->ifa_index), self->opaque);
}