~ubuntu-branches/ubuntu/oneiric/wpasupplicant/oneiric

« back to all changes in this revision

Viewing changes to wpa_gui/networkconfig.ui.h

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2006-10-05 08:04:01 UTC
  • mfrom: (1.2.1 upstream) (2.1.14 edgy)
  • Revision ID: james.westby@ubuntu.com-20061005080401-myfwjtq7di70dyeo
* Update madwifi headers to latest SVN. (Closes: #388316)
* Remove failed attempt at action locking. [debian/functions.sh,
  debian/wpa_action.sh]
* Add hysteresis checking functions, to avoid "event loops" while
  using wpa-roam. [debian/functions.sh, debian/wpa_action.sh]
* Change of co-maintainer email address.
* Add ishex() function to functions.sh to determine wpa-psk value type in
  plaintext or hex. This effectively eliminates the need for the bogus and
  somewhat confusing wpa-passphrase contruct specific to our scripts and
  allows wpa-psk to work with either a 8 to 63 character long plaintext
  string or 64 character long hex string.
* Adjust README.modes to not refer to the redundant wpa-passphrase stuff.
* Add big fat NOTE about acceptable wpa-psk's to top of example gallery.
* Strip surrounding quotes from wpa-ssid if present, instead of just whining
  about them.
* Update email address in copyright blurb of functions.sh, ifupdown.sh and
  wpa_action.sh.  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** ui.h extension file, included from the uic-generated form implementation.
 
3
**
 
4
** If you want to add, delete, or rename functions or slots, use
 
5
** Qt Designer to update this file, preserving your code.
 
6
**
 
7
** You should not define a constructor or destructor in this file.
 
8
** Instead, write your code in functions called init() and destroy().
 
9
** These will automatically be called by the form's constructor and
 
10
** destructor.
 
11
*****************************************************************************/
 
12
 
 
13
 
 
14
enum {
 
15
    AUTH_NONE = 0,
 
16
    AUTH_IEEE8021X = 1,
 
17
    AUTH_WPA_PSK = 2,
 
18
    AUTH_WPA_EAP = 3,
 
19
    AUTH_WPA2_PSK = 4,
 
20
    AUTH_WPA2_EAP = 5
 
21
};
 
22
 
 
23
void NetworkConfig::init()
 
24
{
 
25
    wpagui = NULL;
 
26
    new_network = false;
 
27
}
 
28
 
 
29
void NetworkConfig::paramsFromScanResults(Q3ListViewItem *sel)
 
30
{
 
31
    new_network = true;
 
32
 
 
33
    /* SSID BSSID frequency signal flags */
 
34
    setCaption(sel->text(0));
 
35
    ssidEdit->setText(sel->text(0));
 
36
    
 
37
    QString flags = sel->text(4);
 
38
    int auth, encr = 0;
 
39
    if (flags.find("[WPA2-EAP") >= 0)
 
40
        auth = AUTH_WPA2_EAP;
 
41
    else if (flags.find("[WPA-EAP") >= 0)
 
42
        auth = AUTH_WPA_EAP;
 
43
    else if (flags.find("[WPA2-PSK") >= 0)
 
44
        auth = AUTH_WPA2_PSK;
 
45
    else if (flags.find("[WPA-PSK") >= 0)
 
46
        auth = AUTH_WPA_PSK;
 
47
    else
 
48
        auth = AUTH_NONE;
 
49
    
 
50
    if (flags.find("-CCMP") >= 0)
 
51
        encr = 1;
 
52
    else if (flags.find("-TKIP") >= 0)
 
53
        encr = 0;
 
54
    else if (flags.find("WEP") >= 0)
 
55
        encr = 1;
 
56
    else
 
57
        encr = 0;
 
58
 
 
59
    authSelect->setCurrentItem(auth);
 
60
    authChanged(auth);
 
61
    encrSelect->setCurrentItem(encr);
 
62
 
 
63
    getEapCapa();
 
64
}
 
65
 
 
66
 
 
67
void NetworkConfig::authChanged(int sel)
 
68
{
 
69
    pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);
 
70
    bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||
 
71
               sel == AUTH_WPA2_EAP;
 
72
    eapSelect->setEnabled(eap);
 
73
    identityEdit->setEnabled(eap);
 
74
    passwordEdit->setEnabled(eap);
 
75
    cacertEdit->setEnabled(eap);
 
76
   
 
77
    while (encrSelect->count())
 
78
        encrSelect->removeItem(0);
 
79
    
 
80
    if (sel == AUTH_NONE || sel == AUTH_IEEE8021X) {
 
81
        encrSelect->insertItem("None");
 
82
        encrSelect->insertItem("WEP");
 
83
        encrSelect->setCurrentItem(sel == AUTH_NONE ? 0 : 1);
 
84
    } else {
 
85
        encrSelect->insertItem("TKIP");
 
86
        encrSelect->insertItem("CCMP");
 
87
        encrSelect->setCurrentItem((sel == AUTH_WPA2_PSK ||
 
88
                                    sel == AUTH_WPA2_EAP) ? 1 : 0);
 
89
    }
 
90
    
 
91
    wepEnabled(sel == AUTH_IEEE8021X);
 
92
}
 
93
 
 
94
 
 
95
void NetworkConfig::addNetwork()
 
96
{
 
97
    char reply[10], cmd[256];
 
98
    size_t reply_len;
 
99
    int id;
 
100
    int psklen = pskEdit->text().length();
 
101
    int auth = authSelect->currentItem();
 
102
 
 
103
    if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) {
 
104
        if (psklen < 8 || psklen > 64) {
 
105
            QMessageBox::warning(this, "wpa_gui", "WPA-PSK requires a passphrase "
 
106
                                 "of 8 to 63 characters\n"
 
107
                                 "or 64 hex digit PSK");
 
108
            return;
 
109
        }
 
110
    }
 
111
        
 
112
    if (wpagui == NULL)
 
113
        return;
 
114
    
 
115
    memset(reply, 0, sizeof(reply));
 
116
    reply_len = sizeof(reply) - 1;
 
117
    
 
118
    if (new_network) {
 
119
        wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len);
 
120
        if (reply[0] == 'F') {
 
121
            QMessageBox::warning(this, "wpa_gui", "Failed to add network to wpa_supplicant\n"
 
122
                                 "configuration.");
 
123
            return;
 
124
        }
 
125
        id = atoi(reply);
 
126
    } else {
 
127
        id = edit_network_id;
 
128
    }
 
129
 
 
130
    setNetworkParam(id, "ssid", ssidEdit->text().ascii(), true);
 
131
    
 
132
    char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
 
133
    switch (auth) {
 
134
    case AUTH_NONE:
 
135
        key_mgmt = "NONE";
 
136
        break;
 
137
    case AUTH_IEEE8021X:
 
138
        key_mgmt = "IEEE8021X";
 
139
        break;
 
140
    case AUTH_WPA_PSK:
 
141
        key_mgmt = "WPA-PSK";
 
142
        proto = "WPA";
 
143
        break;
 
144
    case AUTH_WPA_EAP:
 
145
        key_mgmt = "WPA-EAP";
 
146
        proto = "WPA";
 
147
        break;
 
148
    case AUTH_WPA2_PSK:
 
149
        key_mgmt = "WPA-PSK";
 
150
        proto = "WPA2";
 
151
        break;
 
152
    case AUTH_WPA2_EAP:
 
153
        key_mgmt = "WPA-EAP";
 
154
        proto = "WPA2";
 
155
        break;
 
156
    }
 
157
    
 
158
    if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP ||
 
159
        auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) {
 
160
        int encr = encrSelect->currentItem();
 
161
        if (encr == 0)
 
162
            pairwise = "TKIP";
 
163
        else
 
164
            pairwise = "CCMP";
 
165
    }
 
166
    
 
167
    if (proto)
 
168
        setNetworkParam(id, "proto", proto, false);
 
169
    if (key_mgmt)
 
170
        setNetworkParam(id, "key_mgmt", key_mgmt, false);
 
171
    if (pairwise) {
 
172
        setNetworkParam(id, "pairwise", pairwise, false);
 
173
        setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
 
174
    }
 
175
    if (pskEdit->isEnabled())
 
176
        setNetworkParam(id, "psk", pskEdit->text().ascii(), psklen != 64);
 
177
    if (eapSelect->isEnabled())
 
178
        setNetworkParam(id, "eap", eapSelect->currentText().ascii(), false);
 
179
    if (identityEdit->isEnabled())
 
180
        setNetworkParam(id, "identity", identityEdit->text().ascii(), true);
 
