[PATCH 3/4] phonesim: Add Timer Management commands to sim app menu.

2010-11-21 Thread Andrzej Zaborowski
---
 src/qsimcommand.cpp  |   83 
 src/qsimcommand.h|3 +
 src/qsimterminalresponse.cpp |   59 ++
 src/qsimterminalresponse.h   |3 +
 src/simapplication.cpp   |  171 ++
 src/simapplication.h |6 ++
 6 files changed, 325 insertions(+), 0 deletions(-)

diff --git a/src/qsimcommand.cpp b/src/qsimcommand.cpp
index 44bdd9a..9d9e689 100644
--- a/src/qsimcommand.cpp
+++ b/src/qsimcommand.cpp
@@ -66,6 +66,7 @@ public:
 defaultItem = 0;
 iconId = 0;
 otherIconId = 0;
+timerId = 0;
 device = -1;
 qualifier = 0;
 }
@@ -97,6 +98,7 @@ public:
 language = other->language;
 iconId = other->iconId;
 otherIconId = other->otherIconId;
+timerId = other->timerId;
 device = other->device;
 qualifier = other->qualifier;
 extensionData = other->extensionData;
@@ -159,6 +161,7 @@ public:
 QString language;
 uint iconId;
 uint otherIconId;
+uint timerId;
 int device;
 int qualifier;
 QByteArray extensionData;
@@ -2173,6 +2176,33 @@ void QSimCommand::setSmsPacking( bool value )
 }
 
 /*!
+Returns the number of the timer to which a Timer Management command is
+addressed.
+
+Applies to: \c TimerManagement
+
+\sa setTimerId()
+*/
+int QSimCommand::timerId() const
+{
+return d->timerId;
+}
+
+/*!
+Sets the identifier of the timer to which the Timer Management command
+is being sent.  \a id should be between 1 and 8 to address one of the
+eight timers available.
+
+Applies to: \c TimerManagement
+
+\sa timerId()
+*/
+void QSimCommand::setTimerId( int id )
+{
+dwrite()->timerId = id;
+}
+
+/*!
 Copy the QSimCommand object \a value.
 */
 QSimCommand& QSimCommand::operator=( const QSimCommand & value )
@@ -2669,6 +2699,27 @@ QSimCommand QSimCommand::fromPdu( const QByteArray& pdu )
 }
 break;
 
+case 0x24:
+{
+// Timer identifier.
+sc.setTimerId( pdu[posn] );
+}
+break;
+
+case 0x25:
+{
+// Timer value.
+int secs = 0;
+secs += ((uint8_t) pdu[posn + 0] >> 4) * 3600;
+secs += ((uint8_t) pdu[posn + 0] & 15) * 36000;
+secs += ((uint8_t) pdu[posn + 1] >> 4) * 60;
+secs += ((uint8_t) pdu[posn + 1] & 15) * 600;
+secs += ((uint8_t) pdu[posn + 2] >> 4) * 1;
+secs += ((uint8_t) pdu[posn + 2] & 15) * 10;
+sc.setDuration( secs * 1000 );
+}
+break;
+
 case 0x2B:
 {
 // Immediate response block.
@@ -2963,6 +3014,31 @@ static void writeTextAttribute( QByteArray& data, const 
QByteArray& attr )
 }
 }
 
