~ubuntu-branches/ubuntu/hardy/wpasupplicant/hardy

« back to all changes in this revision

Viewing changes to wpa_supplicant/wpa_gui-qt4/wpagui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Alexander Sack
  • Date: 2007-08-26 16:06:57 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070826160657-2m8pxoweuxe8f93t
Tags: 0.6.0+0.5.8-0ubuntu1
* New upstream release
* remove patch 11_erroneous_manpage_ref, applied upstream
* remove patch 25_wpas_dbus_unregister_iface_fix, applied upstream

[ Alexander Sack ]
* bumping upstream version to replace development version 0.6.0 with
  this package from stable release branch.
* attempt to fix wierd timeout and high latency issues by going
  back to stable upstream version (0.5.9) (LP: #140763,
  LP: #141233).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * wpa_gui - WpaGui class
3
 
 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 2 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * Alternatively, this software may be distributed under the terms of BSD
10
 
 * license.
11
 
 *
12
 
 * See README and COPYING for more details.
13
 
 */
14
 
 
15
 
#ifdef __MINGW32__
16
 
/* Need to get getopt() */
17
 
#include <unistd.h>
18
 
#endif
19
 
 
20
 
#include <QMessageBox>
21
 
 
22
 
#include "wpagui.h"
23
 
#include "dirent.h"
24
 
#include "wpa_ctrl.h"
25
 
#include "userdatarequest.h"
26
 
#include "networkconfig.h"
27
 
 
28
 
WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
29
 
        : QMainWindow(parent)
30
 
{
31
 
        setupUi(this);
32
 
 
33
 
        (void) statusBar();
34
 
 
35
 
        connect(helpIndexAction, SIGNAL(activated()), this, SLOT(helpIndex()));
36
 
        connect(helpContentsAction, SIGNAL(activated()), this,
37
 
                SLOT(helpContents()));
38
 
        connect(helpAboutAction, SIGNAL(activated()), this, SLOT(helpAbout()));
39
 
        connect(fileExitAction, SIGNAL(activated()), this, SLOT(close()));
40
 
        connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
41
 
        connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
42
 
        connect(connectButton, SIGNAL(clicked()), this, SLOT(connectB()));
43
 
        connect(fileEventHistoryAction, SIGNAL(activated()), this,
44
 
                SLOT(eventHistory()));
45
 
        connect(networkSelect, SIGNAL(activated(const QString&)), this,
46
 
                SLOT(selectNetwork(const QString&)));
47
 
        connect(fileEdit_networkAction, SIGNAL(activated()), this,
48
 
                SLOT(editNetwork()));
49
 
        connect(fileAdd_NetworkAction, SIGNAL(activated()), this,
50
 
                SLOT(addNetwork()));
51
 
        connect(adapterSelect, SIGNAL(activated(const QString&)), this,
52
 
                SLOT(selectAdapter(const QString&)));
53
 
 
54
 
        eh = NULL;
55
 
        scanres = NULL;
56
 
        udr = NULL;
57
 
        ctrl_iface = NULL;
58
 
        ctrl_conn = NULL;
59
 
        monitor_conn = NULL;
60
 
        msgNotifier = NULL;
61
 
        ctrl_iface_dir = strdup("/var/run/wpa_supplicant");
62
 
 
63
 
        parse_argv();
64
 
 
65
 
        textStatus->setText("connecting to wpa_supplicant");
66
 
        timer = new QTimer(this);
67
 
        connect(timer, SIGNAL(timeout()), SLOT(ping()));
68
 
        timer->start(1000, FALSE);
69
 
 
70
 
        if (openCtrlConnection(ctrl_iface) < 0) {
71
 
                printf("Failed to open control connection to "
72
 
                       "wpa_supplicant.\n");
73
 
        }
74
 
 
75
 
        updateStatus();
76
 
        networkMayHaveChanged = true;
77
 
        updateNetworks();
78
 
}
79
 
 
80
 
 
81
 
WpaGui::~WpaGui()
82
 
{
83
 
        delete msgNotifier;
84
 
 
85
 
        if (monitor_conn) {
86
 
                wpa_ctrl_detach(monitor_conn);
87
 
                wpa_ctrl_close(monitor_conn);
88
 
                monitor_conn = NULL;
89
 
        }
90
 
        if (ctrl_conn) {
91
 
                wpa_ctrl_close(ctrl_conn);
92
 
                ctrl_conn = NULL;
93
 
        }
94
 
 
95
 
        if (eh) {
96
 
                eh->close();
97
 
                delete eh;
98
 
                eh = NULL;
99
 
        }
100
 
 
101
 
        if (scanres) {
102
 
                scanres->close();
103
 
                delete scanres;
104
 
                scanres = NULL;
105
 
        }
106
 
 
107
 
        if (udr) {
108
 
                udr->close();
109
 
                delete udr;
110
 
                udr = NULL;
111
 
        }
112
 
 
113
 
        free(ctrl_iface);
114
 
        ctrl_iface = NULL;
115
 
 
116
 
        free(ctrl_iface_dir);
117
 
        ctrl_iface_dir = NULL;
118
 
}
119
 
 
120
 
 
121
 
void WpaGui::languageChange()
122
 
{
123
 
        retranslateUi(this);
124
 
}
125
 
 
126
 
 
127
 
void WpaGui::parse_argv()
128
 
{
129
 
        int c;
130
 
        for (;;) {
131
 
                c = getopt(qApp->argc(), qApp->argv(), "i:p:");
132
 
                if (c < 0)
133
 
                        break;
134
 
                switch (c) {
135
 
                case 'i':
136
 
                        free(ctrl_iface);
137
 
                        ctrl_iface = strdup(optarg);
138
 
                        break;
139
 
                case 'p':
140
 
                        free(ctrl_iface_dir);
141
 
                        ctrl_iface_dir = strdup(optarg);
142
 
                        break;
143
 
                }
144
 
        }
145
 
}
146
 
 
147
 
 
148
 
int WpaGui::openCtrlConnection(const char *ifname)
149
 
{
150
 
        char *cfile;
151
 
        int flen;
152
 
        char buf[2048], *pos, *pos2;
153
 
        size_t len;
154
 
 
155
 
        if (ifname) {
156
 
                if (ifname != ctrl_iface) {
157
 
                        free(ctrl_iface);
158
 
                        ctrl_iface = strdup(ifname);
159
 
                }
160
 
        } else {
161
 
#ifdef CONFIG_CTRL_IFACE_UDP
162
 
                free(ctrl_iface);
163
 
                ctrl_iface = strdup("udp");
164
 
#endif /* CONFIG_CTRL_IFACE_UDP */
165
 
#ifdef CONFIG_CTRL_IFACE_UNIX
166
 
                struct dirent *dent;
167
 
                DIR *dir = opendir(ctrl_iface_dir);
168
 
                free(ctrl_iface);
169
 
                ctrl_iface = NULL;
170
 
                if (dir) {
171
 
                        while ((dent = readdir(dir))) {
172
 
#ifdef _DIRENT_HAVE_D_TYPE
173
 
                                /* Skip the file if it is not a socket.
174
 
                                 * Also accept DT_UNKNOWN (0) in case
175
 
                                 * the C library or underlying file
176
 
                                 * system does not support d_type. */
177
 
                                if (dent->d_type != DT_SOCK &&
178
 
                                    dent->d_type != DT_UNKNOWN)
179
 
                                        continue;
180
 
#endif /* _DIRENT_HAVE_D_TYPE */
181
 
 
182
 
                                if (strcmp(dent->d_name, ".") == 0 ||
183
 
                                    strcmp(dent->d_name, "..") == 0)
184
 
                                        continue;
185
 
                                printf("Selected interface '%s'\n",
186
 
                                       dent->d_name);
187
 
                                ctrl_iface = strdup(dent->d_name);
188
 
                                break;
189
 
                        }
190
 
                        closedir(dir);
191
 
                }
192
 
#endif /* CONFIG_CTRL_IFACE_UNIX */
193
 
#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
194
 
                struct wpa_ctrl *ctrl;
195
 
                int ret;
196
 
 
197
 
                free(ctrl_iface);
198
 
                ctrl_iface = NULL;
199
 
 
200
 
                ctrl = wpa_ctrl_open(NULL);
201
 
                if (ctrl) {
202
 
                        len = sizeof(buf) - 1;
203
 
                        ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
204
 
                                               &len, NULL);
205
 
                        if (ret >= 0) {
206
 
                                buf[len] = '\0';
207
 
                                pos = strchr(buf, '\n');
208
 
                                if (pos)
209
 
                                        *pos = '\0';
210
 
                                ctrl_iface = strdup(buf);
211
 
                        }
212
 
                        wpa_ctrl_close(ctrl);
213
 
                }
214
 
#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
215
 
        }
216
 
 
217
 
        if (ctrl_iface == NULL)
218
 
                return -1;
219
 
 
220
 
#ifdef CONFIG_CTRL_IFACE_UNIX
221
 
        flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
222
 
        cfile = (char *) malloc(flen);
223
 
        if (cfile == NULL)
224
 
                return -1;
225
 
        snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
226
 
#else /* CONFIG_CTRL_IFACE_UNIX */
227
 
        flen = strlen(ctrl_iface) + 1;
228
 
        cfile = (char *) malloc(flen);
229
 
        if (cfile == NULL)
230
 
                return -1;
231
 
        snprintf(cfile, flen, "%s", ctrl_iface);
232
 
#endif /* CONFIG_CTRL_IFACE_UNIX */
233
 
 
234
 
        if (ctrl_conn) {
235
 
                wpa_ctrl_close(ctrl_conn);
236
 
                ctrl_conn = NULL;
237
 
        }
238
 
 
239
 
        if (monitor_conn) {
240
 
                delete msgNotifier;
241
 
                msgNotifier = NULL;
242
 
                wpa_ctrl_detach(monitor_conn);
243
 
                wpa_ctrl_close(monitor_conn);
244
 
                monitor_conn = NULL;
245
 
        }
246
 
 
247
 
        printf("Trying to connect to '%s'\n", cfile);
248
 
        ctrl_conn = wpa_ctrl_open(cfile);
249
 
        if (ctrl_conn == NULL) {
250
 
                free(cfile);
251
 
                return -1;
252
 
        }
253
 
        monitor_conn = wpa_ctrl_open(cfile);
254
 
        free(cfile);
255
 
        if (monitor_conn == NULL) {
256
 
                wpa_ctrl_close(ctrl_conn);
257
 
                return -1;
258
 
        }
259
 
        if (wpa_ctrl_attach(monitor_conn)) {
260
 
                printf("Failed to attach to wpa_supplicant\n");
261
 
                wpa_ctrl_close(monitor_conn);
262
 
                monitor_conn = NULL;
263
 
                wpa_ctrl_close(ctrl_conn);
264
 
                ctrl_conn = NULL;
265
 
                return -1;
266
 
        }
267
 
 
268
 
#if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
269
 
        msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
270
 
                                          QSocketNotifier::Read, this);
271
 
        connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
272
 
#endif
273
 
 
274
 
        adapterSelect->clear();
275
 
        adapterSelect->insertItem(ctrl_iface);
276
 
        adapterSelect->setCurrentItem(0);
277
 
 
278
 
        len = sizeof(buf) - 1;
279
 
        if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
280
 
            0) {
281
 
                buf[len] = '\0';
282
 
                pos = buf;
283
 
                while (*pos) {
284
 
                        pos2 = strchr(pos, '\n');
285
 
                        if (pos2)
286
 
                                *pos2 = '\0';
287
 
                        if (strcmp(pos, ctrl_iface) != 0)
288
 
                                adapterSelect->insertItem(pos);
289
 
                        if (pos2)
290
 
                                pos = pos2 + 1;
291
 
                        else
292
 
                                break;
293
 
                }
294
 
        }
295
 
 
296
 
        return 0;
297
 
}
298
 
 
299
 
 
300
 
static void wpa_gui_msg_cb(char *msg, size_t)
301
 
{
302
 
        /* This should not happen anymore since two control connections are
303
 
         * used. */
304
 
        printf("missed message: %s\n", msg);
305
 
}
306
 
 
307
 
 
308
 
int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
309
 
{
310
 
        int ret;
311
 
 
312
 
        if (ctrl_conn == NULL)
313
 
                return -3;
314
 
        ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen,
315
 
                               wpa_gui_msg_cb);