181
    if (passwordEdit->isEnabled())
 
182
        setNetworkParam(id, "password", passwordEdit->text().ascii(), true);
 
183
    if (cacertEdit->isEnabled())
 
184
        setNetworkParam(id, "ca_cert", cacertEdit->text().ascii(), true);
 
185
    writeWepKey(id, wep0Edit, 0);
 
186
    writeWepKey(id, wep1Edit, 1);
 
187
    writeWepKey(id, wep2Edit, 2);
 
188
    writeWepKey(id, wep3Edit, 3);
 
189
  
 
190
    if (wep0Radio->isEnabled() && wep0Radio->isChecked())
 
191
        setNetworkParam(id, "wep_tx_keyidx", "0", false);
 
192
    else if (wep1Radio->isEnabled() && wep1Radio->isChecked())
 
193
        setNetworkParam(id, "wep_tx_keyidx", "1", false);
 
194
    else if (wep2Radio->isEnabled() && wep2Radio->isChecked())
 
195
        setNetworkParam(id, "wep_tx_keyidx", "2", false);
 
196
    else if (wep3Radio->isEnabled() && wep3Radio->isChecked())
 
197
        setNetworkParam(id, "wep_tx_keyidx", "3", false);
 
198
 
 
199
    snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id);
 
200
    reply_len = sizeof(reply);
 
201
    wpagui->ctrlRequest(cmd, reply, &reply_len);
 
202
    if (strncmp(reply, "OK", 2) != 0) {
 
203
        QMessageBox::warning(this, "wpa_gui", "Failed to enable network in wpa_supplicant\n"
 
204
                             "configuration.");
 
205
        /* Network was added, so continue anyway */
 
206
    }
 
207
    wpagui->triggerUpdate();
 
208
    wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
 
209
 
 
210
    close();
 
211
}
 
212
 
 
213
 
 
214
void NetworkConfig::setWpaGui( WpaGui *_wpagui )
 
215
{
 
216
    wpagui = _wpagui;
 
217
}
 
218
 
 
219
 
 
220
int NetworkConfig::setNetworkParam(int id, const char *field, const char *value, bool quote)
 
221
{
 
222
    char reply[10], cmd[256];
 
223
    size_t reply_len;
 
224
    snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",
 
225
             id, field, quote ? "\"" : "", value, quote ? "\"" : "");
 
226
    reply_len = sizeof(reply);
 
227
    wpagui->ctrlRequest(cmd, reply, &reply_len);
 
228
    return strncmp(reply, "OK", 2) == 0 ? 0 : -1;
 
229
}
 
230
 
 
231
 
 
232
void NetworkConfig::encrChanged( const QString &sel )
 
233
{
 
234
    wepEnabled(sel.find("WEP") == 0);
 
235
}
 
236
 
 
237
 
 
238
void NetworkConfig::wepEnabled( bool enabled )
 
239
{
 
240
    wep0Edit->setEnabled(enabled);
 
241
    wep1Edit->setEnabled(enabled);
 
242
    wep2Edit->setEnabled(enabled);
 
243
    wep3Edit->setEnabled(enabled);
 
244
    wep0Radio->setEnabled(enabled);
 
245
    wep1Radio->setEnabled(enabled);
 
246
    wep2Radio->setEnabled(enabled);
 
247
    wep3Radio->setEnabled(enabled);
 
248
}
 
249
 
 
250
 
 
251
void NetworkConfig::writeWepKey( int network_id, QLineEdit *edit, int id )
 
252
{
 
253
    char buf[10];
 
254
    bool hex;
 
255
    const char *txt, *pos;
 
256
    size_t len;
 
257
  
 
258
    if (!edit->isEnabled() || edit->text().isEmpty())
 
259
        return;
 
260
    
 
261
    /*
 
262
        * Assume hex key if only hex characters are present and length matches
 
263
       * with 40, 104, or 128-bit key
 
264
       */
 
265
    txt = edit->text().ascii();
 
266
    len = strlen(txt);
 
267
    if (len == 0)
 
268
        return;
 
269
    pos = txt;
 
270
    hex = true;
 
271
    while (*pos) {
 
272
        if (!((*pos >= '0' && *pos <= '9') || (*pos >= 'a' && *pos <= 'f') ||
 
273
              (*pos >= 'A' && *pos <= 'F'))) {
 
274
            hex = false;
 
275
            break;
 
276
        }
 
277
        pos++;
 
278
    }
 
279
    if (hex && len != 10 && len != 26 && len != 32)
 
280
        hex = false;
 
281
    snprintf(buf, sizeof(buf), "wep_key%d", id);
 
282
    setNetworkParam(network_id, buf, txt, !hex);
 
283
}
 
