Diffstat (limited to 'noncore/net/networksetup/wlan/wlanimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/networksetup/wlan/wlanimp.cpp | 415 |
1 files changed, 200 insertions, 215 deletions
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index 01d7e36..689eae2 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp | |||
@@ -1,10 +1,5 @@ | |||
1 | #include "wlanimp.h" | 1 | #include "wlanimp.h" |
2 | #include "interfacesetupimp.h" | ||
2 | 3 | ||
3 | /* Config class */ | ||
4 | #include <qpe/config.h> | ||
5 | /* Global namespace */ | ||
6 | #include <qpe/global.h> | ||
7 | /* system() */ | ||
8 | #include <stdlib.h> | ||
9 | #include <qfile.h> | 4 | #include <qfile.h> |
10 | #include <qdir.h> | 5 | #include <qdir.h> |
@@ -15,233 +10,223 @@ | |||
15 | #include <qradiobutton.h> | 10 | #include <qradiobutton.h> |
16 | #include <qcheckbox.h> | 11 | #include <qcheckbox.h> |
17 | #include <qregexp.h> | ||
18 | #include <qpe/config.h> | ||
19 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
20 | #include "interfacesetupimp.h" | ||
21 | 13 | ||
22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ | 14 | /* system() */ |
23 | config = new Config("wireless"); | 15 | #include <stdlib.h> |
24 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose); | ||
25 | //configure->setProfile(currentProfile); | ||
26 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | ||
27 | 16 | ||
28 | readConfig(); | 17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
29 | 18 | ||
30 | } | 19 | /** |
20 | * Constructor, read in the wireless.opts file for parsing later. | ||
21 | */ | ||
22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { | ||
23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); | ||
24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | ||
31 | 25 | ||
32 | WLANImp::~WLANImp( ){ | 26 | // Read in the config file. |
33 | delete config; | 27 | QString wlanFile = WIRELESS_OPTS; |
28 | QFile file(wlanFile); | ||
29 | if (file.open(IO_ReadOnly)){ | ||
30 | QTextStream stream( &file ); | ||
31 | QString line = ""; | ||
32 | while ( !stream.eof() ) { | ||
33 | line += stream.readLine(); | ||
34 | line += "\n"; | ||
35 | } | ||
36 | file.close(); | ||
37 | settingsFileText = QStringList::split("\n", line, true); | ||
38 | parseSettingFile(); | ||
39 | } | ||
40 | else | ||
41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); | ||
34 | } | 42 | } |
35 | 43 | ||
44 | /** | ||
45 | * Change the profile for both wireless settings and network settings. | ||
46 | */ | ||
36 | void WLANImp::setProfile(QString &profile){ | 47 | void WLANImp::setProfile(QString &profile){ |
37 | interfaceSetup->setProfile(profile); | 48 | interfaceSetup->setProfile(profile); |
49 | parseSettingFile(); | ||
38 | } | 50 | } |
39 | 51 | ||
40 | void WLANImp::readConfig() | 52 | /** |
41 | { | 53 | * Parses the settings file that was read in and gets any setting from it. |
42 | qWarning( "WLANImp::readConfig() called." ); | 54 | */ |
43 | config->setGroup( "Properties" ); | 55 | void WLANImp::parseSettingFile(){ |
44 | QString ssid = config->readEntry( "SSID", "any" ); | 56 | bool foundCase = false; |
45 | if( ssid == "any" || ssid == "ANY" ){ | 57 | bool found = false; |
46 | essNon->setChecked( true ); | 58 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
47 | } else { | 59 | QString line = (*it).simplifyWhiteSpace(); |
48 | essSpecific->setChecked( true ); | 60 | if(line.contains("case")) |
49 | essSpecificLineEdit->setText( ssid ); | 61 | foundCase = true; |
50 | } | 62 | // See if we found our scheme to write or the sceme couldn't be found |
51 | QString mode = config->readEntry( "Mode", "Managed" ); | 63 | if((foundCase && line.contains("esac")) || |
52 | if( mode == "adhoc" ) { | 64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) |
53 | network802->setChecked( true ); | 65 | found = true; |
54 | } else { | 66 | |
55 | networkInfrastructure->setChecked( true ); | 67 | if(line.contains(";;")) |
56 | } | 68 | found = false; |
57 | networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); | 69 | if(found){ |
58 | // config->readEntry( "RATE", "auto" ); | 70 | // write out scheme |
59 | config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); | 71 | if(line.contains("ESSID=")){ |
60 | config->readEntry( "AuthType", "opensystem" ); | 72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); |
61 | config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); | 73 | if(id == "any"){ |
62 | int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); | 74 | essNon->setChecked(true); |
63 | switch( defaultkey ){ | 75 | essSpecific->setChecked(false); |
64 | case 0: | 76 | }else{ |
65 | keyRadio0->setChecked( true ); | 77 | essSpecific->setChecked(true); |
66 | break; | 78 | essSpecificLineEdit->setText(id); |
67 | case 1: | 79 | essNon->setChecked(false); |
68 | keyRadio1->setChecked( true ); | 80 | } |
69 | break; | 81 | } |
70 | case 2: | 82 | if(line.contains("MODE=")){ |
71 | keyRadio2->setChecked( true ); | 83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); |
72 | break; | 84 | if(mode == "Managed"){ |
73 | case 3: | 85 | network802->setChecked( false ); |
74 | keyRadio3->setChecked( true ); | 86 | networkInfrastructure->setChecked( true ); |
75 | break; | 87 | } |
88 | else{ | ||
89 | network802->setChecked( true ); | ||
90 | networkInfrastructure->setChecked( false ); | ||
91 | } | ||
92 | } | ||
93 | if(line.contains("KEY=")){ | ||
94 | line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); | ||
95 | int s = line.find("KEY="); | ||
96 | line = line.mid(s+4, line.length()); | ||
97 | // Find first Key | ||
98 | s = line.find("[1]"); | ||
99 | if(s != -1){ | ||
100 | keyLineEdit0->setText(line.mid(0, s)); | ||
101 | line = line.mid(s+3, line.length()); | ||
102 | } | ||
103 | s = line.find("[2]"); | ||
104 | if(s != -1){ | ||
105 | keyLineEdit1->setText(line.mid(0, s)); | ||
106 | line = line.mid(s+3, line.length()); | ||
107 | } | ||
108 | s = line.find("[3]"); | ||
109 | if(s != -1){ | ||
110 | keyLineEdit2->setText(line.mid(0, s)); | ||
111 | line = line.mid(s+3, line.length()); | ||
112 | } | ||
113 | s = line.find("[4]"); | ||
114 | if(s != -1){ | ||
115 | keyLineEdit3->setText(line.mid(0, s)); | ||
116 | line = line.mid(s+3, line.length()); | ||
117 | } | ||
118 | if(line.contains("key [1]")) keyRadio0->setChecked(true); | ||
119 | if(line.contains("key [2]")) keyRadio1->setChecked(true); | ||
120 | if(line.contains("key [3]")) keyRadio2->setChecked(true); | ||
121 | if(line.contains("key [4]")) keyRadio3->setChecked(true); | ||
122 | if(line.contains("open")){ | ||
123 | authOpen->setChecked(true); | ||
124 | authShared->setChecked(false); | ||
125 | } | ||
126 | else{ | ||
127 | authOpen->setChecked(false); | ||
128 | authShared->setChecked(true); | ||
129 | } | ||
130 | } | ||
131 | if(line.contains("CHANNEL=")){ | ||
132 | networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); | ||
133 | } | ||
76 | } | 134 | } |
77 | keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); | 135 | } |
78 | keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); | ||
79 | keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); | ||
80 | keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); | ||
81 | return; | ||
82 | } | 136 | } |
83 | 137 | ||
84 | bool WLANImp::writeConfig() | 138 | /** |
85 | { | 139 | * Saves settings to the wireless.opts file using the current profile |
86 | qWarning( "WLANImp::writeConfig() called." ); | 140 | */ |
87 | config->setGroup( "Properties" ); | 141 | void WLANImp::changeAndSaveSettingFile(){ |
88 | if( essNon->isChecked() ) { | 142 | QString wlanFile = WIRELESS_OPTS; |
89 | config->writeEntry( "SSID", "any" ); | 143 | QFile::remove(wlanFile); |
90 | } else { | 144 | QFile file(wlanFile); |
91 | config->writeEntry( "SSID", essSpecificLineEdit->text() ); | 145 | |
92 | } | 146 | if (!file.open(IO_ReadWrite)){ |
93 | if( networkInfrastructure->isChecked() ){ | 147 | qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); |
94 | config->writeEntry( "Mode", "Managed" ); | 148 | return; |
95 | } else if( network802->isChecked() ){ | 149 | } |
96 | config->writeEntry( "Mode", "adhoc" ); | 150 | |
97 | } | 151 | QTextStream stream( &file ); |
98 | config->writeEntry( "CHANNEL", networkChannel->value() ); | 152 | bool foundCase = false; |
99 | // config->readEntry( "RATE", "auto" ); | 153 | bool found = false; |
100 | wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" ); | 154 | bool output = true; |
101 | authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" ); | 155 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
102 | key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" ); | 156 | QString line = (*it).simplifyWhiteSpace(); |
103 | if( keyRadio0->isChecked() ){ | 157 | if(line.contains("case")) |
104 | config->writeEntry( "dot11WEPDefaultKeyID", 0 ); | 158 | foundCase = true; |
105 | } else if( keyRadio1->isChecked() ){ | 159 | // See if we found our scheme to write or the sceme couldn't be found |
106 | config->writeEntry( "dot11WEPDefaultKeyID", 1 ); | 160 | if((foundCase && line.contains("esac") && !found) || |
107 | } else if( keyRadio2->isChecked() ){ | 161 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ |
108 | config->writeEntry( "dot11WEPDefaultKeyID", 2 ); | 162 | // write out scheme |
109 | } else if( keyRadio3->isChecked() ){ | 163 | found = true; |
110 | config->writeEntry( "dot11WEPDefaultKeyID", 3 ); | 164 | output = false; |
165 | |||
166 | if(!line.contains("esac")) | ||
167 | stream << line << "\n"; | ||
168 | |||
169 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; | ||
170 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; | ||
171 | if(!wepEnabled->isChecked()) | ||
172 | stream << "#"; | ||
173 | stream << "\tKEY="; | ||
174 | stream << keyLineEdit0->text() << " [1]"; | ||
175 | stream << keyLineEdit1->text() << " [2]"; | ||
176 | stream << keyLineEdit2->text() << " [3]"; | ||
177 | stream << keyLineEdit3->text() << " [4]"; | ||
178 | stream << " key ["; | ||
179 | if(keyRadio0->isChecked()) stream << "1]"; | ||
180 | if(keyRadio1->isChecked()) stream << "2]"; | ||
181 | if(keyRadio2->isChecked()) stream << "3]"; | ||
182 | if(keyRadio3->isChecked()) stream << "4]"; | ||
183 | if(authOpen->isChecked()) stream << " open"; | ||
184 | stream << "\n"; | ||
185 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; | ||
186 | stream << "\tRATE=auto\n"; | ||
187 | if(line.contains("esac")) | ||
188 | stream << line << "\n"; | ||
111 | } | 189 | } |
112 | config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() ); | 190 | if(line.contains(";;")) |
113 | config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() ); | 191 | output = true; |
114 | config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); | 192 | if(output) |
115 | config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); | 193 | stream << (*it) << '\n'; |
116 | return writeWirelessOpts( ); | 194 | } |
195 | file.close(); | ||
117 | } | 196 | } |
118 | 197 | ||
119 | /** | 198 | /** |
199 | * Check to see if the current config is valid | ||
200 | * Save wireless.opts, save interfaces | ||
120 | */ | 201 | */ |
121 | void WLANImp::accept() | 202 | void WLANImp::accept(){ |
122 | { | 203 | if(wepEnabled->isChecked()){ |
123 | if ( writeConfig() ){ | 204 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) |
124 | if(interfaceSetup->saveChanges()) | 205 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); |
125 | QDialog::accept(); | 206 | return; |
126 | } | 207 | } |
208 | |||
209 | // Ok settings are good here, save | ||
210 | changeAndSaveSettingFile(); | ||
211 | |||
212 | // Try to save the interfaces settings. | ||
213 | if(!interfaceSetup->saveChanges()) | ||
214 | return; | ||
215 | |||
216 | // Restart the device now that the settings have changed | ||
217 | QString initpath; | ||
218 | if( QDir("/etc/rc.d/init.d").exists() ) | ||
219 | initpath = "/etc/rc.d/init.d"; | ||
220 | else if( QDir("/etc/init.d").exists() ) | ||
221 | initpath = "/etc/init.d"; | ||
222 | if( initpath ) | ||
223 | system(QString("%1/pcmcia stop").arg(initpath)); | ||
224 | if( initpath ) | ||
225 | system(QString("%1/pcmcia start").arg(initpath)); | ||
226 | |||
227 | // Close out the dialog | ||
228 | QDialog::accept(); | ||
127 | } | 229 | } |
128 | 230 | ||
129 | bool WLANImp::writeWirelessOpts( QString scheme ) | 231 | // wlanimp.cpp |
130 | { | ||
131 | qWarning( "WLANImp::writeWirelessOpts entered." ); | ||
132 | QString prev = "/etc/pcmcia/wireless.opts"; | ||
133 | QFile prevFile(prev); | ||
134 | if ( !prevFile.open( IO_ReadOnly ) ) | ||
135 | return false; | ||
136 | |||
137 | QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; | ||
138 | QFile tmpFile(tmp); | ||
139 | if ( !tmpFile.open( IO_WriteOnly ) ) | ||
140 | return false; | ||
141 | |||
142 | bool retval = true; | ||
143 | |||
144 | QTextStream in( &prevFile ); | ||
145 | QTextStream out( &tmpFile ); | ||
146 | |||
147 | config->setGroup("Properties"); | ||
148 | |||
149 | QString line; | ||
150 | bool found=false; | ||
151 | bool done=false; | ||
152 | while ( !in.atEnd() ) { | ||
153 | QString line = in.readLine(); | ||
154 | QString wline = line.simplifyWhiteSpace(); | ||
155 | if ( !done ) { | ||
156 | if ( found ) { | ||
157 | // skip existing entry for this scheme, and write our own. | ||
158 | if ( wline == ";;" ) { | ||
159 | found = false; | ||
160 | continue; | ||
161 | } else { | ||
162 | continue; | ||
163 | } | ||
164 | } else { | ||
165 | if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) { | ||
166 | found=true; | ||
167 | continue; // skip this line | ||
168 | } else if ( wline == "esac" || wline == "*,*,*,*)" ) { | ||
169 | // end - add new entry | ||
170 | // Not all fields have a GUI, but all are supported | ||
171 | // in the letwork configuration files. | ||
172 | static const char* txtfields[] = { | ||
173 | 0 | ||
174 | }; | ||
175 | QString readmode = config->readEntry( "Mode", "Managed" ); | ||
176 | QString mode; | ||
177 | if( readmode == "Managed" ){ | ||
178 | mode = readmode; | ||
179 | } else if( readmode == "adhoc" ){ | ||
180 | mode = "Ad-Hoc"; | ||
181 | } | ||
182 | QString key; | ||
183 | if( wepEnabled->isChecked() ){ | ||
184 | int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); | ||
185 | switch( defaultkey ){ | ||
186 | case 0: | ||
187 | key += keyLineEdit0->text(); | ||
188 | break; | ||
189 | case 1: | ||
190 | key += keyLineEdit1->text(); | ||
191 | break; | ||
192 | case 2: | ||
193 | key += keyLineEdit2->text(); | ||
194 | break; | ||
195 | case 3: | ||
196 | key += keyLineEdit3->text(); | ||
197 | break; | ||
198 | } | ||
199 | if( config->readEntry( "AuthType", "opensystem" ) == "opensystem") | ||
200 | key += " open"; | ||
201 | } | ||
202 | out << scheme << ",*,*,*)" << "\n" | ||
203 | << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n" | ||
204 | << " MODE=" << mode << "\n" | ||
205 | << " KEY=" << Global::shellQuote( key ) << "\n" | ||
206 | << " RATE=" << "auto" << "\n" | ||
207 | ; | ||
208 | if( mode != "Managed" ) | ||
209 | out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n"; | ||
210 | const char** f = txtfields; | ||
211 | while (*f) { | ||
212 | out << " " << *f << "=" << config->readEntry(*f,"") << "\n"; | ||
213 | ++f; | ||
214 | } | ||
215 | out << " ;;\n"; | ||
216 | done = true; | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | out << line << "\n"; | ||
221 | } | ||
222 | 232 | ||
223 | prevFile.close(); | ||
224 | tmpFile.close(); | ||
225 | QString initpath; | ||
226 | //system("cardctl suspend"); | ||
227 | if( QDir("/etc/rc.d/init.d").exists() ){ | ||
228 | initpath = "/etc/rc.d/init.d"; | ||
229 | } else if( QDir("/etc/init.d").exists() ){ | ||
230 | initpath = "/etc/init.d"; | ||
231 | } | ||
232 | if( initpath ) | ||
233 | system(QString("%1/pcmcia stop").arg(initpath)); | ||
234 | |||
235 | if( system( "mv " + tmp + " " + prev ) ) | ||
236 | retval = false; | ||
237 | //#ifdef USE_SCHEMES | ||
238 | // if ( retval ) | ||
239 | //SchemeChanger::changeScheme(scheme); | ||
240 | //#endif | ||
241 | |||
242 | //system("cardctl resume"); | ||
243 | if( initpath ) | ||
244 | system(QString("%1/pcmcia start").arg(initpath)); | ||
245 | |||
246 | return retval; | ||
247 | } | ||