316
 
        if (ret == -2)
317
 
                printf("'%s' command timed out.\n", cmd);
318
 
        else if (ret < 0)
319
 
                printf("'%s' command failed.\n", cmd);
320
 
 
321
 
        return ret;
322
 
}
323
 
 
324
 
 
325
 
void WpaGui::updateStatus()
326
 
{
327
 
        char buf[2048], *start, *end, *pos;
328
 
        size_t len;
329
 
 
330
 
        pingsToStatusUpdate = 10;
331
 
 
332
 
        len = sizeof(buf) - 1;
333
 
        if (ctrl_conn == NULL || ctrlRequest("STATUS", buf, &len) < 0) {
334
 
                textStatus->setText("Could not get status from "
335
 
                                    "wpa_supplicant");
336
 
                textAuthentication->clear();
337
 
                textEncryption->clear();
338
 
                textSsid->clear();
339
 
                textBssid->clear();
340
 
                textIpAddress->clear();
341
 
                return;
342
 
        }
343
 
 
344
 
        buf[len] = '\0';
345
 
 
346
 
        bool auth_updated = false, ssid_updated = false;
347
 
        bool bssid_updated = false, ipaddr_updated = false;
348
 
        bool status_updated = false;
349
 
        char *pairwise_cipher = NULL, *group_cipher = NULL;
350
 
 
351
 
        start = buf;
352
 
        while (*start) {
353
 
                bool last = false;
354
 
                end = strchr(start, '\n');
355
 
                if (end == NULL) {
356
 
                        last = true;
357
 
                        end = start;
358
 
                        while (end[0] && end[1])
359
 
                                end++;
360
 
                }
361
 
                *end = '\0';
362
 
 
363
 
                pos = strchr(start, '=');
364
 
                if (pos) {
365
 
                        *pos++ = '\0';
366
 
                        if (strcmp(start, "bssid") == 0) {
367
 
                                bssid_updated = true;
368
 
                                textBssid->setText(pos);
369
 
                        } else if (strcmp(start, "ssid") == 0) {
370
 
                                ssid_updated = true;
371
 
                                textSsid->setText(pos);
372
 
                        } else if (strcmp(start, "ip_address") == 0) {
373
 
                                ipaddr_updated = true;
374
 
                                textIpAddress->setText(pos);
375
 
                        } else if (strcmp(start, "wpa_state") == 0) {
376
 
                                status_updated = true;
377
 
                                textStatus->setText(pos);
378
 
                        } else if (strcmp(start, "key_mgmt") == 0) {
379
 
                                auth_updated = true;
380
 
                                textAuthentication->setText(pos);
381
 
                                /* TODO: could add EAP status to this */
382
 
                        } else if (strcmp(start, "pairwise_cipher") == 0) {
383
 
                                pairwise_cipher = pos;
384
 
                        } else if (strcmp(start, "group_cipher") == 0) {
385
 
                                group_cipher = pos;
386
 
                        }
387
 
                }
388
 
 
389
 
                if (last)
390
 
                        break;
391
 
                start = end + 1;
392
 
        }
393
 
 
394
 
        if (pairwise_cipher || group_cipher) {
395
 
                QString encr;
396
 
                if (pairwise_cipher && group_cipher &&
397
 
                    strcmp(pairwise_cipher, group_cipher) != 0) {
398
 
                        encr.append(pairwise_cipher);
399
 
                        encr.append(" + ");
400
 
                        encr.append(group_cipher);
401
 
                } else if (pairwise_cipher) {
402
 
                        encr.append(pairwise_cipher);
403
 
                } else {
404
 
                        encr.append(group_cipher);
405
 
                        encr.append(" [group key only]");
406
 
                }
407
 
                textEncryption->setText(encr);
408
 
        } else
409
 
                textEncryption->clear();
410
 
 
411
 
        if (!status_updated)
412
 
                textStatus->clear();
413
 
        if (!auth_updated)
414
 
                textAuthentication->clear();
415
 
        if (!ssid_updated)
416
 
                textSsid->clear();
417
 
        if (!bssid_updated)
418
 
                textBssid->clear();
419
 
        if (!ipaddr_updated)
420
 
                textIpAddress->clear();
421
 
}
422
 
 
423
 
 
424
 
