📄 profile.cpp
字号:
/* Profile.cpp *//******************************************************************************************* Copyright 2002-2003 ATMEL Corporation. This file is part of ATMEL Wireless LAN Drivers. ATMEL Wireless LAN Drivers is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ATMEL Wireless LAN Drivers 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 ATMEL Wireless LAN Drivers; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*******************************************************************************************/#include "Profile.h"#include "WinterData.h"#include "ChoiceCtrl.h"#include "WinterData.h"#include "Accessor.h"#include "Decls.h"#include "HRStrings.h"#include "WinterSetup.h"#include "WinterDebug.h"#include <wx/filename.h>#include <wx/config.h>#include <wx/fileconf.h>#include <wx/utils.h>#include <wx/tokenzr.h>// CWinterProfile implementation//===============================CWinterProfile::CWinterProfile( const wxString &name ){ mName = name; mDevData = new DEVICE_CONFIGURATION; mWepData = new ENCRYPTION_INFO;}CWinterProfile::~CWinterProfile( ){ delete mDevData; delete mWepData;}void CWinterProfile::SetName( const wxString &name ){ mName = name; return;}wxString CWinterProfile::GetName( ){ return mName;}void CWinterProfile::Import( CWinterModel *model ){ if( model == NULL ) { model = ( CWinterModel * ) CAccessor::Access( AID_CURRENTMODEL ); } CDeviceConfigurationData *dev_data = ( CDeviceConfigurationData * ) model->GetChild( MC_DEVICECONFIGURATIONDATA ); CWepInfoData *wep_data = ( CWepInfoData * ) model->GetChild( MC_WEPINFODATA ); dev_data->Export( mDevData ); wep_data->Export( mWepData ); return;}void CWinterProfile::Import( CDeviceConfigurationData *data ){ data->Export( mDevData ); return;}void CWinterProfile::Import( CWepInfoData *data ){ data->Export( mWepData ); return;}void CWinterProfile::Export( CWinterModel *model ){ if( model == NULL ) { model = ( CWinterModel * ) CAccessor::Access( AID_CURRENTMODEL ); } CDeviceConfigurationData *dev_data = ( CDeviceConfigurationData * ) model->GetChild( MC_DEVICECONFIGURATIONDATA ); CWepInfoData *wep_data = ( CWepInfoData * ) model->GetChild( MC_WEPINFODATA ); dev_data->Import( mDevData ); wep_data->Import( mWepData ); return;}void CWinterProfile::Export( CDeviceConfigurationData *data ){ data->Import( mDevData ); return;}void CWinterProfile::Export( CWepInfoData *data ){ data->Import( mWepData ); return;}// CWinterProfileManager implementation//======================================CWinterProfileManager::CWinterProfileManager( ){ mProfiles.Empty( );}CWinterProfileManager::~CWinterProfileManager( ){}bool CWinterProfileManager::AddProfile( CWinterProfile *profile ){ if( GetProfile( profile->GetName( ) ) != NULL ) { return false; } mProfiles.Add( profile ); return true;}bool CWinterProfileManager::RemoveProfile( CWinterProfile *profile ){ int index = mProfiles.Index( profile ); if( index != wxNOT_FOUND ) { mProfiles.RemoveAt( index ); return true; } return false;}int CWinterProfileManager::CountProfiles( ){ return mProfiles.GetCount( );}CWinterProfile *CWinterProfileManager::GetProfile( int index ){ if ( mProfiles.GetCount( ) != 0 ) { return mProfiles[ index ]; } return NULL;}CWinterProfile *CWinterProfileManager::GetProfile( const wxString &name ){ CWinterProfile *ret = NULL; CWinterProfile *current = NULL; int count = mProfiles.GetCount( ); for( int c = 0; c < count; c++ ) { current = mProfiles[ c ]; if( current->GetName( ) == name ) { ret = current; break; } } return ret;}CWinterProfile *CWinterProfileManager::operator[]( int index ){ return GetProfile( index );}bool CWinterProfileManager::LoadFile( const wxString &str_filename ){#ifndef __WXMSW__ // This code fails under MSW. wxFileName filename; wxString ssid; CDeviceConfigurationData *dev_data = new CDeviceConfigurationData( NULL, NULL ); CWepInfoData *wep_data = new CWepInfoData( NULL, NULL ); CWinterProfile *profile; // If no filename is specified, use the default. if( str_filename == wxT( "" ) ) { filename.Assign( wxGetHomeDir( ) + wxT( "/.winter/" ), wxT( "profilesrc" ) ); if( wxFileName::DirExists( wxGetHomeDir( ) + wxT( "/.winter/" ) ) == false ) { wxFileName::Mkdir( wxGetHomeDir( ) + wxT( "/.winter/" ), 0700 ); } } else { filename = str_filename; } wxConfigBase *config = new wxFileConfig( wxT( "" ), wxT( "" ), filename.GetFullPath( ), filename.GetFullPath( ) ); wxString subgroup; long dummy; UCHAR *key; wxString temp_str; long temp; for( int c = 0; c < config->GetNumberOfGroups( ); c++ ) { if( c == 0 ) { config->GetFirstGroup( subgroup, dummy ); } else { config->GetNextGroup( subgroup, dummy ); } profile = new CWinterProfile( subgroup ); subgroup = wxT( "/" ) + subgroup + wxT( "/" ); // Device configuration config->Read( subgroup + wxT( "OperatingMode" ), &temp ); dev_data->SetOperatingMode( temp ); config->Read( subgroup + wxT( "Channel" ), &temp); dev_data->SetChannel( temp ); config->Read( subgroup + wxT( "SSID" ), &ssid ); dev_data->SetSSID( ( unsigned char * ) ssid.c_str( ) ); dev_data->SetSSIDLength( ssid.Len( ) ); config->Read( subgroup + wxT( "TxRate" ), &temp ); dev_data->SetTxRate( temp ); config->Read( subgroup + wxT( "InternationalRoaming" ), &temp ); dev_data->SetInternationalRoaming( temp ); config->Read( subgroup + wxT( "RadioIsOn" ), &temp ); dev_data->SetRadioIsOn( temp ); config->Read( subgroup + wxT( "PreambleType" ), &temp ); dev_data->SetPreambleType( temp ); config->Read( subgroup + wxT( "PowerSaveMode" ), &temp ); dev_data->SetPowerMgmtMode( temp ); config->Read( subgroup + wxT( "FragmentationThreshold" ), &temp ); dev_data->SetFragmentationThreshold( temp ); config->Read( subgroup + wxT( "RtsCtsThreshold" ), &temp ); dev_data->SetRtsCtsThreshold( temp ); // Wep configuration config->Read( subgroup + wxT( "WepKeyToUse" ), &temp ); wep_data->SetWepKeyToUse( temp ); config->Read( subgroup + wxT( "WepMode" ), &temp ); wep_data->SetWepMode( temp ); config->Read( subgroup + wxT( "AuthenticationType" ), &temp ); wep_data->SetAuthenticationType( temp ); config->Read( subgroup + wxT( "EncryptionLevel" ), &temp ); wep_data->SetEncryptionLevel( temp );#ifdef ATMEL_WLAN key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; for(int i=0; i< MAX_ENCRYPTION_KEYS; i++) { config->Read( subgroup + wxT( "WepKey" ) + wxT( char(i+0x31) ), &temp_str ); if( temp_str.Len( ) <= LONG_WEP_KEY_SIZE ) { memset( key, 0, LONG_WEP_KEY_SIZE + 1 ); strcpy( ( char * ) key, temp_str.c_str( ) ); wep_data->SetWepKey( key, i ); } } delete key;#else if( temp_str.Len( ) <= LONG_WEP_KEY_SIZE ) { key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memset( key, 0, LONG_WEP_KEY_SIZE + 1 ); strcpy( ( char * ) key, temp_str.c_str( ) ); wep_data->SetWepKey1( key ); delete key; } config->Read( subgroup + wxT( "WepKey2" ), &temp_str ); if( temp_str.Len( ) <= LONG_WEP_KEY_SIZE ) { key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memset( key, 0, LONG_WEP_KEY_SIZE + 1 ); strcpy( ( char * ) key, temp_str.c_str( ) ); wep_data->SetWepKey2( key ); delete key; } config->Read( subgroup + wxT( "WepKey3" ), &temp_str ); if( temp_str.Len( ) <= LONG_WEP_KEY_SIZE ) { key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memset( key, 0, LONG_WEP_KEY_SIZE + 1 ); strcpy( ( char * ) key, temp_str.c_str( ) ); wep_data->SetWepKey3( key ); delete key; } config->Read( subgroup + wxT( "WepKey4" ), &temp_str ); if( temp_str.Len( ) <= LONG_WEP_KEY_SIZE ) { key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memset( key, 0, LONG_WEP_KEY_SIZE + 1 ); strcpy( ( char * ) key, temp_str.c_str( ) ); wep_data->SetWepKey4( key ); delete key; }#endif profile->Import( dev_data ); profile->Import( wep_data ); AddProfile( profile ); } delete dev_data; delete wep_data; delete config;#endif // __WXMSW__ return true;}bool CWinterProfileManager::SaveFile( const wxString &str_filename ){#ifndef __WXMSW__ // This code fails under MSW. wxFileName filename; wxString ssid; CDeviceConfigurationData *dev_data = new CDeviceConfigurationData( NULL, NULL ); CWepInfoData *wep_data = new CWepInfoData( NULL, NULL ); CWinterProfile *profile; // If no filename is specified, use the default. if( str_filename == wxT( "" ) ) { filename.Assign( wxGetHomeDir( ) + wxT( "/.winter/" ), wxT( "profilesrc" ) ); if( wxFileName::DirExists( wxGetHomeDir( ) + wxT( "/.winter/" ) ) == false ) { wxFileName::Mkdir( wxGetHomeDir( ) + wxT( "/.winter/" ), 0700 ); } } else { filename = str_filename; } ::wxRemoveFile( filename.GetFullPath( ) ); wxConfigBase *config = new wxFileConfig( wxT( "" ), wxT( "" ), filename.GetFullPath( ), filename.GetFullPath( ) ); CWepKeyFilter filter; wxString subgroup; UCHAR *key; for( int c = 0; c < CountProfiles( ); c++ ) { profile = GetProfile( c ); profile->Export( dev_data ); profile->Export( wep_data ); subgroup = wxT( "/" ) + profile->GetName( ) + wxT( "/" ); config->Write( subgroup + wxT( "OperatingMode" ), ( long ) dev_data->GetOperatingMode( ) ); config->Write( subgroup + wxT( "Channel" ), ( long ) dev_data->GetChannel( ) ); ssid.Clear( ); for( int j = 0; j < dev_data->GetSSIDLength( ); j++ ) { ssid.Append( dev_data->GetSSID( )[ j ] ); } // Device configuration config->Write( subgroup + wxT( "SSID" ), ssid ); config->Write( subgroup + wxT( "TxRate" ), ( long ) dev_data->GetTxRate( ) ); config->Write( subgroup + wxT( "InternationalRoaming" ), ( long ) dev_data->GetInternationalRoaming( ) ); config->Write( subgroup + wxT( "RadioIsOn" ), ( long ) dev_data->GetRadioIsOn( ) ); config->Write( subgroup + wxT( "PreambleType" ), ( long ) dev_data->GetPreambleType( ) ); config->Write( subgroup + wxT( "PowerSaveMode" ), ( long ) dev_data->GetPowerMgmtMode( ) ); config->Write( subgroup + wxT( "FragmentationThreshold" ), ( long ) dev_data->GetFragmentationThreshold( ) ); config->Write( subgroup + wxT( "RtsCtsThreshold" ), ( long ) dev_data->GetRtsCtsThreshold( ) ); // Wep configuration config->Write( subgroup + wxT( "WepKeyToUse" ), ( long ) wep_data->GetWepKeyToUse( ) ); config->Write( subgroup + wxT( "WepMode" ), ( long ) wep_data->GetWepMode( ) ); config->Write( subgroup + wxT( "AuthenticationType" ), ( long ) wep_data->GetAuthenticationType( ) ); config->Write( subgroup + wxT( "EncryptionLevel" ), ( long ) wep_data->GetEncryptionLevel( ) );#ifdef ATMEL_WLAN key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; for(int i=0; i< MAX_ENCRYPTION_KEYS; i++) { memcpy( key, wep_data->GetWepKey(i), LONG_WEP_KEY_SIZE ); key[ LONG_WEP_KEY_SIZE ] = 0; config->Write( subgroup + wxT( "WepKey" ) + wxT( char(i+0x31) ), wxString( key ) ); } delete key;#else key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memcpy( key, wep_data->GetWepKey1( ), LONG_WEP_KEY_SIZE ); key[ LONG_WEP_KEY_SIZE ] = 0; config->Write( subgroup + wxT( "WepKey1" ), wxString( key ) ); delete key; key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memcpy( key, wep_data->GetWepKey2( ), LONG_WEP_KEY_SIZE ); key[ LONG_WEP_KEY_SIZE ] = 0; config->Write( subgroup + wxT( "WepKey2" ), wxString( key ) ); delete key; key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memcpy( key, wep_data->GetWepKey3( ), LONG_WEP_KEY_SIZE ); key[ LONG_WEP_KEY_SIZE ] = 0; config->Write( subgroup + wxT( "WepKey3" ), wxString( key ) ); delete key; key = new UCHAR[ LONG_WEP_KEY_SIZE + 1 ]; memcpy( key, wep_data->GetWepKey4( ), LONG_WEP_KEY_SIZE ); key[ LONG_WEP_KEY_SIZE ] = 0; config->Write( subgroup + wxT( "WepKey4" ), wxString( key ) ); delete key;#endif } config->Flush( ); delete dev_data; delete wep_data; delete config;#endif // __WXMSW__ return true;}// CWinterProfileManagerSingleton class implementation//=====================================================CWinterProfileManager *CWinterProfileManagerSingleton::mManager = NULL;CWinterProfileManagerSingleton::CWinterProfileManagerSingleton( ){}CWinterProfileManagerSingleton::~CWinterProfileManagerSingleton( ){}CWinterProfileManager *CWinterProfileManagerSingleton::Get( ){ if( mManager == NULL ) { mManager = new CWinterProfileManager( ); } return mManager;}// CWepKeyFilter class implementation//====================================CWepKeyFilter::CWepKeyFilter( ){}CWepKeyFilter::CWepKeyFilter( const wxString &input, bool ishex ){ SetWepKey( input, ishex );}CWepKeyFilter::~CWepKeyFilter( ){}void CWepKeyFilter::Clear( ){ mHex = wxT( "" ); mAscii = wxT( "" ); return;}bool CWepKeyFilter::SetWepKey( const wxString &key, bool ishex ){ int c; int count; Clear( ); if( ishex == false ) { count = key.Len( ); for( c = 0; c < count - 1; c++ ) { mHex.Append( wxString::Format( wxT( "%02X " ), key[ c ] ) ); } if( count != 0 ) { mHex.Append( wxString::Format( wxT( "%02X" ), key[ count - 1 ] ) ); } return true; } wxString cpkey = key; wxString token; wxString tmp; cpkey.Strip( wxString::both ); wxStringTokenizer tkn( cpkey, wxT( " " ) ); count = tkn.CountTokens( ); for( c = 0; c < count; c++ ) { token = tkn.GetNextToken( ); mAscii.Append( wxString::Format( wxT( "%c" ), strtol( token.c_str( ), NULL, 16 ) ) ); } return true;}wxString CWepKeyFilter::GetWepKey( bool ishex ){ if( ishex == true ) { return mHex; } return mAscii;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -