Open Source Telephony
 help / color / mirror / Atom feed
From: Sjur =?unknown-8bit?q?Br=C3=A6ndeland?= <sjurbren@gmail.com>
To: ofono@ofono.org
Subject: [PATCHv2 2/2] stemodem: Use RTNL to create network interfaces.
Date: Wed, 15 Dec 2010 22:49:28 +0100	[thread overview]
Message-ID: <1292449768-6060-3-git-send-email-sjurbren@gmail.com> (raw)
In-Reply-To: <1292449768-6060-1-git-send-email-sjurbren@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2773 bytes --]

From: Sjur Brændeland <sjur.brandeland@stericsson.com>

---
 drivers/stemodem/gprs-context.c |   43 ++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/stemodem/gprs-context.c b/drivers/stemodem/gprs-context.c
index 7bdcdb8..1762fb3 100644
--- a/drivers/stemodem/gprs-context.c
+++ b/drivers/stemodem/gprs-context.c
@@ -47,6 +47,7 @@
 #include "stemodem.h"
 #include "caif_socket.h"
 #include "if_caif.h"
+#include "caif_rtnl.h"
 
 #define MAX_CAIF_DEVICES 4
 #define MAX_DNS 2
@@ -172,12 +173,20 @@ static struct conn_info *conn_info_create(unsigned int channel_id)
 	return connection;
 }
 
-/*
- * Creates a new IP interface for CAIF.
- */
-static gboolean caif_if_create(struct conn_info *conn)
+static void rtnl_callback(int ifindex, const char *ifname, void *user_data)
 {
-	return FALSE;
+	struct conn_info *conn = user_data;
+
+	if (ifindex < 0) {
+		conn->created = FALSE;
+		ofono_error("Failed to create caif interface %s",
+			conn->interface);
+		return;
+	}
+
+	strncpy(conn->interface, ifname, sizeof(conn->interface));
+	conn->ifindex = ifindex;
+	conn->created = TRUE;
 }
 
 /*
@@ -185,6 +194,17 @@ static gboolean caif_if_create(struct conn_info *conn)
  */
 static void caif_if_remove(struct conn_info *conn)
 {
+	if (!conn->created)
+		return;
+
+	if (caif_rtnl_delete_interface(conn->ifindex) < 0) {
+		ofono_error("Failed to delete caif interface %s",
+			conn->interface);
+		return;
+	}
+
+	DBG("removed CAIF interface ch:%d ifname:%s ifindex:%d\n",
+		conn->channel_id, conn->interface, conn->ifindex);
 }
 
 static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
@@ -526,7 +546,7 @@ static int ste_gprs_context_probe(struct ofono_gprs_context *gc,
 	GAtChat *chat = data;
 	struct gprs_context_data *gcd;
 	struct conn_info *ci;
-	int i;
+	int i, err;
 
 	gcd = g_new0(struct gprs_context_data, 1);
 	gcd->chat = g_at_chat_clone(chat);
@@ -539,7 +559,14 @@ static int ste_gprs_context_probe(struct ofono_gprs_context *gc,
 		ci = conn_info_create(i+1);
 		if (!ci)
 			return -ENOMEM;
-		caif_if_create(ci);
+		err = caif_rtnl_create_interface(IFLA_CAIF_IPV4_CONNID,
+						ci->channel_id, FALSE,
+						rtnl_callback, ci);
+		if (err < 0) {
+			DBG("Failed to create IP interface for CAIF");
+			return err;
+		}
+
 		g_caif_devices = g_slist_append(g_caif_devices, ci);
 	}
 
@@ -571,10 +598,12 @@ static struct ofono_gprs_context_driver driver = {
 
 void ste_gprs_context_init()
 {
+	caif_rtnl_init();
 	ofono_gprs_context_driver_register(&driver);
 }
 
 void ste_gprs_context_exit()
 {
 	ofono_gprs_context_driver_unregister(&driver);
+	caif_rtnl_exit();
 }
-- 
1.7.0.4


  parent reply	other threads:[~2010-12-15 21:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-15 21:49 [PATCHv2] plugin: Add ste modem initd integration Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-12-15 21:49 ` [PATCHv2 1/2] stemodem: Create network interfaces statically Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-12-21 14:38   ` Marcel Holtmann
2010-12-15 21:49 ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?= [this message]
2010-12-21 14:38   ` [PATCHv2 2/2] stemodem: Use RTNL to create network interfaces Marcel Holtmann
2010-12-21 14:36 ` [PATCHv2] plugin: Add ste modem initd integration Marcel Holtmann
2010-12-21 15:06   ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-12-21 15:18     ` Marcel Holtmann
2010-12-21 15:37       ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-12-23  2:48         ` Marcel Holtmann
2011-01-03 21:42           ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-03 21:55             ` Marcel Holtmann
2011-01-03 22:30               ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-03 22:54                 ` Marcel Holtmann
2011-01-03 23:12                   ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-04  9:49                     ` Marcel Holtmann
2011-01-04 19:07                       ` [PATCHv4 0/1] STE Modem Init Daemon integration Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-04 19:07                       ` [PATCHv4 1/1] plugin: Add ste modem initd integration Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-05 22:06                         ` Marcel Holtmann
2011-01-06  9:38                           ` [PATCHv5] " Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11  0:58                             ` Marcel Holtmann
2011-01-11 17:06                               ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11 21:52                                 ` Marcel Holtmann
2011-01-11 21:56                                   ` Denis Kenzior
2011-01-11 22:05                                     ` Marcel Holtmann
2011-01-11 22:39                                     ` [PATCH] coding-style: Use void if function has no parameters Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11 22:48                                       ` Marcel Holtmann
2011-01-11 22:24                                   ` [PATCHv6] plugin: Add ste modem initd integration Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11 22:35                                     ` Marcel Holtmann
2011-01-11 22:41                                       ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11 22:56                                         ` [PATCHv7] " Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-11 22:58                                           ` Marcel Holtmann
2010-12-21 22:54   ` [PATCHv3] " Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1292449768-6060-3-git-send-email-sjurbren@gmail.com \
    --to=sjurbren@gmail.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox