iPXE
Functions
iwmgmt.h File Reference

Wireless network interface management. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
void iwstat (struct net80211_device *dev)
 Print status of 802.11 device. More...
 
int iwlist (struct net80211_device *dev)
 Scan for wireless networks using 802.11 device. More...
 

Detailed Description

Wireless network interface management.

Definition in file iwmgmt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ iwstat()

void iwstat ( struct net80211_device dev)

Print status of 802.11 device.

Parameters
dev802.11 device

Definition at line 41 of file iwmgmt.c.

41  {
42 
43  ifstat ( dev->netdev );
44 
45  printf ( " [802.11 ");
46  if ( dev->state & NET80211_ASSOCIATED ) {
47  printf ( "SSID '%s', ", dev->essid );
48  } else {
49  printf ( "not associated, " );
50  }
51  if ( dev->channel < dev->nr_channels && dev->rate < dev->nr_rates ) {
52  printf ( "Ch:%d Sig:%d", dev->channels[dev->channel].channel_nr,
53  dev->last_signal );
54  switch ( dev->hw->signal_type ) {
55  case NET80211_SIGNAL_NONE:
56  printf ( "?" );
57  break;
58  case NET80211_SIGNAL_ARBITRARY:
59  printf ( "/%d", dev->hw->signal_max );
60  break;
61  case NET80211_SIGNAL_DB:
62  printf ( "/%d dB", dev->hw->signal_max );
63  break;
64  case NET80211_SIGNAL_DBM:
65  printf ( " dBm" );
66  break;
67  }
68  printf ( ", Qual:%d%% Rate:%d Mbps]\n",
69  ( dev->rx_beacon_interval == 0 ? 0 :
70  100 * dev->tx_beacon_interval /
71  dev->rx_beacon_interval ),
72  dev->rates[dev->rate] / 10 );
73  } else {
74  printf ( "antenna off]\n" );
75  }
76 
77  if ( dev->state & NET80211_WORKING ) {
78  printf ( " [associating" );
79  if ( dev->associating )
80  printf ( " to '%s'", dev->associating->essid );
81  printf ( "...]\n" );
82  }
83 }
enum net80211_hw_info::@576 signal_type
Signal strength information that can be provided by the device.
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
char essid[IEEE80211_MAX_SSID_LEN+1]
The human-readable ESSID (network name)
Definition: net80211.h:1064
unsigned signal_max
Maximum signal in arbitrary cases.
Definition: net80211.h:495
char essid[IEEE80211_MAX_SSID_LEN+1]
SSID of the access point we are or will be associated with.
Definition: net80211.h:962
#define NET80211_WORKING
Whether the auto-association task is running.
Definition: net80211.h:212
u32 tx_beacon_interval
Time between AP sending beacons, microseconds.
Definition: net80211.h:971
u8 nr_channels
The number of channels in the channels array.
Definition: net80211.h:809
int last_signal
Signal strength of last received packet.
Definition: net80211.h:986
u8 nr_rates
The number of transmission rates in the rates array.
Definition: net80211.h:821
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
struct net80211_hw_info * hw
Information about the hardware, provided to net80211_register()
Definition: net80211.h:801
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition: net80211.h:818
struct net80211_wlan * associating
Network with which we are associating.
Definition: net80211.h:866
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
void ifstat(struct net_device *netdev)
Print status of network device.
Definition: ifmgmt.c:110
u16 state
State of our association to the network.
Definition: net80211.h:921
u8 channel_nr
A channel number interpreted according to the band.
Definition: net80211.h:405
u32 rx_beacon_interval
Smoothed average time between beacons, microseconds.
Definition: net80211.h:974
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824

References net80211_device::associating, net80211_device::channel, net80211_channel::channel_nr, net80211_device::channels, net80211_device::essid, net80211_wlan::essid, net80211_device::hw, ifstat(), net80211_device::last_signal, NET80211_ASSOCIATED, NET80211_WORKING, net80211_device::netdev, net80211_device::nr_channels, net80211_device::nr_rates, printf(), net80211_device::rate, net80211_device::rates, net80211_device::rx_beacon_interval, net80211_hw_info::signal_max, net80211_hw_info::signal_type, net80211_device::state, and net80211_device::tx_beacon_interval.

