iPXE
sec80211.h File Reference

Definitions for general secured-network routines. More...

#include <ipxe/net80211.h>
#include <errno.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int sec80211_detect (struct io_buffer *iob, enum net80211_security_proto *secprot, enum net80211_crypto_alg *crypt)
 Detect the cryptosystem and handshaking protocol used by an 802.11 network.
int sec80211_detect_ie (int is_rsn, u8 *start, u8 *end, enum net80211_security_proto *secprot, enum net80211_crypto_alg *crypt)
 Find the RSN or WPA information element in the provided beacon frame.
u8sec80211_find_rsn (union ieee80211_ie *ie, void *ie_end, int *is_rsn, u8 **end)
int sec80211_install (struct net80211_crypto **which, enum net80211_crypto_alg crypt, const void *key, int len, const void *rsc)
 Install 802.11 cryptosystem.
u32 sec80211_rsn_get_crypto_desc (enum net80211_crypto_alg crypt, int rsnie)
 Determine RSN descriptor for specified net80211 cryptosystem number.
u32 sec80211_rsn_get_akm_desc (enum net80211_security_proto secprot, int rsnie)
 Determine RSN descriptor for specified net80211 handshaker number.
enum net80211_crypto_alg sec80211_rsn_get_net80211_crypt (u32 desc)
 Determine net80211 cryptosystem number from RSN descriptor.

Detailed Description

Definitions for general secured-network routines.

Definition in file sec80211.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

References end, start, and u8.

◆ sec80211_detect()

int sec80211_detect ( struct io_buffer * iob,
enum net80211_security_proto * secprot,
enum net80211_crypto_alg * crypt )

Detect the cryptosystem and handshaking protocol used by an 802.11 network.

@v iob I/O buffer containing beacon frame @ret secprot Security handshaking protocol used by network @ret crypt Cryptosystem used by network @ret rc Return status code

This function uses weak linkage, as it must be called from generic contexts but should only be linked in if some encryption is supported; you must test its address against NULL before calling it. If it does not exist, any network with the PRIVACY bit set in beacon->capab should be considered unknown.

Definition at line 407 of file sec80211.c.

410{
411 struct ieee80211_frame *hdr = iob->data;
412 struct ieee80211_beacon *beacon =
413 ( struct ieee80211_beacon * ) hdr->data;
414 u8 *rsn, *rsn_end;
415 int is_rsn, rc;
416
417 *crypt = NET80211_CRYPT_UNKNOWN;
418 *secprot = NET80211_SECPROT_UNKNOWN;
419
420 /* Find RSN or WPA IE */
421 if ( ! ( rsn = sec80211_find_rsn ( beacon->info_element, iob->tail,
422 &is_rsn, &rsn_end ) ) ) {
423 /* No security IE at all; either WEP or no security. */
424 *secprot = NET80211_SECPROT_NONE;
425
426 if ( beacon->capability & IEEE80211_CAPAB_PRIVACY )
427 *crypt = NET80211_CRYPT_WEP;
428 else
429 *crypt = NET80211_CRYPT_NONE;
430
431 return 0;
432 }
433
434 /* Determine type of security */
435 if ( ( rc = sec80211_detect_ie ( is_rsn, rsn, rsn_end, secprot,
436 crypt ) ) == 0 )
437 return 0;
438
439 /* If we get here, the RSN IE was invalid */
440
441 *crypt = NET80211_CRYPT_UNKNOWN;
442 *secprot = NET80211_SECPROT_UNKNOWN;
443 DBG ( "Failed to handle RSN IE:\n" );
444 DBG_HD ( rsn, rsn_end - rsn );
445 return rc;
446}
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBG_HD(...)
Definition compiler.h:525
#define DBG(...)
Print a debugging message.
Definition compiler.h:523
#define IEEE80211_CAPAB_PRIVACY
Set if the network is encrypted (by any method).
Definition ieee80211.h:401
#define ieee80211_beacon
Definition ieee80211.h:1069
#define u8
Definition igbvf_osdep.h:40
@ NET80211_SECPROT_UNKNOWN
Dummy value used when the handshaking type can't be detected.
Definition net80211.h:124
@ NET80211_SECPROT_NONE
No security handshaking.
Definition net80211.h:102
@ NET80211_CRYPT_NONE
No security, an "Open" network.
Definition net80211.h:131
@ NET80211_CRYPT_UNKNOWN
Dummy value used when the cryptosystem can't be detected.
Definition net80211.h:177
@ NET80211_CRYPT_WEP
Network protected with WEP (awful RC4-based system).
Definition net80211.h:145
int sec80211_detect_ie(int is_rsn, u8 *start, u8 *end, enum net80211_security_proto *secprot, enum net80211_crypto_alg *crypt)
Find the RSN or WPA information element in the provided beacon frame.
Definition sec80211.c:341
u8 * sec80211_find_rsn(union ieee80211_ie *ie, void *ie_end, int *is_rsn, u8 **end)
An 802.11 data or management frame without QoS or WDS header fields.
Definition ieee80211.h:301
void * data
Start of data.
Definition iobuf.h:113
void * tail
End of data.
Definition iobuf.h:115

