~ubuntu-branches/ubuntu/dapper/wpasupplicant/dapper

« back to all changes in this revision

Viewing changes to wpa_gui-qt4/networkconfig.ui.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-10-02 18:24:42 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051002182442-wl4fow8xo8gpokzj
Tags: 0.4.5-0ubuntu1
New upstream version.

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
}
 
27
 
 
28
void NetworkConfig::paramsFromScanResults(Q3ListViewItem *sel)
 
29
{
 
30
    /* SSID BSSID frequency signal flags */
 
31
    setCaption(sel->text(0));
 
32
    ssidEdit->setText(sel->text(0));
 
33
    
 
34
    QString flags = sel->text(4);
 
35
    int auth, encr = 0;
 
36
    if (flags.find("[WPA2-EAP") >= 0)
 
37
        auth = AUTH_WPA2_EAP;
 
38
    else if (flags.find("[WPA-EAP") >= 0)
 
39
        auth = AUTH_WPA_EAP;
 
40
    else if (flags.find("[WPA2-PSK") >= 0)
 
41
        auth = AUTH_WPA2_PSK;
 
42
    else if (flags.find("[WPA-PSK") >= 0)
 
43
        auth = AUTH_WPA_PSK;
 
44
    else
 
45
        auth = AUTH_NONE;
 
46
    
 
47
    if (flags.find("-CCMP") >= 0)
 
48
        encr = 1;
 
49
    else if (flags.find("-TKIP") >= 0)
 
50
        encr = 0;
 
51
    else if (flags.find("WEP") >= 0)
 
52
        encr = 1;
 
53
    else
 
54
        encr = 0;
 
55
 
 
56
    authSelect->setCurrentItem(auth);
 
57
    authChanged(auth);
 
58
    encrSelect->setCurrentItem(encr);
 
59
}
 
60
 
 
61
 
 
62
void NetworkConfig::authChanged(int sel)
 
63
{
 
64
    pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);
 
65
    bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||
 
66
               sel == AUTH_WPA2_EAP;
 
67
    eapSelect->setEnabled(eap);
 
68
    identityEdit->setEnabled(eap);
 
69
    passwordEdit->setEnabled(eap);
 
70
   
 
71
    while (encrSelect->count())
 
72
        encrSelect->removeItem(0);
 
73
    
 
74
    if (sel == AUTH_NONE || sel == AUTH_IEEE8021X) {
 
75
        encrSelect->insertItem("None");
 
76
        encrSelect->insertItem("WEP");
 
77
        encrSelect->setCurrentItem(sel == AUTH_NONE ? 0 : 1);
 
78
    } else {
 
79
        encrSelect->insertItem("TKIP");
 
80
        encrSelect->insertItem("CCMP");
 
81
        encrSelect->setCurrentItem((sel == AUTH_WPA2_PSK ||
 
82
                                    sel == AUTH_WPA2_EAP) ? 1 : 0);
 
83
    }
 
84
}
 
85
 
 
86
 
 
87
void NetworkConfig::addNetwork()
 
88
{
 
89
    char reply[10], cmd[256];
 
90
    size_t reply_len;
 
91
    int id;
 
92
    int psklen = pskEdit->text().length();
 
93
    int auth = authSelect->currentItem();
 
94
 
 
95
    if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) {
 
96
        if (psklen < 8 || psklen > 64) {
 
97
            QMessageBox::warning(this, "wpa_gui", "WPA-PSK requires a passphrase "
 
98
                                 "of 8 to 63 characters\n"
 
99
                                 "or 64 hex digit PSK");
 
100
            return;
 
101
        }
 
102
    }
 
103
        
 
104
    if (wpagui == NULL)
 
105
        return;
 
106
    
 
107
    memset(reply, 0, sizeof(reply));
 
108
    reply_len = sizeof(reply) - 1;
 
109
    wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len);
 
110
    if (reply[0] == 'F') {
 
111
        QMessageBox::warning(this, "wpa_gui", "Failed to add network to wpa_supplicant\n"
 
112
                             "configuration.");
 
113
        return;
 
114
    }
 
115
    id = atoi(reply);
 
116
 
 
117
    setNetworkParam(id, "ssid", ssidEdit->text().ascii(), true);
 
118
    
 
119
    char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
 
120
    switch (auth) {
 
121
    case AUTH_NONE:
 
122
        key_mgmt = "NONE";
 
123
        break;
 
124
    case AUTH_IEEE8021X:
 
125
        key_mgmt = "IEEE8021X";
 
126
        break;
 
127
    case AUTH_WPA_PSK:
 
128
        key_mgmt = "WPA-PSK";
 
129
        proto = "WPA";
 
130
        break;
 
131
    case AUTH_WPA_EAP:
 
132
        key_mgmt = "WPA-EAP";
 
133
        proto = "WPA";
 
134
        break;
 
135
    case AUTH_WPA2_PSK:
 
136
        key_mgmt = "WPA2-PSK";
 
137
        proto = "WPA2";
 
138
        break;
 
139
    case AUTH_WPA2_EAP:
 
140
        key_mgmt = "WPA2-EAP";
 
141
        proto = "WPA2";
 
142
        break;
 
143
    }
 
144
    
 
145
    if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP ||
 
146
        auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) {
 
147
        int encr = encrSelect->currentItem();
 
148
        if (encr == 0)
 
149
            pairwise = "TKIP";
 
150
        else
 
151
            pairwise = "CCMP";
 
152
    }
 
153
    
 
154
    if (proto)
 
155
        setNetworkParam(id, "proto", proto, false);
 
156
    if (key_mgmt)
 
157
        setNetworkParam(id, "key_mgmt", key_mgmt, false);
 
158
    if (pairwise) {
 
159
        setNetworkParam(id, "pairwise", pairwise, false);
 
160
        setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
 
161
    }
 
162
    if (pskEdit->isEnabled())
 
163
        setNetworkParam(id, "psk", pskEdit->text().ascii(), psklen != 64);
 
164
    if (eapSelect->isEnabled())
 
165
        setNetworkParam(id, "eap", eapSelect->currentText().ascii(), false);
 
166
    if (identityEdit->isEnabled())
 
167
        setNetworkParam(id, "identity", identityEdit->text().ascii(), true);
 
168
    if (passwordEdit->isEnabled())
 
169
        setNetworkParam(id, "password", passwordEdit->text().ascii(), true);
 
170
 
 
171
    snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id);
 
172
    reply_len = sizeof(reply);
 
173
    wpagui->ctrlRequest(cmd, reply, &reply_len);
 
174
    if (strncmp(reply, "OK", 2) != 0) {
 
175
        QMessageBox::warning(this, "wpa_gui", "Failed to enable network in wpa_supplicant\n"
 
176
                             "configuration.");
 
177
        /* Network was added, so continue anyway */
 
178
    }
 
179
 
 
180
    close();
 
181
}
 
182
 
 
183
 
 
184
void NetworkConfig::setWpaGui( WpaGui *_wpagui )
 
185
{
 
186
    wpagui = _wpagui;
 
187
}
 
188
 
 
189
 
 
190
int NetworkConfig::setNetworkParam(int id, const char *field, const char *value, bool quote)
 
191
{
 
192
    char reply[10], cmd[256];
 
193
    size_t reply_len;
 
194
    snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",
 
195
             id, field, quote ? "\"" : "", value, quote ? "\"" : "");
 
196
    reply_len = sizeof(reply);
 
197
    wpagui->ctrlRequest(cmd, reply, &reply_len);
 
198
    return strncmp(reply, "OK", 2) == 0 ? 0 : -1;
 
199
}