2
* Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
FILE_LICENCE ( GPL2_OR_LATER );
24
#include <ipxe/net80211.h>
25
#include <ipxe/ethernet.h>
26
#include <usr/ifmgmt.h>
27
#include <usr/iwmgmt.h>
31
* Wireless network interface management
36
* Print status of 802.11 device
38
* @v dev 802.11 device
40
void iwstat ( struct net80211_device *dev ) {
42
ifstat ( dev->netdev );
44
printf ( " [802.11 ");
45
if ( dev->state & NET80211_ASSOCIATED ) {
46
printf ( "SSID '%s', ", dev->essid );
48
printf ( "not associated, " );
50
if ( dev->channel < dev->nr_channels && dev->rate < dev->nr_rates ) {
51
printf ( "Ch:%d Sig:%d", dev->channels[dev->channel].channel_nr,
53
switch ( dev->hw->signal_type ) {
54
case NET80211_SIGNAL_NONE:
57
case NET80211_SIGNAL_ARBITRARY:
58
printf ( "/%d", dev->hw->signal_max );
60
case NET80211_SIGNAL_DB:
61
printf ( "/%d dB", dev->hw->signal_max );
63
case NET80211_SIGNAL_DBM:
67
printf ( ", Qual:%d%% Rate:%d Mbps]\n",
68
( dev->rx_beacon_interval == 0 ? 0 :
69
100 * dev->tx_beacon_interval /
70
dev->rx_beacon_interval ),
71
dev->rates[dev->rate] / 10 );
73
printf ( "antenna off]\n" );
76
if ( dev->state & NET80211_WORKING ) {
77
printf ( " [associating" );
78
if ( dev->associating )
79
printf ( " to '%s'", dev->associating->essid );
84
/** Identifiers for 802.11 cryptography types, indexed by type number */
85
static const char *crypto_types[] = {
86
[NET80211_CRYPT_NONE] = "Open",
87
[NET80211_CRYPT_WEP] = "WEP ",
88
[NET80211_CRYPT_TKIP] = "WPA ",
89
[NET80211_CRYPT_CCMP] = "WPA2",
90
[NET80211_CRYPT_UNKNOWN] = "UNK ",
93
/** Number of 802.11 cryptography types defined */
94
#define NR_CRYPTO_TYPES ( sizeof ( crypto_types ) / sizeof ( crypto_types[0] ) )
96
/** Identifiers for 802.11 authentication types, indexed by type number */
97
static const char *auth_types[] = {
98
[NET80211_SECPROT_NONE] = "",
99
[NET80211_SECPROT_PSK] = "PSK",
100
[NET80211_SECPROT_EAP] = "802.1X",
101
[NET80211_SECPROT_UNKNOWN] = "UNK",
104
/** Number of 802.11 authentication types defined */
105
#define NR_AUTH_TYPES ( sizeof ( auth_types ) / sizeof ( auth_types[0] ) )
108
* Scan for wireless networks using 802.11 device
110
* @v dev 802.11 device
111
* @v active Whether to use active scanning
113
* The list of networks found will be printed in tabular format.
115
* This function is safe to call at all times, whether the 802.11
116
* device is open or not, but if called while the auto-association
117
* task is running it will return an error indication.
119
int iwlist ( struct net80211_device *dev ) {
120
struct net80211_probe_ctx *ctx;
121
struct list_head *networks;
122
struct net80211_wlan *wlan;
126
int was_opened = netdev_is_open ( dev->netdev );
127
int was_channel = dev->channels[dev->channel].channel_nr;
129
if ( ! was_opened ) {
130
dev->state |= NET80211_NO_ASSOC;
131
rc = netdev_open ( dev->netdev );
136
if ( dev->state & NET80211_WORKING ) {
138
goto err_close_netdev;
141
if ( ! was_opened ) {
142
rc = net80211_prepare_probe ( dev, dev->hw->bands, 0 );
144
goto err_close_netdev;
147
ctx = net80211_probe_start ( dev, "", 0 );
150
goto err_close_netdev;
153
while ( ! ( rc = net80211_probe_step ( ctx ) ) ) {
157
networks = net80211_probe_finish_all ( ctx );
159
if ( list_empty ( networks ) ) {
160
goto err_free_networks;
165
printf ( "Networks on %s:\n\n", dev->netdev->name );
169
* 0123456789012345678901234567890123456789012345678901234567890
170
* [Sig] SSID BSSID Ch Crypt/Auth
171
* -------------------------------------------------------------
172
* [ 15] abcdefghijklmnopqrst> 00:00:00:00:00:00 11 Open
173
* ... or WPA PSK etc.
176
/* Quoting the dashes and spaces verbatim uses less code space
177
than generating them programmatically. */
178
printf ( "[Sig] SSID BSSID Ch Crypt/Auth\n"
179
"-------------------------------------------------------------\n" );
181
list_for_each_entry ( wlan, networks, list ) {
183
/* Format SSID into 22-character string, space-padded,
184
with '>' indicating truncation */
186
snprintf ( ssid_buf, sizeof ( ssid_buf ), "%s", wlan->essid );
187
for ( i = strlen ( ssid_buf ); i < sizeof ( ssid_buf ) - 1;
190
if ( ssid_buf[sizeof ( ssid_buf ) - 2] != ' ' )
191
ssid_buf[sizeof ( ssid_buf ) - 2] = '>';
192
ssid_buf[sizeof ( ssid_buf ) - 1] = 0;
195
if ( wlan->crypto >= NR_CRYPTO_TYPES ||
196
wlan->handshaking >= NR_AUTH_TYPES )
199
printf ( "[%3d] %s %s %2d %s %s\n",
200
wlan->signal < 0 ? 100 + wlan->signal : wlan->signal,
201
ssid_buf, eth_ntoa ( wlan->bssid ), wlan->channel,
202
crypto_types[wlan->crypto],
203
auth_types[wlan->handshaking] );
208
net80211_free_wlanlist ( networks );
211
if ( ! was_opened ) {
212
dev->state &= ~NET80211_NO_ASSOC;
213
netdev_close ( dev->netdev );
215
net80211_change_channel ( dev, was_channel );
222
printf ( "Scanning for networks on %s: %s\n",
223
dev->netdev->name, strerror ( rc ) );