void WpaGui::updateNetworks()
425
 
{
426
 
        char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
427
 
        size_t len;
428
 
        int first_active = -1;
429
 
        bool selected = false;
430
 
 
431
 
        if (!networkMayHaveChanged)
432
 
                return;
433
 
 
434
 
        networkSelect->clear();
435
 
 
436
 
        if (ctrl_conn == NULL)
437
 
                return;
438
 
 
439
 
        len = sizeof(buf) - 1;
440
 
        if (ctrlRequest("LIST_NETWORKS", buf, &len) < 0)
441
 
                return;
442
 
 
443
 
        buf[len] = '\0';
444
 
        start = strchr(buf, '\n');
445
 
        if (start == NULL)
446
 
                return;
447
 
        start++;
448
 
 
449
 
        while (*start) {
450
 
                bool last = false;
451
 
                end = strchr(start, '\n');
452
 
                if (end == NULL) {
453
 
                        last = true;
454
 
                        end = start;
455
 
                        while (end[0] && end[1])
456
 
                                end++;
457
 
                }
458
 
                *end = '\0';
459
 
 
460
 
                id = start;
461
 
                ssid = strchr(id, '\t');
462
 
                if (ssid == NULL)
463
 
                        break;
464
 
                *ssid++ = '\0';
465
 
                bssid = strchr(ssid, '\t');
466
 
                if (bssid == NULL)
467
 
                        break;
468
 
                *bssid++ = '\0';
469
 
                flags = strchr(bssid, '\t');
470
 
                if (flags == NULL)
471
 
                        break;
472
 
                *flags++ = '\0';
473
 
 
474
 
                QString network(id);
475
 
                network.append(": ");
476
 
                network.append(ssid);
477
 
                networkSelect->insertItem(network);
478
 
 
479
 
                if (strstr(flags, "[CURRENT]")) {
480
 
                        networkSelect->setCurrentItem(networkSelect->count() -
481
 
                                                      1);
482
 
                        selected = true;
483
 
                } else if (first_active < 0 &&
484
 
                           strstr(flags, "[DISABLED]") == NULL)
485
 
                        first_active = networkSelect->count() - 1;
486
 
 
487
 
                if (last)
488
 
                        break;
489
 
                start = end + 1;
490
 
        }
491
 
 
492
 
        if (!selected && first_active >= 0)
493
 
                networkSelect->setCurrentItem(first_active);
494
 
 
495
 
        networkMayHaveChanged = false;
496
 
}
497
 
 
498
 
 
499
 
