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

Function Documentation

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.

References assert, net80211_wlan::beacon, net80211_device::bssid, net80211_wlan::bssid, net80211_wlan::channel, net80211_device_operations::config, net80211_device::crypto, io_buffer::data, ieee80211_frame::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().

{
        struct ieee80211_frame *hdr = wlan->beacon->data;
        struct ieee80211_beacon *beacon =
                ( struct ieee80211_beacon * ) hdr->data;
        struct net80211_handshaker *handshaker;
        int rc;

        assert ( netdev_is_open ( dev->netdev ) );

        net80211_set_state ( dev, NET80211_ASSOCIATED, 0, 0 );
        memcpy ( dev->bssid, wlan->bssid, ETH_ALEN );
        strcpy ( dev->essid, wlan->essid );

        free ( dev->rsn_ie );
        dev->rsn_ie = NULL;

        dev->last_beacon_timestamp = beacon->timestamp;
        dev->tx_beacon_interval = 1024 * beacon->beacon_interval;

        /* Barring an IE that tells us the channel outright, assume
           the channel we heard this AP best on is the channel it's
           communicating on. */
        net80211_change_channel ( dev, wlan->channel );

        rc = net80211_process_capab ( dev, beacon->capability );
        if ( rc )
                return rc;

        rc = net80211_process_ie ( dev, beacon->info_element,
                                   wlan->beacon->tail );
        if ( rc )
                return rc;

        /* Associate at the lowest rate so we know it'll get through */
        dev->rate = 0;
        dev->op->config ( dev, NET80211_CFG_RATE );

        /* Free old handshaker and crypto, if they exist */
        if ( dev->handshaker && dev->handshaker->stop &&
             dev->handshaker->started )
                dev->handshaker->stop ( dev );
        free ( dev->handshaker );
        dev->handshaker = NULL;
        free ( dev->crypto );
        free ( dev->gcrypto );
        dev->crypto = dev->gcrypto = NULL;

        /* Find new security handshaker to use */
        for_each_table_entry ( handshaker, NET80211_HANDSHAKERS ) {
                if ( handshaker->protocol == wlan->handshaking ) {
                        dev->handshaker = zalloc ( sizeof ( *handshaker ) +
                                                   handshaker->priv_len );
                        if ( ! dev->handshaker )
                                return -ENOMEM;

                        memcpy ( dev->handshaker, handshaker,
                                 sizeof ( *handshaker ) );
                        dev->handshaker->priv = ( ( void * ) dev->handshaker +
                                                  sizeof ( *handshaker ) );
                        break;
                }
        }

        if ( ( wlan->handshaking != NET80211_SECPROT_NONE ) &&
             ! dev->handshaker ) {
                DBGC ( dev, "802.11 %p no support for handshaking scheme %d\n",
                       dev, wlan->handshaking );
                return -( ENOTSUP | ( wlan->handshaking << 8 ) );
        }

        /* Initialize security handshaker */
        if ( dev->handshaker ) {
                rc = dev->handshaker->init ( dev );
                if ( rc < 0 )
                        return rc;
        }

        return 0;
}
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.

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

{
        struct io_buffer *iob = alloc_iob ( 64 );
        struct ieee80211_auth *auth;

        net80211_set_state ( dev, 0, NET80211_WAITING, 0 );
        iob_reserve ( iob, IEEE80211_TYP_FRAME_HEADER_LEN );
        auth = iob_put ( iob, sizeof ( *auth ) );
        auth->algorithm = method;
        auth->tx_seq = 1;
        auth->status = 0;

        return net80211_tx_mgmt ( dev, IEEE80211_STYPE_AUTH, wlan->bssid, iob );
}
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.

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

{
        struct io_buffer *iob = alloc_iob ( 128 );
        struct ieee80211_assoc_req *assoc;
        union ieee80211_ie *ie;

        net80211_set_state ( dev, 0, NET80211_WAITING, 0 );

        iob_reserve ( iob, IEEE80211_TYP_FRAME_HEADER_LEN );
        assoc = iob->data;

        assoc->capability = IEEE80211_CAPAB_MANAGED;
        if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_PREAMBLE ) )
                assoc->capability |= IEEE80211_CAPAB_SHORT_PMBL;
        if ( ! ( dev->hw->flags & NET80211_HW_NO_SHORT_SLOT ) )
                assoc->capability |= IEEE80211_CAPAB_SHORT_SLOT;
        if ( wlan->crypto )
                assoc->capability |= IEEE80211_CAPAB_PRIVACY;

        assoc->listen_interval = 1;

        ie = net80211_marshal_request_info ( dev, assoc->info_element );

        DBGP ( "802.11 %p about to send association request:\n", dev );
        DBGP_HD ( iob->data, ( void * ) ie - iob->data );

        iob_put ( iob, ( void * ) ie - iob->data );

        return net80211_tx_mgmt ( dev, IEEE80211_STYPE_ASSOC_REQ,
                                  wlan->bssid, iob );
}
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.

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