iPXE
ath.h File Reference
#include <unistd.h>
#include <string.h>
#include <ipxe/net80211.h>

Go to the source code of this file.

Data Structures

struct  ath_ani
struct  ath_cycle_counters
struct  reg_dmn_pair_mapping
struct  ath_regulatory
struct  ath_keyval
struct  ath_ops
 struct ath_ops - Register read/write operations More...
struct  ath_common

Macros

#define DIV_ROUND_UP(n, d)
#define BITS_PER_BYTE   8
#define BITS_TO_LONGS(nr)
#define BIT(nr)
#define min(x, y)
#define max(x, y)
#define abs(x)
#define ___constant_swab16(x)
#define ___constant_swab32(x)
#define __swab16(x)
#define __swab32(x)
#define swab16   __swab16
#define swab32   __swab32
#define ATH_KEYMAX   128 /* max key cache size we handle */

Enumerations

enum  ath_device_state { ATH_HW_UNAVAILABLE , ATH_HW_INITIALIZED }
enum  ath_bus_type { ATH_PCI , ATH_AHB , ATH_USB }
enum  ath_crypt_caps { ATH_CRYPT_CAP_CIPHER_AESCCM = BIT(0) , ATH_CRYPT_CAP_MIC_COMBINED = BIT(1) }
enum  ath_cipher {
  ATH_CIPHER_WEP = 0 , ATH_CIPHER_AES_OCB = 1 , ATH_CIPHER_AES_CCM = 2 , ATH_CIPHER_CKIP = 3 ,
  ATH_CIPHER_TKIP = 4 , ATH_CIPHER_CLR = 5 , ATH_CIPHER_MIC = 127
}

Functions

 FILE_LICENCE (BSD2)
 FILE_SECBOOT (FORBIDDEN)
static int32_t sign_extend32 (uint32_t value, int index)
static u16 __get_unaligned_le16 (const u8 *p)
static u32 __get_unaligned_le32 (const u8 *p)
static u16 get_unaligned_le16 (const void *p)
static u32 get_unaligned_le32 (const void *p)
void ath_hw_setbssidmask (struct ath_common *common)
 ath_hw_set_bssid_mask - filter out bssids we listen
int ath_hw_keyreset (struct ath_common *common, u16 entry)
void ath_hw_cycle_counters_update (struct ath_common *common)
 ath_hw_cycle_counters_update - common function to update cycle counters
int32_t ath_hw_get_listen_time (struct ath_common *common)

Macro Definition Documentation

◆ DIV_ROUND_UP

#define DIV_ROUND_UP ( n,
d )
Value:
(((n) + (d) - 1) / (d))

Definition at line 31 of file ath.h.

Referenced by ath9k_hw_computetxtime().

◆ BITS_PER_BYTE

#define BITS_PER_BYTE   8

Definition at line 32 of file ath.h.

◆ BITS_TO_LONGS

#define BITS_TO_LONGS ( nr)
Value:
DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#define BITS_PER_BYTE
Definition ath.h:32
#define DIV_ROUND_UP(n, d)
Definition ath.h:31

Definition at line 33 of file ath.h.

◆ BIT

◆ min

◆ max

◆ abs

#define abs ( x)
Value:
({ \
long ret; \
if (sizeof(x) == sizeof(long)) { \
long __x = (x); \
ret = (__x < 0) ? -__x : __x; \
} else { \
int __x = (x); \
ret = (__x < 0) ? -__x : __x; \
} \
ret; \
})

Definition at line 46 of file ath.h.

46#define abs(x) ({ \
47 long ret; \
48 if (sizeof(x) == sizeof(long)) { \
49 long __x = (x); \
50 ret = (__x < 0) ? -__x : __x; \
51 } else { \
52 int __x = (x); \
53 ret = (__x < 0) ? -__x : __x; \
54 } \
55 ret; \
56 })

Referenced by ar5008_hw_spur_mitigate(), ar9002_hw_spur_mitigate(), ar9003_hw_detect_outlier(), ar9003_hw_find_mag_approx(), ar9003_hw_spur_mitigate_ofdm(), ath9k_hw_ar9300_set_txpower(), and png_paeth_predictor().

◆ ___constant_swab16

