iPXE
Functions
802.11 network location API

Functions

int net80211_prepare_probe (struct net80211_device *dev, int band, int active)
 Prepare 802.11 device channel and rate set for scanning. More...
 
struct net80211_probe_ctxnet80211_probe_start (struct net80211_device *dev, const char *essid, int active)
 Begin probe of 802.11 networks. More...
 
int net80211_probe_step (struct net80211_probe_ctx *ctx)
 Continue probe of 802.11 networks. More...
 
struct net80211_wlannet80211_probe_finish_best (struct net80211_probe_ctx *ctx)
 Finish probe of 802.11 networks, returning best-signal network found. More...
 
struct list_headnet80211_probe_finish_all (struct net80211_probe_ctx *ctx)
 Finish probe of 802.11 networks, returning all networks found. More...
 
void net80211_free_wlan (struct net80211_wlan *wlan)
 Free WLAN structure. More...
 
void net80211_free_wlanlist (struct list_head *list)
 Free list of WLAN structures. More...
 

Detailed Description

Function Documentation

◆ net80211_prepare_probe()

int net80211_prepare_probe ( struct net80211_device dev,
int  band,
int  active 
)

Prepare 802.11 device channel and rate set for scanning.

Parameters
dev802.11 device
bandRF band(s) on which to prepare for scanning
activeWhether the scanning will be active
Return values
rcReturn status code

Definition at line 2051 of file net80211.c.

2053 {
2054  assert ( netdev_is_open ( dev->netdev ) );
2055 
2056  if ( active && ( band & NET80211_BAND_BIT_5GHZ ) ) {
2057  DBGC ( dev, "802.11 %p cannot perform active scanning on "
2058  "5GHz band\n", dev );
2059  return -EINVAL_ACTIVE_SCAN;
2060  }
2061 
2062  if ( band == 0 ) {
2063  /* This can happen for a 5GHz-only card with 5GHz
2064  scanning masked out by an active request. */
2065  DBGC ( dev, "802.11 %p asked to prepare for scanning nothing\n",
2066  dev );
2067  return -EINVAL_ACTIVE_SCAN;
2068  }
2069 
2070  dev->nr_channels = 0;
2071 
2072  if ( active )
2074  else {
2075  if ( band & NET80211_BAND_BIT_2GHZ )
2076  net80211_add_channels ( dev, 1, 14,
2078  if ( band & NET80211_BAND_BIT_5GHZ )
2079  net80211_add_channels ( dev, 36, 8,
2081  }
2082 
2084 
2085  /* Use channel 1 for now */
2086  dev->channel = 0;
2087  dev->op->config ( dev, NET80211_CFG_CHANNEL );
2088 
2089  /* Always do active probes at lowest (presumably first) speed */
2090  dev->rate = 0;
2091  dev->nr_rates = 1;
2092  dev->rates[0] = dev->hw->rates[dev->channels[0].band][0];
2093  dev->op->config ( dev, NET80211_CFG_RATE );
2094 
2095  return 0;
2096 }
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
int(* config)(struct net80211_device *dev, int changed)
Update hardware state to match 802.11 layer state.
Definition: net80211.h:381
#define DBGC(...)
Definition: compiler.h:505
#define EINVAL_ACTIVE_SCAN
Definition: net80211_err.h:39
static void net80211_filter_hw_channels(struct net80211_device *dev)
Filter 802.11 device channels for hardware capabilities.
Definition: net80211.c:961
#define NET80211_REG_TXPOWER
Maximum TX power to allow (dBm), if we don't get a regulatory hint.
Definition: net80211.h:287
#define NET80211_BAND_BIT_5GHZ
Bitmask for the 5GHz band.
Definition: net80211.h:54
u16 rates[NET80211_NR_BANDS][NET80211_MAX_RATES]
List of transmission rates supported by the card, indexed by band.
Definition: net80211.h:508
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u8 nr_channels
The number of channels in the channels array.
Definition: net80211.h:809
u8 nr_rates
The number of transmission rates in the rates array.
Definition: net80211.h:821
u8 band
The band with which this channel is associated.
Definition: net80211.h:388
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 net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
struct net80211_device_operations * op
802.11 device operations
Definition: net80211.h:795
#define NET80211_BAND_BIT_2GHZ
Bitmask for the 2GHz band.
Definition: net80211.h:52
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
#define NET80211_CFG_RATE
Requested transmission rate (dev->rate) has changed.
Definition: net80211.h:84
static void net80211_add_channels(struct net80211_device *dev, int start, int len, int txpower)
Add channels to 802.11 device.
Definition: net80211.c:917
#define NET80211_CFG_CHANNEL
Channel choice (dev->channel) or regulatory parameters have changed.
Definition: net80211.h:81
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824

References assert(), net80211_channel::band, net80211_device::channel, net80211_device::channels, net80211_device_operations::config, DBGC, EINVAL_ACTIVE_SCAN, net80211_device::hw, net80211_add_channels(), NET80211_BAND_BIT_2GHZ, NET80211_BAND_BIT_5GHZ, NET80211_CFG_CHANNEL, NET80211_CFG_RATE, net80211_filter_hw_channels(), NET80211_REG_TXPOWER, net80211_device::netdev, netdev_is_open(), net80211_device::nr_channels, net80211_device::nr_rates, net80211_device::op, net80211_device::rate, net80211_hw_info::rates, and net80211_device::rates.

Referenced by iwlist(), and net80211_step_associate().

◆ net80211_probe_start()

struct net80211_probe_ctx* net80211_probe_start ( struct net80211_device dev,
const char *  essid,
int  active 
)

Begin probe of 802.11 networks.

Parameters
dev802.11 device
essidSSID to probe for, or "" to accept any (may not be NULL)
activeWhether to use active scanning
Return values
ctxProbe context

Active scanning may only be used on channels 1-11 in the 2.4GHz band, due to iPXE's lack of a complete regulatory database. If active scanning is used, probe packets will be sent on each channel; this can allow association with hidden-SSID networks if the SSID is properly specified.

A NULL return indicates an out-of-memory condition.

The returned context must be periodically passed to net80211_probe_step() until that function returns zero.

Definition at line 1290 of file net80211.c.

1293 {
1294  struct net80211_probe_ctx *ctx = zalloc ( sizeof ( *ctx ) );
1295 
1296  if ( ! ctx )
1297  return NULL;
1298 
1299  assert ( netdev_is_open ( dev->netdev ) );
1300 
1301  ctx->dev = dev;
1302  ctx->old_keep_mgmt = net80211_keep_mgmt ( dev, 1 );
1303  ctx->essid = essid;
1304  if ( dev->essid != ctx->essid )
1305  strcpy ( dev->essid, ctx->essid );
1306 
1307  if ( active ) {
1308  struct ieee80211_probe_req *probe_req;
1309  union ieee80211_ie *ie;
1310 
1311  ctx->probe = alloc_iob ( 128 );
1313  probe_req = ctx->probe->data;
1314 
1315  ie = net80211_marshal_request_info ( dev,
1316  probe_req->info_element );
1317 
1318  iob_put ( ctx->probe, ( void * ) ie - ctx->probe->data );
1319  }
1320 
1321  ctx->ticks_start = currticks();
1322  ctx->ticks_beacon = 0;
1323  ctx->ticks_channel = currticks();
1324  ctx->hop_time = TICKS_PER_SEC / ( active ? 2 : 6 );
1325 
1326  /*
1327  * Channels on 2.4GHz overlap, and the most commonly used
1328  * are 1, 6, and 11. We'll get a result faster if we check
1329  * every 5 channels, but in order to hit all of them the
1330  * number of channels must be relatively prime to 5. If it's
1331  * not, tweak the hop.
1332  */
1333  ctx->hop_step = 5;
1334  while ( dev->nr_channels % ctx->hop_step == 0 && ctx->hop_step > 1 )
1335  ctx->hop_step--;
1336 
1337  ctx->beacons = malloc ( sizeof ( *ctx->beacons ) );
1338  INIT_LIST_HEAD ( ctx->beacons );
1339 
1340  dev->channel = 0;
1341  dev->op->config ( dev, NET80211_CFG_CHANNEL );
1342 
1343  return ctx;
1344 }
#define iob_put(iobuf, len)
Definition: iobuf.h:116
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
int(* config)(struct net80211_device *dev, int changed)
Update hardware state to match 802.11 layer state.
Definition: net80211.h:381
union ieee80211_ie info_element[0]
List of information elements.
Definition: ieee80211.h:1134
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
Context for a probe operation.
Definition: net80211.c:63
char essid[IEEE80211_MAX_SSID_LEN+1]
SSID of the access point we are or will be associated with.
Definition: net80211.h:962
const char * essid
If non-"", the ESSID to limit ourselves to.
Definition: net80211.c:74
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u8 nr_channels
The number of channels in the channels array.
Definition: net80211.h:809
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
static union ieee80211_ie * net80211_marshal_request_info(struct net80211_device *dev, union ieee80211_ie *ie)
Create information elements for outgoing probe or association packet.
Definition: net80211.c:1202
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:296
struct net80211_device * dev
802.11 device to probe on
Definition: net80211.c:65
Probe request frame data.
Definition: ieee80211.h:1131
int net80211_keep_mgmt(struct net80211_device *dev, int enable)
Set state of 802.11 device keeping management frames.
Definition: net80211.c:646
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
Any 802.11 information element.
Definition: ieee80211.h:972
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define iob_reserve(iobuf, len)
Definition: iobuf.h:63
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct net80211_device_operations * op
802.11 device operations
Definition: net80211.h:795
#define NET80211_CFG_CHANNEL
Channel choice (dev->channel) or regulatory parameters have changed.
Definition: net80211.h:81
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References alloc_iob(), assert(), net80211_device::channel, net80211_device_operations::config, ctx, currticks(), net80211_probe_ctx::dev, net80211_probe_ctx::essid, net80211_device::essid, IEEE80211_TYP_FRAME_HEADER_LEN, ieee80211_probe_req::info_element, INIT_LIST_HEAD, iob_put, iob_reserve, malloc(), NET80211_CFG_CHANNEL, net80211_keep_mgmt(), net80211_marshal_request_info(), net80211_device::netdev, netdev_is_open(), net80211_device::nr_channels, NULL, net80211_device::op, strcpy(), TICKS_PER_SEC, and zalloc().

Referenced by iwlist(), and net80211_step_associate().

◆ net80211_probe_step()

int net80211_probe_step ( struct net80211_probe_ctx ctx)

Continue probe of 802.11 networks.

Parameters
ctxProbe context returned by net80211_probe_start()
Return values
rcProbe status

The return code will be 0 if the probe is still going on (and this function should be called again), a positive number if the probe completed successfully, or a negative error code if the probe failed for that reason.

Whether the probe succeeded or failed, you must call net80211_probe_finish_all() or net80211_probe_finish_best() (depending on whether you want information on all networks or just the best-signal one) in order to release the probe context. A failed probe may still have acquired some valid data.

Definition at line 1363 of file net80211.c.

1364 {
1365  struct net80211_device *dev = ctx->dev;
1366  u32 start_timeout = NET80211_PROBE_TIMEOUT * TICKS_PER_SEC;
1367  u32 gather_timeout = TICKS_PER_SEC;
1368  u32 now = currticks();
1369  struct io_buffer *iob;
1370  int signal;
1371  int rc;
1372  char ssid[IEEE80211_MAX_SSID_LEN + 1];
1373 
1374  gather_timeout *= ( ctx->essid[0] ? NET80211_PROBE_GATHER :
1376 
1377  /* Time out if necessary */
1378  if ( now >= ctx->ticks_start + start_timeout )
1379  return list_empty ( ctx->beacons ) ? -ETIMEDOUT : +1;
1380 
1381  if ( ctx->ticks_beacon > 0 && now >= ctx->ticks_start + gather_timeout )
1382  return +1;
1383 
1384  /* Change channels if necessary */
1385  if ( now >= ctx->ticks_channel + ctx->hop_time ) {
1386  dev->channel = ( dev->channel + ctx->hop_step )
1387  % dev->nr_channels;
1388  dev->op->config ( dev, NET80211_CFG_CHANNEL );
1389  udelay ( dev->hw->channel_change_time );
1390 
1391  ctx->ticks_channel = now;
1392 
1393  if ( ctx->probe ) {
1394  struct io_buffer *siob = ctx->probe; /* to send */
1395 
1396  /* make a copy for future use */
1397  iob = alloc_iob ( siob->tail - siob->head );
1398  iob_reserve ( iob, iob_headroom ( siob ) );
1399  memcpy ( iob_put ( iob, iob_len ( siob ) ),
1400  siob->data, iob_len ( siob ) );
1401 
1402  ctx->probe = iob;
1404  eth_broadcast,
1405  iob_disown ( siob ) );
1406  if ( rc ) {
1407  DBGC ( dev, "802.11 %p send probe failed: "
1408  "%s\n", dev, strerror ( rc ) );
1409  return rc;
1410  }
1411  }
1412  }
1413 
1414  /* Check for new management packets */
1415  while ( ( iob = net80211_mgmt_dequeue ( dev, &signal ) ) != NULL ) {
1416  struct ieee80211_frame *hdr;
1417  struct ieee80211_beacon *beacon;
1418  union ieee80211_ie *ie;
1419  struct net80211_wlan *wlan;
1420  u16 type;
1421 
1422  hdr = iob->data;
1423  type = hdr->fc & IEEE80211_FC_SUBTYPE;
1424  beacon = ( struct ieee80211_beacon * ) hdr->data;
1425 
1428  DBGC2 ( dev, "802.11 %p probe: non-beacon\n", dev );
1429  goto drop;
1430  }
1431 
1432  if ( ( void * ) beacon->info_element >= iob->tail ) {
1433  DBGC ( dev, "802.11 %p probe: beacon with no IEs\n",
1434  dev );
1435  goto drop;
1436  }
1437 
1438  ie = beacon->info_element;
1439 
1440  if ( ! ieee80211_ie_bound ( ie, iob->tail ) )
1441  ie = NULL;
1442 
1443  while ( ie && ie->id != IEEE80211_IE_SSID )
1444  ie = ieee80211_next_ie ( ie, iob->tail );
1445 
1446  if ( ! ie ) {
1447  DBGC ( dev, "802.11 %p probe: beacon with no SSID\n",
1448  dev );
1449  goto drop;
1450  }
1451 
1452  memcpy ( ssid, ie->ssid, ie->len );
1453  ssid[ie->len] = 0;
1454 
1455  if ( ctx->essid[0] && strcmp ( ctx->essid, ssid ) != 0 ) {
1456  DBGC2 ( dev, "802.11 %p probe: beacon with wrong SSID "
1457  "(%s)\n", dev, ssid );
1458  goto drop;
1459  }
1460 
1461  /* See if we've got an entry for this network */
1462  list_for_each_entry ( wlan, ctx->beacons, list ) {
1463  if ( strcmp ( wlan->essid, ssid ) != 0 )
1464  continue;
1465 
1466  if ( signal < wlan->signal ) {
1467  DBGC2 ( dev, "802.11 %p probe: beacon for %s "
1468  "(%s) with weaker signal %d\n", dev,
1469  ssid, eth_ntoa ( hdr->addr3 ), signal );
1470  goto drop;
1471  }
1472 
1473  goto fill;
1474  }
1475 
1476  /* No entry yet - make one */
1477  wlan = zalloc ( sizeof ( *wlan ) );
1478  strcpy ( wlan->essid, ssid );
1479  list_add_tail ( &wlan->list, ctx->beacons );
1480 
1481  /* Whether we're using an old entry or a new one, fill
1482  it with new data. */
1483  fill:
1484  memcpy ( wlan->bssid, hdr->addr3, ETH_ALEN );
1485  wlan->signal = signal;
1486  wlan->channel = dev->channels[dev->channel].channel_nr;
1487 
1488  /* Copy this I/O buffer into a new wlan->beacon; the
1489  * iob we've got probably came from the device driver
1490  * and may have the full 2.4k allocation, which we
1491  * don't want to keep around wasting memory.
1492  */
1493  free_iob ( wlan->beacon );
1494  wlan->beacon = alloc_iob ( iob_len ( iob ) );
1495  memcpy ( iob_put ( wlan->beacon, iob_len ( iob ) ),
1496  iob->data, iob_len ( iob ) );
1497 
1498  if ( ( rc = sec80211_detect ( wlan->beacon, &wlan->handshaking,
1499  &wlan->crypto ) ) == -ENOTSUP ) {
1500  struct ieee80211_beacon *beacon =
1501  ( struct ieee80211_beacon * ) hdr->data;
1502 
1503  if ( beacon->capability & IEEE80211_CAPAB_PRIVACY ) {
1504  DBG ( "802.11 %p probe: secured network %s but "
1505  "encryption support not compiled in\n",
1506  dev, wlan->essid );
1509  } else {
1511  wlan->crypto = NET80211_CRYPT_NONE;
1512  }
1513  } else if ( rc != 0 ) {
1514  DBGC ( dev, "802.11 %p probe warning: network "
1515  "%s with unidentifiable security "
1516  "settings: %s\n", dev, wlan->essid,
1517  strerror ( rc ) );
1518  }
1519 
1520  ctx->ticks_beacon = now;
1521 
1522  DBGC2 ( dev, "802.11 %p probe: good beacon for %s (%s)\n",
1523  dev, wlan->essid, eth_ntoa ( wlan->bssid ) );
1524 
1525  drop:
1526  free_iob ( iob );
1527  }
1528 
1529  return 0;
1530 }
uint16_t u16
Definition: stdint.h:21
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
#define iob_put(iobuf, len)
Definition: iobuf.h:116
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
No security handshaking.
Definition: net80211.h:102
static union ieee80211_ie * ieee80211_next_ie(union ieee80211_ie *ie, void *end)
Advance to next 802.11 information element.
Definition: ieee80211.h:1028
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
int(* config)(struct net80211_device *dev, int changed)
Update hardware state to match 802.11 layer state.
Definition: net80211.h:381
Dummy value used when the cryptosystem can't be detected.
Definition: net80211.h:177
char ssid[0]
SSID data, not NUL-terminated.
Definition: ieee80211.h:16
char essid[IEEE80211_MAX_SSID_LEN+1]
The human-readable ESSID (network name)
Definition: net80211.h:1064
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define IEEE80211_CAPAB_PRIVACY
Set if the network is encrypted (by any method)
Definition: ieee80211.h:401
uint8_t type
Type.
Definition: ena.h:16
enum net80211_security_proto handshaking
Security handshaking method used on the network.
Definition: net80211.h:1084
uint8_t eth_broadcast[ETH_ALEN]
Ethernet broadcast MAC address.
Definition: ethernet.c:47
#define DBGC(...)
Definition: compiler.h:505
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
#define NET80211_PROBE_TIMEOUT
Seconds to allow a probe to take if no network has been found.
Definition: net80211.c:1269
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
Dummy value used when the handshaking type can't be detected.
Definition: net80211.h:124
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define NET80211_PROBE_GATHER_ALL
Seconds to wait after finding a network, to possibly find other networks.
Definition: net80211.c:1266
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
void * tail
End of data.
Definition: iobuf.h:46
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define IEEE80211_FC_SUBTYPE
802.11 Frame Control field, Frame Subtype bitmask
Definition: ieee80211.h:110
u8 id
Information element ID.
Definition: ieee80211.h:976
u8 nr_channels
The number of channels in the channels array.
Definition: net80211.h:809
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct io_buffer * net80211_mgmt_dequeue(struct net80211_device *dev, int *signal)
Get 802.11 management frame.
Definition: net80211.c:667
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define ieee80211_beacon
Definition: ieee80211.h:1069
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:296
__weak int sec80211_detect(struct io_buffer *iob __unused, enum net80211_security_proto *secprot __unused, enum net80211_crypto_alg *crypt __unused)
Detect secure 802.11 network when security support is not available.
Definition: net80211.c:112
#define IEEE80211_IE_SSID
Information element ID for SSID information element.
Definition: ieee80211.h:582
#define NET80211_PROBE_GATHER
Seconds to wait after finding a network, to possibly find better APs for it.
Definition: net80211.c:1259
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
No security, an "Open" network.
Definition: net80211.h:131
static int ieee80211_ie_bound(union ieee80211_ie *ie, void *end)
Check that 802.11 information element is bounded by buffer.
Definition: ieee80211.h:1012
struct net80211_hw_info * hw
Information about the hardware, provided to net80211_register()
Definition: net80211.h:801
#define ETH_ALEN
Definition: if_ether.h:8
Any 802.11 information element.
Definition: ieee80211.h:972
u8 len
Information element data length.
Definition: ieee80211.h:977
#define IEEE80211_STYPE_PROBE_RESP
Subtype value for probe-response management frames.
Definition: ieee80211.h:157
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
uint32_t hdr
Message header.
Definition: intelvf.h:12
int channel
The channel on which that access point communicates.
Definition: net80211.h:1078
#define iob_reserve(iobuf, len)
Definition: iobuf.h:63
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:161
int net80211_tx_mgmt(struct net80211_device *dev, u16 fc, u8 dest[6], struct io_buffer *iob)
Transmit 802.11 management frame.
Definition: net80211.c:706
#define DBGC2(...)
Definition: compiler.h:522
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
void * head
Start of the buffer.
Definition: iobuf.h:42
struct net80211_device_operations * op
802.11 device operations
Definition: net80211.h:795
int signal
Signal strength of beacon frame from that access point.
Definition: net80211.h:1070
void * data
Start of data.
Definition: iobuf.h:44
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
uint8_t fill
Length pair.
Definition: deflate.h:12
u8 bssid[ETH_ALEN]
MAC address of the strongest-signal access point for this ESSID.
Definition: net80211.h:1067
char ssid[0]
SSID text.
Definition: ieee80211.h:979
#define NET80211_CFG_CHANNEL
Channel choice (dev->channel) or regulatory parameters have changed.
Definition: net80211.h:81
#define IEEE80211_STYPE_BEACON
Subtype value for beacon management frames.
Definition: ieee80211.h:168
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
struct io_buffer * beacon
The complete beacon or probe-response frame received.
Definition: net80211.h:1081
u8 channel_nr
A channel number interpreted according to the band.
Definition: net80211.h:405
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned channel_change_time
Estimate of the time required to change channels, in microseconds.
Definition: net80211.h:518
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define IEEE80211_MAX_SSID_LEN
Maximum length of an ESSID.
Definition: ieee80211.h:77
#define IEEE80211_STYPE_PROBE_REQ
Subtype value for probe-request management frames.
Definition: ieee80211.h:150
uint32_t u32
Definition: stdint.h:23
if(natsemi->flags &NATSEMI_64BIT) return 1
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), net80211_wlan::beacon, net80211_wlan::bssid, net80211_device::channel, net80211_wlan::channel, net80211_hw_info::channel_change_time, net80211_channel::channel_nr, net80211_device::channels, net80211_device_operations::config, net80211_wlan::crypto, ctx, currticks(), io_buffer::data, DBG, DBGC, DBGC2, ENOTSUP, net80211_wlan::essid, ETH_ALEN, eth_broadcast, eth_ntoa(), ETIMEDOUT, fill, free_iob(), net80211_wlan::handshaking, hdr, io_buffer::head, net80211_device::hw, ieee80211_ie::id, ieee80211_beacon, IEEE80211_CAPAB_PRIVACY, IEEE80211_FC_SUBTYPE, ieee80211_ie_bound(), IEEE80211_IE_SSID, IEEE80211_MAX_SSID_LEN, ieee80211_next_ie(), IEEE80211_STYPE_BEACON, IEEE80211_STYPE_PROBE_REQ, IEEE80211_STYPE_PROBE_RESP, if(), iob_disown, iob_headroom(), iob_len(), iob_put, iob_reserve, ieee80211_ie::len, net80211_wlan::list, list_add_tail, list_empty, list_for_each_entry, memcpy(), NET80211_CFG_CHANNEL, NET80211_CRYPT_NONE, NET80211_CRYPT_UNKNOWN, net80211_mgmt_dequeue(), NET80211_PROBE_GATHER, NET80211_PROBE_GATHER_ALL, NET80211_PROBE_TIMEOUT, NET80211_SECPROT_NONE, NET80211_SECPROT_UNKNOWN, net80211_tx_mgmt(), net80211_device::nr_channels, NULL, net80211_device::op, rc, sec80211_detect(), net80211_wlan::signal, ssid, ieee80211_ie::ssid, strcmp(), strcpy(), strerror(), io_buffer::tail, TICKS_PER_SEC, type, udelay(), and zalloc().

Referenced by iwlist(), and net80211_step_associate().

◆ net80211_probe_finish_best()

struct net80211_wlan* net80211_probe_finish_best ( struct net80211_probe_ctx ctx)

Finish probe of 802.11 networks, returning best-signal network found.

Parameters
ctxProbe context
Return values
wlanBest-signal network found, or NULL if none were found

If net80211_probe_start() was called with a particular SSID parameter as filter, only a network with that SSID (matching case-sensitively) can be returned from this function.

Definition at line 1544 of file net80211.c.

1545 {
1546  struct net80211_wlan *best = NULL, *wlan;
1547 
1548  if ( ! ctx )
1549  return NULL;
1550 
1551  list_for_each_entry ( wlan, ctx->beacons, list ) {
1552  if ( ! best || best->signal < wlan->signal )
1553  best = wlan;
1554  }
1555 
1556  if ( best )
1557  list_del ( &best->list );
1558  else
1559  DBGC ( ctx->dev, "802.11 %p probe: found nothing for '%s'\n",
1560  ctx->dev, ctx->essid );
1561 
1562  net80211_free_wlanlist ( ctx->beacons );
1563 
1564  net80211_keep_mgmt ( ctx->dev, ctx->old_keep_mgmt );
1565 
1566  if ( ctx->probe )
1567  free_iob ( ctx->probe );
1568 
1569  free ( ctx );
1570 
1571  return best;
1572 }
Structure representing a probed network.
Definition: net80211.h:1056
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define DBGC(...)
Definition: compiler.h:505
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
int net80211_keep_mgmt(struct net80211_device *dev, int enable)
Set state of 802.11 device keeping management frames.
Definition: net80211.c:646
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void net80211_free_wlanlist(struct list_head *list)
Free list of WLAN structures.
Definition: net80211.c:1619
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
int signal
Signal strength of beacon frame from that access point.
Definition: net80211.h:1070
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References ctx, DBGC, free, free_iob(), net80211_wlan::list, list_del, list_for_each_entry, net80211_free_wlanlist(), net80211_keep_mgmt(), NULL, and net80211_wlan::signal.

