iPXE
Data Structures | Macros | Functions | Variables
net80211.c File Reference

802.11 device management More...

#include <string.h>
#include <byteswap.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/settings.h>
#include <ipxe/if_arp.h>
#include <ipxe/ethernet.h>
#include <ipxe/ieee80211.h>
#include <ipxe/netdevice.h>
#include <ipxe/net80211.h>
#include <ipxe/sec80211.h>
#include <ipxe/timer.h>
#include <ipxe/nap.h>
#include <ipxe/errortab.h>
#include <ipxe/net80211_err.h>

Go to the source code of this file.

Data Structures

struct  net80211_rx_info
 Information associated with a received management packet. More...
 
struct  net80211_probe_ctx
 Context for a probe operation. More...
 
struct  net80211_assoc_ctx
 Context for the association task. More...
 

Macros

#define NET80211_PROBE_GATHER   1
 Seconds to wait after finding a network, to possibly find better APs for it. More...
 
#define NET80211_PROBE_GATHER_ALL   2
 Seconds to wait after finding a network, to possibly find other networks. More...
 
#define NET80211_PROBE_TIMEOUT   6
 Seconds to allow a probe to take if no network has been found. More...
 
#define ASSOC_TIMEOUT   TICKS_PER_SEC
 Number of ticks to wait for replies to association management frames. More...
 
#define ASSOC_RETRIES   2
 Number of times to try sending a particular association management frame. More...
 
#define LQ_SMOOTH   7
 Smoothing factor (1-7) for link quality calculation. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
__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. More...
 
static int net80211_netdev_open (struct net_device *netdev)
 Open 802.11 device and start association. More...
 
static void net80211_netdev_close (struct net_device *netdev)
 Close 802.11 device. More...
 
static int net80211_netdev_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet on 802.11 device. More...
 
static void net80211_netdev_poll (struct net_device *netdev)
 Poll 802.11 device for received packets and completed transmissions. More...
 
static void net80211_netdev_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts for 802.11 device. More...
 
