Staging: rtl8192e: array overflow in rtl92e_set_swcam()
[linux-2.6-block.git] / drivers / staging / rtl8192e / rtl8192e / rtl_cam.c
index f246222e5fc954e83cc8fb8be0344aaf057d48a2..c146b7e720a94597c3a14543e9f7cdd29f3cdfaf 100644 (file)
 #include "r8190P_rtl8256.h" /* RTL8225 Radio frontend */
 #include "r8192E_cmdpkt.h"
 
-void CamResetAllEntry(struct net_device *dev)
+void rtl92e_cam_reset(struct net_device *dev)
 {
        u32 ulcommand = 0;
 
        ulcommand |= BIT31|BIT30;
-       write_nic_dword(dev, RWCAM, ulcommand);
+       rtl92e_writel(dev, RWCAM, ulcommand);
 }
 
-void EnableHWSecurityConfig8192(struct net_device *dev)
+void rtl92e_enable_hw_security_config(struct net_device *dev)
 {
        u8 SECR_value = 0x0;
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -65,11 +65,12 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
        RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n",
                 __func__, ieee->hwsec_active, ieee->pairwise_key_type,
                 SECR_value);
-       write_nic_byte(dev, SECR,  SECR_value);
+       rtl92e_writeb(dev, SECR, SECR_value);
 }
 
-void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
-              const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent, u8 is_mesh)
+void rtl92e_set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
+                     u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
+                     u32 *KeyContent, u8 is_mesh)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -77,6 +78,10 @@ void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
        RT_TRACE(COMP_DBG,
                 "===========>%s():EntryNo is %d,KeyIndex is %d,KeyType is %d,is_mesh is %d\n",
                 __func__, EntryNo, KeyIndex, KeyType, is_mesh);
+
+       if (EntryNo >= TOTAL_CAM_ENTRY)
+               return;
+
        if (!is_mesh) {
                ieee->swcamtable[EntryNo].bused = true;
                ieee->swcamtable[EntryNo].key_index = KeyIndex;
@@ -87,8 +92,9 @@ void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
        }
 }
 
-void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
-           const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
+void rtl92e_set_key(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
+                   u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
+                   u32 *KeyContent)
 {
        u32 TargetCommand = 0;
        u32 TargetContent = 0;
@@ -106,7 +112,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
                                return;
                        }
                        down(&priv->rtllib->ips_sem);
-                       IPSLeave(dev);
+                       rtl92e_ips_leave(dev);
                        up(&priv->rtllib->ips_sem);
                }
        }
@@ -115,7 +121,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
                netdev_info(dev, "%s(): Invalid CAM entry\n", __func__);
 
        RT_TRACE(COMP_SEC,
-                "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n",
+                "====>to rtl92e_set_key(), dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n",
                 dev, EntryNo, KeyIndex, KeyType, MacAddr);
 
        if (DefaultKey)
@@ -133,20 +139,20 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
                                (u32)(*(MacAddr+1)) << 24 |
                                (u32)usConfig;
 
-                       write_nic_dword(dev, WCAMI, TargetContent);
-                       write_nic_dword(dev, RWCAM, TargetCommand);
+                       rtl92e_writel(dev, WCAMI, TargetContent);
+                       rtl92e_writel(dev, RWCAM, TargetCommand);
                } else if (i == 1) {
                        TargetContent = (u32)(*(MacAddr+2)) |
                                (u32)(*(MacAddr+3)) <<  8 |
                                (u32)(*(MacAddr+4)) << 16 |
                                (u32)(*(MacAddr+5)) << 24;
-                       write_nic_dword(dev, WCAMI, TargetContent);
-                       write_nic_dword(dev, RWCAM, TargetCommand);
+                       rtl92e_writel(dev, WCAMI, TargetContent);
+                       rtl92e_writel(dev, RWCAM, TargetCommand);
                } else {
                        if (KeyContent != NULL) {
-                               write_nic_dword(dev, WCAMI,
-                                               (u32)(*(KeyContent+i-2)));
-                               write_nic_dword(dev, RWCAM, TargetCommand);
+                               rtl92e_writel(dev, WCAMI,
+                                             (u32)(*(KeyContent+i-2)));
+                               rtl92e_writel(dev, RWCAM, TargetCommand);
                                udelay(100);
                        }
                }
@@ -154,7 +160,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
        RT_TRACE(COMP_SEC, "=========>after set key, usconfig:%x\n", usConfig);
 }
 
-void CamRestoreAllEntry(struct net_device *dev)
+void rtl92e_cam_restore(struct net_device *dev)
 {
        u8 EntryId = 0;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -170,7 +176,7 @@ void CamRestoreAllEntry(struct net_device *dev)
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff
        };
 