Referenced by net80211_autoassociate(), and net80211_step_associate().

◆ net80211_probe_finish_all()

struct list_head* net80211_probe_finish_all ( struct net80211_probe_ctx ctx)

Finish probe of 802.11 networks, returning all networks found.

Parameters
ctxProbe context
Return values
listList of net80211_wlan detailing networks found

If net80211_probe_start() was called with a particular SSID parameter as filter, this will always return either an empty or a one-element list.

Definition at line 1585 of file net80211.c.

1586 {
1587  struct list_head *beacons = ctx->beacons;
1588 
1589  net80211_keep_mgmt ( ctx->dev, ctx->old_keep_mgmt );
1590 
1591  if ( ctx->probe )
1592  free_iob ( ctx->probe );
1593 
1594  free ( ctx );
1595 
1596  return beacons;
1597 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
A doubly-linked list entry (or list head)
Definition: list.h:18
int net80211_keep_mgmt(struct net80211_device *dev, int enable)
Set state of 802.11 device keeping management frames.
Definition: net80211.c:646
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54

References ctx, free, free_iob(), and net80211_keep_mgmt().

Referenced by iwlist().

◆ net80211_free_wlan()

void net80211_free_wlan ( struct net80211_wlan wlan)

Free WLAN structure.

Parameters
wlanWLAN structure to free

Definition at line 1605 of file net80211.c.

1606 {
1607  if ( wlan ) {
1608  free_iob ( wlan->beacon );
1609  free ( wlan );
1610  }
1611 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct io_buffer * beacon
The complete beacon or probe-response frame received.
Definition: net80211.h:1081

References net80211_wlan::beacon, free, and free_iob().

Referenced by net80211_autoassociate(), net80211_free_wlanlist(), and net80211_step_associate().

◆ net80211_free_wlanlist()

void net80211_free_wlanlist ( struct list_head list)

Free list of WLAN structures.

Parameters
listList of WLAN structures to free

Definition at line 1619 of file net80211.c.

1620 {
1621  struct net80211_wlan *wlan, *tmp;
1622 
1623  if ( ! list )
1624  return;
1625 
1626  list_for_each_entry_safe ( wlan, tmp, list, list ) {
1627  list_del ( &wlan->list );
1628  net80211_free_wlan ( wlan );
1629  }
1630 
1631  free ( list );
1632 }
Structure representing a probed network.
Definition: net80211.h:1056
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:447
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint8_t * tmp
Definition: entropy.h:156
void net80211_free_wlan(struct net80211_wlan *wlan)
Free WLAN structure.
Definition: net80211.c:1605
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

References free, net80211_wlan::list, list_del, list_for_each_entry_safe, net80211_free_wlan(), and tmp.

Referenced by iwlist(), and net80211_probe_finish_best().