staging: vt6656: MACvSetKeyEntry create structure to write key
authorMalcolm Priestley <tvboxspy@gmail.com>
Sun, 25 May 2014 20:36:29 +0000 (21:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 25 May 2014 22:13:59 +0000 (15:13 -0700)
Create structure for wKeyCtl , pbyAddr and pbyKey

wKeyCtl(key_ctl) and pbyAddr(addr) form an union of 64 bits with swap
of two 32 bits. pbyKey(key) has a length of WLAN_KEY_LEN_CCMP(16)
bytes.

swap is needed because high order 32 bits needs to written out first.

pbyKey is memcpy on to key.

Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vt6656/mac.c
drivers/staging/vt6656/mac.h

index f4868340749674319d21b1e32d6d890e1d0d3308..bc72144f0d213cc8dda29751f034904d61a08ebc 100644 (file)
@@ -125,60 +125,31 @@ void MACvDisableKeyEntry(struct vnt_private *priv, u8 entry_idx)
 void MACvSetKeyEntry(struct vnt_private *pDevice, u16 wKeyCtl, u32 uEntryIdx,
        u32 uKeyIdx, u8 *pbyAddr, u32 *pdwKey)
 {
-       u8 *pbyKey;
+       struct vnt_mac_set_key set_key;
+       u8 *pbyKey = (u8 *)pdwKey;
        u16 wOffset;
-       u32 dwData1, dwData2;
-       int ii;
-       u8 pbyData[24];
 
        if (pDevice->byLocalID <= MAC_REVISION_A1)
                if (pDevice->vnt_mgmt.byCSSPK == KEY_CTL_CCMP)
                        return;
 
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
-
-    dwData1 = 0;
-    dwData1 |= wKeyCtl;
-    dwData1 <<= 16;
-    dwData1 |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
-
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %X,"\
-               " KeyCtl:%X\n", wOffset, dwData1, wKeyCtl);
-
-    dwData2 = 0;
-    dwData2 |= *(pbyAddr+3);
-    dwData2 <<= 8;
-    dwData2 |= *(pbyAddr+2);
-    dwData2 <<= 8;
-    dwData2 |= *(pbyAddr+1);
-    dwData2 <<= 8;
-    dwData2 |= *(pbyAddr+0);
-
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %X\n",
-               wOffset, dwData2);
-
-    pbyKey = (u8 *)pdwKey;
-
-    pbyData[0] = (u8)dwData1;
-    pbyData[1] = (u8)(dwData1>>8);
-    pbyData[2] = (u8)(dwData1>>16);
-    pbyData[3] = (u8)(dwData1>>24);
-    pbyData[4] = (u8)dwData2;
-    pbyData[5] = (u8)(dwData2>>8);
-    pbyData[6] = (u8)(dwData2>>16);
-    pbyData[7] = (u8)(dwData2>>24);
-    for (ii = 8; ii < 24; ii++)
-       pbyData[ii] = *pbyKey++;
-
-    CONTROLnsRequestOut(pDevice,
-                        MESSAGE_TYPE_SETKEY,
-                        wOffset,
-                        (u16)uKeyIdx,
-                       ARRAY_SIZE(pbyData),
-                        pbyData
-                        );
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
 
+       set_key.u.write.key_ctl = cpu_to_le16(wKeyCtl);
+       memcpy(set_key.u.write.addr, pbyAddr, ETH_ALEN);
+
+       /* swap over swap[0] and swap[1] to get correct write order */
+       swap(set_key.u.swap[0], set_key.u.swap[1]);
+
+       memcpy(set_key.key, pbyKey, WLAN_KEY_LEN_CCMP);
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
+               "offset %d key ctl %d set key %24ph\n",
+                               wOffset, wKeyCtl, (u8 *)&set_key);
+
+       CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_SETKEY, wOffset,
+               (u16)uKeyIdx, sizeof(struct vnt_mac_set_key), (u8 *)&set_key);
 }
 
 void MACvRegBitsOff(struct vnt_private *priv, u8 reg_ofs, u8 bits)
index 2084d4b1e532632aa473365df1b9a3defce8e213..81006853dbdaaeb744b7941459bcbc7213731c87 100644 (file)
 #define MAC_REVISION_A0     0x00
 #define MAC_REVISION_A1     0x01
 
+struct vnt_mac_set_key {
+       union {
+               struct {
+                       u8 addr[ETH_ALEN];
+                       __le16 key_ctl;
+               } write __packed;
+               u32 swap[2];
+       } u;
+       u8 key[WLAN_KEY_LEN_CCMP];
+} __packed;
+
 void MACvWriteMultiAddr(struct vnt_private *, u64);
 void MACbShutdown(struct vnt_private *);
 void MACvSetBBType(struct vnt_private *, u8);