-       RT_TRACE(COMP_SEC, "CamRestoreAllEntry:\n");
+       RT_TRACE(COMP_SEC, "rtl92e_cam_restore:\n");
 
 
        if ((priv->rtllib->pairwise_key_type == KEY_TYPE_WEP40) ||
@@ -179,36 +185,41 @@ void CamRestoreAllEntry(struct net_device *dev)
                for (EntryId = 0; EntryId < 4; EntryId++) {
                        MacAddr = CAM_CONST_ADDR[EntryId];
                        if (priv->rtllib->swcamtable[EntryId].bused) {
-                               setKey(dev, EntryId, EntryId,
-                                      priv->rtllib->pairwise_key_type, MacAddr,
-                                      0, (u32 *)(&priv->rtllib->swcamtable
-                                     [EntryId].key_buf[0]));
+                               rtl92e_set_key(dev, EntryId, EntryId,
+                                              priv->rtllib->pairwise_key_type,
+                                              MacAddr, 0,
+                                              (u32 *)(&priv->rtllib->swcamtable
+                                                      [EntryId].key_buf[0]));
                        }
                }
 
        } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_TKIP) {
                if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
-                       setKey(dev, 4, 0, priv->rtllib->pairwise_key_type,
-                              (u8 *)dev->dev_addr, 0,
-                              (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
+                       rtl92e_set_key(dev, 4, 0,
+                                      priv->rtllib->pairwise_key_type,
+                                      (u8 *)dev->dev_addr, 0,
+                                      (u32 *)(&priv->rtllib->swcamtable[4].
+                                      key_buf[0]));
                } else {
-                       setKey(dev, 4, 0, priv->rtllib->pairwise_key_type,
-                              MacAddr, 0,
-                              (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
+                       rtl92e_set_key(dev, 4, 0,
+                                      priv->rtllib->pairwise_key_type,
+                                      MacAddr, 0,
+                                      (u32 *)(&priv->rtllib->swcamtable[4].
+                                      key_buf[0]));
                }
 
        } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_CCMP) {
                if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
-                       setKey(dev, 4, 0,
-                              priv->rtllib->pairwise_key_type,
-                              (u8 *)dev->dev_addr, 0,
-                              (u32 *)(&priv->rtllib->swcamtable[4].
-                              key_buf[0]));
+                       rtl92e_set_key(dev, 4, 0,
+                                      priv->rtllib->pairwise_key_type,
+                                      (u8 *)dev->dev_addr, 0,
+                                      (u32 *)(&priv->rtllib->swcamtable[4].
+                                      key_buf[0]));
                } else {
-                       setKey(dev, 4, 0,
-                              priv->rtllib->pairwise_key_type, MacAddr,
-                              0, (u32 *)(&priv->rtllib->swcamtable[4].
-                              key_buf[0]));
+                       rtl92e_set_key(dev, 4, 0,
+                                      priv->rtllib->pairwise_key_type, MacAddr,
+                                      0, (u32 *)(&priv->rtllib->swcamtable[4].
+                                      key_buf[0]));
                        }
        }
 
@@ -216,20 +227,18 @@ void CamRestoreAllEntry(struct net_device *dev)
                MacAddr = CAM_CONST_BROAD;
                for (EntryId = 1; EntryId < 4; EntryId++) {
                        if (priv->rtllib->swcamtable[EntryId].bused) {
-                               setKey(dev, EntryId, EntryId,
-                                       priv->rtllib->group_key_type,
-                                       MacAddr, 0,
-                                       (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0])
-                                    );
+                               rtl92e_set_key(dev, EntryId, EntryId,
+                                              priv->rtllib->group_key_type,
+                                              MacAddr, 0,
+                                              (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]));
                        }
                }
                if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
                        if (priv->rtllib->swcamtable[0].bused) {
-                               setKey(dev, 0, 0,
-                                      priv->rtllib->group_key_type,
-                                      CAM_CONST_ADDR[0], 0,
-                                      (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0])
-                                    );
+                               rtl92e_set_key(dev, 0, 0,
+                                              priv->rtllib->group_key_type,
+                                              CAM_CONST_ADDR[0], 0,
+                                              (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]));
                        } else {
                                netdev_warn(dev,
                                            "%s(): ADHOC TKIP: missing key entry.\n",
@@ -241,19 +250,19 @@ void CamRestoreAllEntry(struct net_device *dev)
                MacAddr = CAM_CONST_BROAD;
                for (EntryId = 1; EntryId < 4; EntryId++) {
                        if (priv->rtllib->swcamtable[EntryId].bused) {
-                               setKey(dev, EntryId, EntryId,
-                                      priv->rtllib->group_key_type,
-                                      MacAddr, 0,
-                                      (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]));
+                               rtl92e_set_key(dev, EntryId, EntryId,
+                                              priv->rtllib->group_key_type,
+                                              MacAddr, 0,
+                                              (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]));
                        }
                }
 
                if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
                        if (priv->rtllib->swcamtable[0].bused) {
-                               setKey(dev, 0, 0,
-                                       priv->rtllib->group_key_type,
-                                       CAM_CONST_ADDR[0], 0,
-                                       (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]));
+                               rtl92e_set_key(dev, 0, 0,
+                                              priv->rtllib->group_key_type,
+                                              CAM_CONST_ADDR[0], 0,
+                                              (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]));
                        } else {
                                netdev_warn(dev,
                                            "%s(): ADHOC CCMP: missing key entry.\n",