+// Write a Timer Id field.
+void _qtopiaphone_writeTimerId( QByteArray& data, uint timerId )
+{
+data += 0xa4;
+data += 0x01;
+data += (char) timerId;
+}
+#define writeTimerId _qtopiaphone_writeTimerId
+
+// Write a Timer Value field.
+void _qtopiaphone_writeTimerValue( QByteArray& data, uint value )
+{
+if (!value)
+return;
+
+data += 0xa5;
+data += 0x03;
+#define TO_BCD(bin) (char) bin) / 10) & 0xf) | (((bin) % 10) << 4))
+data += TO_BCD(value / 3600);
+data += TO_BCD((value / 60) % 60);
+data += TO_BCD(value % 60);
+#undef TO_BCD
+}
+#define writeTimerValue _qtopiaphone_writeTimerValue
+
 /*!
 \enum QSimCommand::ToPduOptions
 This enum defines additional options to use when encoding SIM commands 
with QSimCommand::toPdu().
@@ -3189,6 +3265,13 @@ QByteArray QSimCommand::toPdu( QSimCommand::ToPduOptions 
options ) const
 }
 break;
 
+case TimerManagement:
+{
+writeTimerId( data, timerId() );
+writeTimerValue( data, duration() / 1000 );
+}
+break;
+
 case SetupIdleModeText:
 {
 writeTextString( data, text(), options );
diff --git a/src/qsimcommand.h b/src/qsimcommand.h
index d2183b1..eadd768 100644
--- a/src/qsimcommand.h
+++ b/src/qsimcommand.h
@@ -356,6 +356,9 @@ public:
 bool smsPacking() const;
 void setSmsPacking( bool value );
 
+int timerId() const;
+void setTimerId( int id );
+
 int qualifier() const;
 void setQualifier( int value );
 
diff --git a/src/qsimterminalresponse.cpp b/src/qsimterminalresponse.cpp
index db156aa..3e11915 100644
--- a/src/qsimterminalresponse.cpp
+++ b/src/qsimterminalresponse.cpp
@@ -142,6 +142,7 @@ public:
 duration = other->duration;
 menuItem = other->menuItem;
 dataCodingScheme = other->dataCodingScheme;
+timerId = other->timerId;
 extensionData = other->extensionData;
 }
 
@@ -155,6 +156,7 @@ public:
 uint duration;
 uint menuItem;
 int dataCodingScheme;
+u

[PATCH 4/4] phonesim: Add SIM Refresh commands to sim app menu.

2010-11-21 Thread Andrzej Zaborowski
---
 src/simapplication.cpp |  104 
 src/simapplication.h   |2 +
 2 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/src/simapplication.cpp b/src/simapplication.cpp
index d9e3b77..5f99490 100644
--- a/src/simapplication.cpp
+++ b/src/simapplication.cpp
@@ -289,6 +289,7 @@ const QString DemoSimApplication::getName()
 #define MainMenu_SendSMS14
 #define MainMenu_Polling15
 #define MainMenu_Timers 16
+#define MainMenu_Refresh17
 
 #define SportsMenu_Chess1
 #define SportsMenu_Painting 2
@@ -438,6 +439,10 @@ void DemoSimApplication::mainMenu()
 item.setLabel( "Timers" );
 items += item;
 
+item.setIdentifier( MainMenu_Refresh );
+item.setLabel( "SIM Refresh" );
+items += item;
+
 cmd.setMenuItems( items );
 
 command( cmd, 0, 0 );
@@ -568,6 +573,12 @@ void DemoSimApplication::mainMenuSelection( int id )
 }
 break;
 
+case MainMenu_Refresh:
+{
+sendRefreshMenu();
+}
+break;
+
 default:
 {
 // Don't know what this item is, so just re-display the main menu.
@@ -2215,3 +2226,96 @@ bool DemoSimApplication::envelope( const QSimEnvelope& 
env )
 
 return true;
 }
+
+void DemoSimApplication::sendRefreshMenu()
+{
+QSimCommand cmd;
+QSimMenuItem item;
+QList items;
+
+cmd.setType( QSimCommand::SelectItem );
+cmd.setTitle( "SIM Refresh menu" );
+
+/* Use qualifier value + 1 for id */
+item.setIdentifier( 1 );
+item.setLabel( "NAA Initialization+Full File Change Notification" );
+items += item;
+
+item.setIdentifier( 2 );
+item.setLabel( "File Change Notification (EFmsisdn,EFecc,EFfdn)" );
+items += item;
+
+item.setIdentifier( 3 );
+item.setLabel( "NAA Initialization+File Change Notification" );
+items += item;
+
+item.setIdentifier( 4 );
+item.setLabel( "NAA Initialization" );
+items += item;
+
+item.setIdentifier( 5 );
+item.setLabel( "UICC Reset" );
+items += item;
+
+item.setIdentifier( 6 );
+item.setLabel( "NAA Application Reset" );
+items += item;
+
+item.setIdentifier( 7 );
+item.setLabel( "NAA Session Reset" );
+items += item;
+
+cmd.setMenuItems( items );
+
+command( cmd, this, SLOT(refreshMenuResp(QSimTerminalResponse)) );
+}
+
+void DemoSimApplication::refreshMenuResp( const QSimTerminalResponse& resp )
+{
+QSimCommand cmd;
+
+if ( resp.result() != QSimTerminalResponse::Success ) {
+/* Unknown response - just go back to the main menu. */
+endSession();
+
+return;
+}
+
+/* Item selected. */
+
+cmd.setType( QSimCommand::Refresh );
+cmd.setQualifier( resp.menuItem() - 1 );
+cmd.setDestinationDevice( QSimCommand::ME );
+cmd.setText( "" );
+
+if ( cmd.refreshType() == QSimCommand::FileChange ||
+cmd.refreshType() == QSimCommand::InitAndFileChange ||
+cmd.refreshType() == QSimCommand::NaaSessionReset ) {
+QByteArray files;
+files += (char) 0x03;
+/* EFmsisdn */
+files += (char) 0x3f;
+files += (char) 0x00;
+files += (char) 0x7f;
+files += (char) 0xff;
+files += (char) 0x6f;
+files += (char) 0x40;
+/* EFecc */
+files += (char) 0x3f;
+files += (char) 0x00;
+files += (char) 0x7f;
+files += (char) 0xff;
+files += (char) 0x6f;
+files += (char) 0xb7;
+/* EFfdn */
+files += (char) 0x3f;
+files += (char) 0x00;
+files += (char) 0x7f;
+files += (char) 0xff;
+files += (char) 0x6f;
+files += (char) 0x3b;
+cmd.addExtensionField( 0x92, files );
+}
+
+command( cmd, this, SLOT(endSession()) );
+}
diff --git a/src/simapplication.h b/src/simapplication.h
index dbf061d..076a668 100644
--- a/src/simapplication.h
+++ b/src/simapplication.h
@@ -124,6 +124,8 @@ protected slots:
 void sendTimersMenu();
 void timersMenuResp( const QSimTerminalResponse& resp );
 void timersCmdResp( const QSimTerminalResponse& resp );
+void sendRefreshMenu();
+void refreshMenuResp( const QSimTerminalResponse& resp );
 
 private:
 int sticksLeft;
-- 
1.7.1.86.g0e460.dirty

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/4] phonesim: Add SIM Polling commands to sim app menu.

2010-11-21 Thread Andrzej Zaborowski
---
 src/simapplication.cpp |   66 
 src/simapplication.h   |2 +
 3 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/src/simapplication.cpp b/src/simapplication.cpp
index 9742fd9..290ec2a 100644
--- a/src/simapplication.cpp
+++ b/src/simapplication.cpp
@@ -287,6 +287,7 @@ const QString DemoSimApplication::getName()
 #define MainMenu_Language   12
 #define MainMenu_SendUSSD   13
 #define MainMenu_SendSMS14
+#define MainMenu_Polling15
 
 #define SportsMenu_Chess1
 #define SportsMenu_Painting 2
@@ -352,6 +353,11 @@ enum SendSMSMenuItems {
SendSMS_SetContents,
 };
 
+enum PollingMenuItems {
+   Polling_Off = 1,
+   Polling_30s,
+};
+
 void DemoSimApplication::mainMenu()
 {
 QSimCommand cmd;
@@ -416,6 +422,10 @@ void DemoSimApplication::mainMenu()
 item.setLabel( "Send SMS request" );
 items += item;
 
+item.setIdentifier( MainMenu_Polling );
+item.setLabel( "SIM Polling" );
+items += item;
+
 cmd.setMenuItems( items );
 
 command( cmd, 0, 0 );
@@ -534,6 +544,12 @@ void DemoSimApplication::mainMenuSelection( int id )
 }
 break;
 
+case MainMenu_Polling:
+{
+sendPollingMenu();
+}
+break;
+
 default:
 {
 // Don't know what this item is, so just re-display the main menu.
@@ -1978,3 +1994,53 @@ void DemoSimApplication::sendSMSSetTextResp( const 
QSimTerminalResponse& resp )
 smsText = resp.text();
 sendSMSMenu();
 }
