iPXE
Functions
802.11 network association API

Functions

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

Detailed Description

Function Documentation

◆ net80211_prepare_assoc()

int net80211_prepare_assoc ( struct net80211_device dev,
struct net80211_wlan wlan 
)

Prepare 802.11 device channel and rate set for communication.

Parameters
dev802.11 device
wlanWLAN to prepare for communication with
Return values
rcReturn status code

Definition at line 2105 of file net80211.c.

2107 {
2108  struct ieee80211_frame *hdr = wlan->beacon->data;
2109  struct ieee80211_beacon *beacon =
2110  ( struct ieee80211_beacon * ) hdr->data;
2111  struct net80211_handshaker *handshaker;
2112  int rc;
2113 
2114  assert ( netdev_is_open ( dev->netdev ) );
2115 
2116  net80211_set_state ( dev, NET80211_ASSOCIATED, 0, 0 );
2117  memcpy ( dev->bssid, wlan->bssid, ETH_ALEN );
2118  strcpy ( dev->essid, wlan->essid );
2119 
2120  free ( dev->rsn_ie );
2121  dev->rsn_ie = NULL;
2122 
2123  dev->last_beacon_timestamp = beacon->timestamp;
2124  dev->tx_beacon_interval = 1024 * beacon->beacon_interval;
2125 
2126  /* Barring an IE that tells us the channel outright, assume
2127  the channel we heard this AP best on is the channel it's
2128  communicating on. */
2129  net80211_change_channel ( dev, wlan->channel );
2130 
2131  rc = net80211_process_capab ( dev, beacon->capability );
2132  if ( rc )
2133  return rc;
2134 
2135  rc = net80211_process_ie ( dev, beacon->info_element,
2136  wlan->beacon->tail );
2137  if ( rc )
2138  return rc;
2139 
2140  /* Associate at the lowest rate so we know it'll get through */
2141  dev->rate = 0;
2142  dev->op->config ( dev, NET80211_CFG_RATE );
2143 
2144  /* Free old handshaker and crypto, if they exist */
2145  if ( dev->handshaker && dev->handshaker->stop &&
2146  dev->handshaker->started )
2147  dev->handshaker->stop ( dev );
2148  free ( dev->handshaker );
2149  dev->handshaker = NULL;
2150  free ( dev->crypto );
2151  free ( dev->gcrypto );
2152  dev->crypto = dev->gcrypto = NULL;
2153 
2154  /* Find new security handshaker to use */
2155  for_each_table_entry ( handshaker, NET80211_HANDSHAKERS ) {
2156  if ( handshaker->protocol == wlan->handshaking ) {
2157  dev->handshaker = zalloc ( sizeof ( *handshaker ) +
2158  handshaker->priv_len );
2159  if ( ! dev->handshaker )
2160  return -ENOMEM;
2161 
2162  memcpy ( dev->handshaker, handshaker,
2163  sizeof ( *handshaker ) );
2164  dev->handshaker->priv = ( ( void * ) dev->handshaker +
2165  sizeof ( *handshaker ) );
2166  break;
2167  }
2168  }
2169 
2170  if ( ( wlan->handshaking != NET80211_SECPROT_NONE ) &&
2171  ! dev->handshaker ) {
2172  DBGC ( dev, "802.11 %p no support for handshaking scheme %d\n",
2173  dev, wlan->handshaking );
2174  return -( ENOTSUP | ( wlan->handshaking << 8 ) );
2175  }
2176 
2177  /* Initialize security handshaker */
2178  if ( dev->handshaker ) {
2179  rc = dev->handshaker->init ( dev );
2180  if ( rc < 0 )
2181  return rc;
2182  }
2183 
2184  return 0;
2185 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
No security handshaking.
Definition: net80211.h:102
u64 last_beacon_timestamp
TSFT value for last beacon received, microseconds.
Definition: net80211.h:968
int(* config)(struct net80211_device *dev, int changed)
Update hardware state to match 802.11 layer state.
Definition: net80211.h:381
char essid[IEEE80211_MAX_SSID_LEN+1]
The human-readable ESSID (network name)
Definition: net80211.h:1064
enum net80211_security_proto handshaking
Security handshaking method used on the network.
Definition: net80211.h:1084
#define DBGC(...)
Definition: compiler.h:505
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
union ieee80211_ie * rsn_ie
RSN or WPA information element to include with association.
Definition: net80211.h:932
char essid[IEEE80211_MAX_SSID_LEN+1]
SSID of the access point we are or will be associated with.
Definition: net80211.h:962
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u32 tx_beacon_interval
Time between AP sending beacons, microseconds.
Definition: net80211.h:971
void * tail
End of data.
Definition: iobuf.h:46
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * priv
Pointer to private data.
Definition: net80211.h:672
int started
Whether start has been called.
Definition: net80211.h:665
int(* init)(struct net80211_device *dev)
Initialize security handshaking protocol.
Definition: net80211.h:585
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
struct net80211_crypto * crypto
802.11 cryptosystem for our current network
Definition: net80211.h:940
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void(* stop)(struct net80211_device *dev)
Stop security handshaking handlers.
Definition: net80211.h:650
struct net80211_crypto * gcrypto
802.11 cryptosystem for multicast and broadcast frames
Definition: net80211.h:951
#define ieee80211_beacon
Definition: ieee80211.h:1069
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:311
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define NET80211_HANDSHAKERS
Definition: net80211.h:675
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
static int net80211_process_capab(struct net80211_device *dev, u16 capab)
Update 802.11 device state to reflect received capabilities field.
Definition: net80211.c:1010
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
struct net80211_handshaker * handshaker
Security handshaker being used.
Definition: net80211.h:879
#define ETH_ALEN
Definition: if_ether.h:8
Interface to an 802.11 security handshaking protocol.
Definition: net80211.h:564
uint32_t hdr
Message header.
Definition: intelvf.h:12
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
int channel
The channel on which that access point communicates.
Definition: net80211.h:1078
struct net80211_device_operations * op
802.11 device operations
Definition: net80211.h:795
static void net80211_set_state(struct net80211_device *dev, short clear, short set, u16 status)
Set state of 802.11 device.
Definition: net80211.c:866
void * data
Start of data.
Definition: iobuf.h:44
#define NET80211_CFG_RATE
Requested transmission rate (dev->rate) has changed.
Definition: net80211.h:84
u8 bssid[ETH_ALEN]
MAC address of the strongest-signal access point for this ESSID.
Definition: net80211.h:1067
u8 bssid[ETH_ALEN]
MAC address of the access point most recently associated.
Definition: net80211.h:954
struct io_buffer * beacon
The complete beacon or probe-response frame received.
Definition: net80211.h:1081
int net80211_change_channel(struct net80211_device *dev, int channel)
Configure 802.11 device to transmit on a certain channel.
Definition: net80211.c:2021
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.
Definition: net80211.c:1044
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824

References assert(), net80211_wlan::beacon, net80211_device::bssid, net80211_wlan::bssid, net80211_wlan::channel, net80211_device_operations::config, net80211_device::crypto, io_buffer::data, DBGC, ENOMEM, ENOTSUP, net80211_device::essid, net80211_wlan::essid, ETH_ALEN, for_each_table_entry, free, net80211_device::gcrypto, net80211_device::handshaker, net80211_wlan::handshaking, hdr, ieee80211_beacon, net80211_handshaker::init, net80211_device::last_beacon_timestamp, memcpy(), NET80211_ASSOCIATED, NET80211_CFG_RATE, net80211_change_channel(), NET80211_HANDSHAKERS, net80211_process_capab(), net80211_process_ie(), NET80211_SECPROT_NONE, net80211_set_state(), net80211_device::netdev, netdev_is_open(), NULL, net80211_device::op, net80211_handshaker::priv, net80211_device::rate, rc, net80211_device::rsn_ie, net80211_handshaker::started, net80211_handshaker::stop, strcpy(), io_buffer::tail, net80211_device::tx_beacon_interval, and zalloc().

Referenced by net80211_step_associate().

◆ net80211_send_auth()

int net80211_send_auth ( struct net80211_device dev,
struct net80211_wlan wlan,
int  method 
)

Send 802.11 initial authentication frame.

Parameters
dev802.11 device
wlanWLAN to authenticate with
methodAuthentication method
Return values
rcReturn status code

method may be 0 for Open System authentication or 1 for Shared Key authentication. Open System provides no security in association whatsoever, relying on encryption for confidentiality, but Shared Key actively introduces security problems and is very rarely used.

Definition at line 2200 of file net80211.c.

2202 {
2203  struct io_buffer *iob = alloc_iob ( 64 );
2204  struct ieee80211_auth *auth;
2205 
2206  net80211_set_state ( dev, 0, NET80211_WAITING, 0 );
2208  auth = iob_put ( iob, sizeof ( *auth ) );
2209  auth->algorithm = method;
2210  auth->tx_seq = 1;
2211  auth->status = 0;
2212 
2213  return net80211_tx_mgmt ( dev, IEEE80211_STYPE_AUTH, wlan->bssid, iob );
2214 }
#define iob_put(iobuf, len)
Definition: iobuf.h:116
uint8_t method
Definition: ib_mad.h:14
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define IEEE80211_STYPE_AUTH
Subtype value for authentication management frames.
Definition: ieee80211.h:188
u16 tx_seq
Sequence number of this frame; first from client to AP is 1.
Definition: ieee80211.h:1144
u16 status
Status code.
Definition: ieee80211.h:1147
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1141
#define NET80211_WAITING
Whether the auto-association task is waiting for a reply from the AP.
Definition: net80211.h:215
#define iob_reserve(iobuf, len)
Definition: iobuf.h:63
Authentication frame data.
Definition: ieee80211.h:1138
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
static void net80211_set_state(struct net80211_device *dev, short clear, short set, u16 status)
Set state of 802.11 device.
Definition: net80211.c:866
u8 bssid[ETH_ALEN]
MAC address of the strongest-signal access point for this ESSID.
Definition: net80211.h:1067
A persistent I/O buffer.
Definition: iobuf.h:32

References ieee80211_auth::algorithm, alloc_iob(), net80211_wlan::bssid, IEEE80211_STYPE_AUTH, IEEE80211_TYP_FRAME_HEADER_LEN, iob_put, iob_reserve, method, net80211_set_state(), net80211_tx_mgmt(), NET80211_WAITING, ieee80211_auth::status, and ieee80211_auth::tx_seq.

Referenced by net80211_step_associate().

◆ net80211_send_assoc()

int net80211_send_assoc ( struct net80211_device dev,
struct net80211_wlan wlan 
)

Send 802.11 association frame.

Parameters
dev802.11 device
wlanWLAN to associate with
Return values
rcReturn status code

Definition at line 2287 of file net80211.c.

2289 {
2290  struct io_buffer *iob = alloc_iob ( 128 );
2291  struct ieee80211_assoc_req *assoc;
2292  union ieee80211_ie *ie;
2293 
2294  net80211_set_state ( dev, 0, NET80211_WAITING, 0 );
2295 
2297  assoc = iob->data;
2298 
2300  if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_PREAMBLE ) )
2302  if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_SLOT ) )
2304  if ( wlan->crypto )
2306 
2307  assoc->listen_interval = 1;
2308 
2309  ie = net80211_marshal_request_info ( dev, assoc->info_element );
2310 
2311  DBGP ( "802.11 %p about to send association request:\n", dev );
2312  DBGP_HD ( iob->data, ( void * ) ie - iob->data );
2313 
2314  iob_put ( iob, ( void * ) ie - iob->data );
2315 
2317  wlan->bssid, iob );
2318 }
#define DBGP_HD(...)
Definition: compiler.h:534
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 IEEE80211_CAPAB_SHORT_PMBL
Set if PHY supports short preambles on 802.11b.
Definition: ieee80211.h:404
#define IEEE80211_CAPAB_PRIVACY
Set if the network is encrypted (by any method)
Definition: ieee80211.h:401
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define DBGP(...)
Definition: compiler.h:532
#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
#define NET80211_WAITING
Whether the auto-association task is waiting for a reply from the AP.
Definition: net80211.h:215
u16 capability
Capability flags.
Definition: ieee80211.h:1086
struct net80211_hw_info * hw
Information about the hardware, provided to net80211_register()
Definition: net80211.h:801
#define IEEE80211_STYPE_ASSOC_REQ
Subtype value for association-request management frames.
Definition: ieee80211.h:118
Any 802.11 information element.
Definition: ieee80211.h:972
#define IEEE80211_CAPAB_SHORT_SLOT
Set if PHY supports short slot time on 802.11g.
Definition: ieee80211.h:419
#define iob_reserve(iobuf, len)
Definition: iobuf.h:63
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
static void net80211_set_state(struct net80211_device *dev, short clear, short set, u16 status)
Set state of 802.11 device.
Definition: net80211.c:866
#define IEEE80211_CAPAB_MANAGED
Set if using an Access Point (managed mode)
Definition: ieee80211.h:389
void * data
Start of data.
Definition: iobuf.h:44
Association request frame data.
Definition: ieee80211.h:1083
u8 bssid[ETH_ALEN]
MAC address of the strongest-signal access point for this ESSID.
Definition: net80211.h:1067
enum net80211_hw_info::@548 flags
A set of flags indicating peculiarities of this device.
union ieee80211_ie info_element[0]
List of information elements.
Definition: ieee80211.h:1092
u16 listen_interval
Interval at which we wake up, in units of the beacon interval.
Definition: ieee80211.h:1089
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), net80211_wlan::bssid, ieee80211_assoc_req::capability, net80211_wlan::crypto, io_buffer::data, DBGP, DBGP_HD, net80211_hw_info::flags, net80211_device::hw, IEEE80211_CAPAB_MANAGED, IEEE80211_CAPAB_PRIVACY, IEEE80211_CAPAB_SHORT_PMBL, IEEE80211_CAPAB_SHORT_SLOT, IEEE80211_STYPE_ASSOC_REQ, IEEE80211_TYP_FRAME_HEADER_LEN, ieee80211_assoc_req::info_element, iob_put, iob_reserve, ieee80211_assoc_req::listen_interval, net80211_marshal_request_info(), net80211_set_state(), net80211_tx_mgmt(), and NET80211_WAITING.

Referenced by net80211_step_associate().

◆ net80211_deauthenticate()

void net80211_deauthenticate ( struct net80211_device dev,
int  rc 
)

Deauthenticate from current network and try again.

Parameters
dev802.11 device
rcReturn status code indicating reason

The deauthentication will be sent using an 802.11 "unspecified reason", as is common, but rc will be set as a link-up error to aid the user in debugging.

Definition at line 2390 of file net80211.c.

2391 {
2393  dev->assoc_rc = rc;
2394  netdev_link_err ( dev->netdev, rc );
2395 
2396  net80211_autoassociate ( dev );
2397 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define IEEE80211_REASON_UNSPECIFIED
Definition: ieee80211.h:512
static int net80211_send_disassoc(struct net80211_device *dev, int reason, int deauth)
Send 802.11 disassociation frame.
Definition: net80211.c:2361
int assoc_rc
Return status code associated with state.
Definition: net80211.h:924
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:163
void net80211_autoassociate(struct net80211_device *dev)
Start 802.11 association process.
Definition: net80211.c:1929
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789

References net80211_device::assoc_rc, IEEE80211_REASON_UNSPECIFIED, net80211_autoassociate(), net80211_send_disassoc(), net80211_device::netdev, netdev_link_err(), and rc.

Referenced by wpa_fail(), and wpa_psk_start().