284
 
 
285
 
 
286
void NetworkConfig::paramsFromConfig( int network_id )
 
287
{
 
288
    int i;
 
289
 
 
290
    edit_network_id = network_id;
 
291
    getEapCapa();
 
292
    
 
293
    char reply[1024], cmd[256], *pos;
 
294
    size_t reply_len;
 
295
    
 
296
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ssid", network_id);
 
297
    reply_len = sizeof(reply);
 
298
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
299
        reply[0] == '"') {
 
300
        reply[reply_len] = '\0';
 
301
        pos = strchr(reply + 1, '"');
 
302
        if (pos)
 
303
            *pos = '\0';
 
304
        ssidEdit->setText(reply + 1);
 
305
    }
 
306
    
 
307
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d proto", network_id);
 
308
    reply_len = sizeof(reply);
 
309
    int wpa = 0;
 
310
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
 
311
        reply[reply_len] = '\0';
 
312
        if (strstr(reply, "RSN") || strstr(reply, "WPA2"))
 
313
            wpa = 2;
 
314
        else if (strstr(reply, "WPA"))
 
315
            wpa = 1;
 
316
    }
 
317
 
 
318
    int auth = AUTH_NONE, encr = 0;
 
319
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d key_mgmt", network_id);
 
320
    reply_len = sizeof(reply);
 
321
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
 
322
        reply[reply_len] = '\0';
 
323
        if (strstr(reply, "WPA-EAP"))
 
324
            auth = wpa & 2 ? AUTH_WPA2_EAP : AUTH_WPA_EAP;
 
325
        else if (strstr(reply, "WPA-PSK"))
 
326
            auth = wpa & 2 ? AUTH_WPA2_PSK : AUTH_WPA_PSK;
 
327
        else if (strstr(reply, "IEEE8021X")) {
 
328
            auth = AUTH_IEEE8021X;
 
329
            encr = 1;
 
330
        }
 
331
    }
 
332
 
 
333
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d pairwise", network_id);
 
334
    reply_len = sizeof(reply);
 
335
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
 
336
        reply[reply_len] = '\0';
 
337
        if (strstr(reply, "CCMP"))
 
338
            encr = 1;
 
339
        else if (strstr(reply, "TKIP"))
 
340
            encr = 0;
 
341
        else if (strstr(reply, "WEP"))
 
342
            encr = 1;
 
343
        else
 
344
            encr = 0;
 
345
    }
 
346
 
 
347
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d psk", network_id);
 
348
    reply_len = sizeof(reply);
 
349
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
350
        reply[0] == '"') {
 
351
        reply[reply_len] = '\0';
 
352
        pos = strchr(reply + 1, '"');
 
353
        if (pos)
 
354
            *pos = '\0';
 
355
        pskEdit->setText(reply + 1);
 
356
    }
 
357
 
 
358
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d identity", network_id);
 
359
    reply_len = sizeof(reply);
 
360
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
361
        reply[0] == '"') {
 
362
        reply[reply_len] = '\0';
 
363
        pos = strchr(reply + 1, '"');
 
364
        if (pos)
 
365
            *pos = '\0';
 
366
        identityEdit->setText(reply + 1);
 
367
    }
 
368
 
 
369
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d password", network_id);
 
370
    reply_len = sizeof(reply);
 
371
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
372
        reply[0] == '"') {
 
373
        reply[reply_len] = '\0';
 
374
        pos = strchr(reply + 1, '"');
 
375
        if (pos)
 
376
            *pos = '\0';
 
377
        passwordEdit->setText(reply + 1);
 
378
    }
 
379
 
 
380
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ca_cert", network_id);
 
381
    reply_len = sizeof(reply);
 
382
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
383
        reply[0] == '"') {
 
384
        reply[reply_len] = '\0';
 
385
        pos = strchr(reply + 1, '"');
 
386
        if (pos)
 
387
            *pos = '\0';
 
388
        cacertEdit->setText(reply + 1);
 
389
    }
 