+
+void DemoSimApplication::sendPollingMenu()
+{
+QSimCommand cmd;
+QSimMenuItem item;
+QList items;
+
+cmd.setType( QSimCommand::SelectItem );
+cmd.setTitle( "Polling Menu" );
+
+item.setIdentifier( Polling_Off );
+item.setLabel( "Polling Off" );
+items += item;
+
+item.setIdentifier( Polling_30s );
+item.setLabel( "Poll Interval of 30s" );
+items += item;
+
+cmd.setMenuItems( items );
+
+command( cmd, this, SLOT(pollingMenuResp(QSimTerminalResponse)) );
+}
+
+void DemoSimApplication::pollingMenuResp( const QSimTerminalResponse& resp )
+{
+QSimCommand cmd;
+
+if ( resp.result() != QSimTerminalResponse::Success ) {
+/* Unknown response - just go back to the main menu. */
+endSession();
+
+return;
+}
+
+/* Item selected. */
+switch ( resp.menuItem() ) {
+case Polling_Off:
+cmd.setType( QSimCommand::PollingOff );
+cmd.setDestinationDevice( QSimCommand::ME );
+command( cmd, this, SLOT(endSession()) );
+break;
+
+case Polling_30s:
+cmd.setType( QSimCommand::PollInterval );
+cmd.setDuration( 3 );
+cmd.setDestinationDevice( QSimCommand::ME );
+command( cmd, this, SLOT(endSession()) );
+break;
+}
+}
diff --git a/src/simapplication.h b/src/simapplication.h
index 326c4dc..1d6293f 100644
--- a/src/simapplication.h
+++ b/src/simapplication.h
@@ -117,6 +117,8 @@ protected slots:
 void smsMenuResp( const QSimTerminalResponse& resp );
 void smsSetDestResp( const QSimTerminalResponse& resp );
 void smsSetTextResp( const QSimTerminalResponse& resp );
+void sendPollingMenu();
+void pollingMenuResp( const QSimTerminalResponse& resp );
 
 private:
 int sticksLeft;
-- 
1.7.1.86.g0e460.dirty

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/4] phonesim: Add Send Short Message commands to sim app menu.

2010-11-21 Thread Andrzej Zaborowski
---
 src/simapplication.cpp |  148 +++-
 src/simapplication.h   |5 ++
 2 files changed, 152 insertions(+), 1 deletions(-)

diff --git a/src/simapplication.cpp b/src/simapplication.cpp
index 7dc580f..9742fd9 100644
--- a/src/simapplication.cpp
+++ b/src/simapplication.cpp
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include "qsmsmessage.h"
 
 class SimApplicationPrivate
 {
@@ -258,7 +259,8 @@ void SimApplication::endSession()
 }
 
 DemoSimApplication::DemoSimApplication( SimRules *rules, QObject *parent )
-: SimApplication( rules, parent )
+: SimApplication( rules, parent ), smsDestNumber( "12345" ),
+smsText( "Hello" )
 {
 }
 
@@ -284,6 +286,7 @@ const QString DemoSimApplication::getName()
 #define MainMenu_SendSS 11
 #define MainMenu_Language   12
 #define MainMenu_SendUSSD   13
+#define MainMenu_SendSMS14
 
 #define SportsMenu_Chess1
 #define SportsMenu_Painting 2
@@ -342,6 +345,13 @@ const QString DemoSimApplication::getName()
 #define SendUSSD_Error  4
 #define SendUSSD_Main   5
 
+enum SendSMSMenuItems {
+   SendSMS_Unpacked = 1,
+   SendSMS_Packed,
+   SendSMS_SetDestination,
+   SendSMS_SetContents,
+};
+
 void DemoSimApplication::mainMenu()
 {
 QSimCommand cmd;
@@ -402,6 +412,10 @@ void DemoSimApplication::mainMenu()
 item.setLabel( "Send USSD" );
 items += item;
 
+item.setIdentifier( MainMenu_SendSMS );
+item.setLabel( "Send SMS request" );
+items += item;
+
 cmd.setMenuItems( items );
 
 command( cmd, 0, 0 );
@@ -514,6 +528,12 @@ void DemoSimApplication::mainMenuSelection( int id )
 }
 break;
 
+case MainMenu_SendSMS:
+{
+sendSMSMenu();
+}
+break;
+
 default:
 {
 // Don't know what this item is, so just re-display the main menu.
@@ -1832,3 +1852,129 @@ void DemoSimApplication::USSDMenu( const 
QSimTerminalResponse& resp )
 endSession();
 }
 }
+
+void DemoSimApplication::sendSMSMenu()
+{
+QSimCommand cmd;
+QSimMenuItem item;
+QList items;
+
+cmd.setType( QSimCommand::SelectItem );
+cmd.setTitle( "Send SMS" );
+
+item.setIdentifier( SendSMS_Unpacked );
+item.setLabel( "Unpacked" );
+items += item;
+
+item.setIdentifier( SendSMS_Packed );
+item.setLabel( "Packed text" );
+items += item;
+
+item.setIdentifier( SendSMS_SetDestination );
+item.setLabel( "Set destination (" + smsDestNumber + ")" );
+items += item;
+
+item.setIdentifier( SendSMS_SetContents );
+item.setLabel( "Set content text" );
+items += item;
+
+cmd.setMenuItems( items );
+
+command( cmd, this, SLOT(smsMenuResp(QSimTerminalResponse)) );
+}
+
+void DemoSimApplication::smsMenuResp( const QSimTerminalResponse& resp )
+{
+QSimCommand cmd;
+
+if ( resp.result() != QSimTerminalResponse::Success ) {
+/* Unknown response - just go back to the main menu. */
+endSession();
+
+return;
+}
+
+/* Item selected. */
+switch ( resp.menuItem() ) {
+case SendSMS_Unpacked:
+break;
+
+case SendSMS_Packed:
+cmd.setSmsPacking( true );
+break;
+
+case SendSMS_SetDestination:
+cmd.setType( QSimCommand::GetInput );
+cmd.setText( "Enter recipient number" );
+cmd.setWantDigits( true );
+cmd.setMinimumLength( 2 );
+cmd.setMaximumLength( 20 );
+cmd.setDefaultText( smsDestNumber );
+command( cmd, this, SLOT(smsSetDestResp(QSimTerminalResponse)) );
+return;
+
+case SendSMS_SetContents:
+cmd.setType( QSimCommand::GetInput );
+cmd.setText( "Enter message text" );
+cmd.setMaximumLength( 100 );
+cmd.setDefaultText( smsText );
+command( cmd, this, SLOT(smsSetTextResp(QSimTerminalResponse)) );
+return;
+}
+
+QSMSMessage sms;
+sms.setValidityPeriod( -1 );
+sms.setMessageClass( 2 );
+sms.setProtocol( 0 );
+sms.setRecipient( smsDestNumber );
+sms.setText( smsText );
+sms.setForceGsm( false );
+sms.setBestScheme( QSMS_8BitAlphabet );
+sms.setDataCodingScheme( 0xf6 );
+
+cmd.setType( QSimCommand::SendSMS );
+cmd.setText( "Sending an SMS to our friends at " + smsDestNumber );
+cmd.setNumber( "123" );
+cmd.addExtensionField( 0x8b, sms.toPdu().mid( 1 ) );
+cmd.setDestinationDevice( QSimCommand::Network );
+
+command( cmd, this, SLOT(endSession()) );
+}
+
+void DemoSimApplication::smsSetDestResp( const QSimTerminalResponse& resp )
+{
+if ( resp.result() == QSimTerminalResponse::BackwardMove ) {
+sendSMSMenu();
+
+return;
+}
+
+if ( resp.result() != QSimTerminalResponse::Success ) {
+/* Unknown response - just go back to the main menu. */
+endSession();
+
+return;
+}
+
+smsDestNumber = resp.text();
+sendSMSMenu();
+}
+
+void DemoSimApplication::sms

