iPXE
802.11 driver interface API

Functions

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.
u16 net80211_duration (struct net80211_device *dev, int bytes, u16 rate)
 Calculate one frame's contribution to 802.11 duration field.
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.
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.

Detailed Description

Function Documentation

◆ net80211_alloc()

struct net80211_device * net80211_alloc ( size_t priv_size)

Allocate 802.11 device.

Parameters
priv_sizeSize of driver-private allocation area
Return values
devNewly allocated 802.11 device

This function allocates a net_device with space in its private area for both the net80211_device it will wrap and the driver-private data space requested. It initializes the link-layer-specific parts of the net_device, and links the net80211_device to the net_device appropriately.

Definition at line 755 of file net80211.c.

756{
757 struct net80211_device *dev;
758 struct net_device *netdev =
759 alloc_netdev ( sizeof ( *dev ) + priv_size );
760
761 if ( ! netdev )
762 return NULL;
763
764 netdev->ll_protocol = &net80211_ll_protocol;
765 netdev->ll_broadcast = eth_broadcast;
766 netdev->max_pkt_len = IEEE80211_MAX_DATA_LEN;
768
769 dev = netdev->priv;
770 dev->netdev = netdev;
771 dev->priv = ( u8 * ) dev + sizeof ( *dev );
772 dev->op = &net80211_null_ops;
773
775 &netdev->refcnt );
776 INIT_LIST_HEAD ( &dev->mgmt_queue );
777 INIT_LIST_HEAD ( &dev->mgmt_info_queue );
778
779 return dev;
780}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint8_t eth_broadcast[ETH_ALEN]
Ethernet broadcast MAC address.
Definition ethernet.c:48
static struct net_device * netdev
Definition gdbudp.c:53
#define IEEE80211_MAX_DATA_LEN
Maximum length of frame payload.
Definition ieee80211.h:28
#define u8
Definition igbvf_osdep.h:40
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
static struct net80211_device_operations net80211_null_ops
Set of device operations that does nothing.
Definition net80211.c:51
static struct net_device_operations net80211_netdev_ops
Network device operations for a wrapped 802.11 device.
Definition net80211.c:380
static struct process_descriptor net80211_process_desc
802.11 association process descriptor
Definition net80211.c:739
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition netdevice.c:722
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition process.h:146
Structure encapsulating the complete state of an 802.11 device.
Definition net80211.h:787
A network device.
Definition netdevice.h:353
struct device * dev
Underlying hardware device.
Definition netdevice.h:365

References alloc_netdev(), net_device::dev, eth_broadcast, IEEE80211_MAX_DATA_LEN, INIT_LIST_HEAD, net80211_netdev_ops, net80211_null_ops, net80211_process_desc, netdev, netdev_init(), NULL, process_init_stopped(), and u8.

Referenced by ath5k_probe(), ath_pci_probe(), and rtl818x_probe().

◆ net80211_register()

int net80211_register ( struct net80211_device * dev,
struct net80211_device_operations * ops,
struct net80211_hw_info * hw )

Register 802.11 device with network stack.

Parameters
dev802.11 device
ops802.11 device operations
hw802.11 hardware information

This also registers the wrapping net_device with the higher network layers.

Definition at line 792 of file net80211.c.