void WpaGui::helpIndex()
500
 
{
501
 
        printf("helpIndex\n");
502
 
}
503
 
 
504
 
 
505
 
void WpaGui::helpContents()
506
 
{
507
 
        printf("helpContents\n");
508
 
}
509
 
 
510
 
 
511
 
void WpaGui::helpAbout()
512
 
{
513
 
        QMessageBox::about(this, "wpa_gui for wpa_supplicant",
514
 
                           "Copyright (c) 2003-2006,\n"
515
 
                           "Jouni Malinen <j@w1.fi>\n"
516
 
                           "and contributors.\n"
517
 
                           "\n"
518
 
                           "This program is free software. You can\n"
519
 
                           "distribute it and/or modify it under the terms "
520
 
                           "of\n"
521
 
                           "the GNU General Public License version 2.\n"
522
 
                           "\n"
523
 
                           "Alternatively, this software may be distributed\n"
524
 
                           "under the terms of the BSD license.\n"
525
 
                           "\n"
526
 
                           "This product includes software developed\n"
527
 
                           "by the OpenSSL Project for use in the\n"
528
 
                           "OpenSSL Toolkit (http://www.openssl.org/)\n");
529
 
}
530
 
 
531
 
 
532
 
void WpaGui::disconnect()
533
 
{
534
 
        char reply[10];
535
 
        size_t reply_len = sizeof(reply);
536
 
        ctrlRequest("DISCONNECT", reply, &reply_len);
537
 
}
538
 
 
539
 
 
540
 