[PATCHv3 2/2] stemodem: Use RTNL to create network interfaces.

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

---
Changes from V2:
o Squashed functions caif_if_create info ste_gprs_context_probe

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

diff --git a/drivers/stemodem/gprs-context.c b/drivers/stemodem/gprs-context.c
index 3ccda87..f118453 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,18 @@ 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);
+   return;
 }
 
 static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
@@ -526,7 +547,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 +560,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 +599,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()
 {
+   caif_rtnl_exit();
ofono_gprs_context_driver_unregister(&driver);
 }
-- 
1.7.0.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCHv3 1/2] stemodem: Create network interfaces statically

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

Changes:
o Restructure code so interfaces are created statically when probe is called.
o Removed some of the unnecessary initializations at declaration.
o No longer reporting "default gateway" on PtP IP Interface.
o Bugfix: Handle network initiated deactivation.

---
 No changes from v2.

 drivers/stemodem/gprs-context.c |  151 +-
 1 files changed, 83 insertions(+), 68 deletions(-)

diff --git a/drivers/stemodem/gprs-context.c b/drivers/stemodem/gprs-context.c
index 05fec3f..3ccda87 100644
--- a/drivers/stemodem/gprs-context.c
+++ b/drivers/stemodem/gprs-context.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -65,10 +66,18 @@ struct gprs_context_data {
 };
 
 struct conn_info {
+   /*
+* cid is allocated in oFono Core and is identifying
+* the Account. cid = 0 indicates that it is currently unused.
+*/
unsigned int cid;
-   unsigned int device;
+   /* Id used by CAIF and EPPSD to identify the CAIF channel*/
unsigned int channel_id;
-   char interface[10];
+   /* Linux Interface Id */
+   unsigned int ifindex;
+   /* Linux Interface name */
+   char interface[IF_NAMESIZE];
+   gboolean created;
 };
 
 struct eppsd_response {
@@ -76,7 +85,6 @@ struct eppsd_response {
char ip_address[IP_ADDR_LEN];
char subnet_mask[IP_ADDR_LEN];
char mtu[IP_ADDR_LEN];
-   char default_gateway[IP_ADDR_LEN];
char dns_server1[IP_ADDR_LEN];
char dns_server2[IP_ADDR_LEN];
char p_cscf_server[IP_ADDR_LEN];
@@ -96,8 +104,6 @@ static void start_element_handler(GMarkupParseContext 
*context,
rsp->current = rsp->subnet_mask;
else if (!strcmp(element_name, "mtu"))
rsp->current = rsp->mtu;
-   else if (!strcmp(element_name, "default_gateway"))
-   rsp->current = rsp->default_gateway;
else if (!strcmp(element_name, "dns_server") &&
rsp->dns_server1[0] == '\0')
rsp->current = rsp->dns_server1;
@@ -123,7 +129,7 @@ static void text_handler(GMarkupParseContext *context,
 
if (rsp->current) {
strncpy(rsp->current, text, IP_ADDR_LEN);
-   rsp->current[IP_ADDR_LEN] = 0;
+   rsp->current[IP_ADDR_LEN] = '\0';
}
 }
 
@@ -153,8 +159,7 @@ static gint conn_compare_by_cid(gconstpointer a, 
gconstpointer b)
return 0;
 }
 
-static struct conn_info *conn_info_create(unsigned int device,
-   unsigned int channel_id)
+static struct conn_info *conn_info_create(unsigned int channel_id)
 {
struct conn_info *connection = g_try_new0(struct conn_info, 1);
 
@@ -162,7 +167,6 @@ static struct conn_info *conn_info_create(unsigned int 
device,
return NULL;
 
connection->cid = 0;
-   connection->device = device;
connection->channel_id = channel_id;
 
return connection;
@@ -171,7 +175,7 @@ static struct conn_info *conn_info_create(unsigned int 
device,
 /*
  * Creates a new IP interface for CAIF.
  */
-static gboolean caif_if_create(const char *interface, unsigned int connid)
+static gboolean caif_if_create(struct conn_info *conn)
 {
return FALSE;
 }
@@ -179,9 +183,8 @@ static gboolean caif_if_create(const char *interface, 
unsigned int connid)
 /*
  * Removes IP interface for CAIF.
  */
-static gboolean caif_if_remove(const char *interface, unsigned int connid)
+static void caif_if_remove(struct conn_info *conn)
 {
-   return FALSE;
 }
 
 static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
@@ -210,21 +213,13 @@ static void ste_eppsd_down_cb(gboolean ok, GAtResult 
*result,
DBG("Did not find data (used caif device) for"
"connection with cid; %d",
gcd->active_context);
-   goto error;
+   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   return;
}
 
conn = l->data;
-
-   if (!caif_if_remove(conn->interface, conn->channel_id)) {
-   DBG("Failed to remove caif interface %s.",
-   conn->interface);
-   }
-
conn->cid = 0;
-   return;
-
-error:
-   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   CALLBACK_WITH_SUCCESS(cb, cbd->data);
 }
 
 static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -233,7 +228,7 @@ static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
ofono_gprs_context_up_cb_t cb = cbd->cb;
struct ofono_gprs_context *gc = cbd->user;
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
-   struct conn_info *conn = NULL;
+   struct conn_info *conn;
GAtResultIter iter;
GSList *l;
int i;
@@ -241,17 +236,15 @@ static void ste_eppsd_up_cb

Re: [PATCH v2 2/2] stemodem: Use RTNL to create network interfaces.

2010-11-21 Thread Sjur Brændeland
Hi George.

> it looks as if two functions:
>
> caif_if_create/remove (struct conn_info *conn)
>
> do nothing but verify the return results of functions:
>
> caif_rtnl_create_interface/caif_rtnl_delete_interface
>
> declared in in  caif_rtnl.h
>
> Which means if you #include caif_rtnl.h in gprs-context.c
> create/delete_interface will be available directly without any wrappers
> and could make your code run a bit faster and easier to understand?
> Unless I missed something.

Thank you for reviewing this patch :-)
Yes, you are right concerning caif_if_create, I'll change this.
But caif_if_remove needs to stay as is,
it is called from g_slist_foreach and must have the list node as argument.

BTW you should take a look at http://ofono.org/wiki/ofono-etiquette.
Top-posting is not exactly popular on this list ;-)

Regards,
Sjur
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v2 2/2] stemodem: Use RTNL to create network interfaces.

2010-11-21 Thread George Matveev
Hi Sjur,

it looks as if two functions:

caif_if_create/remove (struct conn_info *conn)

do nothing but verify the return results of functions:

caif_rtnl_create_interface/caif_rtnl_delete_interface

declared in in  caif_rtnl.h

Which means if you #include caif_rtnl.h in gprs-context.c
create/delete_interface will be available directly without any wrappers
and could make your code run a bit faster and easier to understand?
Unless I missed something.

Regards,
George

> From: Sjur Brændeland 
>
> ---
>  drivers/stemodem/gprs-context.c |   43
> ++-
>  1 files changed, 42 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/stemodem/gprs-context.c
> b/drivers/stemodem/gprs-context.c
> index 3ccda87..3859107 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,38 @@ static struct conn_info *conn_info_create(unsigned
> int channel_id)
>   return connection;
>  }
>
> +static void rtnl_callback(int ifindex, const char *ifname, void
> *user_data)
> +{
> + 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;
> +}
> +
>  /*
>   * Creates a new IP interface for CAIF.
>   */
>  static gboolean caif_if_create(struct conn_info *conn)
>  {
> - return FALSE;
> + int err;
> +
> + err = caif_rtnl_create_interface(IFLA_CAIF_IPV4_CONNID,
> + conn->channel_id, FALSE,
> + rtnl_callback, conn);
> + if (err < 0) {
> + DBG("Failed to create IP interface for CAIF");
> + return FALSE;
> + }
> +
> + return TRUE;
>  }
>
>  /*
> @@ -185,6 +212,18 @@ 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);
> + return;
>  }
>
>  static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
> @@ -571,10 +610,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()
>  {
> + caif_rtnl_exit();
>   ofono_gprs_context_driver_unregister(&driver);
>  }
> --
> 1.7.0.4
>
> ___
> ofono mailing list
> ofono@ofono.org
> http://lists.ofono.org/listinfo/ofono
>


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/2] unit: Add unit tests for STE modem

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

Add unit tests for AT handling in stemodem/radio-settings.c and
stemodem/gprs-context.c. The tests integrates with gatchat
and verifies AT commands sent to modem and simulates modem
responses.
---
 Makefile.am |   15 ++-
 unit/test-ste.c |  554 +++
 2 files changed, 568 insertions(+), 1 deletions(-)
 create mode 100644 unit/test-ste.c

diff --git a/Makefile.am b/Makefile.am
index e505a39..413e42f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -437,7 +437,7 @@ dist_man_MANS = doc/ofonod.8
 noinst_PROGRAMS = unit/test-common unit/test-util unit/test-idmap \
unit/test-sms unit/test-simutil \
unit/test-mux unit/test-caif \
-   unit/test-stkutil
+   unit/test-stkutil unit/test-ste
 
 unit_objects =
 
@@ -480,6 +480,19 @@ unit_test_caif_SOURCES = unit/test-caif.c 
$(gatchat_sources) \
 unit_test_caif_LDADD = @GLIB_LIBS@
 unit_objects += $(unit_test_caif_OBJECTS)
 
+unit_test_ste_SOURCES = unit/test-ste.c $(gatchat_sources) \
+   $(gdbus_sources) $(local_headers) \
+   drivers/stemodem/stemodem.h \
+   drivers/atmodem/atutil.h \
+   drivers/atmodem/atutil.c \
+   drivers/stemodem/radio-settings.c \
+   drivers/stemodem/gprs-context.c \
+   drivers/stemodem/caif_socket.h \
+   drivers/stemodem/if_caif.h
+
+unit_test_ste_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
+unit_objects += $(unit_test_ste_OBJECTS)
+
 noinst_PROGRAMS += tools/huawei-audio
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
diff --git a/unit/test-ste.c b/unit/test-ste.c
new file mode 100644
index 000..408e592
--- /dev/null
+++ b/unit/test-ste.c
@@ -0,0 +1,554 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 ST-Ericsson AB.
+ *
+ *  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Generic test code decls */
+static GAtChat *chat;
+static GMainLoop *event_loop;
+static int phone_fd;
+
+#define ASSERT_AT(s) g_assert(assert_at(s));
+
+/* Send a simulated AT response */
+static void at_response(char *resp)
+{
+   int r;
+
+   /* Send AT response to g_at_chat and give main look a kick to run
+* one iteration.
+*/
+   r = write(phone_fd, resp, strlen(resp));
+   g_main_iteration(TRUE);
+}
+
+static gboolean assert_at(char *match)
+{
+   char req[256];
+   int r;
+
+   g_main_iteration(TRUE);
+
+   /* Read what g_at_chan has written to "modem" */
+   r = read(phone_fd, req, sizeof(req));
+
+   if (r > 1)
+   req[r-1] = 0;
+
+   if (strcmp(match, req) == 0)
+   return TRUE;
+
+   g_print("AT request did not match:%s != %s\n", match, req);
+   return FALSE;
+}
+
+/* stubs from src/radio-settings.c */
+struct ofono_radio_settings;
+const struct ofono_radio_settings_driver *radio_settings_driver;
+void *radio_settings_data;
+
+void ofono_radio_settings_register(struct ofono_radio_settings *rs)
+{
+}
+
+void ofono_radio_settings_remove(struct ofono_radio_settings *rs)
+{
+}
+
+void ofono_radio_settings_set_data(struct ofono_radio_settings *rs, void *data)
+{
+   radio_settings_data = data;
+}
+
+void *ofono_radio_settings_get_data(struct ofono_radio_settings *rs)
+{
+   return radio_settings_data;
+}
+
+int ofono_radio_settings_driver_register(
+   const struct ofono_radio_settings_driver *d)
+{
+   radio_settings_driver = d;
+   return 0;
+}
+
+void ofono_radio_settings_driver_unregister(
+   const struct ofono_radio_settings_driver *d)
+{
+}
+
+/* stubs from src/gprs-context.c */
+struct ofono_gprs_context;
+const struct ofono_gprs_context_driver *gprs_context_driver;
+void *gprs_context_data;
+
+int caif_rtnl_create_interface(int type, int connid

[PATCH 1/2] unit: CAIF test: remove character dev tests and add RTNL.

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

- Remove tests for CAIF Character device. Character devices are depreceated
and replaced with Sockets.
- Add RTNL Tests for creating and removing CAIF GPRS Network Interface.
---
 Makefile.am  |4 +-
 unit/test-caif.c |  108 +-
 2 files changed, 77 insertions(+), 35 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f841b4c..e505a39 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -474,7 +474,9 @@ unit_objects += $(unit_test_mux_OBJECTS)
 
 unit_test_caif_SOURCES = unit/test-caif.c $(gatchat_sources) \
drivers/stemodem/caif_socket.h \
-   drivers/stemodem/if_caif.h 
+   drivers/stemodem/caif_rtnl.c \
+   drivers/stemodem/caif_rtnl.h \
+   drivers/stemodem/if_caif.h
 unit_test_caif_LDADD = @GLIB_LIBS@
 unit_objects += $(unit_test_caif_OBJECTS)
 
diff --git a/unit/test-caif.c b/unit/test-caif.c
index 51e29bc..fdcdc3e 100644
--- a/unit/test-caif.c
+++ b/unit/test-caif.c
@@ -3,6 +3,7 @@
  *  oFono - Open Source Telephony
  *
  *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010 ST-Ericsson AB.
  *
  *  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
@@ -28,28 +29,26 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 
 #include 
-
+#include 
 #include 
 #include 
+#include 
 
 static GMainLoop *mainloop;
 
-static int do_open(void)
+void ofono_debug(const char *format, ...)
 {
-   int fd;
-
-   fd = open("/dev/chnlat11", O_RDWR);
-   if (fd < 0) {
-   g_printerr("Open of chnlat11 failed (%d)\n", errno);
-   return -EIO;
-   }
-
-   return fd;
+   va_list ap;
+   va_start(ap, format);
+   if (g_test_verbose())
+   vprintf(format, ap);
+   va_end(ap);
 }
 
 static int do_connect(void)
@@ -58,7 +57,7 @@ static int do_connect(void)
int sk, err;
 
/* Create a CAIF socket for AT Service */
-   sk = socket(AF_CAIF, SOCK_SEQPACKET, CAIFPROTO_AT);
+   sk = socket(AF_CAIF, SOCK_STREAM, CAIFPROTO_AT);
if (sk < 0) {
g_printerr("CAIF socket creation failed (%d)\n", errno);
return -EIO;
@@ -81,7 +80,8 @@ static int do_connect(void)
 
 static void caif_debug(const char *str, void *data)
 {
-   g_print("%s\n", str);
+   if (g_test_verbose())
+   g_print("CAIF:%s\n", str);
 }
 
 static void caif_init(gboolean ok, GAtResult *result, gpointer data)
@@ -100,18 +100,15 @@ static void caif_init(gboolean ok, GAtResult *result, 
gpointer data)
g_main_loop_quit(mainloop);
 }
 
-static void test_connect(gboolean use_socket)
+static void test_connect()
 {
GIOChannel *io;
GAtChat *chat;
GAtSyntax *syntax;
int fd;
 
-   if (use_socket == TRUE)
-   fd = do_connect();
-   else
-   fd = do_open();
 
+   fd = do_connect();
if (fd < 0)
return;
 
@@ -138,34 +135,77 @@ static void test_connect(gboolean use_socket)
g_main_loop_unref(mainloop);
 }
 
-static void test_basic(void)
+/* Storage for rtnl_callback data */
+static int rtnl_result;
+static int rtnl_ifi;
+static char rtnl_ifname[16];
+static void *rtnl_user_data;
+
+static void rtnl_create_cb(int ifindex, const char *ifname, void *user_data)
 {
-   if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
-   test_connect(TRUE);
-   exit(0);
-   }
+   strcpy(rtnl_ifname, ifname);
+   rtnl_ifi = ifindex;
+   rtnl_user_data = user_data;
+}
+
+static void test_rtnl_normal()
+{
+   int res;
+   int connid = 1;
+
+   res = caif_rtnl_init();
+   res = caif_rtnl_create_interface(IFLA_CAIF_IPV4_CONNID, connid, FALSE,
+   rtnl_create_cb,
+   (void *)0xbaadf00d);
+   g_assert_cmpint(0, ==, res);
+
+   g_main_iteration(TRUE);
 
-   g_test_trap_assert_passed();
-   //g_test_trap_assert_stderr("failed");
+   g_assert_cmpint(0, ==, rtnl_result);
+   g_assert((void *)0xbaadf00d == rtnl_user_data);
+
+   res = caif_rtnl_delete_interface(rtnl_ifi);
+
+   g_main_iteration(TRUE);
+   g_assert_cmpint(0, ==, res);
+
+   caif_rtnl_exit();
 }
 