795{
796 dev->op = ops;
797 dev->hw = malloc ( sizeof ( *hw ) );
798 if ( ! dev->hw )
799 return -ENOMEM;
800
801 memcpy ( dev->hw, hw, sizeof ( *hw ) );
802 memcpy ( dev->netdev->hw_addr, hw->hwaddr, ETH_ALEN );
803
804 /* Set some sensible channel defaults for driver's open() function */
805 memcpy ( dev->channels, dev->hw->channels,
806 NET80211_MAX_CHANNELS * sizeof ( dev->channels[0] ) );
807 dev->channel = 0;
808
809 /* Mark device as not supporting interrupts, if applicable */
810 if ( ! ops->irq )
812
814 return register_netdev ( dev->netdev );
815}
#define ENOMEM
Not enough space.
Definition errno.h:535
#define ETH_ALEN
Definition if_ether.h:9
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
static struct list_head net80211_devices
List of 802.11 devices.
Definition net80211.c:48
#define NET80211_MAX_CHANNELS
The maximum number of channels we allow to be configured simultaneously.
Definition net80211.h:275
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition netdevice.h:453
Definition hw.c:16
void(* irq)(struct net80211_device *dev, int enable)
Enable or disable interrupts.
Definition net80211.h:364
struct net_device * netdev
The net_device that wraps us.
Definition net80211.h:789
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition net80211.h:806
struct net80211_device_operations * op
802.11 device operations
Definition net80211.h:795
u8 channel
The channel currently in use, as an index into the channels array.
Definition net80211.h:812
struct list_head list
List of 802.11 devices.
Definition net80211.h:792
struct net80211_hw_info * hw
Information about the hardware, provided to net80211_register()
Definition net80211.h:801
struct net80211_channel channels[NET80211_MAX_CHANNELS]
List of RF channels supported by the card.
Definition net80211.h:498
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition netdevice.h:382
unsigned int state
Current device state.
Definition netdevice.h:396

References net_device::dev, ENOMEM, ETH_ALEN, net80211_device_operations::irq, list_add_tail, malloc(), memcpy(), net80211_devices, NET80211_MAX_CHANNELS, NETDEV_IRQ_UNSUPPORTED, and register_netdev().

Referenced by ath5k_attach(), ath9k_init_device(), and rtl818x_probe().

◆ net80211_duration()

u16 net80211_duration ( struct net80211_device * dev,
int bytes,
u16 rate )

Calculate one frame's contribution to 802.11 duration field.

Parameters
dev802.11 device
bytesAmount of data to calculate duration for
Return values
durDuration field in microseconds

To avoid multiple stations attempting to transmit at once, 802.11 provides that every packet shall include a duration field specifying a length of time for which the wireless medium will be reserved after it is transmitted. The duration is measured in microseconds and is calculated with respect to the current physical-layer parameters of the 802.11 device.

For an unfragmented data or management frame, or the last fragment of a fragmented frame, the duration captures only the 10 data bytes of one ACK; call once with bytes = 10.

For a fragment of a data or management rame that will be followed by more fragments, the duration captures an ACK, the following fragment, and its ACK; add the results of three calls, two with bytes = 10 and one with bytes set to the next fragment's size.

For an RTS control frame, the duration captures the responding CTS, the frame being sent, and its ACK; add the results of three calls, two with bytes = 10 and one with bytes set to the next frame's size (assuming unfragmented).

For a CTS-to-self control frame, the duration captures the frame being protected and its ACK; add the results of two calls, one with bytes = 10 and one with bytes set to the next frame's size.

No other frame types are currently supported by iPXE.

Definition at line 442 of file net80211.c.

443{
444 struct net80211_channel *chan = &dev->channels[dev->channel];
445 u32 kbps = rate * 100;
446
447 if ( chan->band == NET80211_BAND_5GHZ || net80211_rate_is_erp ( rate ) ) {
448 /* OFDM encoding (802.11a/g) */
449 int bits_per_symbol = ( kbps * 4 ) / 1000; /* 4us/symbol */
450 int bits = 22 + ( bytes << 3 ); /* 22-bit PLCP */
451 int symbols = ( bits + bits_per_symbol - 1 ) / bits_per_symbol;
452
453 return 16 + 20 + ( symbols * 4 ); /* 16us SIFS, 20us preamble */
454 } else {
455 /* CCK encoding (802.11b) */
456 int phy_time = 144 + 48; /* preamble + PLCP */
457 int bits = bytes << 3;
458 int data_time = ( bits * 1000 + kbps - 1 ) / kbps;
459
461 phy_time >>= 1;
462
463 return 10 + phy_time + data_time; /* 10us SIFS */
464 }
465}
static volatile void * bits
Definition bitops.h:28
#define NET80211_BAND_5GHZ
The band from 4.9 GHz to 5.7 GHz, which tends to be more restricted.
Definition net80211.h:47
#define NET80211_PHY_USE_SHORT_PREAMBLE
Whether to use 802.11b short preamble operation.
Definition net80211.h:260
uint8_t bytes[64]
Definition ib_mad.h:5
static int net80211_rate_is_erp(u16 rate)
Determine whether a transmission rate uses ERP/OFDM.
Definition net80211.c:400
An 802.11 RF channel.
Definition net80211.h:386
u8 band
The band with which this channel is associated.
Definition net80211.h:388
int phy_flags
Physical layer options.
Definition net80211.h:983
#define u32
Definition vga.h:21

References net80211_channel::band, bits, bytes, net80211_device::channel, net80211_device::channels, NET80211_BAND_5GHZ, NET80211_PHY_USE_SHORT_PREAMBLE, net80211_rate_is_erp(), net80211_device::phy_flags, u16, and u32.

Referenced by ath5k_hw_write_rate_duration(), net80211_cts_duration(), net80211_ll_push(), and net80211_tx_mgmt().

◆ net80211_rx()

void net80211_rx ( struct net80211_device * dev,
struct io_buffer * iob,
int signal,
u16 rate )

Handle receipt of 802.11 frame.

Parameters
dev802.11 device
iobI/O buffer
signalReceived signal strength
rateBitrate at which frame was received, in 100 kbps units

If the rate or signal is unknown, 0 should be passed.

Definition at line 2690 of file net80211.c.

2692{
2693 struct ieee80211_frame *hdr = iob->data;
2694 u16 type = hdr->fc & IEEE80211_FC_TYPE;
2696 goto drop; /* drop invalid-version packets */
2697
2698 if ( type == IEEE80211_TYPE_CTRL )
2699 goto drop; /* we don't handle control packets,
2700 the hardware does */
2701
2702 if ( dev->last_rx_seq == hdr->seq )
2703 goto drop; /* avoid duplicate packet */
2704 dev->last_rx_seq = hdr->seq;
2705
2706 if ( dev->hw->flags & NET80211_HW_RX_HAS_FCS ) {
2707 /* discard the FCS */
2708 iob_unput ( iob, 4 );
2709 }
2710
2711 /* Only decrypt packets from our BSSID, to avoid spurious errors */
2712 if ( ( hdr->fc & IEEE80211_FC_PROTECTED ) &&
2713 ! memcmp ( hdr->addr2, dev->bssid, ETH_ALEN ) ) {
2714 /* Decrypt packet; record and drop if it fails */
2715 struct io_buffer *niob;
2716 struct net80211_crypto *crypto = dev->crypto;
2717
2718 if ( ! dev->crypto ) {
2719 DBGC ( dev, "802.11 %p cannot decrypt packet "
2720 "without a cryptosystem\n", dev );
2721 goto drop_crypt;
2722 }
2723
2724 if ( ( hdr->addr1[0] & 1 ) && dev->gcrypto ) {
2725 /* Use group decryption if needed */
2726 crypto = dev->gcrypto;
2727 }
2728
2729 niob = crypto->decrypt ( crypto, iob );
2730 if ( ! niob ) {
2731 DBGC ( dev, "802.11 %p decryption error\n", dev );
2732 goto drop_crypt;
2733 }
2734 free_iob ( iob );
2735 iob = niob;
2736 hdr = iob->data;
2737 }
2738
2739 dev->last_signal = signal;
2740
2741 /* Fragments go into the frag cache or get dropped. */
2742 if ( IEEE80211_FRAG ( hdr->seq ) != 0
2743 || ( hdr->fc & IEEE80211_FC_MORE_FRAG ) ) {
2744 net80211_rx_frag ( dev, iob, signal );
2745 return;
2746 }
2747
2748 /* Management frames get handled, enqueued, or dropped. */
2749 if ( type == IEEE80211_TYPE_MGMT ) {
2750 net80211_handle_mgmt ( dev, iob, signal );
2751 return;
2752 }
2753
2754 /* Data frames get dropped or sent to the net_device. */
2756 goto drop; /* drop QoS, CFP, or null data packets */
2757
2758 /* Update rate-control algorithm */
2759 if ( dev->rctl )
2760 rc80211_update_rx ( dev, hdr->fc & IEEE80211_FC_RETRY, rate );
2761
2762 /* Pass packet onward */
2763 if ( dev->state & NET80211_ASSOCIATED ) {
2764 netdev_rx ( dev->netdev, iob );
2765 return;
2766 }
2767
2768 /* No association? Drop it. */
2769 goto drop;
2770
2771 drop_crypt:
2773 drop:
2774 DBGC2 ( dev, "802.11 %p dropped packet fc=%04x seq=%04x\n", dev,
2775 hdr->fc, hdr->seq );
2776 free_iob ( iob );
2777 return;
2778}
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
uint32_t type
Operating system type.
Definition ena.h:1
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
#define IEEE80211_FC_SUBTYPE
802.11 Frame Control field, Frame Subtype bitmask
Definition ieee80211.h:110
#define IEEE80211_FC_PROTECTED
802.11 Frame Control field: Protected flag
Definition ieee80211.h:264
#define IEEE80211_TYPE_CTRL
Type value for control (layer-1, hardware-managed) frames.
Definition ieee80211.h:103
#define IEEE80211_TYPE_MGMT
Type value for management (layer-2) frames.
Definition ieee80211.h:100
#define IEEE80211_FC_RETRY
802.11 Frame Control field: Retransmission flag
Definition ieee80211.h:243
#define IEEE80211_FC_TYPE
802.11 Frame Control field, Frame Type bitmask
Definition ieee80211.h:97
#define IEEE80211_FC_MORE_FRAG
802.11 Frame Control field: More Fragments flag
Definition ieee80211.h:240
#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_FRAG(seq)
Extract fragment number from 802.11 Sequence Control field.
Definition ieee80211.h:283
static void net80211_handle_mgmt(struct net80211_device *dev, struct io_buffer *iob, int signal)
Handle receipt of 802.11 management frame.
Definition net80211.c:2439
static void net80211_rx_frag(struct net80211_device *dev, struct io_buffer *iob, int signal)
Handle receipt of 802.11 fragment.
Definition net80211.c:2597
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition net80211.h:201
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
#define iob_unput(iobuf, len)
Definition iobuf.h:140
#define EINVAL_CRYPTO_REQUEST
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
void rc80211_update_rx(struct net80211_device *dev, int retry, u16 rate)
Update rate-control state for received packet.
Definition rc80211.c:352
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
An 802.11 data or management frame without QoS or WDS header fields.
Definition ieee80211.h:301
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
Interface to an 802.11 cryptosystem.
Definition net80211.h:690
struct io_buffer *(* decrypt)(struct net80211_crypto *crypto, struct io_buffer *iob)
Decrypt a frame using the cryptosystem.
Definition net80211.h:759
u16 state
State of our association to the network.
Definition net80211.h:921
struct net80211_crypto * crypto
802.11 cryptosystem for our current network
Definition net80211.h:940
int last_signal
Signal strength of last received packet.
Definition net80211.h:986
struct rc80211_ctx * rctl
Rate control state.
Definition net80211.h:989
struct net80211_crypto * gcrypto
802.11 cryptosystem for multicast and broadcast frames
Definition net80211.h:951
u8 bssid[ETH_ALEN]
MAC address of the access point most recently associated.
Definition net80211.h:954
u16 last_rx_seq
Packet duplication elimination state.
Definition net80211.h:1008
enum net80211_hw_info::@277203366166200071173154201003141076360026365126 flags
A set of flags indicating peculiarities of this device.
#define u16
Definition vga.h:20