Referenced by iwstat_payload().

◆ iwlist()

int iwlist ( struct net80211_device dev)

Scan for wireless networks using 802.11 device.

Parameters
dev802.11 device
activeWhether to use active scanning

The list of networks found will be printed in tabular format.

This function is safe to call at all times, whether the 802.11 device is open or not, but if called while the auto-association task is running it will return an error indication.

Definition at line 120 of file iwmgmt.c.

120  {
121  struct net80211_probe_ctx *ctx;
122  struct list_head *networks;
123  struct net80211_wlan *wlan;
124  char ssid_buf[22];
125  int rc;
126  unsigned i;
127  int was_opened = netdev_is_open ( dev->netdev );
128  int was_channel = dev->channels[dev->channel].channel_nr;
129 
130  if ( ! was_opened ) {
131  dev->state |= NET80211_NO_ASSOC;
132  rc = netdev_open ( dev->netdev );
133  if ( rc < 0 )
134  goto err;
135  }
136 
137  if ( dev->state & NET80211_WORKING ) {
138  rc = -EINVAL;
139  goto err_close_netdev;
140  }
141 
142  if ( ! was_opened ) {
143  rc = net80211_prepare_probe ( dev, dev->hw->bands, 0 );
144  if ( rc < 0 )
145  goto err_close_netdev;
146  }
147 
148  ctx = net80211_probe_start ( dev, "", 0 );
149  if ( ! ctx ) {
150  rc = -ENOMEM;
151  goto err_close_netdev;
152  }
153 
154  while ( ! ( rc = net80211_probe_step ( ctx ) ) ) {
155  step();
156  }
157 
158  networks = net80211_probe_finish_all ( ctx );
159 
160  if ( list_empty ( networks ) ) {
161  goto err_free_networks;
162  }
163 
164  rc = 0;
165 
166  printf ( "Networks on %s:\n\n", dev->netdev->name );
167 
168  /* Output format:
169  * 0 1 2 3 4 5 6
170  * 0123456789012345678901234567890123456789012345678901234567890
171  * [Sig] SSID BSSID Ch Crypt/Auth
172  * -------------------------------------------------------------
173  * [ 15] abcdefghijklmnopqrst> 00:00:00:00:00:00 11 Open
174  * ... or WPA PSK etc.
175  */
176 
177  /* Quoting the dashes and spaces verbatim uses less code space
178  than generating them programmatically. */
179  printf ( "[Sig] SSID BSSID Ch Crypt/Auth\n"
180  "-------------------------------------------------------------\n" );
181 
182  list_for_each_entry ( wlan, networks, list ) {
183 
184  /* Format SSID into 22-character string, space-padded,
185  with '>' indicating truncation */
186 
187  snprintf ( ssid_buf, sizeof ( ssid_buf ), "%s", wlan->essid );
188  for ( i = strlen ( ssid_buf ); i < sizeof ( ssid_buf ) - 1;
189  i++ )
190  ssid_buf[i] = ' ';
191  if ( ssid_buf[sizeof ( ssid_buf ) - 2] != ' ' )
192  ssid_buf[sizeof ( ssid_buf ) - 2] = '>';
193  ssid_buf[sizeof ( ssid_buf ) - 1] = 0;
194 
195  /* Sanity check */
196  if ( wlan->crypto >= NR_CRYPTO_TYPES ||
197  wlan->handshaking >= NR_AUTH_TYPES )
198  continue;
199 
200  printf ( "[%3d] %s %s %2d %s %s\n",
201  wlan->signal < 0 ? 100 + wlan->signal : wlan->signal,
202  ssid_buf, eth_ntoa ( wlan->bssid ), wlan->channel,
203  crypto_types[wlan->crypto],
204  auth_types[wlan->handshaking] );
205  }
206  printf ( "\n" );
207 
208  err_free_networks:
209  net80211_free_wlanlist ( networks );
210 
211  err_close_netdev:
212  if ( ! was_opened ) {
213  dev->state &= ~NET80211_NO_ASSOC;
214  netdev_close ( dev->netdev );
215  } else {
216  net80211_change_channel ( dev, was_channel );
217  }
218 
219  if ( ! rc )
220  return 0;
221 
222  err:
223  printf ( "Scanning for networks on %s: %s\n",
224  dev->netdev->name, strerror ( rc ) );
225  return rc;
226 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Structure representing a probed network.
Definition: net80211.h:1056
enum net80211_crypto_alg crypto
Cryptographic algorithm used on the network.
Definition: net80211.h:1087
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
struct net80211_probe_ctx * net80211_probe_start(struct net80211_device *dev, const char *essid, int active)
Begin probe of 802.11 networks.
Definition: net80211.c:1290
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
char essid[IEEE80211_MAX_SSID_LEN+1]
The human-readable ESSID (network name)
Definition: net80211.h:1064
enum net80211_security_proto handshaking
Security handshaking method used on the network.
Definition: net80211.h:1084
Context for a probe operation.
Definition: net80211.c:63
#define NET80211_WORKING
Whether the auto-association task is running.
Definition: net80211.h:212
A doubly-linked list entry (or list head)
Definition: list.h:18
static const char * auth_types[]
Identifiers for 802.11 authentication types, indexed by type number.
Definition: iwmgmt.c:98
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define ENOMEM
Not enough space.
Definition: errno.h:534
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
struct list_head * net80211_probe_finish_all(struct net80211_probe_ctx *ctx)
Finish probe of 802.11 networks, returning all networks found.
Definition: net80211.c:1585
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
static const char * crypto_types[]
Identifiers for 802.11 cryptography types, indexed by type number.
Definition: iwmgmt.c:86
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
int net80211_probe_step(struct net80211_probe_ctx *ctx)
Continue probe of 802.11 networks.
Definition: net80211.c:1363
void net80211_free_wlanlist(struct list_head *list)
Free list of WLAN structures.
Definition: net80211.c:1619
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
#define NET80211_NO_ASSOC
Whether the auto-association task should be suppressed.
Definition: net80211.h:223
struct net80211_hw_info * hw
Information about the hardware, provided to net80211_register()
Definition: net80211.h:801
#define NR_CRYPTO_TYPES
Number of 802.11 cryptography types defined.
Definition: iwmgmt.c:95
struct list_head list
Link to allow chaining multiple structures into a list to be returned from net80211_probe_finish_all(...
Definition: net80211.h:1091
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
int channel
The channel on which that access point communicates.
Definition: net80211.h:1078
#define NR_AUTH_TYPES
Number of 802.11 authentication types defined.
Definition: iwmgmt.c:106
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int signal
Signal strength of beacon frame from that access point.
Definition: net80211.h:1070
void step(void)
Single-step a single process.
Definition: process.c:98
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
u8 bssid[ETH_ALEN]
MAC address of the strongest-signal access point for this ESSID.
Definition: net80211.h:1067
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
int bands
A bitwise OR of the bands on which this device can communicate.
Definition: net80211.h:453
u16 state
State of our association to the network.
Definition: net80211.h:921
u8 channel_nr
A channel number interpreted according to the band.
Definition: net80211.h:405
int net80211_change_channel(struct net80211_device *dev, int channel)
Configure 802.11 device to transmit on a certain channel.
Definition: net80211.c:2021
int net80211_prepare_probe(struct net80211_device *dev, int band, int active)
Prepare 802.11 device channel and rate set for scanning.
Definition: net80211.c:2051
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861

References auth_types, net80211_hw_info::bands, net80211_wlan::bssid, net80211_device::channel, net80211_wlan::channel, net80211_channel::channel_nr, net80211_device::channels, net80211_wlan::crypto, crypto_types, ctx, EINVAL, ENOMEM, net80211_wlan::essid, eth_ntoa(), net80211_wlan::handshaking, net80211_device::hw, net80211_wlan::list, list_empty, list_for_each_entry, net_device::name, net80211_change_channel(), net80211_free_wlanlist(), NET80211_NO_ASSOC, net80211_prepare_probe(), net80211_probe_finish_all(), net80211_probe_start(), net80211_probe_step(), NET80211_WORKING, net80211_device::netdev, netdev_close(), netdev_is_open(), netdev_open(), NR_AUTH_TYPES, NR_CRYPTO_TYPES, printf(), rc, net80211_wlan::signal, snprintf(), net80211_device::state, step(), strerror(), and strlen().

Referenced by iwlist_payload().