void WpaGui::scan()
541
 
{
542
 
        if (scanres) {
543
 
                scanres->close();
544
 
                delete scanres;
545
 
        }
546
 
 
547
 
        scanres = new ScanResults();
548
 
        if (scanres == NULL)
549
 
                return;
550
 
        scanres->setWpaGui(this);
551
 
        scanres->show();
552
 
        scanres->exec();
553
 
}
554
 
 
555
 
 
556
 
void WpaGui::eventHistory()
557
 
{
558
 
        if (eh) {
559
 
                eh->close();
560
 
                delete eh;
561
 
        }
562
 
 
563
 
        eh = new EventHistory();
564
 
        if (eh == NULL)
565
 
                return;
566
 
        eh->addEvents(msgs);
567
 
        eh->show();
568
 
        eh->exec();
569
 
}
570
 
 
571
 
 
572
 
void WpaGui::ping()
573
 
{
574
 
        char buf[10];
575
 
        size_t len;
576
 
 
577
 
#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
578
 
        /*
579
 
         * QSocketNotifier cannot be used with Windows named pipes, so use a
580
 
         * timer to check for received messages for now. This could be
581
 
         * optimized be doing something specific to named pipes or Windows
582
 
         * events, but it is not clear what would be the best way of doing that
583
 
         * in Qt.
584
 
         */
585
 
        receiveMsgs();
586
 
#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
587
 
 
588
 
        if (scanres && !scanres->isVisible()) {
589
 
                delete scanres;
590
 
                scanres = NULL;
591
 
        }
592
 
 
593
 
        if (eh && !eh->isVisible()) {
594
 
                delete eh;
595
 
                eh = NULL;
596
 
        }
597
 
 
598
 
        if (udr && !udr->isVisible()) {
599
 
                delete udr;
600
 
                udr = NULL;
601
 
        }
602
 
 
603
 
        len = sizeof(buf) - 1;
604
 
        if (ctrlRequest("PING", buf, &len) < 0) {
605
 
                printf("PING failed - trying to reconnect\n");
606
 
                if (openCtrlConnection(ctrl_iface) >= 0) {
607
 
                        printf("Reconnected successfully\n");
608
 
                        pingsToStatusUpdate = 0;
609
 
                }
610
 
        }
611
 
 
612
 
        pingsToStatusUpdate--;
613
 
        if (pingsToStatusUpdate <= 0) {
614
 
                updateStatus();
615
 
                updateNetworks();
616
 
        }
617
 
}
618
 
 
619
 
 
620
 
static int str_match(const char *a, const char *b)
621
 
{
622
 
        return strncmp(a, b, strlen(b)) == 0;
623
 
}
624
 
 
625
 
 
626
 
void WpaGui::processMsg(char *msg)
627
 
{
628
 
        char *pos = msg, *pos2;
629
 
        int priority = 2;
630
 
 
631
 
        if (*pos == '<') {
632
 
                /* skip priority */
633
 
                pos++;
634
 
                priority = atoi(pos);
635
 
                pos = strchr(pos, '>');
636
 
                if (pos)
637
 
                        pos++;
638
 
                else
639
 
                        pos = msg;
640
 
        }
641
 
 
642
 
        WpaMsg wm(pos, priority);
643
 
        if (eh)
644
 
                eh->addEvent(wm);
645
 
        msgs.append(wm);
646
 
        while (msgs.count() > 100)
647
 
                msgs.pop_front();
648
 
 
649
 
        /* Update last message with truncated version of the event */
650
 
        if (strncmp(pos, "CTRL-", 5) == 0) {
651
 
                pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' ');
652
 
                if (pos2)
653
 
                        pos2++;
654
 
                else
655
 
                        pos2 = pos;
656
 
        } else
