1
/****************************************************************************
2
** ui.h extension file, included from the uic-generated form implementation.
4
** If you want to add, delete, or rename functions or slots, use
5
** Qt Designer to update this file, preserving your code.
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
11
*****************************************************************************/
15
/* Need to get getopt() */
29
ctrl_iface_dir = strdup("/var/run/wpa_supplicant");
33
textStatus->setText("connecting to wpa_supplicant");
34
timer = new QTimer(this);
35
connect(timer, SIGNAL(timeout()), SLOT(ping()));
36
timer->start(1000, FALSE);
38
if (openCtrlConnection(ctrl_iface) < 0) {
39
printf("Failed to open control connection to wpa_supplicant.\n");
43
networkMayHaveChanged = true;
48
void WpaGui::destroy()
53
wpa_ctrl_detach(monitor_conn);
54
wpa_ctrl_close(monitor_conn);
58
wpa_ctrl_close(ctrl_conn);
84
ctrl_iface_dir = NULL;
88
void WpaGui::parse_argv()
92
c = getopt(qApp->argc(), qApp->argv(), "i:p:");
98
ctrl_iface = strdup(optarg);
101
free(ctrl_iface_dir);
102
ctrl_iface_dir = strdup(optarg);
109
int WpaGui::openCtrlConnection(const char *ifname)
115
if (ifname != ctrl_iface) {
117
ctrl_iface = strdup(ifname);
120
#ifdef CONFIG_CTRL_IFACE_UDP
122
ctrl_iface = strdup("udp");
123
#else /* CONFIG_CTRL_IFACE_UDP */
125
DIR *dir = opendir(ctrl_iface_dir);
129
while ((dent = readdir(dir))) {
130
#ifdef _DIRENT_HAVE_D_TYPE
131
/* Skip the file if it is not a socket.
132
* Also accept DT_UNKNOWN (0) in case
133
* the C library or underlying file
134
* system does not support d_type. */
135
if (dent->d_type != DT_SOCK &&
136
dent->d_type != DT_UNKNOWN)
138
#endif /* _DIRENT_HAVE_D_TYPE */
140
if (strcmp(dent->d_name, ".") == 0 ||
141
strcmp(dent->d_name, "..") == 0)
143
printf("Selected interface '%s'\n", dent->d_name);
144
ctrl_iface = strdup(dent->d_name);
149
#endif /* CONFIG_CTRL_IFACE_UDP */
152
if (ctrl_iface == NULL)
155
flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
156
cfile = (char *) malloc(flen);
159
snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
162
wpa_ctrl_close(ctrl_conn);
169
wpa_ctrl_detach(monitor_conn);
170
wpa_ctrl_close(monitor_conn);
174
printf("Trying to connect to '%s'\n", cfile);
175
ctrl_conn = wpa_ctrl_open(cfile);
176
if (ctrl_conn == NULL) {
180
monitor_conn = wpa_ctrl_open(cfile);
182
if (monitor_conn == NULL) {
183
wpa_ctrl_close(ctrl_conn);
186
if (wpa_ctrl_attach(monitor_conn)) {
187
printf("Failed to attach to wpa_supplicant\n");
188
wpa_ctrl_close(monitor_conn);
190
wpa_ctrl_close(ctrl_conn);
195
msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
196
QSocketNotifier::Read, this);
197
connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
199
adapterSelect->clear();
200
adapterSelect->insertItem(ctrl_iface);
201
adapterSelect->setCurrentItem(0);
207
static void wpa_gui_msg_cb(char *msg, size_t)
209
/* This should not happen anymore since two control connections are used. */
210
printf("missed message: %s\n", msg);
214
int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
218
if (ctrl_conn == NULL)
220
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen,
223
printf("'%s' command timed out.\n", cmd);
224
} else if (ret < 0) {
225
printf("'%s' command failed.\n", cmd);
232
void WpaGui::updateStatus()
234
char buf[2048], *start, *end, *pos;
237
pingsToStatusUpdate = 10;
239
len = sizeof(buf) - 1;
240
if (ctrl_conn == NULL || ctrlRequest("STATUS", buf, &len) < 0) {
241
textStatus->setText("Could not get status from wpa_supplicant");
242
textAuthentication->clear();
243
textEncryption->clear();
246
textIpAddress->clear();
252
bool auth_updated = false, ssid_updated = false;
253
bool bssid_updated = false, ipaddr_updated = false;
254
bool status_updated = false;
255
char *pairwise_cipher = NULL, *group_cipher = NULL;
260
end = strchr(start, '\n');
264
while (end[0] && end[1])
269
pos = strchr(start, '=');
272
if (strcmp(start, "bssid") == 0) {
273
bssid_updated = true;
274
textBssid->setText(pos);
275
} else if (strcmp(start, "ssid") == 0) {
277
textSsid->setText(pos);
278
} else if (strcmp(start, "ip_address") == 0) {
279
ipaddr_updated = true;
280
textIpAddress->setText(pos);
281
} else if (strcmp(start, "wpa_state") == 0) {
282
status_updated = true;
283
textStatus->setText(pos);
284
} else if (strcmp(start, "key_mgmt") == 0) {
286
textAuthentication->setText(pos);
287
/* TODO: could add EAP status to this */
288
} else if (strcmp(start, "pairwise_cipher") == 0) {
289
pairwise_cipher = pos;
290
} else if (strcmp(start, "group_cipher") == 0) {
300
if (pairwise_cipher || group_cipher) {
302
if (pairwise_cipher && group_cipher &&
303
strcmp(pairwise_cipher, group_cipher) != 0) {
304
encr.append(pairwise_cipher);
306
encr.append(group_cipher);
307
} else if (pairwise_cipher) {
308
encr.append(pairwise_cipher);
309
} else if (group_cipher) {
310
encr.append(group_cipher);
311
encr.append(" [group key only]");
315
textEncryption->setText(encr);
317
textEncryption->clear();
322
textAuthentication->clear();
328
textIpAddress->clear();
332
void WpaGui::updateNetworks()
334
char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
336
int first_active = -1;
337
bool selected = false;
339
if (!networkMayHaveChanged)
342
networkSelect->clear();
344
if (ctrl_conn == NULL)
347
len = sizeof(buf) - 1;
348
if (ctrlRequest("LIST_NETWORKS", buf, &len) < 0)
352
start = strchr(buf, '\n');
359
end = strchr(start, '\n');
363
while (end[0] && end[1])
369
ssid = strchr(id, '\t');
373
bssid = strchr(ssid, '\t');
377
flags = strchr(bssid, '\t');
383
network.append(": ");
384
network.append(ssid);
385
networkSelect->insertItem(network);
387
if (strstr(flags, "[CURRENT]")) {
388
networkSelect->setCurrentItem(networkSelect->count() - 1);
390
} else if (first_active < 0 && strstr(flags, "[DISABLED]") == NULL)
391
first_active = networkSelect->count() - 1;
398
if (!selected && first_active >= 0)
399
networkSelect->setCurrentItem(first_active);
401
networkMayHaveChanged = false;
405
void WpaGui::helpIndex()
407
printf("helpIndex\n");
411
void WpaGui::helpContents()
413
printf("helpContents\n");
417
void WpaGui::helpAbout()
419
QMessageBox::about(this, "wpa_gui for wpa_supplicant",
420
"Copyright (c) 2003-2005,\n"
421
"Jouni Malinen <jkmaline@cc.hut.fi>\n"
422
"and contributors.\n"
424
"This program is free software. You can\n"
425
"distribute it and/or modify it under the terms of\n"
426
"the GNU General Public License version 2.\n"
428
"Alternatively, this software may be distributed\n"
429
"under the terms of the BSD license.\n"
431
"This product includes software developed\n"
432
"by the OpenSSL Project for use in the\n"
433
"OpenSSL Toolkit (http://www.openssl.org/)\n");
437
void WpaGui::disconnect()
440
size_t reply_len = sizeof(reply);
441
ctrlRequest("DISCONNECT", reply, &reply_len);
452
scanres = new ScanResults();
455
scanres->setWpaGui(this);
461
void WpaGui::eventHistory()
468
eh = new EventHistory();
482
if (scanres && !scanres->isVisible()) {
487
if (eh && !eh->isVisible()) {
492
if (udr && !udr->isVisible()) {
497
len = sizeof(buf) - 1;
498
if (ctrlRequest("PING", buf, &len) < 0) {
499
printf("PING failed - trying to reconnect\n");
500
if (openCtrlConnection(ctrl_iface) >= 0) {
501
printf("Reconnected successfully\n");
502
pingsToStatusUpdate = 0;
506
pingsToStatusUpdate--;
507
if (pingsToStatusUpdate <= 0) {
514
static int str_match(const char *a, const char *b)
516
return strncmp(a, b, strlen(b)) == 0;
520
void WpaGui::processMsg(char *msg)
522
char *pos = msg, *pos2;
528
priority = atoi(pos);
529
pos = strchr(pos, '>');
536
WpaMsg wm(pos, priority);
540
while (msgs.count() > 100)
543
/* Update last message with truncated version of the event */
544
if (strncmp(pos, "CTRL-", 5) == 0) {
545
pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' ');
552
QString lastmsg = pos2;
553
lastmsg.truncate(40);
554
textLastMessage->setText(lastmsg);
556
pingsToStatusUpdate = 0;
557
networkMayHaveChanged = true;
559
if (str_match(pos, WPA_CTRL_REQ))
560
processCtrlReq(pos + strlen(WPA_CTRL_REQ));
564
void WpaGui::processCtrlReq(const char *req)
570
udr = new UserDataRequest();
573
if (udr->setParams(this, req) < 0) {
583
void WpaGui::receiveMsgs()
588
while (wpa_ctrl_pending(monitor_conn)) {
589
len = sizeof(buf) - 1;
590
if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
598
void WpaGui::connectB()
601
size_t reply_len = sizeof(reply);
602
ctrlRequest("REASSOCIATE", reply, &reply_len);
606
void WpaGui::selectNetwork( const QString &sel )
610
size_t reply_len = sizeof(reply);
612
int pos = cmd.find(':');
614
printf("Invalid selectNetwork '%s'\n", cmd.ascii());
618
cmd.prepend("SELECT_NETWORK ");
619
ctrlRequest(cmd.ascii(), reply, &reply_len);
623
void WpaGui::editNetwork()
625
QString sel(networkSelect->currentText());
626
int pos = sel.find(':');
628
printf("Invalid selectNetwork '%s'\n", sel.ascii());
633
NetworkConfig *nc = new NetworkConfig();
638
nc->paramsFromConfig(sel.toInt());
644
void WpaGui::triggerUpdate()
647
networkMayHaveChanged = true;
652
void WpaGui::addNetwork()
654
NetworkConfig *nc = new NetworkConfig();