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

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FILE_SECBOOT (FORBIDDEN)
__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.
static int net80211_netdev_open (struct net_device *netdev)
 Open 802.11 device and start association.
static void net80211_netdev_close (struct net_device *netdev)
 Close 802.11 device.
static int net80211_netdev_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet on 802.11 device.
static void net80211_netdev_poll (struct net_device *netdev)
 Poll 802.11 device for received packets and completed transmissions.
static void net80211_netdev_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts for 802.11 device.
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.
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.
static void net80211_filter_hw_channels (struct net80211_device *dev)
 Filter 802.11 device channels for hardware capabilities.
static void net80211_set_rtscts_rate (struct net80211_device *dev)
 Pick TX rate for RTS/CTS packets based on data rate.
static int net80211_process_capab (struct net80211_device *dev, u16 capab)
 Update 802.11 device state to reflect received capabilities field.
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.
static union ieee80211_ienet80211_marshal_request_info (struct net80211_device *dev, union ieee80211_ie *ie)
 Create information elements for outgoing probe or association packet.
static void net80211_step_associate (struct net80211_device *dev)
 Step 802.11 association process.
static void net80211_handle_auth (struct net80211_device *dev, struct io_buffer *iob)
 Handle receipt of 802.11 authentication frame.
static void net80211_handle_assoc_reply (struct net80211_device *dev, struct io_buffer *iob)
 Handle receipt of 802.11 association reply frame.
static int net80211_send_disassoc (struct net80211_device *dev, int reason, int deauth)
 Send 802.11 disassociation frame.
static void net80211_handle_mgmt (struct net80211_device *dev, struct io_buffer *iob, int signal)
 Handle receipt of 802.11 management frame.
static void net80211_free_frags (struct net80211_device *dev, int fcid)
 Free buffers used by 802.11 fragment cache entry.
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.
static void net80211_rx_frag (struct net80211_device *dev, struct io_buffer *iob, int signal)
 Handle receipt of 802.11 fragment.
static int net80211_check_settings_update (void)
 Check for 802.11 SSID or key updates.
const struct setting net80211_ssid_setting __setting (SETTING_NETDEV_EXTRA, ssid)
 The network name to associate with.
const struct setting net80211_active_setting __setting (SETTING_NETDEV_EXTRA, active-scan)
 Whether to use active scanning.
const struct setting net80211_key_setting __setting (SETTING_NETDEV_EXTRA, key)
 The cryptographic key to use.
static int net80211_rate_is_erp (u16 rate)
 Determine whether a transmission rate uses ERP/OFDM.
u16 net80211_duration (struct net80211_device *dev, int bytes, u16 rate)
 Calculate one frame's contribution to 802.11 duration field.
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.
struct net80211_devicenet80211_get (struct net_device *netdev)
 Get 802.11 device from wrapping network device.
int net80211_keep_mgmt (struct net80211_device *dev, int enable)
 Set state of 802.11 device keeping management frames.
struct io_buffernet80211_mgmt_dequeue (struct net80211_device *dev, int *signal)
 Get 802.11 management frame.
int net80211_tx_mgmt (struct net80211_device *dev, u16 fc, u8 dest[6], struct io_buffer *iob)
 Transmit 802.11 management frame.
struct net80211_devicenet80211_alloc (size_t priv_size)
 Allocate 802.11 device.
int net80211_register (struct net80211_device *dev, struct net80211_device_operations *ops, struct net80211_hw_info *hw)
 Register 802.11 device with network stack.
void net80211_unregister (struct net80211_device *dev)
 Unregister 802.11 device from network stack.
void net80211_free (struct net80211_device *dev)
 Free 802.11 device.
static void net80211_set_state (struct net80211_device *dev, short clear, short set, u16 status)
 Set state of 802.11 device.
struct net80211_probe_ctxnet80211_probe_start (struct net80211_device *dev, const char *essid, int active)
 Begin probe of 802.11 networks.
int net80211_probe_step (struct net80211_probe_ctx *ctx)
 Continue probe of 802.11 networks.
struct net80211_wlannet80211_probe_finish_best (struct net80211_probe_ctx *ctx)
 Finish probe of 802.11 networks, returning best-signal network found.
struct list_headnet80211_probe_finish_all (struct net80211_probe_ctx *ctx)
 Finish probe of 802.11 networks, returning all networks found.
void net80211_free_wlan (struct net80211_wlan *wlan)
 Free WLAN structure.
void net80211_free_wlanlist (struct list_head *list)
 Free list of WLAN structures.
void net80211_autoassociate (struct net80211_device *dev)
 Start 802.11 association process.
void net80211_set_rate_idx (struct net80211_device *dev, int rate)
 Set data transmission rate for 802.11 device.