657
 
                pos2 = pos;
658
 
        QString lastmsg = pos2;
659
 
        lastmsg.truncate(40);
660
 
        textLastMessage->setText(lastmsg);
661
 
 
662
 
        pingsToStatusUpdate = 0;
663
 
        networkMayHaveChanged = true;
664
 
 
665
 
        if (str_match(pos, WPA_CTRL_REQ))
666
 
                processCtrlReq(pos + strlen(WPA_CTRL_REQ));
667
 
}
668
 
 
669
 
 
670
 
void WpaGui::processCtrlReq(const char *req)
671
 
{
672
 
        if (udr) {
673
 
                udr->close();
674
 
                delete udr;
675
 
        }
676
 
        udr = new UserDataRequest();
677
 
        if (udr == NULL)
678
 
                return;
679
 
        if (udr->setParams(this, req) < 0) {
680
 
                delete udr;
681
 
                udr = NULL;
682
 
                return;
683
 
        }
684
 
        udr->show();
685
 
        udr->exec();
686
 
}
687
 
 
688
 
 
689
 
void WpaGui::receiveMsgs()
690
 
{
691
 
        char buf[256];
692
 
        size_t len;
693
 
 
694
 
        while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
695
 
                len = sizeof(buf) - 1;
696
 
                if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
697
 
                        buf[len] = '\0';
698
 
                        processMsg(buf);
699
 
                }
700
 
        }
701
 
}
702
 
 
703
 
 
704
 
void WpaGui::connectB()
705
 
{
706
 
        char reply[10];
707
 
        size_t reply_len = sizeof(reply);
708
 
        ctrlRequest("REASSOCIATE", reply, &reply_len);
709
 
}
710
 
 
711
 
 
712
 
void WpaGui::selectNetwork( const QString &sel )
713
 
{
714
 
        QString cmd(sel);
715
 
        char reply[10];
716
 
        size_t reply_len = sizeof(reply);
717
 
 
718
 
        int pos = cmd.find(':');
719
 
        if (pos < 0) {
720
 
                printf("Invalid selectNetwork '%s'\n", cmd.ascii());
721
 
                return;
722
 
        }
723
 
        cmd.truncate(pos);
724
 
        cmd.prepend("SELECT_NETWORK ");
725
 
        ctrlRequest(cmd.ascii(), reply, &reply_len);
726
 
}
727
 
 
728
 
 
729
 
void WpaGui::editNetwork()
730
 
{
731
 
        QString sel(networkSelect->currentText());
732
 
        int pos = sel.find(':');
733
 
        if (pos < 0) {
734
 
                printf("Invalid selectNetwork '%s'\n", sel.ascii());
735
 
                return;
736
 
        }
737
 
        sel.truncate(pos);
738
 
 
739
 
        NetworkConfig *nc = new NetworkConfig();
740
 
        if (nc == NULL)
741
 
                return;
742
 
        nc->setWpaGui(this);
743
 
 
744
 
        nc->paramsFromConfig(sel.toInt());
745
 
        nc->show();
746
 
        nc->exec();
747
 
}
748
 
 
749
 
 
750
 
void WpaGui::triggerUpdate()
751
 
{
752
 
        updateStatus();
753
 
        networkMayHaveChanged = true;
754
 
        updateNetworks();
755
 
}
756
 
 
757
 
 
758
 
void WpaGui::addNetwork()
759
 
{
760
 
        NetworkConfig *nc = new NetworkConfig();
761
 
        if (nc == NULL)
762
 
                return;
763
 
        nc->setWpaGui(this);
764
 
        nc->newNetwork();
765
 
        nc->show();
766
 
        nc->exec();
767
 
}
768
 
 
769
 
 
770
 
void WpaGui::selectAdapter( const QString & sel )
771
 
{
772
 
        if (openCtrlConnection(sel.ascii()) < 0)
773
 
                printf("Failed to open control connection to "
774
 
                       "wpa_supplicant.\n");
775
 
        updateStatus();
776
 
        updateNetworks();
777
 
}