Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GPRS_NNI.cpp

Go to the documentation of this file.
00001 #include <system.h>
00002 #include <netnode.h>
00003 #include "GPRSedit.h"
00004 #include "GPRS_NNI.h"
00005 #include "GPRS_NN.h"
00006 
00007 AGPRSDevice::AGPRSDevice( GPRSNetNode * PNN ) : ANetNodeInstance( PNN ) {
00008     Data.APN = "";
00009     Data.User = "";
00010     Data.Password = "";
00011     Data.DefaultGateway = 1;
00012     Data.SetIfSet = 0;
00013     Data.Debug = 0;
00014     Data.Routing.setAutoDelete( TRUE );
00015     GUI = 0;
00016     RT = 0;
00017 }
00018 
00019 void AGPRSDevice::setSpecificAttribute( QString & A, QString & V ) {
00020     if( A == "apn" ) {
00021       Data.APN = V;
00022     } else if( A == "user" ) {
00023       Data.User = V;
00024     } else if( A == "password" ) {
00025       Data.Password = V;
00026     } else if( A == "dns2" ) {
00027       Data.DNS2 = V;
00028     } else if( A == "dns1" ) {
00029       Data.DNS1 = V;
00030     } else if( A == "defaultgateway" ) {
00031       Data.DefaultGateway = (V=="yes");
00032     } else if( A == "setifset" ) {
00033       Data.SetIfSet = (V == "yes");
00034     } else if( A == "routes" ) {
00035       Data.Routing.resize( V.toULong() );
00036     } else if( A.startsWith( "route" ) ) {
00037       QStringList SL = QStringList::split( "/", V );
00038       GPRSRoutingEntry * E = new GPRSRoutingEntry;
00039 
00040       E->Address = SL[0];
00041       E->Mask = SL[1].toULong();
00042 
00043       Data.Routing.insert( A.mid(5).toULong(), E );
00044     } else if( A == "debug" ) {
00045       Data.Debug = V.toShort();
00046     }
00047 }
00048 
00049 void AGPRSDevice::saveSpecificAttribute( QTextStream & TS ) {
00050     TS << "apn=" << Data.APN << endl;
00051     TS << "user=" << Data.User << endl;
00052     TS << "password=" << Data.Password << endl;
00053     TS << "dns1=" << Data.DNS1 << endl;
00054     TS << "dns2=" << Data.DNS2 << endl;
00055     TS << "defaultgateway=" << ( (Data.DefaultGateway) ? "yes" : "no" ) << endl;
00056     TS << "setifset=" << ((Data.SetIfSet) ? "yes" : "no") << endl;
00057     TS << "debug=" << Data.Debug << endl;
00058 
00059     TS << "routes=" << Data.Routing.count() << oendl;
00060     for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) {
00061       TS << "route" << i << "="
00062          << Data.Routing[i]->Address
00063          << "/"
00064          << Data.Routing[i]->Mask
00065          << oendl;
00066     }
00067 }
00068 
00069 QWidget * AGPRSDevice::edit( QWidget * parent ) {
00070     GUI = new GPRSEdit( parent );
00071     GUI->showData( Data );
00072     return GUI;
00073 }
00074 
00075 QString AGPRSDevice::acceptable( void ) {
00076     return ( GUI ) ? GUI->acceptable( ) : QString();
00077 }
00078 
00079 void AGPRSDevice::commit( void ) {
00080     if( GUI && GUI->commit( Data ) )
00081       setModified( 1 );
00082 }
00083 
00084 bool AGPRSDevice::hasDataForFile( SystemFile & S ) {
00085       return S.name() == "pap-secrets" ||
00086              S.name() == "peers" ||
00087              S.name() == "extra" ||
00088              S.name() == "chatscripts" ;
00089 }
00090 
00091 short AGPRSDevice::generateFile( SystemFile & SF,
00092                                  long 
00093                                ) {
00094 
00095     if( SF.name() == "pap-secrets" ) {
00096       SF << Data.User 
00097          << " * " 
00098          << Data.Password 
00099          << " *" 
00100          << endl;
00101       return 0;
00102     } else if( SF.name() == "chatscripts" ) {
00103       SF << "SAY          \"Starting\\n\"" << oendl;
00104       SF << "ECHO         OFF" << oendl;
00105       SF << "ABORT        BUSY" << oendl;
00106       SF << "ABORT        ERROR" << oendl;
00107       SF << "ABORT        VOICE" << oendl;
00108       SF << "ABORT        \"NO CARRIER\"" << oendl;
00109       SF << "ABORT        \"NO DIALTONE\"" << oendl;
00110       SF << "\"\"           AT" << oendl;
00111       SF << "OK           AT+CGATT=1" << oendl;
00112       SF << "OK           AT+CGDCONT=1,\"IP\",\""
00113          << Data.APN 
00114          << "\"" 
00115          << oendl;
00116       SF << "OK           ATD*99***1#\\n" << oendl;
00117       SF << "TIMEOUT      10" << oendl;
00118       SF << "CONNECT      \"\"" << oendl;
00119       SF << "SAY          \"READY\\n\"" << oendl;
00120       return 0;
00121     } else if( SF.name() == "peers" ) {
00122       SF << "noauth" << oendl;
00123       SF << "user " << Data.User << oendl;
00124       SF << "connect \"/usr/sbin/chat -s -v -f /etc/chatscripts/" 
00125          << removeSpaces( networkSetup()->name() ) 
00126          << "\"" 
00127          << oendl;
00128       SF << "ipcp-accept-local" << oendl;
00129       SF << "ipcp-accept-remote" << oendl;
00130       if( Data.DefaultGateway ) {
00131         SF << "defaultroute" << oendl;
00132         if( Data.SetIfSet ) {
00133           SF << "replacedefaultroute" << oendl;
00134         }
00135       }
00136       if( Data.Debug ) {
00137         SF << "logfile /tmp/" 
00138            << removeSpaces( networkSetup()->name() ) 
00139            << oendl;
00140         for( int i = 0; i < Data.Debug; i ++ ) {
00141           SF << "debug" << oendl;
00142         }
00143       }
00144       SF << "nocrtscts" << oendl;
00145       SF << "local" << oendl;
00146       SF << "lcp-echo-interval 0" << oendl;
00147       SF << "lcp-echo-failure 0" << oendl;
00148       SF << "usepeerdns" << oendl;
00149       SF << "linkname " << removeSpaces( networkSetup()->name() ) << oendl;
00150       SF << "nopersist" << oendl;
00151       SF << "ipparam " << removeSpaces( networkSetup()->name() ) <<oendl;
00152       SF << "maxfail 1" << oendl;
00153       return 0;
00154     } else if( SF.name() == "extra" ) {
00155       unsigned long Bits;
00156       // generate 'fixed' settings
00157       for( unsigned int i = 0 ; 
00158            i < Data.Routing.count();
00159            i ++ ) {
00160         if( Data.Routing[i]->Mask == 32 ) {
00161           Bits = 0xffffffff;
00162         } else {
00163           Bits = ~ ((1 << ((32-Data.Routing[i]->Mask))) - 1);
00164         }
00165         SF << "route add -net "
00166            << Data.Routing[i]->Address
00167            << " netmask "
00168            << ((Bits&0xff000000)>>24)
00169            << "."
00170            << ((Bits&0x00ff0000)>>16)
00171            << "."
00172            << ((Bits&0x0000ff00)>>8)
00173            << "."
00174            << ((Bits&0x000000ff))
00175            << " gw $PPP_REMOTE"
00176            << oendl;
00177         SF << "route del -net "
00178            << Data.Routing[i]->Address
00179            << " netmask "
00180            << ((Bits&0xff000000)>>24)
00181            << "."
00182            << ((Bits&0x00ff0000)>>16)
00183            << "."
00184            << ((Bits&0x0000ff00)>>8)
00185            << "."
00186            << ((Bits&0x000000ff))
00187            << " gw $PPP_REMOTE"
00188            << oendl;
00189       }
00190 
00191       if( ! Data.DNS1.isEmpty() ) {
00192         SF << "nameserver "
00193            << Data.DNS1
00194            << " # profile "
00195            << removeSpaces( networkSetup()->name() )
00196            <<oendl;
00197       }
00198 
00199       if( ! Data.DNS2.isEmpty() ) {
00200         SF << "nameserver "
00201            << Data.DNS2
00202            << " # profile "
00203            << removeSpaces( networkSetup()->name() )
00204            <<oendl;
00205       }
00206     }
00207     return 1;
00208 }
00209 
00210 bool AGPRSDevice::openFile( SystemFile & SF, QStringList & SL ) {
00211     if( SF.name() == "peers" ) {
00212       SL << "/etc" << "ppp" << "peers";
00213       SF.setPath( 
00214           QString( "/etc/ppp/peers/" ) + 
00215               removeSpaces( networkSetup()->name() )
00216           );
00217       return 1;
00218     } else if ( SF.name() == "chatscripts" ) {
00219       SL << "/etc" << "chatscripts";
00220       SF.setPath( 
00221           QString( "/etc/chatscripts/" ) + 
00222               removeSpaces( networkSetup()->name() )
00223           );
00224       return 1;
00225       SL << "/etc" << "ppp";
00226     } else if ( SF.name() == "extra" ) {
00227       SF.setPath( 
00228           QString( "/etc/ppp/" ) + 
00229               removeSpaces( networkSetup()->name() ) + ".fixed"
00230           );
00231       return 1;
00232     }
00233     return 0;
00234 }

Generated on Sat Nov 5 16:17:53 2005 for OPIE by  doxygen 1.4.2