int net80211_change_channel (struct net80211_device *dev, int channel)
 Configure 802.11 device to transmit on a certain channel.
int net80211_prepare_probe (struct net80211_device *dev, int band, int active)
 Prepare 802.11 device channel and rate set for scanning.
int net80211_prepare_assoc (struct net80211_device *dev, struct net80211_wlan *wlan)
 Prepare 802.11 device channel and rate set for communication.
int net80211_send_auth (struct net80211_device *dev, struct net80211_wlan *wlan, int method)
 Send 802.11 initial authentication frame.
int net80211_send_assoc (struct net80211_device *dev, struct net80211_wlan *wlan)
 Send 802.11 association frame.
void net80211_deauthenticate (struct net80211_device *dev, int rc)
 Deauthenticate from current network and try again.
static void net80211_update_link_quality (struct net80211_device *dev, struct io_buffer *iob)
 Update link quality information based on received beacon.
void net80211_rx (struct net80211_device *dev, struct io_buffer *iob, int signal, u16 rate)
 Handle receipt of 802.11 frame.
void net80211_rx_err (struct net80211_device *dev, struct io_buffer *iob, int rc)
 Indicate an error in receiving a packet.
void net80211_tx_complete (struct net80211_device *dev, struct io_buffer *iob, int retries, int rc)
 Indicate the completed transmission of a packet.
 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.
static struct net80211_device_operations net80211_null_ops
 Set of device operations that does nothing.
struct settings_applicator net80211_applicator __settings_applicator
 802.11 settings applicator
static struct net_device_operations net80211_netdev_ops
 Network device operations for a wrapped 802.11 device.
static struct ll_protocol net80211_ll_protocol __ll_protocol
 802.11 link-layer protocol
static struct process_descriptor net80211_process_desc
 802.11 association process descriptor
struct errortab common_wireless_errors[] __errortab
 Common 802.11 errors.

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 1260 of file net80211.c.

Referenced by net80211_probe_step().

◆ 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 1267 of file net80211.c.

Referenced by net80211_probe_step().

◆ NET80211_PROBE_TIMEOUT

#define NET80211_PROBE_TIMEOUT   6

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

Definition at line 1270 of file net80211.c.

Referenced by net80211_probe_step().

◆ ASSOC_TIMEOUT

#define ASSOC_TIMEOUT   TICKS_PER_SEC

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

Definition at line 1637 of file net80211.c.

Referenced by net80211_step_associate().

◆ ASSOC_RETRIES

#define ASSOC_RETRIES   2

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

Definition at line 1640 of file net80211.c.

Referenced by net80211_step_associate().

◆ LQ_SMOOTH

#define LQ_SMOOTH   7

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

Definition at line 2402 of file net80211.c.

Referenced by net80211_update_link_quality().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( FORBIDDEN )

◆ 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 113 of file net80211.c.

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

References __unused, __weak, and ENOTSUP.

Referenced by net80211_probe_step().

◆ net80211_rate_is_erp()

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 400 of file net80211.c.

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

References u16.

Referenced by net80211_duration().

◆ net80211_ll_pull()

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 538 of file net80211.c.

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

References __unused, 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, 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 707 of file net80211.c.

