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

wlan_NNI.cpp

Go to the documentation of this file.
00001 #include <unistd.h>
00002 #include "wlanedit.h"
00003 #include "wlan_NNI.h"
00004 #include "wlan_NN.h"
00005 
00006 AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) {
00007     GUI = 0;
00008     RT = 0;
00009     Data.ESSID = "";
00010     Data.NodeName = tr("<UseHostName>");
00011     Data.Mode = 0;
00012     Data.SpecificAP = 0;
00013     Data.APMac = "";
00014     Data.Encrypted = 0;
00015     Data.AcceptNonEncrypted = 0;
00016     Data.Key[0] = "";
00017     Data.Key[1] = "";
00018     Data.Key[2] = "";
00019     Data.Key[3] = "";
00020 }
00021 
00022 void AWLan::setSpecificAttribute( QString & A, QString & V ) {
00023     if( A == "essid" ) {
00024       Data.ESSID = V;
00025     } else if( A == "nodename" ) {
00026       Data.NodeName = V;
00027     } else if( A == "mode" ) {
00028       Data.Mode = V.toShort();
00029     } else if( A == "specificap" ) {
00030       Data.SpecificAP = (V=="yes");
00031     } else if( A == "apmac" ) {
00032       Data.APMac = V;
00033     } else if( A == "encrypted" ) {
00034       Data.Encrypted = (V=="yes");
00035     } else if( A == "acceptnonencrypted" ) {
00036       Data.AcceptNonEncrypted = (V=="yes");
00037     } else if( A == "key0" ) {
00038       Data.Key[0] = V;
00039     } else if( A == "key1" ) {
00040       Data.Key[1] = V;
00041     } else if( A == "key2" ) {
00042       Data.Key[2] = V;
00043     } else if( A == "key3" ) {
00044       Data.Key[3] = V;
00045     }
00046 }
00047 
00048 void AWLan::saveSpecificAttribute( QTextStream & S ) {
00049     S << "essid=" << quote( Data.ESSID ) << endl;
00050     S << "nodename=" << quote( Data.NodeName ) << endl;
00051     S << "mode=" << Data.Mode << endl;
00052     S << "specificap=" 
00053       << ((Data.SpecificAP) ? "yes" : "no") 
00054       << endl;
00055     S << "apmac=" << Data.APMac << endl;
00056     S << "encrypted=" 
00057       << ((Data.Encrypted) ? "yes" : "no") 
00058       << endl;
00059     S << "acceptnonencrypted=" 
00060       << ((Data.AcceptNonEncrypted) ? "yes" : "no") 
00061       << endl;
00062     for( int i = 0 ;i < 4 ; i ++ ) {
00063       S << "key" << i << "=" << Data.Key[i] << endl;
00064     }
00065 }
00066 
00067 QWidget * AWLan::edit( QWidget * parent ) {
00068     GUI = new WLanEdit( parent, this );
00069     GUI->showData( Data );
00070     return GUI;
00071 }
00072 
00073 QString AWLan::acceptable( void ) {
00074     return ( GUI ) ? GUI->acceptable( ) : QString();
00075 }
00076 
00077 void AWLan::commit( void ) {
00078     if( GUI && GUI->commit( Data ) )
00079       setModified( 1 );
00080 }
00081 
00082 short AWLan::generateFileEmbedded( SystemFile & SF,
00083                                   long DevNr ) {
00084 
00085       short rvl, rvd;
00086 
00087       rvl = 1;
00088 
00089       if( SF.name() == "interfaces" ) {
00090         Log(("Generate WLanNNI for %s\n", SF.name().latin1() ));
00091         SF << "  wireless_essid \""
00092            << Data.ESSID
00093            << "\""
00094            << endl;
00095 
00096         if( ! Data.NodeName.isEmpty() ) {
00097           if( Data.NodeName == tr("<UseHostName>") ) {
00098             char Buf[100];
00099             if( gethostname(Buf, sizeof(Buf) ) == 0 ) {
00100               Buf[99] = '\0'; // just to make sure
00101               SF << "  wireless_nick "  
00102                  << Buf
00103                  << endl;
00104             }
00105           } else {
00106             SF << "  wireless_nick \""  
00107                << Data.NodeName
00108                << "\""
00109                << endl;
00110           }
00111         }
00112 
00113         char * M = "Auto";
00114         switch ( Data.Mode ) {
00115           case 0 : 
00116             break;
00117           case 1 : 
00118             M = "Managed";
00119             break;
00120           case 2 : 
00121             M = "Ad-Hoc";
00122             break;
00123         }
00124 
00125         SF << "  wireless_mode "
00126            << M
00127            << endl;
00128         if( Data.Encrypted ) {
00129           for( int i = 0; i < 4; i ++ ) {
00130             if( ! Data.Key[i].isEmpty() ) {
00131               SF << "  wireless_key"
00132                  << i
00133                  << " "
00134                  << Data.Key[i]
00135                  << endl;
00136             }
00137           }
00138           SF << "  wireless_keymode "
00139              << ((Data.AcceptNonEncrypted) ? "open" : "restricted")
00140              << endl;
00141         }
00142         rvl = 0;
00143       }
00144       rvd = ANetNodeInstance::generateFileEmbedded( SF, DevNr);
00145 
00146       return (rvd == 2 || rvl == 2 ) ? 2 :
00147              (rvd == 0 || rvl == 0 ) ? 0 : 1;
00148 }
00149 

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