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

2108 {
2109  struct ieee80211_frame *hdr = wlan->beacon->data;
2110  struct ieee80211_beacon *beacon =
2111  ( struct ieee80211_beacon * ) hdr->data;
2112  struct net80211_handshaker *handshaker;
2113  int rc;
2114 
2115  assert ( netdev_is_open ( dev->netdev ) );
2116 
2117  net80211_set_state ( dev, NET80211_ASSOCIATED, 0, 0 );
2118  memcpy ( dev->bssid, wlan->bssid, ETH_ALEN );
2119  strcpy ( dev->essid, wlan->essid );
2120 
2121  free ( dev->rsn_ie );
2122  dev->rsn_ie = NULL;
2123 
2124  dev->last_beacon_timestamp = beacon->timestamp;
2125  dev->tx_beacon_interval = 1024 * beacon->beacon_interval;
2126 
2127  /* Barring an IE that tells us the channel outright, assume
2128  the channel we heard this AP best on is the channel it's
2129  communicating on. */
2130  net80211_change_channel ( dev, wlan->channel );
2131 
2132  rc = net80211_process_capab ( dev, beacon->capability );
2133  if ( rc )
2134  return rc;
2135 
2136  rc = net80211_process_ie ( dev, beacon->info_element,
2137  wlan->beacon->tail );
2138  if ( rc )
2139  return rc;
2140 
2141  /* Associate at the lowest rate so we know it'll get through */
2142  dev->rate = 0;
2143  dev->op->config ( dev, NET80211_CFG_RATE );
2144 
2145  /* Free old handshaker and crypto, if they exist */
2146  if ( dev->handshaker && dev->handshaker->stop &&
2147  dev->handshaker->started )
2148  dev->handshaker->stop ( dev );
2149  free ( dev->handshaker );
2150  dev->handshaker = NULL;
2151  free ( dev->crypto );
2152  free ( dev->gcrypto );
2153  dev->crypto = dev->gcrypto = NULL;
2154 
2155  /* Find new security handshaker to use */
2156  for_each_table_entry ( handshaker, NET80211_HANDSHAKERS ) {
2157  if ( handshaker->protocol == wlan->handshaking ) {
2158  dev->handshaker = zalloc ( sizeof ( *handshaker ) +
2159  handshaker->priv_len );
2160  if ( ! dev->handshaker )
2161  return -ENOMEM;
2162 
2163  memcpy ( dev->handshaker, handshaker,
2164  sizeof ( *handshaker ) );
2165  dev->handshaker->priv = ( ( void * ) dev->handshaker +
2166  sizeof ( *handshaker ) );
2167  break;
2168  }
2169  }
2170 
2171  if ( ( wlan->handshaking != NET80211_SECPROT_NONE ) &&
2172  ! dev->handshaker ) {
2173  DBGC ( dev, "802.11 %p no support for handshaking scheme %d\n",
2174  dev, wlan->handshaking );
2175  return -( ENOTSUP | ( wlan->handshaking << 8 ) );
2176  }
2177 
2178  /* Initialize security handshaker */
2179  if ( dev->handshaker ) {
2180  rc = dev->handshaker->init ( dev );
2181  if ( rc < 0 )
2182  return rc;
2183  }
2184 
2185  return 0;
2186 }
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
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
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:590
u32 tx_beacon_interval
Time between AP sending beacons, microseconds.
Definition: net80211.h:971
void * tail
End of data.
Definition: iobuf.h:55
#define ENOMEM
Not enough space.
Definition: errno.h:535
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:662
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:347
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#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:1011
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
struct net80211_handshaker * handshaker
Security handshaker being used.
Definition: net80211.h:879
#define ETH_ALEN
Definition: if_ether.h:9
Interface to an 802.11 security handshaking protocol.
Definition: net80211.h:564
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:867
void * data
Start of data.
Definition: iobuf.h:53
#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:2022
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:1045
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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 2201 of file net80211.c.

2203 {
2204  struct io_buffer *iob = alloc_iob ( 64 );
2205  struct ieee80211_auth *auth;
2206 
2207  net80211_set_state ( dev, 0, NET80211_WAITING, 0 );
2209  auth = iob_put ( iob, sizeof ( *auth ) );
2210  auth->algorithm = method;
2211  auth->tx_seq = 1;
2212  auth->status = 0;
2213 
2214  return net80211_tx_mgmt ( dev, IEEE80211_STYPE_AUTH, wlan->bssid, iob );
2215 }
#define iob_put(iobuf, len)
Definition: iobuf.h:125
uint8_t method
Definition: ib_mad.h:15
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#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:72
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:707
static void net80211_set_state(struct net80211_device *dev, short clear, short set, u16 status)
Set state of 802.11 device.
Definition: net80211.c:867
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:38

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

2290 {
2291  struct io_buffer *iob = alloc_iob ( 128 );
2292  struct ieee80211_assoc_req *assoc;
2293  union ieee80211_ie *ie;
2294 
2295  net80211_set_state ( dev, 0, NET80211_WAITING, 0 );
2296 
2298  assoc = iob->data;
2299 
2301  if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_PREAMBLE ) )
2303  if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_SLOT ) )
2305  if ( wlan->crypto )
2307 
2308  assoc->listen_interval = 1;
2309 
2310  ie = net80211_marshal_request_info ( dev, assoc->info_element );
2311 
2312  DBGP ( "802.11 %p about to send association request:\n", dev );
2313  DBGP_HD ( iob->data, ( void * ) ie - iob->data );
2314 
2315  iob_put ( iob, ( void * ) ie - iob->data );
2316 
2318  wlan->bssid, iob );
2319 }
#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:125
#define IEEE80211_CAPAB_SHORT_PMBL
Set if PHY supports short preambles on 802.11b.
Definition: ieee80211.h:404
enum net80211_hw_info::@641 flags
A set of flags indicating peculiarities of this device.
#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:131
#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:1203
#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:72
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:707
static void net80211_set_state(struct net80211_device *dev, short clear, short set, u16 status)
Set state of 802.11 device.
Definition: net80211.c:867
#define IEEE80211_CAPAB_MANAGED
Set if using an Access Point (managed mode)
Definition: ieee80211.h:389
void * data
Start of data.
Definition: iobuf.h:53
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
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:38

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

2392 {
2394  dev->assoc_rc = rc;
2395  netdev_link_err ( dev->netdev, rc );
2396 
2397  net80211_autoassociate ( dev );
2398 }
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:2362
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:208
void net80211_autoassociate(struct net80211_device *dev)
Start 802.11 association process.
Definition: net80211.c:1930
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().