-static void test_chnlat(void)
+static void test_rtnl_bad_delete()
 {
-   if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
-   test_connect(FALSE);
-   exit(0);
-   }
+   int res;
 
-   g_test_trap_assert_passed();
-   //g_test_trap_assert_stderr("failed");
+   res = caif_rtnl_init();
+   res = caif_rtnl_delete_interface(1000);
+   g_assert_cmpint(0, ==, res)

[PATCH 0/2] unit: STE Unit Tests

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

This patch set introduces unit tests for functionality in
o CAIF RTNL functions in drivers/stemodem/caif_rtnl.c
o GPRS context handling in drivers/stemodem/gprs-context.c
o Radio State settings in drivers/stemodem/radio-settings.c
o Test for CAIF Character devices are removed as this is not
  supported by upstream version of CAIF.

The unit tests calls functions in the driver and simulates
AT-responses received from the modem.

Patches should apply and compile cleanly. Successful execution
depends on patches:
stemodem: Create network interfaces statically
stemodem: Use RTNL to create network interfaces.

Sjur Brændeland (2):
  unit: CAIF test: remove character dev tests and add RTNL.
  unit: Add unit tests for STE modem

 Makefile.am  |   19 ++-
 unit/test-caif.c |  108 +++
 unit/test-ste.c  |  554 ++
 3 files changed, 645 insertions(+), 36 deletions(-)
 create mode 100644 unit/test-ste.c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH RESEND] stemodem: Change use of types

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