390
 
 
391
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d eap", network_id);
 
392
    reply_len = sizeof(reply);
 
393
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) {
 
394
        reply[reply_len] = '\0';
 
395
        for (i = 0; i < eapSelect->count(); i++) {
 
396
            if (eapSelect->text(i).compare(reply) == 0) {
 
397
                eapSelect->setCurrentItem(i);
 
398
                break;
 
399
            }
 
400
        }
 
401
    }
 
402
 
 
403
    for (i = 0; i < 4; i++) {
 
404
        snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_key%d", network_id, i);
 
405
        reply_len = sizeof(reply);
 
406
        if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
 
407
            reply[0] == '"') {
 
408
            reply[reply_len] = '\0';
 
409
            pos = strchr(reply + 1, '"');
 
410
            if (pos)
 
411
                *pos = '\0';
 
412
            if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
 
413
                encr = 1;
 
414
 
 
415
            switch (i) {
 
416
            case 0:
 
417
                wep0Edit->setText(reply + 1);
 
418
                break;
 
419
            case 1:
 
420
                wep1Edit->setText(reply + 1);
 
421
                break;
 
422
            case 2:
 
423
                wep2Edit->setText(reply + 1);
 
424
                break;
 
425
            case 3:
 
426
                wep3Edit->setText(reply + 1);
 
427
                break;
 
428
            }
 
429
        }
 
430
    }
 
431
 
 
432
    snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_tx_keyidx", network_id);
 
433
    reply_len = sizeof(reply);
 
434
    if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) {
 
435
        reply[reply_len] = '\0';
 
436
        switch (atoi(reply)) {
 
437
        case 0:
 
438
            wep0Radio->setChecked(true);
 
439
            break;
 
440
        case 1:
 
441
            wep1Radio->setChecked(true);
 
442
            break;
 
443
        case 2:
 
444
            wep2Radio->setChecked(true);
 
445
            break;
 
446
        case 3:
 
447
            wep3Radio->setChecked(true);
 
448
            break;
 
449
        }
 
450
    }
 
451
 
 
452
    authSelect->setCurrentItem(auth);
 
453
    authChanged(auth);
 
454
    encrSelect->setCurrentItem(encr);
 
455
    if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
 
456
        wepEnabled(encr == 1);
 
457
 
 
458
    removeButton->setEnabled(true);
 
459
    addButton->setText("Save");
 
460
}
 
461
 
 
462
 
 
463
void NetworkConfig::removeNetwork()
 
464
{
 
465
    char reply[10], cmd[256];
 
466
    size_t reply_len;
 
467
    
 
468
    if (QMessageBox::information(this, "wpa_gui",
 
469
                                 "This will permanently remove the network\n"
 
470
                                 "from the configuration. Do you really want\n"
 
471
                                 "to remove this network?", "Yes", "No") != 0)
 
472
        return;
 
473
    
 
474
    snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %d", edit_network_id);
 
475
    reply_len = sizeof(reply);
 
476
    wpagui->ctrlRequest(cmd, reply, &reply_len);
 
477
    if (strncmp(reply, "OK", 2) != 0) {
 
478
        QMessageBox::warning(this, "wpa_gui",
 
479
                             "Failed to remove network from wpa_supplicant\n"
 
480
                             "configuration.");
 
481
    } else {
 
482
        wpagui->triggerUpdate();
 
483
        wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
 
484
    }
 
485
 
 
486
    close();
 
487
}
 
488
 
 
489
 
 
490
void NetworkConfig::newNetwork()
 
491
{
 
492
    new_network = true;
 
493
    getEapCapa();
 
494
}
 
495
 
 
496
 
 
497
void NetworkConfig::getEapCapa()
 
498
{
 
499
    char reply[256];
 
500
    size_t reply_len;
 
501
    
 
502
    if (wpagui == NULL)
 
503
        return;
 
504
 
 
505
    reply_len = sizeof(reply) - 1;
 
506
    if (wpagui->ctrlRequest("GET_CAPABILITY eap", reply, &reply_len) < 0)
 
507
        return;
 
508
    reply[reply_len] = '\0';
 
509
    
 
510
    QString res(reply);
 
511
    QStringList types = QStringList::split(QChar(' '), res);
 
512
    eapSelect->insertStringList(types);
 
513
}