Commit fbf76538 authored by Larry Finger's avatar Larry Finger

staging: rtl8192e: Cleanup checkpatch -f warnings and errors - Part XI

Signed-off-by: default avatarLarry Finger <Larry.Finger@lwfinger.net>
parent b2a3fff4
...@@ -29,11 +29,11 @@ void eprom_cs(struct net_device *dev, short bit) ...@@ -29,11 +29,11 @@ void eprom_cs(struct net_device *dev, short bit)
{ {
if (bit) if (bit)
write_nic_byte(dev, EPROM_CMD, write_nic_byte(dev, EPROM_CMD,
(1<<EPROM_CS_SHIFT) | \ (1 << EPROM_CS_SHIFT) |
read_nic_byte(dev, EPROM_CMD)); read_nic_byte(dev, EPROM_CMD));
else else
write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD)\ write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD)
&~(1<<EPROM_CS_SHIFT)); & ~(1<<EPROM_CS_SHIFT));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
} }
...@@ -42,22 +42,22 @@ void eprom_cs(struct net_device *dev, short bit) ...@@ -42,22 +42,22 @@ void eprom_cs(struct net_device *dev, short bit)
void eprom_ck_cycle(struct net_device *dev) void eprom_ck_cycle(struct net_device *dev)
{ {
write_nic_byte(dev, EPROM_CMD, write_nic_byte(dev, EPROM_CMD,
(1<<EPROM_CK_SHIFT) | read_nic_byte(dev,EPROM_CMD)); (1<<EPROM_CK_SHIFT) | read_nic_byte(dev, EPROM_CMD));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
write_nic_byte(dev, EPROM_CMD, write_nic_byte(dev, EPROM_CMD,
read_nic_byte(dev, EPROM_CMD) &~ (1<<EPROM_CK_SHIFT)); read_nic_byte(dev, EPROM_CMD) & ~(1<<EPROM_CK_SHIFT));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
} }
void eprom_w(struct net_device *dev,short bit) void eprom_w(struct net_device *dev, short bit)
{ {
if (bit) if (bit)
write_nic_byte(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) | \ write_nic_byte(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) |
read_nic_byte(dev,EPROM_CMD)); read_nic_byte(dev, EPROM_CMD));
else else
write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev,EPROM_CMD)\ write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD)
&~(1<<EPROM_W_SHIFT)); & ~(1<<EPROM_W_SHIFT));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
} }
...@@ -67,7 +67,7 @@ short eprom_r(struct net_device *dev) ...@@ -67,7 +67,7 @@ short eprom_r(struct net_device *dev)
{ {
short bit; short bit;
bit=(read_nic_byte(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) ); bit = (read_nic_byte(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
if (bit) if (bit)
...@@ -80,45 +80,44 @@ void eprom_send_bits_string(struct net_device *dev, short b[], int len) ...@@ -80,45 +80,44 @@ void eprom_send_bits_string(struct net_device *dev, short b[], int len)
{ {
int i; int i;
for (i=0; i<len; i++){ for (i = 0; i < len; i++) {
eprom_w(dev, b[i]); eprom_w(dev, b[i]);
eprom_ck_cycle(dev); eprom_ck_cycle(dev);
} }
} }
u32 eprom_read(struct net_device *dev, u32 addr) u32 eprom_read(struct net_device *dev, u32 addr)
{ {
struct r8192_priv *priv = rtllib_priv(dev); struct r8192_priv *priv = rtllib_priv(dev);
short read_cmd[]={1,1,0}; short read_cmd[] = {1, 1, 0};
short addr_str[8]; short addr_str[8];
int i; int i;
int addr_len; int addr_len;
u32 ret; u32 ret;
ret=0; ret = 0;
write_nic_byte(dev, EPROM_CMD, write_nic_byte(dev, EPROM_CMD,
(EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT)); (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
udelay(EPROM_DELAY); udelay(EPROM_DELAY);
if (priv->epromtype==EEPROM_93C56){ if (priv->epromtype == EEPROM_93C56) {
addr_str[7]=addr & 1; addr_str[7] = addr & 1;
addr_str[6]=addr & (1<<1); addr_str[6] = addr & (1<<1);
addr_str[5]=addr & (1<<2); addr_str[5] = addr & (1<<2);
addr_str[4]=addr & (1<<3); addr_str[4] = addr & (1<<3);
addr_str[3]=addr & (1<<4); addr_str[3] = addr & (1<<4);
addr_str[2]=addr & (1<<5); addr_str[2] = addr & (1<<5);
addr_str[1]=addr & (1<<6); addr_str[1] = addr & (1<<6);
addr_str[0]=addr & (1<<7); addr_str[0] = addr & (1<<7);
addr_len=8; addr_len = 8;
}else{ } else {
addr_str[5]=addr & 1; addr_str[5] = addr & 1;
addr_str[4]=addr & (1<<1); addr_str[4] = addr & (1<<1);
addr_str[3]=addr & (1<<2); addr_str[3] = addr & (1<<2);
addr_str[2]=addr & (1<<3); addr_str[2] = addr & (1<<3);
addr_str[1]=addr & (1<<4); addr_str[1] = addr & (1<<4);
addr_str[0]=addr & (1<<5); addr_str[0] = addr & (1<<5);
addr_len=6; addr_len = 6;
} }
eprom_cs(dev, 1); eprom_cs(dev, 1);
eprom_ck_cycle(dev); eprom_ck_cycle(dev);
...@@ -127,7 +126,7 @@ u32 eprom_read(struct net_device *dev, u32 addr) ...@@ -127,7 +126,7 @@ u32 eprom_read(struct net_device *dev, u32 addr)
eprom_w(dev, 0); eprom_w(dev, 0);
for (i = 0; i < 16; i++){ for (i = 0; i < 16; i++) {
eprom_ck_cycle(dev); eprom_ck_cycle(dev);
ret |= (eprom_r(dev)<<(15-i)); ret |= (eprom_r(dev)<<(15-i));
} }
......
...@@ -26,4 +26,4 @@ ...@@ -26,4 +26,4 @@
#define EPROM_DELAY 10 #define EPROM_DELAY 10
u32 eprom_read(struct net_device *dev,u32 addr); u32 eprom_read(struct net_device *dev, u32 addr);
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <asm/string.h> #include <linux/string.h>
#include <asm/errno.h> #include <linux/errno.h>
#include "rtllib.h" #include "rtllib.h"
...@@ -152,7 +152,7 @@ int rtllib_unregister_crypto_ops(struct rtllib_crypto_ops *ops) ...@@ -152,7 +152,7 @@ int rtllib_unregister_crypto_ops(struct rtllib_crypto_ops *ops)
} }
struct rtllib_crypto_ops * rtllib_get_crypto_ops(const char *name) struct rtllib_crypto_ops *rtllib_get_crypto_ops(const char *name)
{ {
unsigned long flags; unsigned long flags;
struct list_head *ptr; struct list_head *ptr;
......
...@@ -61,8 +61,8 @@ struct rtllib_crypto_ops { ...@@ -61,8 +61,8 @@ struct rtllib_crypto_ops {
/* maximum number of bytes added by encryption; encrypt buf is /* maximum number of bytes added by encryption; encrypt buf is
* allocated with extra_prefix_len bytes, copy of in_buf, and * allocated with extra_prefix_len bytes, copy of in_buf, and
* extra_postfix_len; encrypt need not use all this space, but * extra_postfix_len; encrypt need not use all this space, but
* the result must start at the beginning of the struct buffer and correct * the result must start at the beginning of the struct buffer and
* length must be returned */ * correct length must be returned */
int extra_prefix_len, extra_postfix_len; int extra_prefix_len, extra_postfix_len;
struct module *owner; struct module *owner;
...@@ -77,9 +77,9 @@ struct rtllib_crypt_data { ...@@ -77,9 +77,9 @@ struct rtllib_crypt_data {
int rtllib_register_crypto_ops(struct rtllib_crypto_ops *ops); int rtllib_register_crypto_ops(struct rtllib_crypto_ops *ops);
int rtllib_unregister_crypto_ops(struct rtllib_crypto_ops *ops); int rtllib_unregister_crypto_ops(struct rtllib_crypto_ops *ops);
struct rtllib_crypto_ops * rtllib_get_crypto_ops(const char *name); struct rtllib_crypto_ops *rtllib_get_crypto_ops(const char *name);
void rtllib_crypt_deinit_entries(struct rtllib_device *, int); void rtllib_crypt_deinit_entries(struct rtllib_device *, int);
void rtllib_crypt_deinit_handler(unsigned long); void rtllib_crypt_deinit_handler(unsigned long);
void rtllib_crypt_delayed_deinit(struct rtllib_device *ieee, void rtllib_crypt_delayed_deinit(struct rtllib_device *ieee,
struct rtllib_crypt_data **crypt); struct rtllib_crypt_data **crypt);
#endif #endif
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <asm/string.h> #include <linux/string.h>
#include <linux/wireless.h> #include <linux/wireless.h>
#include "rtllib.h" #include "rtllib.h"
...@@ -56,10 +56,10 @@ struct rtllib_ccmp_data { ...@@ -56,10 +56,10 @@ struct rtllib_ccmp_data {
void rtllib_ccmp_aes_encrypt(struct crypto_tfm *tfm, void rtllib_ccmp_aes_encrypt(struct crypto_tfm *tfm,
const u8 pt[16], u8 ct[16]) const u8 pt[16], u8 ct[16])
{ {
crypto_cipher_encrypt_one((void*)tfm, ct, pt); crypto_cipher_encrypt_one((void *)tfm, ct, pt);
} }
static void * rtllib_ccmp_init(int key_idx) static void *rtllib_ccmp_init(int key_idx)
{ {
struct rtllib_ccmp_data *priv; struct rtllib_ccmp_data *priv;
...@@ -69,7 +69,7 @@ static void * rtllib_ccmp_init(int key_idx) ...@@ -69,7 +69,7 @@ static void * rtllib_ccmp_init(int key_idx)
memset(priv, 0, sizeof(*priv)); memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx; priv->key_idx = key_idx;
priv->tfm = (void*)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tfm)) { if (IS_ERR(priv->tfm)) {
printk(KERN_DEBUG "rtllib_crypt_ccmp: could not allocate " printk(KERN_DEBUG "rtllib_crypt_ccmp: could not allocate "
"crypto API aes\n"); "crypto API aes\n");
...@@ -81,7 +81,7 @@ static void * rtllib_ccmp_init(int key_idx) ...@@ -81,7 +81,7 @@ static void * rtllib_ccmp_init(int key_idx)
fail: fail:
if (priv) { if (priv) {
if (priv->tfm) if (priv->tfm)
crypto_free_cipher((void*)priv->tfm); crypto_free_cipher((void *)priv->tfm);
kfree(priv); kfree(priv);
} }
...@@ -93,7 +93,7 @@ static void rtllib_ccmp_deinit(void *priv) ...@@ -93,7 +93,7 @@ static void rtllib_ccmp_deinit(void *priv)
{ {
struct rtllib_ccmp_data *_priv = priv; struct rtllib_ccmp_data *_priv = priv;
if (_priv && _priv->tfm) if (_priv && _priv->tfm)
crypto_free_cipher((void*)_priv->tfm); crypto_free_cipher((void *)_priv->tfm);
kfree(priv); kfree(priv);
} }
...@@ -124,7 +124,7 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm, ...@@ -124,7 +124,7 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
/* /*
qc_included = ((WLAN_FC_GET_TYPE(fc) == RTLLIB_FTYPE_DATA) && qc_included = ((WLAN_FC_GET_TYPE(fc) == RTLLIB_FTYPE_DATA) &&
(WLAN_FC_GET_STYPE(fc) & 0x08)); (WLAN_FC_GET_STYPE(fc) & 0x08));
*/ */
qc_included = ((WLAN_FC_GET_TYPE(fc) == RTLLIB_FTYPE_DATA) && qc_included = ((WLAN_FC_GET_TYPE(fc) == RTLLIB_FTYPE_DATA) &&
(WLAN_FC_GET_STYPE(fc) & 0x80)); (WLAN_FC_GET_STYPE(fc) & 0x80));
aad_len = 22; aad_len = 22;
...@@ -192,7 +192,8 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -192,7 +192,8 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
int data_len, i; int data_len, i;
u8 *pos; u8 *pos;
struct rtllib_hdr_4addr *hdr; struct rtllib_hdr_4addr *hdr;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
if (skb_headroom(skb) < CCMP_HDR_LEN || if (skb_headroom(skb) < CCMP_HDR_LEN ||
skb_tailroom(skb) < CCMP_MIC_LEN || skb_tailroom(skb) < CCMP_MIC_LEN ||
skb->len < hdr_len) skb->len < hdr_len)
...@@ -232,7 +233,8 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -232,7 +233,8 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
mic = skb_put(skb, CCMP_MIC_LEN); mic = skb_put(skb, CCMP_MIC_LEN);
ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0); ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len,
b0, b, s0);
blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN; blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
last = data_len % AES_BLOCK_LEN; last = data_len % AES_BLOCK_LEN;
...@@ -262,7 +264,8 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -262,7 +264,8 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
struct rtllib_ccmp_data *key = priv; struct rtllib_ccmp_data *key = priv;
u8 keyidx, *pos; u8 keyidx, *pos;
struct rtllib_hdr_4addr *hdr; struct rtllib_hdr_4addr *hdr;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
u8 pn[6]; u8 pn[6];
if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) { if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) {
...@@ -308,7 +311,8 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -308,7 +311,8 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
return -4; return -4;
} }
if (!tcb_desc->bHwSec) { if (!tcb_desc->bHwSec) {
size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN; size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN -
CCMP_MIC_LEN;
u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; u8 *mic = skb->data + skb->len - CCMP_MIC_LEN;
u8 *b0 = key->rx_b0; u8 *b0 = key->rx_b0;
u8 *b = key->rx_b; u8 *b = key->rx_b;
...@@ -376,7 +380,7 @@ static int rtllib_ccmp_set_key(void *key, int len, u8 *seq, void *priv) ...@@ -376,7 +380,7 @@ static int rtllib_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
data->rx_pn[4] = seq[1]; data->rx_pn[4] = seq[1];
data->rx_pn[5] = seq[0]; data->rx_pn[5] = seq[0];
} }
crypto_cipher_setkey((void*)data->tfm, data->key, CCMP_TK_LEN); crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN);
} else if (len == 0) } else if (len == 0)
data->key_set = 0; data->key_set = 0;
else else
...@@ -410,7 +414,7 @@ static int rtllib_ccmp_get_key(void *key, int len, u8 *seq, void *priv) ...@@ -410,7 +414,7 @@ static int rtllib_ccmp_get_key(void *key, int len, u8 *seq, void *priv)
} }
static char * rtllib_ccmp_print_stats(char *p, void *priv) static char *rtllib_ccmp_print_stats(char *p, void *priv)
{ {
struct rtllib_ccmp_data *ccmp = priv; struct rtllib_ccmp_data *ccmp = priv;
p += sprintf(p, "key[%d] alg=CCMP key_set=%d " p += sprintf(p, "key[%d] alg=CCMP key_set=%d "
......
...@@ -18,15 +18,13 @@ ...@@ -18,15 +18,13 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <asm/string.h> #include <linux/string.h>
#include "rtllib.h"
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/crc32.h> #include <linux/crc32.h>
#include "rtllib.h"
struct rtllib_tkip_data { struct rtllib_tkip_data {
#define TKIP_KEY_LEN 32 #define TKIP_KEY_LEN 32
u8 key[TKIP_KEY_LEN]; u8 key[TKIP_KEY_LEN];
...@@ -39,7 +37,7 @@ struct rtllib_tkip_data { ...@@ -39,7 +37,7 @@ struct rtllib_tkip_data {
u32 rx_iv32; u32 rx_iv32;
u16 rx_iv16; u16 rx_iv16;
bool initialized; bool initialized;
u16 rx_ttak[5]; u16 rx_ttak[5];
int rx_phase1_done; int rx_phase1_done;
u32 rx_iv32_new; u32 rx_iv32_new;
...@@ -58,7 +56,7 @@ struct rtllib_tkip_data { ...@@ -58,7 +56,7 @@ struct rtllib_tkip_data {
u8 rx_hdr[16], tx_hdr[16]; u8 rx_hdr[16], tx_hdr[16];
}; };
static void * rtllib_tkip_init(int key_idx) static void *rtllib_tkip_init(int key_idx)
{ {
struct rtllib_tkip_data *priv; struct rtllib_tkip_data *priv;
...@@ -181,8 +179,7 @@ static inline u16 Mk16_le(u16 *v) ...@@ -181,8 +179,7 @@ static inline u16 Mk16_le(u16 *v)
} }
static const u16 Sbox[256] = static const u16 Sbox[256] = {
{
0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154, 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A, 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B, 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
...@@ -303,7 +300,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -303,7 +300,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
int len; int len;
u8 *pos; u8 *pos;
struct rtllib_hdr_4addr *hdr; struct rtllib_hdr_4addr *hdr;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
struct blkcipher_desc desc = {.tfm = tkey->tx_tfm_arc4}; struct blkcipher_desc desc = {.tfm = tkey->tx_tfm_arc4};
int ret = 0; int ret = 0;
u8 rc4key[16], *icv; u8 rc4key[16], *icv;
...@@ -322,7 +320,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -322,7 +320,8 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
tkey->tx_iv32); tkey->tx_iv32);
tkey->tx_phase1_done = 1; tkey->tx_phase1_done = 1;
} }
tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16); tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak,
tkey->tx_iv16);
} else } else
tkey->tx_phase1_done = 1; tkey->tx_phase1_done = 1;
...@@ -360,7 +359,7 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -360,7 +359,7 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16); crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
ret= crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4); ret = crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
} }
tkey->tx_iv16++; tkey->tx_iv16++;
...@@ -384,7 +383,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -384,7 +383,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
u32 iv32; u32 iv32;
u16 iv16; u16 iv16;
struct rtllib_hdr_4addr *hdr; struct rtllib_hdr_4addr *hdr;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
struct blkcipher_desc desc = {.tfm = tkey->rx_tfm_arc4}; struct blkcipher_desc desc = {.tfm = tkey->rx_tfm_arc4};
u8 rc4key[16]; u8 rc4key[16];
u8 icv[4]; u8 icv[4];
...@@ -422,23 +422,25 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -422,23 +422,25 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24); iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
pos += 8; pos += 8;
if (!tcb_desc->bHwSec || (skb->cb[0] == 1)) if (!tcb_desc->bHwSec || (skb->cb[0] == 1)) {
{
if ((iv32 < tkey->rx_iv32 || if ((iv32 < tkey->rx_iv32 ||
(iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16))&&tkey->initialized) { (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) &&
tkey->initialized) {
if (net_ratelimit()) { if (net_ratelimit()) {
printk(KERN_DEBUG "TKIP: replay detected: STA=" MAC_FMT printk(KERN_DEBUG "TKIP: replay detected: STA="
" previous TSC %08x%04x received TSC " MAC_FMT
"%08x%04x\n", MAC_ARG(hdr->addr2), " previous TSC %08x%04x received TSC "
tkey->rx_iv32, tkey->rx_iv16, iv32, iv16); "%08x%04x\n", MAC_ARG(hdr->addr2),
tkey->rx_iv32, tkey->rx_iv16, iv32, iv16);
} }
tkey->dot11RSNAStatsTKIPReplays++; tkey->dot11RSNAStatsTKIPReplays++;
return -4; return -4;
} }
tkey->initialized = true; tkey->initialized = true;
if (iv32 != tkey->rx_iv32 || !tkey->rx_phase1_done) { if (iv32 != tkey->rx_iv32 || !tkey->rx_phase1_done) {
tkip_mixing_phase1(tkey->rx_ttak, tkey->key, hdr->addr2, iv32); tkip_mixing_phase1(tkey->rx_ttak, tkey->key,
hdr->addr2, iv32);
tkey->rx_phase1_done = 1; tkey->rx_phase1_done = 1;
} }
tkip_mixing_phase2(rc4key, tkey->key, tkey->rx_ttak, iv16); tkip_mixing_phase2(rc4key, tkey->key, tkey->rx_ttak, iv16);
...@@ -451,7 +453,7 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -451,7 +453,7 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) { if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) {
if (net_ratelimit()) { if (net_ratelimit()) {
printk(KERN_DEBUG ": TKIP: failed to decrypt " printk(KERN_DEBUG ": TKIP: failed to decrypt "
"received packet from " MAC_FMT "\n", "received packet from " MAC_FMT "\n",
MAC_ARG(hdr->addr2)); MAC_ARG(hdr->addr2));
} }
return -7; return -7;
...@@ -465,8 +467,9 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -465,8 +467,9 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
if (memcmp(icv, pos + plen, 4) != 0) { if (memcmp(icv, pos + plen, 4) != 0) {
if (iv32 != tkey->rx_iv32) { if (iv32 != tkey->rx_iv32) {
/* Previously cached Phase1 result was already lost, so /* Previously cached Phase1 result was already
* it needs to be recalculated for the next packet. */ * lost, so it needs to be recalculated for the
* next packet. */
tkey->rx_phase1_done = 0; tkey->rx_phase1_done = 0;
} }
if (net_ratelimit()) { if (net_ratelimit()) {
...@@ -493,26 +496,26 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -493,26 +496,26 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
} }
static int michael_mic(struct crypto_hash *tfm_michael, u8 * key, u8 * hdr, static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr,
u8 * data, size_t data_len, u8 * mic) u8 *data, size_t data_len, u8 *mic)
{ {
struct hash_desc desc; struct hash_desc desc;
struct scatterlist sg[2]; struct scatterlist sg[2];
if (tfm_michael == NULL) { if (tfm_michael == NULL) {
printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
return -1; return -1;
} }
sg_init_table(sg, 2); sg_init_table(sg, 2);
sg_set_buf(&sg[0], hdr, 16); sg_set_buf(&sg[0], hdr, 16);
sg_set_buf(&sg[1], data, data_len); sg_set_buf(&sg[1], data, data_len);
if (crypto_hash_setkey(tfm_michael, key, 8)) if (crypto_hash_setkey(tfm_michael, key, 8))
return -1; return -1;
desc.tfm = tfm_michael; desc.tfm = tfm_michael;
desc.flags = 0; desc.flags = 0;
return crypto_hash_digest(&desc, sg, data_len + 16, mic); return crypto_hash_digest(&desc, sg, data_len + 16, mic);
} }
static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr) static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
...@@ -563,12 +566,11 @@ static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -563,12 +566,11 @@ static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv)
michael_mic_hdr(skb, tkey->tx_hdr); michael_mic_hdr(skb, tkey->tx_hdr);
if (RTLLIB_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) { if (RTLLIB_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl)))
tkey->tx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07; tkey->tx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07;
}
pos = skb_put(skb, 8); pos = skb_put(skb, 8);
if (michael_mic(tkey->tx_tfm_michael, &tkey->key[16], tkey->tx_hdr, if (michael_mic(tkey->tx_tfm_michael, &tkey->key[16], tkey->tx_hdr,
skb->data + hdr_len, skb->len - 8 - hdr_len, pos)) skb->data + hdr_len, skb->len - 8 - hdr_len, pos))
return -1; return -1;
return 0; return 0;
...@@ -597,7 +599,8 @@ static void rtllib_michael_mic_failure(struct net_device *dev, ...@@ -597,7 +599,8 @@ static void rtllib_michael_mic_failure(struct net_device *dev,
} }
static int rtllib_michael_mic_verify(struct sk_buff *skb, int keyidx, static int rtllib_michael_mic_verify(struct sk_buff *skb, int keyidx,
int hdr_len, void *priv, struct rtllib_device* ieee) int hdr_len, void *priv,
struct rtllib_device *ieee)
{ {
struct rtllib_tkip_data *tkey = priv; struct rtllib_tkip_data *tkey = priv;
u8 mic[8]; u8 mic[8];
...@@ -609,29 +612,30 @@ static int rtllib_michael_mic_verify(struct sk_buff *skb, int keyidx, ...@@ -609,29 +612,30 @@ static int rtllib_michael_mic_verify(struct sk_buff *skb, int keyidx,
return -1; return -1;
michael_mic_hdr(skb, tkey->rx_hdr); michael_mic_hdr(skb, tkey->rx_hdr);
if (RTLLIB_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) { if (RTLLIB_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl)))
tkey->rx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07; tkey->rx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07;
}
if (michael_mic(tkey->rx_tfm_michael, &tkey->key[24], tkey->rx_hdr, if (michael_mic(tkey->rx_tfm_michael, &tkey->key[24], tkey->rx_hdr,
skb->data + hdr_len, skb->len - 8 - hdr_len, mic)) skb->data + hdr_len, skb->len - 8 - hdr_len, mic))
return -1; return -1;
if ((memcmp(mic, skb->data + skb->len - 8, 8) != 0)||(ieee->force_mic_error)) { if ((memcmp(mic, skb->data + skb->len - 8, 8) != 0) ||
(ieee->force_mic_error)) {
struct rtllib_hdr_4addr *hdr; struct rtllib_hdr_4addr *hdr;
hdr = (struct rtllib_hdr_4addr *) skb->data; hdr = (struct rtllib_hdr_4addr *) skb->data;
printk(KERN_DEBUG "%s: Michael MIC verification failed for " printk(KERN_DEBUG "%s: Michael MIC verification failed for "
"MSDU from " MAC_FMT " keyidx=%d\n", "MSDU from " MAC_FMT " keyidx=%d\n",
skb->dev ? skb->dev->name : "N/A", MAC_ARG(hdr->addr2), skb->dev ? skb->dev->name : "N/A", MAC_ARG(hdr->addr2),
keyidx); keyidx);
printk("%d, force_mic_error = %d\n", (memcmp(mic, skb->data + skb->len - 8, 8) != 0),\ printk(KERN_DEBUG "%d, force_mic_error = %d\n",
ieee->force_mic_error); (memcmp(mic, skb->data + skb->len - 8, 8) != 0),\
ieee->force_mic_error);
if (skb->dev) { if (skb->dev) {
printk("skb->dev != NULL\n"); printk(KERN_INFO "skb->dev != NULL\n");
rtllib_michael_mic_failure(skb->dev, hdr, keyidx); rtllib_michael_mic_failure(skb->dev, hdr, keyidx);
} }
tkey->dot11RSNAStatsTKIPLocalMICFailures++; tkey->dot11RSNAStatsTKIPLocalMICFailures++;
ieee->force_mic_error = false; ieee->force_mic_error = false;
return -1; return -1;
} }
...@@ -711,7 +715,7 @@ static int rtllib_tkip_get_key(void *key, int len, u8 *seq, void *priv) ...@@ -711,7 +715,7 @@ static int rtllib_tkip_get_key(void *key, int len, u8 *seq, void *priv)
} }
static char * rtllib_tkip_print_stats(char *p, void *priv) static char *rtllib_tkip_print_stats(char *p, void *priv)
{ {
struct rtllib_tkip_data *tkip = priv; struct rtllib_tkip_data *tkip = priv;
p += sprintf(p, "key[%d] alg=TKIP key_set=%d " p += sprintf(p, "key[%d] alg=TKIP key_set=%d "
...@@ -751,7 +755,7 @@ static struct rtllib_crypto_ops rtllib_crypt_tkip = { ...@@ -751,7 +755,7 @@ static struct rtllib_crypto_ops rtllib_crypt_tkip = {
.print_stats = rtllib_tkip_print_stats, .print_stats = rtllib_tkip_print_stats,
.extra_prefix_len = 4 + 4, /* IV + ExtIV */ .extra_prefix_len = 4 + 4, /* IV + ExtIV */
.extra_postfix_len = 8 + 4, /* MIC + ICV */ .extra_postfix_len = 8 + 4, /* MIC + ICV */
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
...@@ -768,5 +772,5 @@ void __exit rtllib_crypto_tkip_exit(void) ...@@ -768,5 +772,5 @@ void __exit rtllib_crypto_tkip_exit(void)
void rtllib_tkip_null(void) void rtllib_tkip_null(void)
{ {
return; return;
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <asm/string.h> #include <linux/string.h>
#include "rtllib.h" #include "rtllib.h"
#include <linux/crypto.h> #include <linux/crypto.h>
...@@ -29,12 +29,12 @@ struct prism2_wep_data { ...@@ -29,12 +29,12 @@ struct prism2_wep_data {
u8 key[WEP_KEY_LEN + 1]; u8 key[WEP_KEY_LEN + 1];
u8 key_len; u8 key_len;
u8 key_idx; u8 key_idx;
struct crypto_blkcipher *tx_tfm; struct crypto_blkcipher *tx_tfm;
struct crypto_blkcipher *rx_tfm; struct crypto_blkcipher *rx_tfm;
}; };
static void * prism2_wep_init(int keyidx) static void *prism2_wep_init(int keyidx)
{ {
struct prism2_wep_data *priv; struct prism2_wep_data *priv;
...@@ -45,19 +45,19 @@ static void * prism2_wep_init(int keyidx) ...@@ -45,19 +45,19 @@ static void * prism2_wep_init(int keyidx)
priv->key_idx = keyidx; priv->key_idx = keyidx;
priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm)) { if (IS_ERR(priv->tx_tfm)) {
printk(KERN_DEBUG "rtllib_crypt_wep: could not allocate " printk(KERN_DEBUG "rtllib_crypt_wep: could not allocate "
"crypto API arc4\n"); "crypto API arc4\n");
priv->tx_tfm = NULL; priv->tx_tfm = NULL;
goto fail; goto fail;
} }
priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->rx_tfm)) { if (IS_ERR(priv->rx_tfm)) {
printk(KERN_DEBUG "rtllib_crypt_wep: could not allocate " printk(KERN_DEBUG "rtllib_crypt_wep: could not allocate "
"crypto API arc4\n"); "crypto API arc4\n");
priv->rx_tfm = NULL; priv->rx_tfm = NULL;
goto fail; goto fail;
} }
/* start WEP IV from a random value */ /* start WEP IV from a random value */
get_random_bytes(&priv->iv, 4); get_random_bytes(&priv->iv, 4);
...@@ -66,12 +66,12 @@ static void * prism2_wep_init(int keyidx) ...@@ -66,12 +66,12 @@ static void * prism2_wep_init(int keyidx)
fail: fail:
if (priv) { if (priv) {
if (priv->tx_tfm) if (priv->tx_tfm)
crypto_free_blkcipher(priv->tx_tfm); crypto_free_blkcipher(priv->tx_tfm);
if (priv->rx_tfm) if (priv->rx_tfm)
crypto_free_blkcipher(priv->rx_tfm); crypto_free_blkcipher(priv->rx_tfm);
kfree(priv); kfree(priv);
} }
return NULL; return NULL;
} }
...@@ -81,11 +81,11 @@ static void prism2_wep_deinit(void *priv) ...@@ -81,11 +81,11 @@ static void prism2_wep_deinit(void *priv)
struct prism2_wep_data *_priv = priv; struct prism2_wep_data *_priv = priv;
if (_priv) { if (_priv) {
if (_priv->tx_tfm) if (_priv->tx_tfm)
crypto_free_blkcipher(_priv->tx_tfm); crypto_free_blkcipher(_priv->tx_tfm);
if (_priv->rx_tfm) if (_priv->rx_tfm)
crypto_free_blkcipher(_priv->rx_tfm); crypto_free_blkcipher(_priv->rx_tfm);
} }
kfree(priv); kfree(priv);
} }
...@@ -101,14 +101,17 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -101,14 +101,17 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
u32 klen, len; u32 klen, len;
u8 key[WEP_KEY_LEN + 3]; u8 key[WEP_KEY_LEN + 3];
u8 *pos; u8 *pos;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
struct blkcipher_desc desc = {.tfm = wep->tx_tfm}; struct blkcipher_desc desc = {.tfm = wep->tx_tfm};
u32 crc; u32 crc;
u8 *icv; u8 *icv;
struct scatterlist sg; struct scatterlist sg;
if (skb_headroom(skb) < 4 || skb_tailroom(skb) < 4 || if (skb_headroom(skb) < 4 || skb_tailroom(skb) < 4 ||
skb->len < hdr_len){ skb->len < hdr_len){
printk("Error!!!headroom=%d tailroom=%d skblen=%d hdr_len=%d\n",skb_headroom(skb),skb_tailroom(skb),skb->len,hdr_len); printk(KERN_ERR "Error!!! headroom=%d tailroom=%d skblen=%d"
" hdr_len=%d\n", skb_headroom(skb), skb_tailroom(skb),
skb->len, hdr_len);
return -1; return -1;
} }
len = skb->len - hdr_len; len = skb->len - hdr_len;
...@@ -157,8 +160,8 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -157,8 +160,8 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
} }
/* Perform WEP decryption on given struct buffer. Buffer includes whole WEP part of /* Perform WEP decryption on given struct buffer. Buffer includes whole WEP
* the frame: IV (4 bytes), encrypted payload (including SNAP header), * part of the frame: IV (4 bytes), encrypted payload (including SNAP header),
* ICV (4 bytes). len includes both IV and ICV. * ICV (4 bytes). len includes both IV and ICV.
* *
* Returns 0 if frame was decrypted successfully and ICV was correct and -1 on * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on
...@@ -170,7 +173,8 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -170,7 +173,8 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
u32 klen, plen; u32 klen, plen;
u8 key[WEP_KEY_LEN + 3]; u8 key[WEP_KEY_LEN + 3];
u8 keyidx, *pos; u8 keyidx, *pos;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
MAX_DEV_ADDR_SIZE);
struct blkcipher_desc desc = {.tfm = wep->rx_tfm}; struct blkcipher_desc desc = {.tfm = wep->rx_tfm};
u32 crc; u32 crc;
u8 icv[4]; u8 icv[4];
...@@ -245,7 +249,7 @@ static int prism2_wep_get_key(void *key, int len, u8 *seq, void *priv) ...@@ -245,7 +249,7 @@ static int prism2_wep_get_key(void *key, int len, u8 *seq, void *priv)
} }
static char * prism2_wep_print_stats(char *p, void *priv) static char *prism2_wep_print_stats(char *p, void *priv)
{ {
struct prism2_wep_data *wep = priv; struct prism2_wep_data *wep = priv;
p += sprintf(p, "key[%d] alg=WEP len=%d\n", p += sprintf(p, "key[%d] alg=WEP len=%d\n",
...@@ -284,5 +288,5 @@ void __exit rtllib_crypto_wep_exit(void) ...@@ -284,5 +288,5 @@ void __exit rtllib_crypto_wep_exit(void)
void rtllib_wep_null(void) void rtllib_wep_null(void)
{ {
return; return;
} }
...@@ -14,26 +14,28 @@ ...@@ -14,26 +14,28 @@
#define BYTE_ORDER __MACHINE_LITTLE_ENDIAN #define BYTE_ORDER __MACHINE_LITTLE_ENDIAN
#if BYTE_ORDER == __MACHINE_LITTLE_ENDIAN #if BYTE_ORDER == __MACHINE_LITTLE_ENDIAN
#define EF1Byte(_val) ((u8)(_val)) #define EF1Byte(_val) ((u8)(_val))
#define EF2Byte(_val) ((u16)(_val)) #define EF2Byte(_val) ((u16)(_val))
#define EF4Byte(_val) ((u32)(_val)) #define EF4Byte(_val) ((u32)(_val))
#else #else
#define EF1Byte(_val) ((u8)(_val)) #define EF1Byte(_val) ((u8)(_val))
#define EF2Byte(_val) (((((u16)(_val))&0x00ff)<<8)|((((u16)(_val))&0xff00)>>8)) #define EF2Byte(_val) \
#define EF4Byte(_val) (((((u32)(_val))&0x000000ff)<<24)|\ (((((u16)(_val))&0x00ff)<<8)|((((u16)(_val))&0xff00)>>8))
((((u32)(_val))&0x0000ff00)<<8)|\ #define EF4Byte(_val) \
((((u32)(_val))&0x00ff0000)>>8)|\ (((((u32)(_val))&0x000000ff)<<24)|\
((((u32)(_val))&0xff000000)>>24)) ((((u32)(_val))&0x0000ff00)<<8)|\
((((u32)(_val))&0x00ff0000)>>8)|\
((((u32)(_val))&0xff000000)>>24))
#endif #endif
#define ReadEF1Byte(_ptr) EF1Byte(*((u8 *)(_ptr))) #define ReadEF1Byte(_ptr) EF1Byte(*((u8 *)(_ptr)))
#define ReadEF2Byte(_ptr) EF2Byte(*((u16 *)(_ptr))) #define ReadEF2Byte(_ptr) EF2Byte(*((u16 *)(_ptr)))
#define ReadEF4Byte(_ptr) EF4Byte(*((u32 *)(_ptr))) #define ReadEF4Byte(_ptr) EF4Byte(*((u32 *)(_ptr)))
#define WriteEF1Byte(_ptr, _val) (*((u8 *)(_ptr)))=EF1Byte(_val) #define WriteEF1Byte(_ptr, _val) (*((u8 *)(_ptr))) = EF1Byte(_val)
#define WriteEF2Byte(_ptr, _val) (*((u16 *)(_ptr)))=EF2Byte(_val) #define WriteEF2Byte(_ptr, _val) (*((u16 *)(_ptr))) = EF2Byte(_val)
#define WriteEF4Byte(_ptr, _val) (*((u32 *)(_ptr)))=EF4Byte(_val) #define WriteEF4Byte(_ptr, _val) (*((u32 *)(_ptr))) = EF4Byte(_val)
#if BYTE_ORDER == __MACHINE_LITTLE_ENDIAN #if BYTE_ORDER == __MACHINE_LITTLE_ENDIAN
#define H2N1BYTE(_val) ((u8)(_val)) #define H2N1BYTE(_val) ((u8)(_val))
#define H2N2BYTE(_val) (((((u16)(_val))&0x00ff)<<8)|\ #define H2N2BYTE(_val) (((((u16)(_val))&0x00ff)<<8)|\
...@@ -63,13 +65,14 @@ ...@@ -63,13 +65,14 @@
#endif #endif
#define BIT_LEN_MASK_32(__BitLen) (0xFFFFFFFF >> (32 - (__BitLen))) #define BIT_LEN_MASK_32(__BitLen) (0xFFFFFFFF >> (32 - (__BitLen)))
#define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) (BIT_LEN_MASK_32(__BitLen) << (__BitOffset)) #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
(BIT_LEN_MASK_32(__BitLen) << (__BitOffset))
#define LE_P4BYTE_TO_HOST_4BYTE(__pStart) (EF4Byte(*((u32 *)(__pStart)))) #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) (EF4Byte(*((u32 *)(__pStart))))
#define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \ #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
( \ ( \
( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \ (LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) \
& \ & \
BIT_LEN_MASK_32(__BitLen) \ BIT_LEN_MASK_32(__BitLen) \
) )
...@@ -78,7 +81,7 @@ ...@@ -78,7 +81,7 @@
( \ ( \
LE_P4BYTE_TO_HOST_4BYTE(__pStart) \ LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
& \ & \
( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \ (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)) \
) )
#define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \ #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
...@@ -86,8 +89,8 @@ ...@@ -86,8 +89,8 @@
EF4Byte( \ EF4Byte( \
LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \ LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
| \ | \
( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \ ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
); );
#define BIT_LEN_MASK_16(__BitLen) \ #define BIT_LEN_MASK_16(__BitLen) \
...@@ -101,7 +104,7 @@ ...@@ -101,7 +104,7 @@
#define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \ #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
( \ ( \
( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \ (LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) \
& \ & \
BIT_LEN_MASK_16(__BitLen) \ BIT_LEN_MASK_16(__BitLen) \
) )
...@@ -110,16 +113,16 @@ ...@@ -110,16 +113,16 @@
( \ ( \
LE_P2BYTE_TO_HOST_2BYTE(__pStart) \ LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
& \ & \
( ~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ) \ (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)) \
) )
#define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \ #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
*((u16 *)(__pStart)) = \ *((u16 *)(__pStart)) = \
EF2Byte( \ EF2Byte( \
LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \ LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
| \ | ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << \
( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \ (__BitOffset)) \
); );
#define BIT_LEN_MASK_8(__BitLen) \ #define BIT_LEN_MASK_8(__BitLen) \
(0xFF >> (8 - (__BitLen))) (0xFF >> (8 - (__BitLen)))
...@@ -132,7 +135,7 @@ ...@@ -132,7 +135,7 @@
#define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \ #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
( \ ( \
( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \ (LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) \
& \ & \
BIT_LEN_MASK_8(__BitLen) \ BIT_LEN_MASK_8(__BitLen) \
) )
...@@ -141,16 +144,17 @@ ...@@ -141,16 +144,17 @@
( \ ( \
LE_P1BYTE_TO_HOST_1BYTE(__pStart) \ LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
& \ & \
( ~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ) \ (~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen)) \
) )
#define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \ #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
*((u8 *)(__pStart)) = \ *((u8 *)(__pStart)) = EF1Byte( \
EF1Byte( \
LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \ LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
| \ | ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << \
( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \ (__BitOffset)) \
); );
#define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment)) #define N_BYTE_ALIGMENT(__Value, __Aligment) \
((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / \
__Aligment) * __Aligment))
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment