All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] simfs: Added support for ISim file systems
@ 2017-11-08 17:23 James Prestwood
  2017-11-08 17:23 ` [PATCH 2/4] aidapplications: new class for AID applications James Prestwood
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: James Prestwood @ 2017-11-08 17:23 UTC (permalink / raw)
  To: ofono

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

---
 src/simfilesystem.cpp | 100 +++++++++++++++++++++++++++++++++++++++-----------
 src/simfilesystem.h   |  11 +++++-
 2 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/src/simfilesystem.cpp b/src/simfilesystem.cpp
index a23d0a0..0e5c2a9 100644
--- a/src/simfilesystem.cpp
+++ b/src/simfilesystem.cpp
@@ -133,7 +133,20 @@ static SimFileInfo const knownFiles[] =
     {0,             0,          0,             0,         FILE_TYPE_TRANSPARENT}
 };
 
-SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
+static SimFileInfo const isimFiles[] =
+{
+    // TS 31.103
+    {"6F02",        0,     "EFimpi",        0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6F03",        0,     "EFdomain",      0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6FAD",        0,     "EFad",          0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6F06",        0,     "EFarr",         0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6F07",        0,     "EFist",         0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6F09",        0,     "EFpcscf",       0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {"6FD5",        0,     "EFgbabp",       0x14ff44,  FILE_TYPE_TRANSPARENT},
+    {0,             0,          0,             0,         FILE_TYPE_TRANSPARENT}
+};
+
+SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e, enum file_system_type fstype )
     : QObject( rules )
 {
     this->rules = rules;
@@ -141,7 +154,12 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
     currentItem = rootItem;
 
     // Create all of the standard directories.
-    const SimFileInfo *info = knownFiles;
+    const SimFileInfo *info;
+    if (fstype == FILE_SYSTEM_TYPE_ISIM) {
+        info = isimFiles;
+    } else {
+        info = knownFiles;
+    }
     SimFileItem *dirItem = 0;
     while ( info->fileid ) {
         QString fileid = info->fileid;
@@ -162,20 +180,33 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
             QString fileid = resolveFileId( name );
             int access = findItemAccess( name );
             enum file_type type = findItemFileType( name );
-            SimFileItem *parent = findItemParent( fileid );
-            if ( parent ) {
-                SimFileItem *item;
-                item = findItem( fileid.right(4) );
-                if ( !item )
-                    item = new SimFileItem( fileid.right(4), parent, access, type );
-                else
-                    qDebug() << "File" << name << "defined multiple times";
-                item->setContents( data );
-                QString size = child->getAttribute( "recordsize" );
-                if ( !size.isEmpty() )
-                    item->setRecordSize( size.toInt() );
+
+            if ( fstype == FILE_SYSTEM_TYPE_DEFAULT) {
+                SimFileItem *parent = findItemParent( fileid );
+                if ( parent ) {
+                    SimFileItem *item;
+                    item = findItem( fileid.right(4) );
+                    if ( !item )
+                        item = new SimFileItem( fileid.right(4), parent, access, type );
+                    else
+                        qDebug() << "File" << name << "defined multiple times";
+                    item->setContents( data );
+                    QString size = child->getAttribute( "recordsize" );
+                    if ( !size.isEmpty() )
+                        item->setRecordSize( size.toInt() );
+                } else {
+                    qDebug() << "Could not find parent for" << name;
+                }
             } else {
-                qDebug() << "Could not find parent for" << name;
+                /*
+                 * ISIM files wont have a parent dir set, so they are handled
+                 * differently.
+                 */
+                QString name = child->getAttribute( "name" );
+                QByteArray data = QAtUtils::fromHex( child->contents );
+                QString fileid = resolveISimFileId( name );
+                SimFileItem *item = new SimFileItem( fileid.right(4), rootItem, access, type);
+                item->setContents( data );
             }
         } else {
             qDebug() << "Unknown filesystem command <" << child->tag << ">";
@@ -184,7 +215,8 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
     }
 
     /* Select DFgsm initially */
-    currentItem = findItem("7F20");
+    if ( fstype == FILE_SYSTEM_TYPE_DEFAULT )
+        currentItem = findItem("7F20");
 }
 
 SimFileSystem::~SimFileSystem()
@@ -192,7 +224,7 @@ SimFileSystem::~SimFileSystem()
     delete rootItem;
 }
 
-void SimFileSystem::crsm( const QString& args )
+bool SimFileSystem::fileAccess( const QString& args, QString& resp )
 {
     // Extract the arguments to the command.
     uint posn = 0;
@@ -428,13 +460,26 @@ void SimFileSystem::crsm( const QString& args )
 
     // Send the response information.
     if ( sw1 != 0 ) {
-        QString resp;
-        resp = "+CRSM: " + QString::number(sw1) + "," + QString::number(sw2);
+        resp = QString::number(sw1) + "," + QString::number(sw2);
         if ( !response.isEmpty() )
             resp += "," + response;
-        rules->respond( resp );
     }
-    if ( ok )
+
+    return ok;
+}
+
+void SimFileSystem::crsm( const QString& args )
+{
+    bool ok;
+    QString crsm = "+CRSM: ";
+    QString resp;
+    ok = fileAccess( args, resp );
+
+    crsm += resp;
+
+    rules->respond( crsm );
+
+    if (ok)
         rules->respond( "OK" );
     else
         rules->respond( "ERROR" );
@@ -526,6 +571,19 @@ QString SimFileSystem::resolveFileId( const QString& _fileid ) const
     }
 }
 
+QString SimFileSystem::resolveISimFileId( const QString& name ) const
+{
+    const SimFileInfo *info = (const SimFileInfo *)isimFiles;
+    while ( info->fileid ) {
+        if ( name == info->name ) {
+            QString fileid = info->fileid;
+            return fileid;
+        }
+        ++info;
+    }
+    return QString("");
+}
+
 int SimFileSystem::findItemAccess( const QString& _fileid ) const
 {
     QString fileid = _fileid;
diff --git a/src/simfilesystem.h b/src/simfilesystem.h
index 150416f..477c6c7 100644
--- a/src/simfilesystem.h
+++ b/src/simfilesystem.h
@@ -24,6 +24,11 @@
 
 class SimFileItem;
 
+enum file_system_type {
+    FILE_SYSTEM_TYPE_DEFAULT,
+    FILE_SYSTEM_TYPE_ISIM
+};
+
 enum file_type {
     FILE_TYPE_TRANSPARENT = 0,
     FILE_TYPE_LINEAR_FIXED = 1,
@@ -52,12 +57,14 @@ class SimFileSystem : public QObject
 {
     Q_OBJECT
 public:
-    SimFileSystem( SimRules *rules, SimXmlNode& e );
+    SimFileSystem( SimRules *rules, SimXmlNode& e, enum file_system_type type = FILE_SYSTEM_TYPE_DEFAULT );
     ~SimFileSystem();
 
     // Execute an AT+CRSM command against the filesystem.
     void crsm( const QString& args );
 
+    bool fileAccess( const QString& args, QString& resp );
+
     // Find an item with a specific id.
     SimFileItem *findItem( const QString& fileid ) const;
 
@@ -77,6 +84,8 @@ public:
     // Resolve a file identifier to its full path from the root directory.
     QString resolveFileId( const QString& fileid ) const;
 
+    QString resolveISimFileId( const QString& _fileid ) const;
+
 private:
     SimRules *rules;
     SimFileItem *rootItem;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] aidapplications: new class for AID applications
  2017-11-08 17:23 [PATCH 1/4] simfs: Added support for ISim file systems James Prestwood
@ 2017-11-08 17:23 ` James Prestwood
  2017-11-08 17:23 ` [PATCH 3/4] make: added aidapplication module to build James Prestwood
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2017-11-08 17:23 UTC (permalink / raw)
  To: ofono

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

New AID applications can be created using the XML
<application> tag. Inside this tag a file system
can be created which is accessable via session
based file access.
---
 src/aidapplication.cpp | 276 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/aidapplication.h   |  88 ++++++++++++++++
 2 files changed, 364 insertions(+)
 create mode 100644 src/aidapplication.cpp
 create mode 100644 src/aidapplication.h

diff --git a/src/aidapplication.cpp b/src/aidapplication.cpp
new file mode 100644
index 0000000..e255145
--- /dev/null
+++ b/src/aidapplication.cpp
@@ -0,0 +1,276 @@
+#include "aidapplication.h"
+#include "simfilesystem.h"
+#include "simauth.h"
+
+#include <qatutils.h>
+#include <qsimcontrolevent.h>
+
+AidApplication::AidApplication( QObject *parent, SimXmlNode& n )
+    : QObject( parent )
+{
+    SimXmlNode *child = n.children;
+
+    type = n.getAttribute( "type" );
+    aid = n.getAttribute( "id" );
+
+    while (child) {
+        if ( child->tag == "filesystem" )
+            fs = new SimFileSystem( (SimRules *)parent, *child, FILE_SYSTEM_TYPE_ISIM );
+
+        child = child->next;
+    }
+}
+
+AidApplication::~AidApplication()
+{
+}
+
+AidAppWrapper::AidAppWrapper( SimRules *r, QList<AidApplication *> apps, SimAuth *sa ) : QObject( r )
+{
+    applications = apps;
+    session_start = 257;
+    rules = r;
+    auth = sa;
+}
+
+AidAppWrapper::~AidAppWrapper()
+{
+}
+
+bool AidAppWrapper::command( const QString& cmd )
+{
+    if ( cmd.startsWith( "AT+CUAD") ) {
+        QString response( "+CUAD: " );
+
+        if ( cmd.contains("=?") ) {
+            rules->respond( "OK" );
+            return true;
+        }
+
+        foreach ( AidApplication* app, applications )
+        response += app->getAid();
+
+        response.append( "\n\nOK" );
+
+        rules->respond( response );
+
+        return true;
+    } else if ( cmd.startsWith( "AT+CCHO" ) ) {
+        QString aid;
+        int session_id = -1;
+
+        if ( !cmd.contains("=") ) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        if ( cmd.contains("=?") ) {
+            rules->respond( "OK" );
+            return true;
+        }
+
+        aid = cmd.split('=')[1];
+        aid = aid.replace("\"", "");
+
+        foreach ( AidApplication* app, applications ) {
+            if ( app->getAid().contains( aid ) ) {
+                if ( sessions.size() >= MAX_LOGICAL_CHANNELS )
+                    break;
+
+                sessions.insert( session_start, app );
+                session_id = session_start;
+                session_start++;
+                break;
+            }
+        }
+
+        if ( session_id == -1 ) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        rules->respond( QString( "+CCHO: %1\n\nOK" ).arg(session_id, 0, 10) );
+        return true;
+    } else if ( cmd.startsWith( "AT+CCHC" ) ) {
+        int session_id = -1;
+
+        if ( !cmd.contains("=") ) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        if ( cmd.contains("=?") ) {
+            rules->respond( "OK" );
+            return true;
+        }
+
+        session_id = cmd.split('=')[1].toInt();
+
+        sessions.remove( session_id );
+
+        rules->respond( "OK" );
+        return true;
+    } else if ( cmd.startsWith( "AT+CRLA" ) ) {
+        QString resp;
+        AidApplication *app;
+        QStringList params = cmd.split('=')[1].split(',');
+
+        int session_id = params[0].toInt();
+
+        if ( !sessions.contains( session_id ) ) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        app = sessions[session_id];
+        if (!app) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        QString file_cmd;
+        QString response = "+CRLA: ";
+
+        for (int i = 1; i < params.length(); i++) {
+            file_cmd += params[i];
+
+            if (i != params.length() - 1)
+                file_cmd += ",";
+        }
+
+        bool ok = app->fs->fileAccess( file_cmd, resp );
+
+        if (!ok) {
+            rules->respond( "OK" );
+            return true;
+        }
+
+        response += resp;
+
+        rules->respond( response );
+        rules->respond( "OK" );
+
+        return true;
+    } else if ( cmd.startsWith( "AT+CGLA" ) ) {
+        QString auth_data;
+        QString command;
+        QString resp;
+        AidApplication *app;
+        QStringList params = cmd.split('=')[1].split(',');
+
+        int session_id = params[0].toInt();
+
+        if ( !sessions.contains( session_id ) ) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        app = sessions[session_id];
+        if (!app) {
+            rules->respond( "ERROR" );
+            return true;
+        }
+
+        command = params[2].replace("\"", "");
+        auth_data = command.mid(10);
+
+        switch (checkCommand(app, command)) {
+        case CMD_TYPE_GSM_AUTH:
+        {
+            QString sres, kc;
+            QString rand = auth_data.mid(2, 32);
+            auth->gsmAuthenticate(rand, sres, kc);
+
+            resp = QString( "+CGLA: 32,\"04 %1 08 %2 \"" )
+                                        .arg( sres, kc );
+            resp.replace( " ", "");
+
+            rules->respond( resp );
+            rules->respond( "OK" );
+
+            return true;
+        }
+        break;
+        case CMD_TYPE_UMTS_AUTH:
+        {
+            enum UmtsStatus status;
+            QString res, ck, ik, auts;
+            QString rand = auth_data.mid(2, 32);
+            QString autn = auth_data.mid(36, 32);
+
+            status = auth->umtsAuthenticate( rand, autn, res, ck, ik, auts );
+            resp = QString("+CGLA: ");
+
+            QString test;
+
+            switch (status) {
+            case UMTS_OK:
+                resp += QString( "88,\"DB08 %1 10 %2 10 %3\"" )
+                .arg( res, ck, ik );
+                resp.replace( " ", "" );
+
+                break;
+            case UMTS_INVALID_MAC:
+                resp += QString( "4,\"%1\"")
+                .arg( CMD_TYPE_APP_ERROR, 0, 16 );
+
+                break;
+            case UMTS_SYNC_FAILURE:
+                resp += QString( "34,\"DC0E %1 \"" ).arg( auts );
+                resp.replace( " ", "" );
+
+                break;
+            case UMTS_ERROR:
+                rules->respond( "ERROR" );
+                return true;
+            }
+
+            rules->respond( resp );
+            rules->respond( "OK" );
+        }
+        break;
+        default:
+            return false;
+        }
+    }
+
+    return false;
+}
+
+enum CmdType AidAppWrapper::checkCommand( AidApplication *app, QString command)
+{
+    QString cls = command.mid(0, 2);
+    QString ins = command.mid(2, 2);
+    QString p1 = command.mid(4, 2);
+    QString p2 = command.mid(6, 2);
+    QString lc = command.mid(8, 2);
+
+    if ( cls != "00" )
+        return CMD_TYPE_UNSUPPORTED_CLS;
+
+    if ( ins != "88" )
+        return CMD_TYPE_UNSUPPORTED_INS;
+
+    if ( p1 != "00" )
+        return CMD_TYPE_INCORRECT_P2_P1;
+
+    if ( p2 == "80" ) {
+        if ( lc != "11" )
+            return CMD_TYPE_WRONG_LENGTH;
+
+        if ( !(app->getType() == "USim" || app->getType() == "ISim") )
+            return CMD_TYPE_APP_ERROR;
+
+        return CMD_TYPE_GSM_AUTH;
+    } else if ( p2 == "81" ) {
+        if ( lc != "22" )
+            return CMD_TYPE_WRONG_LENGTH;
+
+        if ( app->getType() != "ISim" )
+            return CMD_TYPE_APP_ERROR;
+
+        return CMD_TYPE_UMTS_AUTH;
+    } else {
+        return CMD_TYPE_UNKNOWN;
+    }
+}
diff --git a/src/aidapplication.h b/src/aidapplication.h
new file mode 100644
index 0000000..6a2f4d9
--- /dev/null
+++ b/src/aidapplication.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** This file is part of the Qt Extended Opensource Package.
+**
+** Copyright (C) 2017  Intel Corporation. All rights reserved.
+**
+** This file may be used under the terms of the GNU General Public License
+** version 2.0 as published by the Free Software Foundation and appearing
+** in the file LICENSE.GPL included in the packaging of this file.
+**
+** Please review the following information to ensure GNU General Public
+** Licensing requirements will be met:
+**     http://www.fsf.org/licensing/licenses/info/GPLv2.html.
+**
+**
+****************************************************************************/
+
+#ifndef AIDAPPLICATION_H
+#define AIDAPPLICATION_H
+
+#include "phonesim.h"
+
+#define MAX_LOGICAL_CHANNELS    4
+
+/*
+ * Some common errors
+ */
+enum CmdType {
+    CMD_TYPE_GSM_AUTH = 0,
+    CMD_TYPE_UMTS_AUTH = 1,
+    CMD_TYPE_UNSUPPORTED_CLS = 0x6E00,
+    CMD_TYPE_UNSUPPORTED_INS = 0x6D00,
+    CMD_TYPE_INCORRECT_P2_P1 = 0x6A86,
+    CMD_TYPE_WRONG_LENGTH = 0x6700,
+    CMD_TYPE_APP_ERROR = 0x9862,
+    CMD_TYPE_UNKNOWN = 0xFFFF
+};
+
+/*
+ * Class for representing a single AID
+ */
+class AidApplication : public QObject
+{
+    Q_OBJECT
+public:
+    AidApplication( QObject *parent, SimXmlNode& n );
+    ~AidApplication();
+
+    QString getAid() { return aid; };
+    QString getType() { return type; };
+    SimFileSystem *fs;
+
+signals:
+    // Send a response to a command.
+    void send( const QString& line );
+
+private:
+    QString aid;
+    QString type;
+};
+
+/*
+ * Wrapper for containing all AIDs on the SIM
+ */
+class AidAppWrapper : public QObject
+{
+    Q_OBJECT
+public:
+    AidAppWrapper( SimRules *r, QList<AidApplication *> apps, SimAuth *auth = NULL );
+    ~AidAppWrapper();
+
+    bool command( const QString& cmd );
+
+//signals:
+        // Send a response to a command.
+//        void send( const QString& line );
+private:
+    QList<AidApplication *> applications;
+    QMap<int, AidApplication*> sessions;
+    int session_start;
+    SimRules *rules;
+    SimAuth *auth;
+
+    enum CmdType checkCommand( AidApplication *app, QString command);
+
+};
+
+#endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] make: added aidapplication module to build
  2017-11-08 17:23 [PATCH 1/4] simfs: Added support for ISim file systems James Prestwood
  2017-11-08 17:23 ` [PATCH 2/4] aidapplications: new class for AID applications James Prestwood
@ 2017-11-08 17:23 ` James Prestwood
  2017-11-08 17:23 ` [PATCH 4/4] phonesim/simauth: removed session code from simauth James Prestwood
  2017-11-09  2:58 ` [PATCH 1/4] simfs: Added support for ISim file systems Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2017-11-08 17:23 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 7feceba..c8814f1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ src_phonesim_SOURCES = src/main.cpp \
 			src/qcbsmessage.h src/qcbsmessage.cpp \
 			src/callmanager.h src/callmanager.cpp \
 			src/simauth.h src/simauth.cpp \
+			src/aidapplication.h src/aidapplication.cpp \
 			src/comp128.h src/comp128.c \
 			src/aes.h src/aes.c \
 			src/simfilesystem.h src/simfilesystem.cpp \
@@ -38,6 +39,7 @@ nodist_src_phonesim_SOURCES = src/ui_controlbase.h \
 				src/moc_hardwaremanipulator.cpp \
 				src/moc_callmanager.cpp \
 				src/moc_simauth.cpp \
+				src/moc_aidapplication.cpp \
 				src/moc_simfilesystem.cpp \
 				src/moc_simapplication.cpp \
 				src/moc_qwsppdu.cpp
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] phonesim/simauth: removed session code from simauth
  2017-11-08 17:23 [PATCH 1/4] simfs: Added support for ISim file systems James Prestwood
  2017-11-08 17:23 ` [PATCH 2/4] aidapplications: new class for AID applications James Prestwood
  2017-11-08 17:23 ` [PATCH 3/4] make: added aidapplication module to build James Prestwood
@ 2017-11-08 17:23 ` James Prestwood
  2017-11-09  2:58 ` [PATCH 1/4] simfs: Added support for ISim file systems Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2017-11-08 17:23 UTC (permalink / raw)
  To: ofono

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

The AID application class handles session managment
so it was removed from simauth. Now, simauth only
implements the authentication algorithms.

Added AID application init code to phonesim and added
a two sample AID applications to default.xml (ISIM/USIM)
---
 src/default.xml  |  14 +++-
 src/phonesim.cpp |  14 +++-
 src/phonesim.h   |   5 ++
 src/simauth.cpp  | 240 -------------------------------------------------------
 src/simauth.h    |  60 +-------------
 5 files changed, 30 insertions(+), 303 deletions(-)

diff --git a/src/default.xml b/src/default.xml
index 39b0216..b32a488 100644
--- a/src/default.xml
+++ b/src/default.xml
@@ -316,8 +316,6 @@
 
 <!-- SIM Auth -->
 <simauth ki="90dca4eda45b53cf0f12d7c9c3bc6a89" opc="cb9cccc4b9258e6dca4760379fb82581" sqn="000000000021">
-        <aid>61184F10A0000000871004FFFFFFFF890619000050044953494DFFFFFFFFFFFFFF</aid>
-        <aid>61184F10A0000000871002FFFFFFFF890619000050045553494DFFFFFFFFFFFFFF</aid>
 </simauth>
 
 <!-- Time -->
@@ -3680,4 +3678,16 @@ OK</response>
 
 </filesystem>
 
+<application type="ISim" id="61184F10A0000000871004FFFFFFFF890619000050044953494DFFFFFFFFFFFFFF">
+    <filesystem>
+        <file name="EFimpi">
+            <!-- 123456789@phonesim.org -->
+            80 15 31 32 33 34 35 36 37 38 40 70 68 6f 6e 65 73 69 6d 2e 6f 72 67
+        </file>
+    </filesystem>
+</application>
+
+<application type="USim" id="61184F10A0000000871002FFFFFFFF890619000050045553494DFFFFFFFFFFFFFF">
+</application>
+
 </simulator>
diff --git a/src/phonesim.cpp b/src/phonesim.cpp
index ec3900a..0e446f6 100644
--- a/src/phonesim.cpp
+++ b/src/phonesim.cpp
@@ -24,6 +24,7 @@
 #include "simapplication.h"
 #include "callmanager.h"
 #include "simauth.h"
+#include "aidapplication.h"
 #include <qatutils.h>
 
 #include <qstring.h>
@@ -630,13 +631,19 @@ SimRules::SimRules( int fd, QObject *p,  const QString& filename, HardwareManipu
             loadPhoneBook( *n );
 
         } else if ( n->tag == "simauth" ) {
+
             _simAuth = new SimAuth( this, *n );
-            connect( _simAuth, SIGNAL(send(QString)),
-                    this, SLOT(respond(QString)) );
+
+        } else if ( n->tag == "application" ) {
+            AidApplication *app = new AidApplication( this, *n );
+            _applications.append(app);
         }
         n = n->next;
     }
 
+    if ( _applications.length() > 0 )
+        _app_wrapper = new AidAppWrapper( this, _applications, _simAuth );
+
     // Clean up the XML reader objects.
     delete handler;
 
@@ -1137,8 +1144,7 @@ void SimRules::command( const QString& cmd )
     if ( _callManager->command( cmd ) )
         return;
 
-    // Proccess SIM auth commands
-    if ( _simAuth &&  _simAuth->command( cmd ) )
+    if (_app_wrapper && _app_wrapper->command( cmd ))
         return;
 
     // Process SIM toolkit related commands with the current SIM application.
diff --git a/src/phonesim.h b/src/phonesim.h
index 452dc12..c8bcaad 100644
--- a/src/phonesim.h
+++ b/src/phonesim.h
@@ -45,6 +45,7 @@
 #include <arpa/inet.h>
 #include <netinet/in.h>
 
+
 class SimState;
 class SimItem;
 class SimChat;
@@ -54,6 +55,8 @@ class SimFileSystem;
 class CallManager;
 class SimApplication;
 class SimAuth;
+class AidApplication;
+class AidAppWrapper;
 
 
 class SimXmlNode
@@ -360,6 +363,8 @@ private:
 
     CallManager *_callManager;
     SimAuth *_simAuth;
+    QList<AidApplication *> _applications;
+    AidAppWrapper *_app_wrapper;
 
     bool simCsimOk( const QByteArray& payload );
 };
diff --git a/src/simauth.cpp b/src/simauth.cpp
index 54184b6..24b2d17 100644
--- a/src/simauth.cpp
+++ b/src/simauth.cpp
@@ -30,255 +30,15 @@ extern "C" {
 SimAuth::SimAuth( QObject *parent, SimXmlNode& n )
     : QObject( parent )
 {
-    SimXmlNode *child = n.children;
-
     _ki = n.getAttribute( "ki" );
     _opc = n.getAttribute( "opc" );
     _sqn = n.getAttribute( "sqn" );
-    _session_start = 257;
-
-    _aid_list = QStringList();
-
-    // parse list of <aid> </aid>
-    while (child) {
-        if ( child->tag == "aid" )
-            _aid_list += QStringList( child->contents );
-
-        child = child->next;
-    }
 }
 
 SimAuth::~SimAuth()
 {
 }
 
-bool SimAuth::command( const QString& cmd )
-{
-    if ( cmd.startsWith( "AT+CUAD") ) {
-        QString response( "+CUAD: " );
-
-        if ( cmd.contains("=?") ) {
-            emit send( "OK" );
-            return true;
-        }
-
-        foreach ( const QString &str, _aid_list )
-            response += str;
-
-        response.append( "\n\nOK" );
-
-        emit send( response );
-    } else if ( cmd.startsWith( "AT+CCHO" ) ) {
-        QString aid;
-        int session_id = -1;
-
-        if ( !cmd.contains("=") ) {
-            emit send( "ERROR" );
-            return true;
-        }
-
-        if ( cmd.contains("=?") ) {
-            emit send( "OK" );
-            return true;
-        }
-
-        aid = cmd.split('=')[1];
-        aid = aid.replace("\"", "");
-
-        foreach ( const QString &str, _aid_list ) {
-            if ( str.contains( aid ) ) {
-                session_id = openChannel( aid );
-                break;
-            }
-        }
-
-        if ( session_id == -1 ) {
-            emit send( "ERROR" );
-            return true;
-        }
-
-        emit send( QString( "+CCHO: %1\n\nOK" ).arg(session_id, 0, 10) );
-    } else if ( cmd.startsWith( "AT+CGLA" ) ) {
-        QString aid;
-        QString data;
-        QString command;
-        QString parameters;
-        QString response;
-        enum CmdType type;
-        int session_id = -1;
-
-        if ( !cmd.contains("=") ) {
-            emit send( "ERROR" );
-            return true;
-        }
-
-        if ( cmd.contains("=?") ) {
-            emit send( "OK" );
-            return true;
-        }
-
-        data = cmd.split('=')[1];
-        session_id = data.split(',')[0].toInt();
-
-        if (!getAidFromSession( session_id, aid )) {
-            emit send( "ERROR" );
-            return true;
-        }
-
-        data = data.split(',')[2].replace("\"", "");
-        parameters = data.mid(10);
-
-        type = checkCommand( data, aid );
-
-        if (type == CMD_TYPE_GSM_AUTH) {
-            QString sres, kc;
-            QString rand = parameters.mid(2, 32);
-
-            gsmAuthenticate( rand, sres, kc );
-
-            response = QString( "+CGLA: 32,\"04 %1 08 %2 \"\n\nOK" )
-                    .arg( sres, kc );
-            response.replace( " ", "");
-
-        } else if (type == CMD_TYPE_UMTS_AUTH) {
-            enum UmtsStatus status;
-            QString res, ck, ik, auts;
-            QString rand = parameters.mid(2, 32);
-            QString autn = parameters.mid(36, 32);
-
-            status = umtsAuthenticate( rand, autn, res, ck, ik, auts );
-
-            response = QString("+CGLA: ");
-
-            QString test;
-
-            switch (status) {
-            case UMTS_OK:
-                response += QString( "88,\"DB08 %1 10 %2 10 %3\"\n\nOK" )
-                        .arg( res, ck, ik );
-                response.replace( " ", "" );
-
-                break;
-            case UMTS_INVALID_MAC:
-                response += QString( "4,\"%1\"\n\nOK")
-                        .arg( CMD_TYPE_APP_ERROR, 0, 16 );
-
-                break;
-            case UMTS_SYNC_FAILURE:
-                response += QString( "34,\"DC0E %1 \"\n\nOK" ).arg( auts );
-                response.replace( " ", "" );
-
-                break;
-            case UMTS_ERROR:
-                response = QString( "ERROR" );
-
-                break;
-            }
-        } else {
-            response = QString("+CGLA: 4,\"%1\"\n\nOK").arg(type, 0, 16);
-        }
-
-        emit send( response );
-    } else if ( cmd.startsWith( "AT+CCHC" ) ) {
-        int session_id = -1;
-
-        if ( !cmd.contains("=") ) {
-            emit send( "ERROR" );
-            return true;
-        }
-
-        if ( cmd.contains("=?") ) {
-            emit send( "OK" );
-            return true;
-        }
-
-        session_id = cmd.split('=')[1].toInt();
-
-        closeChannel(session_id);
-
-        emit send( "OK" );
-    } else {
-        return false;
-    }
-
-    return true;
-}
-
-int SimAuth::openChannel( QString aid )
-{
-    if ( _logical_channels.size() >= MAX_LOGICAL_CHANNELS )
-        return -1;
-
-    _logical_channels.insert( _session_start, aid );
-
-    return _session_start++;
-}
-
-void SimAuth::closeChannel( int session_id )
-{
-    _logical_channels.remove( session_id );
-}
-
-bool SimAuth::getAidFromSession( int session_id, QString& aid )
-{
-    if ( _logical_channels.contains( session_id ) ) {
-        aid = _logical_channels[session_id];
-        return true;
-    }
-
-    return false;
-}
-
-enum AidType SimAuth::getAidType( QString aid )
-{
-    if ( aid.mid(10, 4) == "1004" )
-        return AID_TYPE_ISIM;
-    else if ( aid.mid(10, 4) == "1002")
-        return AID_TYPE_USIM;
-
-    return AID_TYPE_UNKNOWN;
-}
-
-
-enum CmdType SimAuth::checkCommand( QString command, QString aid )
-{
-    QString cls = command.mid(0, 2);
-    QString ins = command.mid(2, 2);
-    QString p1 = command.mid(4, 2);
-    QString p2 = command.mid(6, 2);
-    QString lc = command.mid(8, 2);
-    AidType type = getAidType( aid );
-
-    if ( cls != "00" )
-        return CMD_TYPE_UNSUPPORTED_CLS;
-
-    if ( ins != "88" )
-        return CMD_TYPE_UNSUPPORTED_INS;
-
-    if ( p1 != "00" )
-        return CMD_TYPE_INCORRECT_P2_P1;
-
-    if ( p2 == "80" ) {
-        if ( lc != "11" )
-            return CMD_TYPE_WRONG_LENGTH;
-
-        if ( !(type == AID_TYPE_USIM || type == AID_TYPE_ISIM) )
-            return CMD_TYPE_APP_ERROR;
-
-        return CMD_TYPE_GSM_AUTH;
-    } else if ( p2 == "81" ) {
-        if ( lc != "22" )
-            return CMD_TYPE_WRONG_LENGTH;
-
-        if ( type != AID_TYPE_ISIM )
-            return CMD_TYPE_APP_ERROR;
-
-        return CMD_TYPE_UMTS_AUTH;
-    } else {
-        return CMD_TYPE_UNKNOWN;
-    }
-}
-
 void SimAuth::gsmAuthenticate( QString rand, QString &sres,
         QString &kc )
 {
diff --git a/src/simauth.h b/src/simauth.h
index a66ea52..fb66593 100644
--- a/src/simauth.h
+++ b/src/simauth.h
@@ -22,26 +22,6 @@
 
 #define MAX_LOGICAL_CHANNELS    4
 
-enum AidType {
-    AID_TYPE_USIM,
-    AID_TYPE_ISIM,
-    AID_TYPE_UNKNOWN
-};
-
-/*
- * Some common errors
- */
-enum CmdType {
-    CMD_TYPE_GSM_AUTH = 0,
-    CMD_TYPE_UMTS_AUTH = 1,
-    CMD_TYPE_UNSUPPORTED_CLS = 0x6E00,
-    CMD_TYPE_UNSUPPORTED_INS = 0x6D00,
-    CMD_TYPE_INCORRECT_P2_P1 = 0x6A86,
-    CMD_TYPE_WRONG_LENGTH = 0x6700,
-    CMD_TYPE_APP_ERROR = 0x9862,
-    CMD_TYPE_UNKNOWN = 0xFFFF
-};
-
 enum UmtsStatus {
     UMTS_OK,            // Success
     UMTS_INVALID_MAC,   // MAC did not match AUTN parameter
@@ -56,12 +36,9 @@ public:
     SimAuth( QObject *parent, SimXmlNode& n );
     ~SimAuth();
 
-    // Process an AT command.  Returns false if not a call-related command.
-    bool command( const QString& cmd );
-
-signals:
-    // Send a response to a command.
-    void send( const QString& line );
+    void gsmAuthenticate( QString rand, QString &sres, QString &kc );
+    enum UmtsStatus umtsAuthenticate( QString rand, QString autn,
+            QString &res, QString &ck, QString &ik, QString &auts );
 
 private:
     // secret key, set during initialization (from XML)
@@ -72,37 +49,6 @@ private:
 
     // Sequence number stored on SIM
     QString _sqn;
-
-    // arbitrary session ID starting number
-    int _session_start;
-
-    // parsed list of AID's
-    QStringList _aid_list;
-
-    // map of logical channel integers to AID's
-    QMap<int, QString> _logical_channels;
-
-    // run COMP128v1 algorithm against 'rand' and 'ki'
-    void gsmAuthenticate( QString rand, QString &sres, QString &kc );
-
-    // run Milenage algorithm with ki, rand, and autn
-    enum UmtsStatus umtsAuthenticate( QString rand, QString autn,
-            QString &res, QString &ck, QString &ik, QString &auts);
-
-    // open an AID logical channel
-    int openChannel( QString aid );
-
-    // close an AID logical channel
-    void closeChannel( int session_id );
-
-    // find the AID from a given session ID
-    bool getAidFromSession( int session_id, QString& aid );
-
-    // checks that the AID supports the given command
-    enum CmdType checkCommand( QString command, QString aid );
-
-    // returns the type of AID (USIM/ISIM/UNKNOWN)
-    enum AidType getAidType( QString aid );
 };
 
 #endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] simfs: Added support for ISim file systems
  2017-11-08 17:23 [PATCH 1/4] simfs: Added support for ISim file systems James Prestwood
                   ` (2 preceding siblings ...)
  2017-11-08 17:23 ` [PATCH 4/4] phonesim/simauth: removed session code from simauth James Prestwood
@ 2017-11-09  2:58 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2017-11-09  2:58 UTC (permalink / raw)
  To: ofono

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

Hi James,

On 11/08/2017 11:23 AM, James Prestwood wrote:
> ---
>   src/simfilesystem.cpp | 100 +++++++++++++++++++++++++++++++++++++++-----------
>   src/simfilesystem.h   |  11 +++++-
>   2 files changed, 89 insertions(+), 22 deletions(-)
> 

All 4 applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-09  2:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-08 17:23 [PATCH 1/4] simfs: Added support for ISim file systems James Prestwood
2017-11-08 17:23 ` [PATCH 2/4] aidapplications: new class for AID applications James Prestwood
2017-11-08 17:23 ` [PATCH 3/4] make: added aidapplication module to build James Prestwood
2017-11-08 17:23 ` [PATCH 4/4] phonesim/simauth: removed session code from simauth James Prestwood
2017-11-09  2:58 ` [PATCH 1/4] simfs: Added support for ISim file systems Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.