References io_buffer::data, DBG, DBG_HD, hdr, ieee80211_beacon, IEEE80211_CAPAB_PRIVACY, NET80211_CRYPT_NONE, NET80211_CRYPT_UNKNOWN, NET80211_CRYPT_WEP, NET80211_SECPROT_NONE, NET80211_SECPROT_UNKNOWN, rc, sec80211_detect_ie(), sec80211_find_rsn(), io_buffer::tail, and u8.

◆ sec80211_detect_ie()

int sec80211_detect_ie ( int is_rsn,
u8 * start,
u8 * end,
enum net80211_security_proto * secprot,
enum net80211_crypto_alg * crypt )

Find the RSN or WPA information element in the provided beacon frame.

Parameters
iePointer to first information element to check
ie_endPointer to end of information element space
Return values
is_rsnTRUE if returned IE is RSN, FALSE if it's WPA
endPointer to byte immediately after last byte of data
dataPointer to first byte of data (the `version' field)

If both an RSN and a WPA information element are found, this function will return the first one seen, which by ordering rules should always prefer the newer RSN IE.

If no RSN or WPA infomration element is found, returns NULL and leaves is_rsn and end in an undefined state.

This function will not return a pointer to an information element that states it extends past the tail of the io_buffer, or whose version field is incorrect. */ u8 * sec80211_find_rsn ( union ieee80211_ie *ie, void *ie_end, int *is_rsn, u8 **end ) { u8 *rsn = NULL;

if ( ! ieee80211_ie_bound ( ie, ie_end ) ) return NULL;

while ( ie ) { if ( ie->id == IEEE80211_IE_VENDOR && ie->vendor.oui == IEEE80211_WPA_OUI_VEN ) { DBG ( "RSN detect: old-style WPA IE found\n" ); rsn = &ie->vendor.data[0]; end = rsn + ie->len - 4; is_rsn = 0; } else if ( ie->id == IEEE80211_IE_RSN ) { DBG ( "RSN detect: 802.11i RSN IE found\n" ); rsn = ( u8 * ) &ie->rsn.version; end = rsn + ie->len; is_rsn = 1; }

if ( rsn && ( *end > ( u8 * ) ie_end || rsn >= *end || ( u16 * ) rsn != IEEE80211_RSN_VERSION ) ) { DBG ( "RSN detect: malformed RSN IE or unknown " "version, keep trying\n" ); rsn = NULL; }

if ( rsn ) break;

ie = ieee80211_next_ie ( ie, ie_end ); }

if ( ! ie ) { DBG ( "RSN detect: no RSN IE found\n" ); return NULL; }

return rsn; }

/** Detect crypto and AKM types from RSN information element

@v is_rsn If TRUE, IE is a new-style RSN information element @v start Pointer to first byte of version field @v end Pointer to first byte not in the RSN IE @ret secprot Security handshaking protocol used by network @ret crypt Cryptosystem used by network @ret rc Return status code

If the IE cannot be parsed, returns an error indication and leaves secprot and crypt unchanged.

Definition at line 341 of file sec80211.c.

344{
347 struct descriptor_map *map;
348 u8 *rsn = start;
349
350 /* Set some defaults */
353
354 rsn += 2; /* version - already checked */
355 rsn += 4; /* group cipher - we don't use it here */
356
357 if ( rsn >= end )
358 goto done;
359
360 /* Pick crypto algorithm */
364 if ( ! map )
365 goto invalid_rsn;
366
367 cr = map->net80211_type;
368
369 if ( rsn >= end )
370 goto done;
371
372 /* Pick handshaking algorithm */
373 map = rsn_pick_desc ( &rsn, end, rsn_akm_map,
376 if ( ! map )
377 goto invalid_rsn;
378
379 sp = map->net80211_type;
380
381 done:
382 DBG ( "RSN detect: OK, crypto type %d, secprot type %d\n", cr, sp );
383 *secprot = sp;
384 *crypt = cr;
385 return 0;
386
387 invalid_rsn:
388 DBG ( "RSN detect: invalid RSN IE\n" );
389 return -EINVAL;
390}
struct bofm_section_header done
Definition bofm_test.c:46
uint32_t start
Starting offset.
Definition netvsc.h:1
#define EINVAL
Invalid argument.
Definition errno.h:472
static __always_inline int struct dma_mapping * map
Definition dma.h:184
net80211_security_proto
An 802.11 security handshaking protocol.
Definition net80211.h:96
@ NET80211_SECPROT_EAP
Full EAP 802.1X handshaking.
Definition net80211.h:121
net80211_crypto_alg
An 802.11 data encryption algorithm.
Definition net80211.h:129
@ NET80211_CRYPT_CCMP
Network protected with CCMP (AES-based system).
Definition net80211.h:174
@ NET80211_CRYPT_TKIP
Network protected with TKIP (better RC4-based system).
Definition net80211.h:163
#define NET80211_CRYPTOS
Definition net80211.h:769
#define NET80211_HANDSHAKERS
Definition net80211.h:675
uint32_t end
Ending offset.
Definition netvsc.h:7
uint16_t sp
Definition registers.h:13
static struct descriptor_map rsn_akm_map[]
Mapping between net80211 handshakers and 802.11i AKM IDs.
Definition sec80211.c:84
static struct descriptor_map rsn_cipher_map[]
Mapping between net80211 cryptosystems and 802.11i cipher IDs.
Definition sec80211.c:66
static struct descriptor_map * rsn_pick_desc(u8 **rsnp, u8 *rsn_end, struct descriptor_map *map, void *tbl_start, void *tbl_end)
Determine net80211 crypto or handshaking type value to return for RSN info.
Definition sec80211.c:187
@ cr
Definition sis900.h:22
Mapping from net80211 crypto/secprot types to RSN OUI descriptors.
Definition sec80211.c:54
#define table_end(table)
Get end of linker table.
Definition tables.h:309
#define table_start(table)
Get start of linker table.
Definition tables.h:283

References cr, DBG, done, EINVAL, end, map, NET80211_CRYPT_CCMP, NET80211_CRYPT_TKIP, NET80211_CRYPTOS, NET80211_HANDSHAKERS, NET80211_SECPROT_EAP, rsn_akm_map, rsn_cipher_map, rsn_pick_desc(), sp, start, table_end, table_start, and u8.

Referenced by sec80211_detect(), and wpa_handle_3_of_4().

◆ sec80211_find_rsn()

u8 * sec80211_find_rsn ( union ieee80211_ie * ie,
void * ie_end,
int * is_rsn,
u8 ** end )

◆ sec80211_install()

int sec80211_install ( struct net80211_crypto ** which,
enum net80211_crypto_alg crypt,
const void * key,
int len,
const void * rsc )

Install 802.11 cryptosystem.

Parameters
whichPointer to the cryptosystem structure to install in
cryptCryptosystem ID number
keyEncryption key to use
lenLength of encryption key
rscInitial receive sequence counter, if applicable
Return values
rcReturn status code

The encryption key will not be accessed via the provided pointer after this function returns, so you may keep it on the stack.

which must point to either dev->crypto (for the normal case of installing a unicast cryptosystem) or dev->gcrypto (to install a cryptosystem that will be used only for decrypting group-source frames).

Definition at line 114 of file sec80211.c.

117{
118 struct net80211_crypto *crypto = *which;
119 struct net80211_crypto *tbl_crypto;
120
121 /* Remove old crypto if it exists */
122 free ( *which );
123 *which = NULL;
124
125 if ( crypt == NET80211_CRYPT_NONE ) {
126 DBG ( "802.11-Sec not installing null cryptography\n" );
127 return 0;
128 }
129
130 /* Find cryptosystem to use */
131 for_each_table_entry ( tbl_crypto, NET80211_CRYPTOS ) {
132 if ( tbl_crypto->algorithm == crypt ) {
133 crypto = zalloc ( sizeof ( *crypto ) +
134 tbl_crypto->priv_len );
135 if ( ! crypto ) {
136 DBG ( "802.11-Sec out of memory\n" );
137 return -ENOMEM;
138 }
139
140 memcpy ( crypto, tbl_crypto, sizeof ( *crypto ) );
141 crypto->priv = ( ( void * ) crypto +
142 sizeof ( *crypto ) );
143 break;
144 }
145 }
146
147 if ( ! crypto ) {
148 DBG ( "802.11-Sec no support for cryptosystem %d\n", crypt );
149 return -ENOTSUP_CRYPT ( crypt );
150 }
151
152 *which = crypto;
153
154 DBG ( "802.11-Sec installing cryptosystem %d as %p with key of "
155 "length %d\n", crypt, crypto, len );
156
157 return crypto->init ( crypto, key, len, rsc );
158}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
union @162305117151260234136356364136041353210355154177 key
ring len
Length.
Definition dwmac.h:226
#define ENOMEM
Not enough space.
Definition errno.h:578
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define ENOTSUP_CRYPT(crypt)
Definition sec80211.c:49
Interface to an 802.11 cryptosystem.
Definition net80211.h:690
void * priv
Private data for the algorithm to store key and state info.
Definition net80211.h:766
enum net80211_crypto_alg algorithm
The cryptographic algorithm implemented.
Definition net80211.h:692
int(* init)(struct net80211_crypto *crypto, const void *key, int keylen, const void *rsc)
Initialize cryptosystem using a given key.
Definition net80211.h:707
int priv_len
Length of private data requested to be allocated.
Definition net80211.h:763
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386
u8 rsc[8]
Receive sequence counter for GTK.
Definition wpa.h:42

References net80211_crypto::algorithm, DBG, ENOMEM, ENOTSUP_CRYPT, for_each_table_entry, free, net80211_crypto::init, key, len, memcpy(), NET80211_CRYPT_NONE, NET80211_CRYPTOS, NULL, net80211_crypto::priv, net80211_crypto::priv_len, rsc, and zalloc().

Referenced by trivial_init(), wpa_install_gtk(), and wpa_install_ptk().

◆ sec80211_rsn_get_crypto_desc()

u32 sec80211_rsn_get_crypto_desc ( enum net80211_crypto_alg crypt,
int rsnie )

Determine RSN descriptor for specified net80211 cryptosystem number.

@v crypt Cryptosystem number @v rsnie Whether to return a new-format (RSN IE) descriptor @ret desc RSN descriptor

If rsnie is false, returns an old-format (WPA vendor IE) descriptor.

Definition at line 482 of file sec80211.c.

483{
484 return rsn_get_desc ( crypt, rsnie, rsn_cipher_map );
485}
static u32 rsn_get_desc(unsigned id, int rsnie, struct descriptor_map *map)
Determine RSN descriptor for specified net80211 ID.
Definition sec80211.c:460

References rsn_cipher_map, rsn_get_desc(), and u32.

Referenced by wpa_make_rsn_ie().

◆ sec80211_rsn_get_akm_desc()

u32 sec80211_rsn_get_akm_desc ( enum net80211_security_proto secprot,
int rsnie )

Determine RSN descriptor for specified net80211 handshaker number.

@v secprot Handshaker number @v rsnie Whether to return a new-format (RSN IE) descriptor @ret desc RSN descriptor

If rsnie is false, returns an old-format (WPA vendor IE) descriptor.

Definition at line 497 of file sec80211.c.

499{
500 return rsn_get_desc ( secprot, rsnie, rsn_akm_map );
501}

References rsn_akm_map, rsn_get_desc(), and u32.

Referenced by wpa_make_rsn_ie().

◆ sec80211_rsn_get_net80211_crypt()

enum net80211_crypto_alg sec80211_rsn_get_net80211_crypt ( u32 desc)

Determine net80211 cryptosystem number from RSN descriptor.

@v desc RSN descriptor @ret crypt net80211 cryptosystem enumeration value

Definition at line 509 of file sec80211.c.

510{
512
513 for ( ; map->oui_type != END_MAGIC; map++ ) {
514 if ( map->oui_type == ( desc & OUI_TYPE_MASK ) )
515 break;
516 }
517
518 return map->net80211_type;
519}
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define OUI_TYPE_MASK
Definition ieee80211.h:854
#define END_MAGIC
Magic number in oui_type showing end of list.
Definition sec80211.c:63

References desc, END_MAGIC, map, OUI_TYPE_MASK, rsn_cipher_map, and u32.

Referenced by wpa_handle_3_of_4(), and wpa_make_rsn_ie().