References net80211_device::bssid, net80211_device::crypto, io_buffer::data, DBGC, DBGC2, net80211_crypto::decrypt, EINVAL_CRYPTO_REQUEST, ETH_ALEN, net80211_hw_info::flags, free_iob(), net80211_device::gcrypto, hdr, net80211_device::hw, IEEE80211_FC_MORE_FRAG, IEEE80211_FC_PROTECTED, IEEE80211_FC_RETRY, IEEE80211_FC_SUBTYPE, IEEE80211_FC_TYPE, IEEE80211_FC_VERSION, IEEE80211_FRAG, IEEE80211_STYPE_DATA, IEEE80211_THIS_VERSION, IEEE80211_TYPE_CTRL, IEEE80211_TYPE_MGMT, iob_unput, net80211_device::last_rx_seq, net80211_device::last_signal, memcmp(), NET80211_ASSOCIATED, net80211_handle_mgmt(), net80211_rx_frag(), net80211_device::netdev, netdev_rx(), netdev_rx_err(), NULL, rc80211_update_rx(), net80211_device::rctl, net80211_device::state, type, and u16.

Referenced by ath5k_handle_rx(), ath_rx_tasklet(), net80211_rx_frag(), and rtl818x_handle_rx().

◆ net80211_rx_err()

void net80211_rx_err ( struct net80211_device * dev,
struct io_buffer * iob,
int rc )