static int net80211_ll_push (struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
 Add 802.11 link-layer header. More...
 
static int net80211_ll_pull (struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
 
static void net80211_add_channels (struct net80211_device *dev, int start, int len, int txpower)
 Add channels to 802.11 device. More...
 
static void net80211_filter_hw_channels (struct net80211_device *dev)
 Filter 802.11 device channels for hardware capabilities. More...
 
static void net80211_set_rtscts_rate (struct net80211_device *dev)
 Pick TX rate for RTS/CTS packets based on data rate. More...
 
static int net80211_process_capab (struct net80211_device *dev, u16 capab)
 Update 802.11 device state to reflect received capabilities field. More...
 
static int net80211_process_ie (struct net80211_device *dev, union ieee80211_ie *ie, void *ie_end)
 Update 802.11 device state to reflect received information elements. More...
 
static union ieee80211_ienet80211_marshal_request_info (struct net80211_device *dev, union ieee80211_ie *ie)
 Create information elements for outgoing probe or association packet. More...
 
static void net80211_step_associate (struct net80211_device *dev)
 Step 802.11 association process. More...
 
static void net80211_handle_auth (struct net80211_device *dev, struct io_buffer *iob)
 Handle receipt of 802.11 authentication frame. More...
 
static void net80211_handle_assoc_reply (struct net80211_device *dev, struct io_buffer *iob)
 Handle receipt of 802.11 association reply frame. More...
 
static int net80211_send_disassoc (struct net80211_device *dev, int reason, int deauth)
 Send 802.11 disassociation frame. More...
 
static void net80211_handle_mgmt (struct net80211_device *dev, struct io_buffer *iob, int signal)
 Handle receipt of 802.11 management frame. More...
 
static void net80211_free_frags (struct net80211_device *dev, int fcid)
 Free buffers used by 802.11 fragment cache entry. More...
 
static struct io_buffernet80211_accum_frags (struct net80211_device *dev, int fcid, int nfrags, int size)
 Accumulate 802.11 fragments into one I/O buffer. More...
 
static void net80211_rx_frag (struct net80211_device *dev, struct io_buffer *iob, int signal)
 Handle receipt of 802.11 fragment. More...
 
static int net80211_check_settings_update (void)
 Check for 802.11 SSID or key updates. More...
 
const struct setting net80211_ssid_setting __setting (SETTING_NETDEV_EXTRA, ssid)
 The network name to associate with. More...
 
const struct setting net80211_active_setting __setting (SETTING_NETDEV_EXTRA, active-scan)
 Whether to use active scanning. More...
 
const struct setting net80211_key_setting __setting (SETTING_NETDEV_EXTRA, key)
 The cryptographic key to use. More...
 
static int net80211_rate_is_erp (u16 rate)
 Determine whether a transmission rate uses ERP/OFDM. More...
 
u16 net80211_duration (struct net80211_device *dev, int bytes, u16 rate)
 Calculate one frame's contribution to 802.11 duration field. More...
 
static int net80211_ll_pull (struct net_device *netdev __unused, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
 Remove 802.11 link-layer header. More...
 
struct net80211_devicenet80211_get (struct net_device *netdev)
 Get 802.11 device from wrapping network device. More...
 
int net80211_keep_mgmt (struct net80211_device *dev, int enable)
 Set state of 802.11 device keeping management frames. More...
 
struct io_buffernet80211_mgmt_dequeue (struct net80211_device *dev, int *signal)
 Get 802.11 management frame. More...
 
int net80211_tx_mgmt (struct net80211_device *dev, u16 fc, u8 dest[6], struct io_buffer *iob)
 Transmit 802.11 management frame. More...
 
struct net80211_devicenet80211_alloc (size_t priv_size)
 Allocate 802.11 device. More...
 
int net80211_register (struct net80211_device *dev, struct net80211_device_operations *ops, struct net80211_hw_info *hw)
 Register 802.11 device with network stack. More...
 
void net80211_unregister (struct net80211_device *dev)
 Unregister 802.11 device from network stack. More...
 
void net80211_free (struct net80211_device *dev)
 Free 802.11 device. More...
 
static void net80211_set_state (struct net80211_device *dev, short clear, short set, u16 status)
 Set state of 802.11 device. 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...
 
void net80211_autoassociate (struct net80211_device *dev)
 Start 802.11 association process. More...
 
void net80211_set_rate_idx (struct net80211_device *dev, int rate)
 Set data transmission rate for 802.11 device. More...
 
int net80211_change_channel (struct net80211_device *dev, int channel)
 Configure 802.11 device to transmit on a certain channel. More...
 
int net80211_prepare_probe (struct net80211_device *dev, int band, int active)
 Prepare 802.11 device channel and rate set for scanning. More...
 
int net80211_prepare_assoc (struct net80211_device *dev, struct net80211_wlan *wlan)
 Prepare 802.11 device channel and rate set for communication. More...
 
int net80211_send_auth (struct net80211_device *dev, struct net80211_wlan *wlan, int method)
 Send 802.11 initial authentication frame. More...
 
int net80211_send_assoc (struct net80211_device *dev, struct net80211_wlan *wlan)
 Send 802.11 association frame. More...
 
void net80211_deauthenticate (struct net80211_device *dev, int rc)
 Deauthenticate from current network and try again. More...
 
static void net80211_update_link_quality (struct net80211_device *dev, struct io_buffer *iob)
 Update link quality information based on received beacon. More...
 
void net80211_rx (struct net80211_device *dev, struct io_buffer *iob, int signal, u16 rate)
 Handle receipt of 802.11 frame. More...
 
void net80211_rx_err (struct net80211_device *dev, struct io_buffer *iob, int rc)
 Indicate an error in receiving a packet. More...
 
void net80211_tx_complete (struct net80211_device *dev, struct io_buffer *iob, int retries, int rc)
 Indicate the completed transmission of a packet. More...
 
 REQUIRING_SYMBOL (net80211_ll_protocol)
 
 REQUIRE_OBJECT (config_net80211)
 

Variables

static struct list_head net80211_devices = LIST_HEAD_INIT ( net80211_devices )
 List of 802.11 devices. More...
 
static struct net80211_device_operations net80211_null_ops
 Set of device operations that does nothing. More...
 
struct settings_applicator net80211_applicator __settings_applicator
 802.11 settings applicator More...
 
static struct net_device_operations net80211_netdev_ops
 Network device operations for a wrapped 802.11 device. More...
 
static struct ll_protocol net80211_ll_protocol __ll_protocol
 802.11 link-layer protocol More...
 
static struct process_descriptor net80211_process_desc
 802.11 association process descriptor More...
 
struct errortab common_wireless_errors [] __errortab
 Common 802.11 errors. More...
 

Detailed Description

802.11 device management

Definition in file net80211.c.

Macro Definition Documentation

◆ NET80211_PROBE_GATHER

#define NET80211_PROBE_GATHER   1

Seconds to wait after finding a network, to possibly find better APs for it.

This is used when a specific SSID to scan for is specified.

Definition at line 1259 of file net80211.c.

◆ NET80211_PROBE_GATHER_ALL

#define NET80211_PROBE_GATHER_ALL   2

Seconds to wait after finding a network, to possibly find other networks.

This is used when an empty SSID is specified, to scan for all networks.

Definition at line 1266 of file net80211.c.

◆ NET80211_PROBE_TIMEOUT

#define NET80211_PROBE_TIMEOUT   6

Seconds to allow a probe to take if no network has been found.

Definition at line 1269 of file net80211.c.

◆ ASSOC_TIMEOUT

#define ASSOC_TIMEOUT   TICKS_PER_SEC

Number of ticks to wait for replies to association management frames.

Definition at line 1636 of file net80211.c.

◆ ASSOC_RETRIES

#define ASSOC_RETRIES   2

Number of times to try sending a particular association management frame.

Definition at line 1639 of file net80211.c.

◆ LQ_SMOOTH

#define LQ_SMOOTH   7

Smoothing factor (1-7) for link quality calculation.

Definition at line 2401 of file net80211.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ sec80211_detect()

__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.

Returns
-ENOTSUP, always.

Definition at line 112 of file net80211.c.

114  {
115  return -ENOTSUP;
116 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

Referenced by net80211_probe_step().

◆ net80211_rate_is_erp()

static int net80211_rate_is_erp ( u16  rate)
inlinestatic

Determine whether a transmission rate uses ERP/OFDM.

Parameters
rateRate in 100 kbps units
Return values
is_erpTRUE if the rate is an ERP/OFDM rate

802.11b supports rates of 1.0, 2.0, 5.5, and 11.0 Mbps; any other rate than these on the 2.4GHz spectrum is an ERP (802.11g) rate.

Definition at line 399 of file net80211.c.

400 {
401  if ( rate == 10 || rate == 20 || rate == 55 || rate == 110 )
402  return 0;
403  return 1;
404 }

Referenced by net80211_duration().

◆ net80211_ll_pull()

static int net80211_ll_pull ( struct net_device *netdev  __unused,
struct io_buffer iobuf,
const void **  ll_dest,
const void **  ll_source,
uint16_t net_proto,
unsigned int *  flags 
)
static

Remove 802.11 link-layer header.

Parameters
netdevWrapping network device
iobufI/O buffer
Return values
ll_destLink-layer destination address
ll_sourceLink-layer source
net_protoNetwork-layer protocol, in network byte order
flagsPacket flags
rcReturn status code

This expects and removes both the 802.11 frame header and the 802.2 LLC/SNAP header that are used on data packets.

Definition at line 537 of file net80211.c.

541 {
542  struct ieee80211_frame *hdr = iobuf->data;
543  struct ieee80211_llc_snap_header *lhdr =
544  ( void * ) hdr + IEEE80211_TYP_FRAME_HEADER_LEN;
545 
546  /* Bunch of sanity checks */
547  if ( iob_len ( iobuf ) < IEEE80211_TYP_FRAME_HEADER_LEN +
549  DBGC ( netdev->priv, "802.11 %p packet too short (%zd bytes)\n",
550  netdev->priv, iob_len ( iobuf ) );
551  return -EINVAL_PKT_TOO_SHORT;
552  }
553 
554  if ( ( hdr->fc & IEEE80211_FC_VERSION ) != IEEE80211_THIS_VERSION ) {
555  DBGC ( netdev->priv, "802.11 %p packet invalid version %04x\n",
557  return -EINVAL_PKT_VERSION;
558  }
559 
560  if ( ( hdr->fc & IEEE80211_FC_TYPE ) != IEEE80211_TYPE_DATA ||
562  DBGC ( netdev->priv, "802.11 %p packet not data/data (fc=%04x)\n",
563  netdev->priv, hdr->fc );
564  return -EINVAL_PKT_NOT_DATA;
565  }
566 
567  if ( ( hdr->fc & ( IEEE80211_FC_TODS | IEEE80211_FC_FROMDS ) ) !=
569  DBGC ( netdev->priv, "802.11 %p packet not from DS (fc=%04x)\n",
570  netdev->priv, hdr->fc );
571  return -EINVAL_PKT_NOT_FROMDS;
572  }
573 
574  if ( lhdr->dsap != IEEE80211_LLC_DSAP || lhdr->ssap != IEEE80211_LLC_SSAP ||
575  lhdr->ctrl != IEEE80211_LLC_CTRL || lhdr->oui[0] || lhdr->oui[1] ||
576  lhdr->oui[2] ) {
577  DBGC ( netdev->priv, "802.11 %p LLC header is not plain EtherType "
578  "encapsulator: %02x->%02x [%02x] %02x:%02x:%02x %04x\n",
579  netdev->priv, lhdr->dsap, lhdr->ssap, lhdr->ctrl,
580  lhdr->oui[0], lhdr->oui[1], lhdr->oui[2], lhdr->ethertype );
581  return -EINVAL_PKT_LLC_HEADER;
582  }
583 
584  iob_pull ( iobuf, sizeof ( *hdr ) + sizeof ( *lhdr ) );
585 
586  *ll_dest = hdr->addr1;
587  *ll_source = hdr->addr3;
588  *net_proto = lhdr->ethertype;
589  *flags = ( ( is_multicast_ether_addr ( hdr->addr1 ) ?
590  LL_MULTICAST : 0 ) |
591  ( is_broadcast_ether_addr ( hdr->addr1 ) ?
592  LL_BROADCAST : 0 ) );
593  return 0;
594 }
u16 ethertype
Ethernet Type field.
Definition: ieee80211.h:333
#define LL_MULTICAST
Packet is a multicast (including broadcast) packet.
Definition: netdevice.h:105
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
The 802.2 LLC/SNAP header sent before actual data in a data frame.
Definition: ieee80211.h:324
#define IEEE80211_LLC_SSAP
Value for SSAP field in 802.2 LLC header for 802.11 frames: SNAP.
Definition: ieee80211.h:340
#define DBGC(...)
Definition: compiler.h:505
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
#define IEEE80211_FC_FROMDS
802.11 Frame Control field: From Data System flag
Definition: ieee80211.h:237
#define EINVAL_PKT_TOO_SHORT
Definition: net80211_err.h:21
#define IEEE80211_FC_VERSION
802.11 Frame Control field, Version bitmask
Definition: ieee80211.h:90
#define IEEE80211_THIS_VERSION
Expected value of Version bits in Frame Control.
Definition: ieee80211.h:93
#define IEEE80211_FC_SUBTYPE
802.11 Frame Control field, Frame Subtype bitmask
Definition: ieee80211.h:110
#define EINVAL_PKT_LLC_HEADER
Definition: net80211_err.h:33
u8 oui[3]
Organization code, usually 0.
Definition: ieee80211.h:332
#define IEEE80211_STYPE_DATA
Subtype value for ordinary data frames, with no QoS or CF add-ons.
Definition: ieee80211.h:219
void * priv
Driver private data.
Definition: netdevice.h:425
u8 dsap
Destination SAP ID.
Definition: ieee80211.h:327
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
#define EINVAL_PKT_NOT_DATA
Definition: net80211_err.h:27
static struct net_device * netdev
Definition: gdbudp.c:52
static int is_multicast_ether_addr(const void *addr)
Check if Ethernet address is a multicast address.
Definition: ethernet.h:37
#define IEEE80211_FC_TYPE
802.11 Frame Control field, Frame Type bitmask
Definition: ieee80211.h:97
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define IEEE80211_LLC_DSAP
Value for DSAP field in 802.2 LLC header for 802.11 frames: SNAP.
Definition: ieee80211.h:337
#define EINVAL_PKT_VERSION
Definition: net80211_err.h:24
#define IEEE80211_FC_TODS
802.11 Frame Control field: To Data System flag
Definition: ieee80211.h:229
#define LL_BROADCAST
Packet is a broadcast packet.
Definition: netdevice.h:108
uint32_t hdr
Message header.
Definition: intelvf.h:12
#define EINVAL_PKT_NOT_FROMDS
Definition: net80211_err.h:30
u8 ctrl
Control information.
Definition: ieee80211.h:329
u8 ssap
Source SAP ID.
Definition: ieee80211.h:328
void * data
Start of data.
Definition: iobuf.h:44
static int is_broadcast_ether_addr(const void *addr)
Check if Ethernet address is the broadcast address.
Definition: ethernet.h:61
#define IEEE80211_LLC_HEADER_LEN
Length of LLC/SNAP headers on data frames.
Definition: ieee80211.h:31
#define IEEE80211_LLC_CTRL
Value for control field in 802.2 LLC header for 802.11 frames.
Definition: ieee80211.h:346
#define IEEE80211_TYPE_DATA
Type value for data frames.
Definition: ieee80211.h:106
uint8_t flags
Flags.
Definition: ena.h:18

References ieee80211_llc_snap_header::ctrl, io_buffer::data, DBGC, ieee80211_llc_snap_header::dsap, EINVAL_PKT_LLC_HEADER, EINVAL_PKT_NOT_DATA, EINVAL_PKT_NOT_FROMDS, EINVAL_PKT_TOO_SHORT, EINVAL_PKT_VERSION, ieee80211_llc_snap_header::ethertype, flags, hdr, IEEE80211_FC_FROMDS, IEEE80211_FC_SUBTYPE, IEEE80211_FC_TODS, IEEE80211_FC_TYPE, IEEE80211_FC_VERSION, IEEE80211_LLC_CTRL, IEEE80211_LLC_DSAP, IEEE80211_LLC_HEADER_LEN, IEEE80211_LLC_SSAP, IEEE80211_STYPE_DATA, IEEE80211_THIS_VERSION, IEEE80211_TYP_FRAME_HEADER_LEN, IEEE80211_TYPE_DATA, iob_len(), iob_pull, is_broadcast_ether_addr(), is_multicast_ether_addr(), LL_BROADCAST, LL_MULTICAST, netdev, ieee80211_llc_snap_header::oui, net_device::priv, and ieee80211_llc_snap_header::ssap.

◆ net80211_tx_mgmt()

int net80211_tx_mgmt ( struct net80211_device dev,
u16  fc,
u8  dest[6],
struct io_buffer iob 
)

Transmit 802.11 management frame.

Parameters
dev802.11 device
fcFrame Control flags for management frame
destDestination access point
iobI/O buffer
Return values
rcReturn status code

The fc argument must contain at least an IEEE 802.11 management subtype number (e.g. IEEE80211_STYPE_PROBE_REQ). If it contains IEEE80211_FC_PROTECTED, the frame will be encrypted prior to transmission.

It is required that iob have at least 24 bytes of headroom reserved before its data start.

Definition at line 706 of file net80211.c.

708 {
709  struct ieee80211_frame *hdr = iob_push ( iob,
711 
713  ( fc & ~IEEE80211_FC_PROTECTED );
714  hdr->duration = net80211_duration ( dev, 10, dev->rates[dev->rate] );
715  hdr->seq = IEEE80211_MAKESEQ ( ++dev->last_tx_seqnr, 0 );
716 
717  memcpy ( hdr->addr1, dest, ETH_ALEN ); /* DA = RA */
718  memcpy ( hdr->addr2, dev->netdev->ll_addr, ETH_ALEN ); /* SA = TA */
719  memcpy ( hdr->addr3, dest, ETH_ALEN ); /* BSSID */
720 
721  if ( fc & IEEE80211_FC_PROTECTED ) {
722  if ( ! dev->crypto )
723  return -EINVAL_CRYPTO_REQUEST;
724 
725  struct io_buffer *eiob = dev->crypto->encrypt ( dev->crypto,
726  iob );
727  free_iob ( iob );
728  iob = eiob;
729  }
730 
731  return netdev_tx ( dev->netdev, iob );
732 }
#define iob_push(iobuf, len)
Definition: iobuf.h:80
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
u16 net80211_duration(struct net80211_device *dev, int bytes, u16 rate)
Calculate one frame's contribution to 802.11 duration field.
Definition: net80211.c:441
#define IEEE80211_MAKESEQ(seqnr, frag)
Make 802.11 Sequence Control field from sequence and fragment numbers.
Definition: ieee80211.h:286
#define IEEE80211_THIS_VERSION
Expected value of Version bits in Frame Control.
Definition: ieee80211.h:93
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct net80211_crypto * crypto
802.11 cryptosystem for our current network
Definition: net80211.h:940
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
static void * dest
Definition: strings.h:176
#define IEEE80211_FC_PROTECTED
802.11 Frame Control field: Protected flag
Definition: ieee80211.h:264
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition: netdevice.c:290
#define ETH_ALEN
Definition: if_ether.h:8
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition: net80211.h:818
uint32_t hdr
Message header.
Definition: intelvf.h:12
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define EINVAL_CRYPTO_REQUEST
Definition: net80211_err.h:36
struct io_buffer *(* encrypt)(struct net80211_crypto *crypto, struct io_buffer *iob)
Encrypt a frame using the cryptosystem.
Definition: net80211.h:733
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824
#define IEEE80211_TYPE_MGMT
Type value for management (layer-2) frames.
Definition: ieee80211.h:100
A persistent I/O buffer.
Definition: iobuf.h:32
u16 last_tx_seqnr
The sequence number of the last packet we sent.
Definition: net80211.h:997

References net80211_device::crypto, dest, EINVAL_CRYPTO_REQUEST, net80211_crypto::encrypt, ETH_ALEN, fc, free_iob(), hdr, IEEE80211_FC_PROTECTED, IEEE80211_MAKESEQ, IEEE80211_THIS_VERSION, IEEE80211_TYP_FRAME_HEADER_LEN, IEEE80211_TYPE_MGMT, iob_push, net80211_device::last_tx_seqnr, net_device::ll_addr, memcpy(), net80211_duration(), net80211_device::netdev, netdev_tx(), net80211_device::rate, and net80211_device::rates.

Referenced by net80211_probe_step(), net80211_send_assoc(), net80211_send_auth(), and net80211_send_disassoc().

◆ net80211_set_state()

static void net80211_set_state ( struct net80211_device dev,
short  clear,
short  set,
u16  status 
)
inlinestatic

Set state of 802.11 device.

Parameters
dev802.11 device
clearBitmask of flags to clear
setBitmask of flags to set
statusStatus or reason code for most recent operation

If status represents a reason code, it should be OR'ed with NET80211_IS_REASON.

Clearing authentication also clears association; clearing association also clears security handshaking state. Clearing association removes the link-up flag from the wrapping net_device, but setting it does not automatically set the flag; that is left to the judgment of higher-level code.

Definition at line 866 of file net80211.c.

869 {
870  /* The conditions in this function are deliberately formulated
871  to be decidable at compile-time in most cases. Since clear
872  and set are generally passed as constants, the body of this
873  function can be reduced down to a few statements by the
874  compiler. */
875 
876  const int statmsk = NET80211_STATUS_MASK | NET80211_IS_REASON;
877 
878  if ( clear & NET80211_PROBED )
879  clear |= NET80211_AUTHENTICATED;
880 
881  if ( clear & NET80211_AUTHENTICATED )
882  clear |= NET80211_ASSOCIATED;
883 
884  if ( clear & NET80211_ASSOCIATED )
885  clear |= NET80211_CRYPTO_SYNCED;
886 
887  dev->state = ( dev->state & ~clear ) | set;
888  dev->state = ( dev->state & ~statmsk ) | ( status & statmsk );
889 
890  if ( clear & NET80211_ASSOCIATED )
891  netdev_link_down ( dev->netdev );
892 
893  if ( ( clear | set ) & NET80211_ASSOCIATED )
894  dev->op->config ( dev, NET80211_CFG_ASSOC );
895 
896  if ( status != 0 ) {
897  if ( status & NET80211_IS_REASON )
898  dev->assoc_rc = -E80211_REASON ( status );
899  else
900  dev->assoc_rc = -E80211_STATUS ( status );
901  netdev_link_err ( dev->netdev, dev->assoc_rc );
902  }
903 }
int(* config)(struct net80211_device *dev, int changed)
Update hardware state to match 802.11 layer state.
Definition: net80211.h:381
#define NET80211_STATUS_MASK
An error code indicating the failure mode, or 0 if successful.
Definition: net80211.h:185
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
uint8_t status
Status.
Definition: ena.h:16
#define NET80211_IS_REASON
Whether the error code provided is a "reason" code, not a "status" code.
Definition: net80211.h:188
int assoc_rc
Return status code associated with state.
Definition: net80211.h:924
#define E80211_STATUS(stat)
Make return status code from 802.11 status code.
Definition: net80211_err.h:555
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:163
static fd_set * set
Definition: posix_io.h:48
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define NET80211_AUTHENTICATED
Whether we have successfully authenticated with the network.
Definition: net80211.h:198
struct net80211_device_operations * op
802.11 device operations
Definition: net80211.h:795
#define E80211_REASON(reas)
Make return status code from 802.11 reason code.
Definition: net80211_err.h:598
#define NET80211_PROBED
Whether we have found the network we will be associating with.
Definition: net80211.h:191
u16 state
State of our association to the network.
Definition: net80211.h:921
#define NET80211_CFG_ASSOC
Association has been established with a new BSS (dev->bssid)
Definition: net80211.h:87
#define NET80211_CRYPTO_SYNCED
Whether we have completed security handshaking with the network.
Definition: net80211.h:209

References net_device::dev, E80211_REASON, E80211_STATUS, NET80211_ASSOCIATED, NET80211_AUTHENTICATED, NET80211_CFG_ASSOC, NET80211_CRYPTO_SYNCED, NET80211_IS_REASON, NET80211_PROBED, NET80211_STATUS_MASK, netdev_link_down(), netdev_link_err(), set, and status.

Referenced by net80211_autoassociate(), net80211_handle_assoc_reply(), net80211_handle_auth(), net80211_handle_mgmt(), net80211_prepare_assoc(), net80211_send_assoc(), net80211_send_auth(), and net80211_send_disassoc().

◆ net80211_update_link_quality()

static void net80211_update_link_quality ( struct net80211_device dev,
struct io_buffer iob 
)
static

Update link quality information based on received beacon.

Parameters
dev802.11 device
iobI/O buffer containing beacon
Return values
rcReturn status code

Definition at line 2410 of file net80211.c.

2412 {
2413  struct ieee80211_frame *hdr = iob->data;
2414  struct ieee80211_beacon *beacon;
2415  u32 dt, rxi;
2416 
2417  if ( ! ( dev->state & NET80211_ASSOCIATED ) )
2418  return;
2419 
2420  beacon = ( struct ieee80211_beacon * ) hdr->data;
2421  dt = ( u32 ) ( beacon->timestamp - dev->last_beacon_timestamp );
2422  rxi = dev->rx_beacon_interval;
2423 
2424  rxi = ( LQ_SMOOTH * rxi ) + ( ( 8 - LQ_SMOOTH ) * dt );
2425  dev->rx_beacon_interval = rxi >> 3;
2426 
2427  dev->last_beacon_timestamp = beacon->timestamp;
2428 }
#define LQ_SMOOTH
Smoothing factor (1-7) for link quality calculation.
Definition: net80211.c:2401
u64 last_beacon_timestamp
TSFT value for last beacon received, microseconds.
Definition: net80211.h:968
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
#define ieee80211_beacon
Definition: ieee80211.h:1069
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
uint32_t hdr
Message header.
Definition: intelvf.h:12
void * data
Start of data.
Definition: iobuf.h:44
u16 state
State of our association to the network.
Definition: net80211.h:921
u32 rx_beacon_interval
Smoothed average time between beacons, microseconds.
Definition: net80211.h:974
uint32_t u32
Definition: stdint.h:23

References io_buffer::data, hdr, ieee80211_beacon, net80211_device::last_beacon_timestamp, LQ_SMOOTH, NET80211_ASSOCIATED, net80211_device::rx_beacon_interval, and net80211_device::state.

Referenced by net80211_handle_mgmt().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( net80211_ll_protocol  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_net80211  )

Variable Documentation

◆ net80211_devices

struct list_head net80211_devices = LIST_HEAD_INIT ( net80211_devices )
static

List of 802.11 devices.

Definition at line 47 of file net80211.c.

Referenced by net80211_check_settings_update(), net80211_get(), and net80211_register().

◆ net80211_null_ops

struct net80211_device_operations net80211_null_ops
static

Set of device operations that does nothing.

Definition at line 50 of file net80211.c.

Referenced by net80211_alloc(), net80211_netdev_open(), and net80211_unregister().

◆ net80211_netdev_ops

struct net_device_operations net80211_netdev_ops
static
Initial value:
= {
}
static int net80211_netdev_open(struct net_device *netdev)
Open 802.11 device and start association.
Definition: net80211.c:256
static void net80211_netdev_close(struct net_device *netdev)
Close 802.11 device.
Definition: net80211.c:283
static int net80211_netdev_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet on 802.11 device.
Definition: net80211.c:320
static void net80211_netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts for 802.11 device.
Definition: net80211.c:370
static void net80211_netdev_poll(struct net_device *netdev)
Poll 802.11 device for received packets and completed transmissions.
Definition: net80211.c:356

Network device operations for a wrapped 802.11 device.

Definition at line 379 of file net80211.c.

Referenced by net80211_alloc().

◆ __ll_protocol

struct ll_protocol net80211_ll_protocol __ll_protocol
static
Initial value:
= {
.name = "802.11",
.init_addr = eth_init_addr,
.ntoa = eth_ntoa,
.mc_hash = eth_mc_hash,
.eth_addr = eth_eth_addr,
.eui64 = eth_eui64,
.ll_proto = htons ( ARPHRD_ETHER ),
.hw_addr_len = ETH_ALEN,
.ll_addr_len = ETH_ALEN,
.ll_header_len = IEEE80211_TYP_FRAME_HEADER_LEN +
}
int eth_eth_addr(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: ethernet.c:222
void eth_init_addr(const void *hw_addr, void *ll_addr)
Initialise Ethernet address.
Definition: ethernet.c:150
int eth_eui64(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: ethernet.c:234
static int net80211_ll_pull(struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
int eth_mc_hash(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition: ethernet.c:193
static int net80211_ll_push(struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
Add 802.11 link-layer header.
Definition: net80211.c:483
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
#define ETH_ALEN
Definition: if_ether.h:8
#define IEEE80211_LLC_HEADER_LEN
Length of LLC/SNAP headers on data frames.
Definition: ieee80211.h:31
#define ARPHRD_ETHER
Ethernet 10Mbps.
Definition: if_arp.h:16
#define htons(value)
Definition: byteswap.h:135

802.11 link-layer protocol

Definition at line 597 of file net80211.c.

◆ net80211_process_desc

struct process_descriptor net80211_process_desc
static
Initial value:
=
PROC_DESC ( struct net80211_device, proc_assoc,
static void net80211_step_associate(struct net80211_device *dev)
Step 802.11 association process.
Definition: net80211.c:1646
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition: process.h:82

802.11 association process descriptor

Definition at line 738 of file net80211.c.

Referenced by net80211_alloc().

◆ __errortab

struct errortab common_wireless_errors [] __errortab
Initial value:

Common 802.11 errors.

Definition at line 2820 of file net80211.c.