#define ___constant_swab16 ( x)
Value:
((uint16_t)( \
(((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
(((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
unsigned short uint16_t
Definition stdint.h:11

Definition at line 58 of file ath.h.

58#define ___constant_swab16(x) ((uint16_t)( \
59 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
60 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))

◆ ___constant_swab32

#define ___constant_swab32 ( x)
Value:
((uint32_t)( \
(((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
unsigned int uint32_t
Definition stdint.h:12

Definition at line 61 of file ath.h.

61#define ___constant_swab32(x) ((uint32_t)( \
62 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
63 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
64 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
65 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))

◆ __swab16

#define __swab16 ( x)
Value:
#define ___constant_swab16(x)
Definition ath.h:58

Definition at line 66 of file ath.h.

◆ __swab32

#define __swab32 ( x)
Value:
#define ___constant_swab32(x)
Definition ath.h:61

Definition at line 67 of file ath.h.

◆ swab16

#define swab16   __swab16

◆ swab32

#define swab32   __swab32

◆ ATH_KEYMAX

#define ATH_KEYMAX   128 /* max key cache size we handle */

Definition at line 103 of file ath.h.

Enumeration Type Documentation

◆ ath_device_state

Enumerator
ATH_HW_UNAVAILABLE 
ATH_HW_INITIALIZED 

Definition at line 121 of file ath.h.

121 {
124};
@ ATH_HW_INITIALIZED
Definition ath.h:123
@ ATH_HW_UNAVAILABLE
Definition ath.h:122

◆ ath_bus_type

Enumerator
ATH_PCI 
ATH_AHB 
ATH_USB 

Definition at line 126 of file ath.h.

126 {
127 ATH_PCI,
128 ATH_AHB,
129 ATH_USB,
130};
@ ATH_USB
Definition ath.h:129
@ ATH_AHB
Definition ath.h:128
@ ATH_PCI
Definition ath.h:127

◆ ath_crypt_caps

Enumerator
ATH_CRYPT_CAP_CIPHER_AESCCM 
ATH_CRYPT_CAP_MIC_COMBINED 

Definition at line 149 of file ath.h.

149 {
152};
#define BIT(nr)
Definition ath.h:34
@ ATH_CRYPT_CAP_MIC_COMBINED
Definition ath.h:151
@ ATH_CRYPT_CAP_CIPHER_AESCCM
Definition ath.h:150

◆ ath_cipher

enum ath_cipher
Enumerator
ATH_CIPHER_WEP 
ATH_CIPHER_AES_OCB 
ATH_CIPHER_AES_CCM 
ATH_CIPHER_CKIP 
ATH_CIPHER_TKIP 
ATH_CIPHER_CLR 
ATH_CIPHER_MIC 

Definition at line 165 of file ath.h.

165 {
166 ATH_CIPHER_WEP = 0,
169 ATH_CIPHER_CKIP = 3,
170 ATH_CIPHER_TKIP = 4,
171 ATH_CIPHER_CLR = 5,
172 ATH_CIPHER_MIC = 127
173};
@ ATH_CIPHER_TKIP
Definition ath.h:170
@ ATH_CIPHER_CLR
Definition ath.h:171
@ ATH_CIPHER_AES_OCB
Definition ath.h:167
@ ATH_CIPHER_AES_CCM
Definition ath.h:168
@ ATH_CIPHER_WEP
Definition ath.h:166
@ ATH_CIPHER_CKIP
Definition ath.h:169
@ ATH_CIPHER_MIC
Definition ath.h:172

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( BSD2 )

◆ FILE_SECBOOT()

FILE_SECBOOT ( FORBIDDEN )

◆ sign_extend32()

int32_t sign_extend32 ( uint32_t value,
int index )
inlinestatic

Definition at line 71 of file ath.h.

72{
73 uint8_t shift = 31 - index;
74 return (int32_t)(value << shift) >> shift;
75}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
signed int int32_t
Definition stdint.h:17
unsigned char uint8_t
Definition stdint.h:10
long index
Definition bigint.h:65

References index, and value.

Referenced by ar5008_hw_do_getnf(), ar9002_hw_do_getnf(), and ar9003_hw_do_getnf().

◆ __get_unaligned_le16()

u16 __get_unaligned_le16 ( const u8 * p)
inlinestatic

Definition at line 77 of file ath.h.

78{
79 return p[0] | p[1] << 8;
80}

References u16, and u8.

Referenced by get_unaligned_le16().

◆ __get_unaligned_le32()

u32 __get_unaligned_le32 ( const u8 * p)
inlinestatic

Definition at line 81 of file ath.h.

82{
83 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
84}

References u32, and u8.

Referenced by get_unaligned_le32().

◆ get_unaligned_le16()

u16 get_unaligned_le16 ( const void * p)
inlinestatic

Definition at line 85 of file ath.h.

86{
87 return __get_unaligned_le16((const u8 *)p);
88}
static u16 __get_unaligned_le16(const u8 *p)
Definition ath.h:77
#define u8
Definition igbvf_osdep.h:40

References __get_unaligned_le16(), u16, and u8.

Referenced by ath9k_hw_reset(), ath9k_hw_write_associd(), and ath_hw_setbssidmask().

◆ get_unaligned_le32()

u32 get_unaligned_le32 ( const void * p)
inlinestatic

Definition at line 89 of file ath.h.

90{
91 return __get_unaligned_le32((const u8 *)p);
92}
static u32 __get_unaligned_le32(const u8 *p)
Definition ath.h:81

References __get_unaligned_le32(), u32, and u8.

Referenced by ath9k_hw_reset(), ath9k_hw_write_associd(), and ath_hw_setbssidmask().

◆ ath_hw_setbssidmask()

void ath_hw_setbssidmask ( struct ath_common * common)

ath_hw_set_bssid_mask - filter out bssids we listen

@common: the ath_common struct for the device.

BSSID masking is a method used by AR5212 and newer hardware to inform PCU which bits of the interface's MAC address should be looked at when trying to decide which packets to ACK. In station mode and AP mode with a single BSS every bit matters since we lock to only one BSS. In AP mode with multiple BSSes (virtual interfaces) not every bit matters because hw must accept frames for all BSSes and so we tweak some bits of our mac address in order to have multiple BSSes.

NOTE: This is a simple filter and does not filter out all relevant frames. Some frames that are not for us might get ACKed from us by PCU because they just match the mask.

When handling multiple BSSes you can get the BSSID mask by computing the set of ~ ( MAC XOR BSSID ) for all bssids we handle.

When you do this you are essentially computing the common bits of all your BSSes. Later it is assumed the hardware will "and" (&) the BSSID mask with the MAC address to obtain the relevant bits and compare the result with (frame's BSSID & mask) to see if they match.

Simple example: on your card you have have two BSSes you have created with BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address. There is another BSSID-03 but you are not part of it. For simplicity's sake, assuming only 4 bits for a mac address and for BSSIDs you can then have:

             \

MAC: 0001 | BSSID-01: 0100 | --> Belongs to us BSSID-02: 1001 |

/

BSSID-03: 0110 | --> External

Our bssid_mask would then be:

        On loop iteration for BSSID-01:
        ~(0001 ^ 0100)  -> ~(0101)
                        ->   1010
        bssid_mask      =    1010

        On loop iteration for BSSID-02:
        bssid_mask &= ~(0001   ^   1001)
        bssid_mask =   (1010)  & ~(0001 ^ 1001)
        bssid_mask =   (1010)  & ~(1000)
        bssid_mask =   (1010)  &  (0111)
        bssid_mask =   0010

A bssid_mask of 0010 means "only pay attention to the second least significant bit". This is because its the only bit common amongst the MAC and all BSSIDs we support. To findout what the real common bit is we can simply "&" the bssid_mask now with any BSSID we have or our MAC address (we assume the hardware uses the MAC address).

Now, suppose there's an incoming frame for BSSID-03:

IFRAME-01: 0110

An easy eye-inspeciton of this already should tell you that this frame will not pass our check. This is because the bssid_mask tells the hardware to only look at the second least significant bit and the common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB as 1, which does not match 0.

So with IFRAME-01 we assume the hardware will do:

allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;

--> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0; --> allow = (0010) == 0000 ? 1 : 0; --> allow = 0

Lets now test a frame that should work:

IFRAME-02: 0001 (we should allow)

allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;

--> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0; --> allow = (0000) == (0000) --> allow = 1

Other examples:

IFRAME-03: 0100 --> allowed IFRAME-04: 1001 --> allowed IFRAME-05: 1101 --> allowed but its not for us!!!

Definition at line 122 of file ath_hw.c.

123{
124 void *ah = common->ah;
125
128}
static u16 get_unaligned_le16(const void *p)
Definition ath.h:85
static u32 get_unaligned_le32(const void *p)
Definition ath.h:89
#define REG_WRITE
Definition ath_hw.c:28
struct ib_cm_common common
Definition ib_mad.h:0
#define AR_BSSMSKU
Definition reg.h:37
#define AR_BSSMSKL
Definition reg.h:36
uint8_t ah
Definition registers.h:1

References ah, AR_BSSMSKL, AR_BSSMSKU, common, get_unaligned_le16(), get_unaligned_le32(), and REG_WRITE.

Referenced by ath9k_hw_reset(), and ath_opmode_init().

◆ ath_hw_keyreset()

int ath_hw_keyreset ( struct ath_common * common,
u16 entry )

Definition at line 43 of file ath_key.c.

44{
45 u32 keyType;
46 void *ah = common->ah;
47
48 if (entry >= common->keymax) {
49 DBG("ath: keycache entry %d out of range\n", entry);
50 return 0;
51 }
52
53 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
54
56
57 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
58 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
59 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
60 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
61 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
63 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
64 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
65
66 if (keyType == AR_KEYTABLE_TYPE_TKIP) {
67 u16 micentry = entry + 64;
68
69 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
70 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
71 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
72 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
73 if (common->crypt_caps & ATH_CRYPT_CAP_MIC_COMBINED) {
74 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
75 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
77 }
78
79 }
80
82
83 return 1;
84}
#define AR_KEYTABLE_TYPE(_n)
Definition reg.h:1887
#define AR_KEYTABLE_MAC1(_n)
Definition reg.h:1889
#define AR_KEYTABLE_KEY1(_n)
Definition reg.h:1883
#define AR_KEYTABLE_KEY2(_n)
Definition reg.h:1884
#define AR_KEYTABLE_KEY0(_n)
Definition reg.h:1882
#define AR_KEYTABLE_MAC0(_n)
Definition reg.h:1888
#define AR_KEYTABLE_KEY3(_n)
Definition reg.h:1885
#define AR_KEYTABLE_TYPE_TKIP
Definition reg.h:1876
#define AR_KEYTABLE_KEY4(_n)
Definition reg.h:1886
#define AR_KEYTABLE_TYPE_CLR
Definition reg.h:1879
#define REGWRITE_BUFFER_FLUSH(_ah)
Definition ath_key.c:32
#define REG_WRITE(_ah, _reg, _val)
Definition ath_key.c:27
#define REG_READ
Definition ath_key.c:26
#define ENABLE_REGWRITE_BUFFER(_ah)
Definition ath_key.c:28
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define u16
Definition vga.h:20
#define u32
Definition vga.h:21

References ah, AR_KEYTABLE_KEY0, AR_KEYTABLE_KEY1, AR_KEYTABLE_KEY2, AR_KEYTABLE_KEY3, AR_KEYTABLE_KEY4, AR_KEYTABLE_MAC0, AR_KEYTABLE_MAC1, AR_KEYTABLE_TYPE, AR_KEYTABLE_TYPE_CLR, AR_KEYTABLE_TYPE_TKIP, ATH_CRYPT_CAP_MIC_COMBINED, common, DBG, ENABLE_REGWRITE_BUFFER, REG_READ, REG_WRITE, REGWRITE_BUFFER_FLUSH, u16, and u32.

Referenced by ath9k_init_crypto().

◆ ath_hw_cycle_counters_update()

void ath_hw_cycle_counters_update ( struct ath_common * common)

ath_hw_cycle_counters_update - common function to update cycle counters

@common: the ath_common struct for the device.

This function is used to update all cycle counters in one place. It has to be called while holding common->cc_lock!

Definition at line 139 of file ath_hw.c.

140{
141 u32 cycles, busy, rx, tx;
142 void *ah = common->ah;
143
144 /* freeze */
146
147 /* read */
148 cycles = REG_READ(ah, AR_CCCNT);
149 busy = REG_READ(ah, AR_RCCNT);
152
153 /* clear */
154 REG_WRITE(ah, 0, AR_CCCNT);
155 REG_WRITE(ah, 0, AR_RFCNT);
156 REG_WRITE(ah, 0, AR_RCCNT);
157 REG_WRITE(ah, 0, AR_TFCNT);
158
159 /* unfreeze */
160 REG_WRITE(ah, 0, AR_MIBC);
161
162 /* update all cycle counters here */
163 common->cc_ani.cycles += cycles;
164 common->cc_ani.rx_busy += busy;
165 common->cc_ani.rx_frame += rx;
166 common->cc_ani.tx_frame += tx;
167
168 common->cc_survey.cycles += cycles;
169 common->cc_survey.rx_busy += busy;
170 common->cc_survey.rx_frame += rx;
171 common->cc_survey.tx_frame += tx;
172}
#define REG_READ
Definition ath_hw.c:27
#define AR_RCCNT
Definition reg.h:41
#define AR_TFCNT
Definition reg.h:39
#define AR_MIBC_FMC
Definition reg.h:28
#define AR_MIBC
Definition reg.h:26
#define AR_RFCNT
Definition reg.h:40
#define AR_CCCNT
Definition reg.h:42
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition wpa.h:4
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition wpa.h:1

References ah, AR_CCCNT, AR_MIBC, AR_MIBC_FMC, AR_RCCNT, AR_RFCNT, AR_TFCNT, common, REG_READ, REG_WRITE, rx, tx, and u32.

Referenced by ath9k_hw_ani_read_counters(), and ath_update_survey_stats().

◆ ath_hw_get_listen_time()

int32_t ath_hw_get_listen_time ( struct ath_common * common)

Definition at line 174 of file ath_hw.c.

175{
176 struct ath_cycle_counters *cc = &common->cc_ani;
177 int32_t listen_time;
178
179 listen_time = (cc->cycles - cc->rx_frame - cc->tx_frame) /
180 (common->clockrate * 1000);
181
182 memset(cc, 0, sizeof(*cc));
183
184 return listen_time;
185}
void * memset(void *dest, int character, size_t len) __nonnull

References common, ath_cycle_counters::cycles, memset(), ath_cycle_counters::rx_frame, and ath_cycle_counters::tx_frame.

Referenced by ath9k_hw_ani_read_counters().