Indicate an error in receiving a packet.

Parameters
dev802.11 device
iobI/O buffer with received packet, or NULL
rcError code

This logs the error with the wrapping net_device, and frees iob if it is passed.

Definition at line 2789 of file net80211.c.

2791{
2792 netdev_rx_err ( dev->netdev, iob, rc );
2793}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3

References net80211_device::netdev, netdev_rx_err(), and rc.

Referenced by ath5k_handle_rx(), and rtl818x_handle_rx().

◆ net80211_tx_complete()

void net80211_tx_complete ( struct net80211_device * dev,
struct io_buffer * iob,
int retries,
int rc )

Indicate the completed transmission of a packet.

Parameters
dev802.11 device
iobI/O buffer of transmitted packet
retriesNumber of times this packet was retransmitted
rcError code, or 0 for success

This logs an error with the wrapping net_device if one occurred, and removes and frees the I/O buffer from its TX queue. The provided retry information is used to tune our transmission rate.

If the packet did not need to be retransmitted because it was properly ACKed the first time, retries should be 0.

Definition at line 2809 of file net80211.c.

2811{
2812 /* Update rate-control algorithm */
2813 if ( dev->rctl )
2814 rc80211_update_tx ( dev, retries, rc );
2815
2816 /* Pass completion onward */
2817 netdev_tx_complete_err ( dev->netdev, iob, rc );
2818}
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471
void rc80211_update_tx(struct net80211_device *dev, int retries, int rc)
Update rate-control state for transmitted packet.
Definition rc80211.c:317

References net80211_device::netdev, netdev_tx_complete_err(), rc, rc80211_update_tx(), and net80211_device::rctl.

Referenced by ath5k_tx_processq(), ath5k_txbuf_free(), ath_tx_complete(), rtl818x_free_tx_ring(), and rtl818x_handle_tx().

◆ net80211_unregister()

void net80211_unregister ( struct net80211_device * dev)

Unregister 802.11 device from network stack.

Parameters
dev802.11 device

After this call, the device operations are cleared so that they will not be called.

Definition at line 825 of file net80211.c.

826{
827 unregister_netdev ( dev->netdev );
828 list_del ( &dev->list );
829 dev->op = &net80211_null_ops;
830}
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942

References net_device::dev, list_del, net80211_null_ops, and unregister_netdev().

Referenced by ath5k_detach(), ath9k_deinit_device(), and rtl818x_remove().

◆ net80211_free()

void net80211_free ( struct net80211_device * dev)

Free 802.11 device.

Parameters
dev802.11 device

The device should be unregistered before this function is called.

Definition at line 839 of file net80211.c.

840{
841 free ( dev->hw );
842 rc80211_free ( dev->rctl );
843 netdev_nullify ( dev->netdev );
844 netdev_put ( dev->netdev );
845}
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
void rc80211_free(struct rc80211_ctx *ctx)
Free rate-control context.
Definition rc80211.c:370
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55

References net_device::dev, free, netdev_nullify(), netdev_put(), and rc80211_free().

Referenced by ath5k_probe(), ath5k_remove(), ath_pci_probe(), ath_pci_remove(), rtl818x_probe(), and rtl818x_remove().