709{
710 struct ieee80211_frame *hdr = iob_push ( iob,
712
715 hdr->duration = net80211_duration ( dev, 10, dev->rates[dev->rate] );
716 hdr->seq = IEEE80211_MAKESEQ ( ++dev->last_tx_seqnr, 0 );
717
718 memcpy ( hdr->addr1, dest, ETH_ALEN ); /* DA = RA */
719 memcpy ( hdr->addr2, dev->netdev->ll_addr, ETH_ALEN ); /* SA = TA */
720 memcpy ( hdr->addr3, dest, ETH_ALEN ); /* BSSID */
721
722 if ( fc & IEEE80211_FC_PROTECTED ) {
723 if ( ! dev->crypto )
724 return -EINVAL_CRYPTO_REQUEST;
725
726 struct io_buffer *eiob = dev->crypto->encrypt ( dev->crypto,
727 iob );
728 free_iob ( iob );
729 iob = eiob;
730 }
731
732 return netdev_tx ( dev->netdev, iob );
733}
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
#define IEEE80211_FC_PROTECTED
802.11 Frame Control field: Protected flag
Definition ieee80211.h:264
#define IEEE80211_TYPE_MGMT
Type value for management (layer-2) frames.
Definition ieee80211.h:100
#define IEEE80211_MAKESEQ(seqnr, frag)
Make 802.11 Sequence Control field from sequence and fragment numbers.
Definition ieee80211.h:286
u16 net80211_duration(struct net80211_device *dev, int bytes, u16 rate)
Calculate one frame's contribution to 802.11 duration field.
Definition net80211.c:442
u16 fc
802.11 Frame Control field
Definition ieee80211.h:0
#define ETH_ALEN
Definition if_ether.h:9
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
#define iob_push(iobuf, len)
Definition iobuf.h:89
#define EINVAL_CRYPTO_REQUEST
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition netdevice.c:335
A persistent I/O buffer.
Definition iobuf.h:38
struct io_buffer *(* encrypt)(struct net80211_crypto *crypto, struct io_buffer *iob)
Encrypt a frame using the cryptosystem.
Definition net80211.h:733
struct net_device * netdev
The net_device that wraps us.
Definition net80211.h:789
u16 last_tx_seqnr
The sequence number of the last packet we sent.
Definition net80211.h:997
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition net80211.h:818
struct net80211_crypto * crypto
802.11 cryptosystem for our current network
Definition net80211.h:940
u8 rate
The rate currently in use, as an index into the rates array.
Definition net80211.h:824
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition netdevice.h:388

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, net80211_device::rates, u16, and u8.

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

◆ net80211_set_state()

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 867 of file net80211.c.

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

References clear, 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, status, and u16.

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()

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 2411 of file net80211.c.

2413{
2414 struct ieee80211_frame *hdr = iob->data;
2415 struct ieee80211_beacon *beacon;
2416 u32 dt, rxi;
2417
2418 if ( ! ( dev->state & NET80211_ASSOCIATED ) )
2419 return;
2420
2421 beacon = ( struct ieee80211_beacon * ) hdr->data;
2422 dt = ( u32 ) ( beacon->timestamp - dev->last_beacon_timestamp );
2423 rxi = dev->rx_beacon_interval;
2424
2425 rxi = ( LQ_SMOOTH * rxi ) + ( ( 8 - LQ_SMOOTH ) * dt );
2426 dev->rx_beacon_interval = rxi >> 3;
2427
2428 dev->last_beacon_timestamp = beacon->timestamp;
2429}
#define ieee80211_beacon
Definition ieee80211.h:1069
#define LQ_SMOOTH
Smoothing factor (1-7) for link quality calculation.
Definition net80211.c:2402
u64 last_beacon_timestamp
TSFT value for last beacon received, microseconds.
Definition net80211.h:968
u32 rx_beacon_interval
Smoothed average time between beacons, microseconds.
Definition net80211.h:974
#define u32
Definition vga.h:21

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

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 48 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 51 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 void net80211_netdev_close(struct net_device *netdev)
Close 802.11 device.
Definition net80211.c:284
static int net80211_netdev_open(struct net_device *netdev)
Open 802.11 device and start association.
Definition net80211.c:257
static int net80211_netdev_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet on 802.11 device.
Definition net80211.c:321
static void net80211_netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts for 802.11 device.
Definition net80211.c:371
static void net80211_netdev_poll(struct net_device *netdev)
Poll 802.11 device for received packets and completed transmissions.
Definition net80211.c:357

Network device operations for a wrapped 802.11 device.

Definition at line 380 of file net80211.c.

380 {
381 .open = net80211_netdev_open,
382 .close = net80211_netdev_close,
383 .transmit = net80211_netdev_transmit,
384 .poll = net80211_netdev_poll,
385 .irq = net80211_netdev_irq,
386};

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_mc_hash(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition ethernet.c:194
void eth_init_addr(const void *hw_addr, void *ll_addr)
Initialise Ethernet address.
Definition ethernet.c:151
int eth_eui64(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition ethernet.c:235
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
int eth_eth_addr(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition ethernet.c:223
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 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:484
#define ARPHRD_ETHER
Ethernet 10Mbps.
Definition if_arp.h:17
#define htons(value)
Definition byteswap.h:136

802.11 link-layer protocol

Definition at line 598 of file net80211.c.

598 {
599 .name = "802.11",
600 .push = net80211_ll_push,
601 .pull = net80211_ll_pull,
602 .init_addr = eth_init_addr,
603 .ntoa = eth_ntoa,
604 .mc_hash = eth_mc_hash,
605 .eth_addr = eth_eth_addr,
606 .eui64 = eth_eui64,
607 .ll_proto = htons ( ARPHRD_ETHER ), /* "encapsulated Ethernet" */
608 .hw_addr_len = ETH_ALEN,
609 .ll_addr_len = ETH_ALEN,
610 .ll_header_len = IEEE80211_TYP_FRAME_HEADER_LEN +
612};

◆ 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:1647
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition process.h:83
Structure encapsulating the complete state of an 802.11 device.
Definition net80211.h:787

802.11 association process descriptor

Definition at line 739 of file net80211.c.

Referenced by net80211_alloc().

◆ __errortab

struct errortab common_wireless_errors [] __errortab
Initial value:

Common 802.11 errors.

Definition at line 2821 of file net80211.c.