From fd7f01f309c9baae8eb84cfa903c932dce388b66 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Marco=20Trevisan=20(Trevi=C3=B1o)?= <mail@3v1n0.net>
Date: Wed, 15 Oct 2008 07:58:17 +0200
Subject: [PATCH] Restart the GSM modem on firmware crash
 Sometimes I got the firmware crash error, after some changes I've seen
 that after stopping and reloading the GSM hardware (and Qtopia) I was
 again able to use my phone.
 So this patch tries to get the same: on modem crash it retries to power
 up and down the modem (max 3 times, waiting for the user input to restart
 it) and then it re-init the modem plugin.

---
 .../phonevendors/ficgta01/vendor_ficgta01.cpp      |   46 +++++++++++++++----
 .../phonevendors/ficgta01/vendor_ficgta01_p.h      |    2 +
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
index 4847634..8ca1874 100644
--- a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
+++ b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
@@ -434,11 +434,17 @@ Ficgta01ModemService::Ficgta01ModemService
         ( const QString& service, QSerialIODeviceMultiplexer *mux,
           QObject *parent )
     : QModemService( service, mux, parent )
-    , m_vibratorService( 0 )
-    , m_phoneBook( 0 )
-    , m_phoneBookIsReady( false )
-    , m_smsIsReady( false )
 {
+    modemServiceInit();
+}
+
+void Ficgta01ModemService::modemServiceInit()
+{
+    m_vibratorService = 0;
+    m_phoneBook = 0;
+    m_phoneBookIsReady = false;
+    m_smsIsReady = false;
+    
     connect( this, SIGNAL(resetModem()), this, SLOT(reset()) );
 
     // Register a wakeup command to ping the modem if we haven't
@@ -753,20 +759,40 @@ void Ficgta01ModemService::cstatNotification( const QString& msg )
 // there will be a GUI connection.
 void Ficgta01ModemService::modemDied()
 {
-    static bool claimedDead = false;
-    if (claimedDead)
+    static int retry = 1;
+    if (retry > 3)
         return;
 
-    claimedDead = true;
-
     if (m_vibratorService)
         m_vibratorService->setVibrateNow(true);
+
+    modemPower(false);
+
     QMessageBox::information(0, tr("Modem Died"),
                              tr("The firmware of the modem appears to have crashed. "
-                                "No further interaction with the modem will be possible. "
-                                "Please restart the device."), QMessageBox::Ok);
+                                "No further interaction with the modem is actually possible. "
+                                "Qtopia will now try to recover the GSM modem."
+                                "If your telephony won't work anymore, please restart the device."), QMessageBox::Ok);
+                                
+    modemPower(true);
+    retry++;
+
     if (m_vibratorService)
         m_vibratorService->setVibrateNow(false);
+        
+    modemServiceInit();
+}
+
+void Ficgta01ModemService::modemPower(bool on = true)
+{
+    QFile gsmPower("/sys/devices/platform/neo1973-pm-gsm.0/power_on");
+    gsmPower.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
+    QTextStream out(&gsmPower);
+    if (on)
+        out << "1";
+    else
+        out << "0";
+    gsmPower.close();
 }
 
 void Ficgta01ModemService::echoCancellation(QAtChat* atChat)
diff --git a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
index 92e5aae..0f3f53f 100644
--- a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
+++ b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
@@ -131,6 +131,7 @@ public:
     static void echoCancellation( QAtChat* );
 
 private slots:
+    void modemServiceInit();
     void csq( const QString& msg );
     void csqTimeOut();
     void firstCsqQuery();
@@ -143,6 +144,7 @@ private slots:
     void sendSuspendDone();
 
     void modemDied();
+    void modemPower( bool on );
 
 private slots:
     void cstatNotification( const QString& msg );
-- 
1.5.4.3


