summaryrefslogtreecommitdiff
path: root/gisi
diff options
context:
space:
mode:
authorRĂ©mi Denis-Courmont <remi.denis-courmont@nokia.com>2009-08-19 15:55:47 +0300
committerAki Niemi <aki.niemi@nokia.com>2009-08-19 17:07:15 +0300
commitb2ee53a99f897f51ae6cbb63dff78ac381bd7ec8 (patch)
tree68c9d0addbfa20ccd2b5a256271d5b0ff1102ab6 /gisi
parent21588cc5f870fc94697de8d48b0670543b76b440 (diff)
downloadofono-b2ee53a99f897f51ae6cbb63dff78ac381bd7ec8.tar.gz
gisi: low-level modem scoping for sockets
Diffstat (limited to 'gisi')
-rw-r--r--gisi/Makefile.am4
-rw-r--r--gisi/client.c4
-rw-r--r--gisi/modem.h28
-rw-r--r--gisi/socket.c19
-rw-r--r--gisi/socket.h4
5 files changed, 49 insertions, 10 deletions
diff --git a/gisi/Makefile.am b/gisi/Makefile.am
index 328f07c7..9987f318 100644
--- a/gisi/Makefile.am
+++ b/gisi/Makefile.am
@@ -1,10 +1,10 @@
-AM_CFLAGS = @GLIB_CFLAGS@
+AM_CFLAGS = @GLIB_CFLAGS@ -I$(top_srcdir)
noinst_LTLIBRARIES = libgisi.la
MAINTAINERCLEANFILES = Makefile.in
libgisi_la_SOURCES = \
- phonet.h \
+ phonet.h isicommon.h \
netlink.h netlink.c \
socket.h socket.c \
client.h client.c \
diff --git a/gisi/client.c b/gisi/client.c
index b12dc852..3b86577b 100644
--- a/gisi/client.c
+++ b/gisi/client.c
@@ -112,7 +112,7 @@ GIsiClient *g_isi_client_create(uint8_t resource)
cl->next[254] = 0;
cl->prev[255] = cl->next[255] = 255;
- channel = phonet_new(resource);
+ channel = phonet_new(NULL, resource);
if (channel == NULL) {
free(cl);
return NULL;
@@ -264,7 +264,7 @@ static int g_isi_indication_init(GIsiClient *cl)
uint8_t msg[] = {
0, PNS_SUBSCRIBED_RESOURCES_IND, 1, cl->resource,
};
- GIOChannel *channel = phonet_new(PN_COMMGR);
+ GIOChannel *channel = phonet_new(NULL, PN_COMMGR);
if (channel == NULL)
return errno;
diff --git a/gisi/modem.h b/gisi/modem.h
new file mode 100644
index 00000000..086fb265
--- /dev/null
+++ b/gisi/modem.h
@@ -0,0 +1,28 @@
+/**
+ * Copyright (C) 2009 Nokia Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef GISI_MODEM_H
+#define GISI_MODEM_H
+
+typedef struct _GIsiModem GIsiModem;
+
+static inline unsigned g_isi_modem_index(GIsiModem *m)
+{
+ return (uintptr_t)m;
+}
+
+#endif
diff --git a/gisi/socket.c b/gisi/socket.c
index efa4c889..bca89853 100644
--- a/gisi/socket.c
+++ b/gisi/socket.c
@@ -30,35 +30,44 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <net/if.h>
#include <fcntl.h>
+#include "modem.h"
#include "phonet.h"
#include <glib.h>
#include "socket.h"
-GIOChannel *phonet_new(uint8_t resource)
+GIOChannel *phonet_new(GIsiModem *modem, uint8_t resource)
{
GIOChannel *channel;
struct sockaddr_pn addr = {
.spn_family = AF_PHONET,
.spn_resource = resource,
};
+ unsigned ifi = g_isi_modem_index(modem);
+ char buf[IF_NAMESIZE];
int fd = socket(PF_PHONET, SOCK_DGRAM, 0);
if (fd == -1)
return NULL;
fcntl(fd, F_SETFD, FD_CLOEXEC);
/* Use blocking mode on purpose. */
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) {
- close(fd);
- return NULL;
- }
+
+ if (if_indextoname(ifi, buf) == NULL ||
+ setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, buf, IF_NAMESIZE))
+ goto error;
+ if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)))
+ goto error;
channel = g_io_channel_unix_new(fd);
g_io_channel_set_close_on_unref(channel, TRUE);
g_io_channel_set_encoding(channel, NULL, NULL);
g_io_channel_set_buffered(channel, FALSE);
return channel;
+error:
+ close(fd);
+ return NULL;
}
size_t phonet_peek_length(GIOChannel *channel)
diff --git a/gisi/socket.h b/gisi/socket.h
index b95a4d78..c969a18f 100644
--- a/gisi/socket.h
+++ b/gisi/socket.h
@@ -21,7 +21,9 @@
*
*/
-GIOChannel *phonet_new(uint8_t resource);
+#include "modem.h"
+
+GIOChannel *phonet_new(GIsiModem *, uint8_t resource);
size_t phonet_peek_length(GIOChannel *io);
ssize_t phonet_read(GIOChannel *io, void *restrict buf, size_t len,
uint16_t *restrict obj, uint8_t *restrict res);