Use the type __u32 for sequence counting rather than guint32,
and "void *" instead of gpointer.
Reduce the size of RTNL message buffer from 4096 to 1024,
as this should be sufficient to hold the NEWLINK message.

---
Last patch was sent with base64 encoding :-(

 drivers/stemodem/caif_rtnl.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/stemodem/caif_rtnl.c b/drivers/stemodem/caif_rtnl.c
index 5d4073a..4c00446 100644
--- a/drivers/stemodem/caif_rtnl.c
+++ b/drivers/stemodem/caif_rtnl.c
@@ -41,7 +41,7 @@
 #define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
 
-#define RTNL_MSG_SIZE 4096
+#define RTNL_MSG_SIZE 1024
 
 struct rtnl_msg {
struct nlmsghdr n;
@@ -50,17 +50,17 @@ struct rtnl_msg {
 };
 
 struct iplink_req {
-   guint32 rtnlmsg_seqnr;
-   gpointer user_data;
+   __u32 rtnlmsg_seqnr;
+   void *user_data;
caif_rtnl_create_cb_t callback;
 };
 
 static GSList *pending_requests;
-static guint32 rtnl_seqnr;
+static __u32 rtnl_seqnr;
 static guint rtnl_watch;
 static GIOChannel *rtnl_channel;
 
-static struct iplink_req *find_request(guint32 seq)
+static struct iplink_req *find_request(__u32 seq)
 {
GSList *list;
 
@@ -169,7 +169,7 @@ static int add_attribute(struct nlmsghdr *n, unsigned int 
maxlen, int type,
return 0;
 }
 
-static inline void prep_rtnl_req(struct rtnl_msg *msg, int reqtype, guint 
seqnr)
+static inline void prep_rtnl_req(struct rtnl_msg *msg, int reqtype, __u32 
seqnr)
 {
msg->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
msg->n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
@@ -179,7 +179,7 @@ static inline void prep_rtnl_req(struct rtnl_msg *msg, int 
reqtype, guint seqnr)
 }
 
 static gboolean netlink_event(GIOChannel *chan,
-   GIOCondition cond, gpointer data)
+   GIOCondition cond, void *data)
 {
unsigned char buf[RTNL_MSG_SIZE];
int len, sk;
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 2/2] stemodem: Use RTNL to create network interfaces.

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

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

diff --git a/drivers/stemodem/gprs-context.c b/drivers/stemodem/gprs-context.c
index 3ccda87..3859107 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,38 @@ static struct conn_info *conn_info_create(unsigned int 
channel_id)
return connection;
 }
 
+static void rtnl_callback(int ifindex, const char *ifname, void *user_data)
+{
+   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;
+}
+
 /*
  * Creates a new IP interface for CAIF.
  */
 static gboolean caif_if_create(struct conn_info *conn)
 {
-   return FALSE;
+   int err;
+
+   err = caif_rtnl_create_interface(IFLA_CAIF_IPV4_CONNID,
+   conn->channel_id, FALSE,
+   rtnl_callback, conn);
+   if (err < 0) {
+   DBG("Failed to create IP interface for CAIF");
+   return FALSE;
+   }
+
+   return TRUE;
 }
 
 /*
@@ -185,6 +212,18 @@ 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);
+   return;
 }
 
 static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
@@ -571,10 +610,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()
 {
+   caif_rtnl_exit();
ofono_gprs_context_driver_unregister(&driver);
 }
-- 
1.7.0.4

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v2 1/2] stemodem: Create network interfaces statically

2010-11-21 Thread Sjur Brændeland
From: Sjur Brændeland 

Changes:
o Restructure code so interfaces are created statically when probe is called.
o Removed some of the unnecessary initializations at declaration.
o No longer reporting "default gateway" on PtP IP Interface.
o Bugfix: Handle network initiated deactivation.
---
Changes from V1:
o Removed unused label


  
 drivers/stemodem/gprs-context.c |  151 +-
 1 files changed, 83 insertions(+), 68 deletions(-)

diff --git a/drivers/stemodem/gprs-context.c b/drivers/stemodem/gprs-context.c
index 05fec3f..3ccda87 100644
--- a/drivers/stemodem/gprs-context.c
+++ b/drivers/stemodem/gprs-context.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -65,10 +66,18 @@ struct gprs_context_data {
 };
 
 struct conn_info {
+   /*
+* cid is allocated in oFono Core and is identifying
+* the Account. cid = 0 indicates that it is currently unused.
+*/
unsigned int cid;
-   unsigned int device;
+   /* Id used by CAIF and EPPSD to identify the CAIF channel*/
unsigned int channel_id;
-   char interface[10];
+   /* Linux Interface Id */
+   unsigned int ifindex;
+   /* Linux Interface name */
+   char interface[IF_NAMESIZE];
+   gboolean created;
 };
 
 struct eppsd_response {
@@ -76,7 +85,6 @@ struct eppsd_response {
char ip_address[IP_ADDR_LEN];
char subnet_mask[IP_ADDR_LEN];
char mtu[IP_ADDR_LEN];
-   char default_gateway[IP_ADDR_LEN];
char dns_server1[IP_ADDR_LEN];
char dns_server2[IP_ADDR_LEN];
char p_cscf_server[IP_ADDR_LEN];
@@ -96,8 +104,6 @@ static void start_element_handler(GMarkupParseContext 
*context,
rsp->current = rsp->subnet_mask;
else if (!strcmp(element_name, "mtu"))
rsp->current = rsp->mtu;
-   else if (!strcmp(element_name, "default_gateway"))
-   rsp->current = rsp->default_gateway;
else if (!strcmp(element_name, "dns_server") &&
rsp->dns_server1[0] == '\0')
rsp->current = rsp->dns_server1;
@@ -123,7 +129,7 @@ static void text_handler(GMarkupParseContext *context,
 
if (rsp->current) {
strncpy(rsp->current, text, IP_ADDR_LEN);
-   rsp->current[IP_ADDR_LEN] = 0;
+   rsp->current[IP_ADDR_LEN] = '\0';
}
 }
 
@@ -153,8 +159,7 @@ static gint conn_compare_by_cid(gconstpointer a, 
gconstpointer b)
return 0;
 }
 
-static struct conn_info *conn_info_create(unsigned int device,
-   unsigned int channel_id)
+static struct conn_info *conn_info_create(unsigned int channel_id)
 {
struct conn_info *connection = g_try_new0(struct conn_info, 1);
 
@@ -162,7 +167,6 @@ static struct conn_info *conn_info_create(unsigned int 
device,
return NULL;
 
connection->cid = 0;
-   connection->device = device;
connection->channel_id = channel_id;
 
return connection;
@@ -171,7 +175,7 @@ static struct conn_info *conn_info_create(unsigned int 
device,
 /*
  * Creates a new IP interface for CAIF.
  */
-static gboolean caif_if_create(const char *interface, unsigned int connid)
+static gboolean caif_if_create(struct conn_info *conn)
 {
return FALSE;
 }
@@ -179,9 +183,8 @@ static gboolean caif_if_create(const char *interface, 
unsigned int connid)
 /*
  * Removes IP interface for CAIF.
  */
-static gboolean caif_if_remove(const char *interface, unsigned int connid)
+static void caif_if_remove(struct conn_info *conn)
 {
-   return FALSE;
 }
 
 static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
@@ -210,21 +213,13 @@ static void ste_eppsd_down_cb(gboolean ok, GAtResult 
*result,
DBG("Did not find data (used caif device) for"
"connection with cid; %d",
gcd->active_context);
-   goto error;
+   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   return;
}
 
conn = l->data;
-
-   if (!caif_if_remove(conn->interface, conn->channel_id)) {
-   DBG("Failed to remove caif interface %s.",
-   conn->interface);
-   }
-
conn->cid = 0;
-   return;
-
-error:
-   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   CALLBACK_WITH_SUCCESS(cb, cbd->data);
 }
 
 static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -233,7 +228,7 @@ static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
ofono_gprs_context_up_cb_t cb = cbd->cb;
struct ofono_gprs_context *gc = cbd->user;
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
-   struct conn_info *conn = NULL;
+   struct conn_info *conn;
GAtResultIter iter;
GSList *l;
int i;
@@ -241,17 +236,15 @@ stati

RE: [PATCH] TODO: Add vCard export to SM/ME stores

2010-11-21 Thread Marcel Holtmann
Hi Jaako,

> > > Is there already a specification/draft of the format of this dict? If
> > not, I would be tempted to use the 27.007 +CPBR/W field names as keys
> > (e.g. index, number, type, text, adnumber, secondtext, sip_uri, etc.)
> > 
> > there is not. So you need to propose one here.
> 
> For simplicity, I would propose that both import and export would use an 
> array of dict's with the 27.007 keys:
> 
> index: type=integer, import=always export=ignored

no index number. We will never use them. It is either the full phonebook
at once or nothing. The write function has to empty out left over
entries.

> number: type=string, import=always/empty export=optional/empty
> type: type=integer, import=always export=mandatory
> text: type=string, import=always/empty export=optional/empty
> hidden: type=int, import=always, export=optional/default=0
> group: type=string, import=if nonempty, export=optional
> adnumber: type=string, import=if nonempty, export=optional
> adtype: type=integer, import/export=mandatory if adnumber nonempty
> secondtext: type=string, import=if nonempty, export=optional
> email: type=string, import=if nonempty, export=optional
> sip_uri: type=string, import=if nonempty, export=optional
> tel_uri: type=string, import=if nonempty, export=optional

Actually I prefer we use proper Dict field names. We never use anything
literally from the specifications in this area. So why start now. Please
propose proper human readable names.

Regards

Marcel


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


RE: [PATCH] TODO: Add vCard export to SM/ME stores

2010-11-21 Thread Kiviluoto, Jaakko J
> > > > To support this feature then first we need to convert the current
> > > > feature into returning a dict. And then have this feature using a
> > dict
> > > > as input.
> > >
> > > Is there already a specification/draft of the format of this dict?
> If
> > not, I would be tempted to use the 27.007 +CPBR/W field names as keys
> > (e.g. index, number, type, text, adnumber, secondtext, sip_uri, etc.)
> >
> > there is not. So you need to propose one here.
> 
> For simplicity, I would propose that both import and export would use
> an array of dict's with the 27.007 keys:
> 
> index: type=integer, import=always export=ignored
> number: type=string, import=always/empty export=optional/empty
> type: type=integer, import=always export=mandatory
> text: type=string, import=always/empty export=optional/empty
> hidden: type=int, import=always, export=optional/default=0
> group: type=string, import=if nonempty, export=optional
> adnumber: type=string, import=if nonempty, export=optional
> adtype: type=integer, import/export=mandatory if adnumber nonempty
> secondtext: type=string, import=if nonempty, export=optional
> email: type=string, import=if nonempty, export=optional
> sip_uri: type=string, import=if nonempty, export=optional
> tel_uri: type=string, import=if nonempty, export=optional
> 
> Either 'text' or 'number' must be nonempty on export.
> 
> This simple scheme would also necessitate removing the contact merging
> from the import functionality. Would that be ok?
> 
> Otherwise the dict would have to contain a list of number structures
> instead of number/adnumber fields, and merging/unmerging would have to
> be (re)implemented for both import and export.

So, any comments on this format? Should I go ahead and re-implement the Import 
functionality, plus the new Export functionality?

Jaakko

-
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono